From 52b1899ebe86cff752ee38f754cca056aaea48cc Mon Sep 17 00:00:00 2001 From: liuxingbaoyu <30521560+liuxingbaoyu@users.noreply.github.com> Date: Fri, 16 Sep 2022 17:35:12 +0800 Subject: [PATCH 1/6] fix --- .../src/plugins/typescript/scope.ts | 35 ++-- .../export-func-in-declare-module/input.ts | 12 ++ .../export-func-in-declare-module/output.json | 193 ++++++++++++++++++ 3 files changed, 219 insertions(+), 21 deletions(-) create mode 100644 packages/babel-parser/test/fixtures/typescript/scope/export-func-in-declare-module/input.ts create mode 100644 packages/babel-parser/test/fixtures/typescript/scope/export-func-in-declare-module/output.json diff --git a/packages/babel-parser/src/plugins/typescript/scope.ts b/packages/babel-parser/src/plugins/typescript/scope.ts index ad0be49bb9ed..92a418901d72 100644 --- a/packages/babel-parser/src/plugins/typescript/scope.ts +++ b/packages/babel-parser/src/plugins/typescript/scope.ts @@ -64,22 +64,9 @@ export default class TypeScriptScopeHandler extends ScopeHandler 1) { - for (let i = 0; i < len - 1; i++) { - if (this.importsStack[i].has(name)) return true; - } - } - return false; - } - declareName(name: string, bindingType: BindingTypes, loc: Position) { if (bindingType & BIND_FLAGS_TS_IMPORT) { - if (this.hasImport(name, true)) { + if (this.importsStack[this.importsStack.length - 1].has(name)) { this.parser.raise(Errors.VarRedeclaration, { at: loc, identifierName: name, @@ -143,14 +130,20 @@ export default class TypeScriptScopeHandler extends ScopeHandler Date: Fri, 16 Sep 2022 17:51:13 +0800 Subject: [PATCH 2/6] fix --- .../src/plugins/typescript/scope.ts | 3 + .../export-import-in-declare-module/input.ts | 4 + .../output.json | 88 +++++++++++++++++++ 3 files changed, 95 insertions(+) create mode 100644 packages/babel-parser/test/fixtures/typescript/scope/export-import-in-declare-module/input.ts create mode 100644 packages/babel-parser/test/fixtures/typescript/scope/export-import-in-declare-module/output.json diff --git a/packages/babel-parser/src/plugins/typescript/scope.ts b/packages/babel-parser/src/plugins/typescript/scope.ts index 92a418901d72..cef20424ed38 100644 --- a/packages/babel-parser/src/plugins/typescript/scope.ts +++ b/packages/babel-parser/src/plugins/typescript/scope.ts @@ -133,6 +133,9 @@ export default class TypeScriptScopeHandler extends ScopeHandler Date: Fri, 16 Sep 2022 17:59:14 +0800 Subject: [PATCH 3/6] fix --- .../src/plugins/typescript/scope.ts | 28 +++++++++++-------- 1 file changed, 17 insertions(+), 11 deletions(-) diff --git a/packages/babel-parser/src/plugins/typescript/scope.ts b/packages/babel-parser/src/plugins/typescript/scope.ts index cef20424ed38..9e08e2c1376e 100644 --- a/packages/babel-parser/src/plugins/typescript/scope.ts +++ b/packages/babel-parser/src/plugins/typescript/scope.ts @@ -64,9 +64,22 @@ export default class TypeScriptScopeHandler extends ScopeHandler 1) { + for (let i = 0; i < len - 1; i++) { + if (this.importsStack[i].has(name)) return true; + } + } + return false; + } + declareName(name: string, bindingType: BindingTypes, loc: Position) { if (bindingType & BIND_FLAGS_TS_IMPORT) { - if (this.importsStack[this.importsStack.length - 1].has(name)) { + if (this.hasImport(name, true)) { this.parser.raise(Errors.VarRedeclaration, { at: loc, identifierName: name, @@ -132,19 +145,12 @@ export default class TypeScriptScopeHandler extends ScopeHandler Date: Mon, 19 Sep 2022 16:45:26 +0800 Subject: [PATCH 4/6] Update packages/babel-parser/src/plugins/typescript/scope.ts MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Huáng Jùnliàng --- packages/babel-parser/src/plugins/typescript/scope.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/babel-parser/src/plugins/typescript/scope.ts b/packages/babel-parser/src/plugins/typescript/scope.ts index 9e08e2c1376e..a23e22b7af95 100644 --- a/packages/babel-parser/src/plugins/typescript/scope.ts +++ b/packages/babel-parser/src/plugins/typescript/scope.ts @@ -148,7 +148,7 @@ export default class TypeScriptScopeHandler extends ScopeHandler= 0; i--) { const stack = this.scopeStack[i]; if (stack.types.has(name) || stack.exportOnlyBindings.has(name)) return; } From d25292284a814cade3431526136420c4d4851f57 Mon Sep 17 00:00:00 2001 From: liuxingbaoyu <30521560+liuxingbaoyu@users.noreply.github.com> Date: Mon, 19 Sep 2022 16:48:04 +0800 Subject: [PATCH 5/6] update allowlist --- scripts/parser-tests/typescript/allowlist.txt | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/scripts/parser-tests/typescript/allowlist.txt b/scripts/parser-tests/typescript/allowlist.txt index 245d2d088bbb..d4404a932f64 100644 --- a/scripts/parser-tests/typescript/allowlist.txt +++ b/scripts/parser-tests/typescript/allowlist.txt @@ -11,7 +11,7 @@ exportDeclarationsInAmbientNamespaces2.ts multipleExports.ts -# 134 valid programs produced a parsing error +# 131 valid programs produced a parsing error ArrowFunctionExpression1.ts MemberAccessorDeclaration15.ts @@ -71,12 +71,9 @@ exportAssignmentWithDeclareAndExportModifiers.ts exportAssignmentWithDeclareModifier.ts exportAssignmentWithExportModifier.ts exportClassWithoutName.ts -exportDeclarationsInAmbientNamespaces.ts exportDefaultAsyncFunction2.ts exportInterfaceClassAndValue.ts exportSameNameFuncVar.ts -exportSpecifierAndExportedMemberDeclaration.ts -exportSpecifierAndLocalMemberDeclaration.ts exportSpecifierForAGlobal.ts # We handle this fine, but it doesn't consider the different files together exportSpecifierReferencingOuterDeclaration2.ts # We handle this fine, but it doesn't consider the different files together expressionsForbiddenInParameterInitializers.ts From 1422ea8544a7e6207a13bcd8dd024e376100bb61 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicol=C3=B2=20Ribaudo?= Date: Mon, 19 Sep 2022 14:47:35 +0200 Subject: [PATCH 6/6] Update packages/babel-parser/src/plugins/typescript/scope.ts --- packages/babel-parser/src/plugins/typescript/scope.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/babel-parser/src/plugins/typescript/scope.ts b/packages/babel-parser/src/plugins/typescript/scope.ts index a23e22b7af95..dff7669b79f4 100644 --- a/packages/babel-parser/src/plugins/typescript/scope.ts +++ b/packages/babel-parser/src/plugins/typescript/scope.ts @@ -149,8 +149,8 @@ export default class TypeScriptScopeHandler extends ScopeHandler= 0; i--) { - const stack = this.scopeStack[i]; - if (stack.types.has(name) || stack.exportOnlyBindings.has(name)) return; + const scope = this.scopeStack[i]; + if (scope.types.has(name) || scope.exportOnlyBindings.has(name)) return; } super.checkLocalExport(id);