mirror of
https://github.com/danbulant/oxc
synced 2026-05-25 04:42:10 +00:00
refactor(transformer/typescript): use a memory-safe implementation instead (#3481)
The previous implementation causes memory double free, but I don't know why.
This commit is contained in:
parent
25e5bdda3c
commit
9dc58d582d
2 changed files with 13 additions and 14 deletions
|
|
@ -337,18 +337,20 @@ impl<'a> TypeScriptAnnotations<'a> {
|
||||||
|
|
||||||
// Add assignments after super calls
|
// Add assignments after super calls
|
||||||
if !self.assignments.is_empty() {
|
if !self.assignments.is_empty() {
|
||||||
let mut super_indexes = vec![];
|
let has_super_call = stmts.iter().any(|stmt| {
|
||||||
for (index, stmt) in stmts.iter().rev().enumerate() {
|
matches!(stmt, Statement::ExpressionStatement(stmt) if stmt.expression.is_super_call_expression())
|
||||||
if matches!(stmt, Statement::ExpressionStatement(stmt) if stmt.expression.is_super_call_expression())
|
});
|
||||||
{
|
if has_super_call {
|
||||||
super_indexes.push(index);
|
let mut new_stmts = self.ctx.ast.new_vec();
|
||||||
|
for stmt in stmts.drain(..) {
|
||||||
|
let is_super_call = matches!(stmt, Statement::ExpressionStatement(ref stmt) if stmt.expression.is_super_call_expression());
|
||||||
|
new_stmts.push(stmt);
|
||||||
|
if is_super_call {
|
||||||
|
new_stmts.extend(self.ctx.ast.copy(&self.assignments));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
if !super_indexes.is_empty() {
|
|
||||||
self.has_super_call = true;
|
self.has_super_call = true;
|
||||||
for index in super_indexes.iter().rev() {
|
*stmts = new_stmts;
|
||||||
stmts.splice((index + 1)..=*index, self.ctx.ast.copy(&self.assignments));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -2,13 +2,10 @@ commit: 64d2eeea
|
||||||
|
|
||||||
transformer_typescript Summary:
|
transformer_typescript Summary:
|
||||||
AST Parsed : 5243/5243 (100.00%)
|
AST Parsed : 5243/5243 (100.00%)
|
||||||
Positive Passed: 5234/5243 (99.83%)
|
Positive Passed: 5237/5243 (99.89%)
|
||||||
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/sourceMapValidationClasses.ts"
|
||||||
Mismatch: "compiler/styledComponentsInstantiaionLimitNotReached.ts"
|
Mismatch: "compiler/styledComponentsInstantiaionLimitNotReached.ts"
|
||||||
Mismatch: "compiler/tsxReactPropsInferenceSucceedsOnIntersections.tsx"
|
Mismatch: "compiler/tsxReactPropsInferenceSucceedsOnIntersections.tsx"
|
||||||
Mismatch: "conformance/classes/constructorDeclarations/superCalls/emitStatementsBeforeSuperCall.ts"
|
|
||||||
Mismatch: "conformance/classes/constructorDeclarations/superCalls/emitStatementsBeforeSuperCallWithDefineFields.ts"
|
|
||||||
Mismatch: "conformance/statements/VariableStatements/usingDeclarations/usingDeclarations.11.ts"
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue