Skip to content

Commit

Permalink
fix(semantic): transform checker catch more scope flags mismatches (#…
Browse files Browse the repository at this point in the history
…5054)

There was a bug previously where scope flags were only checked if there was also a bindings mismatch.
  • Loading branch information
overlookmotel committed Aug 22, 2024
1 parent 7156fd2 commit da64014
Show file tree
Hide file tree
Showing 5 changed files with 131 additions and 9 deletions.
5 changes: 2 additions & 3 deletions crates/oxc_semantic/src/post_transform_checker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -292,10 +292,9 @@ impl<'s> PostTransformChecker<'s> {
(Some(scope_id_after_transform), Some(scope_id_rebuilt)) => {
let scope_ids = Pair::new(scope_id_after_transform, scope_id_rebuilt);
let bindings = self.get_pair(scope_ids, get_sorted_bindings);
if bindings.is_match() {
continue;
if bindings.is_mismatch() {
self.errors.push_mismatch("Bindings mismatch", scope_ids, bindings);
}
self.errors.push_mismatch("Bindings mismatch", scope_ids, bindings);
scope_ids
}
(Some(scope_id), None) => {
Expand Down
54 changes: 53 additions & 1 deletion tasks/coverage/semantic_babel.snap
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ commit: 12619ffe

semantic_babel Summary:
AST Parsed : 2101/2101 (100.00%)
Positive Passed: 1853/2101 (88.20%)
Positive Passed: 1845/2101 (87.82%)
tasks/coverage/babel/packages/babel-parser/test/fixtures/comments/interpreter-directive/interpreter-directive-import/input.js
semantic error: Bindings mismatch:
after transform: ScopeId(0): ["spawn"]
Expand Down Expand Up @@ -363,6 +363,11 @@ Bindings mismatch:
after transform: ScopeId(4): ["T", "x"]
rebuilt : ScopeId(4): ["x"]

tasks/coverage/babel/packages/babel-parser/test/fixtures/typescript/enum/const/input.ts
semantic error: Scope flags mismatch:
after transform: ScopeId(1): ScopeFlags(StrictMode)
rebuilt : ScopeId(1): ScopeFlags(StrictMode | Function)

tasks/coverage/babel/packages/babel-parser/test/fixtures/typescript/enum/declare/input.ts
semantic error: Bindings mismatch:
after transform: ScopeId(0): ["E"]
Expand All @@ -378,6 +383,16 @@ semantic error: Bindings mismatch:
after transform: ScopeId(0): ["E"]
rebuilt : ScopeId(0): []

tasks/coverage/babel/packages/babel-parser/test/fixtures/typescript/enum/export/input.ts
semantic error: Scope flags mismatch:
after transform: ScopeId(1): ScopeFlags(StrictMode)
rebuilt : ScopeId(1): ScopeFlags(StrictMode | Function)

tasks/coverage/babel/packages/babel-parser/test/fixtures/typescript/enum/export-const/input.ts
semantic error: Scope flags mismatch:
after transform: ScopeId(1): ScopeFlags(StrictMode)
rebuilt : ScopeId(1): ScopeFlags(StrictMode | Function)

tasks/coverage/babel/packages/babel-parser/test/fixtures/typescript/enum/export-declare-const/input.ts
semantic error: Bindings mismatch:
after transform: ScopeId(0): ["E"]
Expand Down Expand Up @@ -455,6 +470,9 @@ tasks/coverage/babel/packages/babel-parser/test/fixtures/typescript/export/expor
semantic error: Bindings mismatch:
after transform: ScopeId(0): ["C", "D", "E", "a", "b"]
rebuilt : ScopeId(0): ["C", "D", "a", "b"]
Scope flags mismatch:
after transform: ScopeId(3): ScopeFlags(StrictMode)
rebuilt : ScopeId(3): ScopeFlags(StrictMode | Function)

tasks/coverage/babel/packages/babel-parser/test/fixtures/typescript/export/nested-same-name/input.ts
semantic error: Semantic Collector failed after transform
Expand Down Expand Up @@ -843,6 +861,9 @@ tasks/coverage/babel/packages/babel-parser/test/fixtures/typescript/regression/i
semantic error: Bindings mismatch:
after transform: ScopeId(0): ["E", "I", "T"]
rebuilt : ScopeId(0): ["E"]
Scope flags mismatch:
after transform: ScopeId(2): ScopeFlags(StrictMode)
rebuilt : ScopeId(1): ScopeFlags(StrictMode | Function)

tasks/coverage/babel/packages/babel-parser/test/fixtures/typescript/regression/issue-7742/input.ts
semantic error: Bindings mismatch:
Expand Down Expand Up @@ -880,6 +901,21 @@ semantic error: Bindings mismatch:
after transform: ScopeId(0): ["Equals"]
rebuilt : ScopeId(0): []

tasks/coverage/babel/packages/babel-parser/test/fixtures/typescript/scope/enum-block-scoped/input.ts
semantic error: Scope flags mismatch:
after transform: ScopeId(2): ScopeFlags(StrictMode)
rebuilt : ScopeId(2): ScopeFlags(StrictMode | Function)

tasks/coverage/babel/packages/babel-parser/test/fixtures/typescript/scope/export-enum-after/input.ts
semantic error: Scope flags mismatch:
after transform: ScopeId(1): ScopeFlags(StrictMode)
rebuilt : ScopeId(1): ScopeFlags(StrictMode | Function)

tasks/coverage/babel/packages/babel-parser/test/fixtures/typescript/scope/export-enum-before/input.ts
semantic error: Scope flags mismatch:
after transform: ScopeId(1): ScopeFlags(StrictMode)
rebuilt : ScopeId(1): ScopeFlags(StrictMode | Function)

tasks/coverage/babel/packages/babel-parser/test/fixtures/typescript/scope/export-func-in-declare-module/input.ts
semantic error: Bindings mismatch:
after transform: ScopeId(0): ["m2"]
Expand Down Expand Up @@ -923,6 +959,22 @@ rebuilt : ScopeId(0): []
tasks/coverage/babel/packages/babel-parser/test/fixtures/typescript/scope/module-declaration-var-2/input.js
semantic error: Namespaces exporting non-const are not supported by Babel. Change to const or see: https://babeljs.io/docs/en/babel-plugin-transform-typescript

tasks/coverage/babel/packages/babel-parser/test/fixtures/typescript/scope/redeclaration-constenum-constenum/input.ts
semantic error: Scope flags mismatch:
after transform: ScopeId(1): ScopeFlags(StrictMode)
rebuilt : ScopeId(1): ScopeFlags(StrictMode | Function)
Scope flags mismatch:
after transform: ScopeId(2): ScopeFlags(StrictMode)
rebuilt : ScopeId(2): ScopeFlags(StrictMode | Function)

tasks/coverage/babel/packages/babel-parser/test/fixtures/typescript/scope/redeclaration-enum-enum/input.ts
semantic error: Scope flags mismatch:
after transform: ScopeId(1): ScopeFlags(StrictMode)
rebuilt : ScopeId(1): ScopeFlags(StrictMode | Function)
Scope flags mismatch:
after transform: ScopeId(2): ScopeFlags(StrictMode)
rebuilt : ScopeId(2): ScopeFlags(StrictMode | Function)

tasks/coverage/babel/packages/babel-parser/test/fixtures/typescript/scope/redeclaration-import-ambient-class/input.ts
semantic error: Bindings mismatch:
after transform: ScopeId(0): ["Something"]
Expand Down
14 changes: 13 additions & 1 deletion tasks/coverage/semantic_misc.snap
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,19 @@ after transform: ScopeId(0): ["BrowserWorkingCopyBackupTracker", "CancellationTo
rebuilt : ScopeId(0): ["BrowserWorkingCopyBackupTracker", "DisposableStore", "EditorService", "IEditorGroupsService", "IEditorService", "IFilesConfigurationService", "ILifecycleService", "ILogService", "IWorkingCopyBackupService", "IWorkingCopyEditorService", "IWorkingCopyService", "InMemoryTestWorkingCopyBackupService", "LifecyclePhase", "Schemas", "TestServiceAccessor", "TestWorkingCopy", "URI", "UntitledTextEditorInput", "VSBuffer", "assert", "bufferToReadable", "createEditorPart", "ensureNoDisposablesAreLeakedInTestSuite", "isWindows", "registerTestResourceEditor", "timeout", "toResource", "toTypedWorkingCopyId", "toUntypedWorkingCopyId", "workbenchInstantiationService", "workbenchTeardown"]

tasks/coverage/misc/pass/oxc-4449.ts
semantic error: Bindings mismatch:
semantic error: Scope flags mismatch:
after transform: ScopeId(1): ScopeFlags(StrictMode)
rebuilt : ScopeId(1): ScopeFlags(StrictMode | Function)
Scope flags mismatch:
after transform: ScopeId(2): ScopeFlags(StrictMode)
rebuilt : ScopeId(2): ScopeFlags(StrictMode | Function)
Scope flags mismatch:
after transform: ScopeId(3): ScopeFlags(StrictMode)
rebuilt : ScopeId(3): ScopeFlags(StrictMode | Function)
Scope flags mismatch:
after transform: ScopeId(4): ScopeFlags(StrictMode)
rebuilt : ScopeId(4): ScopeFlags(StrictMode | Function)
Bindings mismatch:
after transform: ScopeId(5): ["E", "baz"]
rebuilt : ScopeId(5): ["E"]
Scope flags mismatch:
Expand Down
41 changes: 39 additions & 2 deletions tasks/coverage/semantic_typescript.snap
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ commit: d8086f14

semantic_typescript Summary:
AST Parsed : 6456/6456 (100.00%)
Positive Passed: 3815/6456 (59.09%)
Positive Passed: 3810/6456 (59.01%)
tasks/coverage/typescript/tests/cases/compiler/APILibCheck.ts
semantic error: `import lib = require(...);` is only supported when compiling modules to CommonJS.
Please consider using `import lib from '...';` alongside Typescript's --allowSyntheticDefaultImports option, or add @babel/plugin-transform-modules-commonjs to your Babel config.
Expand Down Expand Up @@ -3390,6 +3390,11 @@ Reference mismatch:
after transform: ReferenceId(1): Some("a")
rebuilt : ReferenceId(1): None

tasks/coverage/typescript/tests/cases/compiler/emptyEnum.ts
semantic error: Scope flags mismatch:
after transform: ScopeId(1): ScopeFlags(0x0)
rebuilt : ScopeId(1): ScopeFlags(Function)

tasks/coverage/typescript/tests/cases/compiler/emptyIndexer.ts
semantic error: Bindings mismatch:
after transform: ScopeId(0): ["I1", "I2", "n", "x"]
Expand Down Expand Up @@ -10448,6 +10453,14 @@ semantic error: Bindings mismatch:
after transform: ScopeId(0): ["Foo", "Test", "UnNullify", "v"]
rebuilt : ScopeId(0): ["v"]

tasks/coverage/typescript/tests/cases/compiler/overload2.ts
semantic error: Scope flags mismatch:
after transform: ScopeId(1): ScopeFlags(0x0)
rebuilt : ScopeId(1): ScopeFlags(Function)
Scope flags mismatch:
after transform: ScopeId(2): ScopeFlags(0x0)
rebuilt : ScopeId(2): ScopeFlags(Function)

tasks/coverage/typescript/tests/cases/compiler/overloadBindingAcrossDeclarationBoundaries.ts
semantic error: Bindings mismatch:
after transform: ScopeId(0): ["A", "Opt1", "Opt2", "Opt3", "Opt4", "a", "a1"]
Expand Down Expand Up @@ -18446,6 +18459,11 @@ semantic error: Bindings mismatch:
after transform: ScopeId(0): ["Foo", "x"]
rebuilt : ScopeId(0): ["x"]

tasks/coverage/typescript/tests/cases/conformance/es6/Symbols/symbolType19.ts
semantic error: Scope flags mismatch:
after transform: ScopeId(1): ScopeFlags(0x0)
rebuilt : ScopeId(1): ScopeFlags(Function)

tasks/coverage/typescript/tests/cases/conformance/es6/classDeclaration/emitClassDeclarationWithExtensionAndTypeArgumentInES6.ts
semantic error: Bindings mismatch:
after transform: ScopeId(1): ["T"]
Expand Down Expand Up @@ -21287,6 +21305,14 @@ Scope flags mismatch:
after transform: ScopeId(1): ScopeFlags(0x0)
rebuilt : ScopeId(1): ScopeFlags(Function)

tasks/coverage/typescript/tests/cases/conformance/expressions/typeGuards/typeGuardEnums.ts
semantic error: Scope flags mismatch:
after transform: ScopeId(1): ScopeFlags(0x0)
rebuilt : ScopeId(1): ScopeFlags(Function)
Scope flags mismatch:
after transform: ScopeId(2): ScopeFlags(0x0)
rebuilt : ScopeId(2): ScopeFlags(Function)

tasks/coverage/typescript/tests/cases/conformance/expressions/typeGuards/typeGuardFunction.ts
semantic error: Bindings mismatch:
after transform: ScopeId(0): ["A", "B", "C", "D", "I1", "a", "b", "f1", "obj", "subType", "union", "union2", "union3"]
Expand All @@ -21301,6 +21327,9 @@ tasks/coverage/typescript/tests/cases/conformance/expressions/typeGuards/typeGua
semantic error: Bindings mismatch:
after transform: ScopeId(0): ["Tag", "Tag2", "value"]
rebuilt : ScopeId(0): ["Tag2", "value"]
Scope flags mismatch:
after transform: ScopeId(7): ScopeFlags(0x0)
rebuilt : ScopeId(3): ScopeFlags(Function)

tasks/coverage/typescript/tests/cases/conformance/expressions/typeGuards/typeGuardOfFormInstanceOfOnInterface.ts
semantic error: Bindings mismatch:
Expand Down Expand Up @@ -21422,7 +21451,10 @@ tasks/coverage/typescript/tests/cases/conformance/expressions/unaryOperators/voi
semantic error: Namespaces exporting non-const are not supported by Babel. Change to const or see: https://babeljs.io/docs/en/babel-plugin-transform-typescript

tasks/coverage/typescript/tests/cases/conformance/expressions/unaryOperators/voidOperator/voidOperatorWithEnumType.ts
semantic error: Bindings mismatch:
semantic error: Scope flags mismatch:
after transform: ScopeId(1): ScopeFlags(0x0)
rebuilt : ScopeId(1): ScopeFlags(Function)
Bindings mismatch:
after transform: ScopeId(2): ["", "A", "B", "ENUM1"]
rebuilt : ScopeId(2): ["ENUM1"]
Scope flags mismatch:
Expand Down Expand Up @@ -23445,6 +23477,11 @@ Scope flags mismatch:
after transform: ScopeId(1): ScopeFlags(0x0)
rebuilt : ScopeId(1): ScopeFlags(Function)

tasks/coverage/typescript/tests/cases/conformance/parser/ecmascript5/EnumDeclarations/parserEnum3.ts
semantic error: Scope flags mismatch:
after transform: ScopeId(1): ScopeFlags(0x0)
rebuilt : ScopeId(1): ScopeFlags(Function)

tasks/coverage/typescript/tests/cases/conformance/parser/ecmascript5/EnumDeclarations/parserEnum6.ts
semantic error: Bindings mismatch:
after transform: ScopeId(1): ["A", "B", "C", "E"]
Expand Down
26 changes: 24 additions & 2 deletions tasks/transform_conformance/babel.snap.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
commit: 12619ffe

Passed: 406/953
Passed: 403/953

# All Passed:
* babel-preset-react
Expand Down Expand Up @@ -1745,7 +1745,7 @@ preset-env: unknown field `shippedProposals`, expected `targets` or `bugfixes`



# babel-plugin-transform-typescript (61/151)
# babel-plugin-transform-typescript (58/151)
* class/accessor-allowDeclareFields-false/input.ts
x TS(18010): An accessibility modifier cannot be used with a private
| identifier.
Expand Down Expand Up @@ -1802,6 +1802,12 @@ preset-env: unknown field `shippedProposals`, expected `targets` or `bugfixes`
| rebuilt : ScopeId(1): ScopeFlags(StrictMode | Function)


* enum/const/input.ts
x Scope flags mismatch:
| after transform: ScopeId(1): ScopeFlags(StrictMode)
| rebuilt : ScopeId(1): ScopeFlags(StrictMode | Function)


* enum/constant-folding/input.ts
x Bindings mismatch:
| after transform: ScopeId(1): ["E", "a", "b", "c", "d", "e", "f", "g", "h",
Expand Down Expand Up @@ -1981,6 +1987,12 @@ preset-env: unknown field `shippedProposals`, expected `targets` or `bugfixes`
| rebuilt : ScopeId(2): ScopeFlags(StrictMode | Function)


* enum/scoped/input.ts
x Scope flags mismatch:
| after transform: ScopeId(2): ScopeFlags(StrictMode)
| rebuilt : ScopeId(2): ScopeFlags(StrictMode | Function)


* enum/string-value/input.ts
x Bindings mismatch:
| after transform: ScopeId(1): ["A", "A2", "B", "B2", "E"]
Expand Down Expand Up @@ -2051,6 +2063,10 @@ preset-env: unknown field `shippedProposals`, expected `targets` or `bugfixes`
| after transform: ScopeId(13): ScopeFlags(StrictMode)
| rebuilt : ScopeId(3): ScopeFlags(StrictMode | Function)

x Scope flags mismatch:
| after transform: ScopeId(16): ScopeFlags(StrictMode)
| rebuilt : ScopeId(4): ScopeFlags(StrictMode | Function)

x Reference mismatch:
| after transform: ReferenceId(0): Some("x")
| rebuilt : ReferenceId(0): None
Expand All @@ -2068,6 +2084,12 @@ preset-env: unknown field `shippedProposals`, expected `targets` or `bugfixes`
| rebuilt : ReferenceId(3): None


* exports/export-const-enums/input.ts
x Scope flags mismatch:
| after transform: ScopeId(1): ScopeFlags(StrictMode)
| rebuilt : ScopeId(1): ScopeFlags(StrictMode | Function)


* exports/export-import=/input.ts
x Semantic Collector failed after transform

Expand Down

0 comments on commit da64014

Please sign in to comment.