mirror of
https://github.com/facebook/react.git
synced 2026-11-18 20:15:56 +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:
1 parent
896ef251b4
commit
83f3999a2e
1 file changed
+19
-7
@@ -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