From 4ae83fa8d351e767478f5f94f27c14e56cdf1635 Mon Sep 17 00:00:00 2001 From: Ron Buckton Date: Tue, 17 May 2016 22:44:19 -0700 Subject: [PATCH] Fix issues after merge --- src/compiler/factory.ts | 82 ++++++++++++------------- src/compiler/printer.ts | 8 --- src/compiler/transformers/generators.ts | 34 +++++++--- 3 files changed, 65 insertions(+), 59 deletions(-) diff --git a/src/compiler/factory.ts b/src/compiler/factory.ts index 06a7bb66e71..768ec165d8e 100644 --- a/src/compiler/factory.ts +++ b/src/compiler/factory.ts @@ -112,7 +112,7 @@ namespace ts { export function createLiteral(textSource: StringLiteral | Identifier, location?: TextRange, emitOptions?: NodeEmitOptions): StringLiteral; export function createLiteral(value: string, location?: TextRange, emitOptions?: NodeEmitOptions): StringLiteral; - export function createLiteral(value: number, location?: TextRange, emitOptions?: NodeEmitOptions): LiteralExpression; + export function createLiteral(value: number, location?: TextRange, emitOptions?: NodeEmitOptions): NumericLiteral; export function createLiteral(value: string | number | boolean, location?: TextRange, emitOptions?: NodeEmitOptions): PrimaryExpression; export function createLiteral(value: string | number | boolean | StringLiteral | Identifier, location?: TextRange, emitOptions?: NodeEmitOptions): PrimaryExpression { if (typeof value === "number") { @@ -505,7 +505,7 @@ namespace ts { return node; } - export function createCaseBlock(clauses: CaseClause[], location?: TextRange): CaseBlock { + export function createCaseBlock(clauses: CaseOrDefaultClause[], location?: TextRange): CaseBlock { const node = createNode(SyntaxKind.CaseBlock, location); node.clauses = createNodeArray(clauses); return node; @@ -570,13 +570,6 @@ namespace ts { return node; } - export function createSwitch(expression: Expression, caseBlock: CaseBlock, location?: TextRange): ReturnStatement { - const node = createNode(SyntaxKind.SwitchStatement, location); - node.expression = expression; - node.caseBlock = caseBlock; - return node; - } - export function createThrow(expression: Expression, location?: TextRange): ReturnStatement { const node = createNode(SyntaxKind.ThrowStatement, location); node.expression = expression; @@ -626,12 +619,6 @@ namespace ts { return node; } - export function createCaseBlock(clauses: CaseOrDefaultClause[], location?: TextRange) { - const node = createNode(SyntaxKind.CaseBlock, location); - node.clauses = createNodeArray(clauses); - return node; - } - export function createExportDefault(expression: Expression) { const node = createNode(SyntaxKind.ExportAssignment); node.isExportEquals = false; @@ -1262,34 +1249,47 @@ namespace ts { function createExpressionForAccessorDeclaration(properties: NodeArray, property: AccessorDeclaration, receiver: Expression, multiLine: boolean) { const { firstAccessor, getAccessor, setAccessor } = getAllAccessorDeclarations(properties, property); if (property === firstAccessor) { - return aggregateTransformFlags( - createObjectDefineProperty( + const properties: ObjectLiteralElement[] = []; + if (getAccessor) { + const getterFunction = createFunctionExpression( + /*asteriskToken*/ undefined, + /*name*/ undefined, + getAccessor.parameters, + getAccessor.body, + /*location*/ getAccessor, + /*original*/ getAccessor + ); + const getter = createPropertyAssignment("get", getterFunction); + properties.push(getter); + } + + if (setAccessor) { + const setterFunction = createFunctionExpression( + /*asteriskToken*/ undefined, + /*name*/ undefined, + setAccessor.parameters, + setAccessor.body, + /*location*/ setAccessor, + /*original*/ setAccessor + ); + const setter = createPropertyAssignment("set", setterFunction); + properties.push(setter); + } + + properties.push(createPropertyAssignment("enumerable", createLiteral(true))); + properties.push(createPropertyAssignment("configurable", createLiteral(true))); + + const expression = createCall( + createPropertyAccess(createIdentifier("Object"), "defineProperty"), + [ receiver, - createExpressionForPropertyName(property.name, /*location*/ property.name), - { - get: getAccessor && createFunctionExpression( - /*asteriskToken*/ undefined, - /*name*/ undefined, - getAccessor.parameters, - getAccessor.body, - /*location*/ getAccessor, - /*original*/ getAccessor - ), - set: setAccessor && createFunctionExpression( - /*asteriskToken*/ undefined, - /*name*/ undefined, - setAccessor.parameters, - setAccessor.body, - /*location*/ setAccessor, - /*original*/ setAccessor - ), - enumerable: true, - configurable: true - }, - multiLine, - /*location*/ firstAccessor - ) + createExpressionForPropertyName(property.name), + createObjectLiteral(properties, /*location*/ undefined, multiLine) + ], + /*location*/ firstAccessor ); + + return aggregateTransformFlags(expression); } return undefined; diff --git a/src/compiler/printer.ts b/src/compiler/printer.ts index 83895b27ffe..3a19a5d0f43 100644 --- a/src/compiler/printer.ts +++ b/src/compiler/printer.ts @@ -2129,14 +2129,6 @@ const _super = (function (geti, seti) { } } - function shouldEmitCaseOrDefaultClauseStatementOnSameLine(parentNode: Node, statement: Statement) { - if (statement.startsOnNewLine || nodeIsSynthesized(parentNode)) { - return false; - } - - return nodeIsSynthesized(statement) || rangeStartPositionsAreOnSameLine(parentNode, statement); - } - function emitHeritageClause(node: HeritageClause) { write(" "); writeTokenText(node.token); diff --git a/src/compiler/transformers/generators.ts b/src/compiler/transformers/generators.ts index 073cf50c90a..54d02593caa 100644 --- a/src/compiler/transformers/generators.ts +++ b/src/compiler/transformers/generators.ts @@ -235,11 +235,13 @@ namespace ts { endLexicalEnvironment, hoistFunctionDeclaration, hoistVariableDeclaration, + setSourceMapRange, + setCommentRange } = context; const resolver = context.getEmitResolver(); - const previousExpressionSubstitution = context.expressionSubstitution; - context.expressionSubstitution = substituteExpression; + const previousOnSubstituteNode = context.onSubstituteNode; + context.onSubstituteNode = onSubstituteNode; let renamedCatchVariables: Map; let renamedCatchVariableDeclarations: Map; @@ -994,7 +996,7 @@ namespace ts { // .mark resumeLabel // _b.apply(_a, _c.concat([%sent%, 2])); - const { target, thisArg } = createCallBinding(node.expression); + const { target, thisArg } = createCallBinding(node.expression, hoistVariableDeclaration); return setOriginalNode( createFunctionApply( cacheExpression(visitNode(target, visitor, isLeftHandSideExpression)), @@ -1022,7 +1024,7 @@ namespace ts { // .mark resumeLabel // new (_b.apply(_a, _c.concat([%sent%, 2]))); - const { target, thisArg } = createCallBinding(createPropertyAccess(node.expression, "bind")); + const { target, thisArg } = createCallBinding(createPropertyAccess(node.expression, "bind"), hoistVariableDeclaration); return setOriginalNode( createNew( createFunctionApply( @@ -1807,8 +1809,15 @@ namespace ts { return -1; } + function onSubstituteNode(node: Node, isExpression: boolean): Node { + node = previousOnSubstituteNode(node, isExpression); + if (isExpression) { + return substituteExpression( node); + } + return node; + } + function substituteExpression(node: Expression): Expression { - node = previousExpressionSubstitution(node); if (isIdentifier(node)) { return substituteExpressionIdentifier(node); } @@ -1823,7 +1832,10 @@ namespace ts { if (declaration) { const name = getProperty(renamedCatchVariableDeclarations, String(getOriginalNodeId(declaration))); if (name) { - return getRelocatedClone(name, /*location*/ node); + const clone = getMutableClone(name); + setSourceMapRange(clone, node); + setCommentRange(clone, node); + return clone; } } } @@ -1842,7 +1854,7 @@ namespace ts { temp = createUniqueName(node.text); } else { - temp = createTempVariable(); + temp = createTempVariable(hoistVariableDeclaration); } emitAssignment(temp, node, /*location*/ node); @@ -1852,7 +1864,7 @@ namespace ts { function declareLocal(name?: string): Identifier { const temp = name ? createUniqueName(name) - : createTempVariable(); + : createTempVariable(hoistVariableDeclaration); hoistVariableDeclaration(temp); return temp; } @@ -1991,7 +2003,7 @@ namespace ts { if (!renamedCatchVariables) { renamedCatchVariables = {}; renamedCatchVariableDeclarations = {}; - context.enableExpressionSubstitution(SyntaxKind.Identifier); + context.enableSubstitution(SyntaxKind.Identifier); } renamedCatchVariables[text] = true; @@ -2300,7 +2312,9 @@ namespace ts { * Creates a numeric literal for the provided instruction. */ function createInstruction(instruction: Instruction): NumericLiteral { - return createLiteral(instruction, /*location*/ undefined, instructionNames[instruction]); + const literal = createLiteral(instruction); + literal.trailingComment = instructionNames[instruction]; + return literal; } /**