From 0a181cf37ea88b50d3e3fe1f1fd20c6baffced5c Mon Sep 17 00:00:00 2001 From: Tee Ming Chew Date: Thu, 25 Sep 2025 11:52:50 +0800 Subject: [PATCH 1/9] claude code fix --- src/index.ts | 8 +- .../expected.json | 136 ++++++++++++++++++ .../input.ts | 1 + 3 files changed, 144 insertions(+), 1 deletion(-) create mode 100644 test/arrow-function_type_test_async_generic_empty_params/expected.json create mode 100644 test/arrow-function_type_test_async_generic_empty_params/input.ts diff --git a/src/index.ts b/src/index.ts index 2fb8d40..ffcce5d 100644 --- a/src/index.ts +++ b/src/index.ts @@ -466,6 +466,8 @@ export function tsPlugin(options?: { node.typeParameters = this.tsParseTypeParameters(this.tsParseConstModifier); // Don't use overloaded parseFunctionParams which would look for "<" again. + // Initialize params array before calling parseFunctionParams + node.params = []; super.parseFunctionParams(node); node.returnType = this.tsTryParseTypeOrTypePredicateAnnotation(); @@ -481,7 +483,7 @@ export function tsPlugin(options?: { return super.parseArrowExpression( res, - /* params are already set */ null, + /* params are already set */ res.params, /* async */ true, /* forInit */ forInit ); @@ -3229,6 +3231,10 @@ export function tsPlugin(options?: { } toAssignableList(exprList: any[], isBinding: boolean): any { + if (!exprList) { + return exprList; // Return null/undefined as-is + } + for (let i = 0; i < exprList.length; i++) { const expr = exprList[i]; diff --git a/test/arrow-function_type_test_async_generic_empty_params/expected.json b/test/arrow-function_type_test_async_generic_empty_params/expected.json new file mode 100644 index 0000000..09a27c8 --- /dev/null +++ b/test/arrow-function_type_test_async_generic_empty_params/expected.json @@ -0,0 +1,136 @@ +{ + "type": "Program", + "start": 0, + "end": 46, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 46 + } + }, + "body": [ + { + "type": "VariableDeclaration", + "start": 0, + "end": 46, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 46 + } + }, + "declarations": [ + { + "type": "VariableDeclarator", + "start": 6, + "end": 45, + "loc": { + "start": { + "line": 1, + "column": 6 + }, + "end": { + "line": 1, + "column": 45 + } + }, + "id": { + "type": "Identifier", + "start": 6, + "end": 25, + "loc": { + "start": { + "line": 1, + "column": 6 + }, + "end": { + "line": 1, + "column": 25 + } + }, + "name": "loadDataWithGeneric" + }, + "init": { + "type": "ArrowFunctionExpression", + "start": 28, + "end": 45, + "loc": { + "start": { + "line": 1, + "column": 28 + }, + "end": { + "line": 1, + "column": 45 + } + }, + "typeParameters": { + "type": "TSTypeParameterDeclaration", + "start": 34, + "end": 37, + "loc": { + "start": { + "line": 1, + "column": 34 + }, + "end": { + "line": 1, + "column": 37 + } + }, + "params": [ + { + "type": "TSTypeParameter", + "start": 35, + "end": 36, + "loc": { + "start": { + "line": 1, + "column": 35 + }, + "end": { + "line": 1, + "column": 36 + } + }, + "name": "T" + } + ] + }, + "params": [], + "id": null, + "expression": false, + "generator": false, + "async": true, + "body": { + "type": "BlockStatement", + "start": 43, + "end": 45, + "loc": { + "start": { + "line": 1, + "column": 43 + }, + "end": { + "line": 1, + "column": 45 + } + }, + "body": [] + } + } + } + ], + "kind": "const" + } + ], + "sourceType": "module" +} diff --git a/test/arrow-function_type_test_async_generic_empty_params/input.ts b/test/arrow-function_type_test_async_generic_empty_params/input.ts new file mode 100644 index 0000000..a2182f8 --- /dev/null +++ b/test/arrow-function_type_test_async_generic_empty_params/input.ts @@ -0,0 +1 @@ +const loadDataWithGeneric = async () => {}; \ No newline at end of file From 8549146c8205e096f5490884e41dc1d43e8b2afe Mon Sep 17 00:00:00 2001 From: Tee Ming Chew Date: Thu, 25 Sep 2025 12:14:10 +0800 Subject: [PATCH 2/9] more claude code fixes and tests --- src/index.ts | 2 +- .../expected.json | 170 ++++++++++++++++++ .../input.ts | 3 + .../expected.json | 170 ++++++++++++++++++ .../input.ts | 4 + 5 files changed, 348 insertions(+), 1 deletion(-) create mode 100644 test/arrow-function_type_test_async_generic_after_import/expected.json create mode 100644 test/arrow-function_type_test_async_generic_after_import/input.ts create mode 100644 test/arrow-function_type_test_async_generic_with_import/expected.json create mode 100644 test/arrow-function_type_test_async_generic_with_import/input.ts diff --git a/src/index.ts b/src/index.ts index ffcce5d..c85bdc9 100644 --- a/src/index.ts +++ b/src/index.ts @@ -430,7 +430,7 @@ export function tsPlugin(options?: { return ( base.type === 'Identifier' && base.name === 'async' && - this.lastTokEndLoc.column === base.end && + this.lastTokEnd === base.end && !this.canInsertSemicolon() && base.end - base.start === 5 && base.start === this.potentialArrowAt diff --git a/test/arrow-function_type_test_async_generic_after_import/expected.json b/test/arrow-function_type_test_async_generic_after_import/expected.json new file mode 100644 index 0000000..48e4f9c --- /dev/null +++ b/test/arrow-function_type_test_async_generic_after_import/expected.json @@ -0,0 +1,170 @@ +{ + "type": "Program", + "start": 0, + "end": 73, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 3, + "column": 46 + } + }, + "body": [ + { + "type": "ImportDeclaration", + "start": 0, + "end": 25, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 25 + } + }, + "importKind": "value", + "specifiers": [], + "source": { + "type": "Literal", + "start": 15, + "end": 25, + "loc": { + "start": { + "line": 1, + "column": 15 + }, + "end": { + "line": 1, + "column": 25 + } + }, + "value": "./config", + "raw": "'./config'" + } + }, + { + "type": "VariableDeclaration", + "start": 27, + "end": 73, + "loc": { + "start": { + "line": 3, + "column": 0 + }, + "end": { + "line": 3, + "column": 46 + } + }, + "declarations": [ + { + "type": "VariableDeclarator", + "start": 33, + "end": 72, + "loc": { + "start": { + "line": 3, + "column": 6 + }, + "end": { + "line": 3, + "column": 45 + } + }, + "id": { + "type": "Identifier", + "start": 33, + "end": 52, + "loc": { + "start": { + "line": 3, + "column": 6 + }, + "end": { + "line": 3, + "column": 25 + } + }, + "name": "loadDataWithGeneric" + }, + "init": { + "type": "ArrowFunctionExpression", + "start": 55, + "end": 72, + "loc": { + "start": { + "line": 3, + "column": 28 + }, + "end": { + "line": 3, + "column": 45 + } + }, + "typeParameters": { + "type": "TSTypeParameterDeclaration", + "start": 61, + "end": 64, + "loc": { + "start": { + "line": 3, + "column": 34 + }, + "end": { + "line": 3, + "column": 37 + } + }, + "params": [ + { + "type": "TSTypeParameter", + "start": 62, + "end": 63, + "loc": { + "start": { + "line": 3, + "column": 35 + }, + "end": { + "line": 3, + "column": 36 + } + }, + "name": "T" + } + ] + }, + "params": [], + "id": null, + "expression": false, + "generator": false, + "async": true, + "body": { + "type": "BlockStatement", + "start": 70, + "end": 72, + "loc": { + "start": { + "line": 3, + "column": 43 + }, + "end": { + "line": 3, + "column": 45 + } + }, + "body": [] + } + } + } + ], + "kind": "const" + } + ], + "sourceType": "module" +} diff --git a/test/arrow-function_type_test_async_generic_after_import/input.ts b/test/arrow-function_type_test_async_generic_after_import/input.ts new file mode 100644 index 0000000..e3d493a --- /dev/null +++ b/test/arrow-function_type_test_async_generic_after_import/input.ts @@ -0,0 +1,3 @@ +import {} from './config' + +const loadDataWithGeneric = async () => {}; \ No newline at end of file diff --git a/test/arrow-function_type_test_async_generic_with_import/expected.json b/test/arrow-function_type_test_async_generic_with_import/expected.json new file mode 100644 index 0000000..fd478ae --- /dev/null +++ b/test/arrow-function_type_test_async_generic_with_import/expected.json @@ -0,0 +1,170 @@ +{ + "type": "Program", + "start": 0, + "end": 128, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 4, + "column": 46 + } + }, + "body": [ + { + "type": "ImportDeclaration", + "start": 55, + "end": 80, + "loc": { + "start": { + "line": 2, + "column": 0 + }, + "end": { + "line": 2, + "column": 25 + } + }, + "importKind": "value", + "specifiers": [], + "source": { + "type": "Literal", + "start": 70, + "end": 80, + "loc": { + "start": { + "line": 2, + "column": 15 + }, + "end": { + "line": 2, + "column": 25 + } + }, + "value": "./config", + "raw": "'./config'" + } + }, + { + "type": "VariableDeclaration", + "start": 82, + "end": 128, + "loc": { + "start": { + "line": 4, + "column": 0 + }, + "end": { + "line": 4, + "column": 46 + } + }, + "declarations": [ + { + "type": "VariableDeclarator", + "start": 88, + "end": 127, + "loc": { + "start": { + "line": 4, + "column": 6 + }, + "end": { + "line": 4, + "column": 45 + } + }, + "id": { + "type": "Identifier", + "start": 88, + "end": 107, + "loc": { + "start": { + "line": 4, + "column": 6 + }, + "end": { + "line": 4, + "column": 25 + } + }, + "name": "loadDataWithGeneric" + }, + "init": { + "type": "ArrowFunctionExpression", + "start": 110, + "end": 127, + "loc": { + "start": { + "line": 4, + "column": 28 + }, + "end": { + "line": 4, + "column": 45 + } + }, + "typeParameters": { + "type": "TSTypeParameterDeclaration", + "start": 116, + "end": 119, + "loc": { + "start": { + "line": 4, + "column": 34 + }, + "end": { + "line": 4, + "column": 37 + } + }, + "params": [ + { + "type": "TSTypeParameter", + "start": 117, + "end": 118, + "loc": { + "start": { + "line": 4, + "column": 35 + }, + "end": { + "line": 4, + "column": 36 + } + }, + "name": "T" + } + ] + }, + "params": [], + "id": null, + "expression": false, + "generator": false, + "async": true, + "body": { + "type": "BlockStatement", + "start": 125, + "end": 127, + "loc": { + "start": { + "line": 4, + "column": 43 + }, + "end": { + "line": 4, + "column": 45 + } + }, + "body": [] + } + } + } + ], + "kind": "const" + } + ], + "sourceType": "module" +} diff --git a/test/arrow-function_type_test_async_generic_with_import/input.ts b/test/arrow-function_type_test_async_generic_with_import/input.ts new file mode 100644 index 0000000..cbf2367 --- /dev/null +++ b/test/arrow-function_type_test_async_generic_with_import/input.ts @@ -0,0 +1,4 @@ +// removing the comment below yields a different error +import {} from './config' + +const loadDataWithGeneric = async () => {}; \ No newline at end of file From 678956f4bbb3a4cb979ee91b8139a5847e531307 Mon Sep 17 00:00:00 2001 From: Tee Ming Chew Date: Thu, 25 Sep 2025 17:01:24 +0800 Subject: [PATCH 3/9] wip --- src/index.ts | 8 +- .../expected.json | 170 ------------------ .../input.ts | 3 + .../expected.json | 170 ------------------ .../input.ts | 4 - 5 files changed, 6 insertions(+), 349 deletions(-) delete mode 100644 test/arrow-function_type_test_async_generic_after_import/expected.json create mode 100644 test/arrow-function_type_test_async_generic_with_commented_import/input.ts delete mode 100644 test/arrow-function_type_test_async_generic_with_import/expected.json delete mode 100644 test/arrow-function_type_test_async_generic_with_import/input.ts diff --git a/src/index.ts b/src/index.ts index c85bdc9..99a26cb 100644 --- a/src/index.ts +++ b/src/index.ts @@ -430,7 +430,7 @@ export function tsPlugin(options?: { return ( base.type === 'Identifier' && base.name === 'async' && - this.lastTokEnd === base.end && + this.lastTokEndLoc.column === base.end && !this.canInsertSemicolon() && base.end - base.start === 5 && base.start === this.potentialArrowAt @@ -466,8 +466,6 @@ export function tsPlugin(options?: { node.typeParameters = this.tsParseTypeParameters(this.tsParseConstModifier); // Don't use overloaded parseFunctionParams which would look for "<" again. - // Initialize params array before calling parseFunctionParams - node.params = []; super.parseFunctionParams(node); node.returnType = this.tsTryParseTypeOrTypePredicateAnnotation(); @@ -3232,9 +3230,9 @@ export function tsPlugin(options?: { toAssignableList(exprList: any[], isBinding: boolean): any { if (!exprList) { - return exprList; // Return null/undefined as-is + return exprList; } - + for (let i = 0; i < exprList.length; i++) { const expr = exprList[i]; diff --git a/test/arrow-function_type_test_async_generic_after_import/expected.json b/test/arrow-function_type_test_async_generic_after_import/expected.json deleted file mode 100644 index 48e4f9c..0000000 --- a/test/arrow-function_type_test_async_generic_after_import/expected.json +++ /dev/null @@ -1,170 +0,0 @@ -{ - "type": "Program", - "start": 0, - "end": 73, - "loc": { - "start": { - "line": 1, - "column": 0 - }, - "end": { - "line": 3, - "column": 46 - } - }, - "body": [ - { - "type": "ImportDeclaration", - "start": 0, - "end": 25, - "loc": { - "start": { - "line": 1, - "column": 0 - }, - "end": { - "line": 1, - "column": 25 - } - }, - "importKind": "value", - "specifiers": [], - "source": { - "type": "Literal", - "start": 15, - "end": 25, - "loc": { - "start": { - "line": 1, - "column": 15 - }, - "end": { - "line": 1, - "column": 25 - } - }, - "value": "./config", - "raw": "'./config'" - } - }, - { - "type": "VariableDeclaration", - "start": 27, - "end": 73, - "loc": { - "start": { - "line": 3, - "column": 0 - }, - "end": { - "line": 3, - "column": 46 - } - }, - "declarations": [ - { - "type": "VariableDeclarator", - "start": 33, - "end": 72, - "loc": { - "start": { - "line": 3, - "column": 6 - }, - "end": { - "line": 3, - "column": 45 - } - }, - "id": { - "type": "Identifier", - "start": 33, - "end": 52, - "loc": { - "start": { - "line": 3, - "column": 6 - }, - "end": { - "line": 3, - "column": 25 - } - }, - "name": "loadDataWithGeneric" - }, - "init": { - "type": "ArrowFunctionExpression", - "start": 55, - "end": 72, - "loc": { - "start": { - "line": 3, - "column": 28 - }, - "end": { - "line": 3, - "column": 45 - } - }, - "typeParameters": { - "type": "TSTypeParameterDeclaration", - "start": 61, - "end": 64, - "loc": { - "start": { - "line": 3, - "column": 34 - }, - "end": { - "line": 3, - "column": 37 - } - }, - "params": [ - { - "type": "TSTypeParameter", - "start": 62, - "end": 63, - "loc": { - "start": { - "line": 3, - "column": 35 - }, - "end": { - "line": 3, - "column": 36 - } - }, - "name": "T" - } - ] - }, - "params": [], - "id": null, - "expression": false, - "generator": false, - "async": true, - "body": { - "type": "BlockStatement", - "start": 70, - "end": 72, - "loc": { - "start": { - "line": 3, - "column": 43 - }, - "end": { - "line": 3, - "column": 45 - } - }, - "body": [] - } - } - } - ], - "kind": "const" - } - ], - "sourceType": "module" -} diff --git a/test/arrow-function_type_test_async_generic_with_commented_import/input.ts b/test/arrow-function_type_test_async_generic_with_commented_import/input.ts new file mode 100644 index 0000000..f24af49 --- /dev/null +++ b/test/arrow-function_type_test_async_generic_with_commented_import/input.ts @@ -0,0 +1,3 @@ +// import {} from './config' + +const loadDataWithGeneric = async () => {}; \ No newline at end of file diff --git a/test/arrow-function_type_test_async_generic_with_import/expected.json b/test/arrow-function_type_test_async_generic_with_import/expected.json deleted file mode 100644 index fd478ae..0000000 --- a/test/arrow-function_type_test_async_generic_with_import/expected.json +++ /dev/null @@ -1,170 +0,0 @@ -{ - "type": "Program", - "start": 0, - "end": 128, - "loc": { - "start": { - "line": 1, - "column": 0 - }, - "end": { - "line": 4, - "column": 46 - } - }, - "body": [ - { - "type": "ImportDeclaration", - "start": 55, - "end": 80, - "loc": { - "start": { - "line": 2, - "column": 0 - }, - "end": { - "line": 2, - "column": 25 - } - }, - "importKind": "value", - "specifiers": [], - "source": { - "type": "Literal", - "start": 70, - "end": 80, - "loc": { - "start": { - "line": 2, - "column": 15 - }, - "end": { - "line": 2, - "column": 25 - } - }, - "value": "./config", - "raw": "'./config'" - } - }, - { - "type": "VariableDeclaration", - "start": 82, - "end": 128, - "loc": { - "start": { - "line": 4, - "column": 0 - }, - "end": { - "line": 4, - "column": 46 - } - }, - "declarations": [ - { - "type": "VariableDeclarator", - "start": 88, - "end": 127, - "loc": { - "start": { - "line": 4, - "column": 6 - }, - "end": { - "line": 4, - "column": 45 - } - }, - "id": { - "type": "Identifier", - "start": 88, - "end": 107, - "loc": { - "start": { - "line": 4, - "column": 6 - }, - "end": { - "line": 4, - "column": 25 - } - }, - "name": "loadDataWithGeneric" - }, - "init": { - "type": "ArrowFunctionExpression", - "start": 110, - "end": 127, - "loc": { - "start": { - "line": 4, - "column": 28 - }, - "end": { - "line": 4, - "column": 45 - } - }, - "typeParameters": { - "type": "TSTypeParameterDeclaration", - "start": 116, - "end": 119, - "loc": { - "start": { - "line": 4, - "column": 34 - }, - "end": { - "line": 4, - "column": 37 - } - }, - "params": [ - { - "type": "TSTypeParameter", - "start": 117, - "end": 118, - "loc": { - "start": { - "line": 4, - "column": 35 - }, - "end": { - "line": 4, - "column": 36 - } - }, - "name": "T" - } - ] - }, - "params": [], - "id": null, - "expression": false, - "generator": false, - "async": true, - "body": { - "type": "BlockStatement", - "start": 125, - "end": 127, - "loc": { - "start": { - "line": 4, - "column": 43 - }, - "end": { - "line": 4, - "column": 45 - } - }, - "body": [] - } - } - } - ], - "kind": "const" - } - ], - "sourceType": "module" -} diff --git a/test/arrow-function_type_test_async_generic_with_import/input.ts b/test/arrow-function_type_test_async_generic_with_import/input.ts deleted file mode 100644 index cbf2367..0000000 --- a/test/arrow-function_type_test_async_generic_with_import/input.ts +++ /dev/null @@ -1,4 +0,0 @@ -// removing the comment below yields a different error -import {} from './config' - -const loadDataWithGeneric = async () => {}; \ No newline at end of file From 8274082a5031ce92664322f1bb89d2b9621e01de Mon Sep 17 00:00:00 2001 From: Tee Ming Chew Date: Thu, 25 Sep 2025 17:42:00 +0800 Subject: [PATCH 4/9] fix arrow function with generic --- src/index.ts | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/src/index.ts b/src/index.ts index 99a26cb..d44a9be 100644 --- a/src/index.ts +++ b/src/index.ts @@ -481,7 +481,7 @@ export function tsPlugin(options?: { return super.parseArrowExpression( res, - /* params are already set */ res.params, + /* params are already set */ null, /* async */ true, /* forInit */ forInit ); @@ -3228,11 +3228,9 @@ export function tsPlugin(options?: { return node.expression; } - toAssignableList(exprList: any[], isBinding: boolean): any { - if (!exprList) { - return exprList; - } - + toAssignableList(exprList: any[] | null, isBinding: boolean): any { + if (!exprList) exprList = []; + for (let i = 0; i < exprList.length; i++) { const expr = exprList[i]; From 4c532b68832a44d6be26e499c47870fe4c90dd86 Mon Sep 17 00:00:00 2001 From: Tee Ming Chew Date: Fri, 26 Sep 2025 13:31:07 +0800 Subject: [PATCH 5/9] add tests --- .../expected.json | 170 ++++++++++++++++++ .../expected.json | 136 ++++++++++++++ 2 files changed, 306 insertions(+) create mode 100644 test/arrow-function_type_test_async_generic_after_import/expected.json create mode 100644 test/arrow-function_type_test_async_generic_with_commented_import/expected.json diff --git a/test/arrow-function_type_test_async_generic_after_import/expected.json b/test/arrow-function_type_test_async_generic_after_import/expected.json new file mode 100644 index 0000000..e56c00b --- /dev/null +++ b/test/arrow-function_type_test_async_generic_after_import/expected.json @@ -0,0 +1,170 @@ +{ + "type": "Program", + "start": 0, + "end": 73, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 3, + "column": 46 + } + }, + "body": [ + { + "type": "ImportDeclaration", + "start": 0, + "end": 25, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 25 + } + }, + "importKind": "value", + "specifiers": [], + "source": { + "type": "Literal", + "start": 15, + "end": 25, + "loc": { + "start": { + "line": 1, + "column": 15 + }, + "end": { + "line": 1, + "column": 25 + } + }, + "value": "./config", + "raw": "'./config'" + } + }, + { + "type": "VariableDeclaration", + "start": 27, + "end": 73, + "loc": { + "start": { + "line": 3, + "column": 0 + }, + "end": { + "line": 3, + "column": 46 + } + }, + "declarations": [ + { + "type": "VariableDeclarator", + "start": 33, + "end": 72, + "loc": { + "start": { + "line": 3, + "column": 6 + }, + "end": { + "line": 3, + "column": 45 + } + }, + "id": { + "type": "Identifier", + "start": 33, + "end": 52, + "loc": { + "start": { + "line": 3, + "column": 6 + }, + "end": { + "line": 3, + "column": 25 + } + }, + "name": "loadDataWithGeneric" + }, + "init": { + "type": "ArrowFunctionExpression", + "start": 55, + "end": 72, + "loc": { + "start": { + "line": 3, + "column": 28 + }, + "end": { + "line": 3, + "column": 45 + } + }, + "typeParameters": { + "type": "TSTypeParameterDeclaration", + "start": 61, + "end": 64, + "loc": { + "start": { + "line": 3, + "column": 34 + }, + "end": { + "line": 3, + "column": 37 + } + }, + "params": [ + { + "type": "TSTypeParameter", + "start": 62, + "end": 63, + "loc": { + "start": { + "line": 3, + "column": 35 + }, + "end": { + "line": 3, + "column": 36 + } + }, + "name": "T" + } + ] + }, + "params": [], + "id": null, + "expression": false, + "generator": false, + "async": true, + "body": { + "type": "BlockStatement", + "start": 70, + "end": 72, + "loc": { + "start": { + "line": 3, + "column": 43 + }, + "end": { + "line": 3, + "column": 45 + } + }, + "body": [] + } + } + } + ], + "kind": "const" + } + ], + "sourceType": "module" +} \ No newline at end of file diff --git a/test/arrow-function_type_test_async_generic_with_commented_import/expected.json b/test/arrow-function_type_test_async_generic_with_commented_import/expected.json new file mode 100644 index 0000000..1b59888 --- /dev/null +++ b/test/arrow-function_type_test_async_generic_with_commented_import/expected.json @@ -0,0 +1,136 @@ +{ + "type": "Program", + "start": 0, + "end": 76, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 3, + "column": 46 + } + }, + "body": [ + { + "type": "VariableDeclaration", + "start": 30, + "end": 76, + "loc": { + "start": { + "line": 3, + "column": 0 + }, + "end": { + "line": 3, + "column": 46 + } + }, + "declarations": [ + { + "type": "VariableDeclarator", + "start": 36, + "end": 75, + "loc": { + "start": { + "line": 3, + "column": 6 + }, + "end": { + "line": 3, + "column": 45 + } + }, + "id": { + "type": "Identifier", + "start": 36, + "end": 55, + "loc": { + "start": { + "line": 3, + "column": 6 + }, + "end": { + "line": 3, + "column": 25 + } + }, + "name": "loadDataWithGeneric" + }, + "init": { + "type": "ArrowFunctionExpression", + "start": 58, + "end": 75, + "loc": { + "start": { + "line": 3, + "column": 28 + }, + "end": { + "line": 3, + "column": 45 + } + }, + "typeParameters": { + "type": "TSTypeParameterDeclaration", + "start": 64, + "end": 67, + "loc": { + "start": { + "line": 3, + "column": 34 + }, + "end": { + "line": 3, + "column": 37 + } + }, + "params": [ + { + "type": "TSTypeParameter", + "start": 65, + "end": 66, + "loc": { + "start": { + "line": 3, + "column": 35 + }, + "end": { + "line": 3, + "column": 36 + } + }, + "name": "T" + } + ] + }, + "params": [], + "id": null, + "expression": false, + "generator": false, + "async": true, + "body": { + "type": "BlockStatement", + "start": 73, + "end": 75, + "loc": { + "start": { + "line": 3, + "column": 43 + }, + "end": { + "line": 3, + "column": 45 + } + }, + "body": [] + } + } + } + ], + "kind": "const" + } + ], + "sourceType": "module" +} \ No newline at end of file From 4a0d0821de44b7917e706a0bed414df3f4ad9fc2 Mon Sep 17 00:00:00 2001 From: Tee Ming Chew Date: Fri, 26 Sep 2025 13:46:49 +0800 Subject: [PATCH 6/9] fix type --- src/middleware.ts | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/middleware.ts b/src/middleware.ts index 6c7be08..0b4bc8a 100644 --- a/src/middleware.ts +++ b/src/middleware.ts @@ -47,11 +47,11 @@ export declare class AcornParseClass extends Parser { scopeStack: any[]; inModule: any; undefinedExports: any; - lastTokEndLoc: any; - lastTokStartLoc: any; + lastTokEndLoc: Position; + lastTokStartLoc: Position; context: any[]; - endLoc: any; - startLoc: any; + endLoc: Position; + startLoc: Position; potentialArrowInForAwait: boolean; type: TokenType & Record; start: number; From 9ab798832534e7c1c02c37849a9728d78c8f5f3d Mon Sep 17 00:00:00 2001 From: Tee Ming Chew Date: Fri, 26 Sep 2025 13:47:16 +0800 Subject: [PATCH 7/9] fix for generic async arrow function proceeding an import statement --- src/index.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/index.ts b/src/index.ts index d44a9be..c3a2e61 100644 --- a/src/index.ts +++ b/src/index.ts @@ -430,7 +430,7 @@ export function tsPlugin(options?: { return ( base.type === 'Identifier' && base.name === 'async' && - this.lastTokEndLoc.column === base.end && + this.lastTokEnd === base.end && !this.canInsertSemicolon() && base.end - base.start === 5 && base.start === this.potentialArrowAt @@ -4165,7 +4165,7 @@ export function tsPlugin(options?: { override = modified.override; readonly = modified.readonly; if (allowModifiers === false && (accessibility || readonly || override)) { - this.raise(startLoc.start, TypeScriptError.UnexpectedParameterModifier); + this.raise(startLoc.column, TypeScriptError.UnexpectedParameterModifier); } } From c42ac13d8101c47de7296530d0409e3b41453b35 Mon Sep 17 00:00:00 2001 From: Tee Ming Chew Date: Fri, 26 Sep 2025 13:51:36 +0800 Subject: [PATCH 8/9] format --- .../expected.json | 338 +++++++++--------- .../expected.json | 270 +++++++------- 2 files changed, 304 insertions(+), 304 deletions(-) diff --git a/test/arrow-function_type_test_async_generic_after_import/expected.json b/test/arrow-function_type_test_async_generic_after_import/expected.json index e56c00b..48e4f9c 100644 --- a/test/arrow-function_type_test_async_generic_after_import/expected.json +++ b/test/arrow-function_type_test_async_generic_after_import/expected.json @@ -1,170 +1,170 @@ { - "type": "Program", - "start": 0, - "end": 73, - "loc": { - "start": { - "line": 1, - "column": 0 - }, - "end": { - "line": 3, - "column": 46 - } - }, - "body": [ - { - "type": "ImportDeclaration", - "start": 0, - "end": 25, - "loc": { - "start": { - "line": 1, - "column": 0 - }, - "end": { - "line": 1, - "column": 25 - } - }, - "importKind": "value", - "specifiers": [], - "source": { - "type": "Literal", - "start": 15, - "end": 25, - "loc": { - "start": { - "line": 1, - "column": 15 - }, - "end": { - "line": 1, - "column": 25 - } - }, - "value": "./config", - "raw": "'./config'" - } - }, - { - "type": "VariableDeclaration", - "start": 27, - "end": 73, - "loc": { - "start": { - "line": 3, - "column": 0 - }, - "end": { - "line": 3, - "column": 46 - } - }, - "declarations": [ - { - "type": "VariableDeclarator", - "start": 33, - "end": 72, - "loc": { - "start": { - "line": 3, - "column": 6 - }, - "end": { - "line": 3, - "column": 45 - } - }, - "id": { - "type": "Identifier", - "start": 33, - "end": 52, - "loc": { - "start": { - "line": 3, - "column": 6 - }, - "end": { - "line": 3, - "column": 25 - } - }, - "name": "loadDataWithGeneric" - }, - "init": { - "type": "ArrowFunctionExpression", - "start": 55, - "end": 72, - "loc": { - "start": { - "line": 3, - "column": 28 - }, - "end": { - "line": 3, - "column": 45 - } - }, - "typeParameters": { - "type": "TSTypeParameterDeclaration", - "start": 61, - "end": 64, - "loc": { - "start": { - "line": 3, - "column": 34 - }, - "end": { - "line": 3, - "column": 37 - } - }, - "params": [ - { - "type": "TSTypeParameter", - "start": 62, - "end": 63, - "loc": { - "start": { - "line": 3, - "column": 35 - }, - "end": { - "line": 3, - "column": 36 - } - }, - "name": "T" - } - ] - }, - "params": [], - "id": null, - "expression": false, - "generator": false, - "async": true, - "body": { - "type": "BlockStatement", - "start": 70, - "end": 72, - "loc": { - "start": { - "line": 3, - "column": 43 - }, - "end": { - "line": 3, - "column": 45 - } - }, - "body": [] - } - } - } - ], - "kind": "const" - } - ], - "sourceType": "module" -} \ No newline at end of file + "type": "Program", + "start": 0, + "end": 73, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 3, + "column": 46 + } + }, + "body": [ + { + "type": "ImportDeclaration", + "start": 0, + "end": 25, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 25 + } + }, + "importKind": "value", + "specifiers": [], + "source": { + "type": "Literal", + "start": 15, + "end": 25, + "loc": { + "start": { + "line": 1, + "column": 15 + }, + "end": { + "line": 1, + "column": 25 + } + }, + "value": "./config", + "raw": "'./config'" + } + }, + { + "type": "VariableDeclaration", + "start": 27, + "end": 73, + "loc": { + "start": { + "line": 3, + "column": 0 + }, + "end": { + "line": 3, + "column": 46 + } + }, + "declarations": [ + { + "type": "VariableDeclarator", + "start": 33, + "end": 72, + "loc": { + "start": { + "line": 3, + "column": 6 + }, + "end": { + "line": 3, + "column": 45 + } + }, + "id": { + "type": "Identifier", + "start": 33, + "end": 52, + "loc": { + "start": { + "line": 3, + "column": 6 + }, + "end": { + "line": 3, + "column": 25 + } + }, + "name": "loadDataWithGeneric" + }, + "init": { + "type": "ArrowFunctionExpression", + "start": 55, + "end": 72, + "loc": { + "start": { + "line": 3, + "column": 28 + }, + "end": { + "line": 3, + "column": 45 + } + }, + "typeParameters": { + "type": "TSTypeParameterDeclaration", + "start": 61, + "end": 64, + "loc": { + "start": { + "line": 3, + "column": 34 + }, + "end": { + "line": 3, + "column": 37 + } + }, + "params": [ + { + "type": "TSTypeParameter", + "start": 62, + "end": 63, + "loc": { + "start": { + "line": 3, + "column": 35 + }, + "end": { + "line": 3, + "column": 36 + } + }, + "name": "T" + } + ] + }, + "params": [], + "id": null, + "expression": false, + "generator": false, + "async": true, + "body": { + "type": "BlockStatement", + "start": 70, + "end": 72, + "loc": { + "start": { + "line": 3, + "column": 43 + }, + "end": { + "line": 3, + "column": 45 + } + }, + "body": [] + } + } + } + ], + "kind": "const" + } + ], + "sourceType": "module" +} diff --git a/test/arrow-function_type_test_async_generic_with_commented_import/expected.json b/test/arrow-function_type_test_async_generic_with_commented_import/expected.json index 1b59888..601b002 100644 --- a/test/arrow-function_type_test_async_generic_with_commented_import/expected.json +++ b/test/arrow-function_type_test_async_generic_with_commented_import/expected.json @@ -1,136 +1,136 @@ { - "type": "Program", - "start": 0, - "end": 76, - "loc": { - "start": { - "line": 1, - "column": 0 - }, - "end": { - "line": 3, - "column": 46 - } - }, - "body": [ - { - "type": "VariableDeclaration", - "start": 30, - "end": 76, - "loc": { - "start": { - "line": 3, - "column": 0 - }, - "end": { - "line": 3, - "column": 46 - } - }, - "declarations": [ - { - "type": "VariableDeclarator", - "start": 36, - "end": 75, - "loc": { - "start": { - "line": 3, - "column": 6 - }, - "end": { - "line": 3, - "column": 45 - } - }, - "id": { - "type": "Identifier", - "start": 36, - "end": 55, - "loc": { - "start": { - "line": 3, - "column": 6 - }, - "end": { - "line": 3, - "column": 25 - } - }, - "name": "loadDataWithGeneric" - }, - "init": { - "type": "ArrowFunctionExpression", - "start": 58, - "end": 75, - "loc": { - "start": { - "line": 3, - "column": 28 - }, - "end": { - "line": 3, - "column": 45 - } - }, - "typeParameters": { - "type": "TSTypeParameterDeclaration", - "start": 64, - "end": 67, - "loc": { - "start": { - "line": 3, - "column": 34 - }, - "end": { - "line": 3, - "column": 37 - } - }, - "params": [ - { - "type": "TSTypeParameter", - "start": 65, - "end": 66, - "loc": { - "start": { - "line": 3, - "column": 35 - }, - "end": { - "line": 3, - "column": 36 - } - }, - "name": "T" - } - ] - }, - "params": [], - "id": null, - "expression": false, - "generator": false, - "async": true, - "body": { - "type": "BlockStatement", - "start": 73, - "end": 75, - "loc": { - "start": { - "line": 3, - "column": 43 - }, - "end": { - "line": 3, - "column": 45 - } - }, - "body": [] - } - } - } - ], - "kind": "const" - } - ], - "sourceType": "module" -} \ No newline at end of file + "type": "Program", + "start": 0, + "end": 76, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 3, + "column": 46 + } + }, + "body": [ + { + "type": "VariableDeclaration", + "start": 30, + "end": 76, + "loc": { + "start": { + "line": 3, + "column": 0 + }, + "end": { + "line": 3, + "column": 46 + } + }, + "declarations": [ + { + "type": "VariableDeclarator", + "start": 36, + "end": 75, + "loc": { + "start": { + "line": 3, + "column": 6 + }, + "end": { + "line": 3, + "column": 45 + } + }, + "id": { + "type": "Identifier", + "start": 36, + "end": 55, + "loc": { + "start": { + "line": 3, + "column": 6 + }, + "end": { + "line": 3, + "column": 25 + } + }, + "name": "loadDataWithGeneric" + }, + "init": { + "type": "ArrowFunctionExpression", + "start": 58, + "end": 75, + "loc": { + "start": { + "line": 3, + "column": 28 + }, + "end": { + "line": 3, + "column": 45 + } + }, + "typeParameters": { + "type": "TSTypeParameterDeclaration", + "start": 64, + "end": 67, + "loc": { + "start": { + "line": 3, + "column": 34 + }, + "end": { + "line": 3, + "column": 37 + } + }, + "params": [ + { + "type": "TSTypeParameter", + "start": 65, + "end": 66, + "loc": { + "start": { + "line": 3, + "column": 35 + }, + "end": { + "line": 3, + "column": 36 + } + }, + "name": "T" + } + ] + }, + "params": [], + "id": null, + "expression": false, + "generator": false, + "async": true, + "body": { + "type": "BlockStatement", + "start": 73, + "end": 75, + "loc": { + "start": { + "line": 3, + "column": 43 + }, + "end": { + "line": 3, + "column": 45 + } + }, + "body": [] + } + } + } + ], + "kind": "const" + } + ], + "sourceType": "module" +} From 3b47f3ab32f121dd62dd590eb39f88fa2dc7728c Mon Sep 17 00:00:00 2001 From: Tee Ming Chew Date: Fri, 26 Sep 2025 13:52:15 +0800 Subject: [PATCH 9/9] changeset --- .changeset/flat-poets-beam.md | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 .changeset/flat-poets-beam.md diff --git a/.changeset/flat-poets-beam.md b/.changeset/flat-poets-beam.md new file mode 100644 index 0000000..a37ada5 --- /dev/null +++ b/.changeset/flat-poets-beam.md @@ -0,0 +1,5 @@ +--- +'@sveltejs/acorn-typescript': patch +--- + +fix: correctly parse async arrow functions with generics