mirror of
https://github.com/danbulant/oxc
synced 2026-05-24 12:21:58 +00:00
fix(transformer/typescript): create Reference for require (#8355)
Create a `Reference` when generating new `IdentifierReference` for `require`.
This commit is contained in:
parent
6c7acac72e
commit
0df18667ea
4 changed files with 20 additions and 657 deletions
|
|
@ -104,7 +104,14 @@ impl<'a> TypeScriptModule<'a, '_> {
|
||||||
self.ctx.error(diagnostics::import_equals_cannot_be_used_in_esm(decl_span));
|
self.ctx.error(diagnostics::import_equals_cannot_be_used_in_esm(decl_span));
|
||||||
}
|
}
|
||||||
|
|
||||||
let callee = ctx.ast.expression_identifier_reference(SPAN, "require");
|
let require_symbol_id =
|
||||||
|
ctx.scopes().find_binding(ctx.current_scope_id(), "require");
|
||||||
|
let callee = ctx.create_ident_expr(
|
||||||
|
SPAN,
|
||||||
|
Atom::from("require"),
|
||||||
|
require_symbol_id,
|
||||||
|
ReferenceFlags::Read,
|
||||||
|
);
|
||||||
let arguments =
|
let arguments =
|
||||||
ctx.ast.vec1(Argument::StringLiteral(ctx.alloc(reference.expression.clone())));
|
ctx.ast.vec1(Argument::StringLiteral(ctx.alloc(reference.expression.clone())));
|
||||||
(
|
(
|
||||||
|
|
|
||||||
|
|
@ -131,13 +131,9 @@ rebuilt : []
|
||||||
|
|
||||||
tasks/coverage/babel/packages/babel-parser/test/fixtures/estree/typescript/import-require/input.js
|
tasks/coverage/babel/packages/babel-parser/test/fixtures/estree/typescript/import-require/input.js
|
||||||
semantic error: Missing SymbolId: "x"
|
semantic error: Missing SymbolId: "x"
|
||||||
Missing ReferenceId: "require"
|
|
||||||
Binding symbols mismatch:
|
Binding symbols mismatch:
|
||||||
after transform: ScopeId(0): [SymbolId(0)]
|
after transform: ScopeId(0): [SymbolId(0)]
|
||||||
rebuilt : ScopeId(0): [SymbolId(0)]
|
rebuilt : ScopeId(0): [SymbolId(0)]
|
||||||
Unresolved references mismatch:
|
|
||||||
after transform: []
|
|
||||||
rebuilt : ["require"]
|
|
||||||
|
|
||||||
tasks/coverage/babel/packages/babel-parser/test/fixtures/estree/typescript/literals/input.js
|
tasks/coverage/babel/packages/babel-parser/test/fixtures/estree/typescript/literals/input.js
|
||||||
semantic error: Scope children mismatch:
|
semantic error: Scope children mismatch:
|
||||||
|
|
@ -740,23 +736,15 @@ rebuilt : ScopeId(0): [SymbolId(0)]
|
||||||
|
|
||||||
tasks/coverage/babel/packages/babel-parser/test/fixtures/typescript/import/equals-require/input.ts
|
tasks/coverage/babel/packages/babel-parser/test/fixtures/typescript/import/equals-require/input.ts
|
||||||
semantic error: Missing SymbolId: "a"
|
semantic error: Missing SymbolId: "a"
|
||||||
Missing ReferenceId: "require"
|
|
||||||
Binding symbols mismatch:
|
Binding symbols mismatch:
|
||||||
after transform: ScopeId(0): [SymbolId(0)]
|
after transform: ScopeId(0): [SymbolId(0)]
|
||||||
rebuilt : ScopeId(0): [SymbolId(0)]
|
rebuilt : ScopeId(0): [SymbolId(0)]
|
||||||
Unresolved references mismatch:
|
|
||||||
after transform: []
|
|
||||||
rebuilt : ["require"]
|
|
||||||
|
|
||||||
tasks/coverage/babel/packages/babel-parser/test/fixtures/typescript/import/equals-require-in-unambiguous/input.ts
|
tasks/coverage/babel/packages/babel-parser/test/fixtures/typescript/import/equals-require-in-unambiguous/input.ts
|
||||||
semantic error: Missing SymbolId: "a"
|
semantic error: Missing SymbolId: "a"
|
||||||
Missing ReferenceId: "require"
|
|
||||||
Binding symbols mismatch:
|
Binding symbols mismatch:
|
||||||
after transform: ScopeId(0): [SymbolId(0)]
|
after transform: ScopeId(0): [SymbolId(0)]
|
||||||
rebuilt : ScopeId(0): [SymbolId(0)]
|
rebuilt : ScopeId(0): [SymbolId(0)]
|
||||||
Unresolved references mismatch:
|
|
||||||
after transform: []
|
|
||||||
rebuilt : ["require"]
|
|
||||||
|
|
||||||
tasks/coverage/babel/packages/babel-parser/test/fixtures/typescript/import/export-import/input.ts
|
tasks/coverage/babel/packages/babel-parser/test/fixtures/typescript/import/export-import/input.ts
|
||||||
semantic error: Missing SymbolId: "A"
|
semantic error: Missing SymbolId: "A"
|
||||||
|
|
@ -766,23 +754,15 @@ rebuilt : ScopeId(0): [SymbolId(0)]
|
||||||
|
|
||||||
tasks/coverage/babel/packages/babel-parser/test/fixtures/typescript/import/export-import-require/input.ts
|
tasks/coverage/babel/packages/babel-parser/test/fixtures/typescript/import/export-import-require/input.ts
|
||||||
semantic error: Missing SymbolId: "a"
|
semantic error: Missing SymbolId: "a"
|
||||||
Missing ReferenceId: "require"
|
|
||||||
Binding symbols mismatch:
|
Binding symbols mismatch:
|
||||||
after transform: ScopeId(0): [SymbolId(0)]
|
after transform: ScopeId(0): [SymbolId(0)]
|
||||||
rebuilt : ScopeId(0): [SymbolId(0)]
|
rebuilt : ScopeId(0): [SymbolId(0)]
|
||||||
Unresolved references mismatch:
|
|
||||||
after transform: []
|
|
||||||
rebuilt : ["require"]
|
|
||||||
|
|
||||||
tasks/coverage/babel/packages/babel-parser/test/fixtures/typescript/import/export-import-type-as-identifier/input.ts
|
tasks/coverage/babel/packages/babel-parser/test/fixtures/typescript/import/export-import-type-as-identifier/input.ts
|
||||||
semantic error: Missing SymbolId: "type"
|
semantic error: Missing SymbolId: "type"
|
||||||
Missing ReferenceId: "require"
|
|
||||||
Binding symbols mismatch:
|
Binding symbols mismatch:
|
||||||
after transform: ScopeId(0): [SymbolId(0)]
|
after transform: ScopeId(0): [SymbolId(0)]
|
||||||
rebuilt : ScopeId(0): [SymbolId(0)]
|
rebuilt : ScopeId(0): [SymbolId(0)]
|
||||||
Unresolved references mismatch:
|
|
||||||
after transform: []
|
|
||||||
rebuilt : ["require"]
|
|
||||||
|
|
||||||
tasks/coverage/babel/packages/babel-parser/test/fixtures/typescript/import/export-import-type-require/input.ts
|
tasks/coverage/babel/packages/babel-parser/test/fixtures/typescript/import/export-import-type-require/input.ts
|
||||||
semantic error: Bindings mismatch:
|
semantic error: Bindings mismatch:
|
||||||
|
|
@ -791,16 +771,12 @@ rebuilt : ScopeId(0): []
|
||||||
|
|
||||||
tasks/coverage/babel/packages/babel-parser/test/fixtures/typescript/import/export-named-import-require/input.ts
|
tasks/coverage/babel/packages/babel-parser/test/fixtures/typescript/import/export-named-import-require/input.ts
|
||||||
semantic error: Missing SymbolId: "a"
|
semantic error: Missing SymbolId: "a"
|
||||||
Missing ReferenceId: "require"
|
|
||||||
Binding symbols mismatch:
|
Binding symbols mismatch:
|
||||||
after transform: ScopeId(0): [SymbolId(0)]
|
after transform: ScopeId(0): [SymbolId(0)]
|
||||||
rebuilt : ScopeId(0): [SymbolId(0)]
|
rebuilt : ScopeId(0): [SymbolId(0)]
|
||||||
Reference symbol mismatch for "a":
|
Reference symbol mismatch for "a":
|
||||||
after transform: SymbolId(0) "a"
|
after transform: SymbolId(0) "a"
|
||||||
rebuilt : SymbolId(0) "a"
|
rebuilt : SymbolId(0) "a"
|
||||||
Unresolved references mismatch:
|
|
||||||
after transform: []
|
|
||||||
rebuilt : ["require"]
|
|
||||||
|
|
||||||
tasks/coverage/babel/packages/babel-parser/test/fixtures/typescript/import/import-default-and-named-id-type/input.ts
|
tasks/coverage/babel/packages/babel-parser/test/fixtures/typescript/import/import-default-and-named-id-type/input.ts
|
||||||
semantic error: Bindings mismatch:
|
semantic error: Bindings mismatch:
|
||||||
|
|
@ -824,13 +800,9 @@ rebuilt : ScopeId(0): []
|
||||||
|
|
||||||
tasks/coverage/babel/packages/babel-parser/test/fixtures/typescript/import/import-type-as-identifier/input.ts
|
tasks/coverage/babel/packages/babel-parser/test/fixtures/typescript/import/import-type-as-identifier/input.ts
|
||||||
semantic error: Missing SymbolId: "type"
|
semantic error: Missing SymbolId: "type"
|
||||||
Missing ReferenceId: "require"
|
|
||||||
Binding symbols mismatch:
|
Binding symbols mismatch:
|
||||||
after transform: ScopeId(0): [SymbolId(0)]
|
after transform: ScopeId(0): [SymbolId(0)]
|
||||||
rebuilt : ScopeId(0): [SymbolId(0)]
|
rebuilt : ScopeId(0): [SymbolId(0)]
|
||||||
Unresolved references mismatch:
|
|
||||||
after transform: []
|
|
||||||
rebuilt : ["require"]
|
|
||||||
|
|
||||||
tasks/coverage/babel/packages/babel-parser/test/fixtures/typescript/import/internal-comments/input.ts
|
tasks/coverage/babel/packages/babel-parser/test/fixtures/typescript/import/internal-comments/input.ts
|
||||||
semantic error: Bindings mismatch:
|
semantic error: Bindings mismatch:
|
||||||
|
|
|
||||||
File diff suppressed because it is too large
Load diff
|
|
@ -2161,16 +2161,12 @@ rebuilt : ScopeId(0): []
|
||||||
|
|
||||||
* imports/import=-module-to-cjs/input.ts
|
* imports/import=-module-to-cjs/input.ts
|
||||||
Missing SymbolId: "lib"
|
Missing SymbolId: "lib"
|
||||||
Missing ReferenceId: "require"
|
|
||||||
Binding symbols mismatch:
|
Binding symbols mismatch:
|
||||||
after transform: ScopeId(0): [SymbolId(0)]
|
after transform: ScopeId(0): [SymbolId(0)]
|
||||||
rebuilt : ScopeId(0): [SymbolId(0)]
|
rebuilt : ScopeId(0): [SymbolId(0)]
|
||||||
Reference symbol mismatch for "lib":
|
Reference symbol mismatch for "lib":
|
||||||
after transform: SymbolId(0) "lib"
|
after transform: SymbolId(0) "lib"
|
||||||
rebuilt : SymbolId(0) "lib"
|
rebuilt : SymbolId(0) "lib"
|
||||||
Unresolved references mismatch:
|
|
||||||
after transform: []
|
|
||||||
rebuilt : ["require"]
|
|
||||||
|
|
||||||
* imports/only-remove-type-imports/input.ts
|
* imports/only-remove-type-imports/input.ts
|
||||||
Bindings mismatch:
|
Bindings mismatch:
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue