Skip to content

Add support for captured block scoped bindings #7693

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Mar 29, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 34 additions & 2 deletions src/compiler/factory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -482,6 +482,19 @@ namespace ts {
return node;
}

export function createSwitch(expression: Expression, caseBlock: CaseBlock, location?: TextRange): SwitchStatement {
const node = <SwitchStatement>createNode(SyntaxKind.SwitchStatement, location);
node.expression = parenthesizeExpressionForList(expression);
node.caseBlock = caseBlock;
return node;
}

export function createCaseBlock(clauses: CaseClause[], location?: TextRange): CaseBlock {
const node = <CaseBlock>createNode(SyntaxKind.CaseBlock, location);
node.clauses = createNodeArray(clauses);
return node;
}

export function createFor(initializer: ForInitializer, condition: Expression, incrementor: Expression, statement: Statement, location?: TextRange) {
const node = <ForStatement>createNode(SyntaxKind.ForStatement, location);
node.initializer = initializer;
Expand Down Expand Up @@ -687,6 +700,22 @@ namespace ts {
);
}

export function createBreak(label?: Identifier, location?: TextRange): BreakStatement {
const node = <BreakStatement>createNode(SyntaxKind.BreakStatement, location);
if (label) {
node.label = label;
}
return node;
}

export function createContinue(label?: Identifier, location?: TextRange): BreakStatement {
const node = <ContinueStatement>createNode(SyntaxKind.ContinueStatement, location);
if (label) {
node.label = label;
}
return node;
}

export function createFunctionApply(func: Expression, thisArg: Expression, argumentsExpression: Expression, location?: TextRange) {
return createCall(
createPropertyAccess(func, "apply"),
Expand Down Expand Up @@ -1349,8 +1378,11 @@ namespace ts {
return clone;
}
}
else if (getLeftmostExpression(expression).kind === SyntaxKind.ObjectLiteralExpression) {
return createParen(expression, /*location*/ expression);
else {
const leftmostExpressionKind = getLeftmostExpression(expression).kind;
if (leftmostExpressionKind === SyntaxKind.ObjectLiteralExpression || leftmostExpressionKind === SyntaxKind.FunctionExpression) {
return createParen(expression, /*location*/ expression);
}
}

return expression;
Expand Down
11 changes: 10 additions & 1 deletion src/compiler/printer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1751,7 +1751,16 @@ const _super = (function (geti, seti) {
}

function emitCaseOrDefaultClauseStatements(parentNode: Node, statements: NodeArray<Statement>) {
if (statements.length === 1 && rangeStartPositionsAreOnSameLine(parentNode, statements[0], currentSourceFile)) {
const emitAsSingleStatement =
statements.length === 1 &&
(
// treat synthesized nodes as located on the same line for emit purposes
nodeIsSynthesized(parentNode) ||
nodeIsSynthesized(statements[0]) ||
rangeStartPositionsAreOnSameLine(parentNode, statements[0], currentSourceFile)
);

if (emitAsSingleStatement) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: Newline above

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

write(" ");
emit(statements[0]);
}
Expand Down
2 changes: 1 addition & 1 deletion src/compiler/transformers/destructuring.ts
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ namespace ts {

const pendingAssignments: Expression[] = [];

flattenDestructuring(context, node, /*value*/ undefined, node, emitAssignment, emitTempVariableAssignment);
flattenDestructuring(context, node, /*value*/ undefined, node, emitAssignment, emitTempVariableAssignment, visitor);

const expression = inlineExpressions(pendingAssignments);
aggregateTransformFlags(expression);
Expand Down
Loading