Skip to content

Commit 3989d23

Browse files
committed
Merge pull request #7693 from Microsoft/transforms-block-scoped-bindings
Add support for captured block scoped bindings
2 parents 6ba0285 + 5d8d3b8 commit 3989d23

33 files changed

+1172
-291
lines changed

src/compiler/factory.ts

Lines changed: 34 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -482,6 +482,19 @@ namespace ts {
482482
return node;
483483
}
484484

485+
export function createSwitch(expression: Expression, caseBlock: CaseBlock, location?: TextRange): SwitchStatement {
486+
const node = <SwitchStatement>createNode(SyntaxKind.SwitchStatement, location);
487+
node.expression = parenthesizeExpressionForList(expression);
488+
node.caseBlock = caseBlock;
489+
return node;
490+
}
491+
492+
export function createCaseBlock(clauses: CaseClause[], location?: TextRange): CaseBlock {
493+
const node = <CaseBlock>createNode(SyntaxKind.CaseBlock, location);
494+
node.clauses = createNodeArray(clauses);
495+
return node;
496+
}
497+
485498
export function createFor(initializer: ForInitializer, condition: Expression, incrementor: Expression, statement: Statement, location?: TextRange) {
486499
const node = <ForStatement>createNode(SyntaxKind.ForStatement, location);
487500
node.initializer = initializer;
@@ -687,6 +700,22 @@ namespace ts {
687700
);
688701
}
689702

703+
export function createBreak(label?: Identifier, location?: TextRange): BreakStatement {
704+
const node = <BreakStatement>createNode(SyntaxKind.BreakStatement, location);
705+
if (label) {
706+
node.label = label;
707+
}
708+
return node;
709+
}
710+
711+
export function createContinue(label?: Identifier, location?: TextRange): BreakStatement {
712+
const node = <ContinueStatement>createNode(SyntaxKind.ContinueStatement, location);
713+
if (label) {
714+
node.label = label;
715+
}
716+
return node;
717+
}
718+
690719
export function createFunctionApply(func: Expression, thisArg: Expression, argumentsExpression: Expression, location?: TextRange) {
691720
return createCall(
692721
createPropertyAccess(func, "apply"),
@@ -1349,8 +1378,11 @@ namespace ts {
13491378
return clone;
13501379
}
13511380
}
1352-
else if (getLeftmostExpression(expression).kind === SyntaxKind.ObjectLiteralExpression) {
1353-
return createParen(expression, /*location*/ expression);
1381+
else {
1382+
const leftmostExpressionKind = getLeftmostExpression(expression).kind;
1383+
if (leftmostExpressionKind === SyntaxKind.ObjectLiteralExpression || leftmostExpressionKind === SyntaxKind.FunctionExpression) {
1384+
return createParen(expression, /*location*/ expression);
1385+
}
13541386
}
13551387

13561388
return expression;

src/compiler/printer.ts

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1751,7 +1751,16 @@ const _super = (function (geti, seti) {
17511751
}
17521752

17531753
function emitCaseOrDefaultClauseStatements(parentNode: Node, statements: NodeArray<Statement>) {
1754-
if (statements.length === 1 && rangeStartPositionsAreOnSameLine(parentNode, statements[0], currentSourceFile)) {
1754+
const emitAsSingleStatement =
1755+
statements.length === 1 &&
1756+
(
1757+
// treat synthesized nodes as located on the same line for emit purposes
1758+
nodeIsSynthesized(parentNode) ||
1759+
nodeIsSynthesized(statements[0]) ||
1760+
rangeStartPositionsAreOnSameLine(parentNode, statements[0], currentSourceFile)
1761+
);
1762+
1763+
if (emitAsSingleStatement) {
17551764
write(" ");
17561765
emit(statements[0]);
17571766
}

src/compiler/transformers/destructuring.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,7 @@ namespace ts {
165165

166166
const pendingAssignments: Expression[] = [];
167167

168-
flattenDestructuring(context, node, /*value*/ undefined, node, emitAssignment, emitTempVariableAssignment);
168+
flattenDestructuring(context, node, /*value*/ undefined, node, emitAssignment, emitTempVariableAssignment, visitor);
169169

170170
const expression = inlineExpressions(pendingAssignments);
171171
aggregateTransformFlags(expression);

0 commit comments

Comments
 (0)