mirror of
https://github.com/microsoft/TypeScript.git
synced 2025-11-18 17:21:48 +00:00
Fix 'var' hoisting in 'if' in SystemJS emit (#54016)
This commit is contained in:
@@ -45,6 +45,7 @@ import {
|
||||
hasSyntacticModifier,
|
||||
Identifier,
|
||||
idText,
|
||||
IfStatement,
|
||||
ImportCall,
|
||||
ImportDeclaration,
|
||||
ImportEqualsDeclaration,
|
||||
@@ -1210,6 +1211,9 @@ export function transformSystemModule(context: TransformationContext): (x: Sourc
|
||||
case SyntaxKind.WithStatement:
|
||||
return visitWithStatement(node as WithStatement);
|
||||
|
||||
case SyntaxKind.IfStatement:
|
||||
return visitIfStatement(node as IfStatement);
|
||||
|
||||
case SyntaxKind.SwitchStatement:
|
||||
return visitSwitchStatement(node as SwitchStatement);
|
||||
|
||||
@@ -1383,6 +1387,20 @@ export function transformSystemModule(context: TransformationContext): (x: Sourc
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Visits the body of a IfStatement to hoist declarations.
|
||||
*
|
||||
* @param node The node to visit.
|
||||
*/
|
||||
function visitIfStatement(node: IfStatement): VisitResult<Statement> {
|
||||
return factory.updateIfStatement(
|
||||
node,
|
||||
visitNode(node.expression, visitor, isExpression),
|
||||
Debug.checkDefined(visitNode(node.thenStatement, topLevelNestedVisitor, isStatement, factory.liftToBlock)),
|
||||
visitNode(node.elseStatement, topLevelNestedVisitor, isStatement, factory.liftToBlock)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Visits the body of a SwitchStatement to hoist declarations.
|
||||
*
|
||||
|
||||
@@ -0,0 +1,29 @@
|
||||
//// [topLevelVarHoistingSystem.ts]
|
||||
if (false) {
|
||||
var y = 1;
|
||||
}
|
||||
|
||||
function f() {
|
||||
console.log(y);
|
||||
}
|
||||
|
||||
export { y };
|
||||
|
||||
//// [topLevelVarHoistingSystem.js]
|
||||
System.register([], function (exports_1, context_1) {
|
||||
"use strict";
|
||||
var y;
|
||||
var __moduleName = context_1 && context_1.id;
|
||||
function f() {
|
||||
console.log(y);
|
||||
}
|
||||
return {
|
||||
setters: [],
|
||||
execute: function () {
|
||||
if (false) {
|
||||
y = 1;
|
||||
exports_1("y", y);
|
||||
}
|
||||
}
|
||||
};
|
||||
});
|
||||
@@ -0,0 +1,12 @@
|
||||
// @target: esnext
|
||||
// @module: system
|
||||
// @noTypesAndSymbols: true
|
||||
if (false) {
|
||||
var y = 1;
|
||||
}
|
||||
|
||||
function f() {
|
||||
console.log(y);
|
||||
}
|
||||
|
||||
export { y };
|
||||
Reference in New Issue
Block a user