mirror of
https://github.com/danbulant/oxc
synced 2026-05-24 12:21:58 +00:00
feat(transformer/typescript): handle namespace directive correctly (#3532)
This commit is contained in:
parent
30ba828bc3
commit
ee9a215a21
2 changed files with 22 additions and 4 deletions
|
|
@ -280,15 +280,34 @@ impl<'a> TypeScript<'a> {
|
||||||
&self,
|
&self,
|
||||||
arg_name: Atom<'a>,
|
arg_name: Atom<'a>,
|
||||||
real_name: Atom<'a>,
|
real_name: Atom<'a>,
|
||||||
stmts: Vec<'a, Statement<'a>>,
|
mut stmts: Vec<'a, Statement<'a>>,
|
||||||
parent_export: Option<Expression<'a>>,
|
parent_export: Option<Expression<'a>>,
|
||||||
scope_id: ScopeId,
|
scope_id: ScopeId,
|
||||||
ctx: &mut TraverseCtx,
|
ctx: &mut TraverseCtx,
|
||||||
) -> Statement<'a> {
|
) -> Statement<'a> {
|
||||||
|
let mut directives = self.ctx.ast.new_vec();
|
||||||
|
|
||||||
|
// Check if the namespace has a `use strict` directive
|
||||||
|
if stmts.first().is_some_and(|stmt| {
|
||||||
|
matches!(stmt, Statement::ExpressionStatement(es) if
|
||||||
|
matches!(&es.expression, Expression::StringLiteral(literal) if
|
||||||
|
literal.value == "use strict")
|
||||||
|
)
|
||||||
|
}) {
|
||||||
|
stmts.remove(0);
|
||||||
|
let directive = self.ctx.ast.new_atom("use strict");
|
||||||
|
let directive = Directive {
|
||||||
|
span: SPAN,
|
||||||
|
expression: StringLiteral::new(SPAN, directive.clone()),
|
||||||
|
directive,
|
||||||
|
};
|
||||||
|
directives.push(directive);
|
||||||
|
}
|
||||||
|
|
||||||
// `(function (_N) { var x; })(N || (N = {}))`;
|
// `(function (_N) { var x; })(N || (N = {}))`;
|
||||||
// ^^^^^^^^^^^^^^^^^^^^^^^^^^
|
// ^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||||
let callee = {
|
let callee = {
|
||||||
let body = self.ctx.ast.function_body(SPAN, self.ctx.ast.new_vec(), stmts);
|
let body = self.ctx.ast.function_body(SPAN, directives, stmts);
|
||||||
let params = {
|
let params = {
|
||||||
let ident =
|
let ident =
|
||||||
self.ctx.ast.binding_pattern_identifier(BindingIdentifier::new(SPAN, arg_name));
|
self.ctx.ast.binding_pattern_identifier(BindingIdentifier::new(SPAN, arg_name));
|
||||||
|
|
|
||||||
|
|
@ -2,10 +2,9 @@ commit: 64d2eeea
|
||||||
|
|
||||||
transformer_typescript Summary:
|
transformer_typescript Summary:
|
||||||
AST Parsed : 5243/5243 (100.00%)
|
AST Parsed : 5243/5243 (100.00%)
|
||||||
Positive Passed: 5237/5243 (99.89%)
|
Positive Passed: 5238/5243 (99.90%)
|
||||||
Mismatch: "compiler/elidedEmbeddedStatementsReplacedWithSemicolon.ts"
|
Mismatch: "compiler/elidedEmbeddedStatementsReplacedWithSemicolon.ts"
|
||||||
Mismatch: "compiler/jsxComplexSignatureHasApplicabilityError.tsx"
|
Mismatch: "compiler/jsxComplexSignatureHasApplicabilityError.tsx"
|
||||||
Mismatch: "compiler/jsxEmptyExpressionNotCountedAsChild.tsx"
|
Mismatch: "compiler/jsxEmptyExpressionNotCountedAsChild.tsx"
|
||||||
Mismatch: "compiler/sourceMapValidationClasses.ts"
|
|
||||||
Mismatch: "compiler/styledComponentsInstantiaionLimitNotReached.ts"
|
Mismatch: "compiler/styledComponentsInstantiaionLimitNotReached.ts"
|
||||||
Mismatch: "compiler/tsxReactPropsInferenceSucceedsOnIntersections.tsx"
|
Mismatch: "compiler/tsxReactPropsInferenceSucceedsOnIntersections.tsx"
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue