feat(transformer/typescript): handle namespace directive correctly (#3532)

This commit is contained in:
Dunqing 2024-06-05 09:02:49 +00:00
parent 30ba828bc3
commit ee9a215a21
2 changed files with 22 additions and 4 deletions

View file

@ -280,15 +280,34 @@ impl<'a> TypeScript<'a> {
&self,
arg_name: Atom<'a>,
real_name: Atom<'a>,
stmts: Vec<'a, Statement<'a>>,
mut stmts: Vec<'a, Statement<'a>>,
parent_export: Option<Expression<'a>>,
scope_id: ScopeId,
ctx: &mut TraverseCtx,
) -> 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 = {}))`;
// ^^^^^^^^^^^^^^^^^^^^^^^^^^
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 ident =
self.ctx.ast.binding_pattern_identifier(BindingIdentifier::new(SPAN, arg_name));

View file

@ -2,10 +2,9 @@ commit: 64d2eeea
transformer_typescript Summary:
AST Parsed : 5243/5243 (100.00%)
Positive Passed: 5237/5243 (99.89%)
Positive Passed: 5238/5243 (99.90%)
Mismatch: "compiler/elidedEmbeddedStatementsReplacedWithSemicolon.ts"
Mismatch: "compiler/jsxComplexSignatureHasApplicabilityError.tsx"
Mismatch: "compiler/jsxEmptyExpressionNotCountedAsChild.tsx"
Mismatch: "compiler/sourceMapValidationClasses.ts"
Mismatch: "compiler/styledComponentsInstantiaionLimitNotReached.ts"
Mismatch: "compiler/tsxReactPropsInferenceSucceedsOnIntersections.tsx"