mirror of
https://github.com/facebook/react.git
synced 2025-11-01 09:12:30 +00:00
Support var declaration hoisting
Var declarations were treated identical as other declarations which cause code relying on them getting hoisted now triggers runtime exception on TDZ. This diff fixed that by generating `var` for `var` so they can be hoisted as usual. commit-id:00ab02f6
This commit is contained in:
@@ -247,14 +247,26 @@ export class Func {
|
||||
* let output1, output2;
|
||||
*/
|
||||
emitReactiveBlockOutputDecls(block: LIR.ReactiveBlock) {
|
||||
if (block.outputDecls.size > 0) {
|
||||
const vars: t.VariableDeclarator[] = [];
|
||||
const lets: t.VariableDeclarator[] = [];
|
||||
|
||||
for (const decl of block.outputDecls) {
|
||||
if (decl.binding.kind === "var") {
|
||||
vars.push(t.variableDeclarator(decl.binding.identifier));
|
||||
} else {
|
||||
lets.push(t.variableDeclarator(decl.binding.identifier));
|
||||
}
|
||||
}
|
||||
|
||||
if (vars.length > 0) {
|
||||
this.code.push(
|
||||
t.variableDeclaration(
|
||||
/*kind*/ "let",
|
||||
/*declarators*/ [...block.outputDecls.values()].map((output) =>
|
||||
t.variableDeclarator(/*id*/ output.binding.identifier)
|
||||
)
|
||||
)
|
||||
t.variableDeclaration(/*kind*/ "var", /*declarators*/ vars)
|
||||
);
|
||||
}
|
||||
|
||||
if (lets.length > 0) {
|
||||
this.code.push(
|
||||
t.variableDeclaration(/*kind*/ "let", /*declarators*/ lets)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user