Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(semantic): bind TSImportEqualsDeclarations #4100

Merged
merged 4 commits into from
Jul 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions crates/oxc_linter/src/rules/react/jsx_no_undef.rs
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,16 @@ fn test() {
),
("var App; var React; enum A { App }; React.render(<App />);", None),
("var React; enum A { App }; var App; React.render(<App />);", None),
("var React; import App = require('./app'); React.render(<App />);", None),
(
"
var React;
DonIsaac marked this conversation as resolved.
Show resolved Hide resolved
import { Foo } from './foo';
import App = Foo.App;
React.render(<App />);
",
None,
),
];

let fail = vec![
Expand Down
6 changes: 6 additions & 0 deletions crates/oxc_semantic/src/binder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -294,6 +294,12 @@ impl<'a> Binder for ImportNamespaceSpecifier<'a> {
}
}

impl<'a> Binder for TSImportEqualsDeclaration<'a> {
fn bind(&self, builder: &mut SemanticBuilder) {
declare_symbol_for_import_specifier(&self.id, builder);
}
}

impl<'a> Binder for TSTypeAliasDeclaration<'a> {
fn bind(&self, builder: &mut SemanticBuilder) {
let symbol_id = builder.declare_symbol(
Expand Down
3 changes: 3 additions & 0 deletions crates/oxc_semantic/src/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1672,6 +1672,9 @@ impl<'a> SemanticBuilder<'a> {
AstKind::ImportNamespaceSpecifier(specifier) => {
specifier.bind(self);
}
AstKind::TSImportEqualsDeclaration(decl) => {
decl.bind(self);
}
AstKind::VariableDeclarator(decl) => {
decl.bind(self);
self.make_all_namespaces_valuelike();
Expand Down
13 changes: 13 additions & 0 deletions crates/oxc_semantic/tests/integration/modules.rs
Original file line number Diff line number Diff line change
Expand Up @@ -202,3 +202,16 @@ fn test_export_in_invalid_scope() {
assert!(!errors.is_empty(), "expected an export within a function to produce a check error, but no errors were produced");
assert!(semantic.module_record().exported_bindings.is_empty());
}

#[test]
fn test_import_assignment() {
SemanticTester::ts("import Foo = require('./foo')")
.has_root_symbol("Foo")
.contains_flags(SymbolFlags::ImportBinding)
.test();

SemanticTester::ts("import { Foo } from './foo'; import Baz = Foo.Bar.Baz")
.has_root_symbol("Baz")
.contains_flags(SymbolFlags::ImportBinding)
.test();
}
40 changes: 36 additions & 4 deletions tasks/coverage/parser_typescript.snap
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ commit: d8086f14
parser_typescript Summary:
AST Parsed : 5279/5283 (99.92%)
Positive Passed: 5272/5283 (99.79%)
Negative Passed: 1082/4875 (22.19%)
Negative Passed: 1085/4875 (22.26%)
Expect Syntax Error: "compiler/ClassDeclaration10.ts"
Expect Syntax Error: "compiler/ClassDeclaration11.ts"
Expect Syntax Error: "compiler/ClassDeclaration13.ts"
Expand Down Expand Up @@ -874,7 +874,6 @@ Expect Syntax Error: "compiler/implicitAnyWidenToAny.ts"
Expect Syntax Error: "compiler/implicitConstParameters.ts"
Expect Syntax Error: "compiler/importAnImport.ts"
Expect Syntax Error: "compiler/importAndVariableDeclarationConflict1.ts"
Expect Syntax Error: "compiler/importAndVariableDeclarationConflict3.ts"
Expect Syntax Error: "compiler/importAndVariableDeclarationConflict4.ts"
Expect Syntax Error: "compiler/importDeclRefereingExternalModuleWithNoResolve.ts"
Expect Syntax Error: "compiler/importDeclWithClassModifiers.ts"
Expand Down Expand Up @@ -1186,8 +1185,6 @@ Expect Syntax Error: "compiler/moduleImport.ts"
Expect Syntax Error: "compiler/moduleNewExportBug.ts"
Expect Syntax Error: "compiler/moduleNoneErrors.ts"
Expect Syntax Error: "compiler/moduleProperty2.ts"
Expect Syntax Error: "compiler/moduleSharesNameWithImportDeclarationInsideIt3.ts"
Expect Syntax Error: "compiler/moduleSharesNameWithImportDeclarationInsideIt5.ts"
Expect Syntax Error: "compiler/moduleVariableArrayIndexer.ts"
Expect Syntax Error: "compiler/moduleVisibilityTest2.ts"
Expect Syntax Error: "compiler/moduleVisibilityTest3.ts"
Expand Down Expand Up @@ -6866,6 +6863,17 @@ Expect to Parse: "conformance/salsa/plainJSRedeclare3.ts"
17 │ }
╰────

× Identifier `x` has already been declared
╭─[compiler/importAndVariableDeclarationConflict3.ts:5:8]
4 │
5 │ import x = m.m;
· ┬
· ╰── `x` has already been declared here
6 │ import x = m.m;
· ┬
· ╰── It can not be redeclared here
╰────

× Unexpected token
╭─[compiler/importAssertionNonstring.ts:1:52]
1 │ import * as thing1 from "./mod.mjs" assert {field: 0};
Expand Down Expand Up @@ -7962,6 +7970,30 @@ Expect to Parse: "conformance/salsa/plainJSRedeclare3.ts"
╰────
help: Try insert a semicolon here

× Identifier `M` has already been declared
╭─[compiler/moduleSharesNameWithImportDeclarationInsideIt3.ts:10:12]
9 │ module A.M {
10 │ import M = Z.M;
· ┬
· ╰── `M` has already been declared here
11 │ import M = Z.I;
· ┬
· ╰── It can not be redeclared here
12 │
╰────

× Identifier `M` has already been declared
╭─[compiler/moduleSharesNameWithImportDeclarationInsideIt5.ts:10:12]
9 │ module A.M {
10 │ import M = Z.I;
· ┬
· ╰── `M` has already been declared here
11 │ import M = Z.M;
· ┬
· ╰── It can not be redeclared here
12 │
╰────

× TS1108: A 'return' statement can only be used within a function body
╭─[compiler/multiLinePropertyAccessAndArrowFunctionIndent1.ts:1:1]
1 │ return this.edit(role)
Expand Down
Loading