├── playground ├── input.ts └── index.js ├── test ├── jsx_simple │ ├── input.ts │ └── expected.json ├── export_type_star │ ├── input.ts │ └── expected.json ├── jsx_jsx_with_type_generics │ ├── input.ts │ └── expected.json ├── satisfies_normal │ ├── input.ts │ └── expected.json ├── type_casts_number1_expression │ ├── input.ts │ └── expected.json ├── type_casts_number1_label │ ├── input.ts │ └── expected.json ├── type_casts_1_as_number_expression │ ├── input.ts │ └── expected.json ├── type_casts_1_as_number_label │ ├── input.ts │ └── expected.json ├── variables_declaration_any │ ├── input.ts │ └── expected.json ├── class_escaped_static_method │ ├── error.txt │ └── input.ts ├── normal_export_export_const │ ├── input.ts │ └── expected.json ├── normal_syntax_issue_45 │ ├── input.ts │ └── expected.json ├── type_casts_number1_declaration │ ├── input.ts │ └── expected.json ├── variables_declaration_number │ ├── input.ts │ └── expected.json ├── variables_declaration_unknown │ ├── input.ts │ └── expected.json ├── export_type_export_type │ ├── input.ts │ └── expected.json ├── for_async_in_for_of_without_decl │ ├── error.txt │ └── input.ts ├── jsx_props_with_expr │ └── input.ts ├── normal_syntax_import_without_specifiers │ ├── input.ts │ └── expected.json ├── type_casts_1_as_number_declaration │ ├── input.ts │ └── expected.json ├── variables_declaration_boolean │ ├── input.ts │ └── expected.json ├── variables_declaration_number_with_definite │ ├── input.ts │ └── expected.json ├── variables_declaration_string │ ├── input.ts │ └── expected.json ├── arrow-function_type_test_assignment_pattern │ ├── input.ts │ └── expected.json ├── assert_import_with_duplicate │ ├── error.txt │ └── input.ts ├── class_definite_property │ ├── input.ts │ └── expected.json ├── jsx_value_with_colon │ └── input.ts ├── variables_declaration_expression_with_paren │ ├── input.ts │ └── expected.json ├── variables_declaration_let_union │ └── input.ts ├── variables_declaration_symbol │ └── input.ts ├── variables_declaration_undefined │ ├── input.ts │ └── expected.json ├── variables_declaration_union │ └── input.ts ├── arrow-function_type_test_rest_parameter │ └── input.ts ├── class_escaped_keyword_property │ ├── input.ts │ └── expected.json ├── class_no_super_override │ ├── input.ts │ └── error.txt ├── for_in_without_decl │ └── input.ts ├── normal_export_export_default_anonymous_class │ ├── input.ts │ └── expected.json ├── normal_syntax_import_default_specifiers │ ├── input.ts │ └── expected.json ├── try_statement_normal │ └── input.ts ├── variables_declaration_bigint │ └── input.ts ├── variables_declaration_parse_generics_with_comma │ └── input.ts ├── variables_declaration_parse_generics_without_comma │ └── input.ts ├── assert_import_assert │ ├── input.ts │ └── expected.json ├── assert_import_with │ ├── input.ts │ └── expected.json ├── class_duplicate_constructor │ ├── error.txt │ └── input.ts ├── class_super_override │ └── input.ts ├── function_type_test_async_arrow_function_with_one_param │ ├── input.ts │ └── expected.json ├── normal_export_export_default_object │ ├── input.ts │ └── expected.json ├── normal_identifier_test_typevalue_same_name_1 │ ├── input.ts │ └── expected.json ├── try_statement_with_type │ └── input.ts ├── tuple_named_and_anonymous_mixed │ └── input.ts ├── variables_declaration_parse_condition_express_error │ ├── input.ts │ └── error.txt ├── assert_dynamic_import_assert │ └── input.ts ├── expression_type_test_normal_type │ └── input.ts ├── normal_identifier_test_import_identifier_as │ ├── input.ts │ └── expected.json ├── normal_identifier_test_interface_merging │ ├── input.ts │ └── expected.json ├── normal_identifier_test_typeidentifier_same_name_2 │ ├── input.ts │ └── expected.json ├── normal_syntax_import_name_specifiers │ ├── input.ts │ └── expected.json ├── normal_syntax_import_namespace_specifiers │ ├── input.ts │ └── expected.json ├── variables_declaration_expression_equal_arrow_function │ ├── input.ts │ └── expected.json ├── variables_declaration_expression_equal_function │ ├── input.ts │ └── expected.json ├── variables_declaration_object │ └── input.ts ├── arrow-function_type_test_async_+_rest_parameter │ └── input.ts ├── assert_export_all_as_assert │ ├── input.ts │ └── expected.json ├── class_constructor_signature │ └── input.ts ├── class_simple_generic │ └── input.ts ├── expression_type_test_enum │ ├── input.ts │ └── expected.json ├── for_of │ └── input.ts ├── function_type_test_simple_generic │ └── input.ts ├── namespace_export_type │ └── input.ts ├── normal_identifier_test_export_identifier_as │ ├── input.ts │ └── expected.json ├── normal_syntax_import_name_as_specifiers │ ├── input.ts │ └── expected.json ├── object_async_arrow_function_in_subscript │ └── input.ts ├── function_type_test_no_parameter_with_any │ ├── input.ts │ └── expected.json ├── normal_identifier_test_typeidentifier_same_name_3 │ ├── input.ts │ └── expected.json ├── normal_syntax_import_type_specifier_with_as │ ├── input.ts │ └── expected.json ├── type_syntax_import_default_specifiers_with_type_token │ ├── input.ts │ └── expected.json ├── arrow-function_type_test_issue_32 │ └── input.ts ├── arrow-function_type_test_simple_generic │ └── input.ts ├── class_generic_with_const │ └── input.ts ├── enum_normal │ └── input.ts ├── function_type_test_generic_with_const │ └── input.ts ├── function_type_test_no_parameter_with_boolean │ ├── input.ts │ └── expected.json ├── function_type_test_no_parameter_with_number │ ├── input.ts │ └── expected.json ├── function_type_test_no_parameter_with_string │ ├── input.ts │ └── expected.json ├── function_type_test_no_parameter_with_unknown │ ├── input.ts │ └── expected.json ├── function_type_test_no_parameter_with_void │ └── input.ts ├── normal_identifier_test_identifier_multiple_times_error_1 │ ├── input.ts │ └── error.txt ├── normal_identifier_test_identifier_multiple_times_error_2 │ ├── input.ts │ └── error.txt ├── type_syntax_import_namespace_specifiers_with_type_token │ ├── input.ts │ └── expected.json ├── variables_reassignment_TSNonNullExpression │ └── input.ts ├── arrow-function_type_test_async_generic_empty_params │ ├── input.ts │ └── expected.json ├── export_type_export_outer_type_type_with_name │ ├── input.ts │ └── error.txt ├── function_type_test_no_parameter_with_object │ └── input.ts ├── function_type_test_no_parameter_with_union │ └── input.ts ├── normal_export_export │ └── input.ts ├── normal_export_export_default_arrow_function │ └── input.ts ├── normal_export_export_default_function │ └── input.ts ├── normal_syntax_import_type_specifier_with_as_as │ ├── input.ts │ └── expected.json ├── type_syntax_import_type_specifiers_with_outer_type │ ├── input.ts │ └── error.txt ├── variables_declaration_expression_equal_async_arrow_function │ └── input.ts ├── variables_declaration_expression_equal_async_function │ └── input.ts ├── variables_declaration_type │ └── input.ts ├── arrow-function_type_test_generic_with_const │ └── input.ts ├── class_generic_with_extends │ └── input.ts ├── export_type_export_type_as_as_with_name │ └── input.ts ├── function_type_test_arrow_function_with_optional_param │ └── input.ts ├── function_type_test_generic_with_extends │ └── input.ts ├── function_type_test_no_parameter_with_bigint │ └── input.ts ├── function_type_test_no_parameter_with_never │ └── input.ts ├── function_type_test_no_parameter_with_symbol │ └── input.ts ├── function_type_test_no_parameter_with_undefined │ ├── input.ts │ └── expected.json ├── type_syntax_import_name_as_specifiers_with_type_token │ ├── input.ts │ └── expected.json ├── class_class_abstract_method_with_body │ ├── input.ts │ └── error.txt ├── class_private_id_class_method │ └── input.ts ├── export_type_export_type_and_const │ └── input.ts ├── function_type_test_one_parameter_with_void │ └── input.ts ├── variables_declaration_identifier_that_could_be_keyword_inside_template_literal │ └── input.ts ├── arrow-function_type_test_generic_with_extends │ └── input.ts ├── class_private_class_method │ └── input.ts ├── class_static_gettersetter │ └── input.ts ├── export_type_export_serious_type │ └── input.ts ├── expression_type_test_declare │ └── input.ts ├── normal_export_export_default_function_with_name │ └── input.ts ├── normal_syntax_import_namespace_type_specifiers │ └── input.ts ├── variables_reassignment_TSAsExpression │ └── input.ts ├── export_type_export_type_type_with_as │ └── input.ts ├── export_type_export_type_with_as_and_const │ └── input.ts ├── expression_type_test_normal_interface │ └── input.ts ├── function_type_test_one_optional_parameter_with_void │ └── input.ts ├── export_type_export_type_type_with_as_as │ └── input.ts ├── function_type_test_async_generator_function │ └── input.ts ├── arrow-function_type_test_issue_39 │ └── input.ts ├── function_type_test_declare_function_comma_after_rest_element │ └── input.ts ├── object_normal_object │ └── input.ts ├── arrow-function_type_test_async_generic_after_import │ └── input.ts ├── class_accessor │ └── input.ts ├── normal_syntax_import_namespace_type_specifiers_with_as │ └── input.ts ├── function_type_test_no_parameter_with_type │ └── input.ts ├── arrow-function_type_test_async_generic_with_commented_import │ ├── input.ts │ └── expected.json ├── arrow-function_type_test_destructuring_+_default_value │ └── input.ts ├── class_static_property │ └── input.ts ├── try_statement_catch_redeclared_var_statement_captured │ └── input.ts ├── normal_syntax_import_complex_specifiers │ └── input.ts ├── variables_declaration_expression_list_arrow_function_and_param_is_function │ └── input.ts ├── variables_declaration_expression_list_arrow_function_and_var │ └── input.ts ├── dts_export_type_dts_export_duplicate │ └── input.ts ├── jsx_issue_46 │ └── input.ts ├── variables_declaration_issue_43 │ └── input.ts ├── function_type_test_declare_function_types │ └── input.ts ├── decorator_after_interface │ └── input.ts ├── type_syntax_import_complex_type │ └── input.ts ├── class_computed_property │ └── input.ts ├── class_class_duplicate_method │ └── input.ts ├── expression_type_test_nested_interface │ └── input.ts ├── decorators_class_params │ └── input.ts ├── variables_declaration_interface │ └── input.ts ├── jsx_issue_48 │ └── input.ts ├── class_class_duplicate_constructor │ └── input.ts ├── class_static_async_methods │ └── input.ts ├── function_type_test_complex_function │ └── input.ts ├── arrow-function_type_test_issue_38 │ └── input.ts ├── object_get_and_set_with_this │ └── input.ts ├── object_get_and_set_without_this │ └── input.ts ├── decorators_class_property │ └── input.ts ├── class_issue_42 │ └── input.ts ├── expression_type_test_extend_interface │ └── input.ts ├── function_type_test_no_parameter_with_interface │ └── input.ts ├── class_normal_property │ └── input.ts ├── decorators_class_method │ └── input.ts ├── class_private_property │ └── input.ts ├── class_public_property │ └── input.ts ├── class_readonly_property │ └── input.ts ├── class_protected_property │ └── input.ts ├── decorators_class │ └── input.ts ├── decorators_class_accessor │ └── input.ts ├── class_issue_44 │ └── input.ts ├── expression_type_test_declare_namespace │ └── input.ts ├── class_abstract_class │ └── input.ts ├── dts_expression_type_test_issue_29 │ └── input.ts ├── class_issue_33 │ └── input.ts ├── parseExpressionAt.test.ts ├── jsx_issue_29_jsx │ └── input.ts ├── jsx_tsx │ └── input.ts ├── class_issue_34 │ └── input.ts ├── class_issue_36 │ └── input.ts ├── utils.ts ├── class_issue_35 │ └── input.ts ├── run.test.ts └── plugin.test.ts ├── .npmrc ├── .prettierignore ├── .prettierrc ├── index.d.ts ├── .changeset ├── config.json └── README.md ├── tsconfig.json ├── src ├── whitespace.ts ├── parseutil.ts ├── types.ts └── extentions │ └── import-assertions.ts ├── .github └── workflows │ ├── ci.yml │ └── release.yml ├── LICENSE.md ├── package.json ├── README.md └── .gitignore /playground/input.ts: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /test/jsx_simple/input.ts: -------------------------------------------------------------------------------- 1 |
-------------------------------------------------------------------------------- /.npmrc: -------------------------------------------------------------------------------- 1 | registry = https://registry.npmjs.org/ 2 | -------------------------------------------------------------------------------- /test/export_type_star/input.ts: -------------------------------------------------------------------------------- 1 | export type * from './foo'; -------------------------------------------------------------------------------- /test/jsx_jsx_with_type_generics/input.ts: -------------------------------------------------------------------------------- 1 | /> -------------------------------------------------------------------------------- /test/satisfies_normal/input.ts: -------------------------------------------------------------------------------- 1 | const a = 1 satisfies any -------------------------------------------------------------------------------- /test/type_casts_number1_expression/input.ts: -------------------------------------------------------------------------------- 1 | foo(1) -------------------------------------------------------------------------------- /test/type_casts_number1_label/input.ts: -------------------------------------------------------------------------------- 1 | $: test = 1 -------------------------------------------------------------------------------- /test/type_casts_1_as_number_expression/input.ts: -------------------------------------------------------------------------------- 1 | foo(1 as number) -------------------------------------------------------------------------------- /test/type_casts_1_as_number_label/input.ts: -------------------------------------------------------------------------------- 1 | $: test = 1 as number -------------------------------------------------------------------------------- /test/variables_declaration_any/input.ts: -------------------------------------------------------------------------------- 1 | const test: any = 123 -------------------------------------------------------------------------------- /test/class_escaped_static_method/error.txt: -------------------------------------------------------------------------------- 1 | Unexpected token (2:13) -------------------------------------------------------------------------------- /test/normal_export_export_const/input.ts: -------------------------------------------------------------------------------- 1 | export const test = '12345' -------------------------------------------------------------------------------- /test/normal_syntax_issue_45/input.ts: -------------------------------------------------------------------------------- 1 | import assert from './index.js' -------------------------------------------------------------------------------- /test/type_casts_number1_declaration/input.ts: -------------------------------------------------------------------------------- 1 | let test = 1 -------------------------------------------------------------------------------- /test/variables_declaration_number/input.ts: -------------------------------------------------------------------------------- 1 | const test: number = 123 -------------------------------------------------------------------------------- /test/variables_declaration_unknown/input.ts: -------------------------------------------------------------------------------- 1 | const test: unknown = 123 -------------------------------------------------------------------------------- /test/export_type_export_type/input.ts: -------------------------------------------------------------------------------- 1 | export type Test = string | number -------------------------------------------------------------------------------- /test/for_async_in_for_of_without_decl/error.txt: -------------------------------------------------------------------------------- 1 | Unexpected token (2:14) -------------------------------------------------------------------------------- /test/jsx_props_with_expr/input.ts: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /test/normal_syntax_import_without_specifiers/input.ts: -------------------------------------------------------------------------------- 1 | import './index.js' -------------------------------------------------------------------------------- /test/type_casts_1_as_number_declaration/input.ts: -------------------------------------------------------------------------------- 1 | let test = 1 as number -------------------------------------------------------------------------------- /test/variables_declaration_boolean/input.ts: -------------------------------------------------------------------------------- 1 | const test: boolean = false -------------------------------------------------------------------------------- /test/variables_declaration_number_with_definite/input.ts: -------------------------------------------------------------------------------- 1 | let test!: number -------------------------------------------------------------------------------- /test/variables_declaration_string/input.ts: -------------------------------------------------------------------------------- 1 | const test: string = '12355' -------------------------------------------------------------------------------- /test/arrow-function_type_test_assignment_pattern/input.ts: -------------------------------------------------------------------------------- 1 | (x = 42): void => {} -------------------------------------------------------------------------------- /test/assert_import_with_duplicate/error.txt: -------------------------------------------------------------------------------- 1 | Duplicated key in attributes (1:63) -------------------------------------------------------------------------------- /test/class_definite_property/input.ts: -------------------------------------------------------------------------------- 1 | class Student { 2 | name!: string 3 | } -------------------------------------------------------------------------------- /test/jsx_value_with_colon/input.ts: -------------------------------------------------------------------------------- 1 | {value} -------------------------------------------------------------------------------- /test/variables_declaration_expression_with_paren/input.ts: -------------------------------------------------------------------------------- 1 | let test = (1 === 2) -------------------------------------------------------------------------------- /test/variables_declaration_let_union/input.ts: -------------------------------------------------------------------------------- 1 | let test: string | number = 123 -------------------------------------------------------------------------------- /test/variables_declaration_symbol/input.ts: -------------------------------------------------------------------------------- 1 | const test: symbol = Symbol('123') -------------------------------------------------------------------------------- /test/variables_declaration_undefined/input.ts: -------------------------------------------------------------------------------- 1 | const test: undefined = undefined -------------------------------------------------------------------------------- /test/variables_declaration_union/input.ts: -------------------------------------------------------------------------------- 1 | const test: string | number = 123 -------------------------------------------------------------------------------- /test/arrow-function_type_test_rest_parameter/input.ts: -------------------------------------------------------------------------------- 1 | const f = (...args: any) => {} -------------------------------------------------------------------------------- /test/class_escaped_keyword_property/input.ts: -------------------------------------------------------------------------------- 1 | class C { 2 | \u0069n: string 3 | } -------------------------------------------------------------------------------- /test/class_escaped_static_method/input.ts: -------------------------------------------------------------------------------- 1 | class C { 2 | st\u0061tic m() {} 3 | } -------------------------------------------------------------------------------- /test/class_no_super_override/input.ts: -------------------------------------------------------------------------------- 1 | class A { 2 | override c() {} 3 | } 4 | -------------------------------------------------------------------------------- /test/for_async_in_for_of_without_decl/input.ts: -------------------------------------------------------------------------------- 1 | var async; 2 | for (async of [1]) ; -------------------------------------------------------------------------------- /test/for_in_without_decl/input.ts: -------------------------------------------------------------------------------- 1 | for (word in words) { 2 | console.log(word) 3 | } -------------------------------------------------------------------------------- /test/normal_export_export_default_anonymous_class/input.ts: -------------------------------------------------------------------------------- 1 | export default class {} -------------------------------------------------------------------------------- /test/normal_syntax_import_default_specifiers/input.ts: -------------------------------------------------------------------------------- 1 | import test from './index.js' -------------------------------------------------------------------------------- /test/try_statement_normal/input.ts: -------------------------------------------------------------------------------- 1 | try { 2 | console.log(123) 3 | } catch(e) {} -------------------------------------------------------------------------------- /test/variables_declaration_bigint/input.ts: -------------------------------------------------------------------------------- 1 | const test: bigint = BigInt('123123') -------------------------------------------------------------------------------- /test/variables_declaration_parse_generics_with_comma/input.ts: -------------------------------------------------------------------------------- 1 | const a: Foo = 1 -------------------------------------------------------------------------------- /test/variables_declaration_parse_generics_without_comma/input.ts: -------------------------------------------------------------------------------- 1 | const a: Foo = 1 -------------------------------------------------------------------------------- /.prettierignore: -------------------------------------------------------------------------------- 1 | test/*/input.ts 2 | .changeset 3 | node_modules 4 | pnpm-lock.yaml 5 | -------------------------------------------------------------------------------- /test/assert_import_assert/input.ts: -------------------------------------------------------------------------------- 1 | import json from './foo.json' assert { type: 'json' }; -------------------------------------------------------------------------------- /test/assert_import_with/input.ts: -------------------------------------------------------------------------------- 1 | import json from './foo.json' with { type: 'json' }; -------------------------------------------------------------------------------- /test/class_duplicate_constructor/error.txt: -------------------------------------------------------------------------------- 1 | Duplicate constructor in the same class (3:1) -------------------------------------------------------------------------------- /test/class_super_override/input.ts: -------------------------------------------------------------------------------- 1 | class A extends B { 2 | override c() {} 3 | } 4 | -------------------------------------------------------------------------------- /test/function_type_test_async_arrow_function_with_one_param/input.ts: -------------------------------------------------------------------------------- 1 | a = async x => {} -------------------------------------------------------------------------------- /test/normal_export_export_default_object/input.ts: -------------------------------------------------------------------------------- 1 | export default { 2 | a: '12345' 3 | } -------------------------------------------------------------------------------- /test/normal_identifier_test_typevalue_same_name_1/input.ts: -------------------------------------------------------------------------------- 1 | type abc = 1234; 2 | var abc; -------------------------------------------------------------------------------- /test/try_statement_with_type/input.ts: -------------------------------------------------------------------------------- 1 | try { 2 | console.log(123) 3 | } catch(e: any) {} -------------------------------------------------------------------------------- /test/tuple_named_and_anonymous_mixed/input.ts: -------------------------------------------------------------------------------- 1 | type A = [foo: string, ...number[]]; 2 | -------------------------------------------------------------------------------- /test/variables_declaration_parse_condition_express_error/input.ts: -------------------------------------------------------------------------------- 1 | const a = true ? : 1 -------------------------------------------------------------------------------- /test/assert_dynamic_import_assert/input.ts: -------------------------------------------------------------------------------- 1 | import("./foo.json", { with: { type: "json" } }); -------------------------------------------------------------------------------- /test/expression_type_test_normal_type/input.ts: -------------------------------------------------------------------------------- 1 | type School = 'Tsinghua' | 'Peking' | 'GDUT' -------------------------------------------------------------------------------- /test/normal_identifier_test_import_identifier_as/input.ts: -------------------------------------------------------------------------------- 1 | import { as as as } from './foo.js'; -------------------------------------------------------------------------------- /test/normal_identifier_test_interface_merging/input.ts: -------------------------------------------------------------------------------- 1 | interface abc {} 2 | interface abc {} -------------------------------------------------------------------------------- /test/normal_identifier_test_typeidentifier_same_name_2/input.ts: -------------------------------------------------------------------------------- 1 | type abc = 1234; 2 | let abc; -------------------------------------------------------------------------------- /test/normal_syntax_import_name_specifiers/input.ts: -------------------------------------------------------------------------------- 1 | import { test, name } from './index.js' -------------------------------------------------------------------------------- /test/normal_syntax_import_namespace_specifiers/input.ts: -------------------------------------------------------------------------------- 1 | import * as test from './index.js' -------------------------------------------------------------------------------- /test/variables_declaration_expression_equal_arrow_function/input.ts: -------------------------------------------------------------------------------- 1 | let test = (): void => {} -------------------------------------------------------------------------------- /test/variables_declaration_expression_equal_function/input.ts: -------------------------------------------------------------------------------- 1 | let test = function(): void {} -------------------------------------------------------------------------------- /test/variables_declaration_object/input.ts: -------------------------------------------------------------------------------- 1 | const test: object = { 2 | a: 1, 3 | b: 2 4 | } -------------------------------------------------------------------------------- /test/variables_declaration_parse_condition_express_error/error.txt: -------------------------------------------------------------------------------- 1 | Unexpected token (1:17) -------------------------------------------------------------------------------- /test/arrow-function_type_test_async_+_rest_parameter/input.ts: -------------------------------------------------------------------------------- 1 | const f = async (...args: any) => {} -------------------------------------------------------------------------------- /test/assert_export_all_as_assert/input.ts: -------------------------------------------------------------------------------- 1 | export * as name from "./foo.json" with { type: "json" }; -------------------------------------------------------------------------------- /test/class_constructor_signature/input.ts: -------------------------------------------------------------------------------- 1 | class C { 2 | constructor() 3 | constructor(){} 4 | } -------------------------------------------------------------------------------- /test/class_duplicate_constructor/input.ts: -------------------------------------------------------------------------------- 1 | class C { 2 | constructor(){} 3 | constructor(){} 4 | } -------------------------------------------------------------------------------- /test/class_simple_generic/input.ts: -------------------------------------------------------------------------------- 1 | class X { 2 | test(a: T): T { 3 | return a 4 | } 5 | } -------------------------------------------------------------------------------- /test/expression_type_test_enum/input.ts: -------------------------------------------------------------------------------- 1 | enum Test { 2 | Start = 'start', 3 | End = 'end' 4 | } -------------------------------------------------------------------------------- /test/for_of/input.ts: -------------------------------------------------------------------------------- 1 | const words = [] 2 | for (const word of words) { 3 | console.log(word) 4 | } -------------------------------------------------------------------------------- /test/function_type_test_simple_generic/input.ts: -------------------------------------------------------------------------------- 1 | function test(a: T): T { 2 | return a 3 | } -------------------------------------------------------------------------------- /test/namespace_export_type/input.ts: -------------------------------------------------------------------------------- 1 | namespace SomeNamespace { 2 | export type Foo = true; 3 | } -------------------------------------------------------------------------------- /test/normal_identifier_test_export_identifier_as/input.ts: -------------------------------------------------------------------------------- 1 | var foo = 8; 2 | export { foo as as }; -------------------------------------------------------------------------------- /test/normal_syntax_import_name_as_specifiers/input.ts: -------------------------------------------------------------------------------- 1 | import { test as test1 } from './index.js' -------------------------------------------------------------------------------- /test/object_async_arrow_function_in_subscript/input.ts: -------------------------------------------------------------------------------- 1 | async () => { 2 | console.log(123) 3 | } -------------------------------------------------------------------------------- /test/function_type_test_no_parameter_with_any/input.ts: -------------------------------------------------------------------------------- 1 | function test(): any { 2 | return 123 3 | } -------------------------------------------------------------------------------- /test/normal_identifier_test_typeidentifier_same_name_3/input.ts: -------------------------------------------------------------------------------- 1 | type abc = 1234; 2 | function abc() {} -------------------------------------------------------------------------------- /test/normal_syntax_import_type_specifier_with_as/input.ts: -------------------------------------------------------------------------------- 1 | import test, { type as age } from './index.js' -------------------------------------------------------------------------------- /test/type_syntax_import_default_specifiers_with_type_token/input.ts: -------------------------------------------------------------------------------- 1 | import type Test from './index.ts' -------------------------------------------------------------------------------- /test/arrow-function_type_test_issue_32/input.ts: -------------------------------------------------------------------------------- 1 | const testApp = async(app: string, index: number) => { 2 | }; -------------------------------------------------------------------------------- /test/arrow-function_type_test_simple_generic/input.ts: -------------------------------------------------------------------------------- 1 | const test = (a: T): T => { 2 | return a 3 | } -------------------------------------------------------------------------------- /test/assert_import_with_duplicate/input.ts: -------------------------------------------------------------------------------- 1 | import json from './foo.json' with { type: 'json', type: 'json' }; -------------------------------------------------------------------------------- /test/class_generic_with_const/input.ts: -------------------------------------------------------------------------------- 1 | class X { 2 | test(a: T): T { 3 | return a 4 | } 5 | } -------------------------------------------------------------------------------- /test/enum_normal/input.ts: -------------------------------------------------------------------------------- 1 | enum Student { 2 | name = 'tyreal', 3 | age = 22, 4 | school = 'string' 5 | } -------------------------------------------------------------------------------- /test/function_type_test_generic_with_const/input.ts: -------------------------------------------------------------------------------- 1 | function test(a: T): T { 2 | return a 3 | } -------------------------------------------------------------------------------- /test/function_type_test_no_parameter_with_boolean/input.ts: -------------------------------------------------------------------------------- 1 | function test(): boolean { 2 | return true 3 | } -------------------------------------------------------------------------------- /test/function_type_test_no_parameter_with_number/input.ts: -------------------------------------------------------------------------------- 1 | function test(): number { 2 | return 123 3 | } -------------------------------------------------------------------------------- /test/function_type_test_no_parameter_with_string/input.ts: -------------------------------------------------------------------------------- 1 | function test(): string { 2 | return '123' 3 | } -------------------------------------------------------------------------------- /test/function_type_test_no_parameter_with_unknown/input.ts: -------------------------------------------------------------------------------- 1 | function test(): unknown { 2 | return 123 3 | } -------------------------------------------------------------------------------- /test/function_type_test_no_parameter_with_void/input.ts: -------------------------------------------------------------------------------- 1 | function test(): void { 2 | console.log(123) 3 | } -------------------------------------------------------------------------------- /test/normal_identifier_test_identifier_multiple_times_error_1/input.ts: -------------------------------------------------------------------------------- 1 | let abc = 1234; 2 | function abc() {} -------------------------------------------------------------------------------- /test/normal_identifier_test_identifier_multiple_times_error_2/input.ts: -------------------------------------------------------------------------------- 1 | type abc = 1234; 2 | type abc = 'hi'; -------------------------------------------------------------------------------- /test/type_syntax_import_namespace_specifiers_with_type_token/input.ts: -------------------------------------------------------------------------------- 1 | import type * as Test from './index.ts' -------------------------------------------------------------------------------- /test/variables_reassignment_TSNonNullExpression/input.ts: -------------------------------------------------------------------------------- 1 | let a: number | undefined = 1 2 | a! = 2 3 | a! += 3 -------------------------------------------------------------------------------- /test/arrow-function_type_test_async_generic_empty_params/input.ts: -------------------------------------------------------------------------------- 1 | const loadDataWithGeneric = async () => {}; -------------------------------------------------------------------------------- /test/export_type_export_outer_type_type_with_name/input.ts: -------------------------------------------------------------------------------- 1 | const A = 'test' 2 | export type { 3 | type A 4 | } -------------------------------------------------------------------------------- /test/function_type_test_no_parameter_with_object/input.ts: -------------------------------------------------------------------------------- 1 | function test(): object { 2 | return { a: 1 } 3 | } -------------------------------------------------------------------------------- /test/function_type_test_no_parameter_with_union/input.ts: -------------------------------------------------------------------------------- 1 | function test(): string | number { 2 | return 123 3 | } -------------------------------------------------------------------------------- /test/normal_export_export/input.ts: -------------------------------------------------------------------------------- 1 | const Name = 'tyreal' 2 | let Age = 22 3 | export { 4 | Name, 5 | Age 6 | } -------------------------------------------------------------------------------- /test/normal_export_export_default_arrow_function/input.ts: -------------------------------------------------------------------------------- 1 | export default () => { 2 | console.log('12345') 3 | } -------------------------------------------------------------------------------- /test/normal_export_export_default_function/input.ts: -------------------------------------------------------------------------------- 1 | export default function() { 2 | console.log('12345') 3 | } -------------------------------------------------------------------------------- /test/normal_syntax_import_type_specifier_with_as_as/input.ts: -------------------------------------------------------------------------------- 1 | import { type as as somethings } from './index.js' -------------------------------------------------------------------------------- /test/type_syntax_import_type_specifiers_with_outer_type/input.ts: -------------------------------------------------------------------------------- 1 | import type { type Test1 } from './index1.ts' -------------------------------------------------------------------------------- /test/variables_declaration_expression_equal_async_arrow_function/input.ts: -------------------------------------------------------------------------------- 1 | let test = async (): Promise => {} -------------------------------------------------------------------------------- /test/variables_declaration_expression_equal_async_function/input.ts: -------------------------------------------------------------------------------- 1 | let test = async function(): Promise {} -------------------------------------------------------------------------------- /test/variables_declaration_type/input.ts: -------------------------------------------------------------------------------- 1 | type TestType = string | number | object 2 | const test: TestType = 123 -------------------------------------------------------------------------------- /test/arrow-function_type_test_generic_with_const/input.ts: -------------------------------------------------------------------------------- 1 | const test = (a: T): T => { 2 | return a 3 | } -------------------------------------------------------------------------------- /test/class_generic_with_extends/input.ts: -------------------------------------------------------------------------------- 1 | class X { 2 | test(a: T): T { 3 | return a 4 | } 5 | } -------------------------------------------------------------------------------- /test/export_type_export_type_as_as_with_name/input.ts: -------------------------------------------------------------------------------- 1 | const as = 'test' 2 | export { 3 | type as as someName 4 | } -------------------------------------------------------------------------------- /test/function_type_test_arrow_function_with_optional_param/input.ts: -------------------------------------------------------------------------------- 1 | const test = (name: string, age?: number) => 42 -------------------------------------------------------------------------------- /test/function_type_test_generic_with_extends/input.ts: -------------------------------------------------------------------------------- 1 | function test(a: T): T { 2 | return a 3 | } -------------------------------------------------------------------------------- /test/function_type_test_no_parameter_with_bigint/input.ts: -------------------------------------------------------------------------------- 1 | function test(): bigint { 2 | return BigInt('123123') 3 | } -------------------------------------------------------------------------------- /test/function_type_test_no_parameter_with_never/input.ts: -------------------------------------------------------------------------------- 1 | function test(): never { 2 | throw new Error('123') 3 | } -------------------------------------------------------------------------------- /test/function_type_test_no_parameter_with_symbol/input.ts: -------------------------------------------------------------------------------- 1 | function test(): symbol { 2 | return Symbol('123') 3 | } -------------------------------------------------------------------------------- /test/function_type_test_no_parameter_with_undefined/input.ts: -------------------------------------------------------------------------------- 1 | function test(): undefined { 2 | return undefined 3 | } -------------------------------------------------------------------------------- /test/normal_identifier_test_identifier_multiple_times_error_2/error.txt: -------------------------------------------------------------------------------- 1 | type 'abc' has already been declared. (2:5) -------------------------------------------------------------------------------- /test/type_syntax_import_name_as_specifiers_with_type_token/input.ts: -------------------------------------------------------------------------------- 1 | import type { Test as Test1 } from './index.ts' -------------------------------------------------------------------------------- /test/class_class_abstract_method_with_body/input.ts: -------------------------------------------------------------------------------- 1 | abstract class Person { 2 | abstract find(string): Person {} 3 | } -------------------------------------------------------------------------------- /test/class_private_id_class_method/input.ts: -------------------------------------------------------------------------------- 1 | class Student { 2 | #study() { 3 | console.log('Im studying') 4 | } 5 | } -------------------------------------------------------------------------------- /test/export_type_export_type_and_const/input.ts: -------------------------------------------------------------------------------- 1 | const a = 1 2 | type A = number 3 | export { 4 | a, 5 | type A 6 | } -------------------------------------------------------------------------------- /test/function_type_test_one_parameter_with_void/input.ts: -------------------------------------------------------------------------------- 1 | function test(name: string): void { 2 | console.log(name) 3 | } -------------------------------------------------------------------------------- /test/normal_identifier_test_identifier_multiple_times_error_1/error.txt: -------------------------------------------------------------------------------- 1 | Identifier 'abc' has already been declared (2:9) -------------------------------------------------------------------------------- /test/variables_declaration_identifier_that_could_be_keyword_inside_template_literal/input.ts: -------------------------------------------------------------------------------- 1 | const str = `${obj?.class}`; -------------------------------------------------------------------------------- /.prettierrc: -------------------------------------------------------------------------------- 1 | { 2 | "useTabs": true, 3 | "singleQuote": true, 4 | "trailingComma": "none", 5 | "printWidth": 100 6 | } 7 | -------------------------------------------------------------------------------- /test/arrow-function_type_test_generic_with_extends/input.ts: -------------------------------------------------------------------------------- 1 | const test = (a: T): T => { 2 | return a 3 | } -------------------------------------------------------------------------------- /test/class_private_class_method/input.ts: -------------------------------------------------------------------------------- 1 | class Student { 2 | private study() { 3 | console.log('Im studying') 4 | } 5 | } -------------------------------------------------------------------------------- /test/class_static_gettersetter/input.ts: -------------------------------------------------------------------------------- 1 | class C { 2 | static get foo(): number {} 3 | static set foo(value: number) {} 4 | } -------------------------------------------------------------------------------- /test/export_type_export_serious_type/input.ts: -------------------------------------------------------------------------------- 1 | type Name = string 2 | type Age = number 3 | export { 4 | Name, 5 | Age 6 | } -------------------------------------------------------------------------------- /test/expression_type_test_declare/input.ts: -------------------------------------------------------------------------------- 1 | declare module '*.png' { 2 | const value: string; 3 | export default value; 4 | } -------------------------------------------------------------------------------- /test/normal_export_export_default_function_with_name/input.ts: -------------------------------------------------------------------------------- 1 | export default function Test() { 2 | console.log('12345') 3 | } -------------------------------------------------------------------------------- /test/normal_syntax_import_namespace_type_specifiers/input.ts: -------------------------------------------------------------------------------- 1 | import test, { name, type age, school as school1 } from './index.js' -------------------------------------------------------------------------------- /test/variables_reassignment_TSAsExpression/input.ts: -------------------------------------------------------------------------------- 1 | let a: number | undefined = 1; 2 | (a as number) = 2; 3 | (a as number) += 3; -------------------------------------------------------------------------------- /test/class_class_abstract_method_with_body/error.txt: -------------------------------------------------------------------------------- 1 | Method 'find' cannot have an implementation because it is marked abstract. (2:2) -------------------------------------------------------------------------------- /test/export_type_export_type_type_with_as/input.ts: -------------------------------------------------------------------------------- 1 | const a = 1 2 | type type = number 3 | export { 4 | a, 5 | type type as A 6 | } -------------------------------------------------------------------------------- /test/export_type_export_type_with_as_and_const/input.ts: -------------------------------------------------------------------------------- 1 | const a = 1 2 | type A = number 3 | export { 4 | a, 5 | type A as B 6 | } -------------------------------------------------------------------------------- /test/expression_type_test_normal_interface/input.ts: -------------------------------------------------------------------------------- 1 | interface Student { 2 | name: string 3 | age: number 4 | school: string 5 | } -------------------------------------------------------------------------------- /test/function_type_test_one_optional_parameter_with_void/input.ts: -------------------------------------------------------------------------------- 1 | function test(name?: string): void { 2 | console.log(name) 3 | } -------------------------------------------------------------------------------- /test/export_type_export_type_type_with_as_as/input.ts: -------------------------------------------------------------------------------- 1 | const a = 1 2 | type type = number 3 | export { 4 | a, 5 | type type as as 6 | } -------------------------------------------------------------------------------- /test/function_type_test_async_generator_function/input.ts: -------------------------------------------------------------------------------- 1 | async function * test(p: Promise): void { 2 | yield * await p 3 | } -------------------------------------------------------------------------------- /test/arrow-function_type_test_issue_39/input.ts: -------------------------------------------------------------------------------- 1 | export const getPureFunctions = ({ treeshake }: NormalizedInputOptions): PureFunctions => {}; -------------------------------------------------------------------------------- /test/function_type_test_declare_function_comma_after_rest_element/input.ts: -------------------------------------------------------------------------------- 1 | declare function test(a: number | string, ...b,): number | string; -------------------------------------------------------------------------------- /test/object_normal_object/input.ts: -------------------------------------------------------------------------------- 1 | const test = { 2 | privateName: 'tyreal', 3 | speak() { 4 | console.log(123) 5 | }, 6 | } -------------------------------------------------------------------------------- /test/arrow-function_type_test_async_generic_after_import/input.ts: -------------------------------------------------------------------------------- 1 | import {} from './config' 2 | 3 | const loadDataWithGeneric = async () => {}; -------------------------------------------------------------------------------- /test/class_accessor/input.ts: -------------------------------------------------------------------------------- 1 | class Person { 2 | accessor name: string; 3 | constructor(name: string) { 4 | this.name = name; 5 | } 6 | } -------------------------------------------------------------------------------- /test/normal_syntax_import_namespace_type_specifiers_with_as/input.ts: -------------------------------------------------------------------------------- 1 | import test, { name, type age as age1, school as school1 } from './index.js' -------------------------------------------------------------------------------- /test/class_no_super_override/error.txt: -------------------------------------------------------------------------------- 1 | This member cannot have an 'override' modifier because its containing class does not extend another class. (2:4) -------------------------------------------------------------------------------- /test/function_type_test_no_parameter_with_type/input.ts: -------------------------------------------------------------------------------- 1 | type TestType = string | number | object 2 | function test(): TestType { 3 | return 123 4 | } -------------------------------------------------------------------------------- /test/arrow-function_type_test_async_generic_with_commented_import/input.ts: -------------------------------------------------------------------------------- 1 | // import {} from './config' 2 | 3 | const loadDataWithGeneric = async () => {}; -------------------------------------------------------------------------------- /test/arrow-function_type_test_destructuring_+_default_value/input.ts: -------------------------------------------------------------------------------- 1 | const increment = ({ increment } : { increment?: number } = {}) => { 2 | count += 1 3 | } -------------------------------------------------------------------------------- /test/class_static_property/input.ts: -------------------------------------------------------------------------------- 1 | class Student { 2 | static school: string = 'gdut' 3 | static study() { 4 | console.log('Im studying') 5 | } 6 | } -------------------------------------------------------------------------------- /test/try_statement_catch_redeclared_var_statement_captured/input.ts: -------------------------------------------------------------------------------- 1 | try { 2 | throw new Error(); 3 | } catch (foo) { 4 | var foo = "initializer in catch"; 5 | } -------------------------------------------------------------------------------- /test/export_type_export_outer_type_type_with_name/error.txt: -------------------------------------------------------------------------------- 1 | The 'type' modifier cannot be used on a named export when 'export type' is used on its export statement. (3:2) -------------------------------------------------------------------------------- /test/type_syntax_import_type_specifiers_with_outer_type/error.txt: -------------------------------------------------------------------------------- 1 | The 'type' modifier cannot be used on a named import when 'import type' is used on its import statement. (1:14) -------------------------------------------------------------------------------- /test/normal_syntax_import_complex_specifiers/input.ts: -------------------------------------------------------------------------------- 1 | import './index3.js' 2 | import test, { name, age, school as school1 } from './index.js' 3 | import * as test1 from './index1.js' -------------------------------------------------------------------------------- /test/variables_declaration_expression_list_arrow_function_and_param_is_function/input.ts: -------------------------------------------------------------------------------- 1 | let test = (name: string, speak: (() => void)): void => { 2 | console.log(name, age) 3 | } -------------------------------------------------------------------------------- /test/variables_declaration_expression_list_arrow_function_and_var/input.ts: -------------------------------------------------------------------------------- 1 | let test1 = 2, 2 | test = (name: string, age: number): void => { 3 | console.log(name, age) 4 | } -------------------------------------------------------------------------------- /test/dts_export_type_dts_export_duplicate/input.ts: -------------------------------------------------------------------------------- 1 | export function defineConfig(options: RollupOptions): RollupOptions; 2 | export function defineConfig(options: RollupOptions[]): RollupOptions[]; -------------------------------------------------------------------------------- /test/jsx_issue_46/input.ts: -------------------------------------------------------------------------------- 1 | 2 | import * as React from 'react' 3 | import { Link as RRLink } from 'react-router-dom'; 4 | 5 | const Link = (props: React.ComponentProps) => null 6 | -------------------------------------------------------------------------------- /test/variables_declaration_issue_43/input.ts: -------------------------------------------------------------------------------- 1 | 2 | const binaryOperators: { 3 | [operator in any]?: (left: any, right: any) => any; 4 | } = { 5 | '<': (left, right) => left! < right! 6 | }; 7 | -------------------------------------------------------------------------------- /test/function_type_test_declare_function_types/input.ts: -------------------------------------------------------------------------------- 1 | function test(a: string): string 2 | function test(a: number): number 3 | function test(a: number | string): number | string { 4 | return a 5 | } -------------------------------------------------------------------------------- /test/decorator_after_interface/input.ts: -------------------------------------------------------------------------------- 1 | interface User { 2 | id: number; 3 | name: string; 4 | } 5 | 6 | @Injectable() 7 | export class UserService { 8 | getUser() { return null; } 9 | } 10 | -------------------------------------------------------------------------------- /test/type_syntax_import_complex_type/input.ts: -------------------------------------------------------------------------------- 1 | import './index.ts' 2 | import type Test1 from './index1.ts' 3 | import type { Test as Test2 } from './index2.ts' 4 | import type * as Test3 from './index3.ts' -------------------------------------------------------------------------------- /test/class_computed_property/input.ts: -------------------------------------------------------------------------------- 1 | class Student { 2 | private _school: string 3 | get school() { 4 | return this._school 5 | } 6 | set school(value: string) { 7 | this._school = value 8 | } 9 | } -------------------------------------------------------------------------------- /test/class_class_duplicate_method/input.ts: -------------------------------------------------------------------------------- 1 | class Student { 2 | study(book: 'math'): void 3 | study(book: 'english'): void 4 | study(book: 'math' | 'english'): void { 5 | console.log('Im studying') 6 | } 7 | } -------------------------------------------------------------------------------- /test/expression_type_test_nested_interface/input.ts: -------------------------------------------------------------------------------- 1 | interface Student { 2 | name: string 3 | age: number 4 | family: string[] 5 | interest: { 6 | artificialIntelligence: string 7 | study: string 8 | } 9 | } -------------------------------------------------------------------------------- /test/decorators_class_params/input.ts: -------------------------------------------------------------------------------- 1 | class MyClass { 2 | myMethod(@logParam myParameter: string) {} 3 | } 4 | function logParam(target: any, methodKey: string, parameterIndex: number) { 5 | target.test = methodKey; 6 | } -------------------------------------------------------------------------------- /test/variables_declaration_interface/input.ts: -------------------------------------------------------------------------------- 1 | interface Student { 2 | name: string 3 | age: number 4 | school: string 5 | } 6 | const test: Student = { 7 | name: 'tyreal', 8 | age: 22, 9 | school: 'gdut', 10 | } -------------------------------------------------------------------------------- /test/jsx_issue_48/input.ts: -------------------------------------------------------------------------------- 1 | 2 | import styled from 'styled-components'; 3 | 4 | type ExtendedProps = { 5 | $anyprop: string; 6 | }; 7 | 8 | const StyledDiv = styled.div` 9 | color: red; 10 | `; 11 | -------------------------------------------------------------------------------- /test/class_class_duplicate_constructor/input.ts: -------------------------------------------------------------------------------- 1 | class Student { 2 | constructor(book: 'math'): void 3 | constructor(book: 'english'): void 4 | constructor(book: 'math' | 'english'): void { 5 | console.log('Im studying') 6 | } 7 | } -------------------------------------------------------------------------------- /test/class_static_async_methods/input.ts: -------------------------------------------------------------------------------- 1 | class Student { 2 | static async study(): Promise { 3 | console.log('Im studying') 4 | } 5 | static async * students(): AsyncIterable { 6 | yield 'John Smith' 7 | } 8 | } -------------------------------------------------------------------------------- /test/function_type_test_complex_function/input.ts: -------------------------------------------------------------------------------- 1 | interface Family { 2 | father: string 3 | mother: string 4 | } 5 | function test(name: string, family: Family, age?: number): Family { 6 | console.log(name, age) 7 | return family 8 | } -------------------------------------------------------------------------------- /test/arrow-function_type_test_issue_38/input.ts: -------------------------------------------------------------------------------- 1 | 2 | let defaultHashSize = 0 3 | export const getHashPlaceholderGenerator = (): any => { 4 | let nextIndex = 0; 5 | return (optionName: string, hashSize: number = defaultHashSize) => {} 6 | } 7 | -------------------------------------------------------------------------------- /test/object_get_and_set_with_this/input.ts: -------------------------------------------------------------------------------- 1 | const test = { 2 | privateName: 'tyreal', 3 | get name(this) { 4 | return this.privateName 5 | }, 6 | set name(this, _name) { 7 | this.privateName = _name 8 | } 9 | } -------------------------------------------------------------------------------- /test/object_get_and_set_without_this/input.ts: -------------------------------------------------------------------------------- 1 | const test = { 2 | privateName: 'tyreal', 3 | get name() { 4 | return this.privateName 5 | }, 6 | set name(_name: string) { 7 | this.privateName = _name 8 | } 9 | } -------------------------------------------------------------------------------- /test/decorators_class_property/input.ts: -------------------------------------------------------------------------------- 1 | function format(target: string) { 2 | return target 3 | } 4 | class ExampleClass { 5 | @format('Hello, %s') 6 | title: string 7 | constructor(t: string) { 8 | this.title = t; 9 | } 10 | } -------------------------------------------------------------------------------- /test/class_issue_42/input.ts: -------------------------------------------------------------------------------- 1 | 2 | export class ObjectEntity extends ExpressionEntity { 3 | constructor( 4 | properties: ObjectProperty[] | PropertyMap, 5 | private prototypeExpression: ExpressionEntity | null, 6 | private immutable = false 7 | ) {} 8 | } 9 | -------------------------------------------------------------------------------- /test/expression_type_test_extend_interface/input.ts: -------------------------------------------------------------------------------- 1 | interface Person { 2 | name: string 3 | age: number 4 | } 5 | 6 | interface Student extends Person { 7 | family: string[] 8 | interest: { 9 | artificialIntelligence: string 10 | study: string 11 | } 12 | } -------------------------------------------------------------------------------- /test/function_type_test_no_parameter_with_interface/input.ts: -------------------------------------------------------------------------------- 1 | interface Student { 2 | name: string 3 | age: number 4 | school: string 5 | } 6 | function test(): Student { 7 | return { 8 | name: 'tyreal', 9 | age: 22, 10 | school: 'gdut', 11 | } 12 | } -------------------------------------------------------------------------------- /test/class_normal_property/input.ts: -------------------------------------------------------------------------------- 1 | class Student { 2 | name: string 3 | age: number 4 | school: string 5 | constructor(name: string, age: number, school: string) { 6 | this.name = name 7 | this.age = age 8 | this.school = school 9 | } 10 | study() { 11 | console.log('Im studying') 12 | } 13 | } -------------------------------------------------------------------------------- /test/decorators_class_method/input.ts: -------------------------------------------------------------------------------- 1 | function first() { 2 | console.log("first(): factory evaluated"); 3 | return function (target: any, propertyKey: string, descriptor: PropertyDescriptor) { 4 | console.log("first(): called"); 5 | }; 6 | } 7 | class ExampleClass { 8 | @first() 9 | method() {} 10 | } -------------------------------------------------------------------------------- /test/class_private_property/input.ts: -------------------------------------------------------------------------------- 1 | class Student { 2 | private name: string 3 | private age: number 4 | private school: string 5 | constructor(name: string, age: number, school: string) { 6 | this.name = name 7 | this.age = age 8 | this.school = school 9 | } 10 | study() { 11 | console.log('Im studying') 12 | } 13 | } -------------------------------------------------------------------------------- /test/class_public_property/input.ts: -------------------------------------------------------------------------------- 1 | class Student { 2 | public name: string 3 | public age: number 4 | public school: string 5 | constructor(name: string, age: number, school: string) { 6 | this.name = name 7 | this.age = age 8 | this.school = school 9 | } 10 | study() { 11 | console.log('Im studying') 12 | } 13 | } -------------------------------------------------------------------------------- /test/class_readonly_property/input.ts: -------------------------------------------------------------------------------- 1 | class Student { 2 | readonly name: string 3 | readonly age: number 4 | readonly school: string 5 | constructor(name: string, age: number, school: string) { 6 | this.name = name 7 | this.age = age 8 | this.school = school 9 | } 10 | study() { 11 | console.log('Im studying') 12 | } 13 | } -------------------------------------------------------------------------------- /index.d.ts: -------------------------------------------------------------------------------- 1 | import { Parser } from 'acorn'; 2 | 3 | export function tsPlugin(options?: { 4 | dts?: boolean; 5 | /** Whether to use JSX. Defaults to false */ 6 | jsx?: 7 | | boolean 8 | | { 9 | allowNamespaces?: boolean; 10 | allowNamespacedObjects?: boolean; 11 | }; 12 | }): (BaseParser: typeof Parser) => typeof Parser; 13 | -------------------------------------------------------------------------------- /test/class_protected_property/input.ts: -------------------------------------------------------------------------------- 1 | class Student { 2 | protected name: string 3 | protected age: number 4 | protected school: string 5 | constructor(name: string, age: number, school: string) { 6 | this.name = name 7 | this.age = age 8 | this.school = school 9 | } 10 | study() { 11 | console.log('Im studying') 12 | } 13 | } -------------------------------------------------------------------------------- /test/decorators_class/input.ts: -------------------------------------------------------------------------------- 1 | function reportableClassDecorator(constructor: T) { 2 | return class extends constructor { 3 | reportingURL = "http://www..."; 4 | }; 5 | } 6 | @reportableClassDecorator 7 | class ExampleClass { 8 | title: string 9 | constructor(t: string) { 10 | this.title = t; 11 | } 12 | } -------------------------------------------------------------------------------- /.changeset/config.json: -------------------------------------------------------------------------------- 1 | { 2 | "$schema": "https://unpkg.com/@changesets/config@3.1.1/schema.json", 3 | "changelog": [ 4 | "@svitejs/changesets-changelog-github-compact", 5 | { "repo": "sveltejs/acorn-typescript" } 6 | ], 7 | "commit": false, 8 | "fixed": [], 9 | "linked": [], 10 | "access": "public", 11 | "baseBranch": "main", 12 | "updateInternalDependencies": "patch", 13 | "ignore": [] 14 | } 15 | -------------------------------------------------------------------------------- /test/decorators_class_accessor/input.ts: -------------------------------------------------------------------------------- 1 | function configurable(value: Boolean) { 2 | return function (target: any, propertyKey: string, descriptor: PropertyDescriptor) { 3 | descriptor.configurable = value; 4 | }; 5 | } 6 | class ExampleClass { 7 | title: string 8 | constructor(t: string) { 9 | this.title = t; 10 | } 11 | @configurable(false) 12 | get x() { 13 | return this.title; 14 | } 15 | } -------------------------------------------------------------------------------- /test/class_issue_44/input.ts: -------------------------------------------------------------------------------- 1 | 2 | class Test { 3 | parseNode(esTreeNode: GenericEsTreeNode): void { 4 | const { param } = esTreeNode; 5 | if (param) { 6 | (this.param as GenericEsTreeNode) = new (this.context.getNodeConstructor(param.type))( 7 | param, this,this.scope 8 | ); 9 | this.param!.declare('parameter', UNKNOWN_EXPRESSION); 10 | } 11 | super.parseNode(esTreeNode); 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /test/expression_type_test_declare_namespace/input.ts: -------------------------------------------------------------------------------- 1 | declare namespace myLib { 2 | let timeout: number; 3 | const version: string; 4 | class Cat { 5 | constructor(n: number); 6 | readonly age: number; 7 | purr(): void; 8 | } 9 | interface CatSettings { 10 | weight: number; 11 | name: string; 12 | tailLength?: number; 13 | } 14 | type VetID = string | number; 15 | function checkCat(c: Cat, s?: VetID); 16 | } -------------------------------------------------------------------------------- /playground/index.js: -------------------------------------------------------------------------------- 1 | import * as fs from 'fs'; 2 | import * as acorn from 'acorn'; 3 | import { tsPlugin } from '../index.js'; 4 | 5 | const parser = acorn.Parser.extend(tsPlugin()); 6 | 7 | const content = fs.readFileSync('playground/input.ts', 'utf8'); 8 | const output = parser.parse(content, { 9 | sourceType: 'module', 10 | ecmaVersion: 'latest', 11 | locations: true 12 | }); 13 | 14 | fs.writeFileSync('playground/output.json', JSON.stringify(output, null, 4)); 15 | -------------------------------------------------------------------------------- /test/class_abstract_class/input.ts: -------------------------------------------------------------------------------- 1 | abstract class Person { 2 | name: string; 3 | constructor(name: string) { 4 | this.name = name; 5 | } 6 | display(): void{ 7 | console.log(this.name); 8 | } 9 | abstract find(string): Person; 10 | } 11 | class Employee extends Person { 12 | empCode: number; 13 | constructor(name: string, code: number) { 14 | super(name); 15 | this.empCode = code; 16 | } 17 | find(name:string): Person { 18 | return new Employee(name, 1); 19 | } 20 | } -------------------------------------------------------------------------------- /test/dts_expression_type_test_issue_29/input.ts: -------------------------------------------------------------------------------- 1 | import type { ReactNode, Ref } from "react"; 2 | import type { CommonProps } from "./types"; 3 | export type SlideApi = { 4 | goToNextSlide: () => void; 5 | goToPreviousSlide: () => void; 6 | }; 7 | export type SlideProps = CommonProps & { 8 | children: ReactNode; 9 | defaultSlide?: number; 10 | onSlideChange?: (slide: number) => void; 11 | ref?: Ref; 12 | }; 13 | declare function SlideProps(props: SlideProps): JSX.Element; 14 | export default SlideProps; -------------------------------------------------------------------------------- /.changeset/README.md: -------------------------------------------------------------------------------- 1 | # Changesets 2 | 3 | Hello and welcome! This folder has been automatically generated by `@changesets/cli`, a build tool that works 4 | with multi-package repos, or single-package repos to help you version and publish your code. You can 5 | find the full documentation for it [in our repository](https://github.com/changesets/changesets) 6 | 7 | We have a quick list of common questions to get you started engaging with this project in 8 | [our documentation](https://github.com/changesets/changesets/blob/main/docs/common-questions.md) 9 | -------------------------------------------------------------------------------- /test/class_issue_33/input.ts: -------------------------------------------------------------------------------- 1 | 2 | export default class Bundle { 3 | private readonly facadeChunkByModule = new Map(); 4 | private readonly includedNamespaces = new Set(); 5 | 6 | constructor( 7 | private readonly outputOptions: NormalizedOutputOptions, 8 | private readonly unsetOptions: ReadonlySet, 9 | private readonly inputOptions: NormalizedInputOptions, 10 | private readonly pluginDriver: PluginDriver, 11 | private readonly graph: Graph 12 | ) {} 13 | } 14 | -------------------------------------------------------------------------------- /tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "allowJs": false, 4 | "target": "es6", 5 | "allowSyntheticDefaultImports": true, 6 | "moduleResolution": "node", 7 | "outDir": "lib", 8 | "experimentalDecorators": true, 9 | "lib": ["es2017", "dom"], 10 | "noUnusedLocals": true, 11 | "noUnusedParameters": true, 12 | "preserveConstEnums": true, 13 | "removeComments": false, 14 | "sourceMap": true, 15 | "strict": false, 16 | "skipLibCheck": true 17 | }, 18 | "include": ["./src/**/*", "./test/**/*"], 19 | "exclude": ["./test/*/input.ts"] 20 | } 21 | -------------------------------------------------------------------------------- /test/parseExpressionAt.test.ts: -------------------------------------------------------------------------------- 1 | import { describe, it, expect } from 'vitest'; 2 | import { generateSource, Parser } from './utils'; 3 | 4 | function parseExpressionAt(input: string, pos: number) { 5 | return Parser.parseExpressionAt(input, pos, { 6 | sourceType: 'module', 7 | ecmaVersion: 'latest', 8 | locations: true 9 | }); 10 | } 11 | 12 | describe('parseExpressionAt API', () => { 13 | it('normal', () => { 14 | const node = parseExpressionAt(generateSource([` {}`, `} />`]), 14); 15 | 16 | expect(node.type).toEqual('ArrowFunctionExpression'); 17 | }); 18 | }); 19 | -------------------------------------------------------------------------------- /test/jsx_issue_29_jsx/input.ts: -------------------------------------------------------------------------------- 1 | import React, { forwardRef } from "react"; 2 | import PropTypes from "prop-types"; 3 | const CustomButton = forwardRef( 4 | ( 5 | { 6 | iconStart, 7 | iconEnd, 8 | text 9 | }, 10 | ref 11 | ) => { 12 | return ( 13 | 18 | ); 19 | } 20 | ); 21 | CustomButton.displayName = "CustomButton"; 22 | CustomButton.propTypes = { 23 | text: PropTypes.string, 24 | iconStart: PropTypes.element, 25 | iconEnd: PropTypes.element, 26 | }; 27 | export default CustomButton; -------------------------------------------------------------------------------- /test/jsx_tsx/input.ts: -------------------------------------------------------------------------------- 1 | import * as React from "react"; 2 | import UserInterface from '../UserInterface' 3 | export default class UserComponent extends React.Component { 4 | constructor (props: UserInterface){ 5 | super(props); 6 | } 7 | render() { 8 | return ( 9 |
10 | >User Component 11 | Hello, {this.props.name} 12 |
13 | You are {this.props.age} years old 14 |
15 | You live at: {this.props.address} 16 |
17 | You were born: {this.props.dob.toDateString()} 18 |
19 | ); 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /test/export_type_star/expected.json: -------------------------------------------------------------------------------- 1 | { 2 | "body": [ 3 | { 4 | "end": 27, 5 | "exportKind": "type", 6 | "exported": null, 7 | "loc": { 8 | "end": { 9 | "column": 27, 10 | "line": 1 11 | }, 12 | "start": { 13 | "column": 0, 14 | "line": 1 15 | } 16 | }, 17 | "source": { 18 | "end": 26, 19 | "loc": { 20 | "end": { 21 | "column": 26, 22 | "line": 1 23 | }, 24 | "start": { 25 | "column": 19, 26 | "line": 1 27 | } 28 | }, 29 | "raw": "'./foo'", 30 | "start": 19, 31 | "type": "Literal", 32 | "value": "./foo" 33 | }, 34 | "start": 0, 35 | "type": "ExportAllDeclaration" 36 | } 37 | ], 38 | "end": 27, 39 | "loc": { 40 | "end": { 41 | "column": 27, 42 | "line": 1 43 | }, 44 | "start": { 45 | "column": 0, 46 | "line": 1 47 | } 48 | }, 49 | "sourceType": "module", 50 | "start": 0, 51 | "type": "Program" 52 | } 53 | -------------------------------------------------------------------------------- /test/normal_syntax_import_without_specifiers/expected.json: -------------------------------------------------------------------------------- 1 | { 2 | "type": "Program", 3 | "start": 0, 4 | "end": 19, 5 | "loc": { 6 | "start": { 7 | "line": 1, 8 | "column": 0 9 | }, 10 | "end": { 11 | "line": 1, 12 | "column": 19 13 | } 14 | }, 15 | "body": [ 16 | { 17 | "type": "ImportDeclaration", 18 | "start": 0, 19 | "end": 19, 20 | "loc": { 21 | "start": { 22 | "line": 1, 23 | "column": 0 24 | }, 25 | "end": { 26 | "line": 1, 27 | "column": 19 28 | } 29 | }, 30 | "importKind": "value", 31 | "specifiers": [], 32 | "source": { 33 | "type": "Literal", 34 | "start": 7, 35 | "end": 19, 36 | "loc": { 37 | "start": { 38 | "line": 1, 39 | "column": 7 40 | }, 41 | "end": { 42 | "line": 1, 43 | "column": 19 44 | } 45 | }, 46 | "value": "./index.js", 47 | "raw": "'./index.js'" 48 | } 49 | } 50 | ], 51 | "sourceType": "module" 52 | } 53 | -------------------------------------------------------------------------------- /src/whitespace.ts: -------------------------------------------------------------------------------- 1 | export const skipWhiteSpaceInLine = /(?:[^\S\n\r\u2028\u2029]|\/\/.*|\/\*.*?\*\/)*/y; 2 | 3 | // Skip whitespace and single-line comments, including /* no newline here */. 4 | // After this RegExp matches, its lastIndex points to a line terminator, or 5 | // the start of multi-line comment (which is effectively a line terminator), 6 | // or the end of string. 7 | export const skipWhiteSpaceToLineBreak = new RegExp( 8 | // Unfortunately JS doesn't support Perl's atomic /(?>pattern)/ or 9 | // possessive quantifiers, so we use a trick to prevent backtracking 10 | // when the look-ahead for line terminator fails. 11 | '(?=(' + 12 | // Capture the whitespace and comments that should be skipped inside 13 | // a look-ahead assertion, and then re-match the group as a unit. 14 | skipWhiteSpaceInLine.source + 15 | '))\\1' + 16 | // Look-ahead for either line terminator, start of multi-line comment, 17 | // or end of string. 18 | /(?=[\n\r\u2028\u2029]|\/\*(?!.*?\*\/)|$)/.source, 19 | 'y' // sticky 20 | ); 21 | -------------------------------------------------------------------------------- /test/class_issue_34/input.ts: -------------------------------------------------------------------------------- 1 | 2 | export default class Graph { 3 | readonly acornParser: typeof acorn.Parser; 4 | readonly cachedModules = new Map(); 5 | readonly deoptimizationTracker = new PathTracker(); 6 | entryModules: Module[] = []; 7 | readonly fileOperationQueue: Queue; 8 | readonly moduleLoader: ModuleLoader; 9 | readonly modulesById = new Map(); 10 | needsTreeshakingPass = false; 11 | phase: BuildPhase = BuildPhase.LOAD_AND_PARSE; 12 | readonly pluginDriver: PluginDriver; 13 | readonly pureFunctions: PureFunctions; 14 | readonly scope = new GlobalScope(); 15 | readonly watchFiles: Record = Object.create(null); 16 | watchMode = false; 17 | 18 | private readonly externalModules: ExternalModule[] = []; 19 | private implicitEntryModules: Module[] = []; 20 | private modules: Module[] = []; 21 | private declare pluginCache?: Record; 22 | } 23 | -------------------------------------------------------------------------------- /.github/workflows/ci.yml: -------------------------------------------------------------------------------- 1 | name: CI 2 | 3 | on: 4 | push: 5 | branches: 6 | - main 7 | pull_request: 8 | branches: 9 | - main 10 | 11 | jobs: 12 | test: 13 | runs-on: ${{ matrix.os }} 14 | 15 | strategy: 16 | matrix: 17 | node-version: [20.x, 22.x] 18 | os: [ubuntu-latest] 19 | 20 | steps: 21 | - uses: actions/checkout@v4 22 | - uses: pnpm/action-setup@v4.1.0 23 | - name: Use Node.js ${{ matrix.node-version }} 24 | uses: actions/setup-node@v4 25 | with: 26 | node-version: ${{ matrix.node-version }} 27 | cache: pnpm 28 | - run: pnpm install --frozen-lockfile 29 | - run: pnpm build 30 | - run: pnpm test 31 | - run: pnpm test:test262 32 | 33 | lint: 34 | runs-on: ubuntu-latest 35 | steps: 36 | - uses: actions/checkout@v4 37 | - uses: pnpm/action-setup@v4.1.0 38 | - uses: actions/setup-node@v4 39 | with: 40 | node-version: 22 41 | cache: pnpm 42 | - run: pnpm install --frozen-lockfile 43 | - run: pnpm check 44 | - run: pnpm lint 45 | -------------------------------------------------------------------------------- /LICENSE.md: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2022 Tyreal Hu 4 | Copyright (c) 2025 The Svelte Team 5 | 6 | Permission is hereby granted, free of charge, to any person obtaining a copy 7 | of this software and associated documentation files (the "Software"), to deal 8 | in the Software without restriction, including without limitation the rights 9 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | copies of the Software, and to permit persons to whom the Software is 11 | furnished to do so, subject to the following conditions: 12 | 13 | The above copyright notice and this permission notice shall be included in all 14 | copies or substantial portions of the Software. 15 | 16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | SOFTWARE. 23 | -------------------------------------------------------------------------------- /test/class_issue_36/input.ts: -------------------------------------------------------------------------------- 1 | 2 | const getIdMatcher = >( 3 | option: 4 | | undefined 5 | | boolean 6 | | string 7 | | RegExp 8 | | (string | RegExp)[] 9 | | ((id: string, ...parameters: T) => boolean | null | void) 10 | ): ((id: string, ...parameters: T) => boolean) => { 11 | if (option === true) { 12 | return () => true; 13 | } 14 | if (typeof option === 'function') { 15 | return (id, ...parameters) => (!id.startsWith('\0') && option(id, ...parameters)) || false; 16 | } 17 | if (option) { 18 | const ids = new Set(); 19 | const matchers: RegExp[] = []; 20 | for (const value of ensureArray(option)) { 21 | if (value instanceof RegExp) { 22 | matchers.push(value); 23 | } else { 24 | ids.add(value); 25 | } 26 | } 27 | return (id: string, ..._arguments) => ids.has(id) || matchers.some(matcher => matcher.test(id)); 28 | } 29 | return () => false; 30 | }; 31 | -------------------------------------------------------------------------------- /test/normal_export_export_default_anonymous_class/expected.json: -------------------------------------------------------------------------------- 1 | { 2 | "type": "Program", 3 | "start": 0, 4 | "end": 23, 5 | "loc": { 6 | "start": { 7 | "line": 1, 8 | "column": 0 9 | }, 10 | "end": { 11 | "line": 1, 12 | "column": 23 13 | } 14 | }, 15 | "body": [ 16 | { 17 | "type": "ExportDefaultDeclaration", 18 | "start": 0, 19 | "end": 23, 20 | "loc": { 21 | "start": { 22 | "line": 1, 23 | "column": 0 24 | }, 25 | "end": { 26 | "line": 1, 27 | "column": 23 28 | } 29 | }, 30 | "exportKind": "value", 31 | "declaration": { 32 | "type": "ClassDeclaration", 33 | "start": 15, 34 | "end": 23, 35 | "loc": { 36 | "start": { 37 | "line": 1, 38 | "column": 15 39 | }, 40 | "end": { 41 | "line": 1, 42 | "column": 23 43 | } 44 | }, 45 | "id": null, 46 | "superClass": null, 47 | "body": { 48 | "type": "ClassBody", 49 | "start": 21, 50 | "end": 23, 51 | "loc": { 52 | "start": { 53 | "line": 1, 54 | "column": 21 55 | }, 56 | "end": { 57 | "line": 1, 58 | "column": 23 59 | } 60 | }, 61 | "body": [] 62 | } 63 | } 64 | } 65 | ], 66 | "sourceType": "module" 67 | } 68 | -------------------------------------------------------------------------------- /src/parseutil.ts: -------------------------------------------------------------------------------- 1 | export class DestructuringErrors { 2 | public shorthandAssign: number; 3 | public trailingComma: number; 4 | public parenthesizedAssign: number; 5 | public parenthesizedBind: number; 6 | public doubleProto: number; 7 | 8 | constructor() { 9 | this.shorthandAssign = 10 | this.trailingComma = 11 | this.parenthesizedAssign = 12 | this.parenthesizedBind = 13 | this.doubleProto = 14 | -1; 15 | } 16 | } 17 | 18 | export function isPrivateNameConflicted(privateNameMap, element) { 19 | const name = element.key.name; 20 | const curr = privateNameMap[name]; 21 | 22 | let next = 'true'; 23 | if (element.type === 'MethodDefinition' && (element.kind === 'get' || element.kind === 'set')) { 24 | next = (element.static ? 's' : 'i') + element.kind; 25 | } 26 | 27 | // `class { get #a(){}; static set #a(_){} }` is also conflict. 28 | if ( 29 | (curr === 'iget' && next === 'iset') || 30 | (curr === 'iset' && next === 'iget') || 31 | (curr === 'sget' && next === 'sset') || 32 | (curr === 'sset' && next === 'sget') 33 | ) { 34 | privateNameMap[name] = 'true'; 35 | return false; 36 | } else if (!curr) { 37 | privateNameMap[name] = next; 38 | return false; 39 | } else { 40 | return true; 41 | } 42 | } 43 | 44 | export function checkKeyName(node, name) { 45 | const { computed, key } = node; 46 | return ( 47 | !computed && 48 | ((key.type === 'Identifier' && key.name === name) || 49 | (key.type === 'Literal' && key.value === name)) 50 | ); 51 | } 52 | -------------------------------------------------------------------------------- /test/jsx_simple/expected.json: -------------------------------------------------------------------------------- 1 | { 2 | "type": "Program", 3 | "start": 0, 4 | "end": 7, 5 | "loc": { 6 | "start": { 7 | "line": 1, 8 | "column": 0 9 | }, 10 | "end": { 11 | "line": 1, 12 | "column": 7 13 | } 14 | }, 15 | "body": [ 16 | { 17 | "type": "ExpressionStatement", 18 | "start": 0, 19 | "end": 7, 20 | "loc": { 21 | "start": { 22 | "line": 1, 23 | "column": 0 24 | }, 25 | "end": { 26 | "line": 1, 27 | "column": 7 28 | } 29 | }, 30 | "expression": { 31 | "type": "JSXElement", 32 | "start": 0, 33 | "end": 7, 34 | "loc": { 35 | "start": { 36 | "line": 1, 37 | "column": 0 38 | }, 39 | "end": { 40 | "line": 1, 41 | "column": 7 42 | } 43 | }, 44 | "openingElement": { 45 | "type": "JSXOpeningElement", 46 | "start": 0, 47 | "end": 7, 48 | "loc": { 49 | "start": { 50 | "line": 1, 51 | "column": 0 52 | }, 53 | "end": { 54 | "line": 1, 55 | "column": 7 56 | } 57 | }, 58 | "name": { 59 | "type": "JSXIdentifier", 60 | "start": 1, 61 | "end": 4, 62 | "loc": { 63 | "start": { 64 | "line": 1, 65 | "column": 1 66 | }, 67 | "end": { 68 | "line": 1, 69 | "column": 4 70 | } 71 | }, 72 | "name": "div" 73 | }, 74 | "attributes": [], 75 | "selfClosing": true 76 | }, 77 | "closingElement": null, 78 | "children": [] 79 | } 80 | } 81 | ], 82 | "sourceType": "module" 83 | } 84 | -------------------------------------------------------------------------------- /test/normal_syntax_issue_45/expected.json: -------------------------------------------------------------------------------- 1 | { 2 | "type": "Program", 3 | "start": 0, 4 | "end": 31, 5 | "loc": { 6 | "start": { 7 | "line": 1, 8 | "column": 0 9 | }, 10 | "end": { 11 | "line": 1, 12 | "column": 31 13 | } 14 | }, 15 | "body": [ 16 | { 17 | "type": "ImportDeclaration", 18 | "start": 0, 19 | "end": 31, 20 | "loc": { 21 | "start": { 22 | "line": 1, 23 | "column": 0 24 | }, 25 | "end": { 26 | "line": 1, 27 | "column": 31 28 | } 29 | }, 30 | "importKind": "value", 31 | "specifiers": [ 32 | { 33 | "type": "ImportDefaultSpecifier", 34 | "start": 7, 35 | "end": 13, 36 | "loc": { 37 | "start": { 38 | "line": 1, 39 | "column": 7 40 | }, 41 | "end": { 42 | "line": 1, 43 | "column": 13 44 | } 45 | }, 46 | "local": { 47 | "type": "Identifier", 48 | "start": 7, 49 | "end": 13, 50 | "loc": { 51 | "start": { 52 | "line": 1, 53 | "column": 7 54 | }, 55 | "end": { 56 | "line": 1, 57 | "column": 13 58 | } 59 | }, 60 | "name": "assert" 61 | } 62 | } 63 | ], 64 | "source": { 65 | "type": "Literal", 66 | "start": 19, 67 | "end": 31, 68 | "loc": { 69 | "start": { 70 | "line": 1, 71 | "column": 19 72 | }, 73 | "end": { 74 | "line": 1, 75 | "column": 31 76 | } 77 | }, 78 | "value": "./index.js", 79 | "raw": "'./index.js'" 80 | } 81 | } 82 | ], 83 | "sourceType": "module" 84 | } 85 | -------------------------------------------------------------------------------- /test/utils.ts: -------------------------------------------------------------------------------- 1 | import { assert } from 'vitest'; 2 | import * as acorn from 'acorn'; 3 | import { tsPlugin } from '../src'; 4 | 5 | export const Parser = acorn.Parser.extend(tsPlugin() as any); 6 | 7 | export const DtsParser = acorn.Parser.extend( 8 | tsPlugin({ 9 | dts: true 10 | }) as any 11 | ); 12 | 13 | export const JsxParser = acorn.Parser.extend( 14 | tsPlugin({ 15 | jsx: true 16 | }) as any 17 | ); 18 | 19 | export function equalNode(node, snapshot) { 20 | assert.deepEqual(JSON.parse(JSON.stringify(node)), snapshot, 'should be' + JSON.stringify(node)); 21 | } 22 | 23 | export function parseDtsSource(input: string) { 24 | return DtsParser.parse(input, { 25 | sourceType: 'module', 26 | ecmaVersion: 'latest', 27 | locations: true 28 | }); 29 | } 30 | 31 | export function parseJsxSource(input: string) { 32 | return JsxParser.parse(input, { 33 | sourceType: 'module', 34 | ecmaVersion: 'latest', 35 | locations: true 36 | }); 37 | } 38 | 39 | export function parseSource(input: string) { 40 | return Parser.parse(input, { 41 | sourceType: 'module', 42 | ecmaVersion: 'latest', 43 | locations: true 44 | }); 45 | } 46 | 47 | export function parseSourceShouldThrowError(input: string, message?: string) { 48 | try { 49 | Parser.parse(input, { 50 | sourceType: 'module', 51 | ecmaVersion: 'latest', 52 | locations: true 53 | }); 54 | 55 | assert.fail('should throw an error'); 56 | } catch (e) { 57 | if (message) { 58 | assert.equal(e.message, message); 59 | } 60 | } 61 | } 62 | 63 | export function generateSource(input: string[]): string { 64 | return input.join('\n'); 65 | } 66 | -------------------------------------------------------------------------------- /test/normal_syntax_import_default_specifiers/expected.json: -------------------------------------------------------------------------------- 1 | { 2 | "type": "Program", 3 | "start": 0, 4 | "end": 29, 5 | "loc": { 6 | "start": { 7 | "line": 1, 8 | "column": 0 9 | }, 10 | "end": { 11 | "line": 1, 12 | "column": 29 13 | } 14 | }, 15 | "body": [ 16 | { 17 | "type": "ImportDeclaration", 18 | "start": 0, 19 | "end": 29, 20 | "loc": { 21 | "start": { 22 | "line": 1, 23 | "column": 0 24 | }, 25 | "end": { 26 | "line": 1, 27 | "column": 29 28 | } 29 | }, 30 | "importKind": "value", 31 | "specifiers": [ 32 | { 33 | "type": "ImportDefaultSpecifier", 34 | "start": 7, 35 | "end": 11, 36 | "loc": { 37 | "start": { 38 | "line": 1, 39 | "column": 7 40 | }, 41 | "end": { 42 | "line": 1, 43 | "column": 11 44 | } 45 | }, 46 | "local": { 47 | "type": "Identifier", 48 | "start": 7, 49 | "end": 11, 50 | "loc": { 51 | "start": { 52 | "line": 1, 53 | "column": 7 54 | }, 55 | "end": { 56 | "line": 1, 57 | "column": 11 58 | } 59 | }, 60 | "name": "test" 61 | } 62 | } 63 | ], 64 | "source": { 65 | "type": "Literal", 66 | "start": 17, 67 | "end": 29, 68 | "loc": { 69 | "start": { 70 | "line": 1, 71 | "column": 17 72 | }, 73 | "end": { 74 | "line": 1, 75 | "column": 29 76 | } 77 | }, 78 | "value": "./index.js", 79 | "raw": "'./index.js'" 80 | } 81 | } 82 | ], 83 | "sourceType": "module" 84 | } 85 | -------------------------------------------------------------------------------- /test/normal_syntax_import_namespace_specifiers/expected.json: -------------------------------------------------------------------------------- 1 | { 2 | "type": "Program", 3 | "start": 0, 4 | "end": 34, 5 | "loc": { 6 | "start": { 7 | "line": 1, 8 | "column": 0 9 | }, 10 | "end": { 11 | "line": 1, 12 | "column": 34 13 | } 14 | }, 15 | "body": [ 16 | { 17 | "type": "ImportDeclaration", 18 | "start": 0, 19 | "end": 34, 20 | "loc": { 21 | "start": { 22 | "line": 1, 23 | "column": 0 24 | }, 25 | "end": { 26 | "line": 1, 27 | "column": 34 28 | } 29 | }, 30 | "importKind": "value", 31 | "specifiers": [ 32 | { 33 | "type": "ImportNamespaceSpecifier", 34 | "start": 7, 35 | "end": 16, 36 | "loc": { 37 | "start": { 38 | "line": 1, 39 | "column": 7 40 | }, 41 | "end": { 42 | "line": 1, 43 | "column": 16 44 | } 45 | }, 46 | "local": { 47 | "type": "Identifier", 48 | "start": 12, 49 | "end": 16, 50 | "loc": { 51 | "start": { 52 | "line": 1, 53 | "column": 12 54 | }, 55 | "end": { 56 | "line": 1, 57 | "column": 16 58 | } 59 | }, 60 | "name": "test" 61 | } 62 | } 63 | ], 64 | "source": { 65 | "type": "Literal", 66 | "start": 22, 67 | "end": 34, 68 | "loc": { 69 | "start": { 70 | "line": 1, 71 | "column": 22 72 | }, 73 | "end": { 74 | "line": 1, 75 | "column": 34 76 | } 77 | }, 78 | "value": "./index.js", 79 | "raw": "'./index.js'" 80 | } 81 | } 82 | ], 83 | "sourceType": "module" 84 | } 85 | -------------------------------------------------------------------------------- /test/type_syntax_import_default_specifiers_with_type_token/expected.json: -------------------------------------------------------------------------------- 1 | { 2 | "type": "Program", 3 | "start": 0, 4 | "end": 34, 5 | "loc": { 6 | "start": { 7 | "line": 1, 8 | "column": 0 9 | }, 10 | "end": { 11 | "line": 1, 12 | "column": 34 13 | } 14 | }, 15 | "body": [ 16 | { 17 | "type": "ImportDeclaration", 18 | "start": 0, 19 | "end": 34, 20 | "loc": { 21 | "start": { 22 | "line": 1, 23 | "column": 0 24 | }, 25 | "end": { 26 | "line": 1, 27 | "column": 34 28 | } 29 | }, 30 | "importKind": "type", 31 | "specifiers": [ 32 | { 33 | "type": "ImportDefaultSpecifier", 34 | "start": 12, 35 | "end": 16, 36 | "loc": { 37 | "start": { 38 | "line": 1, 39 | "column": 12 40 | }, 41 | "end": { 42 | "line": 1, 43 | "column": 16 44 | } 45 | }, 46 | "local": { 47 | "type": "Identifier", 48 | "start": 12, 49 | "end": 16, 50 | "loc": { 51 | "start": { 52 | "line": 1, 53 | "column": 12 54 | }, 55 | "end": { 56 | "line": 1, 57 | "column": 16 58 | } 59 | }, 60 | "name": "Test" 61 | } 62 | } 63 | ], 64 | "source": { 65 | "type": "Literal", 66 | "start": 22, 67 | "end": 34, 68 | "loc": { 69 | "start": { 70 | "line": 1, 71 | "column": 22 72 | }, 73 | "end": { 74 | "line": 1, 75 | "column": 34 76 | } 77 | }, 78 | "value": "./index.ts", 79 | "raw": "'./index.ts'" 80 | } 81 | } 82 | ], 83 | "sourceType": "module" 84 | } 85 | -------------------------------------------------------------------------------- /test/type_syntax_import_namespace_specifiers_with_type_token/expected.json: -------------------------------------------------------------------------------- 1 | { 2 | "type": "Program", 3 | "start": 0, 4 | "end": 39, 5 | "loc": { 6 | "start": { 7 | "line": 1, 8 | "column": 0 9 | }, 10 | "end": { 11 | "line": 1, 12 | "column": 39 13 | } 14 | }, 15 | "body": [ 16 | { 17 | "type": "ImportDeclaration", 18 | "start": 0, 19 | "end": 39, 20 | "loc": { 21 | "start": { 22 | "line": 1, 23 | "column": 0 24 | }, 25 | "end": { 26 | "line": 1, 27 | "column": 39 28 | } 29 | }, 30 | "importKind": "type", 31 | "specifiers": [ 32 | { 33 | "type": "ImportNamespaceSpecifier", 34 | "start": 12, 35 | "end": 21, 36 | "loc": { 37 | "start": { 38 | "line": 1, 39 | "column": 12 40 | }, 41 | "end": { 42 | "line": 1, 43 | "column": 21 44 | } 45 | }, 46 | "local": { 47 | "type": "Identifier", 48 | "start": 17, 49 | "end": 21, 50 | "loc": { 51 | "start": { 52 | "line": 1, 53 | "column": 17 54 | }, 55 | "end": { 56 | "line": 1, 57 | "column": 21 58 | } 59 | }, 60 | "name": "Test" 61 | } 62 | } 63 | ], 64 | "source": { 65 | "type": "Literal", 66 | "start": 27, 67 | "end": 39, 68 | "loc": { 69 | "start": { 70 | "line": 1, 71 | "column": 27 72 | }, 73 | "end": { 74 | "line": 1, 75 | "column": 39 76 | } 77 | }, 78 | "value": "./index.ts", 79 | "raw": "'./index.ts'" 80 | } 81 | } 82 | ], 83 | "sourceType": "module" 84 | } 85 | -------------------------------------------------------------------------------- /test/class_issue_35/input.ts: -------------------------------------------------------------------------------- 1 | 2 | export class PluginDriver { 3 | public readonly emitFile: EmitFile; 4 | public finaliseAssets: () => void; 5 | public getFileName: (fileReferenceId: string) => string; 6 | public readonly setChunkInformation: (facadeChunkByModule: ReadonlyMap) => void; 7 | public readonly setOutputBundle: ( 8 | bundle: OutputBundleWithPlaceholders, 9 | outputOptions: NormalizedOutputOptions 10 | ) => void; 11 | 12 | private readonly fileEmitter: FileEmitter; 13 | private readonly pluginContexts: ReadonlyMap; 14 | private readonly plugins: readonly Plugin[]; 15 | private readonly sortedPlugins = new Map(); 16 | private readonly unfulfilledActions = new Set(); 17 | 18 | hookFirst( 19 | hookName: H, 20 | parameters: Parameters, 21 | replaceContext?: ReplaceContext | null, 22 | skipped?: ReadonlySet | null 23 | ): Promise | null> { 24 | let promise: Promise | null> = Promise.resolve(null); 25 | for (const plugin of this.getSortedPlugins(hookName)) { 26 | if (skipped && skipped.has(plugin)) continue; 27 | promise = promise.then(result => { 28 | if (result != null) return result; 29 | return this.runHook(hookName, parameters, plugin, replaceContext); 30 | }); 31 | } 32 | return promise; 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /.github/workflows/release.yml: -------------------------------------------------------------------------------- 1 | name: Release 2 | 3 | on: 4 | push: 5 | branches: 6 | - main 7 | 8 | permissions: {} 9 | jobs: 10 | release: 11 | # prevents this action from running on forks 12 | if: github.repository == 'sveltejs/acorn-typescript' 13 | permissions: 14 | contents: write # to create release (changesets/action) 15 | id-token: write # OpenID Connect token needed for provenance 16 | pull-requests: write # to create pull request (changesets/action) 17 | name: Release 18 | runs-on: ubuntu-latest 19 | steps: 20 | - name: Checkout Repo 21 | uses: actions/checkout@v4 22 | with: 23 | # This makes Actions fetch all Git history so that Changesets can generate changelogs with the correct commits 24 | fetch-depth: 0 25 | - uses: pnpm/action-setup@v4.1.0 26 | - name: Setup Node.js 27 | uses: actions/setup-node@v4 28 | with: 29 | node-version: 24.x 30 | cache: pnpm 31 | 32 | - run: pnpm install --frozen-lockfile 33 | 34 | - name: Create Release Pull Request or Publish to npm 35 | id: changesets 36 | uses: changesets/action@v1 37 | with: 38 | # This expects you to have a script called release which does a build for your packages and calls changeset publish 39 | publish: pnpm changeset:release 40 | version: pnpm changeset:version 41 | env: 42 | GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} 43 | NPM_CONFIG_PROVENANCE: true 44 | 45 | # TODO alert discord 46 | # - name: Send a Slack notification if a publish happens 47 | # if: steps.changesets.outputs.published == 'true' 48 | # # You can do something when a publish happens. 49 | # run: my-slack-bot send-notification --message "A new version of ${GITHUB_REPOSITORY} was published!" 50 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "@sveltejs/acorn-typescript", 3 | "version": "1.0.8", 4 | "description": "Acorn plugin that parses TypeScript", 5 | "type": "module", 6 | "types": "index.d.ts", 7 | "files": [ 8 | "index.js", 9 | "index.d.ts" 10 | ], 11 | "scripts": { 12 | "build": "esbuild src/index.ts --bundle --format=esm --outfile=index.js --platform=node --external:acorn", 13 | "format": "prettier --write .", 14 | "check": "tsc --noEmit", 15 | "lint": "prettier --check .", 16 | "test": "vitest run", 17 | "test:update": "cross-env UPDATE_SNAPSHOT=true vitest run && pnpm run format", 18 | "test:test262": "pnpm run build && node ./test/run_test262.js", 19 | "changeset:version": "changeset version && git add --all", 20 | "changeset:release": "changeset publish", 21 | "prepublishOnly": "pnpm build", 22 | "playground": "pnpm build && node ./playground/index.js" 23 | }, 24 | "exports": { 25 | ".": { 26 | "types": "./index.d.ts", 27 | "default": "./index.js" 28 | } 29 | }, 30 | "repository": { 31 | "type": "git", 32 | "url": "git+https://github.com/sveltejs/acorn-typescript.git" 33 | }, 34 | "author": "tyrealhu and the Svelte team", 35 | "license": "MIT", 36 | "bugs": { 37 | "url": "https://github.com/sveltejs/acorn-typescript/issues" 38 | }, 39 | "homepage": "https://github.com/sveltejs/acorn-typescript#readme", 40 | "devDependencies": { 41 | "@changesets/cli": "^2.27.11", 42 | "@svitejs/changesets-changelog-github-compact": "^1.1.0", 43 | "acorn": "^8.14.0", 44 | "acorn-jsx": "~5.3.2", 45 | "cross-env": "^7.0.3", 46 | "esbuild": "^0.25.0", 47 | "prettier": "~3.5.2", 48 | "test262": "git+https://github.com/tc39/test262.git#88ebb1e3755198cd08757bca1698effbbf360345", 49 | "test262-parser-runner": "^0.5.0", 50 | "typescript": "^5.7.3", 51 | "vitest": "^3.0.7" 52 | }, 53 | "peerDependencies": { 54 | "acorn": "^8.9.0" 55 | }, 56 | "packageManager": "pnpm@9.15.5" 57 | } 58 | -------------------------------------------------------------------------------- /test/normal_identifier_test_import_identifier_as/expected.json: -------------------------------------------------------------------------------- 1 | { 2 | "type": "Program", 3 | "start": 0, 4 | "end": 36, 5 | "loc": { 6 | "start": { 7 | "line": 1, 8 | "column": 0 9 | }, 10 | "end": { 11 | "line": 1, 12 | "column": 36 13 | } 14 | }, 15 | "body": [ 16 | { 17 | "type": "ImportDeclaration", 18 | "start": 0, 19 | "end": 36, 20 | "loc": { 21 | "start": { 22 | "line": 1, 23 | "column": 0 24 | }, 25 | "end": { 26 | "line": 1, 27 | "column": 36 28 | } 29 | }, 30 | "importKind": "value", 31 | "specifiers": [ 32 | { 33 | "type": "ImportSpecifier", 34 | "start": 9, 35 | "end": 17, 36 | "loc": { 37 | "start": { 38 | "line": 1, 39 | "column": 9 40 | }, 41 | "end": { 42 | "line": 1, 43 | "column": 17 44 | } 45 | }, 46 | "imported": { 47 | "type": "Identifier", 48 | "start": 9, 49 | "end": 11, 50 | "loc": { 51 | "start": { 52 | "line": 1, 53 | "column": 9 54 | }, 55 | "end": { 56 | "line": 1, 57 | "column": 11 58 | } 59 | }, 60 | "name": "as" 61 | }, 62 | "local": { 63 | "type": "Identifier", 64 | "start": 15, 65 | "end": 17, 66 | "loc": { 67 | "start": { 68 | "line": 1, 69 | "column": 15 70 | }, 71 | "end": { 72 | "line": 1, 73 | "column": 17 74 | } 75 | }, 76 | "name": "as" 77 | }, 78 | "importKind": "value" 79 | } 80 | ], 81 | "source": { 82 | "type": "Literal", 83 | "start": 25, 84 | "end": 35, 85 | "loc": { 86 | "start": { 87 | "line": 1, 88 | "column": 25 89 | }, 90 | "end": { 91 | "line": 1, 92 | "column": 35 93 | } 94 | }, 95 | "value": "./foo.js", 96 | "raw": "'./foo.js'" 97 | } 98 | } 99 | ], 100 | "sourceType": "module" 101 | } 102 | -------------------------------------------------------------------------------- /test/normal_syntax_import_name_as_specifiers/expected.json: -------------------------------------------------------------------------------- 1 | { 2 | "type": "Program", 3 | "start": 0, 4 | "end": 42, 5 | "loc": { 6 | "start": { 7 | "line": 1, 8 | "column": 0 9 | }, 10 | "end": { 11 | "line": 1, 12 | "column": 42 13 | } 14 | }, 15 | "body": [ 16 | { 17 | "type": "ImportDeclaration", 18 | "start": 0, 19 | "end": 42, 20 | "loc": { 21 | "start": { 22 | "line": 1, 23 | "column": 0 24 | }, 25 | "end": { 26 | "line": 1, 27 | "column": 42 28 | } 29 | }, 30 | "importKind": "value", 31 | "specifiers": [ 32 | { 33 | "type": "ImportSpecifier", 34 | "start": 9, 35 | "end": 22, 36 | "loc": { 37 | "start": { 38 | "line": 1, 39 | "column": 9 40 | }, 41 | "end": { 42 | "line": 1, 43 | "column": 22 44 | } 45 | }, 46 | "imported": { 47 | "type": "Identifier", 48 | "start": 9, 49 | "end": 13, 50 | "loc": { 51 | "start": { 52 | "line": 1, 53 | "column": 9 54 | }, 55 | "end": { 56 | "line": 1, 57 | "column": 13 58 | } 59 | }, 60 | "name": "test" 61 | }, 62 | "local": { 63 | "type": "Identifier", 64 | "start": 17, 65 | "end": 22, 66 | "loc": { 67 | "start": { 68 | "line": 1, 69 | "column": 17 70 | }, 71 | "end": { 72 | "line": 1, 73 | "column": 22 74 | } 75 | }, 76 | "name": "test1" 77 | }, 78 | "importKind": "value" 79 | } 80 | ], 81 | "source": { 82 | "type": "Literal", 83 | "start": 30, 84 | "end": 42, 85 | "loc": { 86 | "start": { 87 | "line": 1, 88 | "column": 30 89 | }, 90 | "end": { 91 | "line": 1, 92 | "column": 42 93 | } 94 | }, 95 | "value": "./index.js", 96 | "raw": "'./index.js'" 97 | } 98 | } 99 | ], 100 | "sourceType": "module" 101 | } 102 | -------------------------------------------------------------------------------- /test/normal_syntax_import_type_specifier_with_as_as/expected.json: -------------------------------------------------------------------------------- 1 | { 2 | "type": "Program", 3 | "start": 0, 4 | "end": 50, 5 | "loc": { 6 | "start": { 7 | "line": 1, 8 | "column": 0 9 | }, 10 | "end": { 11 | "line": 1, 12 | "column": 50 13 | } 14 | }, 15 | "body": [ 16 | { 17 | "type": "ImportDeclaration", 18 | "start": 0, 19 | "end": 50, 20 | "loc": { 21 | "start": { 22 | "line": 1, 23 | "column": 0 24 | }, 25 | "end": { 26 | "line": 1, 27 | "column": 50 28 | } 29 | }, 30 | "importKind": "value", 31 | "specifiers": [ 32 | { 33 | "type": "ImportSpecifier", 34 | "start": 9, 35 | "end": 30, 36 | "loc": { 37 | "start": { 38 | "line": 1, 39 | "column": 9 40 | }, 41 | "end": { 42 | "line": 1, 43 | "column": 30 44 | } 45 | }, 46 | "imported": { 47 | "type": "Identifier", 48 | "start": 14, 49 | "end": 16, 50 | "loc": { 51 | "start": { 52 | "line": 1, 53 | "column": 14 54 | }, 55 | "end": { 56 | "line": 1, 57 | "column": 16 58 | } 59 | }, 60 | "name": "as" 61 | }, 62 | "local": { 63 | "type": "Identifier", 64 | "start": 20, 65 | "end": 30, 66 | "loc": { 67 | "start": { 68 | "line": 1, 69 | "column": 20 70 | }, 71 | "end": { 72 | "line": 1, 73 | "column": 30 74 | } 75 | }, 76 | "name": "somethings" 77 | }, 78 | "importKind": "type" 79 | } 80 | ], 81 | "source": { 82 | "type": "Literal", 83 | "start": 38, 84 | "end": 50, 85 | "loc": { 86 | "start": { 87 | "line": 1, 88 | "column": 38 89 | }, 90 | "end": { 91 | "line": 1, 92 | "column": 50 93 | } 94 | }, 95 | "value": "./index.js", 96 | "raw": "'./index.js'" 97 | } 98 | } 99 | ], 100 | "sourceType": "module" 101 | } 102 | -------------------------------------------------------------------------------- /test/type_syntax_import_name_as_specifiers_with_type_token/expected.json: -------------------------------------------------------------------------------- 1 | { 2 | "type": "Program", 3 | "start": 0, 4 | "end": 47, 5 | "loc": { 6 | "start": { 7 | "line": 1, 8 | "column": 0 9 | }, 10 | "end": { 11 | "line": 1, 12 | "column": 47 13 | } 14 | }, 15 | "body": [ 16 | { 17 | "type": "ImportDeclaration", 18 | "start": 0, 19 | "end": 47, 20 | "loc": { 21 | "start": { 22 | "line": 1, 23 | "column": 0 24 | }, 25 | "end": { 26 | "line": 1, 27 | "column": 47 28 | } 29 | }, 30 | "importKind": "type", 31 | "specifiers": [ 32 | { 33 | "type": "ImportSpecifier", 34 | "start": 14, 35 | "end": 27, 36 | "loc": { 37 | "start": { 38 | "line": 1, 39 | "column": 14 40 | }, 41 | "end": { 42 | "line": 1, 43 | "column": 27 44 | } 45 | }, 46 | "imported": { 47 | "type": "Identifier", 48 | "start": 14, 49 | "end": 18, 50 | "loc": { 51 | "start": { 52 | "line": 1, 53 | "column": 14 54 | }, 55 | "end": { 56 | "line": 1, 57 | "column": 18 58 | } 59 | }, 60 | "name": "Test" 61 | }, 62 | "local": { 63 | "type": "Identifier", 64 | "start": 22, 65 | "end": 27, 66 | "loc": { 67 | "start": { 68 | "line": 1, 69 | "column": 22 70 | }, 71 | "end": { 72 | "line": 1, 73 | "column": 27 74 | } 75 | }, 76 | "name": "Test1" 77 | }, 78 | "importKind": "value" 79 | } 80 | ], 81 | "source": { 82 | "type": "Literal", 83 | "start": 35, 84 | "end": 47, 85 | "loc": { 86 | "start": { 87 | "line": 1, 88 | "column": 35 89 | }, 90 | "end": { 91 | "line": 1, 92 | "column": 47 93 | } 94 | }, 95 | "value": "./index.ts", 96 | "raw": "'./index.ts'" 97 | } 98 | } 99 | ], 100 | "sourceType": "module" 101 | } 102 | -------------------------------------------------------------------------------- /test/variables_declaration_number_with_definite/expected.json: -------------------------------------------------------------------------------- 1 | { 2 | "type": "Program", 3 | "start": 0, 4 | "end": 17, 5 | "loc": { 6 | "start": { 7 | "line": 1, 8 | "column": 0 9 | }, 10 | "end": { 11 | "line": 1, 12 | "column": 17 13 | } 14 | }, 15 | "body": [ 16 | { 17 | "type": "VariableDeclaration", 18 | "start": 0, 19 | "end": 17, 20 | "loc": { 21 | "start": { 22 | "line": 1, 23 | "column": 0 24 | }, 25 | "end": { 26 | "line": 1, 27 | "column": 17 28 | } 29 | }, 30 | "declarations": [ 31 | { 32 | "type": "VariableDeclarator", 33 | "start": 4, 34 | "end": 17, 35 | "loc": { 36 | "start": { 37 | "line": 1, 38 | "column": 4 39 | }, 40 | "end": { 41 | "line": 1, 42 | "column": 17 43 | } 44 | }, 45 | "id": { 46 | "type": "Identifier", 47 | "start": 4, 48 | "end": 17, 49 | "loc": { 50 | "start": { 51 | "line": 1, 52 | "column": 4 53 | }, 54 | "end": { 55 | "line": 1, 56 | "column": 17 57 | } 58 | }, 59 | "name": "test", 60 | "typeAnnotation": { 61 | "type": "TSTypeAnnotation", 62 | "start": 9, 63 | "end": 17, 64 | "loc": { 65 | "start": { 66 | "line": 1, 67 | "column": 9 68 | }, 69 | "end": { 70 | "line": 1, 71 | "column": 17 72 | } 73 | }, 74 | "typeAnnotation": { 75 | "type": "TSNumberKeyword", 76 | "start": 11, 77 | "end": 17, 78 | "loc": { 79 | "start": { 80 | "line": 1, 81 | "column": 11 82 | }, 83 | "end": { 84 | "line": 1, 85 | "column": 17 86 | } 87 | } 88 | } 89 | } 90 | }, 91 | "definite": true, 92 | "init": null 93 | } 94 | ], 95 | "kind": "let" 96 | } 97 | ], 98 | "sourceType": "module" 99 | } 100 | -------------------------------------------------------------------------------- /src/types.ts: -------------------------------------------------------------------------------- 1 | import type { Position, TokenType } from 'acorn'; 2 | 3 | export type Accessibility = 'public' | 'protected' | 'private'; 4 | 5 | export type VarianceAnnotations = 'in' | 'out'; 6 | 7 | export type ClassAccessor = 'accessor'; 8 | 9 | export type TsModifier = 10 | | 'readonly' 11 | | 'abstract' 12 | | 'declare' 13 | | 'static' 14 | | 'override' 15 | | 'const' 16 | | Accessibility 17 | | VarianceAnnotations 18 | | ClassAccessor; 19 | 20 | export type LookaheadState = { 21 | pos: number; 22 | value: any; 23 | type: TokenType; 24 | start: number; 25 | end: number; 26 | context: any[]; 27 | startLoc: any; 28 | endLoc: any; 29 | lastTokEndLoc: any; 30 | lastTokStartLoc: any; 31 | lastTokStart: any; 32 | lastTokEnd: any; 33 | curLine: number; 34 | lineStart: number; 35 | curPosition: () => Position; 36 | containsEsc: boolean; 37 | }; 38 | 39 | export type ParsingContext = 40 | | 'EnumMembers' 41 | | 'HeritageClauseElement' 42 | | 'TupleElementTypes' 43 | | 'TypeMembers' 44 | | 'TypeParametersOrArguments'; 45 | 46 | export type ModifierBase = { 47 | accessibility?: Accessibility; 48 | } & { 49 | [key in TsModifier]?: boolean | undefined | null; 50 | }; 51 | 52 | export type TryParse = { 53 | node: Node; 54 | error: Error; 55 | thrown: Thrown; 56 | aborted: Aborted; 57 | failState: FailState; 58 | }; 59 | 60 | export type AcornTypeScript = { 61 | tokTypes: Record; 62 | tokContexts: Record; 63 | keywordsRegExp: RegExp; 64 | tokenIsLiteralPropertyName(token: TokenType): boolean; 65 | tokenIsKeywordOrIdentifier(token: TokenType): boolean; 66 | tokenIsIdentifier(token: TokenType): boolean; 67 | tokenIsTSDeclarationStart(token: TokenType): boolean; 68 | tokenIsTSTypeOperator(token: TokenType): boolean; 69 | tokenIsTemplate(token: TokenType): boolean; 70 | }; 71 | 72 | export type AcornJsx = { 73 | tokTypes: { 74 | jsxName: TokenType; 75 | jsxText: TokenType; 76 | jsxTagEnd: TokenType; 77 | jsxTagStart: TokenType; 78 | }; 79 | tokContexts: { 80 | tc_oTag: any; 81 | tc_cTag: any; 82 | tc_expr: any; 83 | }; 84 | }; 85 | -------------------------------------------------------------------------------- /test/normal_export_export_const/expected.json: -------------------------------------------------------------------------------- 1 | { 2 | "type": "Program", 3 | "start": 0, 4 | "end": 27, 5 | "loc": { 6 | "start": { 7 | "line": 1, 8 | "column": 0 9 | }, 10 | "end": { 11 | "line": 1, 12 | "column": 27 13 | } 14 | }, 15 | "body": [ 16 | { 17 | "type": "ExportNamedDeclaration", 18 | "start": 0, 19 | "end": 27, 20 | "loc": { 21 | "start": { 22 | "line": 1, 23 | "column": 0 24 | }, 25 | "end": { 26 | "line": 1, 27 | "column": 27 28 | } 29 | }, 30 | "exportKind": "value", 31 | "declaration": { 32 | "type": "VariableDeclaration", 33 | "start": 7, 34 | "end": 27, 35 | "loc": { 36 | "start": { 37 | "line": 1, 38 | "column": 7 39 | }, 40 | "end": { 41 | "line": 1, 42 | "column": 27 43 | } 44 | }, 45 | "declarations": [ 46 | { 47 | "type": "VariableDeclarator", 48 | "start": 13, 49 | "end": 27, 50 | "loc": { 51 | "start": { 52 | "line": 1, 53 | "column": 13 54 | }, 55 | "end": { 56 | "line": 1, 57 | "column": 27 58 | } 59 | }, 60 | "id": { 61 | "type": "Identifier", 62 | "start": 13, 63 | "end": 17, 64 | "loc": { 65 | "start": { 66 | "line": 1, 67 | "column": 13 68 | }, 69 | "end": { 70 | "line": 1, 71 | "column": 17 72 | } 73 | }, 74 | "name": "test" 75 | }, 76 | "init": { 77 | "type": "Literal", 78 | "start": 20, 79 | "end": 27, 80 | "loc": { 81 | "start": { 82 | "line": 1, 83 | "column": 20 84 | }, 85 | "end": { 86 | "line": 1, 87 | "column": 27 88 | } 89 | }, 90 | "value": "12345", 91 | "raw": "'12345'" 92 | } 93 | } 94 | ], 95 | "kind": "const" 96 | }, 97 | "specifiers": [], 98 | "source": null 99 | } 100 | ], 101 | "sourceType": "module" 102 | } 103 | -------------------------------------------------------------------------------- /test/normal_export_export_default_object/expected.json: -------------------------------------------------------------------------------- 1 | { 2 | "type": "Program", 3 | "start": 0, 4 | "end": 31, 5 | "loc": { 6 | "start": { 7 | "line": 1, 8 | "column": 0 9 | }, 10 | "end": { 11 | "line": 3, 12 | "column": 1 13 | } 14 | }, 15 | "body": [ 16 | { 17 | "type": "ExportDefaultDeclaration", 18 | "start": 0, 19 | "end": 31, 20 | "loc": { 21 | "start": { 22 | "line": 1, 23 | "column": 0 24 | }, 25 | "end": { 26 | "line": 3, 27 | "column": 1 28 | } 29 | }, 30 | "exportKind": "value", 31 | "declaration": { 32 | "type": "ObjectExpression", 33 | "start": 15, 34 | "end": 31, 35 | "loc": { 36 | "start": { 37 | "line": 1, 38 | "column": 15 39 | }, 40 | "end": { 41 | "line": 3, 42 | "column": 1 43 | } 44 | }, 45 | "properties": [ 46 | { 47 | "type": "Property", 48 | "start": 19, 49 | "end": 29, 50 | "loc": { 51 | "start": { 52 | "line": 2, 53 | "column": 2 54 | }, 55 | "end": { 56 | "line": 2, 57 | "column": 12 58 | } 59 | }, 60 | "method": false, 61 | "shorthand": false, 62 | "computed": false, 63 | "key": { 64 | "type": "Identifier", 65 | "start": 19, 66 | "end": 20, 67 | "loc": { 68 | "start": { 69 | "line": 2, 70 | "column": 2 71 | }, 72 | "end": { 73 | "line": 2, 74 | "column": 3 75 | } 76 | }, 77 | "name": "a" 78 | }, 79 | "value": { 80 | "type": "Literal", 81 | "start": 22, 82 | "end": 29, 83 | "loc": { 84 | "start": { 85 | "line": 2, 86 | "column": 5 87 | }, 88 | "end": { 89 | "line": 2, 90 | "column": 12 91 | } 92 | }, 93 | "value": "12345", 94 | "raw": "'12345'" 95 | }, 96 | "kind": "init" 97 | } 98 | ] 99 | } 100 | } 101 | ], 102 | "sourceType": "module" 103 | } 104 | -------------------------------------------------------------------------------- /test/normal_identifier_test_interface_merging/expected.json: -------------------------------------------------------------------------------- 1 | { 2 | "type": "Program", 3 | "start": 0, 4 | "end": 33, 5 | "loc": { 6 | "start": { 7 | "line": 1, 8 | "column": 0 9 | }, 10 | "end": { 11 | "line": 2, 12 | "column": 16 13 | } 14 | }, 15 | "body": [ 16 | { 17 | "type": "TSInterfaceDeclaration", 18 | "start": 0, 19 | "end": 16, 20 | "loc": { 21 | "start": { 22 | "line": 1, 23 | "column": 0 24 | }, 25 | "end": { 26 | "line": 1, 27 | "column": 16 28 | } 29 | }, 30 | "id": { 31 | "type": "Identifier", 32 | "start": 10, 33 | "end": 13, 34 | "loc": { 35 | "start": { 36 | "line": 1, 37 | "column": 10 38 | }, 39 | "end": { 40 | "line": 1, 41 | "column": 13 42 | } 43 | }, 44 | "name": "abc" 45 | }, 46 | "body": { 47 | "type": "TSInterfaceBody", 48 | "start": 14, 49 | "end": 16, 50 | "loc": { 51 | "start": { 52 | "line": 1, 53 | "column": 14 54 | }, 55 | "end": { 56 | "line": 1, 57 | "column": 16 58 | } 59 | }, 60 | "body": [] 61 | } 62 | }, 63 | { 64 | "type": "TSInterfaceDeclaration", 65 | "start": 17, 66 | "end": 33, 67 | "loc": { 68 | "start": { 69 | "line": 2, 70 | "column": 0 71 | }, 72 | "end": { 73 | "line": 2, 74 | "column": 16 75 | } 76 | }, 77 | "id": { 78 | "type": "Identifier", 79 | "start": 27, 80 | "end": 30, 81 | "loc": { 82 | "start": { 83 | "line": 2, 84 | "column": 10 85 | }, 86 | "end": { 87 | "line": 2, 88 | "column": 13 89 | } 90 | }, 91 | "name": "abc" 92 | }, 93 | "body": { 94 | "type": "TSInterfaceBody", 95 | "start": 31, 96 | "end": 33, 97 | "loc": { 98 | "start": { 99 | "line": 2, 100 | "column": 14 101 | }, 102 | "end": { 103 | "line": 2, 104 | "column": 16 105 | } 106 | }, 107 | "body": [] 108 | } 109 | } 110 | ], 111 | "sourceType": "module" 112 | } 113 | -------------------------------------------------------------------------------- /test/run.test.ts: -------------------------------------------------------------------------------- 1 | import * as fs from 'fs'; 2 | import * as path from 'path'; 3 | import { describe } from 'vitest'; 4 | import { it } from 'vitest'; 5 | import { 6 | equalNode, 7 | parseDtsSource, 8 | parseJsxSource, 9 | parseSource, 10 | parseSourceShouldThrowError 11 | } from './utils'; 12 | 13 | describe('tests', () => { 14 | fs.readdirSync(__dirname, { withFileTypes: true }) 15 | .filter((dirent) => dirent.isDirectory()) 16 | .forEach((dirent) => { 17 | const folder_path = path.join(__dirname, dirent.name); 18 | const input_path = path.join(folder_path, 'input.ts'); 19 | const expected_path = path.join(folder_path, 'expected.json'); 20 | const error_path = path.join(folder_path, 'error.txt'); 21 | 22 | const _it = dirent.name.endsWith('.skip') 23 | ? it.skip 24 | : dirent.name.endsWith('.only') 25 | ? it.only 26 | : it; 27 | 28 | if (fs.existsSync(expected_path)) { 29 | _it(dirent.name, () => { 30 | const input_code = fs.readFileSync(input_path, 'utf-8'); 31 | const expected_result = fs.readFileSync(expected_path, 'utf-8'); 32 | 33 | const parsed_result = dirent.name.startsWith('jsx_') 34 | ? parseJsxSource(input_code) 35 | : dirent.name.startsWith('dts_') 36 | ? parseDtsSource(input_code) 37 | : parseSource(input_code); 38 | 39 | if (!expected_result) { 40 | fs.writeFileSync(expected_path, JSON.stringify(parsed_result, null, 2)); 41 | } else { 42 | try { 43 | equalNode(parsed_result, JSON.parse(expected_result)); 44 | } catch (e) { 45 | if (process.env.UPDATE_SNAPSHOT) { 46 | fs.writeFileSync(expected_path, JSON.stringify(parsed_result, null, 2)); 47 | } else { 48 | throw e; 49 | } 50 | } 51 | } 52 | }); 53 | } else if (fs.existsSync(error_path)) { 54 | _it(dirent.name, () => { 55 | const input_code = fs.readFileSync(input_path, 'utf-8'); 56 | const error_message = fs.readFileSync(error_path, 'utf-8').trim(); 57 | 58 | parseSourceShouldThrowError(input_code, error_message); 59 | }); 60 | } else { 61 | throw new Error('No expected result or error file found for ' + dirent.name); 62 | } 63 | }); 64 | }); 65 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # @sveltejs/acorn-typescript 2 | 3 | [![License](https://img.shields.io/npm/l/svelte.svg)](LICENSE.md) [![Chat](https://img.shields.io/discord/457912077277855764?label=chat&logo=discord)](https://svelte.dev/chat) 4 | 5 | This is a plugin for [Acorn](http://marijnhaverbeke.nl/acorn/) - a tiny, fast JavaScript parser, written completely in JavaScript. 6 | 7 | It was created as an experimental alternative, faster [TypeScript](https://www.typescriptlang.org/) parser. It will help you to parse 8 | TypeScript using Acorn. 9 | 10 | ## Usage 11 | 12 | To get started, import the plugin and use Acorn's extension mechanism to register it. You have to enable `options.locations` while using `@sveltejs/acorn-typescript`. 13 | 14 | ```typescript 15 | import { Parser } from 'acorn'; 16 | import { tsPlugin } from '@sveltejs/acorn-typescript'; 17 | 18 | const node = Parser.extend(tsPlugin()).parse( 19 | ` 20 | const a = 1 21 | type A = number 22 | export { 23 | a, 24 | type A as B 25 | } 26 | `, 27 | { 28 | sourceType: 'module', 29 | ecmaVersion: 'latest', 30 | locations: true 31 | } 32 | ); 33 | ``` 34 | 35 | If you want to enable parsing within a TypeScript ambient context, where certain syntax have different rules (like `.d.ts` files and inside [declare module blocks](https://www.typescriptlang.org/docs/handbook/declaration-files/introduction.html)): 36 | 37 | ```typescript 38 | import { Parser } from 'acorn'; 39 | import { tsPlugin } from '@sveltejs/acorn-typescript'; 40 | 41 | const node = Parser.extend(tsPlugin({ dts: true })).parse( 42 | ` 43 | const a = 1 44 | type A = number 45 | export { 46 | a, 47 | type A as B 48 | } 49 | `, 50 | { 51 | sourceType: 'module', 52 | ecmaVersion: 'latest', 53 | locations: true 54 | } 55 | ); 56 | ``` 57 | 58 | ## SUPPORTED 59 | 60 | - Typescript normal syntax 61 | - Support to parse TypeScript [Decorators](https://www.typescriptlang.org/docs/handbook/decorators.html) 62 | - Support to parse JSX & TSX 63 | 64 | ## CHANGELOG 65 | 66 | [click](./CHANGELOG.md) 67 | 68 | ## Acknowledgments 69 | 70 | We want to thank [TyrealHu](https://github.com/TyrealHu) for his original work on this project. He maintained [`acorn-typescript`](https://github.com/TyrealHu/acorn-typescript) until early 2024. 71 | -------------------------------------------------------------------------------- /src/extentions/import-assertions.ts: -------------------------------------------------------------------------------- 1 | import { AcornParseClass } from '../middleware'; 2 | import { AcornTypeScript } from '../types'; 3 | import * as acornNamespace from 'acorn'; 4 | 5 | export default function generateParseImportAssertions( 6 | Parse: typeof AcornParseClass, 7 | acornTypeScript: AcornTypeScript, 8 | acorn: typeof acornNamespace | (typeof AcornParseClass)['acorn'] 9 | ) { 10 | const { tokTypes } = acornTypeScript; 11 | const { tokTypes: tt } = acorn; 12 | return class ImportAttributes extends Parse { 13 | parseMaybeImportAttributes(node) { 14 | // import assertions 15 | if (this.type === tt._with || this.type === tokTypes.assert) { 16 | this.next(); 17 | const attributes = this.parseImportAttributes(); 18 | if (attributes) { 19 | node.attributes = attributes; 20 | } 21 | } 22 | } 23 | 24 | parseImportAttributes() { 25 | this.expect(tt.braceL); 26 | const attrs = this.parseWithEntries(); 27 | this.expect(tt.braceR); 28 | return attrs; 29 | } 30 | 31 | parseWithEntries() { 32 | const attrs = []; 33 | const attrNames = new Set(); 34 | 35 | do { 36 | if (this.type === tt.braceR) { 37 | break; 38 | } 39 | 40 | const node = this.startNode(); 41 | 42 | // parse withionKey : IdentifierName, StringLiteral 43 | let withionKeyNode; 44 | if (this.type === tt.string) { 45 | withionKeyNode = this.parseLiteral(this.value); 46 | } else { 47 | withionKeyNode = this.parseIdent(true); 48 | } 49 | this.next(); 50 | node.key = withionKeyNode; 51 | 52 | // check if we already have an entry for an attribute 53 | // if a duplicate entry is found, throw an error 54 | // for now this logic will come into play only when someone declares `type` twice 55 | if (attrNames.has(node.key.name)) { 56 | this.raise(this.pos, 'Duplicated key in attributes'); 57 | } 58 | attrNames.add(node.key.name); 59 | 60 | if (this.type !== tt.string) { 61 | this.raise(this.pos, 'Only string is supported as an attribute value'); 62 | } 63 | 64 | node.value = this.parseLiteral(this.value); 65 | 66 | attrs.push(this.finishNode(node, 'ImportAttribute')); 67 | } while (this.eat(tt.comma)); 68 | 69 | return attrs; 70 | } 71 | }; 72 | } 73 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Logs 2 | logs 3 | *.log 4 | npm-debug.log* 5 | yarn-debug.log* 6 | yarn-error.log* 7 | lerna-debug.log* 8 | 9 | # Diagnostic reports (https://nodejs.org/api/report.html) 10 | report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json 11 | # ide 12 | 13 | .idea/ 14 | 15 | # Runtime data 16 | pids 17 | *.pid 18 | *.seed 19 | *.pid.lock 20 | 21 | # Directory for instrumented libs generated by jscoverage/JSCover 22 | lib-cov 23 | 24 | # Coverage directory used by tools like istanbul 25 | coverage 26 | *.lcov 27 | 28 | # nyc test coverage 29 | .nyc_output 30 | 31 | # Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files) 32 | .grunt 33 | 34 | # Bower dependency directory (https://bower.io/) 35 | bower_components 36 | 37 | # node-waf configuration 38 | .lock-wscript 39 | 40 | # Compiled binary addons (https://nodejs.org/api/addons.html) 41 | build/Release 42 | 43 | # Dependency directories 44 | node_modules/ 45 | jspm_packages/ 46 | 47 | # TypeScript v1 declaration files 48 | typings/ 49 | 50 | # TypeScript cache 51 | *.tsbuildinfo 52 | 53 | # Optional npm cache directory 54 | .npm 55 | 56 | # Optional eslint cache 57 | .eslintcache 58 | 59 | # Microbundle cache 60 | .rpt2_cache/ 61 | .rts2_cache_cjs/ 62 | .rts2_cache_es/ 63 | .rts2_cache_umd/ 64 | 65 | # Optional REPL history 66 | .node_repl_history 67 | 68 | # Output of 'npm pack' 69 | *.tgz 70 | 71 | # Yarn Integrity file 72 | .yarn-integrity 73 | 74 | # dotenv environment variables file 75 | .env 76 | .env.test 77 | 78 | # parcel-bundler cache (https://parceljs.org/) 79 | .cache 80 | 81 | # Next.js build output 82 | .next 83 | 84 | # Nuxt.js build / generate output 85 | .nuxt 86 | dist 87 | 88 | # Gatsby files 89 | .cache/ 90 | # Comment in the public line in if your project uses Gatsby and *not* Next.js 91 | # https://nextjs.org/blog/next-9-1#public-directory-support 92 | # public 93 | 94 | # vuepress build output 95 | .vuepress/dist 96 | 97 | # Serverless directories 98 | .serverless/ 99 | 100 | # FuseBox cache 101 | .fusebox/ 102 | 103 | # DynamoDB Local files 104 | .dynamodb/ 105 | 106 | # TernJS port file 107 | .tern-port 108 | 109 | lib 110 | 111 | .DS_Store 112 | 113 | test262/yarn.lock 114 | test262/package-lock.json 115 | /index.js 116 | /playground/output.json -------------------------------------------------------------------------------- /test/export_type_export_type/expected.json: -------------------------------------------------------------------------------- 1 | { 2 | "type": "Program", 3 | "start": 0, 4 | "end": 34, 5 | "loc": { 6 | "start": { 7 | "line": 1, 8 | "column": 0 9 | }, 10 | "end": { 11 | "line": 1, 12 | "column": 34 13 | } 14 | }, 15 | "body": [ 16 | { 17 | "type": "ExportNamedDeclaration", 18 | "start": 0, 19 | "end": 34, 20 | "loc": { 21 | "start": { 22 | "line": 1, 23 | "column": 0 24 | }, 25 | "end": { 26 | "line": 1, 27 | "column": 34 28 | } 29 | }, 30 | "exportKind": "type", 31 | "declaration": { 32 | "type": "TSTypeAliasDeclaration", 33 | "start": 7, 34 | "end": 34, 35 | "loc": { 36 | "start": { 37 | "line": 1, 38 | "column": 7 39 | }, 40 | "end": { 41 | "line": 1, 42 | "column": 34 43 | } 44 | }, 45 | "id": { 46 | "type": "Identifier", 47 | "start": 12, 48 | "end": 16, 49 | "loc": { 50 | "start": { 51 | "line": 1, 52 | "column": 12 53 | }, 54 | "end": { 55 | "line": 1, 56 | "column": 16 57 | } 58 | }, 59 | "name": "Test" 60 | }, 61 | "typeAnnotation": { 62 | "type": "TSUnionType", 63 | "start": 19, 64 | "end": 34, 65 | "loc": { 66 | "start": { 67 | "line": 1, 68 | "column": 19 69 | }, 70 | "end": { 71 | "line": 1, 72 | "column": 34 73 | } 74 | }, 75 | "types": [ 76 | { 77 | "type": "TSStringKeyword", 78 | "start": 19, 79 | "end": 25, 80 | "loc": { 81 | "start": { 82 | "line": 1, 83 | "column": 19 84 | }, 85 | "end": { 86 | "line": 1, 87 | "column": 25 88 | } 89 | } 90 | }, 91 | { 92 | "type": "TSNumberKeyword", 93 | "start": 28, 94 | "end": 34, 95 | "loc": { 96 | "start": { 97 | "line": 1, 98 | "column": 28 99 | }, 100 | "end": { 101 | "line": 1, 102 | "column": 34 103 | } 104 | } 105 | } 106 | ] 107 | } 108 | }, 109 | "specifiers": [], 110 | "source": null 111 | } 112 | ], 113 | "sourceType": "module" 114 | } 115 | -------------------------------------------------------------------------------- /test/type_casts_1_as_number_expression/expected.json: -------------------------------------------------------------------------------- 1 | { 2 | "type": "Program", 3 | "start": 0, 4 | "end": 16, 5 | "loc": { 6 | "start": { 7 | "line": 1, 8 | "column": 0 9 | }, 10 | "end": { 11 | "line": 1, 12 | "column": 16 13 | } 14 | }, 15 | "body": [ 16 | { 17 | "type": "ExpressionStatement", 18 | "start": 0, 19 | "end": 16, 20 | "loc": { 21 | "start": { 22 | "line": 1, 23 | "column": 0 24 | }, 25 | "end": { 26 | "line": 1, 27 | "column": 16 28 | } 29 | }, 30 | "expression": { 31 | "type": "CallExpression", 32 | "start": 0, 33 | "end": 16, 34 | "loc": { 35 | "start": { 36 | "line": 1, 37 | "column": 0 38 | }, 39 | "end": { 40 | "line": 1, 41 | "column": 16 42 | } 43 | }, 44 | "callee": { 45 | "type": "Identifier", 46 | "start": 0, 47 | "end": 3, 48 | "loc": { 49 | "start": { 50 | "line": 1, 51 | "column": 0 52 | }, 53 | "end": { 54 | "line": 1, 55 | "column": 3 56 | } 57 | }, 58 | "name": "foo" 59 | }, 60 | "arguments": [ 61 | { 62 | "type": "TSAsExpression", 63 | "start": 4, 64 | "end": 15, 65 | "loc": { 66 | "start": { 67 | "line": 1, 68 | "column": 4 69 | }, 70 | "end": { 71 | "line": 1, 72 | "column": 15 73 | } 74 | }, 75 | "expression": { 76 | "type": "Literal", 77 | "start": 4, 78 | "end": 5, 79 | "loc": { 80 | "start": { 81 | "line": 1, 82 | "column": 4 83 | }, 84 | "end": { 85 | "line": 1, 86 | "column": 5 87 | } 88 | }, 89 | "value": 1, 90 | "raw": "1" 91 | }, 92 | "typeAnnotation": { 93 | "type": "TSNumberKeyword", 94 | "start": 9, 95 | "end": 15, 96 | "loc": { 97 | "start": { 98 | "line": 1, 99 | "column": 9 100 | }, 101 | "end": { 102 | "line": 1, 103 | "column": 15 104 | } 105 | } 106 | } 107 | } 108 | ], 109 | "optional": false 110 | } 111 | } 112 | ], 113 | "sourceType": "module" 114 | } 115 | -------------------------------------------------------------------------------- /test/type_casts_number1_expression/expected.json: -------------------------------------------------------------------------------- 1 | { 2 | "type": "Program", 3 | "start": 0, 4 | "end": 14, 5 | "loc": { 6 | "start": { 7 | "line": 1, 8 | "column": 0 9 | }, 10 | "end": { 11 | "line": 1, 12 | "column": 14 13 | } 14 | }, 15 | "body": [ 16 | { 17 | "type": "ExpressionStatement", 18 | "start": 0, 19 | "end": 14, 20 | "loc": { 21 | "start": { 22 | "line": 1, 23 | "column": 0 24 | }, 25 | "end": { 26 | "line": 1, 27 | "column": 14 28 | } 29 | }, 30 | "expression": { 31 | "type": "CallExpression", 32 | "start": 0, 33 | "end": 14, 34 | "loc": { 35 | "start": { 36 | "line": 1, 37 | "column": 0 38 | }, 39 | "end": { 40 | "line": 1, 41 | "column": 14 42 | } 43 | }, 44 | "callee": { 45 | "type": "Identifier", 46 | "start": 0, 47 | "end": 3, 48 | "loc": { 49 | "start": { 50 | "line": 1, 51 | "column": 0 52 | }, 53 | "end": { 54 | "line": 1, 55 | "column": 3 56 | } 57 | }, 58 | "name": "foo" 59 | }, 60 | "arguments": [ 61 | { 62 | "type": "TSTypeAssertion", 63 | "start": 4, 64 | "end": 13, 65 | "loc": { 66 | "start": { 67 | "line": 1, 68 | "column": 4 69 | }, 70 | "end": { 71 | "line": 1, 72 | "column": 13 73 | } 74 | }, 75 | "typeAnnotation": { 76 | "type": "TSNumberKeyword", 77 | "start": 5, 78 | "end": 11, 79 | "loc": { 80 | "start": { 81 | "line": 1, 82 | "column": 5 83 | }, 84 | "end": { 85 | "line": 1, 86 | "column": 11 87 | } 88 | } 89 | }, 90 | "expression": { 91 | "type": "Literal", 92 | "start": 12, 93 | "end": 13, 94 | "loc": { 95 | "start": { 96 | "line": 1, 97 | "column": 12 98 | }, 99 | "end": { 100 | "line": 1, 101 | "column": 13 102 | } 103 | }, 104 | "value": 1, 105 | "raw": "1" 106 | } 107 | } 108 | ], 109 | "optional": false 110 | } 111 | } 112 | ], 113 | "sourceType": "module" 114 | } 115 | -------------------------------------------------------------------------------- /test/satisfies_normal/expected.json: -------------------------------------------------------------------------------- 1 | { 2 | "type": "Program", 3 | "start": 0, 4 | "end": 25, 5 | "loc": { 6 | "start": { 7 | "line": 1, 8 | "column": 0 9 | }, 10 | "end": { 11 | "line": 1, 12 | "column": 25 13 | } 14 | }, 15 | "body": [ 16 | { 17 | "type": "VariableDeclaration", 18 | "start": 0, 19 | "end": 25, 20 | "loc": { 21 | "start": { 22 | "line": 1, 23 | "column": 0 24 | }, 25 | "end": { 26 | "line": 1, 27 | "column": 25 28 | } 29 | }, 30 | "declarations": [ 31 | { 32 | "type": "VariableDeclarator", 33 | "start": 6, 34 | "end": 25, 35 | "loc": { 36 | "start": { 37 | "line": 1, 38 | "column": 6 39 | }, 40 | "end": { 41 | "line": 1, 42 | "column": 25 43 | } 44 | }, 45 | "id": { 46 | "type": "Identifier", 47 | "start": 6, 48 | "end": 7, 49 | "loc": { 50 | "start": { 51 | "line": 1, 52 | "column": 6 53 | }, 54 | "end": { 55 | "line": 1, 56 | "column": 7 57 | } 58 | }, 59 | "name": "a" 60 | }, 61 | "init": { 62 | "type": "TSSatisfiesExpression", 63 | "start": 10, 64 | "end": 25, 65 | "loc": { 66 | "start": { 67 | "line": 1, 68 | "column": 10 69 | }, 70 | "end": { 71 | "line": 1, 72 | "column": 25 73 | } 74 | }, 75 | "expression": { 76 | "type": "Literal", 77 | "start": 10, 78 | "end": 11, 79 | "loc": { 80 | "start": { 81 | "line": 1, 82 | "column": 10 83 | }, 84 | "end": { 85 | "line": 1, 86 | "column": 11 87 | } 88 | }, 89 | "value": 1, 90 | "raw": "1" 91 | }, 92 | "typeAnnotation": { 93 | "type": "TSAnyKeyword", 94 | "start": 22, 95 | "end": 25, 96 | "loc": { 97 | "start": { 98 | "line": 1, 99 | "column": 22 100 | }, 101 | "end": { 102 | "line": 1, 103 | "column": 25 104 | } 105 | } 106 | } 107 | } 108 | } 109 | ], 110 | "kind": "const" 111 | } 112 | ], 113 | "sourceType": "module" 114 | } 115 | -------------------------------------------------------------------------------- /test/assert_export_all_as_assert/expected.json: -------------------------------------------------------------------------------- 1 | { 2 | "type": "Program", 3 | "start": 0, 4 | "end": 57, 5 | "loc": { 6 | "start": { 7 | "line": 1, 8 | "column": 0 9 | }, 10 | "end": { 11 | "line": 1, 12 | "column": 57 13 | } 14 | }, 15 | "body": [ 16 | { 17 | "type": "ExportAllDeclaration", 18 | "start": 0, 19 | "end": 57, 20 | "loc": { 21 | "start": { 22 | "line": 1, 23 | "column": 0 24 | }, 25 | "end": { 26 | "line": 1, 27 | "column": 57 28 | } 29 | }, 30 | "exportKind": "value", 31 | "exported": { 32 | "type": "Identifier", 33 | "start": 12, 34 | "end": 16, 35 | "loc": { 36 | "start": { 37 | "line": 1, 38 | "column": 12 39 | }, 40 | "end": { 41 | "line": 1, 42 | "column": 16 43 | } 44 | }, 45 | "name": "name" 46 | }, 47 | "source": { 48 | "type": "Literal", 49 | "start": 22, 50 | "end": 34, 51 | "loc": { 52 | "start": { 53 | "line": 1, 54 | "column": 22 55 | }, 56 | "end": { 57 | "line": 1, 58 | "column": 34 59 | } 60 | }, 61 | "value": "./foo.json", 62 | "raw": "\"./foo.json\"" 63 | }, 64 | "attributes": [ 65 | { 66 | "type": "ImportAttribute", 67 | "start": 42, 68 | "end": 54, 69 | "loc": { 70 | "start": { 71 | "line": 1, 72 | "column": 42 73 | }, 74 | "end": { 75 | "line": 1, 76 | "column": 54 77 | } 78 | }, 79 | "key": { 80 | "type": "Identifier", 81 | "start": 42, 82 | "end": 46, 83 | "loc": { 84 | "start": { 85 | "line": 1, 86 | "column": 42 87 | }, 88 | "end": { 89 | "line": 1, 90 | "column": 46 91 | } 92 | }, 93 | "name": "type" 94 | }, 95 | "value": { 96 | "type": "Literal", 97 | "start": 48, 98 | "end": 54, 99 | "loc": { 100 | "start": { 101 | "line": 1, 102 | "column": 48 103 | }, 104 | "end": { 105 | "line": 1, 106 | "column": 54 107 | } 108 | }, 109 | "value": "json", 110 | "raw": "\"json\"" 111 | } 112 | } 113 | ] 114 | } 115 | ], 116 | "sourceType": "module" 117 | } 118 | -------------------------------------------------------------------------------- /test/type_casts_1_as_number_declaration/expected.json: -------------------------------------------------------------------------------- 1 | { 2 | "type": "Program", 3 | "start": 0, 4 | "end": 22, 5 | "loc": { 6 | "start": { 7 | "line": 1, 8 | "column": 0 9 | }, 10 | "end": { 11 | "line": 1, 12 | "column": 22 13 | } 14 | }, 15 | "body": [ 16 | { 17 | "type": "VariableDeclaration", 18 | "start": 0, 19 | "end": 22, 20 | "loc": { 21 | "start": { 22 | "line": 1, 23 | "column": 0 24 | }, 25 | "end": { 26 | "line": 1, 27 | "column": 22 28 | } 29 | }, 30 | "declarations": [ 31 | { 32 | "type": "VariableDeclarator", 33 | "start": 4, 34 | "end": 22, 35 | "loc": { 36 | "start": { 37 | "line": 1, 38 | "column": 4 39 | }, 40 | "end": { 41 | "line": 1, 42 | "column": 22 43 | } 44 | }, 45 | "id": { 46 | "type": "Identifier", 47 | "start": 4, 48 | "end": 8, 49 | "loc": { 50 | "start": { 51 | "line": 1, 52 | "column": 4 53 | }, 54 | "end": { 55 | "line": 1, 56 | "column": 8 57 | } 58 | }, 59 | "name": "test" 60 | }, 61 | "init": { 62 | "type": "TSAsExpression", 63 | "start": 11, 64 | "end": 22, 65 | "loc": { 66 | "start": { 67 | "line": 1, 68 | "column": 11 69 | }, 70 | "end": { 71 | "line": 1, 72 | "column": 22 73 | } 74 | }, 75 | "expression": { 76 | "type": "Literal", 77 | "start": 11, 78 | "end": 12, 79 | "loc": { 80 | "start": { 81 | "line": 1, 82 | "column": 11 83 | }, 84 | "end": { 85 | "line": 1, 86 | "column": 12 87 | } 88 | }, 89 | "value": 1, 90 | "raw": "1" 91 | }, 92 | "typeAnnotation": { 93 | "type": "TSNumberKeyword", 94 | "start": 16, 95 | "end": 22, 96 | "loc": { 97 | "start": { 98 | "line": 1, 99 | "column": 16 100 | }, 101 | "end": { 102 | "line": 1, 103 | "column": 22 104 | } 105 | } 106 | } 107 | } 108 | } 109 | ], 110 | "kind": "let" 111 | } 112 | ], 113 | "sourceType": "module" 114 | } 115 | -------------------------------------------------------------------------------- /test/type_casts_number1_declaration/expected.json: -------------------------------------------------------------------------------- 1 | { 2 | "type": "Program", 3 | "start": 0, 4 | "end": 20, 5 | "loc": { 6 | "start": { 7 | "line": 1, 8 | "column": 0 9 | }, 10 | "end": { 11 | "line": 1, 12 | "column": 20 13 | } 14 | }, 15 | "body": [ 16 | { 17 | "type": "VariableDeclaration", 18 | "start": 0, 19 | "end": 20, 20 | "loc": { 21 | "start": { 22 | "line": 1, 23 | "column": 0 24 | }, 25 | "end": { 26 | "line": 1, 27 | "column": 20 28 | } 29 | }, 30 | "declarations": [ 31 | { 32 | "type": "VariableDeclarator", 33 | "start": 4, 34 | "end": 20, 35 | "loc": { 36 | "start": { 37 | "line": 1, 38 | "column": 4 39 | }, 40 | "end": { 41 | "line": 1, 42 | "column": 20 43 | } 44 | }, 45 | "id": { 46 | "type": "Identifier", 47 | "start": 4, 48 | "end": 8, 49 | "loc": { 50 | "start": { 51 | "line": 1, 52 | "column": 4 53 | }, 54 | "end": { 55 | "line": 1, 56 | "column": 8 57 | } 58 | }, 59 | "name": "test" 60 | }, 61 | "init": { 62 | "type": "TSTypeAssertion", 63 | "start": 11, 64 | "end": 20, 65 | "loc": { 66 | "start": { 67 | "line": 1, 68 | "column": 11 69 | }, 70 | "end": { 71 | "line": 1, 72 | "column": 20 73 | } 74 | }, 75 | "typeAnnotation": { 76 | "type": "TSNumberKeyword", 77 | "start": 12, 78 | "end": 18, 79 | "loc": { 80 | "start": { 81 | "line": 1, 82 | "column": 12 83 | }, 84 | "end": { 85 | "line": 1, 86 | "column": 18 87 | } 88 | } 89 | }, 90 | "expression": { 91 | "type": "Literal", 92 | "start": 19, 93 | "end": 20, 94 | "loc": { 95 | "start": { 96 | "line": 1, 97 | "column": 19 98 | }, 99 | "end": { 100 | "line": 1, 101 | "column": 20 102 | } 103 | }, 104 | "value": 1, 105 | "raw": "1" 106 | } 107 | } 108 | } 109 | ], 110 | "kind": "let" 111 | } 112 | ], 113 | "sourceType": "module" 114 | } 115 | -------------------------------------------------------------------------------- /test/variables_declaration_undefined/expected.json: -------------------------------------------------------------------------------- 1 | { 2 | "type": "Program", 3 | "start": 0, 4 | "end": 33, 5 | "loc": { 6 | "start": { 7 | "line": 1, 8 | "column": 0 9 | }, 10 | "end": { 11 | "line": 1, 12 | "column": 33 13 | } 14 | }, 15 | "body": [ 16 | { 17 | "type": "VariableDeclaration", 18 | "start": 0, 19 | "end": 33, 20 | "loc": { 21 | "start": { 22 | "line": 1, 23 | "column": 0 24 | }, 25 | "end": { 26 | "line": 1, 27 | "column": 33 28 | } 29 | }, 30 | "declarations": [ 31 | { 32 | "type": "VariableDeclarator", 33 | "start": 6, 34 | "end": 33, 35 | "loc": { 36 | "start": { 37 | "line": 1, 38 | "column": 6 39 | }, 40 | "end": { 41 | "line": 1, 42 | "column": 33 43 | } 44 | }, 45 | "id": { 46 | "type": "Identifier", 47 | "start": 6, 48 | "end": 21, 49 | "loc": { 50 | "start": { 51 | "line": 1, 52 | "column": 6 53 | }, 54 | "end": { 55 | "line": 1, 56 | "column": 21 57 | } 58 | }, 59 | "name": "test", 60 | "typeAnnotation": { 61 | "type": "TSTypeAnnotation", 62 | "start": 10, 63 | "end": 21, 64 | "loc": { 65 | "start": { 66 | "line": 1, 67 | "column": 10 68 | }, 69 | "end": { 70 | "line": 1, 71 | "column": 21 72 | } 73 | }, 74 | "typeAnnotation": { 75 | "type": "TSUndefinedKeyword", 76 | "start": 12, 77 | "end": 21, 78 | "loc": { 79 | "start": { 80 | "line": 1, 81 | "column": 12 82 | }, 83 | "end": { 84 | "line": 1, 85 | "column": 21 86 | } 87 | } 88 | } 89 | } 90 | }, 91 | "init": { 92 | "type": "Identifier", 93 | "start": 24, 94 | "end": 33, 95 | "loc": { 96 | "start": { 97 | "line": 1, 98 | "column": 24 99 | }, 100 | "end": { 101 | "line": 1, 102 | "column": 33 103 | } 104 | }, 105 | "name": "undefined" 106 | } 107 | } 108 | ], 109 | "kind": "const" 110 | } 111 | ], 112 | "sourceType": "module" 113 | } 114 | -------------------------------------------------------------------------------- /test/variables_declaration_any/expected.json: -------------------------------------------------------------------------------- 1 | { 2 | "type": "Program", 3 | "start": 0, 4 | "end": 21, 5 | "loc": { 6 | "start": { 7 | "line": 1, 8 | "column": 0 9 | }, 10 | "end": { 11 | "line": 1, 12 | "column": 21 13 | } 14 | }, 15 | "body": [ 16 | { 17 | "type": "VariableDeclaration", 18 | "start": 0, 19 | "end": 21, 20 | "loc": { 21 | "start": { 22 | "line": 1, 23 | "column": 0 24 | }, 25 | "end": { 26 | "line": 1, 27 | "column": 21 28 | } 29 | }, 30 | "declarations": [ 31 | { 32 | "type": "VariableDeclarator", 33 | "start": 6, 34 | "end": 21, 35 | "loc": { 36 | "start": { 37 | "line": 1, 38 | "column": 6 39 | }, 40 | "end": { 41 | "line": 1, 42 | "column": 21 43 | } 44 | }, 45 | "id": { 46 | "type": "Identifier", 47 | "start": 6, 48 | "end": 15, 49 | "loc": { 50 | "start": { 51 | "line": 1, 52 | "column": 6 53 | }, 54 | "end": { 55 | "line": 1, 56 | "column": 15 57 | } 58 | }, 59 | "name": "test", 60 | "typeAnnotation": { 61 | "type": "TSTypeAnnotation", 62 | "start": 10, 63 | "end": 15, 64 | "loc": { 65 | "start": { 66 | "line": 1, 67 | "column": 10 68 | }, 69 | "end": { 70 | "line": 1, 71 | "column": 15 72 | } 73 | }, 74 | "typeAnnotation": { 75 | "type": "TSAnyKeyword", 76 | "start": 12, 77 | "end": 15, 78 | "loc": { 79 | "start": { 80 | "line": 1, 81 | "column": 12 82 | }, 83 | "end": { 84 | "line": 1, 85 | "column": 15 86 | } 87 | } 88 | } 89 | } 90 | }, 91 | "init": { 92 | "type": "Literal", 93 | "start": 18, 94 | "end": 21, 95 | "loc": { 96 | "start": { 97 | "line": 1, 98 | "column": 18 99 | }, 100 | "end": { 101 | "line": 1, 102 | "column": 21 103 | } 104 | }, 105 | "value": 123, 106 | "raw": "123" 107 | } 108 | } 109 | ], 110 | "kind": "const" 111 | } 112 | ], 113 | "sourceType": "module" 114 | } 115 | -------------------------------------------------------------------------------- /test/variables_declaration_number/expected.json: -------------------------------------------------------------------------------- 1 | { 2 | "type": "Program", 3 | "start": 0, 4 | "end": 24, 5 | "loc": { 6 | "start": { 7 | "line": 1, 8 | "column": 0 9 | }, 10 | "end": { 11 | "line": 1, 12 | "column": 24 13 | } 14 | }, 15 | "body": [ 16 | { 17 | "type": "VariableDeclaration", 18 | "start": 0, 19 | "end": 24, 20 | "loc": { 21 | "start": { 22 | "line": 1, 23 | "column": 0 24 | }, 25 | "end": { 26 | "line": 1, 27 | "column": 24 28 | } 29 | }, 30 | "declarations": [ 31 | { 32 | "type": "VariableDeclarator", 33 | "start": 6, 34 | "end": 24, 35 | "loc": { 36 | "start": { 37 | "line": 1, 38 | "column": 6 39 | }, 40 | "end": { 41 | "line": 1, 42 | "column": 24 43 | } 44 | }, 45 | "id": { 46 | "type": "Identifier", 47 | "start": 6, 48 | "end": 18, 49 | "loc": { 50 | "start": { 51 | "line": 1, 52 | "column": 6 53 | }, 54 | "end": { 55 | "line": 1, 56 | "column": 18 57 | } 58 | }, 59 | "name": "test", 60 | "typeAnnotation": { 61 | "type": "TSTypeAnnotation", 62 | "start": 10, 63 | "end": 18, 64 | "loc": { 65 | "start": { 66 | "line": 1, 67 | "column": 10 68 | }, 69 | "end": { 70 | "line": 1, 71 | "column": 18 72 | } 73 | }, 74 | "typeAnnotation": { 75 | "type": "TSNumberKeyword", 76 | "start": 12, 77 | "end": 18, 78 | "loc": { 79 | "start": { 80 | "line": 1, 81 | "column": 12 82 | }, 83 | "end": { 84 | "line": 1, 85 | "column": 18 86 | } 87 | } 88 | } 89 | } 90 | }, 91 | "init": { 92 | "type": "Literal", 93 | "start": 21, 94 | "end": 24, 95 | "loc": { 96 | "start": { 97 | "line": 1, 98 | "column": 21 99 | }, 100 | "end": { 101 | "line": 1, 102 | "column": 24 103 | } 104 | }, 105 | "value": 123, 106 | "raw": "123" 107 | } 108 | } 109 | ], 110 | "kind": "const" 111 | } 112 | ], 113 | "sourceType": "module" 114 | } 115 | -------------------------------------------------------------------------------- /test/variables_declaration_unknown/expected.json: -------------------------------------------------------------------------------- 1 | { 2 | "type": "Program", 3 | "start": 0, 4 | "end": 25, 5 | "loc": { 6 | "start": { 7 | "line": 1, 8 | "column": 0 9 | }, 10 | "end": { 11 | "line": 1, 12 | "column": 25 13 | } 14 | }, 15 | "body": [ 16 | { 17 | "type": "VariableDeclaration", 18 | "start": 0, 19 | "end": 25, 20 | "loc": { 21 | "start": { 22 | "line": 1, 23 | "column": 0 24 | }, 25 | "end": { 26 | "line": 1, 27 | "column": 25 28 | } 29 | }, 30 | "declarations": [ 31 | { 32 | "type": "VariableDeclarator", 33 | "start": 6, 34 | "end": 25, 35 | "loc": { 36 | "start": { 37 | "line": 1, 38 | "column": 6 39 | }, 40 | "end": { 41 | "line": 1, 42 | "column": 25 43 | } 44 | }, 45 | "id": { 46 | "type": "Identifier", 47 | "start": 6, 48 | "end": 19, 49 | "loc": { 50 | "start": { 51 | "line": 1, 52 | "column": 6 53 | }, 54 | "end": { 55 | "line": 1, 56 | "column": 19 57 | } 58 | }, 59 | "name": "test", 60 | "typeAnnotation": { 61 | "type": "TSTypeAnnotation", 62 | "start": 10, 63 | "end": 19, 64 | "loc": { 65 | "start": { 66 | "line": 1, 67 | "column": 10 68 | }, 69 | "end": { 70 | "line": 1, 71 | "column": 19 72 | } 73 | }, 74 | "typeAnnotation": { 75 | "type": "TSUnknownKeyword", 76 | "start": 12, 77 | "end": 19, 78 | "loc": { 79 | "start": { 80 | "line": 1, 81 | "column": 12 82 | }, 83 | "end": { 84 | "line": 1, 85 | "column": 19 86 | } 87 | } 88 | } 89 | } 90 | }, 91 | "init": { 92 | "type": "Literal", 93 | "start": 22, 94 | "end": 25, 95 | "loc": { 96 | "start": { 97 | "line": 1, 98 | "column": 22 99 | }, 100 | "end": { 101 | "line": 1, 102 | "column": 25 103 | } 104 | }, 105 | "value": 123, 106 | "raw": "123" 107 | } 108 | } 109 | ], 110 | "kind": "const" 111 | } 112 | ], 113 | "sourceType": "module" 114 | } 115 | -------------------------------------------------------------------------------- /test/variables_declaration_boolean/expected.json: -------------------------------------------------------------------------------- 1 | { 2 | "type": "Program", 3 | "start": 0, 4 | "end": 27, 5 | "loc": { 6 | "start": { 7 | "line": 1, 8 | "column": 0 9 | }, 10 | "end": { 11 | "line": 1, 12 | "column": 27 13 | } 14 | }, 15 | "body": [ 16 | { 17 | "type": "VariableDeclaration", 18 | "start": 0, 19 | "end": 27, 20 | "loc": { 21 | "start": { 22 | "line": 1, 23 | "column": 0 24 | }, 25 | "end": { 26 | "line": 1, 27 | "column": 27 28 | } 29 | }, 30 | "declarations": [ 31 | { 32 | "type": "VariableDeclarator", 33 | "start": 6, 34 | "end": 27, 35 | "loc": { 36 | "start": { 37 | "line": 1, 38 | "column": 6 39 | }, 40 | "end": { 41 | "line": 1, 42 | "column": 27 43 | } 44 | }, 45 | "id": { 46 | "type": "Identifier", 47 | "start": 6, 48 | "end": 19, 49 | "loc": { 50 | "start": { 51 | "line": 1, 52 | "column": 6 53 | }, 54 | "end": { 55 | "line": 1, 56 | "column": 19 57 | } 58 | }, 59 | "name": "test", 60 | "typeAnnotation": { 61 | "type": "TSTypeAnnotation", 62 | "start": 10, 63 | "end": 19, 64 | "loc": { 65 | "start": { 66 | "line": 1, 67 | "column": 10 68 | }, 69 | "end": { 70 | "line": 1, 71 | "column": 19 72 | } 73 | }, 74 | "typeAnnotation": { 75 | "type": "TSBooleanKeyword", 76 | "start": 12, 77 | "end": 19, 78 | "loc": { 79 | "start": { 80 | "line": 1, 81 | "column": 12 82 | }, 83 | "end": { 84 | "line": 1, 85 | "column": 19 86 | } 87 | } 88 | } 89 | } 90 | }, 91 | "init": { 92 | "type": "Literal", 93 | "start": 22, 94 | "end": 27, 95 | "loc": { 96 | "start": { 97 | "line": 1, 98 | "column": 22 99 | }, 100 | "end": { 101 | "line": 1, 102 | "column": 27 103 | } 104 | }, 105 | "value": false, 106 | "raw": "false" 107 | } 108 | } 109 | ], 110 | "kind": "const" 111 | } 112 | ], 113 | "sourceType": "module" 114 | } 115 | -------------------------------------------------------------------------------- /test/variables_declaration_string/expected.json: -------------------------------------------------------------------------------- 1 | { 2 | "type": "Program", 3 | "start": 0, 4 | "end": 28, 5 | "loc": { 6 | "start": { 7 | "line": 1, 8 | "column": 0 9 | }, 10 | "end": { 11 | "line": 1, 12 | "column": 28 13 | } 14 | }, 15 | "body": [ 16 | { 17 | "type": "VariableDeclaration", 18 | "start": 0, 19 | "end": 28, 20 | "loc": { 21 | "start": { 22 | "line": 1, 23 | "column": 0 24 | }, 25 | "end": { 26 | "line": 1, 27 | "column": 28 28 | } 29 | }, 30 | "declarations": [ 31 | { 32 | "type": "VariableDeclarator", 33 | "start": 6, 34 | "end": 28, 35 | "loc": { 36 | "start": { 37 | "line": 1, 38 | "column": 6 39 | }, 40 | "end": { 41 | "line": 1, 42 | "column": 28 43 | } 44 | }, 45 | "id": { 46 | "type": "Identifier", 47 | "start": 6, 48 | "end": 18, 49 | "loc": { 50 | "start": { 51 | "line": 1, 52 | "column": 6 53 | }, 54 | "end": { 55 | "line": 1, 56 | "column": 18 57 | } 58 | }, 59 | "name": "test", 60 | "typeAnnotation": { 61 | "type": "TSTypeAnnotation", 62 | "start": 10, 63 | "end": 18, 64 | "loc": { 65 | "start": { 66 | "line": 1, 67 | "column": 10 68 | }, 69 | "end": { 70 | "line": 1, 71 | "column": 18 72 | } 73 | }, 74 | "typeAnnotation": { 75 | "type": "TSStringKeyword", 76 | "start": 12, 77 | "end": 18, 78 | "loc": { 79 | "start": { 80 | "line": 1, 81 | "column": 12 82 | }, 83 | "end": { 84 | "line": 1, 85 | "column": 18 86 | } 87 | } 88 | } 89 | } 90 | }, 91 | "init": { 92 | "type": "Literal", 93 | "start": 21, 94 | "end": 28, 95 | "loc": { 96 | "start": { 97 | "line": 1, 98 | "column": 21 99 | }, 100 | "end": { 101 | "line": 1, 102 | "column": 28 103 | } 104 | }, 105 | "value": "12355", 106 | "raw": "'12355'" 107 | } 108 | } 109 | ], 110 | "kind": "const" 111 | } 112 | ], 113 | "sourceType": "module" 114 | } 115 | -------------------------------------------------------------------------------- /test/jsx_jsx_with_type_generics/expected.json: -------------------------------------------------------------------------------- 1 | { 2 | "type": "Program", 3 | "start": 0, 4 | "end": 18, 5 | "loc": { 6 | "start": { 7 | "line": 1, 8 | "column": 0 9 | }, 10 | "end": { 11 | "line": 1, 12 | "column": 18 13 | } 14 | }, 15 | "body": [ 16 | { 17 | "type": "ExpressionStatement", 18 | "start": 0, 19 | "end": 18, 20 | "loc": { 21 | "start": { 22 | "line": 1, 23 | "column": 0 24 | }, 25 | "end": { 26 | "line": 1, 27 | "column": 18 28 | } 29 | }, 30 | "expression": { 31 | "type": "JSXElement", 32 | "start": 0, 33 | "end": 18, 34 | "loc": { 35 | "start": { 36 | "line": 1, 37 | "column": 0 38 | }, 39 | "end": { 40 | "line": 1, 41 | "column": 18 42 | } 43 | }, 44 | "openingElement": { 45 | "type": "JSXOpeningElement", 46 | "start": 0, 47 | "end": 18, 48 | "loc": { 49 | "start": { 50 | "line": 1, 51 | "column": 0 52 | }, 53 | "end": { 54 | "line": 1, 55 | "column": 18 56 | } 57 | }, 58 | "name": { 59 | "type": "JSXIdentifier", 60 | "start": 1, 61 | "end": 7, 62 | "loc": { 63 | "start": { 64 | "line": 1, 65 | "column": 1 66 | }, 67 | "end": { 68 | "line": 1, 69 | "column": 7 70 | } 71 | }, 72 | "name": "Select" 73 | }, 74 | "typeArguments": { 75 | "type": "TSTypeParameterInstantiation", 76 | "start": 7, 77 | "end": 15, 78 | "loc": { 79 | "start": { 80 | "line": 1, 81 | "column": 7 82 | }, 83 | "end": { 84 | "line": 1, 85 | "column": 15 86 | } 87 | }, 88 | "params": [ 89 | { 90 | "type": "TSStringKeyword", 91 | "start": 8, 92 | "end": 14, 93 | "loc": { 94 | "start": { 95 | "line": 1, 96 | "column": 8 97 | }, 98 | "end": { 99 | "line": 1, 100 | "column": 14 101 | } 102 | } 103 | } 104 | ] 105 | }, 106 | "attributes": [], 107 | "selfClosing": true 108 | }, 109 | "closingElement": null, 110 | "children": [] 111 | } 112 | } 113 | ], 114 | "sourceType": "module" 115 | } 116 | -------------------------------------------------------------------------------- /test/variables_declaration_expression_with_paren/expected.json: -------------------------------------------------------------------------------- 1 | { 2 | "type": "Program", 3 | "start": 0, 4 | "end": 20, 5 | "loc": { 6 | "start": { 7 | "line": 1, 8 | "column": 0 9 | }, 10 | "end": { 11 | "line": 1, 12 | "column": 20 13 | } 14 | }, 15 | "body": [ 16 | { 17 | "type": "VariableDeclaration", 18 | "start": 0, 19 | "end": 20, 20 | "loc": { 21 | "start": { 22 | "line": 1, 23 | "column": 0 24 | }, 25 | "end": { 26 | "line": 1, 27 | "column": 20 28 | } 29 | }, 30 | "declarations": [ 31 | { 32 | "type": "VariableDeclarator", 33 | "start": 4, 34 | "end": 20, 35 | "loc": { 36 | "start": { 37 | "line": 1, 38 | "column": 4 39 | }, 40 | "end": { 41 | "line": 1, 42 | "column": 20 43 | } 44 | }, 45 | "id": { 46 | "type": "Identifier", 47 | "start": 4, 48 | "end": 8, 49 | "loc": { 50 | "start": { 51 | "line": 1, 52 | "column": 4 53 | }, 54 | "end": { 55 | "line": 1, 56 | "column": 8 57 | } 58 | }, 59 | "name": "test" 60 | }, 61 | "init": { 62 | "type": "BinaryExpression", 63 | "start": 12, 64 | "end": 19, 65 | "loc": { 66 | "start": { 67 | "line": 1, 68 | "column": 12 69 | }, 70 | "end": { 71 | "line": 1, 72 | "column": 19 73 | } 74 | }, 75 | "left": { 76 | "type": "Literal", 77 | "start": 12, 78 | "end": 13, 79 | "loc": { 80 | "start": { 81 | "line": 1, 82 | "column": 12 83 | }, 84 | "end": { 85 | "line": 1, 86 | "column": 13 87 | } 88 | }, 89 | "value": 1, 90 | "raw": "1" 91 | }, 92 | "operator": "===", 93 | "right": { 94 | "type": "Literal", 95 | "start": 18, 96 | "end": 19, 97 | "loc": { 98 | "start": { 99 | "line": 1, 100 | "column": 18 101 | }, 102 | "end": { 103 | "line": 1, 104 | "column": 19 105 | } 106 | }, 107 | "value": 2, 108 | "raw": "2" 109 | } 110 | } 111 | } 112 | ], 113 | "kind": "let" 114 | } 115 | ], 116 | "sourceType": "module" 117 | } 118 | -------------------------------------------------------------------------------- /test/function_type_test_async_arrow_function_with_one_param/expected.json: -------------------------------------------------------------------------------- 1 | { 2 | "type": "Program", 3 | "start": 0, 4 | "end": 17, 5 | "loc": { 6 | "start": { 7 | "line": 1, 8 | "column": 0 9 | }, 10 | "end": { 11 | "line": 1, 12 | "column": 17 13 | } 14 | }, 15 | "body": [ 16 | { 17 | "type": "ExpressionStatement", 18 | "start": 0, 19 | "end": 17, 20 | "loc": { 21 | "start": { 22 | "line": 1, 23 | "column": 0 24 | }, 25 | "end": { 26 | "line": 1, 27 | "column": 17 28 | } 29 | }, 30 | "expression": { 31 | "type": "AssignmentExpression", 32 | "start": 0, 33 | "end": 17, 34 | "loc": { 35 | "start": { 36 | "line": 1, 37 | "column": 0 38 | }, 39 | "end": { 40 | "line": 1, 41 | "column": 17 42 | } 43 | }, 44 | "operator": "=", 45 | "left": { 46 | "type": "Identifier", 47 | "start": 0, 48 | "end": 1, 49 | "loc": { 50 | "start": { 51 | "line": 1, 52 | "column": 0 53 | }, 54 | "end": { 55 | "line": 1, 56 | "column": 1 57 | } 58 | }, 59 | "name": "a" 60 | }, 61 | "right": { 62 | "type": "ArrowFunctionExpression", 63 | "start": 4, 64 | "end": 17, 65 | "loc": { 66 | "start": { 67 | "line": 1, 68 | "column": 4 69 | }, 70 | "end": { 71 | "line": 1, 72 | "column": 17 73 | } 74 | }, 75 | "id": null, 76 | "expression": false, 77 | "generator": false, 78 | "async": true, 79 | "params": [ 80 | { 81 | "type": "Identifier", 82 | "start": 10, 83 | "end": 11, 84 | "loc": { 85 | "start": { 86 | "line": 1, 87 | "column": 10 88 | }, 89 | "end": { 90 | "line": 1, 91 | "column": 11 92 | } 93 | }, 94 | "name": "x" 95 | } 96 | ], 97 | "body": { 98 | "type": "BlockStatement", 99 | "start": 15, 100 | "end": 17, 101 | "loc": { 102 | "start": { 103 | "line": 1, 104 | "column": 15 105 | }, 106 | "end": { 107 | "line": 1, 108 | "column": 17 109 | } 110 | }, 111 | "body": [] 112 | } 113 | } 114 | } 115 | } 116 | ], 117 | "sourceType": "module" 118 | } 119 | -------------------------------------------------------------------------------- /test/normal_identifier_test_typevalue_same_name_1/expected.json: -------------------------------------------------------------------------------- 1 | { 2 | "type": "Program", 3 | "start": 0, 4 | "end": 25, 5 | "loc": { 6 | "start": { 7 | "line": 1, 8 | "column": 0 9 | }, 10 | "end": { 11 | "line": 2, 12 | "column": 8 13 | } 14 | }, 15 | "body": [ 16 | { 17 | "type": "TSTypeAliasDeclaration", 18 | "start": 0, 19 | "end": 16, 20 | "loc": { 21 | "start": { 22 | "line": 1, 23 | "column": 0 24 | }, 25 | "end": { 26 | "line": 1, 27 | "column": 16 28 | } 29 | }, 30 | "id": { 31 | "type": "Identifier", 32 | "start": 5, 33 | "end": 8, 34 | "loc": { 35 | "start": { 36 | "line": 1, 37 | "column": 5 38 | }, 39 | "end": { 40 | "line": 1, 41 | "column": 8 42 | } 43 | }, 44 | "name": "abc" 45 | }, 46 | "typeAnnotation": { 47 | "type": "TSLiteralType", 48 | "start": 11, 49 | "end": 15, 50 | "loc": { 51 | "start": { 52 | "line": 1, 53 | "column": 11 54 | }, 55 | "end": { 56 | "line": 1, 57 | "column": 15 58 | } 59 | }, 60 | "literal": { 61 | "type": "Literal", 62 | "start": 11, 63 | "end": 15, 64 | "loc": { 65 | "start": { 66 | "line": 1, 67 | "column": 11 68 | }, 69 | "end": { 70 | "line": 1, 71 | "column": 15 72 | } 73 | }, 74 | "value": 1234, 75 | "raw": "1234" 76 | } 77 | } 78 | }, 79 | { 80 | "type": "VariableDeclaration", 81 | "start": 17, 82 | "end": 25, 83 | "loc": { 84 | "start": { 85 | "line": 2, 86 | "column": 0 87 | }, 88 | "end": { 89 | "line": 2, 90 | "column": 8 91 | } 92 | }, 93 | "declarations": [ 94 | { 95 | "type": "VariableDeclarator", 96 | "start": 21, 97 | "end": 24, 98 | "loc": { 99 | "start": { 100 | "line": 2, 101 | "column": 4 102 | }, 103 | "end": { 104 | "line": 2, 105 | "column": 7 106 | } 107 | }, 108 | "id": { 109 | "type": "Identifier", 110 | "start": 21, 111 | "end": 24, 112 | "loc": { 113 | "start": { 114 | "line": 2, 115 | "column": 4 116 | }, 117 | "end": { 118 | "line": 2, 119 | "column": 7 120 | } 121 | }, 122 | "name": "abc" 123 | }, 124 | "init": null 125 | } 126 | ], 127 | "kind": "var" 128 | } 129 | ], 130 | "sourceType": "module" 131 | } 132 | -------------------------------------------------------------------------------- /test/normal_identifier_test_typeidentifier_same_name_2/expected.json: -------------------------------------------------------------------------------- 1 | { 2 | "type": "Program", 3 | "start": 0, 4 | "end": 25, 5 | "loc": { 6 | "start": { 7 | "line": 1, 8 | "column": 0 9 | }, 10 | "end": { 11 | "line": 2, 12 | "column": 8 13 | } 14 | }, 15 | "body": [ 16 | { 17 | "type": "TSTypeAliasDeclaration", 18 | "start": 0, 19 | "end": 16, 20 | "loc": { 21 | "start": { 22 | "line": 1, 23 | "column": 0 24 | }, 25 | "end": { 26 | "line": 1, 27 | "column": 16 28 | } 29 | }, 30 | "id": { 31 | "type": "Identifier", 32 | "start": 5, 33 | "end": 8, 34 | "loc": { 35 | "start": { 36 | "line": 1, 37 | "column": 5 38 | }, 39 | "end": { 40 | "line": 1, 41 | "column": 8 42 | } 43 | }, 44 | "name": "abc" 45 | }, 46 | "typeAnnotation": { 47 | "type": "TSLiteralType", 48 | "start": 11, 49 | "end": 15, 50 | "loc": { 51 | "start": { 52 | "line": 1, 53 | "column": 11 54 | }, 55 | "end": { 56 | "line": 1, 57 | "column": 15 58 | } 59 | }, 60 | "literal": { 61 | "type": "Literal", 62 | "start": 11, 63 | "end": 15, 64 | "loc": { 65 | "start": { 66 | "line": 1, 67 | "column": 11 68 | }, 69 | "end": { 70 | "line": 1, 71 | "column": 15 72 | } 73 | }, 74 | "value": 1234, 75 | "raw": "1234" 76 | } 77 | } 78 | }, 79 | { 80 | "type": "VariableDeclaration", 81 | "start": 17, 82 | "end": 25, 83 | "loc": { 84 | "start": { 85 | "line": 2, 86 | "column": 0 87 | }, 88 | "end": { 89 | "line": 2, 90 | "column": 8 91 | } 92 | }, 93 | "declarations": [ 94 | { 95 | "type": "VariableDeclarator", 96 | "start": 21, 97 | "end": 24, 98 | "loc": { 99 | "start": { 100 | "line": 2, 101 | "column": 4 102 | }, 103 | "end": { 104 | "line": 2, 105 | "column": 7 106 | } 107 | }, 108 | "id": { 109 | "type": "Identifier", 110 | "start": 21, 111 | "end": 24, 112 | "loc": { 113 | "start": { 114 | "line": 2, 115 | "column": 4 116 | }, 117 | "end": { 118 | "line": 2, 119 | "column": 7 120 | } 121 | }, 122 | "name": "abc" 123 | }, 124 | "init": null 125 | } 126 | ], 127 | "kind": "let" 128 | } 129 | ], 130 | "sourceType": "module" 131 | } 132 | -------------------------------------------------------------------------------- /test/normal_identifier_test_typeidentifier_same_name_3/expected.json: -------------------------------------------------------------------------------- 1 | { 2 | "type": "Program", 3 | "start": 0, 4 | "end": 34, 5 | "loc": { 6 | "start": { 7 | "line": 1, 8 | "column": 0 9 | }, 10 | "end": { 11 | "line": 2, 12 | "column": 17 13 | } 14 | }, 15 | "body": [ 16 | { 17 | "type": "TSTypeAliasDeclaration", 18 | "start": 0, 19 | "end": 16, 20 | "loc": { 21 | "start": { 22 | "line": 1, 23 | "column": 0 24 | }, 25 | "end": { 26 | "line": 1, 27 | "column": 16 28 | } 29 | }, 30 | "id": { 31 | "type": "Identifier", 32 | "start": 5, 33 | "end": 8, 34 | "loc": { 35 | "start": { 36 | "line": 1, 37 | "column": 5 38 | }, 39 | "end": { 40 | "line": 1, 41 | "column": 8 42 | } 43 | }, 44 | "name": "abc" 45 | }, 46 | "typeAnnotation": { 47 | "type": "TSLiteralType", 48 | "start": 11, 49 | "end": 15, 50 | "loc": { 51 | "start": { 52 | "line": 1, 53 | "column": 11 54 | }, 55 | "end": { 56 | "line": 1, 57 | "column": 15 58 | } 59 | }, 60 | "literal": { 61 | "type": "Literal", 62 | "start": 11, 63 | "end": 15, 64 | "loc": { 65 | "start": { 66 | "line": 1, 67 | "column": 11 68 | }, 69 | "end": { 70 | "line": 1, 71 | "column": 15 72 | } 73 | }, 74 | "value": 1234, 75 | "raw": "1234" 76 | } 77 | } 78 | }, 79 | { 80 | "type": "FunctionDeclaration", 81 | "start": 17, 82 | "end": 34, 83 | "loc": { 84 | "start": { 85 | "line": 2, 86 | "column": 0 87 | }, 88 | "end": { 89 | "line": 2, 90 | "column": 17 91 | } 92 | }, 93 | "id": { 94 | "type": "Identifier", 95 | "start": 26, 96 | "end": 29, 97 | "loc": { 98 | "start": { 99 | "line": 2, 100 | "column": 9 101 | }, 102 | "end": { 103 | "line": 2, 104 | "column": 12 105 | } 106 | }, 107 | "name": "abc" 108 | }, 109 | "expression": false, 110 | "generator": false, 111 | "async": false, 112 | "params": [], 113 | "body": { 114 | "type": "BlockStatement", 115 | "start": 32, 116 | "end": 34, 117 | "loc": { 118 | "start": { 119 | "line": 2, 120 | "column": 15 121 | }, 122 | "end": { 123 | "line": 2, 124 | "column": 17 125 | } 126 | }, 127 | "body": [] 128 | } 129 | } 130 | ], 131 | "sourceType": "module" 132 | } 133 | -------------------------------------------------------------------------------- /test/function_type_test_no_parameter_with_undefined/expected.json: -------------------------------------------------------------------------------- 1 | { 2 | "type": "Program", 3 | "start": 0, 4 | "end": 49, 5 | "loc": { 6 | "start": { 7 | "line": 1, 8 | "column": 0 9 | }, 10 | "end": { 11 | "line": 3, 12 | "column": 1 13 | } 14 | }, 15 | "body": [ 16 | { 17 | "type": "FunctionDeclaration", 18 | "start": 0, 19 | "end": 49, 20 | "loc": { 21 | "start": { 22 | "line": 1, 23 | "column": 0 24 | }, 25 | "end": { 26 | "line": 3, 27 | "column": 1 28 | } 29 | }, 30 | "id": { 31 | "type": "Identifier", 32 | "start": 9, 33 | "end": 13, 34 | "loc": { 35 | "start": { 36 | "line": 1, 37 | "column": 9 38 | }, 39 | "end": { 40 | "line": 1, 41 | "column": 13 42 | } 43 | }, 44 | "name": "test" 45 | }, 46 | "expression": false, 47 | "generator": false, 48 | "async": false, 49 | "params": [], 50 | "returnType": { 51 | "type": "TSTypeAnnotation", 52 | "start": 15, 53 | "end": 26, 54 | "loc": { 55 | "start": { 56 | "line": 1, 57 | "column": 15 58 | }, 59 | "end": { 60 | "line": 1, 61 | "column": 26 62 | } 63 | }, 64 | "typeAnnotation": { 65 | "type": "TSUndefinedKeyword", 66 | "start": 17, 67 | "end": 26, 68 | "loc": { 69 | "start": { 70 | "line": 1, 71 | "column": 17 72 | }, 73 | "end": { 74 | "line": 1, 75 | "column": 26 76 | } 77 | } 78 | } 79 | }, 80 | "body": { 81 | "type": "BlockStatement", 82 | "start": 27, 83 | "end": 49, 84 | "loc": { 85 | "start": { 86 | "line": 1, 87 | "column": 27 88 | }, 89 | "end": { 90 | "line": 3, 91 | "column": 1 92 | } 93 | }, 94 | "body": [ 95 | { 96 | "type": "ReturnStatement", 97 | "start": 31, 98 | "end": 47, 99 | "loc": { 100 | "start": { 101 | "line": 2, 102 | "column": 2 103 | }, 104 | "end": { 105 | "line": 2, 106 | "column": 18 107 | } 108 | }, 109 | "argument": { 110 | "type": "Identifier", 111 | "start": 38, 112 | "end": 47, 113 | "loc": { 114 | "start": { 115 | "line": 2, 116 | "column": 9 117 | }, 118 | "end": { 119 | "line": 2, 120 | "column": 18 121 | } 122 | }, 123 | "name": "undefined" 124 | } 125 | } 126 | ] 127 | } 128 | } 129 | ], 130 | "sourceType": "module" 131 | } 132 | -------------------------------------------------------------------------------- /test/function_type_test_no_parameter_with_any/expected.json: -------------------------------------------------------------------------------- 1 | { 2 | "type": "Program", 3 | "start": 0, 4 | "end": 37, 5 | "loc": { 6 | "start": { 7 | "line": 1, 8 | "column": 0 9 | }, 10 | "end": { 11 | "line": 3, 12 | "column": 1 13 | } 14 | }, 15 | "body": [ 16 | { 17 | "type": "FunctionDeclaration", 18 | "start": 0, 19 | "end": 37, 20 | "loc": { 21 | "start": { 22 | "line": 1, 23 | "column": 0 24 | }, 25 | "end": { 26 | "line": 3, 27 | "column": 1 28 | } 29 | }, 30 | "id": { 31 | "type": "Identifier", 32 | "start": 9, 33 | "end": 13, 34 | "loc": { 35 | "start": { 36 | "line": 1, 37 | "column": 9 38 | }, 39 | "end": { 40 | "line": 1, 41 | "column": 13 42 | } 43 | }, 44 | "name": "test" 45 | }, 46 | "expression": false, 47 | "generator": false, 48 | "async": false, 49 | "params": [], 50 | "returnType": { 51 | "type": "TSTypeAnnotation", 52 | "start": 15, 53 | "end": 20, 54 | "loc": { 55 | "start": { 56 | "line": 1, 57 | "column": 15 58 | }, 59 | "end": { 60 | "line": 1, 61 | "column": 20 62 | } 63 | }, 64 | "typeAnnotation": { 65 | "type": "TSAnyKeyword", 66 | "start": 17, 67 | "end": 20, 68 | "loc": { 69 | "start": { 70 | "line": 1, 71 | "column": 17 72 | }, 73 | "end": { 74 | "line": 1, 75 | "column": 20 76 | } 77 | } 78 | } 79 | }, 80 | "body": { 81 | "type": "BlockStatement", 82 | "start": 21, 83 | "end": 37, 84 | "loc": { 85 | "start": { 86 | "line": 1, 87 | "column": 21 88 | }, 89 | "end": { 90 | "line": 3, 91 | "column": 1 92 | } 93 | }, 94 | "body": [ 95 | { 96 | "type": "ReturnStatement", 97 | "start": 25, 98 | "end": 35, 99 | "loc": { 100 | "start": { 101 | "line": 2, 102 | "column": 2 103 | }, 104 | "end": { 105 | "line": 2, 106 | "column": 12 107 | } 108 | }, 109 | "argument": { 110 | "type": "Literal", 111 | "start": 32, 112 | "end": 35, 113 | "loc": { 114 | "start": { 115 | "line": 2, 116 | "column": 9 117 | }, 118 | "end": { 119 | "line": 2, 120 | "column": 12 121 | } 122 | }, 123 | "value": 123, 124 | "raw": "123" 125 | } 126 | } 127 | ] 128 | } 129 | } 130 | ], 131 | "sourceType": "module" 132 | } 133 | -------------------------------------------------------------------------------- /test/function_type_test_no_parameter_with_boolean/expected.json: -------------------------------------------------------------------------------- 1 | { 2 | "type": "Program", 3 | "start": 0, 4 | "end": 42, 5 | "loc": { 6 | "start": { 7 | "line": 1, 8 | "column": 0 9 | }, 10 | "end": { 11 | "line": 3, 12 | "column": 1 13 | } 14 | }, 15 | "body": [ 16 | { 17 | "type": "FunctionDeclaration", 18 | "start": 0, 19 | "end": 42, 20 | "loc": { 21 | "start": { 22 | "line": 1, 23 | "column": 0 24 | }, 25 | "end": { 26 | "line": 3, 27 | "column": 1 28 | } 29 | }, 30 | "id": { 31 | "type": "Identifier", 32 | "start": 9, 33 | "end": 13, 34 | "loc": { 35 | "start": { 36 | "line": 1, 37 | "column": 9 38 | }, 39 | "end": { 40 | "line": 1, 41 | "column": 13 42 | } 43 | }, 44 | "name": "test" 45 | }, 46 | "expression": false, 47 | "generator": false, 48 | "async": false, 49 | "params": [], 50 | "returnType": { 51 | "type": "TSTypeAnnotation", 52 | "start": 15, 53 | "end": 24, 54 | "loc": { 55 | "start": { 56 | "line": 1, 57 | "column": 15 58 | }, 59 | "end": { 60 | "line": 1, 61 | "column": 24 62 | } 63 | }, 64 | "typeAnnotation": { 65 | "type": "TSBooleanKeyword", 66 | "start": 17, 67 | "end": 24, 68 | "loc": { 69 | "start": { 70 | "line": 1, 71 | "column": 17 72 | }, 73 | "end": { 74 | "line": 1, 75 | "column": 24 76 | } 77 | } 78 | } 79 | }, 80 | "body": { 81 | "type": "BlockStatement", 82 | "start": 25, 83 | "end": 42, 84 | "loc": { 85 | "start": { 86 | "line": 1, 87 | "column": 25 88 | }, 89 | "end": { 90 | "line": 3, 91 | "column": 1 92 | } 93 | }, 94 | "body": [ 95 | { 96 | "type": "ReturnStatement", 97 | "start": 29, 98 | "end": 40, 99 | "loc": { 100 | "start": { 101 | "line": 2, 102 | "column": 2 103 | }, 104 | "end": { 105 | "line": 2, 106 | "column": 13 107 | } 108 | }, 109 | "argument": { 110 | "type": "Literal", 111 | "start": 36, 112 | "end": 40, 113 | "loc": { 114 | "start": { 115 | "line": 2, 116 | "column": 9 117 | }, 118 | "end": { 119 | "line": 2, 120 | "column": 13 121 | } 122 | }, 123 | "value": true, 124 | "raw": "true" 125 | } 126 | } 127 | ] 128 | } 129 | } 130 | ], 131 | "sourceType": "module" 132 | } 133 | -------------------------------------------------------------------------------- /test/function_type_test_no_parameter_with_number/expected.json: -------------------------------------------------------------------------------- 1 | { 2 | "type": "Program", 3 | "start": 0, 4 | "end": 40, 5 | "loc": { 6 | "start": { 7 | "line": 1, 8 | "column": 0 9 | }, 10 | "end": { 11 | "line": 3, 12 | "column": 1 13 | } 14 | }, 15 | "body": [ 16 | { 17 | "type": "FunctionDeclaration", 18 | "start": 0, 19 | "end": 40, 20 | "loc": { 21 | "start": { 22 | "line": 1, 23 | "column": 0 24 | }, 25 | "end": { 26 | "line": 3, 27 | "column": 1 28 | } 29 | }, 30 | "id": { 31 | "type": "Identifier", 32 | "start": 9, 33 | "end": 13, 34 | "loc": { 35 | "start": { 36 | "line": 1, 37 | "column": 9 38 | }, 39 | "end": { 40 | "line": 1, 41 | "column": 13 42 | } 43 | }, 44 | "name": "test" 45 | }, 46 | "expression": false, 47 | "generator": false, 48 | "async": false, 49 | "params": [], 50 | "returnType": { 51 | "type": "TSTypeAnnotation", 52 | "start": 15, 53 | "end": 23, 54 | "loc": { 55 | "start": { 56 | "line": 1, 57 | "column": 15 58 | }, 59 | "end": { 60 | "line": 1, 61 | "column": 23 62 | } 63 | }, 64 | "typeAnnotation": { 65 | "type": "TSNumberKeyword", 66 | "start": 17, 67 | "end": 23, 68 | "loc": { 69 | "start": { 70 | "line": 1, 71 | "column": 17 72 | }, 73 | "end": { 74 | "line": 1, 75 | "column": 23 76 | } 77 | } 78 | } 79 | }, 80 | "body": { 81 | "type": "BlockStatement", 82 | "start": 24, 83 | "end": 40, 84 | "loc": { 85 | "start": { 86 | "line": 1, 87 | "column": 24 88 | }, 89 | "end": { 90 | "line": 3, 91 | "column": 1 92 | } 93 | }, 94 | "body": [ 95 | { 96 | "type": "ReturnStatement", 97 | "start": 28, 98 | "end": 38, 99 | "loc": { 100 | "start": { 101 | "line": 2, 102 | "column": 2 103 | }, 104 | "end": { 105 | "line": 2, 106 | "column": 12 107 | } 108 | }, 109 | "argument": { 110 | "type": "Literal", 111 | "start": 35, 112 | "end": 38, 113 | "loc": { 114 | "start": { 115 | "line": 2, 116 | "column": 9 117 | }, 118 | "end": { 119 | "line": 2, 120 | "column": 12 121 | } 122 | }, 123 | "value": 123, 124 | "raw": "123" 125 | } 126 | } 127 | ] 128 | } 129 | } 130 | ], 131 | "sourceType": "module" 132 | } 133 | -------------------------------------------------------------------------------- /test/function_type_test_no_parameter_with_string/expected.json: -------------------------------------------------------------------------------- 1 | { 2 | "type": "Program", 3 | "start": 0, 4 | "end": 42, 5 | "loc": { 6 | "start": { 7 | "line": 1, 8 | "column": 0 9 | }, 10 | "end": { 11 | "line": 3, 12 | "column": 1 13 | } 14 | }, 15 | "body": [ 16 | { 17 | "type": "FunctionDeclaration", 18 | "start": 0, 19 | "end": 42, 20 | "loc": { 21 | "start": { 22 | "line": 1, 23 | "column": 0 24 | }, 25 | "end": { 26 | "line": 3, 27 | "column": 1 28 | } 29 | }, 30 | "id": { 31 | "type": "Identifier", 32 | "start": 9, 33 | "end": 13, 34 | "loc": { 35 | "start": { 36 | "line": 1, 37 | "column": 9 38 | }, 39 | "end": { 40 | "line": 1, 41 | "column": 13 42 | } 43 | }, 44 | "name": "test" 45 | }, 46 | "expression": false, 47 | "generator": false, 48 | "async": false, 49 | "params": [], 50 | "returnType": { 51 | "type": "TSTypeAnnotation", 52 | "start": 15, 53 | "end": 23, 54 | "loc": { 55 | "start": { 56 | "line": 1, 57 | "column": 15 58 | }, 59 | "end": { 60 | "line": 1, 61 | "column": 23 62 | } 63 | }, 64 | "typeAnnotation": { 65 | "type": "TSStringKeyword", 66 | "start": 17, 67 | "end": 23, 68 | "loc": { 69 | "start": { 70 | "line": 1, 71 | "column": 17 72 | }, 73 | "end": { 74 | "line": 1, 75 | "column": 23 76 | } 77 | } 78 | } 79 | }, 80 | "body": { 81 | "type": "BlockStatement", 82 | "start": 24, 83 | "end": 42, 84 | "loc": { 85 | "start": { 86 | "line": 1, 87 | "column": 24 88 | }, 89 | "end": { 90 | "line": 3, 91 | "column": 1 92 | } 93 | }, 94 | "body": [ 95 | { 96 | "type": "ReturnStatement", 97 | "start": 28, 98 | "end": 40, 99 | "loc": { 100 | "start": { 101 | "line": 2, 102 | "column": 2 103 | }, 104 | "end": { 105 | "line": 2, 106 | "column": 14 107 | } 108 | }, 109 | "argument": { 110 | "type": "Literal", 111 | "start": 35, 112 | "end": 40, 113 | "loc": { 114 | "start": { 115 | "line": 2, 116 | "column": 9 117 | }, 118 | "end": { 119 | "line": 2, 120 | "column": 14 121 | } 122 | }, 123 | "value": "123", 124 | "raw": "'123'" 125 | } 126 | } 127 | ] 128 | } 129 | } 130 | ], 131 | "sourceType": "module" 132 | } 133 | -------------------------------------------------------------------------------- /test/function_type_test_no_parameter_with_unknown/expected.json: -------------------------------------------------------------------------------- 1 | { 2 | "type": "Program", 3 | "start": 0, 4 | "end": 41, 5 | "loc": { 6 | "start": { 7 | "line": 1, 8 | "column": 0 9 | }, 10 | "end": { 11 | "line": 3, 12 | "column": 1 13 | } 14 | }, 15 | "body": [ 16 | { 17 | "type": "FunctionDeclaration", 18 | "start": 0, 19 | "end": 41, 20 | "loc": { 21 | "start": { 22 | "line": 1, 23 | "column": 0 24 | }, 25 | "end": { 26 | "line": 3, 27 | "column": 1 28 | } 29 | }, 30 | "id": { 31 | "type": "Identifier", 32 | "start": 9, 33 | "end": 13, 34 | "loc": { 35 | "start": { 36 | "line": 1, 37 | "column": 9 38 | }, 39 | "end": { 40 | "line": 1, 41 | "column": 13 42 | } 43 | }, 44 | "name": "test" 45 | }, 46 | "expression": false, 47 | "generator": false, 48 | "async": false, 49 | "params": [], 50 | "returnType": { 51 | "type": "TSTypeAnnotation", 52 | "start": 15, 53 | "end": 24, 54 | "loc": { 55 | "start": { 56 | "line": 1, 57 | "column": 15 58 | }, 59 | "end": { 60 | "line": 1, 61 | "column": 24 62 | } 63 | }, 64 | "typeAnnotation": { 65 | "type": "TSUnknownKeyword", 66 | "start": 17, 67 | "end": 24, 68 | "loc": { 69 | "start": { 70 | "line": 1, 71 | "column": 17 72 | }, 73 | "end": { 74 | "line": 1, 75 | "column": 24 76 | } 77 | } 78 | } 79 | }, 80 | "body": { 81 | "type": "BlockStatement", 82 | "start": 25, 83 | "end": 41, 84 | "loc": { 85 | "start": { 86 | "line": 1, 87 | "column": 25 88 | }, 89 | "end": { 90 | "line": 3, 91 | "column": 1 92 | } 93 | }, 94 | "body": [ 95 | { 96 | "type": "ReturnStatement", 97 | "start": 29, 98 | "end": 39, 99 | "loc": { 100 | "start": { 101 | "line": 2, 102 | "column": 2 103 | }, 104 | "end": { 105 | "line": 2, 106 | "column": 12 107 | } 108 | }, 109 | "argument": { 110 | "type": "Literal", 111 | "start": 36, 112 | "end": 39, 113 | "loc": { 114 | "start": { 115 | "line": 2, 116 | "column": 9 117 | }, 118 | "end": { 119 | "line": 2, 120 | "column": 12 121 | } 122 | }, 123 | "value": 123, 124 | "raw": "123" 125 | } 126 | } 127 | ] 128 | } 129 | } 130 | ], 131 | "sourceType": "module" 132 | } 133 | -------------------------------------------------------------------------------- /test/assert_import_assert/expected.json: -------------------------------------------------------------------------------- 1 | { 2 | "type": "Program", 3 | "start": 0, 4 | "end": 54, 5 | "loc": { 6 | "start": { 7 | "line": 1, 8 | "column": 0 9 | }, 10 | "end": { 11 | "line": 1, 12 | "column": 54 13 | } 14 | }, 15 | "body": [ 16 | { 17 | "type": "ImportDeclaration", 18 | "start": 0, 19 | "end": 54, 20 | "loc": { 21 | "start": { 22 | "line": 1, 23 | "column": 0 24 | }, 25 | "end": { 26 | "line": 1, 27 | "column": 54 28 | } 29 | }, 30 | "importKind": "value", 31 | "specifiers": [ 32 | { 33 | "type": "ImportDefaultSpecifier", 34 | "start": 7, 35 | "end": 11, 36 | "loc": { 37 | "start": { 38 | "line": 1, 39 | "column": 7 40 | }, 41 | "end": { 42 | "line": 1, 43 | "column": 11 44 | } 45 | }, 46 | "local": { 47 | "type": "Identifier", 48 | "start": 7, 49 | "end": 11, 50 | "loc": { 51 | "start": { 52 | "line": 1, 53 | "column": 7 54 | }, 55 | "end": { 56 | "line": 1, 57 | "column": 11 58 | } 59 | }, 60 | "name": "json" 61 | } 62 | } 63 | ], 64 | "source": { 65 | "type": "Literal", 66 | "start": 17, 67 | "end": 29, 68 | "loc": { 69 | "start": { 70 | "line": 1, 71 | "column": 17 72 | }, 73 | "end": { 74 | "line": 1, 75 | "column": 29 76 | } 77 | }, 78 | "value": "./foo.json", 79 | "raw": "'./foo.json'" 80 | }, 81 | "attributes": [ 82 | { 83 | "type": "ImportAttribute", 84 | "start": 39, 85 | "end": 51, 86 | "loc": { 87 | "start": { 88 | "line": 1, 89 | "column": 39 90 | }, 91 | "end": { 92 | "line": 1, 93 | "column": 51 94 | } 95 | }, 96 | "key": { 97 | "type": "Identifier", 98 | "start": 39, 99 | "end": 43, 100 | "loc": { 101 | "start": { 102 | "line": 1, 103 | "column": 39 104 | }, 105 | "end": { 106 | "line": 1, 107 | "column": 43 108 | } 109 | }, 110 | "name": "type" 111 | }, 112 | "value": { 113 | "type": "Literal", 114 | "start": 45, 115 | "end": 51, 116 | "loc": { 117 | "start": { 118 | "line": 1, 119 | "column": 45 120 | }, 121 | "end": { 122 | "line": 1, 123 | "column": 51 124 | } 125 | }, 126 | "value": "json", 127 | "raw": "'json'" 128 | } 129 | } 130 | ] 131 | } 132 | ], 133 | "sourceType": "module" 134 | } 135 | -------------------------------------------------------------------------------- /test/assert_import_with/expected.json: -------------------------------------------------------------------------------- 1 | { 2 | "type": "Program", 3 | "start": 0, 4 | "end": 52, 5 | "loc": { 6 | "start": { 7 | "line": 1, 8 | "column": 0 9 | }, 10 | "end": { 11 | "line": 1, 12 | "column": 52 13 | } 14 | }, 15 | "body": [ 16 | { 17 | "type": "ImportDeclaration", 18 | "start": 0, 19 | "end": 52, 20 | "loc": { 21 | "start": { 22 | "line": 1, 23 | "column": 0 24 | }, 25 | "end": { 26 | "line": 1, 27 | "column": 52 28 | } 29 | }, 30 | "importKind": "value", 31 | "specifiers": [ 32 | { 33 | "type": "ImportDefaultSpecifier", 34 | "start": 7, 35 | "end": 11, 36 | "loc": { 37 | "start": { 38 | "line": 1, 39 | "column": 7 40 | }, 41 | "end": { 42 | "line": 1, 43 | "column": 11 44 | } 45 | }, 46 | "local": { 47 | "type": "Identifier", 48 | "start": 7, 49 | "end": 11, 50 | "loc": { 51 | "start": { 52 | "line": 1, 53 | "column": 7 54 | }, 55 | "end": { 56 | "line": 1, 57 | "column": 11 58 | } 59 | }, 60 | "name": "json" 61 | } 62 | } 63 | ], 64 | "source": { 65 | "type": "Literal", 66 | "start": 17, 67 | "end": 29, 68 | "loc": { 69 | "start": { 70 | "line": 1, 71 | "column": 17 72 | }, 73 | "end": { 74 | "line": 1, 75 | "column": 29 76 | } 77 | }, 78 | "value": "./foo.json", 79 | "raw": "'./foo.json'" 80 | }, 81 | "attributes": [ 82 | { 83 | "type": "ImportAttribute", 84 | "start": 37, 85 | "end": 49, 86 | "loc": { 87 | "start": { 88 | "line": 1, 89 | "column": 37 90 | }, 91 | "end": { 92 | "line": 1, 93 | "column": 49 94 | } 95 | }, 96 | "key": { 97 | "type": "Identifier", 98 | "start": 37, 99 | "end": 41, 100 | "loc": { 101 | "start": { 102 | "line": 1, 103 | "column": 37 104 | }, 105 | "end": { 106 | "line": 1, 107 | "column": 41 108 | } 109 | }, 110 | "name": "type" 111 | }, 112 | "value": { 113 | "type": "Literal", 114 | "start": 43, 115 | "end": 49, 116 | "loc": { 117 | "start": { 118 | "line": 1, 119 | "column": 43 120 | }, 121 | "end": { 122 | "line": 1, 123 | "column": 49 124 | } 125 | }, 126 | "value": "json", 127 | "raw": "'json'" 128 | } 129 | } 130 | ] 131 | } 132 | ], 133 | "sourceType": "module" 134 | } 135 | -------------------------------------------------------------------------------- /test/normal_syntax_import_type_specifier_with_as/expected.json: -------------------------------------------------------------------------------- 1 | { 2 | "type": "Program", 3 | "start": 0, 4 | "end": 46, 5 | "loc": { 6 | "start": { 7 | "line": 1, 8 | "column": 0 9 | }, 10 | "end": { 11 | "line": 1, 12 | "column": 46 13 | } 14 | }, 15 | "body": [ 16 | { 17 | "type": "ImportDeclaration", 18 | "start": 0, 19 | "end": 46, 20 | "loc": { 21 | "start": { 22 | "line": 1, 23 | "column": 0 24 | }, 25 | "end": { 26 | "line": 1, 27 | "column": 46 28 | } 29 | }, 30 | "importKind": "value", 31 | "specifiers": [ 32 | { 33 | "type": "ImportDefaultSpecifier", 34 | "start": 7, 35 | "end": 11, 36 | "loc": { 37 | "start": { 38 | "line": 1, 39 | "column": 7 40 | }, 41 | "end": { 42 | "line": 1, 43 | "column": 11 44 | } 45 | }, 46 | "local": { 47 | "type": "Identifier", 48 | "start": 7, 49 | "end": 11, 50 | "loc": { 51 | "start": { 52 | "line": 1, 53 | "column": 7 54 | }, 55 | "end": { 56 | "line": 1, 57 | "column": 11 58 | } 59 | }, 60 | "name": "test" 61 | } 62 | }, 63 | { 64 | "type": "ImportSpecifier", 65 | "start": 15, 66 | "end": 26, 67 | "loc": { 68 | "start": { 69 | "line": 1, 70 | "column": 15 71 | }, 72 | "end": { 73 | "line": 1, 74 | "column": 26 75 | } 76 | }, 77 | "imported": { 78 | "type": "Identifier", 79 | "start": 15, 80 | "end": 19, 81 | "loc": { 82 | "start": { 83 | "line": 1, 84 | "column": 15 85 | }, 86 | "end": { 87 | "line": 1, 88 | "column": 19 89 | } 90 | }, 91 | "name": "type" 92 | }, 93 | "local": { 94 | "type": "Identifier", 95 | "start": 23, 96 | "end": 26, 97 | "loc": { 98 | "start": { 99 | "line": 1, 100 | "column": 23 101 | }, 102 | "end": { 103 | "line": 1, 104 | "column": 26 105 | } 106 | }, 107 | "name": "age" 108 | }, 109 | "importKind": "value" 110 | } 111 | ], 112 | "source": { 113 | "type": "Literal", 114 | "start": 34, 115 | "end": 46, 116 | "loc": { 117 | "start": { 118 | "line": 1, 119 | "column": 34 120 | }, 121 | "end": { 122 | "line": 1, 123 | "column": 46 124 | } 125 | }, 126 | "value": "./index.js", 127 | "raw": "'./index.js'" 128 | } 129 | } 130 | ], 131 | "sourceType": "module" 132 | } 133 | -------------------------------------------------------------------------------- /test/class_escaped_keyword_property/expected.json: -------------------------------------------------------------------------------- 1 | { 2 | "type": "Program", 3 | "start": 0, 4 | "end": 28, 5 | "loc": { 6 | "start": { 7 | "line": 1, 8 | "column": 0 9 | }, 10 | "end": { 11 | "line": 3, 12 | "column": 1 13 | } 14 | }, 15 | "body": [ 16 | { 17 | "type": "ClassDeclaration", 18 | "start": 0, 19 | "end": 28, 20 | "loc": { 21 | "start": { 22 | "line": 1, 23 | "column": 0 24 | }, 25 | "end": { 26 | "line": 3, 27 | "column": 1 28 | } 29 | }, 30 | "id": { 31 | "type": "Identifier", 32 | "start": 6, 33 | "end": 7, 34 | "loc": { 35 | "start": { 36 | "line": 1, 37 | "column": 6 38 | }, 39 | "end": { 40 | "line": 1, 41 | "column": 7 42 | } 43 | }, 44 | "name": "C" 45 | }, 46 | "superClass": null, 47 | "body": { 48 | "type": "ClassBody", 49 | "start": 8, 50 | "end": 28, 51 | "loc": { 52 | "start": { 53 | "line": 1, 54 | "column": 8 55 | }, 56 | "end": { 57 | "line": 3, 58 | "column": 1 59 | } 60 | }, 61 | "body": [ 62 | { 63 | "type": "PropertyDefinition", 64 | "start": 11, 65 | "end": 26, 66 | "loc": { 67 | "start": { 68 | "line": 2, 69 | "column": 1 70 | }, 71 | "end": { 72 | "line": 2, 73 | "column": 16 74 | } 75 | }, 76 | "static": false, 77 | "computed": false, 78 | "key": { 79 | "type": "Identifier", 80 | "start": 11, 81 | "end": 18, 82 | "loc": { 83 | "start": { 84 | "line": 2, 85 | "column": 1 86 | }, 87 | "end": { 88 | "line": 2, 89 | "column": 8 90 | } 91 | }, 92 | "name": "in" 93 | }, 94 | "typeAnnotation": { 95 | "type": "TSTypeAnnotation", 96 | "start": 18, 97 | "end": 26, 98 | "loc": { 99 | "start": { 100 | "line": 2, 101 | "column": 8 102 | }, 103 | "end": { 104 | "line": 2, 105 | "column": 16 106 | } 107 | }, 108 | "typeAnnotation": { 109 | "type": "TSStringKeyword", 110 | "start": 20, 111 | "end": 26, 112 | "loc": { 113 | "start": { 114 | "line": 2, 115 | "column": 10 116 | }, 117 | "end": { 118 | "line": 2, 119 | "column": 16 120 | } 121 | } 122 | } 123 | }, 124 | "value": null 125 | } 126 | ] 127 | } 128 | } 129 | ], 130 | "sourceType": "module" 131 | } 132 | -------------------------------------------------------------------------------- /test/class_definite_property/expected.json: -------------------------------------------------------------------------------- 1 | { 2 | "type": "Program", 3 | "start": 0, 4 | "end": 32, 5 | "loc": { 6 | "start": { 7 | "line": 1, 8 | "column": 0 9 | }, 10 | "end": { 11 | "line": 3, 12 | "column": 1 13 | } 14 | }, 15 | "body": [ 16 | { 17 | "type": "ClassDeclaration", 18 | "start": 0, 19 | "end": 32, 20 | "loc": { 21 | "start": { 22 | "line": 1, 23 | "column": 0 24 | }, 25 | "end": { 26 | "line": 3, 27 | "column": 1 28 | } 29 | }, 30 | "id": { 31 | "type": "Identifier", 32 | "start": 6, 33 | "end": 13, 34 | "loc": { 35 | "start": { 36 | "line": 1, 37 | "column": 6 38 | }, 39 | "end": { 40 | "line": 1, 41 | "column": 13 42 | } 43 | }, 44 | "name": "Student" 45 | }, 46 | "superClass": null, 47 | "body": { 48 | "type": "ClassBody", 49 | "start": 14, 50 | "end": 32, 51 | "loc": { 52 | "start": { 53 | "line": 1, 54 | "column": 14 55 | }, 56 | "end": { 57 | "line": 3, 58 | "column": 1 59 | } 60 | }, 61 | "body": [ 62 | { 63 | "type": "PropertyDefinition", 64 | "start": 17, 65 | "end": 30, 66 | "loc": { 67 | "start": { 68 | "line": 2, 69 | "column": 1 70 | }, 71 | "end": { 72 | "line": 2, 73 | "column": 14 74 | } 75 | }, 76 | "static": false, 77 | "computed": false, 78 | "key": { 79 | "type": "Identifier", 80 | "start": 17, 81 | "end": 21, 82 | "loc": { 83 | "start": { 84 | "line": 2, 85 | "column": 1 86 | }, 87 | "end": { 88 | "line": 2, 89 | "column": 5 90 | } 91 | }, 92 | "name": "name" 93 | }, 94 | "definite": true, 95 | "typeAnnotation": { 96 | "type": "TSTypeAnnotation", 97 | "start": 22, 98 | "end": 30, 99 | "loc": { 100 | "start": { 101 | "line": 2, 102 | "column": 6 103 | }, 104 | "end": { 105 | "line": 2, 106 | "column": 14 107 | } 108 | }, 109 | "typeAnnotation": { 110 | "type": "TSStringKeyword", 111 | "start": 24, 112 | "end": 30, 113 | "loc": { 114 | "start": { 115 | "line": 2, 116 | "column": 8 117 | }, 118 | "end": { 119 | "line": 2, 120 | "column": 14 121 | } 122 | } 123 | } 124 | }, 125 | "value": null 126 | } 127 | ] 128 | } 129 | } 130 | ], 131 | "sourceType": "module" 132 | } 133 | -------------------------------------------------------------------------------- /test/plugin.test.ts: -------------------------------------------------------------------------------- 1 | import { describe, it, expect } from 'vitest'; 2 | import * as acorn from 'acorn'; 3 | import { tsPlugin } from '../src'; 4 | import type { AcornTypeScript } from '../src/types'; 5 | 6 | function checkAcornTypeScriptUndefined(acornTypeScript?: AcornTypeScript): boolean { 7 | if (!acornTypeScript) return false; 8 | 9 | return ( 10 | Boolean(acornTypeScript.tokTypes) && 11 | Boolean(acornTypeScript.keywordsRegExp) && 12 | Boolean(acornTypeScript.tokenIsLiteralPropertyName) && 13 | Boolean(acornTypeScript.tokenIsKeywordOrIdentifier) && 14 | Boolean(acornTypeScript.tokenIsIdentifier) && 15 | Boolean(acornTypeScript.tokenIsTSDeclarationStart) && 16 | Boolean(acornTypeScript.tokenIsTSTypeOperator) && 17 | Boolean(acornTypeScript.tokenIsTemplate) 18 | ); 19 | } 20 | 21 | function checkAcornTypeScriptEqual( 22 | acornTypeScriptOne?: AcornTypeScript, 23 | acornTypeScriptTwo?: AcornTypeScript 24 | ): boolean { 25 | if (!acornTypeScriptTwo || !acornTypeScriptOne) return false; 26 | if ( 27 | !checkAcornTypeScriptUndefined(acornTypeScriptOne) || 28 | !checkAcornTypeScriptUndefined(acornTypeScriptTwo) 29 | ) 30 | return false; 31 | 32 | return ( 33 | acornTypeScriptOne.tokTypes === acornTypeScriptTwo.tokTypes && 34 | acornTypeScriptOne.keywordsRegExp === acornTypeScriptTwo.keywordsRegExp && 35 | acornTypeScriptOne.tokenIsLiteralPropertyName === 36 | acornTypeScriptTwo.tokenIsLiteralPropertyName && 37 | acornTypeScriptOne.tokenIsKeywordOrIdentifier === 38 | acornTypeScriptTwo.tokenIsKeywordOrIdentifier && 39 | acornTypeScriptOne.tokenIsIdentifier === acornTypeScriptTwo.tokenIsIdentifier && 40 | acornTypeScriptOne.tokenIsTSDeclarationStart === acornTypeScriptTwo.tokenIsTSDeclarationStart && 41 | acornTypeScriptOne.tokenIsTSTypeOperator === acornTypeScriptTwo.tokenIsTSTypeOperator && 42 | acornTypeScriptOne.tokenIsTemplate === acornTypeScriptTwo.tokenIsTemplate 43 | ); 44 | } 45 | 46 | describe('static plugin', () => { 47 | it('acornTypeScript', () => { 48 | let acornTypeScript: any; 49 | acorn.Parser.extend(tsPlugin() as any, function (BaseParser) { 50 | acornTypeScript = (BaseParser as any).acornTypeScript; 51 | return BaseParser; 52 | }); 53 | 54 | expect(checkAcornTypeScriptUndefined(acornTypeScript)).toBe(true); 55 | }); 56 | 57 | it('acornTypeScript in two plugins', () => { 58 | let acornTypeScriptOne: any; 59 | let acornTypeScriptTwo: any; 60 | acorn.Parser.extend( 61 | tsPlugin() as any, 62 | function (BaseParser) { 63 | acornTypeScriptOne = (BaseParser as any).acornTypeScript; 64 | return BaseParser; 65 | }, 66 | function (BaseParser) { 67 | acornTypeScriptTwo = (BaseParser as any).acornTypeScript; 68 | return BaseParser; 69 | } 70 | ); 71 | 72 | expect(checkAcornTypeScriptEqual(acornTypeScriptOne, acornTypeScriptTwo)).toBe(true); 73 | }); 74 | }); 75 | -------------------------------------------------------------------------------- /test/variables_declaration_expression_equal_function/expected.json: -------------------------------------------------------------------------------- 1 | { 2 | "type": "Program", 3 | "start": 0, 4 | "end": 30, 5 | "loc": { 6 | "start": { 7 | "line": 1, 8 | "column": 0 9 | }, 10 | "end": { 11 | "line": 1, 12 | "column": 30 13 | } 14 | }, 15 | "body": [ 16 | { 17 | "type": "VariableDeclaration", 18 | "start": 0, 19 | "end": 30, 20 | "loc": { 21 | "start": { 22 | "line": 1, 23 | "column": 0 24 | }, 25 | "end": { 26 | "line": 1, 27 | "column": 30 28 | } 29 | }, 30 | "declarations": [ 31 | { 32 | "type": "VariableDeclarator", 33 | "start": 4, 34 | "end": 30, 35 | "loc": { 36 | "start": { 37 | "line": 1, 38 | "column": 4 39 | }, 40 | "end": { 41 | "line": 1, 42 | "column": 30 43 | } 44 | }, 45 | "id": { 46 | "type": "Identifier", 47 | "start": 4, 48 | "end": 8, 49 | "loc": { 50 | "start": { 51 | "line": 1, 52 | "column": 4 53 | }, 54 | "end": { 55 | "line": 1, 56 | "column": 8 57 | } 58 | }, 59 | "name": "test" 60 | }, 61 | "init": { 62 | "type": "FunctionExpression", 63 | "start": 11, 64 | "end": 30, 65 | "loc": { 66 | "start": { 67 | "line": 1, 68 | "column": 11 69 | }, 70 | "end": { 71 | "line": 1, 72 | "column": 30 73 | } 74 | }, 75 | "id": null, 76 | "expression": false, 77 | "generator": false, 78 | "async": false, 79 | "params": [], 80 | "returnType": { 81 | "type": "TSTypeAnnotation", 82 | "start": 21, 83 | "end": 27, 84 | "loc": { 85 | "start": { 86 | "line": 1, 87 | "column": 21 88 | }, 89 | "end": { 90 | "line": 1, 91 | "column": 27 92 | } 93 | }, 94 | "typeAnnotation": { 95 | "type": "TSVoidKeyword", 96 | "start": 23, 97 | "end": 27, 98 | "loc": { 99 | "start": { 100 | "line": 1, 101 | "column": 23 102 | }, 103 | "end": { 104 | "line": 1, 105 | "column": 27 106 | } 107 | } 108 | } 109 | }, 110 | "body": { 111 | "type": "BlockStatement", 112 | "start": 28, 113 | "end": 30, 114 | "loc": { 115 | "start": { 116 | "line": 1, 117 | "column": 28 118 | }, 119 | "end": { 120 | "line": 1, 121 | "column": 30 122 | } 123 | }, 124 | "body": [] 125 | } 126 | } 127 | } 128 | ], 129 | "kind": "let" 130 | } 131 | ], 132 | "sourceType": "module" 133 | } 134 | -------------------------------------------------------------------------------- /test/variables_declaration_expression_equal_arrow_function/expected.json: -------------------------------------------------------------------------------- 1 | { 2 | "type": "Program", 3 | "start": 0, 4 | "end": 25, 5 | "loc": { 6 | "start": { 7 | "line": 1, 8 | "column": 0 9 | }, 10 | "end": { 11 | "line": 1, 12 | "column": 25 13 | } 14 | }, 15 | "body": [ 16 | { 17 | "type": "VariableDeclaration", 18 | "start": 0, 19 | "end": 25, 20 | "loc": { 21 | "start": { 22 | "line": 1, 23 | "column": 0 24 | }, 25 | "end": { 26 | "line": 1, 27 | "column": 25 28 | } 29 | }, 30 | "declarations": [ 31 | { 32 | "type": "VariableDeclarator", 33 | "start": 4, 34 | "end": 25, 35 | "loc": { 36 | "start": { 37 | "line": 1, 38 | "column": 4 39 | }, 40 | "end": { 41 | "line": 1, 42 | "column": 25 43 | } 44 | }, 45 | "id": { 46 | "type": "Identifier", 47 | "start": 4, 48 | "end": 8, 49 | "loc": { 50 | "start": { 51 | "line": 1, 52 | "column": 4 53 | }, 54 | "end": { 55 | "line": 1, 56 | "column": 8 57 | } 58 | }, 59 | "name": "test" 60 | }, 61 | "init": { 62 | "type": "ArrowFunctionExpression", 63 | "start": 11, 64 | "end": 25, 65 | "loc": { 66 | "start": { 67 | "line": 1, 68 | "column": 11 69 | }, 70 | "end": { 71 | "line": 1, 72 | "column": 25 73 | } 74 | }, 75 | "returnType": { 76 | "type": "TSTypeAnnotation", 77 | "start": 13, 78 | "end": 19, 79 | "loc": { 80 | "start": { 81 | "line": 1, 82 | "column": 13 83 | }, 84 | "end": { 85 | "line": 1, 86 | "column": 19 87 | } 88 | }, 89 | "typeAnnotation": { 90 | "type": "TSVoidKeyword", 91 | "start": 15, 92 | "end": 19, 93 | "loc": { 94 | "start": { 95 | "line": 1, 96 | "column": 15 97 | }, 98 | "end": { 99 | "line": 1, 100 | "column": 19 101 | } 102 | } 103 | } 104 | }, 105 | "id": null, 106 | "expression": false, 107 | "generator": false, 108 | "async": false, 109 | "params": [], 110 | "body": { 111 | "type": "BlockStatement", 112 | "start": 23, 113 | "end": 25, 114 | "loc": { 115 | "start": { 116 | "line": 1, 117 | "column": 23 118 | }, 119 | "end": { 120 | "line": 1, 121 | "column": 25 122 | } 123 | }, 124 | "body": [] 125 | } 126 | } 127 | } 128 | ], 129 | "kind": "let" 130 | } 131 | ], 132 | "sourceType": "module" 133 | } 134 | -------------------------------------------------------------------------------- /test/type_casts_number1_label/expected.json: -------------------------------------------------------------------------------- 1 | { 2 | "type": "Program", 3 | "start": 0, 4 | "end": 19, 5 | "loc": { 6 | "start": { 7 | "line": 1, 8 | "column": 0 9 | }, 10 | "end": { 11 | "line": 1, 12 | "column": 19 13 | } 14 | }, 15 | "body": [ 16 | { 17 | "type": "LabeledStatement", 18 | "start": 0, 19 | "end": 19, 20 | "loc": { 21 | "start": { 22 | "line": 1, 23 | "column": 0 24 | }, 25 | "end": { 26 | "line": 1, 27 | "column": 19 28 | } 29 | }, 30 | "body": { 31 | "type": "ExpressionStatement", 32 | "start": 3, 33 | "end": 19, 34 | "loc": { 35 | "start": { 36 | "line": 1, 37 | "column": 3 38 | }, 39 | "end": { 40 | "line": 1, 41 | "column": 19 42 | } 43 | }, 44 | "expression": { 45 | "type": "AssignmentExpression", 46 | "start": 3, 47 | "end": 19, 48 | "loc": { 49 | "start": { 50 | "line": 1, 51 | "column": 3 52 | }, 53 | "end": { 54 | "line": 1, 55 | "column": 19 56 | } 57 | }, 58 | "operator": "=", 59 | "left": { 60 | "type": "Identifier", 61 | "start": 3, 62 | "end": 7, 63 | "loc": { 64 | "start": { 65 | "line": 1, 66 | "column": 3 67 | }, 68 | "end": { 69 | "line": 1, 70 | "column": 7 71 | } 72 | }, 73 | "name": "test" 74 | }, 75 | "right": { 76 | "type": "TSTypeAssertion", 77 | "start": 10, 78 | "end": 19, 79 | "loc": { 80 | "start": { 81 | "line": 1, 82 | "column": 10 83 | }, 84 | "end": { 85 | "line": 1, 86 | "column": 19 87 | } 88 | }, 89 | "typeAnnotation": { 90 | "type": "TSNumberKeyword", 91 | "start": 11, 92 | "end": 17, 93 | "loc": { 94 | "start": { 95 | "line": 1, 96 | "column": 11 97 | }, 98 | "end": { 99 | "line": 1, 100 | "column": 17 101 | } 102 | } 103 | }, 104 | "expression": { 105 | "type": "Literal", 106 | "start": 18, 107 | "end": 19, 108 | "loc": { 109 | "start": { 110 | "line": 1, 111 | "column": 18 112 | }, 113 | "end": { 114 | "line": 1, 115 | "column": 19 116 | } 117 | }, 118 | "value": 1, 119 | "raw": "1" 120 | } 121 | } 122 | } 123 | }, 124 | "label": { 125 | "type": "Identifier", 126 | "start": 0, 127 | "end": 1, 128 | "loc": { 129 | "start": { 130 | "line": 1, 131 | "column": 0 132 | }, 133 | "end": { 134 | "line": 1, 135 | "column": 1 136 | } 137 | }, 138 | "name": "$" 139 | } 140 | } 141 | ], 142 | "sourceType": "module" 143 | } 144 | -------------------------------------------------------------------------------- /test/type_casts_1_as_number_label/expected.json: -------------------------------------------------------------------------------- 1 | { 2 | "type": "Program", 3 | "start": 0, 4 | "end": 21, 5 | "loc": { 6 | "start": { 7 | "line": 1, 8 | "column": 0 9 | }, 10 | "end": { 11 | "line": 1, 12 | "column": 21 13 | } 14 | }, 15 | "body": [ 16 | { 17 | "type": "LabeledStatement", 18 | "start": 0, 19 | "end": 21, 20 | "loc": { 21 | "start": { 22 | "line": 1, 23 | "column": 0 24 | }, 25 | "end": { 26 | "line": 1, 27 | "column": 21 28 | } 29 | }, 30 | "body": { 31 | "type": "ExpressionStatement", 32 | "start": 3, 33 | "end": 21, 34 | "loc": { 35 | "start": { 36 | "line": 1, 37 | "column": 3 38 | }, 39 | "end": { 40 | "line": 1, 41 | "column": 21 42 | } 43 | }, 44 | "expression": { 45 | "type": "AssignmentExpression", 46 | "start": 3, 47 | "end": 21, 48 | "loc": { 49 | "start": { 50 | "line": 1, 51 | "column": 3 52 | }, 53 | "end": { 54 | "line": 1, 55 | "column": 21 56 | } 57 | }, 58 | "operator": "=", 59 | "left": { 60 | "type": "Identifier", 61 | "start": 3, 62 | "end": 7, 63 | "loc": { 64 | "start": { 65 | "line": 1, 66 | "column": 3 67 | }, 68 | "end": { 69 | "line": 1, 70 | "column": 7 71 | } 72 | }, 73 | "name": "test" 74 | }, 75 | "right": { 76 | "type": "TSAsExpression", 77 | "start": 10, 78 | "end": 21, 79 | "loc": { 80 | "start": { 81 | "line": 1, 82 | "column": 10 83 | }, 84 | "end": { 85 | "line": 1, 86 | "column": 21 87 | } 88 | }, 89 | "expression": { 90 | "type": "Literal", 91 | "start": 10, 92 | "end": 11, 93 | "loc": { 94 | "start": { 95 | "line": 1, 96 | "column": 10 97 | }, 98 | "end": { 99 | "line": 1, 100 | "column": 11 101 | } 102 | }, 103 | "value": 1, 104 | "raw": "1" 105 | }, 106 | "typeAnnotation": { 107 | "type": "TSNumberKeyword", 108 | "start": 15, 109 | "end": 21, 110 | "loc": { 111 | "start": { 112 | "line": 1, 113 | "column": 15 114 | }, 115 | "end": { 116 | "line": 1, 117 | "column": 21 118 | } 119 | } 120 | } 121 | } 122 | } 123 | }, 124 | "label": { 125 | "type": "Identifier", 126 | "start": 0, 127 | "end": 1, 128 | "loc": { 129 | "start": { 130 | "line": 1, 131 | "column": 0 132 | }, 133 | "end": { 134 | "line": 1, 135 | "column": 1 136 | } 137 | }, 138 | "name": "$" 139 | } 140 | } 141 | ], 142 | "sourceType": "module" 143 | } 144 | -------------------------------------------------------------------------------- /test/arrow-function_type_test_async_generic_empty_params/expected.json: -------------------------------------------------------------------------------- 1 | { 2 | "type": "Program", 3 | "start": 0, 4 | "end": 46, 5 | "loc": { 6 | "start": { 7 | "line": 1, 8 | "column": 0 9 | }, 10 | "end": { 11 | "line": 1, 12 | "column": 46 13 | } 14 | }, 15 | "body": [ 16 | { 17 | "type": "VariableDeclaration", 18 | "start": 0, 19 | "end": 46, 20 | "loc": { 21 | "start": { 22 | "line": 1, 23 | "column": 0 24 | }, 25 | "end": { 26 | "line": 1, 27 | "column": 46 28 | } 29 | }, 30 | "declarations": [ 31 | { 32 | "type": "VariableDeclarator", 33 | "start": 6, 34 | "end": 45, 35 | "loc": { 36 | "start": { 37 | "line": 1, 38 | "column": 6 39 | }, 40 | "end": { 41 | "line": 1, 42 | "column": 45 43 | } 44 | }, 45 | "id": { 46 | "type": "Identifier", 47 | "start": 6, 48 | "end": 25, 49 | "loc": { 50 | "start": { 51 | "line": 1, 52 | "column": 6 53 | }, 54 | "end": { 55 | "line": 1, 56 | "column": 25 57 | } 58 | }, 59 | "name": "loadDataWithGeneric" 60 | }, 61 | "init": { 62 | "type": "ArrowFunctionExpression", 63 | "start": 28, 64 | "end": 45, 65 | "loc": { 66 | "start": { 67 | "line": 1, 68 | "column": 28 69 | }, 70 | "end": { 71 | "line": 1, 72 | "column": 45 73 | } 74 | }, 75 | "typeParameters": { 76 | "type": "TSTypeParameterDeclaration", 77 | "start": 34, 78 | "end": 37, 79 | "loc": { 80 | "start": { 81 | "line": 1, 82 | "column": 34 83 | }, 84 | "end": { 85 | "line": 1, 86 | "column": 37 87 | } 88 | }, 89 | "params": [ 90 | { 91 | "type": "TSTypeParameter", 92 | "start": 35, 93 | "end": 36, 94 | "loc": { 95 | "start": { 96 | "line": 1, 97 | "column": 35 98 | }, 99 | "end": { 100 | "line": 1, 101 | "column": 36 102 | } 103 | }, 104 | "name": "T" 105 | } 106 | ] 107 | }, 108 | "params": [], 109 | "id": null, 110 | "expression": false, 111 | "generator": false, 112 | "async": true, 113 | "body": { 114 | "type": "BlockStatement", 115 | "start": 43, 116 | "end": 45, 117 | "loc": { 118 | "start": { 119 | "line": 1, 120 | "column": 43 121 | }, 122 | "end": { 123 | "line": 1, 124 | "column": 45 125 | } 126 | }, 127 | "body": [] 128 | } 129 | } 130 | } 131 | ], 132 | "kind": "const" 133 | } 134 | ], 135 | "sourceType": "module" 136 | } 137 | -------------------------------------------------------------------------------- /test/arrow-function_type_test_async_generic_with_commented_import/expected.json: -------------------------------------------------------------------------------- 1 | { 2 | "type": "Program", 3 | "start": 0, 4 | "end": 76, 5 | "loc": { 6 | "start": { 7 | "line": 1, 8 | "column": 0 9 | }, 10 | "end": { 11 | "line": 3, 12 | "column": 46 13 | } 14 | }, 15 | "body": [ 16 | { 17 | "type": "VariableDeclaration", 18 | "start": 30, 19 | "end": 76, 20 | "loc": { 21 | "start": { 22 | "line": 3, 23 | "column": 0 24 | }, 25 | "end": { 26 | "line": 3, 27 | "column": 46 28 | } 29 | }, 30 | "declarations": [ 31 | { 32 | "type": "VariableDeclarator", 33 | "start": 36, 34 | "end": 75, 35 | "loc": { 36 | "start": { 37 | "line": 3, 38 | "column": 6 39 | }, 40 | "end": { 41 | "line": 3, 42 | "column": 45 43 | } 44 | }, 45 | "id": { 46 | "type": "Identifier", 47 | "start": 36, 48 | "end": 55, 49 | "loc": { 50 | "start": { 51 | "line": 3, 52 | "column": 6 53 | }, 54 | "end": { 55 | "line": 3, 56 | "column": 25 57 | } 58 | }, 59 | "name": "loadDataWithGeneric" 60 | }, 61 | "init": { 62 | "type": "ArrowFunctionExpression", 63 | "start": 58, 64 | "end": 75, 65 | "loc": { 66 | "start": { 67 | "line": 3, 68 | "column": 28 69 | }, 70 | "end": { 71 | "line": 3, 72 | "column": 45 73 | } 74 | }, 75 | "typeParameters": { 76 | "type": "TSTypeParameterDeclaration", 77 | "start": 64, 78 | "end": 67, 79 | "loc": { 80 | "start": { 81 | "line": 3, 82 | "column": 34 83 | }, 84 | "end": { 85 | "line": 3, 86 | "column": 37 87 | } 88 | }, 89 | "params": [ 90 | { 91 | "type": "TSTypeParameter", 92 | "start": 65, 93 | "end": 66, 94 | "loc": { 95 | "start": { 96 | "line": 3, 97 | "column": 35 98 | }, 99 | "end": { 100 | "line": 3, 101 | "column": 36 102 | } 103 | }, 104 | "name": "T" 105 | } 106 | ] 107 | }, 108 | "params": [], 109 | "id": null, 110 | "expression": false, 111 | "generator": false, 112 | "async": true, 113 | "body": { 114 | "type": "BlockStatement", 115 | "start": 73, 116 | "end": 75, 117 | "loc": { 118 | "start": { 119 | "line": 3, 120 | "column": 43 121 | }, 122 | "end": { 123 | "line": 3, 124 | "column": 45 125 | } 126 | }, 127 | "body": [] 128 | } 129 | } 130 | } 131 | ], 132 | "kind": "const" 133 | } 134 | ], 135 | "sourceType": "module" 136 | } 137 | -------------------------------------------------------------------------------- /test/expression_type_test_enum/expected.json: -------------------------------------------------------------------------------- 1 | { 2 | "type": "Program", 3 | "start": 0, 4 | "end": 46, 5 | "loc": { 6 | "start": { 7 | "line": 1, 8 | "column": 0 9 | }, 10 | "end": { 11 | "line": 4, 12 | "column": 1 13 | } 14 | }, 15 | "body": [ 16 | { 17 | "type": "TSEnumDeclaration", 18 | "start": 0, 19 | "end": 46, 20 | "loc": { 21 | "start": { 22 | "line": 1, 23 | "column": 0 24 | }, 25 | "end": { 26 | "line": 4, 27 | "column": 1 28 | } 29 | }, 30 | "id": { 31 | "type": "Identifier", 32 | "start": 5, 33 | "end": 9, 34 | "loc": { 35 | "start": { 36 | "line": 1, 37 | "column": 5 38 | }, 39 | "end": { 40 | "line": 1, 41 | "column": 9 42 | } 43 | }, 44 | "name": "Test" 45 | }, 46 | "members": [ 47 | { 48 | "type": "TSEnumMember", 49 | "start": 14, 50 | "end": 29, 51 | "loc": { 52 | "start": { 53 | "line": 2, 54 | "column": 2 55 | }, 56 | "end": { 57 | "line": 2, 58 | "column": 17 59 | } 60 | }, 61 | "id": { 62 | "type": "Identifier", 63 | "start": 14, 64 | "end": 19, 65 | "loc": { 66 | "start": { 67 | "line": 2, 68 | "column": 2 69 | }, 70 | "end": { 71 | "line": 2, 72 | "column": 7 73 | } 74 | }, 75 | "name": "Start" 76 | }, 77 | "initializer": { 78 | "type": "Literal", 79 | "start": 22, 80 | "end": 29, 81 | "loc": { 82 | "start": { 83 | "line": 2, 84 | "column": 10 85 | }, 86 | "end": { 87 | "line": 2, 88 | "column": 17 89 | } 90 | }, 91 | "value": "start", 92 | "raw": "'start'" 93 | } 94 | }, 95 | { 96 | "type": "TSEnumMember", 97 | "start": 33, 98 | "end": 44, 99 | "loc": { 100 | "start": { 101 | "line": 3, 102 | "column": 2 103 | }, 104 | "end": { 105 | "line": 3, 106 | "column": 13 107 | } 108 | }, 109 | "id": { 110 | "type": "Identifier", 111 | "start": 33, 112 | "end": 36, 113 | "loc": { 114 | "start": { 115 | "line": 3, 116 | "column": 2 117 | }, 118 | "end": { 119 | "line": 3, 120 | "column": 5 121 | } 122 | }, 123 | "name": "End" 124 | }, 125 | "initializer": { 126 | "type": "Literal", 127 | "start": 39, 128 | "end": 44, 129 | "loc": { 130 | "start": { 131 | "line": 3, 132 | "column": 8 133 | }, 134 | "end": { 135 | "line": 3, 136 | "column": 13 137 | } 138 | }, 139 | "value": "end", 140 | "raw": "'end'" 141 | } 142 | } 143 | ] 144 | } 145 | ], 146 | "sourceType": "module" 147 | } 148 | -------------------------------------------------------------------------------- /test/arrow-function_type_test_assignment_pattern/expected.json: -------------------------------------------------------------------------------- 1 | { 2 | "type": "Program", 3 | "start": 0, 4 | "end": 20, 5 | "loc": { 6 | "start": { 7 | "line": 1, 8 | "column": 0 9 | }, 10 | "end": { 11 | "line": 1, 12 | "column": 20 13 | } 14 | }, 15 | "body": [ 16 | { 17 | "type": "ExpressionStatement", 18 | "start": 0, 19 | "end": 20, 20 | "loc": { 21 | "start": { 22 | "line": 1, 23 | "column": 0 24 | }, 25 | "end": { 26 | "line": 1, 27 | "column": 20 28 | } 29 | }, 30 | "expression": { 31 | "type": "ArrowFunctionExpression", 32 | "start": 0, 33 | "end": 20, 34 | "loc": { 35 | "start": { 36 | "line": 1, 37 | "column": 0 38 | }, 39 | "end": { 40 | "line": 1, 41 | "column": 20 42 | } 43 | }, 44 | "returnType": { 45 | "type": "TSTypeAnnotation", 46 | "start": 8, 47 | "end": 14, 48 | "loc": { 49 | "start": { 50 | "line": 1, 51 | "column": 8 52 | }, 53 | "end": { 54 | "line": 1, 55 | "column": 14 56 | } 57 | }, 58 | "typeAnnotation": { 59 | "type": "TSVoidKeyword", 60 | "start": 10, 61 | "end": 14, 62 | "loc": { 63 | "start": { 64 | "line": 1, 65 | "column": 10 66 | }, 67 | "end": { 68 | "line": 1, 69 | "column": 14 70 | } 71 | } 72 | } 73 | }, 74 | "id": null, 75 | "expression": false, 76 | "generator": false, 77 | "async": false, 78 | "params": [ 79 | { 80 | "type": "AssignmentPattern", 81 | "start": 1, 82 | "end": 7, 83 | "loc": { 84 | "start": { 85 | "line": 1, 86 | "column": 1 87 | }, 88 | "end": { 89 | "line": 1, 90 | "column": 7 91 | } 92 | }, 93 | "left": { 94 | "type": "Identifier", 95 | "start": 1, 96 | "end": 2, 97 | "loc": { 98 | "start": { 99 | "line": 1, 100 | "column": 1 101 | }, 102 | "end": { 103 | "line": 1, 104 | "column": 2 105 | } 106 | }, 107 | "name": "x" 108 | }, 109 | "right": { 110 | "type": "Literal", 111 | "start": 5, 112 | "end": 7, 113 | "loc": { 114 | "start": { 115 | "line": 1, 116 | "column": 5 117 | }, 118 | "end": { 119 | "line": 1, 120 | "column": 7 121 | } 122 | }, 123 | "value": 42, 124 | "raw": "42" 125 | } 126 | } 127 | ], 128 | "body": { 129 | "type": "BlockStatement", 130 | "start": 18, 131 | "end": 20, 132 | "loc": { 133 | "start": { 134 | "line": 1, 135 | "column": 18 136 | }, 137 | "end": { 138 | "line": 1, 139 | "column": 20 140 | } 141 | }, 142 | "body": [] 143 | } 144 | } 145 | } 146 | ], 147 | "sourceType": "module" 148 | } 149 | -------------------------------------------------------------------------------- /test/normal_syntax_import_name_specifiers/expected.json: -------------------------------------------------------------------------------- 1 | { 2 | "type": "Program", 3 | "start": 0, 4 | "end": 39, 5 | "loc": { 6 | "start": { 7 | "line": 1, 8 | "column": 0 9 | }, 10 | "end": { 11 | "line": 1, 12 | "column": 39 13 | } 14 | }, 15 | "body": [ 16 | { 17 | "type": "ImportDeclaration", 18 | "start": 0, 19 | "end": 39, 20 | "loc": { 21 | "start": { 22 | "line": 1, 23 | "column": 0 24 | }, 25 | "end": { 26 | "line": 1, 27 | "column": 39 28 | } 29 | }, 30 | "importKind": "value", 31 | "specifiers": [ 32 | { 33 | "type": "ImportSpecifier", 34 | "start": 9, 35 | "end": 13, 36 | "loc": { 37 | "start": { 38 | "line": 1, 39 | "column": 9 40 | }, 41 | "end": { 42 | "line": 1, 43 | "column": 13 44 | } 45 | }, 46 | "imported": { 47 | "type": "Identifier", 48 | "start": 9, 49 | "end": 13, 50 | "loc": { 51 | "start": { 52 | "line": 1, 53 | "column": 9 54 | }, 55 | "end": { 56 | "line": 1, 57 | "column": 13 58 | } 59 | }, 60 | "name": "test" 61 | }, 62 | "local": { 63 | "type": "Identifier", 64 | "start": 9, 65 | "end": 13, 66 | "loc": { 67 | "start": { 68 | "line": 1, 69 | "column": 9 70 | }, 71 | "end": { 72 | "line": 1, 73 | "column": 13 74 | } 75 | }, 76 | "name": "test" 77 | }, 78 | "importKind": "value" 79 | }, 80 | { 81 | "type": "ImportSpecifier", 82 | "start": 15, 83 | "end": 19, 84 | "loc": { 85 | "start": { 86 | "line": 1, 87 | "column": 15 88 | }, 89 | "end": { 90 | "line": 1, 91 | "column": 19 92 | } 93 | }, 94 | "imported": { 95 | "type": "Identifier", 96 | "start": 15, 97 | "end": 19, 98 | "loc": { 99 | "start": { 100 | "line": 1, 101 | "column": 15 102 | }, 103 | "end": { 104 | "line": 1, 105 | "column": 19 106 | } 107 | }, 108 | "name": "name" 109 | }, 110 | "local": { 111 | "type": "Identifier", 112 | "start": 15, 113 | "end": 19, 114 | "loc": { 115 | "start": { 116 | "line": 1, 117 | "column": 15 118 | }, 119 | "end": { 120 | "line": 1, 121 | "column": 19 122 | } 123 | }, 124 | "name": "name" 125 | }, 126 | "importKind": "value" 127 | } 128 | ], 129 | "source": { 130 | "type": "Literal", 131 | "start": 27, 132 | "end": 39, 133 | "loc": { 134 | "start": { 135 | "line": 1, 136 | "column": 27 137 | }, 138 | "end": { 139 | "line": 1, 140 | "column": 39 141 | } 142 | }, 143 | "value": "./index.js", 144 | "raw": "'./index.js'" 145 | } 146 | } 147 | ], 148 | "sourceType": "module" 149 | } 150 | -------------------------------------------------------------------------------- /test/normal_identifier_test_export_identifier_as/expected.json: -------------------------------------------------------------------------------- 1 | { 2 | "type": "Program", 3 | "start": 0, 4 | "end": 34, 5 | "loc": { 6 | "start": { 7 | "line": 1, 8 | "column": 0 9 | }, 10 | "end": { 11 | "line": 2, 12 | "column": 21 13 | } 14 | }, 15 | "body": [ 16 | { 17 | "type": "VariableDeclaration", 18 | "start": 0, 19 | "end": 12, 20 | "loc": { 21 | "start": { 22 | "line": 1, 23 | "column": 0 24 | }, 25 | "end": { 26 | "line": 1, 27 | "column": 12 28 | } 29 | }, 30 | "declarations": [ 31 | { 32 | "type": "VariableDeclarator", 33 | "start": 4, 34 | "end": 11, 35 | "loc": { 36 | "start": { 37 | "line": 1, 38 | "column": 4 39 | }, 40 | "end": { 41 | "line": 1, 42 | "column": 11 43 | } 44 | }, 45 | "id": { 46 | "type": "Identifier", 47 | "start": 4, 48 | "end": 7, 49 | "loc": { 50 | "start": { 51 | "line": 1, 52 | "column": 4 53 | }, 54 | "end": { 55 | "line": 1, 56 | "column": 7 57 | } 58 | }, 59 | "name": "foo" 60 | }, 61 | "init": { 62 | "type": "Literal", 63 | "start": 10, 64 | "end": 11, 65 | "loc": { 66 | "start": { 67 | "line": 1, 68 | "column": 10 69 | }, 70 | "end": { 71 | "line": 1, 72 | "column": 11 73 | } 74 | }, 75 | "value": 8, 76 | "raw": "8" 77 | } 78 | } 79 | ], 80 | "kind": "var" 81 | }, 82 | { 83 | "type": "ExportNamedDeclaration", 84 | "start": 13, 85 | "end": 34, 86 | "loc": { 87 | "start": { 88 | "line": 2, 89 | "column": 0 90 | }, 91 | "end": { 92 | "line": 2, 93 | "column": 21 94 | } 95 | }, 96 | "exportKind": "value", 97 | "declaration": null, 98 | "specifiers": [ 99 | { 100 | "type": "ExportSpecifier", 101 | "start": 22, 102 | "end": 31, 103 | "loc": { 104 | "start": { 105 | "line": 2, 106 | "column": 9 107 | }, 108 | "end": { 109 | "line": 2, 110 | "column": 18 111 | } 112 | }, 113 | "local": { 114 | "type": "Identifier", 115 | "start": 22, 116 | "end": 25, 117 | "loc": { 118 | "start": { 119 | "line": 2, 120 | "column": 9 121 | }, 122 | "end": { 123 | "line": 2, 124 | "column": 12 125 | } 126 | }, 127 | "name": "foo" 128 | }, 129 | "exported": { 130 | "type": "Identifier", 131 | "start": 29, 132 | "end": 31, 133 | "loc": { 134 | "start": { 135 | "line": 2, 136 | "column": 16 137 | }, 138 | "end": { 139 | "line": 2, 140 | "column": 18 141 | } 142 | }, 143 | "name": "as" 144 | }, 145 | "exportKind": "value" 146 | } 147 | ], 148 | "source": null 149 | } 150 | ], 151 | "sourceType": "module" 152 | } 153 | --------------------------------------------------------------------------------