From cd2cf7d3c6ac93a5c14ff83c75387f149bdbe1a5 Mon Sep 17 00:00:00 2001 From: Ron Buckton Date: Mon, 29 Feb 2016 13:28:16 -0800 Subject: [PATCH 1/9] PR Feedback and defer makeUniqueName/getGeneratedNameForNode to printer. --- src/compiler/factory.ts | 34 +++++--- src/compiler/printer.ts | 162 +++++++++++++++++++++++++++--------- src/compiler/transformer.ts | 118 -------------------------- src/compiler/types.ts | 17 ++-- src/compiler/utilities.ts | 12 +-- 5 files changed, 161 insertions(+), 182 deletions(-) diff --git a/src/compiler/factory.ts b/src/compiler/factory.ts index 8f388a01520..eae769fd562 100644 --- a/src/compiler/factory.ts +++ b/src/compiler/factory.ts @@ -185,24 +185,38 @@ namespace ts { // Identifiers - export function createIdentifier(text: string): Identifier { - const node = createNode(SyntaxKind.Identifier); + export function createIdentifier(text: string, location?: TextRange): Identifier { + const node = createNode(SyntaxKind.Identifier, location); node.text = text; return node; } - export function createTempVariable(): Identifier { - const name = createNode(SyntaxKind.Identifier); - name.text = undefined; - name.tempKind = TempVariableKind.Auto; + export function createTempVariable(location?: TextRange): Identifier { + const name = createNode(SyntaxKind.Identifier, location); + name.autoGenerateKind = GeneratedIdentifierKind.Auto; getNodeId(name); return name; } - export function createLoopVariable(): Identifier { - const name = createNode(SyntaxKind.Identifier); - name.text = undefined; - name.tempKind = TempVariableKind.Loop; + export function createLoopVariable(location?: TextRange): Identifier { + const name = createNode(SyntaxKind.Identifier, location); + name.autoGenerateKind = GeneratedIdentifierKind.Loop; + getNodeId(name); + return name; + } + + export function createUniqueName(text: string, location?: TextRange): Identifier { + const name = createNode(SyntaxKind.Identifier, location); + name.text = text; + name.autoGenerateKind = GeneratedIdentifierKind.Unique; + getNodeId(name); + return name; + } + + export function createGeneratedNameForNode(node: Node, location?: TextRange): Identifier { + const name = createNode(SyntaxKind.Identifier, location); + name.autoGenerateKind = GeneratedIdentifierKind.Node; + name.original = node; getNodeId(name); return name; } diff --git a/src/compiler/printer.ts b/src/compiler/printer.ts index a1d284dd42b..e44e88b4612 100644 --- a/src/compiler/printer.ts +++ b/src/compiler/printer.ts @@ -121,7 +121,6 @@ const _super = (function (geti, seti) { const writer = createTextWriter(newLine); const { write, - writeTextOfNode, writeLine, increaseIndent, decreaseIndent @@ -154,11 +153,12 @@ const _super = (function (geti, seti) { let identifierSubstitution: (node: Identifier) => Identifier; let onBeforeEmitNode: (node: Node) => void; let onAfterEmitNode: (node: Node) => void; - let isUniqueName: (name: string) => boolean; - let temporaryVariables: string[] = []; + let nodeToGeneratedName: string[]; + let generatedNameSet: Map; let tempFlags: TempFlags; let currentSourceFile: SourceFile; let currentText: string; + let currentFileIdentifiers: Map; let extendsEmitted: boolean; let decorateEmitted: boolean; let paramEmitted: boolean; @@ -169,6 +169,8 @@ const _super = (function (geti, seti) { function doPrint(jsFilePath: string, sourceMapFilePath: string, sourceFiles: SourceFile[], isBundledEmit: boolean) { sourceMap.initialize(jsFilePath, sourceMapFilePath, sourceFiles, isBundledEmit); + nodeToGeneratedName = []; + generatedNameSet = {}; isOwnFileEmit = !isBundledEmit; // Emit helpers from all the files @@ -213,8 +215,6 @@ const _super = (function (geti, seti) { identifierSubstitution = undefined; onBeforeEmitNode = undefined; onAfterEmitNode = undefined; - isUniqueName = undefined; - temporaryVariables = undefined; tempFlags = TempFlags.Auto; currentSourceFile = undefined; currentText = undefined; @@ -236,13 +236,13 @@ const _super = (function (geti, seti) { identifierSubstitution = context.identifierSubstitution; onBeforeEmitNode = context.onBeforeEmitNode; onAfterEmitNode = context.onAfterEmitNode; - isUniqueName = context.isUniqueName; return printSourceFile; } function printSourceFile(node: SourceFile) { currentSourceFile = node; currentText = node.text; + currentFileIdentifiers = node.identifiers; sourceMap.setSourceFile(node); comments.setSourceFile(node); emitWorker(node); @@ -659,22 +659,11 @@ const _super = (function (geti, seti) { // function emitIdentifier(node: Identifier) { - if (node.text === undefined) { - // Emit a temporary variable name for this node. - const nodeId = getOriginalNodeId(node); - const text = temporaryVariables[nodeId] || (temporaryVariables[nodeId] = makeTempVariableName(tempKindToFlags(node.tempKind))); - write(text); - } - else if (nodeIsSynthesized(node) || !node.parent) { - if (getNodeEmitFlags(node) & NodeEmitFlags.UMDDefine) { - writeLines(umdHelper); - } - else { - write(node.text); - } + if (getNodeEmitFlags(node) && NodeEmitFlags.UMDDefine) { + writeLines(umdHelper); } else { - writeTextOfNode(currentText, node); + write(getTextOfNode(node, /*includeTrivia*/ false)); } } @@ -1720,7 +1709,6 @@ const _super = (function (geti, seti) { emitExpression(node.expression); write(":"); - debugger; emitCaseOrDefaultClauseStatements(node, node.statements); } @@ -1763,14 +1751,14 @@ const _super = (function (geti, seti) { function emitPropertyAssignment(node: PropertyAssignment) { emit(node.name); write(": "); - // // This is to ensure that we emit comment in the following case: - // // For example: - // // obj = { - // // id: /*comment1*/ ()=>void - // // } - // // "comment1" is not considered to be leading comment for node.initializer - // // but rather a trailing comment on the previous node. - // emitTrailingCommentsOfPosition(node.initializer.pos); + // This is to ensure that we emit comment in the following case: + // For example: + // obj = { + // id: /*comment1*/ ()=>void + // } + // "comment1" is not considered to be leading comment for node.initializer + // but rather a trailing comment on the previous node. + emitLeadingComments(node.initializer, getTrailingComments(collapseTextRange(node.initializer, TextRangeCollapse.CollapseToStart))); emitExpression(node.initializer); } @@ -1951,11 +1939,8 @@ const _super = (function (geti, seti) { } function emitModifiers(node: Node, modifiers: ModifiersArray) { - const startingPos = writer.getTextPos(); - emitList(node, modifiers, ListFormat.SingleLine); - - const endingPos = writer.getTextPos(); - if (startingPos !== endingPos) { + if (modifiers && modifiers.length) { + emitList(node, modifiers, ListFormat.SingleLine); write(" "); } } @@ -2345,7 +2330,15 @@ const _super = (function (geti, seti) { } function getTextOfNode(node: Node, includeTrivia?: boolean) { - if (nodeIsSynthesized(node) && (isLiteralExpression(node) || isIdentifier(node))) { + if (isIdentifier(node)) { + if (node.autoGenerateKind) { + return getGeneratedIdentifier(node); + } + else if (nodeIsSynthesized(node) || !node.parent) { + return node.text; + } + } + else if (isLiteralExpression(node) && (nodeIsSynthesized(node) || !node.parent)) { return node.text; } @@ -2368,10 +2361,22 @@ const _super = (function (geti, seti) { && rangeEndIsOnSameLineAsRangeStart(block, block); } - function tempKindToFlags(kind: TempVariableKind) { - return kind === TempVariableKind.Loop - ? TempFlags._i - : TempFlags.Auto; + function isUniqueName(name: string): boolean { + return !resolver.hasGlobalName(name) && + !hasProperty(currentFileIdentifiers, name) && + !hasProperty(generatedNameSet, name); + } + + function isUniqueLocalName(name: string, container: Node): boolean { + for (let node = container; isNodeDescendentOf(node, container); node = node.nextContainer) { + if (node.locals && hasProperty(node.locals, name)) { + // We conservatively include alias symbols to cover cases where they're emitted as locals + if (node.locals[name].flags & (SymbolFlags.Value | SymbolFlags.ExportValue | SymbolFlags.Alias)) { + return false; + } + } + } + return true; } /** @@ -2401,6 +2406,85 @@ const _super = (function (geti, seti) { } } } + + // Generate a name that is unique within the current file and doesn't conflict with any names + // in global scope. The name is formed by adding an '_n' suffix to the specified base name, + // where n is a positive integer. Note that names generated by makeTempVariableName and + // makeUniqueName are guaranteed to never conflict. + function makeUniqueName(baseName: string): string { + // Find the first unique 'name_n', where n is a positive number + if (baseName.charCodeAt(baseName.length - 1) !== CharacterCodes._) { + baseName += "_"; + } + let i = 1; + while (true) { + const generatedName = baseName + i; + if (isUniqueName(generatedName)) { + return generatedNameSet[generatedName] = generatedName; + } + i++; + } + } + + function generateNameForModuleOrEnum(node: ModuleDeclaration | EnumDeclaration) { + const name = node.name.text; + // Use module/enum name itself if it is unique, otherwise make a unique variation + return isUniqueLocalName(name, node) ? name : makeUniqueName(name); + } + + function generateNameForImportOrExportDeclaration(node: ImportDeclaration | ExportDeclaration) { + const expr = getExternalModuleName(node); + const baseName = expr.kind === SyntaxKind.StringLiteral ? + escapeIdentifier(makeIdentifierFromModuleName((expr).text)) : "module"; + return makeUniqueName(baseName); + } + + function generateNameForExportDefault() { + return makeUniqueName("default"); + } + + function generateNameForClassExpression() { + return makeUniqueName("class"); + } + + function generateNameForNode(node: Node) { + switch (node.kind) { + case SyntaxKind.Identifier: + return makeUniqueName((node).text); + case SyntaxKind.ModuleDeclaration: + case SyntaxKind.EnumDeclaration: + return generateNameForModuleOrEnum(node); + case SyntaxKind.ImportDeclaration: + case SyntaxKind.ExportDeclaration: + return generateNameForImportOrExportDeclaration(node); + case SyntaxKind.FunctionDeclaration: + case SyntaxKind.ClassDeclaration: + case SyntaxKind.ExportAssignment: + return generateNameForExportDefault(); + case SyntaxKind.ClassExpression: + return generateNameForClassExpression(); + default: + return makeTempVariableName(TempFlags.Auto); + } + } + + function generateIdentifier(node: Identifier) { + switch (node.autoGenerateKind) { + case GeneratedIdentifierKind.Auto: + return makeTempVariableName(TempFlags.Auto); + case GeneratedIdentifierKind.Loop: + return makeTempVariableName(TempFlags._i); + case GeneratedIdentifierKind.Unique: + return makeUniqueName(node.text); + case GeneratedIdentifierKind.Node: + return generateNameForNode(getOriginalNode(node)); + } + } + + function getGeneratedIdentifier(node: Identifier) { + const id = getOriginalNodeId(node); + return nodeToGeneratedName[id] || (nodeToGeneratedName[id] = unescapeIdentifier(generateIdentifier(node))); + } } } diff --git a/src/compiler/transformer.ts b/src/compiler/transformer.ts index 65d61c044c2..98b71f0c16e 100644 --- a/src/compiler/transformer.ts +++ b/src/compiler/transformer.ts @@ -22,8 +22,6 @@ namespace ts { * @param transforms An array of Transformers. */ export function transformFiles(resolver: EmitResolver, host: EmitHost, sourceFiles: SourceFile[], transformers: Transformer[]) { - const nodeToGeneratedName: Identifier[] = []; - const generatedNameSet: Map = {}; const nodeEmitFlags: NodeEmitFlags[] = []; const lexicalEnvironmentVariableDeclarationsStack: VariableDeclaration[][] = []; const lexicalEnvironmentFunctionDeclarationsStack: FunctionDeclaration[][] = []; @@ -40,10 +38,6 @@ namespace ts { getEmitResolver: () => resolver, getNodeEmitFlags, setNodeEmitFlags, - isUniqueName, - getGeneratedNameForNode, - nodeHasGeneratedName, - makeUniqueName, hoistVariableDeclaration, hoistFunctionDeclaration, startLexicalEnvironment, @@ -119,118 +113,6 @@ namespace ts { return node; } - /** - * Generate a name that is unique within the current file and doesn't conflict with any names - * in global scope. The name is formed by adding an '_n' suffix to the specified base name, - * where n is a positive integer. Note that names generated by makeTempVariableName and - * makeUniqueName are guaranteed to never conflict. - */ - function makeUniqueName(baseName: string): Identifier { - // Find the first unique 'name_n', where n is a positive number - if (baseName.charCodeAt(baseName.length - 1) !== CharacterCodes._) { - baseName += "_"; - } - - let i = 1; - while (true) { - const generatedName = baseName + i; - if (isUniqueName(generatedName)) { - return createIdentifier(generatedNameSet[generatedName] = generatedName); - } - - i++; - } - } - - /** - * Gets the generated name for a node. - */ - function getGeneratedNameForNode(node: Node) { - const id = getNodeId(node); - return nodeToGeneratedName[id] || (nodeToGeneratedName[id] = generateNameForNode(node)); - } - - /** - * Gets a value indicating whether a node has a generated name. - */ - function nodeHasGeneratedName(node: Node) { - const id = getNodeId(node); - return nodeToGeneratedName[id] !== undefined; - } - - /** - * Tests whether the provided name is unique. - */ - function isUniqueName(name: string): boolean { - return !resolver.hasGlobalName(name) - && !hasProperty(currentSourceFile.identifiers, name) - && !hasProperty(generatedNameSet, name); - } - - /** - * Tests whether the provided name is unique within a container. - */ - function isUniqueLocalName(name: string, container: Node): boolean { - container = getOriginalNode(container); - for (let node = container; isNodeDescendentOf(node, container); node = node.nextContainer) { - if (node.locals && hasProperty(node.locals, name)) { - // We conservatively include alias symbols to cover cases where they're emitted as locals - if (node.locals[name].flags & (SymbolFlags.Value | SymbolFlags.ExportValue | SymbolFlags.Alias)) { - return false; - } - } - } - return true; - } - - /** - * Generates a name for a node. - */ - function generateNameForNode(node: Node): Identifier { - switch (node.kind) { - case SyntaxKind.Identifier: - return makeUniqueName((node).text); - case SyntaxKind.ModuleDeclaration: - case SyntaxKind.EnumDeclaration: - return generateNameForModuleOrEnum(node); - case SyntaxKind.ImportDeclaration: - case SyntaxKind.ExportDeclaration: - return generateNameForImportOrExportDeclaration(node); - case SyntaxKind.FunctionDeclaration: - case SyntaxKind.ClassDeclaration: - Debug.assert((node.flags & NodeFlags.Default) !== 0, "Can only generate a name for a default export."); - return generateNameForExportDefault(); - case SyntaxKind.ExportAssignment: - return generateNameForExportDefault(); - case SyntaxKind.ClassExpression: - return generateNameForClassExpression(); - default: - return createTempVariable(); - } - } - - function generateNameForModuleOrEnum(node: ModuleDeclaration | EnumDeclaration) { - const name = node.name; - // Use module/enum name itself if it is unique, otherwise make a unique variation - return isUniqueLocalName(name.text, node) ? name : makeUniqueName(name.text); - } - - function generateNameForImportOrExportDeclaration(node: ImportDeclaration | ExportDeclaration) { - const expr = getExternalModuleName(node); - const baseName = expr.kind === SyntaxKind.StringLiteral - ? escapeIdentifier(makeIdentifierFromModuleName((expr).text)) - : "module"; - return makeUniqueName(baseName); - } - - function generateNameForExportDefault() { - return makeUniqueName("default"); - } - - function generateNameForClassExpression() { - return makeUniqueName("class"); - } - /** * Records a hoisted variable declaration for the provided name within a lexical environment. */ diff --git a/src/compiler/types.ts b/src/compiler/types.ts index 6a55153f631..fb5ab0c3609 100644 --- a/src/compiler/types.ts +++ b/src/compiler/types.ts @@ -497,16 +497,19 @@ namespace ts { // @kind(SyntaxKind.StaticKeyword) export interface Modifier extends Node { } - export const enum TempVariableKind { - Auto, // Automatically generated identifier - Loop, // Automatically generated identifier with a preference for '_i' + export const enum GeneratedIdentifierKind { + None, // Not automatically generated. + Auto, // Automatically generated identifier. + Loop, // Automatically generated identifier with a preference for '_i'. + Unique, // Unique name based on the 'text' property. + Node, // Unique name based on the node in the 'original' property. } // @kind(SyntaxKind.Identifier) export interface Identifier extends PrimaryExpression { text: string; // Text of identifier (with escapes converted to characters) - tempKind?: TempVariableKind; // Specifies whether to auto-generate the text for an identifier. originalKeywordKind?: SyntaxKind; // Original syntaxKind which get set so that we can report an error later + autoGenerateKind?: GeneratedIdentifierKind; // Specifies whether to auto-generate the text for an identifier. } // @kind(SyntaxKind.QualifiedName) @@ -2805,7 +2808,7 @@ namespace ts { SingleLine = 1 << 6, // The contents of this node should be emit on a single line. AdviseOnEmitNode = 1 << 7, // The node printer should invoke the onBeforeEmitNode and onAfterEmitNode callbacks when printing this node. IsNotEmittedNode = 1 << 8, // Is a node that is not emitted but whose comments should be preserved if possible. - EmitCommentsOfNotEmittedParent = 1 << 8, // Emits comments of missing parent nodes. + EmitCommentsOfNotEmittedParent = 1 << 9, // Emits comments of missing parent nodes. } /** Additional context provided to `visitEachChild` */ @@ -2825,10 +2828,6 @@ namespace ts { setNodeEmitFlags(node: T, flags: NodeEmitFlags): T; hoistFunctionDeclaration(node: FunctionDeclaration): void; hoistVariableDeclaration(node: Identifier): void; - isUniqueName(name: string): boolean; - getGeneratedNameForNode(node: Node): Identifier; - nodeHasGeneratedName(node: Node): boolean; - makeUniqueName(baseName: string): Identifier; /** * Hook used by transformers to substitute non-expression identifiers diff --git a/src/compiler/utilities.ts b/src/compiler/utilities.ts index 10b5b467158..514ee5f258d 100644 --- a/src/compiler/utilities.ts +++ b/src/compiler/utilities.ts @@ -2297,11 +2297,11 @@ namespace ts { writer.write(" "); } - let emitInterveningSeperator = false; + let emitInterveningSeparator = false; for (const comment of comments) { - if (emitInterveningSeperator) { + if (emitInterveningSeparator) { writer.write(" "); - emitInterveningSeperator = false; + emitInterveningSeparator = false; } writeComment(text, lineMap, writer, comment, newLine); @@ -2309,11 +2309,11 @@ namespace ts { writer.writeLine(); } else { - emitInterveningSeperator = true; + emitInterveningSeparator = true; } } - if (emitInterveningSeperator && trailingSeparator) { + if (emitInterveningSeparator && trailingSeparator) { writer.write(" "); } } @@ -2723,7 +2723,7 @@ namespace ts { } return collapse === TextRangeCollapse.CollapseToStart - ? { pos: range.pos, end: range.end } + ? { pos: range.pos, end: range.pos } : { pos: range.end, end: range.end }; } From b1d88282ce4d56a79ae0f2aa5d53e392cb01e556 Mon Sep 17 00:00:00 2001 From: Ron Buckton Date: Mon, 29 Feb 2016 13:29:03 -0800 Subject: [PATCH 2/9] Remove transformCompatibleEmit flag and make it the default. --- Jakefile.js | 8 - src/compiler/commandLineParser.ts | 7 - src/compiler/emitter.ts | 27 +- src/compiler/types.ts | 1 - ...ticVariableAndExportedVarThatShareAName.js | 4 +- ...VariableAndNonExportedVarThatShareAName.js | 4 +- ...onWithInvalidConstOnPropertyDeclaration.js | 2 +- .../baselines/reference/ES5SymbolProperty1.js | 3 +- .../amdImportNotAsPrimaryExpression.js | 2 +- tests/baselines/reference/autolift4.js | 2 +- .../blockScopedVariablesUseBeforeDef.js | 30 +- tests/baselines/reference/class2.js | 2 +- .../classExpressionWithDecorator1.js | 8 +- .../classExpressionWithStaticProperties1.js | 16 +- .../classExpressionWithStaticProperties2.js | 14 +- .../classMemberInitializerScoping.js | 2 +- .../classMemberInitializerWithLamdaScoping.js | 14 +- .../reference/classWithPrivateProperty.js | 2 +- .../reference/classWithProtectedProperty.js | 2 +- .../reference/classWithPublicProperty.js | 2 +- .../reference/cloduleStaticMembers.js | 4 +- .../reference/commentsOnStaticMembers.js | 16 +- .../commonJSImportAsPrimaryExpression.js | 2 +- .../commonJSImportNotAsPrimaryExpression.js | 2 +- .../reference/computedPropertyNames10_ES5.js | 3 +- .../reference/computedPropertyNames11_ES5.js | 3 +- .../reference/computedPropertyNames12_ES5.js | 2 +- .../reference/computedPropertyNames18_ES5.js | 3 +- .../reference/computedPropertyNames19_ES5.js | 3 +- .../reference/computedPropertyNames1_ES5.js | 3 +- .../reference/computedPropertyNames20_ES5.js | 3 +- .../reference/computedPropertyNames22_ES5.js | 3 +- .../reference/computedPropertyNames25_ES5.js | 3 +- .../reference/computedPropertyNames28_ES5.js | 3 +- .../reference/computedPropertyNames29_ES5.js | 3 +- .../reference/computedPropertyNames30_ES5.js | 3 +- .../reference/computedPropertyNames31_ES5.js | 3 +- .../reference/computedPropertyNames33_ES5.js | 3 +- .../reference/computedPropertyNames34_ES5.js | 3 +- .../reference/computedPropertyNames46_ES5.js | 3 +- .../reference/computedPropertyNames47_ES5.js | 3 +- .../reference/computedPropertyNames48_ES5.js | 9 +- .../reference/computedPropertyNames49_ES5.js | 3 +- .../reference/computedPropertyNames4_ES5.js | 3 +- .../reference/computedPropertyNames50_ES5.js | 3 +- .../reference/computedPropertyNames5_ES5.js | 3 +- .../reference/computedPropertyNames6_ES5.js | 3 +- .../reference/computedPropertyNames7_ES5.js | 3 +- .../reference/computedPropertyNames8_ES5.js | 3 +- .../reference/computedPropertyNames9_ES5.js | 3 +- ...mputedPropertyNamesContextualType10_ES5.js | 3 +- ...omputedPropertyNamesContextualType1_ES5.js | 3 +- ...omputedPropertyNamesContextualType2_ES5.js | 3 +- ...omputedPropertyNamesContextualType3_ES5.js | 3 +- ...omputedPropertyNamesContextualType4_ES5.js | 3 +- ...omputedPropertyNamesContextualType5_ES5.js | 3 +- ...omputedPropertyNamesContextualType6_ES5.js | 3 +- ...omputedPropertyNamesContextualType7_ES5.js | 3 +- ...omputedPropertyNamesContextualType8_ES5.js | 3 +- ...omputedPropertyNamesContextualType9_ES5.js | 3 +- ...mputedPropertyNamesDeclarationEmit5_ES5.js | 3 +- .../computedPropertyNamesSourceMap2_ES5.js | 3 +- ...computedPropertyNamesSourceMap2_ES5.js.map | 2 +- ...dPropertyNamesSourceMap2_ES5.sourcemap.txt | 16 +- ...TypedClassExpressionMethodDeclaration01.js | 40 +- .../reference/declFilePrivateStatic.js | 4 +- .../reference/decoratorCallGeneric.js | 6 +- .../decoratorChecksFunctionBodies.js | 14 +- ...ratorInstantiateModulesInFunctionBodies.js | 6 +- .../baselines/reference/decoratorMetadata.js | 20 +- ...taForMethodWithNoReturnTypeAnnotation01.js | 12 +- .../decoratorMetadataOnInferredType.js | 8 +- .../decoratorMetadataWithConstructorType.js | 8 +- ...adataWithImportDeclarationNameCollision.js | 8 +- ...dataWithImportDeclarationNameCollision2.js | 8 +- ...dataWithImportDeclarationNameCollision3.js | 8 +- ...dataWithImportDeclarationNameCollision4.js | 8 +- ...dataWithImportDeclarationNameCollision5.js | 8 +- ...dataWithImportDeclarationNameCollision6.js | 8 +- ...dataWithImportDeclarationNameCollision7.js | 8 +- ...dataWithImportDeclarationNameCollision8.js | 8 +- .../baselines/reference/decoratorOnClass1.js | 6 +- .../baselines/reference/decoratorOnClass2.js | 6 +- .../baselines/reference/decoratorOnClass3.js | 6 +- .../baselines/reference/decoratorOnClass4.js | 6 +- .../baselines/reference/decoratorOnClass5.js | 6 +- .../baselines/reference/decoratorOnClass8.js | 6 +- .../reference/decoratorOnClassAccessor1.js | 6 +- .../reference/decoratorOnClassAccessor2.js | 6 +- .../reference/decoratorOnClassAccessor3.js | 6 +- .../reference/decoratorOnClassAccessor4.js | 6 +- .../reference/decoratorOnClassAccessor5.js | 6 +- .../reference/decoratorOnClassAccessor6.js | 6 +- .../decoratorOnClassConstructorParameter1.js | 6 +- .../decoratorOnClassConstructorParameter4.js | 6 +- .../reference/decoratorOnClassMethod1.js | 6 +- .../reference/decoratorOnClassMethod10.js | 6 +- .../reference/decoratorOnClassMethod11.js | 6 +- .../reference/decoratorOnClassMethod12.js | 6 +- .../reference/decoratorOnClassMethod2.js | 6 +- .../reference/decoratorOnClassMethod3.js | 6 +- .../reference/decoratorOnClassMethod8.js | 6 +- .../decoratorOnClassMethodOverload2.js | 6 +- .../decoratorOnClassMethodParameter1.js | 6 +- .../reference/decoratorOnClassProperty1.js | 6 +- .../reference/decoratorOnClassProperty10.js | 6 +- .../reference/decoratorOnClassProperty11.js | 6 +- .../reference/decoratorOnClassProperty2.js | 6 +- .../reference/decoratorOnClassProperty3.js | 6 +- .../reference/decoratorOnClassProperty6.js | 6 +- .../reference/decoratorOnClassProperty7.js | 6 +- ...dClassSuperCallsInNonConstructorMembers.js | 2 +- tests/baselines/reference/errorSuperCalls.js | 4 +- .../reference/errorSuperPropertyAccess.js | 4 +- .../reference/es3defaultAliasIsQuoted.js | 2 +- tests/baselines/reference/es6ClassTest.js | 2 +- tests/baselines/reference/es6ClassTest2.js | 2 +- .../reference/generatedContextualTyping.js | 72 +- ...nericClassWithStaticsUsingTypeArguments.js | 8 +- .../baselines/reference/gettersAndSetters.js | 2 +- .../reference/importImportOnlyModule.js | 2 +- .../instanceAndStaticDeclarations1.js | 2 +- .../baselines/reference/invalidStaticField.js | 2 +- .../literalsInComputedProperties1.js | 3 +- .../reference/missingDecoratorType.js | 6 +- ...difierOnClassExpressionMemberInFunction.js | 18 +- tests/baselines/reference/noEmitHelpers2.js | 10 +- .../parserAccessibilityAfterStatic3.js | 2 +- ...ErrorRecovery_IncompleteMemberVariable1.js | 4 +- ...ErrorRecovery_IncompleteMemberVariable2.js | 4 +- tests/baselines/reference/parserharness.js | 6 +- .../privacyCannotNameVarTypeDeclFile.js | 24 +- tests/baselines/reference/privateIndexer2.js | 3 +- .../privateStaticMemberAccessibility.js | 2 +- .../reference/propertyAccessibility2.js | 2 +- .../reference/quotedPropertyName2.js | 2 +- .../baselines/reference/reassignStaticProp.js | 2 +- .../reference/sourceMap-FileWithComments.js | 4 +- .../sourceMap-FileWithComments.js.map | 2 +- .../sourceMap-FileWithComments.sourcemap.txt | 133 ++-- .../sourceMapValidationDecorators.js | 62 +- .../sourceMapValidationDecorators.js.map | 2 +- ...ourceMapValidationDecorators.sourcemap.txt | 650 +++++++++--------- tests/baselines/reference/staticClassProps.js | 2 +- .../staticMemberAccessOffDerivedType1.js | 2 +- .../reference/staticMemberInitialization.js | 2 +- .../staticMemberWithStringAndNumberNames.js | 10 +- .../reference/staticModifierAlreadySeen.js | 2 +- tests/baselines/reference/staticPropSuper.js | 2 +- tests/baselines/reference/statics.js | 6 +- .../reference/staticsInConstructorBodies.js | 2 +- .../reference/staticsNotInScopeInClodule.js | 2 +- .../reference/strictModeInConstructor.js | 6 +- tests/baselines/reference/superAccess.js | 2 +- tests/baselines/reference/superAccess2.js | 2 +- ...thisInArrowFunctionInStaticInitializer1.js | 8 +- .../reference/thisInConstructorParameter2.js | 2 +- .../reference/thisInInvalidContexts.js | 2 +- .../thisInInvalidContextsExternalModule.js | 2 +- .../reference/thisInOuterClassBody.js | 2 +- .../thisInPropertyBoundDeclarations.js | 10 +- .../reference/thisInStaticMethod1.js | 2 +- tests/baselines/reference/thisTypeErrors.js | 2 +- ...peArgumentInferenceWithClassExpression1.js | 14 +- ...peArgumentInferenceWithClassExpression2.js | 14 +- tests/baselines/reference/typeOfPrototype.js | 2 +- .../reference/typeOfThisInStaticMembers2.js | 4 +- tests/baselines/reference/typeQueryOnClass.js | 4 +- .../unqualifiedCallToClassStatic1.js | 8 +- tests/baselines/reference/witness.js | 2 +- tests/cases/unittests/transpile.ts | 126 ++-- 171 files changed, 947 insertions(+), 1017 deletions(-) diff --git a/Jakefile.js b/Jakefile.js index d1821b5b5e0..7b9c4806e0a 100644 --- a/Jakefile.js +++ b/Jakefile.js @@ -223,7 +223,6 @@ function concatenateFiles(destinationFile, sourceFiles) { var useDebugMode = true; var useTransforms = process.env.USE_TRANSFORMS || false; -var useTransformCompat = false; var host = (process.env.host || process.env.TYPESCRIPT_HOST || "node"); var compilerFilename = "tsc.js"; var LKGCompiler = path.join(LKGDirectory, compilerFilename); @@ -286,9 +285,6 @@ function compileFile(outFile, sources, prereqs, prefixes, useBuiltCompiler, noOu if (useBuiltCompiler && useTransforms) { options += " --experimentalTransforms" } - else if (useBuiltCompiler && useTransformCompat) { - options += " --transformCompatibleEmit" - } var cmd = host + " " + compilerPath + " " + options + " "; cmd = cmd + sources.join(" "); @@ -417,10 +413,6 @@ task("setTransforms", function() { useTransforms = true; }); -task("setTransformCompat", function() { - useTransformCompat = true; -}); - task("configure-nightly", [configureNightlyJs], function() { var cmd = host + " " + configureNightlyJs + " " + packageJson + " " + programTs; console.log(cmd); diff --git a/src/compiler/commandLineParser.ts b/src/compiler/commandLineParser.ts index 307bb5d5403..cc2806f93c1 100644 --- a/src/compiler/commandLineParser.ts +++ b/src/compiler/commandLineParser.ts @@ -327,13 +327,6 @@ namespace ts { name: "experimentalTransforms", type: "boolean", experimental: true - }, - { - // this option will be removed when this is merged with master and exists solely - // to enable the tree transforming emitter side-by-side with the existing emitter. - name: "transformCompatibleEmit", - type: "boolean", - experimental: true } ]; diff --git a/src/compiler/emitter.ts b/src/compiler/emitter.ts index 357fec7f0fd..a3c27d8d817 100644 --- a/src/compiler/emitter.ts +++ b/src/compiler/emitter.ts @@ -1915,9 +1915,6 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge if (multiLine) { decreaseIndent(); - if (!compilerOptions.transformCompatibleEmit) { - writeLine(); - } } write(")"); @@ -2237,7 +2234,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge return forEach(elements, e => e.kind === SyntaxKind.SpreadElementExpression); } - function skipParentheses(node: Expression): Expression { + function skipParenthesesAndAssertions(node: Expression): Expression { while (node.kind === SyntaxKind.ParenthesizedExpression || node.kind === SyntaxKind.TypeAssertionExpression || node.kind === SyntaxKind.AsExpression) { node = (node).expression; } @@ -2268,7 +2265,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge function emitCallWithSpread(node: CallExpression) { let target: Expression; - const expr = skipParentheses(node.expression); + const expr = skipParenthesesAndAssertions(node.expression); if (expr.kind === SyntaxKind.PropertyAccessExpression) { // Target will be emitted as "this" argument target = emitCallTarget((expr).expression); @@ -4334,9 +4331,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge writeLine(); emitStart(restParam); emitNodeWithCommentsAndWithoutSourcemap(restParam.name); - write(restIndex > 0 || !compilerOptions.transformCompatibleEmit - ? `[${tempName} - ${restIndex}] = arguments[${tempName}];` - : `[${tempName}] = arguments[${tempName}];`); + write(`[${tempName} - ${restIndex}] = arguments[${tempName}];`); emitEnd(restParam); decreaseIndent(); writeLine(); @@ -5356,7 +5351,7 @@ const _super = (function (geti, seti) { const isClassExpressionWithStaticProperties = staticProperties.length > 0 && node.kind === SyntaxKind.ClassExpression; let tempVariable: Identifier; - if (isClassExpressionWithStaticProperties && compilerOptions.transformCompatibleEmit) { + if (isClassExpressionWithStaticProperties) { tempVariable = createAndRecordTempVariable(TempFlags.Auto); write("("); increaseIndent(); @@ -5393,11 +5388,6 @@ const _super = (function (geti, seti) { writeLine(); emitConstructor(node, baseTypeNode); emitMemberFunctionsForES5AndLower(node); - if (!compilerOptions.transformCompatibleEmit) { - emitPropertyDeclarations(node, staticProperties); - writeLine(); - emitDecoratorsOfClass(node, /*decoratedClassAlias*/ undefined); - } writeLine(); emitToken(SyntaxKind.CloseBraceToken, node.members.end, () => { write("return "); @@ -5424,13 +5414,10 @@ const _super = (function (geti, seti) { write("))"); if (node.kind === SyntaxKind.ClassDeclaration) { write(";"); - if (compilerOptions.transformCompatibleEmit) { - emitPropertyDeclarations(node, staticProperties); - writeLine(); - emitDecoratorsOfClass(node, /*decoratedClassAlias*/ undefined); - } + emitPropertyDeclarations(node, staticProperties); + emitDecoratorsOfClass(node, /*decoratedClassAlias*/ undefined); } - else if (isClassExpressionWithStaticProperties && compilerOptions.transformCompatibleEmit) { + else if (isClassExpressionWithStaticProperties) { for (const property of staticProperties) { write(","); writeLine(); diff --git a/src/compiler/types.ts b/src/compiler/types.ts index fb5ab0c3609..07d1daec669 100644 --- a/src/compiler/types.ts +++ b/src/compiler/types.ts @@ -2473,7 +2473,6 @@ namespace ts { allowJs?: boolean; /* @internal */ stripInternal?: boolean; /* @internal */ experimentalTransforms?: boolean; - /* @internal */ transformCompatibleEmit?: boolean; // Skip checking lib.d.ts to help speed up tests. /* @internal */ skipDefaultLibCheck?: boolean; diff --git a/tests/baselines/reference/ClassAndModuleThatMergeWithStaticVariableAndExportedVarThatShareAName.js b/tests/baselines/reference/ClassAndModuleThatMergeWithStaticVariableAndExportedVarThatShareAName.js index a0cb50e7382..63d3739846b 100644 --- a/tests/baselines/reference/ClassAndModuleThatMergeWithStaticVariableAndExportedVarThatShareAName.js +++ b/tests/baselines/reference/ClassAndModuleThatMergeWithStaticVariableAndExportedVarThatShareAName.js @@ -28,9 +28,9 @@ var Point = (function () { this.x = x; this.y = y; } - Point.Origin = { x: 0, y: 0 }; return Point; }()); +Point.Origin = { x: 0, y: 0 }; var Point; (function (Point) { Point.Origin = ""; //expected duplicate identifier error @@ -42,9 +42,9 @@ var A; this.x = x; this.y = y; } - Point.Origin = { x: 0, y: 0 }; return Point; }()); + Point.Origin = { x: 0, y: 0 }; A.Point = Point; var Point; (function (Point) { diff --git a/tests/baselines/reference/ClassAndModuleThatMergeWithStaticVariableAndNonExportedVarThatShareAName.js b/tests/baselines/reference/ClassAndModuleThatMergeWithStaticVariableAndNonExportedVarThatShareAName.js index 3bbf3b98d6e..3921546a21c 100644 --- a/tests/baselines/reference/ClassAndModuleThatMergeWithStaticVariableAndNonExportedVarThatShareAName.js +++ b/tests/baselines/reference/ClassAndModuleThatMergeWithStaticVariableAndNonExportedVarThatShareAName.js @@ -28,9 +28,9 @@ var Point = (function () { this.x = x; this.y = y; } - Point.Origin = { x: 0, y: 0 }; return Point; }()); +Point.Origin = { x: 0, y: 0 }; var Point; (function (Point) { var Origin = ""; // not an error, since not exported @@ -42,9 +42,9 @@ var A; this.x = x; this.y = y; } - Point.Origin = { x: 0, y: 0 }; return Point; }()); + Point.Origin = { x: 0, y: 0 }; A.Point = Point; var Point; (function (Point) { diff --git a/tests/baselines/reference/ClassDeclarationWithInvalidConstOnPropertyDeclaration.js b/tests/baselines/reference/ClassDeclarationWithInvalidConstOnPropertyDeclaration.js index d5c3b3d63f4..7633955b227 100644 --- a/tests/baselines/reference/ClassDeclarationWithInvalidConstOnPropertyDeclaration.js +++ b/tests/baselines/reference/ClassDeclarationWithInvalidConstOnPropertyDeclaration.js @@ -7,6 +7,6 @@ class AtomicNumbers { var AtomicNumbers = (function () { function AtomicNumbers() { } - AtomicNumbers.H = 1; return AtomicNumbers; }()); +AtomicNumbers.H = 1; diff --git a/tests/baselines/reference/ES5SymbolProperty1.js b/tests/baselines/reference/ES5SymbolProperty1.js index 1073a33163d..ab3f420c95c 100644 --- a/tests/baselines/reference/ES5SymbolProperty1.js +++ b/tests/baselines/reference/ES5SymbolProperty1.js @@ -14,7 +14,6 @@ obj[Symbol.foo]; var Symbol; var obj = (_a = {}, _a[Symbol.foo] = 0, - _a -); + _a); obj[Symbol.foo]; var _a; diff --git a/tests/baselines/reference/amdImportNotAsPrimaryExpression.js b/tests/baselines/reference/amdImportNotAsPrimaryExpression.js index beb91191bc0..0739792fddd 100644 --- a/tests/baselines/reference/amdImportNotAsPrimaryExpression.js +++ b/tests/baselines/reference/amdImportNotAsPrimaryExpression.js @@ -38,9 +38,9 @@ define(["require", "exports"], function (require, exports) { function C1() { this.m1 = 42; } - C1.s1 = true; return C1; }()); + C1.s1 = true; exports.C1 = C1; (function (E1) { E1[E1["A"] = 0] = "A"; diff --git a/tests/baselines/reference/autolift4.js b/tests/baselines/reference/autolift4.js index 8ee1f397d43..e6790021f63 100644 --- a/tests/baselines/reference/autolift4.js +++ b/tests/baselines/reference/autolift4.js @@ -37,9 +37,9 @@ var Point = (function () { Point.prototype.getDist = function () { return Math.sqrt(this.x * this.x + this.y * this.y); }; - Point.origin = new Point(0, 0); return Point; }()); +Point.origin = new Point(0, 0); var Point3D = (function (_super) { __extends(Point3D, _super); function Point3D(x, y, z, m) { diff --git a/tests/baselines/reference/blockScopedVariablesUseBeforeDef.js b/tests/baselines/reference/blockScopedVariablesUseBeforeDef.js index 06eaa9916e3..0197d919fef 100644 --- a/tests/baselines/reference/blockScopedVariablesUseBeforeDef.js +++ b/tests/baselines/reference/blockScopedVariablesUseBeforeDef.js @@ -163,31 +163,35 @@ function foo8() { var x; } function foo9() { - var y = (function () { - function class_3() { - } - class_3.a = x; - return class_3; - }()); + var y = (_a = (function () { + function class_3() { + } + return class_3; + }()), + _a.a = x, + _a); var x; + var _a; } function foo10() { var A = (function () { function A() { } - A.a = x; return A; }()); + A.a = x; var x; } function foo11() { function f() { - var y = (function () { - function class_4() { - } - class_4.a = x; - return class_4; - }()); + var y = (_a = (function () { + function class_4() { + } + return class_4; + }()), + _a.a = x, + _a); + var _a; } var x; } diff --git a/tests/baselines/reference/class2.js b/tests/baselines/reference/class2.js index 6ef78ed46ee..91ac89da109 100644 --- a/tests/baselines/reference/class2.js +++ b/tests/baselines/reference/class2.js @@ -5,6 +5,6 @@ class foo { constructor() { static f = 3; } } var foo = (function () { function foo() { } - foo.f = 3; return foo; }()); +foo.f = 3; diff --git a/tests/baselines/reference/classExpressionWithDecorator1.js b/tests/baselines/reference/classExpressionWithDecorator1.js index e051e05251b..9b52891b559 100644 --- a/tests/baselines/reference/classExpressionWithDecorator1.js +++ b/tests/baselines/reference/classExpressionWithDecorator1.js @@ -12,10 +12,10 @@ var v = ; var C = (function () { function C() { } - C.p = 1; - C = __decorate([ - decorate - ], C); return C; }()); +C.p = 1; +C = __decorate([ + decorate +], C); ; diff --git a/tests/baselines/reference/classExpressionWithStaticProperties1.js b/tests/baselines/reference/classExpressionWithStaticProperties1.js index cfe85d97a71..23d18d76766 100644 --- a/tests/baselines/reference/classExpressionWithStaticProperties1.js +++ b/tests/baselines/reference/classExpressionWithStaticProperties1.js @@ -2,10 +2,12 @@ var v = class C { static a = 1; static b = 2 }; //// [classExpressionWithStaticProperties1.js] -var v = (function () { - function C() { - } - C.a = 1; - C.b = 2; - return C; -}()); +var v = (_a = (function () { + function C() { + } + return C; + }()), + _a.a = 1, + _a.b = 2, + _a); +var _a; diff --git a/tests/baselines/reference/classExpressionWithStaticProperties2.js b/tests/baselines/reference/classExpressionWithStaticProperties2.js index 134441e0ad9..b9fc0345591 100644 --- a/tests/baselines/reference/classExpressionWithStaticProperties2.js +++ b/tests/baselines/reference/classExpressionWithStaticProperties2.js @@ -2,9 +2,11 @@ var v = class C { static a = 1; static b }; //// [classExpressionWithStaticProperties2.js] -var v = (function () { - function C() { - } - C.a = 1; - return C; -}()); +var v = (_a = (function () { + function C() { + } + return C; + }()), + _a.a = 1, + _a); +var _a; diff --git a/tests/baselines/reference/classMemberInitializerScoping.js b/tests/baselines/reference/classMemberInitializerScoping.js index 8f78cfb9ac6..52bbaee8945 100644 --- a/tests/baselines/reference/classMemberInitializerScoping.js +++ b/tests/baselines/reference/classMemberInitializerScoping.js @@ -27,9 +27,9 @@ var CCC = (function () { this.y = aaa; this.y = ''; // was: error, cannot assign string to number } - CCC.staticY = aaa; // This shouldnt be error return CCC; }()); +CCC.staticY = aaa; // This shouldnt be error // above is equivalent to this: var aaaa = 1; var CCCC = (function () { diff --git a/tests/baselines/reference/classMemberInitializerWithLamdaScoping.js b/tests/baselines/reference/classMemberInitializerWithLamdaScoping.js index 752220a4cbc..c5b661831a2 100644 --- a/tests/baselines/reference/classMemberInitializerWithLamdaScoping.js +++ b/tests/baselines/reference/classMemberInitializerWithLamdaScoping.js @@ -40,12 +40,12 @@ var Test = (function () { console.log(field); // Using field here shouldnt be error }; } - Test.staticMessageHandler = function () { - var field = Test.field; - console.log(field); // Using field here shouldnt be error - }; return Test; }()); +Test.staticMessageHandler = function () { + var field = Test.field; + console.log(field); // Using field here shouldnt be error +}; var field1; var Test1 = (function () { function Test1(field1) { @@ -56,8 +56,8 @@ var Test1 = (function () { // it would resolve to private field1 and thats not what user intended here. }; } - Test1.staticMessageHandler = function () { - console.log(field1); // This shouldnt be error as its a static property - }; return Test1; }()); +Test1.staticMessageHandler = function () { + console.log(field1); // This shouldnt be error as its a static property +}; diff --git a/tests/baselines/reference/classWithPrivateProperty.js b/tests/baselines/reference/classWithPrivateProperty.js index 6e75797523f..c94f1d8ed80 100644 --- a/tests/baselines/reference/classWithPrivateProperty.js +++ b/tests/baselines/reference/classWithPrivateProperty.js @@ -32,9 +32,9 @@ var C = (function () { } C.prototype.c = function () { return ''; }; C.f = function () { return ''; }; - C.g = function () { return ''; }; return C; }()); +C.g = function () { return ''; }; var c = new C(); var r1 = c.x; var r2 = c.a; diff --git a/tests/baselines/reference/classWithProtectedProperty.js b/tests/baselines/reference/classWithProtectedProperty.js index 75eadaf4010..2b2e01e59df 100644 --- a/tests/baselines/reference/classWithProtectedProperty.js +++ b/tests/baselines/reference/classWithProtectedProperty.js @@ -42,9 +42,9 @@ var C = (function () { } C.prototype.c = function () { return ''; }; C.f = function () { return ''; }; - C.g = function () { return ''; }; return C; }()); +C.g = function () { return ''; }; var D = (function (_super) { __extends(D, _super); function D() { diff --git a/tests/baselines/reference/classWithPublicProperty.js b/tests/baselines/reference/classWithPublicProperty.js index 054713264bd..47708b7aff3 100644 --- a/tests/baselines/reference/classWithPublicProperty.js +++ b/tests/baselines/reference/classWithPublicProperty.js @@ -30,9 +30,9 @@ var C = (function () { } C.prototype.c = function () { return ''; }; C.f = function () { return ''; }; - C.g = function () { return ''; }; return C; }()); +C.g = function () { return ''; }; // all of these are valid var c = new C(); var r1 = c.x; diff --git a/tests/baselines/reference/cloduleStaticMembers.js b/tests/baselines/reference/cloduleStaticMembers.js index 6095442b629..868b9305bdf 100644 --- a/tests/baselines/reference/cloduleStaticMembers.js +++ b/tests/baselines/reference/cloduleStaticMembers.js @@ -16,10 +16,10 @@ module Clod { var Clod = (function () { function Clod() { } - Clod.x = 10; - Clod.y = 10; return Clod; }()); +Clod.x = 10; +Clod.y = 10; var Clod; (function (Clod) { var p = Clod.x; diff --git a/tests/baselines/reference/commentsOnStaticMembers.js b/tests/baselines/reference/commentsOnStaticMembers.js index 51ed906841d..851f9025be3 100644 --- a/tests/baselines/reference/commentsOnStaticMembers.js +++ b/tests/baselines/reference/commentsOnStaticMembers.js @@ -24,13 +24,13 @@ class test { var test = (function () { function test() { } - /** - * p1 comment appears in output - */ - test.p1 = ""; - /** - * p3 comment appears in output - */ - test.p3 = ""; return test; }()); +/** + * p1 comment appears in output + */ +test.p1 = ""; +/** + * p3 comment appears in output + */ +test.p3 = ""; diff --git a/tests/baselines/reference/commonJSImportAsPrimaryExpression.js b/tests/baselines/reference/commonJSImportAsPrimaryExpression.js index 3f49588c103..b8cf42ea762 100644 --- a/tests/baselines/reference/commonJSImportAsPrimaryExpression.js +++ b/tests/baselines/reference/commonJSImportAsPrimaryExpression.js @@ -19,9 +19,9 @@ var C1 = (function () { function C1() { this.m1 = 42; } - C1.s1 = true; return C1; }()); +C1.s1 = true; exports.C1 = C1; //// [foo_1.js] "use strict"; diff --git a/tests/baselines/reference/commonJSImportNotAsPrimaryExpression.js b/tests/baselines/reference/commonJSImportNotAsPrimaryExpression.js index 720554f7e32..34d5c343b3c 100644 --- a/tests/baselines/reference/commonJSImportNotAsPrimaryExpression.js +++ b/tests/baselines/reference/commonJSImportNotAsPrimaryExpression.js @@ -37,9 +37,9 @@ var C1 = (function () { function C1() { this.m1 = 42; } - C1.s1 = true; return C1; }()); +C1.s1 = true; exports.C1 = C1; (function (E1) { E1[E1["A"] = 0] = "A"; diff --git a/tests/baselines/reference/computedPropertyNames10_ES5.js b/tests/baselines/reference/computedPropertyNames10_ES5.js index 14d9235b12b..302f9355be8 100644 --- a/tests/baselines/reference/computedPropertyNames10_ES5.js +++ b/tests/baselines/reference/computedPropertyNames10_ES5.js @@ -32,6 +32,5 @@ var v = (_a = {}, _a[true] = function () { }, _a["hello bye"] = function () { }, _a["hello " + a + " bye"] = function () { }, - _a -); + _a); var _a; diff --git a/tests/baselines/reference/computedPropertyNames11_ES5.js b/tests/baselines/reference/computedPropertyNames11_ES5.js index 0917f824770..4fc74b30cbe 100644 --- a/tests/baselines/reference/computedPropertyNames11_ES5.js +++ b/tests/baselines/reference/computedPropertyNames11_ES5.js @@ -68,6 +68,5 @@ var v = (_a = {}, enumerable: true, configurable: true }), - _a -); + _a); var _a; diff --git a/tests/baselines/reference/computedPropertyNames12_ES5.js b/tests/baselines/reference/computedPropertyNames12_ES5.js index 2aec8856286..10427b5dc13 100644 --- a/tests/baselines/reference/computedPropertyNames12_ES5.js +++ b/tests/baselines/reference/computedPropertyNames12_ES5.js @@ -26,6 +26,6 @@ var C = (function () { this[s + n] = 2; this["hello bye"] = 0; } - C["hello " + a + " bye"] = 0; return C; }()); +C["hello " + a + " bye"] = 0; diff --git a/tests/baselines/reference/computedPropertyNames18_ES5.js b/tests/baselines/reference/computedPropertyNames18_ES5.js index b65c7fd4f7d..a62af506531 100644 --- a/tests/baselines/reference/computedPropertyNames18_ES5.js +++ b/tests/baselines/reference/computedPropertyNames18_ES5.js @@ -9,7 +9,6 @@ function foo() { function foo() { var obj = (_a = {}, _a[this.bar] = 0, - _a - ); + _a); var _a; } diff --git a/tests/baselines/reference/computedPropertyNames19_ES5.js b/tests/baselines/reference/computedPropertyNames19_ES5.js index 36f3e66c7c2..bda3e01bbed 100644 --- a/tests/baselines/reference/computedPropertyNames19_ES5.js +++ b/tests/baselines/reference/computedPropertyNames19_ES5.js @@ -10,7 +10,6 @@ var M; (function (M) { var obj = (_a = {}, _a[this.bar] = 0, - _a - ); + _a); var _a; })(M || (M = {})); diff --git a/tests/baselines/reference/computedPropertyNames1_ES5.js b/tests/baselines/reference/computedPropertyNames1_ES5.js index 4fdec28c7aa..75bbe909927 100644 --- a/tests/baselines/reference/computedPropertyNames1_ES5.js +++ b/tests/baselines/reference/computedPropertyNames1_ES5.js @@ -17,6 +17,5 @@ var v = (_a = {}, enumerable: true, configurable: true }), - _a -); + _a); var _a; diff --git a/tests/baselines/reference/computedPropertyNames20_ES5.js b/tests/baselines/reference/computedPropertyNames20_ES5.js index 65acd7fa08f..1eec0a7bcdb 100644 --- a/tests/baselines/reference/computedPropertyNames20_ES5.js +++ b/tests/baselines/reference/computedPropertyNames20_ES5.js @@ -6,6 +6,5 @@ var obj = { //// [computedPropertyNames20_ES5.js] var obj = (_a = {}, _a[this.bar] = 0, - _a -); + _a); var _a; diff --git a/tests/baselines/reference/computedPropertyNames22_ES5.js b/tests/baselines/reference/computedPropertyNames22_ES5.js index 5448f4dcf8d..721418ee930 100644 --- a/tests/baselines/reference/computedPropertyNames22_ES5.js +++ b/tests/baselines/reference/computedPropertyNames22_ES5.js @@ -15,8 +15,7 @@ var C = (function () { C.prototype.bar = function () { var obj = (_a = {}, _a[this.bar()] = function () { }, - _a - ); + _a); return 0; var _a; }; diff --git a/tests/baselines/reference/computedPropertyNames25_ES5.js b/tests/baselines/reference/computedPropertyNames25_ES5.js index f38ac0b2e0d..b03dd285ced 100644 --- a/tests/baselines/reference/computedPropertyNames25_ES5.js +++ b/tests/baselines/reference/computedPropertyNames25_ES5.js @@ -35,8 +35,7 @@ var C = (function (_super) { C.prototype.foo = function () { var obj = (_a = {}, _a[_super.prototype.bar.call(this)] = function () { }, - _a - ); + _a); return 0; var _a; }; diff --git a/tests/baselines/reference/computedPropertyNames28_ES5.js b/tests/baselines/reference/computedPropertyNames28_ES5.js index b5b1fdf77aa..ed15bbf0145 100644 --- a/tests/baselines/reference/computedPropertyNames28_ES5.js +++ b/tests/baselines/reference/computedPropertyNames28_ES5.js @@ -27,8 +27,7 @@ var C = (function (_super) { _super.call(this); var obj = (_a = {}, _a[(_super.call(this), "prop")] = function () { }, - _a - ); + _a); var _a; } return C; diff --git a/tests/baselines/reference/computedPropertyNames29_ES5.js b/tests/baselines/reference/computedPropertyNames29_ES5.js index 46ba529d7a5..af6f93c8ad9 100644 --- a/tests/baselines/reference/computedPropertyNames29_ES5.js +++ b/tests/baselines/reference/computedPropertyNames29_ES5.js @@ -19,8 +19,7 @@ var C = (function () { (function () { var obj = (_a = {}, _a[_this.bar()] = function () { }, - _a - ); + _a); var _a; }); return 0; diff --git a/tests/baselines/reference/computedPropertyNames30_ES5.js b/tests/baselines/reference/computedPropertyNames30_ES5.js index e787689d393..a900fd44c67 100644 --- a/tests/baselines/reference/computedPropertyNames30_ES5.js +++ b/tests/baselines/reference/computedPropertyNames30_ES5.js @@ -36,8 +36,7 @@ var C = (function (_super) { // illegal, and not capturing this is consistent with //treatment of other similar violations. _a[(_super.call(this), "prop")] = function () { }, - _a - ); + _a); var _a; }); } diff --git a/tests/baselines/reference/computedPropertyNames31_ES5.js b/tests/baselines/reference/computedPropertyNames31_ES5.js index 8417f103fb7..86fb6655a27 100644 --- a/tests/baselines/reference/computedPropertyNames31_ES5.js +++ b/tests/baselines/reference/computedPropertyNames31_ES5.js @@ -39,8 +39,7 @@ var C = (function (_super) { (function () { var obj = (_a = {}, _a[_super.prototype.bar.call(_this)] = function () { }, - _a - ); + _a); var _a; }); return 0; diff --git a/tests/baselines/reference/computedPropertyNames33_ES5.js b/tests/baselines/reference/computedPropertyNames33_ES5.js index 8db62818e22..e6d46b03c10 100644 --- a/tests/baselines/reference/computedPropertyNames33_ES5.js +++ b/tests/baselines/reference/computedPropertyNames33_ES5.js @@ -17,8 +17,7 @@ var C = (function () { C.prototype.bar = function () { var obj = (_a = {}, _a[foo()] = function () { }, - _a - ); + _a); return 0; var _a; }; diff --git a/tests/baselines/reference/computedPropertyNames34_ES5.js b/tests/baselines/reference/computedPropertyNames34_ES5.js index fa0af2897f7..3109c400422 100644 --- a/tests/baselines/reference/computedPropertyNames34_ES5.js +++ b/tests/baselines/reference/computedPropertyNames34_ES5.js @@ -17,8 +17,7 @@ var C = (function () { C.bar = function () { var obj = (_a = {}, _a[foo()] = function () { }, - _a - ); + _a); return 0; var _a; }; diff --git a/tests/baselines/reference/computedPropertyNames46_ES5.js b/tests/baselines/reference/computedPropertyNames46_ES5.js index 307dadcbe91..815f5769f3b 100644 --- a/tests/baselines/reference/computedPropertyNames46_ES5.js +++ b/tests/baselines/reference/computedPropertyNames46_ES5.js @@ -6,6 +6,5 @@ var o = { //// [computedPropertyNames46_ES5.js] var o = (_a = {}, _a["" || 0] = 0, - _a -); + _a); var _a; diff --git a/tests/baselines/reference/computedPropertyNames47_ES5.js b/tests/baselines/reference/computedPropertyNames47_ES5.js index d03b614b29b..a2fff2110b4 100644 --- a/tests/baselines/reference/computedPropertyNames47_ES5.js +++ b/tests/baselines/reference/computedPropertyNames47_ES5.js @@ -16,6 +16,5 @@ var E2; })(E2 || (E2 = {})); var o = (_a = {}, _a[E1.x || E2.x] = 0, - _a -); + _a); var _a; diff --git a/tests/baselines/reference/computedPropertyNames48_ES5.js b/tests/baselines/reference/computedPropertyNames48_ES5.js index 15123a98f30..55b08ef8301 100644 --- a/tests/baselines/reference/computedPropertyNames48_ES5.js +++ b/tests/baselines/reference/computedPropertyNames48_ES5.js @@ -25,14 +25,11 @@ var E; var a; extractIndexer((_a = {}, _a[a] = "", - _a -)); // Should return string + _a)); // Should return string extractIndexer((_b = {}, _b[E.x] = "", - _b -)); // Should return string + _b)); // Should return string extractIndexer((_c = {}, _c["" || 0] = "", - _c -)); // Should return any (widened form of undefined) + _c)); // Should return any (widened form of undefined) var _a, _b, _c; diff --git a/tests/baselines/reference/computedPropertyNames49_ES5.js b/tests/baselines/reference/computedPropertyNames49_ES5.js index 3427ea665a0..12c3430fbe9 100644 --- a/tests/baselines/reference/computedPropertyNames49_ES5.js +++ b/tests/baselines/reference/computedPropertyNames49_ES5.js @@ -62,6 +62,5 @@ var x = (_a = { }), , _a.p2 = 20, - _a -); + _a); var _a; diff --git a/tests/baselines/reference/computedPropertyNames4_ES5.js b/tests/baselines/reference/computedPropertyNames4_ES5.js index f91476c79c1..ac0fa8ec937 100644 --- a/tests/baselines/reference/computedPropertyNames4_ES5.js +++ b/tests/baselines/reference/computedPropertyNames4_ES5.js @@ -32,6 +32,5 @@ var v = (_a = {}, _a[true] = 0, _a["hello bye"] = 0, _a["hello " + a + " bye"] = 0, - _a -); + _a); var _a; diff --git a/tests/baselines/reference/computedPropertyNames50_ES5.js b/tests/baselines/reference/computedPropertyNames50_ES5.js index a74561295be..db9a03578df 100644 --- a/tests/baselines/reference/computedPropertyNames50_ES5.js +++ b/tests/baselines/reference/computedPropertyNames50_ES5.js @@ -58,6 +58,5 @@ var x = (_a = { }), , _a.p2 = 20, - _a -); + _a); var _a; diff --git a/tests/baselines/reference/computedPropertyNames5_ES5.js b/tests/baselines/reference/computedPropertyNames5_ES5.js index 58c5af2efa3..3367faa2c20 100644 --- a/tests/baselines/reference/computedPropertyNames5_ES5.js +++ b/tests/baselines/reference/computedPropertyNames5_ES5.js @@ -18,6 +18,5 @@ var v = (_a = {}, _a[{}] = 0, _a[undefined] = undefined, _a[null] = null, - _a -); + _a); var _a; diff --git a/tests/baselines/reference/computedPropertyNames6_ES5.js b/tests/baselines/reference/computedPropertyNames6_ES5.js index 7e9c6202940..29d035bfcbf 100644 --- a/tests/baselines/reference/computedPropertyNames6_ES5.js +++ b/tests/baselines/reference/computedPropertyNames6_ES5.js @@ -16,6 +16,5 @@ var v = (_a = {}, _a[p1] = 0, _a[p2] = 1, _a[p3] = 2, - _a -); + _a); var _a; diff --git a/tests/baselines/reference/computedPropertyNames7_ES5.js b/tests/baselines/reference/computedPropertyNames7_ES5.js index 3311ec7e092..01cf2efc030 100644 --- a/tests/baselines/reference/computedPropertyNames7_ES5.js +++ b/tests/baselines/reference/computedPropertyNames7_ES5.js @@ -13,6 +13,5 @@ var E; })(E || (E = {})); var v = (_a = {}, _a[E.member] = 0, - _a -); + _a); var _a; diff --git a/tests/baselines/reference/computedPropertyNames8_ES5.js b/tests/baselines/reference/computedPropertyNames8_ES5.js index 6eceee81adb..82d262c7e4e 100644 --- a/tests/baselines/reference/computedPropertyNames8_ES5.js +++ b/tests/baselines/reference/computedPropertyNames8_ES5.js @@ -15,7 +15,6 @@ function f() { var v = (_a = {}, _a[t] = 0, _a[u] = 1, - _a - ); + _a); var _a; } diff --git a/tests/baselines/reference/computedPropertyNames9_ES5.js b/tests/baselines/reference/computedPropertyNames9_ES5.js index 6c1d7bcb4d0..b1ac6c9e3b6 100644 --- a/tests/baselines/reference/computedPropertyNames9_ES5.js +++ b/tests/baselines/reference/computedPropertyNames9_ES5.js @@ -16,6 +16,5 @@ var v = (_a = {}, _a[f("")] = 0, _a[f(0)] = 0, _a[f(true)] = 0, - _a -); + _a); var _a; diff --git a/tests/baselines/reference/computedPropertyNamesContextualType10_ES5.js b/tests/baselines/reference/computedPropertyNamesContextualType10_ES5.js index 1f7a3ae123e..d8a33951d4a 100644 --- a/tests/baselines/reference/computedPropertyNamesContextualType10_ES5.js +++ b/tests/baselines/reference/computedPropertyNamesContextualType10_ES5.js @@ -12,6 +12,5 @@ var o: I = { var o = (_a = {}, _a[+"foo"] = "", _a[+"bar"] = 0, - _a -); + _a); var _a; diff --git a/tests/baselines/reference/computedPropertyNamesContextualType1_ES5.js b/tests/baselines/reference/computedPropertyNamesContextualType1_ES5.js index c4bfde03531..1ee88351154 100644 --- a/tests/baselines/reference/computedPropertyNamesContextualType1_ES5.js +++ b/tests/baselines/reference/computedPropertyNamesContextualType1_ES5.js @@ -13,6 +13,5 @@ var o: I = { var o = (_a = {}, _a["" + 0] = function (y) { return y.length; }, _a["" + 1] = function (y) { return y.length; }, - _a -); + _a); var _a; diff --git a/tests/baselines/reference/computedPropertyNamesContextualType2_ES5.js b/tests/baselines/reference/computedPropertyNamesContextualType2_ES5.js index 945475f8533..6be09e4bef3 100644 --- a/tests/baselines/reference/computedPropertyNamesContextualType2_ES5.js +++ b/tests/baselines/reference/computedPropertyNamesContextualType2_ES5.js @@ -13,6 +13,5 @@ var o: I = { var o = (_a = {}, _a[+"foo"] = function (y) { return y.length; }, _a[+"bar"] = function (y) { return y.length; }, - _a -); + _a); var _a; diff --git a/tests/baselines/reference/computedPropertyNamesContextualType3_ES5.js b/tests/baselines/reference/computedPropertyNamesContextualType3_ES5.js index 98042f201e3..b510cda2916 100644 --- a/tests/baselines/reference/computedPropertyNamesContextualType3_ES5.js +++ b/tests/baselines/reference/computedPropertyNamesContextualType3_ES5.js @@ -12,6 +12,5 @@ var o: I = { var o = (_a = {}, _a[+"foo"] = function (y) { return y.length; }, _a[+"bar"] = function (y) { return y.length; }, - _a -); + _a); var _a; diff --git a/tests/baselines/reference/computedPropertyNamesContextualType4_ES5.js b/tests/baselines/reference/computedPropertyNamesContextualType4_ES5.js index b17f91be38b..0c319a526f4 100644 --- a/tests/baselines/reference/computedPropertyNamesContextualType4_ES5.js +++ b/tests/baselines/reference/computedPropertyNamesContextualType4_ES5.js @@ -13,6 +13,5 @@ var o: I = { var o = (_a = {}, _a["" + "foo"] = "", _a["" + "bar"] = 0, - _a -); + _a); var _a; diff --git a/tests/baselines/reference/computedPropertyNamesContextualType5_ES5.js b/tests/baselines/reference/computedPropertyNamesContextualType5_ES5.js index c7a728e5ef8..51d78be59d4 100644 --- a/tests/baselines/reference/computedPropertyNamesContextualType5_ES5.js +++ b/tests/baselines/reference/computedPropertyNamesContextualType5_ES5.js @@ -13,6 +13,5 @@ var o: I = { var o = (_a = {}, _a[+"foo"] = "", _a[+"bar"] = 0, - _a -); + _a); var _a; diff --git a/tests/baselines/reference/computedPropertyNamesContextualType6_ES5.js b/tests/baselines/reference/computedPropertyNamesContextualType6_ES5.js index c97b7c5b1f8..c6ef45d7fab 100644 --- a/tests/baselines/reference/computedPropertyNamesContextualType6_ES5.js +++ b/tests/baselines/reference/computedPropertyNamesContextualType6_ES5.js @@ -21,6 +21,5 @@ foo((_a = { _a["hi" + "bye"] = true, _a[0 + 1] = 0, _a[+"hi"] = [0], - _a -)); + _a)); var _a; diff --git a/tests/baselines/reference/computedPropertyNamesContextualType7_ES5.js b/tests/baselines/reference/computedPropertyNamesContextualType7_ES5.js index 9ca7e826aa7..9caf5f2aebf 100644 --- a/tests/baselines/reference/computedPropertyNamesContextualType7_ES5.js +++ b/tests/baselines/reference/computedPropertyNamesContextualType7_ES5.js @@ -21,6 +21,5 @@ foo((_a = { _a["hi" + "bye"] = true, _a[0 + 1] = 0, _a[+"hi"] = [0], - _a -)); + _a)); var _a; diff --git a/tests/baselines/reference/computedPropertyNamesContextualType8_ES5.js b/tests/baselines/reference/computedPropertyNamesContextualType8_ES5.js index 419ea906550..24f6218864c 100644 --- a/tests/baselines/reference/computedPropertyNamesContextualType8_ES5.js +++ b/tests/baselines/reference/computedPropertyNamesContextualType8_ES5.js @@ -13,6 +13,5 @@ var o: I = { var o = (_a = {}, _a["" + "foo"] = "", _a["" + "bar"] = 0, - _a -); + _a); var _a; diff --git a/tests/baselines/reference/computedPropertyNamesContextualType9_ES5.js b/tests/baselines/reference/computedPropertyNamesContextualType9_ES5.js index d3beb8b8deb..340802da2af 100644 --- a/tests/baselines/reference/computedPropertyNamesContextualType9_ES5.js +++ b/tests/baselines/reference/computedPropertyNamesContextualType9_ES5.js @@ -13,6 +13,5 @@ var o: I = { var o = (_a = {}, _a[+"foo"] = "", _a[+"bar"] = 0, - _a -); + _a); var _a; diff --git a/tests/baselines/reference/computedPropertyNamesDeclarationEmit5_ES5.js b/tests/baselines/reference/computedPropertyNamesDeclarationEmit5_ES5.js index e77eb79dc70..c903b864829 100644 --- a/tests/baselines/reference/computedPropertyNamesDeclarationEmit5_ES5.js +++ b/tests/baselines/reference/computedPropertyNamesDeclarationEmit5_ES5.js @@ -20,8 +20,7 @@ var v = (_a = {}, enumerable: true, configurable: true }), - _a -); + _a); var _a; diff --git a/tests/baselines/reference/computedPropertyNamesSourceMap2_ES5.js b/tests/baselines/reference/computedPropertyNamesSourceMap2_ES5.js index 39e393c46cc..972aaf9b52f 100644 --- a/tests/baselines/reference/computedPropertyNamesSourceMap2_ES5.js +++ b/tests/baselines/reference/computedPropertyNamesSourceMap2_ES5.js @@ -10,7 +10,6 @@ var v = (_a = {}, _a["hello"] = function () { debugger; }, - _a -); + _a); var _a; //# sourceMappingURL=computedPropertyNamesSourceMap2_ES5.js.map \ No newline at end of file diff --git a/tests/baselines/reference/computedPropertyNamesSourceMap2_ES5.js.map b/tests/baselines/reference/computedPropertyNamesSourceMap2_ES5.js.map index baf1e998efd..bdc21497651 100644 --- a/tests/baselines/reference/computedPropertyNamesSourceMap2_ES5.js.map +++ b/tests/baselines/reference/computedPropertyNamesSourceMap2_ES5.js.map @@ -1,2 +1,2 @@ //// [computedPropertyNamesSourceMap2_ES5.js.map] -{"version":3,"file":"computedPropertyNamesSourceMap2_ES5.js","sourceRoot":"","sources":["computedPropertyNamesSourceMap2_ES5.ts"],"names":[],"mappings":"AAAA,IAAI,CAAC,GAAG;IACJ,GAAC,OAAO,CAAC,GAAT;QACI,QAAQ,CAAC;IACb,CAAC;;CACJ,CAAA"} \ No newline at end of file +{"version":3,"file":"computedPropertyNamesSourceMap2_ES5.js","sourceRoot":"","sources":["computedPropertyNamesSourceMap2_ES5.ts"],"names":[],"mappings":"AAAA,IAAI,CAAC,GAAG;IACJ,GAAC,OAAO,CAAC,GAAT;QACI,QAAQ,CAAC;IACb,CAAC;OACJ,CAAA"} \ No newline at end of file diff --git a/tests/baselines/reference/computedPropertyNamesSourceMap2_ES5.sourcemap.txt b/tests/baselines/reference/computedPropertyNamesSourceMap2_ES5.sourcemap.txt index f6501777985..0535196f923 100644 --- a/tests/baselines/reference/computedPropertyNamesSourceMap2_ES5.sourcemap.txt +++ b/tests/baselines/reference/computedPropertyNamesSourceMap2_ES5.sourcemap.txt @@ -56,23 +56,21 @@ sourceFile:computedPropertyNamesSourceMap2_ES5.ts >>> }, 1 >^^^^ 2 > ^ -3 > ^^-> +3 > ^^^^-> 1 > > 2 > } 1 >Emitted(4, 5) Source(4, 5) + SourceIndex(0) 2 >Emitted(4, 6) Source(4, 6) + SourceIndex(0) --- ->>> _a ->>>); -1->^ -2 > ^ -3 > ^^^^^^-> +>>> _a); +1->^^^^^^^ +2 > ^ 1-> >} -2 > -1->Emitted(6, 2) Source(5, 2) + SourceIndex(0) -2 >Emitted(6, 3) Source(5, 2) + SourceIndex(0) +2 > +1->Emitted(5, 8) Source(5, 2) + SourceIndex(0) +2 >Emitted(5, 9) Source(5, 2) + SourceIndex(0) --- >>>var _a; >>>//# sourceMappingURL=computedPropertyNamesSourceMap2_ES5.js.map \ No newline at end of file diff --git a/tests/baselines/reference/contextuallyTypedClassExpressionMethodDeclaration01.js b/tests/baselines/reference/contextuallyTypedClassExpressionMethodDeclaration01.js index 11081be4fb3..2c8efdd424a 100644 --- a/tests/baselines/reference/contextuallyTypedClassExpressionMethodDeclaration01.js +++ b/tests/baselines/reference/contextuallyTypedClassExpressionMethodDeclaration01.js @@ -61,28 +61,32 @@ function getFoo1() { }()); } function getFoo2() { - return (function () { - function class_2() { - } - class_2.method1 = function (arg) { + return (_a = (function () { + function class_2() { + } + return class_2; + }()), + _a.method1 = function (arg) { arg.numProp = 10; - }; - class_2.method2 = function (arg) { + }, + _a.method2 = function (arg) { arg.strProp = "hello"; - }; - return class_2; - }()); + }, + _a); + var _a; } function getFoo3() { - return (function () { - function class_3() { - } - class_3.method1 = function (arg) { + return (_a = (function () { + function class_3() { + } + return class_3; + }()), + _a.method1 = function (arg) { arg.numProp = 10; - }; - class_3.method2 = function (arg) { + }, + _a.method2 = function (arg) { arg.strProp = "hello"; - }; - return class_3; - }()); + }, + _a); + var _a; } diff --git a/tests/baselines/reference/declFilePrivateStatic.js b/tests/baselines/reference/declFilePrivateStatic.js index 30cd85444cf..fb24bea7660 100644 --- a/tests/baselines/reference/declFilePrivateStatic.js +++ b/tests/baselines/reference/declFilePrivateStatic.js @@ -40,10 +40,10 @@ var C = (function () { enumerable: true, configurable: true }); - C.x = 1; - C.y = 1; return C; }()); +C.x = 1; +C.y = 1; //// [declFilePrivateStatic.d.ts] diff --git a/tests/baselines/reference/decoratorCallGeneric.js b/tests/baselines/reference/decoratorCallGeneric.js index acc9c48297d..a1d470b7063 100644 --- a/tests/baselines/reference/decoratorCallGeneric.js +++ b/tests/baselines/reference/decoratorCallGeneric.js @@ -24,8 +24,8 @@ var C = (function () { function C() { } C.m = function () { }; - C = __decorate([ - dec - ], C); return C; }()); +C = __decorate([ + dec +], C); diff --git a/tests/baselines/reference/decoratorChecksFunctionBodies.js b/tests/baselines/reference/decoratorChecksFunctionBodies.js index d70c4a33460..68dbe6bd1ef 100644 --- a/tests/baselines/reference/decoratorChecksFunctionBodies.js +++ b/tests/baselines/reference/decoratorChecksFunctionBodies.js @@ -30,12 +30,12 @@ var A = (function () { } A.prototype.m = function () { }; - __decorate([ - (function (x, p) { - var a = 3; - func(a); - return x; - }) - ], A.prototype, "m", null); return A; }()); +__decorate([ + (function (x, p) { + var a = 3; + func(a); + return x; + }) +], A.prototype, "m", null); diff --git a/tests/baselines/reference/decoratorInstantiateModulesInFunctionBodies.js b/tests/baselines/reference/decoratorInstantiateModulesInFunctionBodies.js index 92dcc1f836c..28b620a3e8c 100644 --- a/tests/baselines/reference/decoratorInstantiateModulesInFunctionBodies.js +++ b/tests/baselines/reference/decoratorInstantiateModulesInFunctionBodies.js @@ -45,8 +45,8 @@ var Wat = (function () { Wat.whatever = function () { // ... }; - __decorate([ - filter(function () { return a_1.test == 'abc'; }) - ], Wat, "whatever", null); return Wat; }()); +__decorate([ + filter(function () { return a_1.test == 'abc'; }) +], Wat, "whatever", null); diff --git a/tests/baselines/reference/decoratorMetadata.js b/tests/baselines/reference/decoratorMetadata.js index 2f360df0618..d95658c7f18 100644 --- a/tests/baselines/reference/decoratorMetadata.js +++ b/tests/baselines/reference/decoratorMetadata.js @@ -45,15 +45,15 @@ var MyComponent = (function () { } MyComponent.prototype.method = function (x) { }; - __decorate([ - decorator, - __metadata('design:type', Function), - __metadata('design:paramtypes', [Object]), - __metadata('design:returntype', void 0) - ], MyComponent.prototype, "method", null); - MyComponent = __decorate([ - decorator, - __metadata('design:paramtypes', [service_1.default]) - ], MyComponent); return MyComponent; }()); +__decorate([ + decorator, + __metadata('design:type', Function), + __metadata('design:paramtypes', [Object]), + __metadata('design:returntype', void 0) +], MyComponent.prototype, "method", null); +MyComponent = __decorate([ + decorator, + __metadata('design:paramtypes', [service_1.default]) +], MyComponent); diff --git a/tests/baselines/reference/decoratorMetadataForMethodWithNoReturnTypeAnnotation01.js b/tests/baselines/reference/decoratorMetadataForMethodWithNoReturnTypeAnnotation01.js index f5048ead631..e5127987d53 100644 --- a/tests/baselines/reference/decoratorMetadataForMethodWithNoReturnTypeAnnotation01.js +++ b/tests/baselines/reference/decoratorMetadataForMethodWithNoReturnTypeAnnotation01.js @@ -20,11 +20,11 @@ var MyClass = (function () { } MyClass.prototype.doSomething = function () { }; - __decorate([ - decorator, - __metadata('design:type', Function), - __metadata('design:paramtypes', []), - __metadata('design:returntype', void 0) - ], MyClass.prototype, "doSomething", null); return MyClass; }()); +__decorate([ + decorator, + __metadata('design:type', Function), + __metadata('design:paramtypes', []), + __metadata('design:returntype', void 0) +], MyClass.prototype, "doSomething", null); diff --git a/tests/baselines/reference/decoratorMetadataOnInferredType.js b/tests/baselines/reference/decoratorMetadataOnInferredType.js index 5a39a6ce42c..47b6c45e806 100644 --- a/tests/baselines/reference/decoratorMetadataOnInferredType.js +++ b/tests/baselines/reference/decoratorMetadataOnInferredType.js @@ -31,10 +31,10 @@ var B = (function () { function B() { this.x = new A(); } - __decorate([ - decorator, - __metadata('design:type', Object) - ], B.prototype, "x", void 0); return B; }()); +__decorate([ + decorator, + __metadata('design:type', Object) +], B.prototype, "x", void 0); exports.B = B; diff --git a/tests/baselines/reference/decoratorMetadataWithConstructorType.js b/tests/baselines/reference/decoratorMetadataWithConstructorType.js index 39e8d1811aa..0559e62754c 100644 --- a/tests/baselines/reference/decoratorMetadataWithConstructorType.js +++ b/tests/baselines/reference/decoratorMetadataWithConstructorType.js @@ -31,10 +31,10 @@ var B = (function () { function B() { this.x = new A(); } - __decorate([ - decorator, - __metadata('design:type', A) - ], B.prototype, "x", void 0); return B; }()); +__decorate([ + decorator, + __metadata('design:type', A) +], B.prototype, "x", void 0); exports.B = B; diff --git a/tests/baselines/reference/decoratorMetadataWithImportDeclarationNameCollision.js b/tests/baselines/reference/decoratorMetadataWithImportDeclarationNameCollision.js index b549d28c7f1..a0bc68bd8d8 100644 --- a/tests/baselines/reference/decoratorMetadataWithImportDeclarationNameCollision.js +++ b/tests/baselines/reference/decoratorMetadataWithImportDeclarationNameCollision.js @@ -44,10 +44,10 @@ var MyClass = (function () { this.db = db; this.db.doSomething(); } - MyClass = __decorate([ - someDecorator, - __metadata('design:paramtypes', [db_1.db]) - ], MyClass); return MyClass; }()); +MyClass = __decorate([ + someDecorator, + __metadata('design:paramtypes', [db_1.db]) +], MyClass); exports.MyClass = MyClass; diff --git a/tests/baselines/reference/decoratorMetadataWithImportDeclarationNameCollision2.js b/tests/baselines/reference/decoratorMetadataWithImportDeclarationNameCollision2.js index acd86e78d76..49a2983ce70 100644 --- a/tests/baselines/reference/decoratorMetadataWithImportDeclarationNameCollision2.js +++ b/tests/baselines/reference/decoratorMetadataWithImportDeclarationNameCollision2.js @@ -44,10 +44,10 @@ var MyClass = (function () { this.db = db; this.db.doSomething(); } - MyClass = __decorate([ - someDecorator, - __metadata('design:paramtypes', [db_1.db]) - ], MyClass); return MyClass; }()); +MyClass = __decorate([ + someDecorator, + __metadata('design:paramtypes', [db_1.db]) +], MyClass); exports.MyClass = MyClass; diff --git a/tests/baselines/reference/decoratorMetadataWithImportDeclarationNameCollision3.js b/tests/baselines/reference/decoratorMetadataWithImportDeclarationNameCollision3.js index 2acd829c107..f3c1d1b5da5 100644 --- a/tests/baselines/reference/decoratorMetadataWithImportDeclarationNameCollision3.js +++ b/tests/baselines/reference/decoratorMetadataWithImportDeclarationNameCollision3.js @@ -44,10 +44,10 @@ var MyClass = (function () { this.db = db; this.db.doSomething(); } - MyClass = __decorate([ - someDecorator, - __metadata('design:paramtypes', [db.db]) - ], MyClass); return MyClass; }()); +MyClass = __decorate([ + someDecorator, + __metadata('design:paramtypes', [db.db]) +], MyClass); exports.MyClass = MyClass; diff --git a/tests/baselines/reference/decoratorMetadataWithImportDeclarationNameCollision4.js b/tests/baselines/reference/decoratorMetadataWithImportDeclarationNameCollision4.js index 4af0beeddcb..3448352eaaf 100644 --- a/tests/baselines/reference/decoratorMetadataWithImportDeclarationNameCollision4.js +++ b/tests/baselines/reference/decoratorMetadataWithImportDeclarationNameCollision4.js @@ -44,10 +44,10 @@ var MyClass = (function () { this.db = db; this.db.doSomething(); } - MyClass = __decorate([ - someDecorator, - __metadata('design:paramtypes', [Object]) - ], MyClass); return MyClass; }()); +MyClass = __decorate([ + someDecorator, + __metadata('design:paramtypes', [Object]) +], MyClass); exports.MyClass = MyClass; diff --git a/tests/baselines/reference/decoratorMetadataWithImportDeclarationNameCollision5.js b/tests/baselines/reference/decoratorMetadataWithImportDeclarationNameCollision5.js index f1537e3b447..8eae92ec4d1 100644 --- a/tests/baselines/reference/decoratorMetadataWithImportDeclarationNameCollision5.js +++ b/tests/baselines/reference/decoratorMetadataWithImportDeclarationNameCollision5.js @@ -45,10 +45,10 @@ var MyClass = (function () { this.db = db; this.db.doSomething(); } - MyClass = __decorate([ - someDecorator, - __metadata('design:paramtypes', [db_1.default]) - ], MyClass); return MyClass; }()); +MyClass = __decorate([ + someDecorator, + __metadata('design:paramtypes', [db_1.default]) +], MyClass); exports.MyClass = MyClass; diff --git a/tests/baselines/reference/decoratorMetadataWithImportDeclarationNameCollision6.js b/tests/baselines/reference/decoratorMetadataWithImportDeclarationNameCollision6.js index 7ef2c288810..26e714c16a1 100644 --- a/tests/baselines/reference/decoratorMetadataWithImportDeclarationNameCollision6.js +++ b/tests/baselines/reference/decoratorMetadataWithImportDeclarationNameCollision6.js @@ -45,10 +45,10 @@ var MyClass = (function () { this.db = db; this.db.doSomething(); } - MyClass = __decorate([ - someDecorator, - __metadata('design:paramtypes', [db_1.default]) - ], MyClass); return MyClass; }()); +MyClass = __decorate([ + someDecorator, + __metadata('design:paramtypes', [db_1.default]) +], MyClass); exports.MyClass = MyClass; diff --git a/tests/baselines/reference/decoratorMetadataWithImportDeclarationNameCollision7.js b/tests/baselines/reference/decoratorMetadataWithImportDeclarationNameCollision7.js index f8469cdd6a4..1d3b8a92349 100644 --- a/tests/baselines/reference/decoratorMetadataWithImportDeclarationNameCollision7.js +++ b/tests/baselines/reference/decoratorMetadataWithImportDeclarationNameCollision7.js @@ -45,10 +45,10 @@ var MyClass = (function () { this.db = db; this.db.doSomething(); } - MyClass = __decorate([ - someDecorator, - __metadata('design:paramtypes', [Object]) - ], MyClass); return MyClass; }()); +MyClass = __decorate([ + someDecorator, + __metadata('design:paramtypes', [Object]) +], MyClass); exports.MyClass = MyClass; diff --git a/tests/baselines/reference/decoratorMetadataWithImportDeclarationNameCollision8.js b/tests/baselines/reference/decoratorMetadataWithImportDeclarationNameCollision8.js index f1885ccfaec..910008b9c27 100644 --- a/tests/baselines/reference/decoratorMetadataWithImportDeclarationNameCollision8.js +++ b/tests/baselines/reference/decoratorMetadataWithImportDeclarationNameCollision8.js @@ -44,10 +44,10 @@ var MyClass = (function () { this.db = db; this.db.doSomething(); } - MyClass = __decorate([ - someDecorator, - __metadata('design:paramtypes', [database.db]) - ], MyClass); return MyClass; }()); +MyClass = __decorate([ + someDecorator, + __metadata('design:paramtypes', [database.db]) +], MyClass); exports.MyClass = MyClass; diff --git a/tests/baselines/reference/decoratorOnClass1.js b/tests/baselines/reference/decoratorOnClass1.js index 7ea46b4698f..5cff4c2649c 100644 --- a/tests/baselines/reference/decoratorOnClass1.js +++ b/tests/baselines/reference/decoratorOnClass1.js @@ -15,8 +15,8 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key, var C = (function () { function C() { } - C = __decorate([ - dec - ], C); return C; }()); +C = __decorate([ + dec +], C); diff --git a/tests/baselines/reference/decoratorOnClass2.js b/tests/baselines/reference/decoratorOnClass2.js index 3f24c7ae55b..4d9c2007ad0 100644 --- a/tests/baselines/reference/decoratorOnClass2.js +++ b/tests/baselines/reference/decoratorOnClass2.js @@ -16,9 +16,9 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key, var C = (function () { function C() { } - C = __decorate([ - dec - ], C); return C; }()); +C = __decorate([ + dec +], C); exports.C = C; diff --git a/tests/baselines/reference/decoratorOnClass3.js b/tests/baselines/reference/decoratorOnClass3.js index 5a3601fc1f3..fd09a6d8de5 100644 --- a/tests/baselines/reference/decoratorOnClass3.js +++ b/tests/baselines/reference/decoratorOnClass3.js @@ -16,8 +16,8 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key, var C = (function () { function C() { } - C = __decorate([ - dec - ], C); return C; }()); +C = __decorate([ + dec +], C); diff --git a/tests/baselines/reference/decoratorOnClass4.js b/tests/baselines/reference/decoratorOnClass4.js index adbe30db662..daf19e20327 100644 --- a/tests/baselines/reference/decoratorOnClass4.js +++ b/tests/baselines/reference/decoratorOnClass4.js @@ -15,8 +15,8 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key, var C = (function () { function C() { } - C = __decorate([ - dec() - ], C); return C; }()); +C = __decorate([ + dec() +], C); diff --git a/tests/baselines/reference/decoratorOnClass5.js b/tests/baselines/reference/decoratorOnClass5.js index 6741b26373b..70fc5515140 100644 --- a/tests/baselines/reference/decoratorOnClass5.js +++ b/tests/baselines/reference/decoratorOnClass5.js @@ -15,8 +15,8 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key, var C = (function () { function C() { } - C = __decorate([ - dec() - ], C); return C; }()); +C = __decorate([ + dec() +], C); diff --git a/tests/baselines/reference/decoratorOnClass8.js b/tests/baselines/reference/decoratorOnClass8.js index e5cd8812ea7..ae50ab75ab8 100644 --- a/tests/baselines/reference/decoratorOnClass8.js +++ b/tests/baselines/reference/decoratorOnClass8.js @@ -15,8 +15,8 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key, var C = (function () { function C() { } - C = __decorate([ - dec() - ], C); return C; }()); +C = __decorate([ + dec() +], C); diff --git a/tests/baselines/reference/decoratorOnClassAccessor1.js b/tests/baselines/reference/decoratorOnClassAccessor1.js index cf989705b79..27966350fae 100644 --- a/tests/baselines/reference/decoratorOnClassAccessor1.js +++ b/tests/baselines/reference/decoratorOnClassAccessor1.js @@ -20,8 +20,8 @@ var C = (function () { enumerable: true, configurable: true }); - __decorate([ - dec - ], C.prototype, "accessor", null); return C; }()); +__decorate([ + dec +], C.prototype, "accessor", null); diff --git a/tests/baselines/reference/decoratorOnClassAccessor2.js b/tests/baselines/reference/decoratorOnClassAccessor2.js index 9e9455b4380..57cb3b50461 100644 --- a/tests/baselines/reference/decoratorOnClassAccessor2.js +++ b/tests/baselines/reference/decoratorOnClassAccessor2.js @@ -20,8 +20,8 @@ var C = (function () { enumerable: true, configurable: true }); - __decorate([ - dec - ], C.prototype, "accessor", null); return C; }()); +__decorate([ + dec +], C.prototype, "accessor", null); diff --git a/tests/baselines/reference/decoratorOnClassAccessor3.js b/tests/baselines/reference/decoratorOnClassAccessor3.js index 8a27914e0c8..c02f984e70a 100644 --- a/tests/baselines/reference/decoratorOnClassAccessor3.js +++ b/tests/baselines/reference/decoratorOnClassAccessor3.js @@ -20,8 +20,8 @@ var C = (function () { enumerable: true, configurable: true }); - __decorate([ - dec - ], C.prototype, "accessor", null); return C; }()); +__decorate([ + dec +], C.prototype, "accessor", null); diff --git a/tests/baselines/reference/decoratorOnClassAccessor4.js b/tests/baselines/reference/decoratorOnClassAccessor4.js index 85b35e95cef..0e0af58f526 100644 --- a/tests/baselines/reference/decoratorOnClassAccessor4.js +++ b/tests/baselines/reference/decoratorOnClassAccessor4.js @@ -20,8 +20,8 @@ var C = (function () { enumerable: true, configurable: true }); - __decorate([ - dec - ], C.prototype, "accessor", null); return C; }()); +__decorate([ + dec +], C.prototype, "accessor", null); diff --git a/tests/baselines/reference/decoratorOnClassAccessor5.js b/tests/baselines/reference/decoratorOnClassAccessor5.js index 12ec7a08adc..c7d5d109cc0 100644 --- a/tests/baselines/reference/decoratorOnClassAccessor5.js +++ b/tests/baselines/reference/decoratorOnClassAccessor5.js @@ -20,8 +20,8 @@ var C = (function () { enumerable: true, configurable: true }); - __decorate([ - dec - ], C.prototype, "accessor", null); return C; }()); +__decorate([ + dec +], C.prototype, "accessor", null); diff --git a/tests/baselines/reference/decoratorOnClassAccessor6.js b/tests/baselines/reference/decoratorOnClassAccessor6.js index d5477deb5af..8ac40e72299 100644 --- a/tests/baselines/reference/decoratorOnClassAccessor6.js +++ b/tests/baselines/reference/decoratorOnClassAccessor6.js @@ -20,8 +20,8 @@ var C = (function () { enumerable: true, configurable: true }); - __decorate([ - dec - ], C.prototype, "accessor", null); return C; }()); +__decorate([ + dec +], C.prototype, "accessor", null); diff --git a/tests/baselines/reference/decoratorOnClassConstructorParameter1.js b/tests/baselines/reference/decoratorOnClassConstructorParameter1.js index fe04f569e30..176e2309ae0 100644 --- a/tests/baselines/reference/decoratorOnClassConstructorParameter1.js +++ b/tests/baselines/reference/decoratorOnClassConstructorParameter1.js @@ -18,8 +18,8 @@ var __param = (this && this.__param) || function (paramIndex, decorator) { var C = (function () { function C(p) { } - C = __decorate([ - __param(0, dec) - ], C); return C; }()); +C = __decorate([ + __param(0, dec) +], C); diff --git a/tests/baselines/reference/decoratorOnClassConstructorParameter4.js b/tests/baselines/reference/decoratorOnClassConstructorParameter4.js index 8d02bd467d6..e14f0358808 100644 --- a/tests/baselines/reference/decoratorOnClassConstructorParameter4.js +++ b/tests/baselines/reference/decoratorOnClassConstructorParameter4.js @@ -18,8 +18,8 @@ var __param = (this && this.__param) || function (paramIndex, decorator) { var C = (function () { function C(public, p) { } - C = __decorate([ - __param(1, dec) - ], C); return C; }()); +C = __decorate([ + __param(1, dec) +], C); diff --git a/tests/baselines/reference/decoratorOnClassMethod1.js b/tests/baselines/reference/decoratorOnClassMethod1.js index ef029b84543..b93d7f88771 100644 --- a/tests/baselines/reference/decoratorOnClassMethod1.js +++ b/tests/baselines/reference/decoratorOnClassMethod1.js @@ -16,8 +16,8 @@ var C = (function () { function C() { } C.prototype.method = function () { }; - __decorate([ - dec - ], C.prototype, "method", null); return C; }()); +__decorate([ + dec +], C.prototype, "method", null); diff --git a/tests/baselines/reference/decoratorOnClassMethod10.js b/tests/baselines/reference/decoratorOnClassMethod10.js index f90251d6196..bfa57f0aeb7 100644 --- a/tests/baselines/reference/decoratorOnClassMethod10.js +++ b/tests/baselines/reference/decoratorOnClassMethod10.js @@ -16,8 +16,8 @@ var C = (function () { function C() { } C.prototype.method = function () { }; - __decorate([ - dec - ], C.prototype, "method", null); return C; }()); +__decorate([ + dec +], C.prototype, "method", null); diff --git a/tests/baselines/reference/decoratorOnClassMethod11.js b/tests/baselines/reference/decoratorOnClassMethod11.js index f1589a39286..c703459b88d 100644 --- a/tests/baselines/reference/decoratorOnClassMethod11.js +++ b/tests/baselines/reference/decoratorOnClassMethod11.js @@ -22,9 +22,9 @@ var M; } C.prototype.decorator = function (target, key) { }; C.prototype.method = function () { }; - __decorate([ - this.decorator - ], C.prototype, "method", null); return C; }()); + __decorate([ + this.decorator + ], C.prototype, "method", null); })(M || (M = {})); diff --git a/tests/baselines/reference/decoratorOnClassMethod12.js b/tests/baselines/reference/decoratorOnClassMethod12.js index 0650f1d00ee..6e9b9763a3a 100644 --- a/tests/baselines/reference/decoratorOnClassMethod12.js +++ b/tests/baselines/reference/decoratorOnClassMethod12.js @@ -35,9 +35,9 @@ var M; _super.apply(this, arguments); } C.prototype.method = function () { }; - __decorate([ - _super.decorator - ], C.prototype, "method", null); return C; }(S)); + __decorate([ + _super.decorator + ], C.prototype, "method", null); })(M || (M = {})); diff --git a/tests/baselines/reference/decoratorOnClassMethod2.js b/tests/baselines/reference/decoratorOnClassMethod2.js index 5db2922ed71..98ad8ad43ad 100644 --- a/tests/baselines/reference/decoratorOnClassMethod2.js +++ b/tests/baselines/reference/decoratorOnClassMethod2.js @@ -16,8 +16,8 @@ var C = (function () { function C() { } C.prototype.method = function () { }; - __decorate([ - dec - ], C.prototype, "method", null); return C; }()); +__decorate([ + dec +], C.prototype, "method", null); diff --git a/tests/baselines/reference/decoratorOnClassMethod3.js b/tests/baselines/reference/decoratorOnClassMethod3.js index 30f527368f2..4a5943681d4 100644 --- a/tests/baselines/reference/decoratorOnClassMethod3.js +++ b/tests/baselines/reference/decoratorOnClassMethod3.js @@ -16,8 +16,8 @@ var C = (function () { function C() { } C.prototype.method = function () { }; - __decorate([ - dec - ], C.prototype, "method", null); return C; }()); +__decorate([ + dec +], C.prototype, "method", null); diff --git a/tests/baselines/reference/decoratorOnClassMethod8.js b/tests/baselines/reference/decoratorOnClassMethod8.js index bf8c06d9b90..c1ad826cab0 100644 --- a/tests/baselines/reference/decoratorOnClassMethod8.js +++ b/tests/baselines/reference/decoratorOnClassMethod8.js @@ -16,8 +16,8 @@ var C = (function () { function C() { } C.prototype.method = function () { }; - __decorate([ - dec - ], C.prototype, "method", null); return C; }()); +__decorate([ + dec +], C.prototype, "method", null); diff --git a/tests/baselines/reference/decoratorOnClassMethodOverload2.js b/tests/baselines/reference/decoratorOnClassMethodOverload2.js index eafa5da7110..db077dd7b51 100644 --- a/tests/baselines/reference/decoratorOnClassMethodOverload2.js +++ b/tests/baselines/reference/decoratorOnClassMethodOverload2.js @@ -18,8 +18,8 @@ var C = (function () { function C() { } C.prototype.method = function () { }; - __decorate([ - dec - ], C.prototype, "method", null); return C; }()); +__decorate([ + dec +], C.prototype, "method", null); diff --git a/tests/baselines/reference/decoratorOnClassMethodParameter1.js b/tests/baselines/reference/decoratorOnClassMethodParameter1.js index efb1e4abff2..d5d8599d7a8 100644 --- a/tests/baselines/reference/decoratorOnClassMethodParameter1.js +++ b/tests/baselines/reference/decoratorOnClassMethodParameter1.js @@ -19,8 +19,8 @@ var C = (function () { function C() { } C.prototype.method = function (p) { }; - __decorate([ - __param(0, dec) - ], C.prototype, "method", null); return C; }()); +__decorate([ + __param(0, dec) +], C.prototype, "method", null); diff --git a/tests/baselines/reference/decoratorOnClassProperty1.js b/tests/baselines/reference/decoratorOnClassProperty1.js index 65a399332f1..6547e0bdb18 100644 --- a/tests/baselines/reference/decoratorOnClassProperty1.js +++ b/tests/baselines/reference/decoratorOnClassProperty1.js @@ -15,8 +15,8 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key, var C = (function () { function C() { } - __decorate([ - dec - ], C.prototype, "prop", void 0); return C; }()); +__decorate([ + dec +], C.prototype, "prop", void 0); diff --git a/tests/baselines/reference/decoratorOnClassProperty10.js b/tests/baselines/reference/decoratorOnClassProperty10.js index 9df40eaf83a..174f26a315a 100644 --- a/tests/baselines/reference/decoratorOnClassProperty10.js +++ b/tests/baselines/reference/decoratorOnClassProperty10.js @@ -15,8 +15,8 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key, var C = (function () { function C() { } - __decorate([ - dec() - ], C.prototype, "prop", void 0); return C; }()); +__decorate([ + dec() +], C.prototype, "prop", void 0); diff --git a/tests/baselines/reference/decoratorOnClassProperty11.js b/tests/baselines/reference/decoratorOnClassProperty11.js index 8b771caf8b5..c901637402d 100644 --- a/tests/baselines/reference/decoratorOnClassProperty11.js +++ b/tests/baselines/reference/decoratorOnClassProperty11.js @@ -15,8 +15,8 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key, var C = (function () { function C() { } - __decorate([ - dec - ], C.prototype, "prop", void 0); return C; }()); +__decorate([ + dec +], C.prototype, "prop", void 0); diff --git a/tests/baselines/reference/decoratorOnClassProperty2.js b/tests/baselines/reference/decoratorOnClassProperty2.js index 3ab2b515e3c..ceaf43caa59 100644 --- a/tests/baselines/reference/decoratorOnClassProperty2.js +++ b/tests/baselines/reference/decoratorOnClassProperty2.js @@ -15,8 +15,8 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key, var C = (function () { function C() { } - __decorate([ - dec - ], C.prototype, "prop", void 0); return C; }()); +__decorate([ + dec +], C.prototype, "prop", void 0); diff --git a/tests/baselines/reference/decoratorOnClassProperty3.js b/tests/baselines/reference/decoratorOnClassProperty3.js index 9c0d3f90e42..8436be93968 100644 --- a/tests/baselines/reference/decoratorOnClassProperty3.js +++ b/tests/baselines/reference/decoratorOnClassProperty3.js @@ -15,8 +15,8 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key, var C = (function () { function C() { } - __decorate([ - dec - ], C.prototype, "prop", void 0); return C; }()); +__decorate([ + dec +], C.prototype, "prop", void 0); diff --git a/tests/baselines/reference/decoratorOnClassProperty6.js b/tests/baselines/reference/decoratorOnClassProperty6.js index 823a652af24..c7f5490c648 100644 --- a/tests/baselines/reference/decoratorOnClassProperty6.js +++ b/tests/baselines/reference/decoratorOnClassProperty6.js @@ -15,8 +15,8 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key, var C = (function () { function C() { } - __decorate([ - dec - ], C.prototype, "prop", void 0); return C; }()); +__decorate([ + dec +], C.prototype, "prop", void 0); diff --git a/tests/baselines/reference/decoratorOnClassProperty7.js b/tests/baselines/reference/decoratorOnClassProperty7.js index 134f35022e0..828d548ff6b 100644 --- a/tests/baselines/reference/decoratorOnClassProperty7.js +++ b/tests/baselines/reference/decoratorOnClassProperty7.js @@ -15,8 +15,8 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key, var C = (function () { function C() { } - __decorate([ - dec - ], C.prototype, "prop", void 0); return C; }()); +__decorate([ + dec +], C.prototype, "prop", void 0); diff --git a/tests/baselines/reference/derivedClassSuperCallsInNonConstructorMembers.js b/tests/baselines/reference/derivedClassSuperCallsInNonConstructorMembers.js index e043ee8a5c5..50408d3bee7 100644 --- a/tests/baselines/reference/derivedClassSuperCallsInNonConstructorMembers.js +++ b/tests/baselines/reference/derivedClassSuperCallsInNonConstructorMembers.js @@ -77,6 +77,6 @@ var Derived = (function (_super) { enumerable: true, configurable: true }); - Derived.a = _super.call(this); return Derived; }(Base)); +Derived.a = _super.call(this); diff --git a/tests/baselines/reference/errorSuperCalls.js b/tests/baselines/reference/errorSuperCalls.js index 4cc6a4d968f..097b16b3024 100644 --- a/tests/baselines/reference/errorSuperCalls.js +++ b/tests/baselines/reference/errorSuperCalls.js @@ -119,10 +119,10 @@ var NoBase = (function () { enumerable: true, configurable: true }); - //super call in static class member initializer with no base type - NoBase.k = _super.call(this); return NoBase; }()); +//super call in static class member initializer with no base type +NoBase.k = _super.call(this); var Base = (function () { function Base() { } diff --git a/tests/baselines/reference/errorSuperPropertyAccess.js b/tests/baselines/reference/errorSuperPropertyAccess.js index cf6ed2598ea..dbfbdb46940 100644 --- a/tests/baselines/reference/errorSuperPropertyAccess.js +++ b/tests/baselines/reference/errorSuperPropertyAccess.js @@ -175,10 +175,10 @@ var SomeBase = (function () { SomeBase.prototype.publicFunc = function () { }; SomeBase.privateStaticFunc = function () { }; SomeBase.publicStaticFunc = function () { }; - SomeBase.privateStaticMember = 0; - SomeBase.publicStaticMember = 0; return SomeBase; }()); +SomeBase.privateStaticMember = 0; +SomeBase.publicStaticMember = 0; //super.publicInstanceMemberNotFunction in constructor of derived class //super.publicInstanceMemberNotFunction in instance member function of derived class //super.publicInstanceMemberNotFunction in instance member accessor(get and set) of derived class diff --git a/tests/baselines/reference/es3defaultAliasIsQuoted.js b/tests/baselines/reference/es3defaultAliasIsQuoted.js index ac6a0bd24da..89fd0c47a7e 100644 --- a/tests/baselines/reference/es3defaultAliasIsQuoted.js +++ b/tests/baselines/reference/es3defaultAliasIsQuoted.js @@ -19,9 +19,9 @@ assert(Foo.CONSTANT === "Foo"); var Foo = (function () { function Foo() { } - Foo.CONSTANT = "Foo"; return Foo; }()); +Foo.CONSTANT = "Foo"; exports.Foo = Foo; function assert(value) { if (!value) diff --git a/tests/baselines/reference/es6ClassTest.js b/tests/baselines/reference/es6ClassTest.js index 365e91321a4..a722cce1670 100644 --- a/tests/baselines/reference/es6ClassTest.js +++ b/tests/baselines/reference/es6ClassTest.js @@ -113,9 +113,9 @@ var Foo = (function (_super) { } Foo.prototype.bar = function () { return 0; }; Foo.prototype.boo = function (x) { return x; }; - Foo.statVal = 0; return Foo; }(Bar)); +Foo.statVal = 0; var f = new Foo(); //class GetSetMonster { // // attack(target) { diff --git a/tests/baselines/reference/es6ClassTest2.js b/tests/baselines/reference/es6ClassTest2.js index 86ff00121cf..1881e6b8c87 100644 --- a/tests/baselines/reference/es6ClassTest2.js +++ b/tests/baselines/reference/es6ClassTest2.js @@ -283,9 +283,9 @@ var Statics = (function () { Statics.baz = function () { return ""; }; - Statics.foo = 1; return Statics; }()); +Statics.foo = 1; var stat = new Statics(); var ImplementsInterface = (function () { function ImplementsInterface() { diff --git a/tests/baselines/reference/generatedContextualTyping.js b/tests/baselines/reference/generatedContextualTyping.js index 8093c8bec41..e5488121d34 100644 --- a/tests/baselines/reference/generatedContextualTyping.js +++ b/tests/baselines/reference/generatedContextualTyping.js @@ -612,219 +612,219 @@ var x48 = (function () { var x49 = (function () { function x49() { } - x49.member = function () { return [d1, d2]; }; return x49; }()); +x49.member = function () { return [d1, d2]; }; var x50 = (function () { function x50() { } - x50.member = function () { return [d1, d2]; }; return x50; }()); +x50.member = function () { return [d1, d2]; }; var x51 = (function () { function x51() { } - x51.member = function named() { return [d1, d2]; }; return x51; }()); +x51.member = function named() { return [d1, d2]; }; var x52 = (function () { function x52() { } - x52.member = function () { return [d1, d2]; }; return x52; }()); +x52.member = function () { return [d1, d2]; }; var x53 = (function () { function x53() { } - x53.member = function () { return [d1, d2]; }; return x53; }()); +x53.member = function () { return [d1, d2]; }; var x54 = (function () { function x54() { } - x54.member = function named() { return [d1, d2]; }; return x54; }()); +x54.member = function named() { return [d1, d2]; }; var x55 = (function () { function x55() { } - x55.member = [d1, d2]; return x55; }()); +x55.member = [d1, d2]; var x56 = (function () { function x56() { } - x56.member = [d1, d2]; return x56; }()); +x56.member = [d1, d2]; var x57 = (function () { function x57() { } - x57.member = [d1, d2]; return x57; }()); +x57.member = [d1, d2]; var x58 = (function () { function x58() { } - x58.member = { n: [d1, d2] }; return x58; }()); +x58.member = { n: [d1, d2] }; var x59 = (function () { function x59() { } - x59.member = function (n) { var n; return null; }; return x59; }()); +x59.member = function (n) { var n; return null; }; var x60 = (function () { function x60() { } - x60.member = { func: function (n) { return [d1, d2]; } }; return x60; }()); +x60.member = { func: function (n) { return [d1, d2]; } }; var x61 = (function () { function x61() { } - x61.member = function () { return [d1, d2]; }; return x61; }()); +x61.member = function () { return [d1, d2]; }; var x62 = (function () { function x62() { } - x62.member = function () { return [d1, d2]; }; return x62; }()); +x62.member = function () { return [d1, d2]; }; var x63 = (function () { function x63() { } - x63.member = function named() { return [d1, d2]; }; return x63; }()); +x63.member = function named() { return [d1, d2]; }; var x64 = (function () { function x64() { } - x64.member = function () { return [d1, d2]; }; return x64; }()); +x64.member = function () { return [d1, d2]; }; var x65 = (function () { function x65() { } - x65.member = function () { return [d1, d2]; }; return x65; }()); +x65.member = function () { return [d1, d2]; }; var x66 = (function () { function x66() { } - x66.member = function named() { return [d1, d2]; }; return x66; }()); +x66.member = function named() { return [d1, d2]; }; var x67 = (function () { function x67() { } - x67.member = [d1, d2]; return x67; }()); +x67.member = [d1, d2]; var x68 = (function () { function x68() { } - x68.member = [d1, d2]; return x68; }()); +x68.member = [d1, d2]; var x69 = (function () { function x69() { } - x69.member = [d1, d2]; return x69; }()); +x69.member = [d1, d2]; var x70 = (function () { function x70() { } - x70.member = { n: [d1, d2] }; return x70; }()); +x70.member = { n: [d1, d2] }; var x71 = (function () { function x71() { } - x71.member = function (n) { var n; return null; }; return x71; }()); +x71.member = function (n) { var n; return null; }; var x72 = (function () { function x72() { } - x72.member = { func: function (n) { return [d1, d2]; } }; return x72; }()); +x72.member = { func: function (n) { return [d1, d2]; } }; var x73 = (function () { function x73() { } - x73.member = function () { return [d1, d2]; }; return x73; }()); +x73.member = function () { return [d1, d2]; }; var x74 = (function () { function x74() { } - x74.member = function () { return [d1, d2]; }; return x74; }()); +x74.member = function () { return [d1, d2]; }; var x75 = (function () { function x75() { } - x75.member = function named() { return [d1, d2]; }; return x75; }()); +x75.member = function named() { return [d1, d2]; }; var x76 = (function () { function x76() { } - x76.member = function () { return [d1, d2]; }; return x76; }()); +x76.member = function () { return [d1, d2]; }; var x77 = (function () { function x77() { } - x77.member = function () { return [d1, d2]; }; return x77; }()); +x77.member = function () { return [d1, d2]; }; var x78 = (function () { function x78() { } - x78.member = function named() { return [d1, d2]; }; return x78; }()); +x78.member = function named() { return [d1, d2]; }; var x79 = (function () { function x79() { } - x79.member = [d1, d2]; return x79; }()); +x79.member = [d1, d2]; var x80 = (function () { function x80() { } - x80.member = [d1, d2]; return x80; }()); +x80.member = [d1, d2]; var x81 = (function () { function x81() { } - x81.member = [d1, d2]; return x81; }()); +x81.member = [d1, d2]; var x82 = (function () { function x82() { } - x82.member = { n: [d1, d2] }; return x82; }()); +x82.member = { n: [d1, d2] }; var x83 = (function () { function x83() { } - x83.member = function (n) { var n; return null; }; return x83; }()); +x83.member = function (n) { var n; return null; }; var x84 = (function () { function x84() { } - x84.member = { func: function (n) { return [d1, d2]; } }; return x84; }()); +x84.member = { func: function (n) { return [d1, d2]; } }; var x85 = (function () { function x85(parm) { if (parm === void 0) { parm = function () { return [d1, d2]; }; } diff --git a/tests/baselines/reference/genericClassWithStaticsUsingTypeArguments.js b/tests/baselines/reference/genericClassWithStaticsUsingTypeArguments.js index 2039e459572..053fa785ee0 100644 --- a/tests/baselines/reference/genericClassWithStaticsUsingTypeArguments.js +++ b/tests/baselines/reference/genericClassWithStaticsUsingTypeArguments.js @@ -25,9 +25,9 @@ var Foo = (function () { Foo.f = function (xs) { return xs.reverse(); }; - Foo.a = function (n) { }; - Foo.c = []; - Foo.d = false || (function (x) { return x || undefined; })(null); - Foo.e = function (x) { return null; }; return Foo; }()); +Foo.a = function (n) { }; +Foo.c = []; +Foo.d = false || (function (x) { return x || undefined; })(null); +Foo.e = function (x) { return null; }; diff --git a/tests/baselines/reference/gettersAndSetters.js b/tests/baselines/reference/gettersAndSetters.js index 16d66c7dc71..265a1210b16 100644 --- a/tests/baselines/reference/gettersAndSetters.js +++ b/tests/baselines/reference/gettersAndSetters.js @@ -65,9 +65,9 @@ var C = (function () { enumerable: true, configurable: true }); - C.barBack = ""; return C; }()); +C.barBack = ""; var c = new C(); var foo = c.Foo; c.Foo = "foov"; diff --git a/tests/baselines/reference/importImportOnlyModule.js b/tests/baselines/reference/importImportOnlyModule.js index 7b41e4400c5..013999321f9 100644 --- a/tests/baselines/reference/importImportOnlyModule.js +++ b/tests/baselines/reference/importImportOnlyModule.js @@ -22,9 +22,9 @@ define(["require", "exports"], function (require, exports) { function C1() { this.m1 = 42; } - C1.s1 = true; return C1; }()); + C1.s1 = true; exports.C1 = C1; }); //// [foo_1.js] diff --git a/tests/baselines/reference/instanceAndStaticDeclarations1.js b/tests/baselines/reference/instanceAndStaticDeclarations1.js index 093e9c15cc8..bf9b6963bb2 100644 --- a/tests/baselines/reference/instanceAndStaticDeclarations1.js +++ b/tests/baselines/reference/instanceAndStaticDeclarations1.js @@ -25,6 +25,6 @@ var Point = (function () { return Math.sqrt(dx * dx + dy * dy); }; Point.distance = function (p1, p2) { return p1.distance(p2); }; - Point.origin = new Point(0, 0); return Point; }()); +Point.origin = new Point(0, 0); diff --git a/tests/baselines/reference/invalidStaticField.js b/tests/baselines/reference/invalidStaticField.js index dc582e830c7..08a06d5ee27 100644 --- a/tests/baselines/reference/invalidStaticField.js +++ b/tests/baselines/reference/invalidStaticField.js @@ -12,6 +12,6 @@ var A = (function () { var B = (function () { function B() { } - B.NOT_NULL = new B(); return B; }()); +B.NOT_NULL = new B(); diff --git a/tests/baselines/reference/literalsInComputedProperties1.js b/tests/baselines/reference/literalsInComputedProperties1.js index 82a6367e5d2..4c28a5e9083 100644 --- a/tests/baselines/reference/literalsInComputedProperties1.js +++ b/tests/baselines/reference/literalsInComputedProperties1.js @@ -58,8 +58,7 @@ var x = (_a = { _a[2] = 1, _a["3"] = 1, _a["4"] = 1, - _a -); + _a); x[1].toExponential(); x[2].toExponential(); x[3].toExponential(); diff --git a/tests/baselines/reference/missingDecoratorType.js b/tests/baselines/reference/missingDecoratorType.js index 7356be39798..1dcbb3febc5 100644 --- a/tests/baselines/reference/missingDecoratorType.js +++ b/tests/baselines/reference/missingDecoratorType.js @@ -33,8 +33,8 @@ var C = (function () { function C() { } C.prototype.method = function () { }; - __decorate([ - dec - ], C.prototype, "method", null); return C; }()); +__decorate([ + dec +], C.prototype, "method", null); diff --git a/tests/baselines/reference/modifierOnClassExpressionMemberInFunction.js b/tests/baselines/reference/modifierOnClassExpressionMemberInFunction.js index 70eea5b2c5c..211c80bcce8 100644 --- a/tests/baselines/reference/modifierOnClassExpressionMemberInFunction.js +++ b/tests/baselines/reference/modifierOnClassExpressionMemberInFunction.js @@ -10,14 +10,16 @@ function g() { //// [modifierOnClassExpressionMemberInFunction.js] function g() { - var x = (function () { - function C() { - this.prop1 = 1; - } - C.prototype.foo = function () { }; - C.prop2 = 43; - return C; - }()); + var x = (_a = (function () { + function C() { + this.prop1 = 1; + } + C.prototype.foo = function () { }; + return C; + }()), + _a.prop2 = 43, + _a); + var _a; } diff --git a/tests/baselines/reference/noEmitHelpers2.js b/tests/baselines/reference/noEmitHelpers2.js index f3bbfe54896..fc4baf334c3 100644 --- a/tests/baselines/reference/noEmitHelpers2.js +++ b/tests/baselines/reference/noEmitHelpers2.js @@ -12,10 +12,10 @@ class A { var A = (function () { function A(a, b) { } - A = __decorate([ - decorator, - __param(1, decorator), - __metadata('design:paramtypes', [Number, String]) - ], A); return A; }()); +A = __decorate([ + decorator, + __param(1, decorator), + __metadata('design:paramtypes', [Number, String]) +], A); diff --git a/tests/baselines/reference/parserAccessibilityAfterStatic3.js b/tests/baselines/reference/parserAccessibilityAfterStatic3.js index 7a9ae06e439..38202bc5dc8 100644 --- a/tests/baselines/reference/parserAccessibilityAfterStatic3.js +++ b/tests/baselines/reference/parserAccessibilityAfterStatic3.js @@ -9,6 +9,6 @@ static public = 1; var Outer = (function () { function Outer() { } - Outer.public = 1; return Outer; }()); +Outer.public = 1; diff --git a/tests/baselines/reference/parserErrorRecovery_IncompleteMemberVariable1.js b/tests/baselines/reference/parserErrorRecovery_IncompleteMemberVariable1.js index 9bb4395e556..57d0536e975 100644 --- a/tests/baselines/reference/parserErrorRecovery_IncompleteMemberVariable1.js +++ b/tests/baselines/reference/parserErrorRecovery_IncompleteMemberVariable1.js @@ -41,10 +41,10 @@ var Shapes; } // Instance member Point.prototype.getDist = function () { return Math.sqrt(this.x * this.x + this.y * this.y); }; - // Static member - Point.origin = new Point(0, 0); return Point; }()); + // Static member + Point.origin = new Point(0, 0); Shapes.Point = Point; })(Shapes || (Shapes = {})); // Local variables diff --git a/tests/baselines/reference/parserErrorRecovery_IncompleteMemberVariable2.js b/tests/baselines/reference/parserErrorRecovery_IncompleteMemberVariable2.js index 0ee73b8b1e5..2bb08a14e35 100644 --- a/tests/baselines/reference/parserErrorRecovery_IncompleteMemberVariable2.js +++ b/tests/baselines/reference/parserErrorRecovery_IncompleteMemberVariable2.js @@ -42,10 +42,10 @@ var Shapes; } // Instance member Point.prototype.getDist = function () { return Math.sqrt(this.x * this.x + this.y * this.y); }; - // Static member - Point.origin = new Point(0, 0); return Point; }()); + // Static member + Point.origin = new Point(0, 0); Shapes.Point = Point; })(Shapes || (Shapes = {})); // Local variables diff --git a/tests/baselines/reference/parserharness.js b/tests/baselines/reference/parserharness.js index 6b38a8c9e4c..1a525c49d19 100644 --- a/tests/baselines/reference/parserharness.js +++ b/tests/baselines/reference/parserharness.js @@ -2371,11 +2371,11 @@ var Harness; errorHandlerStack[errorHandlerStack.length - 1](e); } }; - // The current stack of Runnable objects - Runnable.currentStack = []; - Runnable.errorHandlerStack = []; return Runnable; }()); + // The current stack of Runnable objects + Runnable.currentStack = []; + Runnable.errorHandlerStack = []; Harness.Runnable = Runnable; var TestCase = (function (_super) { __extends(TestCase, _super); diff --git a/tests/baselines/reference/privacyCannotNameVarTypeDeclFile.js b/tests/baselines/reference/privacyCannotNameVarTypeDeclFile.js index 6c2dcf304cf..c139b6279fd 100644 --- a/tests/baselines/reference/privacyCannotNameVarTypeDeclFile.js +++ b/tests/baselines/reference/privacyCannotNameVarTypeDeclFile.js @@ -159,12 +159,12 @@ var publicClassWithWithPrivatePropertyTypes = (function () { this.myPublicProperty1 = exporter.createExportedWidget3(); // Error this.myPrivateProperty1 = exporter.createExportedWidget3(); } - publicClassWithWithPrivatePropertyTypes.myPublicStaticProperty = exporter.createExportedWidget1(); // Error - publicClassWithWithPrivatePropertyTypes.myPrivateStaticProperty = exporter.createExportedWidget1(); - publicClassWithWithPrivatePropertyTypes.myPublicStaticProperty1 = exporter.createExportedWidget3(); // Error - publicClassWithWithPrivatePropertyTypes.myPrivateStaticProperty1 = exporter.createExportedWidget3(); return publicClassWithWithPrivatePropertyTypes; }()); +publicClassWithWithPrivatePropertyTypes.myPublicStaticProperty = exporter.createExportedWidget1(); // Error +publicClassWithWithPrivatePropertyTypes.myPrivateStaticProperty = exporter.createExportedWidget1(); +publicClassWithWithPrivatePropertyTypes.myPublicStaticProperty1 = exporter.createExportedWidget3(); // Error +publicClassWithWithPrivatePropertyTypes.myPrivateStaticProperty1 = exporter.createExportedWidget3(); exports.publicClassWithWithPrivatePropertyTypes = publicClassWithWithPrivatePropertyTypes; var privateClassWithWithPrivatePropertyTypes = (function () { function privateClassWithWithPrivatePropertyTypes() { @@ -173,12 +173,12 @@ var privateClassWithWithPrivatePropertyTypes = (function () { this.myPublicProperty1 = exporter.createExportedWidget3(); this.myPrivateProperty1 = exporter.createExportedWidget3(); } - privateClassWithWithPrivatePropertyTypes.myPublicStaticProperty = exporter.createExportedWidget1(); - privateClassWithWithPrivatePropertyTypes.myPrivateStaticProperty = exporter.createExportedWidget1(); - privateClassWithWithPrivatePropertyTypes.myPublicStaticProperty1 = exporter.createExportedWidget3(); - privateClassWithWithPrivatePropertyTypes.myPrivateStaticProperty1 = exporter.createExportedWidget3(); return privateClassWithWithPrivatePropertyTypes; }()); +privateClassWithWithPrivatePropertyTypes.myPublicStaticProperty = exporter.createExportedWidget1(); +privateClassWithWithPrivatePropertyTypes.myPrivateStaticProperty = exporter.createExportedWidget1(); +privateClassWithWithPrivatePropertyTypes.myPublicStaticProperty1 = exporter.createExportedWidget3(); +privateClassWithWithPrivatePropertyTypes.myPrivateStaticProperty1 = exporter.createExportedWidget3(); exports.publicVarWithPrivatePropertyTypes = exporter.createExportedWidget1(); // Error var privateVarWithPrivatePropertyTypes = exporter.createExportedWidget1(); exports.publicVarWithPrivatePropertyTypes1 = exporter.createExportedWidget3(); // Error @@ -188,10 +188,10 @@ var publicClassWithPrivateModulePropertyTypes = (function () { this.myPublicProperty = exporter.createExportedWidget2(); // Error this.myPublicProperty1 = exporter.createExportedWidget4(); // Error } - publicClassWithPrivateModulePropertyTypes.myPublicStaticProperty = exporter.createExportedWidget2(); // Error - publicClassWithPrivateModulePropertyTypes.myPublicStaticProperty1 = exporter.createExportedWidget4(); // Error return publicClassWithPrivateModulePropertyTypes; }()); +publicClassWithPrivateModulePropertyTypes.myPublicStaticProperty = exporter.createExportedWidget2(); // Error +publicClassWithPrivateModulePropertyTypes.myPublicStaticProperty1 = exporter.createExportedWidget4(); // Error exports.publicClassWithPrivateModulePropertyTypes = publicClassWithPrivateModulePropertyTypes; exports.publicVarWithPrivateModulePropertyTypes = exporter.createExportedWidget2(); // Error exports.publicVarWithPrivateModulePropertyTypes1 = exporter.createExportedWidget4(); // Error @@ -200,10 +200,10 @@ var privateClassWithPrivateModulePropertyTypes = (function () { this.myPublicProperty = exporter.createExportedWidget2(); this.myPublicProperty1 = exporter.createExportedWidget4(); } - privateClassWithPrivateModulePropertyTypes.myPublicStaticProperty = exporter.createExportedWidget2(); - privateClassWithPrivateModulePropertyTypes.myPublicStaticProperty1 = exporter.createExportedWidget4(); return privateClassWithPrivateModulePropertyTypes; }()); +privateClassWithPrivateModulePropertyTypes.myPublicStaticProperty = exporter.createExportedWidget2(); +privateClassWithPrivateModulePropertyTypes.myPublicStaticProperty1 = exporter.createExportedWidget4(); var privateVarWithPrivateModulePropertyTypes = exporter.createExportedWidget2(); var privateVarWithPrivateModulePropertyTypes1 = exporter.createExportedWidget4(); diff --git a/tests/baselines/reference/privateIndexer2.js b/tests/baselines/reference/privateIndexer2.js index 1268c6e4c25..a90e03a5bc2 100644 --- a/tests/baselines/reference/privateIndexer2.js +++ b/tests/baselines/reference/privateIndexer2.js @@ -14,7 +14,6 @@ var y: { var x = (_a = {}, _a[x] = string, _a.string = , - _a -); + _a); var y; var _a; diff --git a/tests/baselines/reference/privateStaticMemberAccessibility.js b/tests/baselines/reference/privateStaticMemberAccessibility.js index 2074e5aa864..352256ac9bd 100644 --- a/tests/baselines/reference/privateStaticMemberAccessibility.js +++ b/tests/baselines/reference/privateStaticMemberAccessibility.js @@ -25,6 +25,6 @@ var Derived = (function (_super) { _super.apply(this, arguments); this.bing = function () { return Base.foo; }; // error } - Derived.bar = Base.foo; // error return Derived; }(Base)); +Derived.bar = Base.foo; // error diff --git a/tests/baselines/reference/propertyAccessibility2.js b/tests/baselines/reference/propertyAccessibility2.js index afce6c4c24a..3618b86fcc5 100644 --- a/tests/baselines/reference/propertyAccessibility2.js +++ b/tests/baselines/reference/propertyAccessibility2.js @@ -9,7 +9,7 @@ var c = C.x; var C = (function () { function C() { } - C.x = 1; return C; }()); +C.x = 1; var c = C.x; diff --git a/tests/baselines/reference/quotedPropertyName2.js b/tests/baselines/reference/quotedPropertyName2.js index 1c4d85076ea..550e5299702 100644 --- a/tests/baselines/reference/quotedPropertyName2.js +++ b/tests/baselines/reference/quotedPropertyName2.js @@ -7,6 +7,6 @@ class Test1 { var Test1 = (function () { function Test1() { } - Test1["prop1"] = 0; return Test1; }()); +Test1["prop1"] = 0; diff --git a/tests/baselines/reference/reassignStaticProp.js b/tests/baselines/reference/reassignStaticProp.js index 2bf2bafa128..d9c37c29ad5 100644 --- a/tests/baselines/reference/reassignStaticProp.js +++ b/tests/baselines/reference/reassignStaticProp.js @@ -15,6 +15,6 @@ class foo { var foo = (function () { function foo() { } - foo.bar = 1; return foo; }()); +foo.bar = 1; diff --git a/tests/baselines/reference/sourceMap-FileWithComments.js b/tests/baselines/reference/sourceMap-FileWithComments.js index 9bb18dba33d..dd2131889af 100644 --- a/tests/baselines/reference/sourceMap-FileWithComments.js +++ b/tests/baselines/reference/sourceMap-FileWithComments.js @@ -49,10 +49,10 @@ var Shapes; } // Instance member Point.prototype.getDist = function () { return Math.sqrt(this.x * this.x + this.y * this.y); }; - // Static member - Point.origin = new Point(0, 0); return Point; }()); + // Static member + Point.origin = new Point(0, 0); Shapes.Point = Point; // Variable comment after class var a = 10; diff --git a/tests/baselines/reference/sourceMap-FileWithComments.js.map b/tests/baselines/reference/sourceMap-FileWithComments.js.map index f3e9674336d..80437501d33 100644 --- a/tests/baselines/reference/sourceMap-FileWithComments.js.map +++ b/tests/baselines/reference/sourceMap-FileWithComments.js.map @@ -1,2 +1,2 @@ //// [sourceMap-FileWithComments.js.map] -{"version":3,"file":"sourceMap-FileWithComments.js","sourceRoot":"","sources":["sourceMap-FileWithComments.ts"],"names":[],"mappings":"AAMA,SAAS;AACT,IAAO,MAAM,CAwBZ;AAxBD,WAAO,MAAM,EAAC,CAAC;IAEX,QAAQ;IACR;QACI,cAAc;QACd,eAAmB,CAAS,EAAS,CAAS;YAA3B,MAAC,GAAD,CAAC,CAAQ;YAAS,MAAC,GAAD,CAAC,CAAQ;QAAI,CAAC;QAEnD,kBAAkB;QAClB,uBAAO,GAAP,cAAY,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,GAAG,IAAI,CAAC,CAAC,GAAG,IAAI,CAAC,CAAC,GAAG,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;QAElE,gBAAgB;QACT,YAAM,GAAG,IAAI,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC;QACpC,YAAC;IAAD,CAAC,AATD,IASC;IATY,YAAK,QASjB,CAAA;IAED,+BAA+B;IAC/B,IAAI,CAAC,GAAG,EAAE,CAAC;IAEX;IACA,CAAC;IADe,UAAG,MAClB,CAAA;IAED;;MAEE;IACF,IAAI,CAAC,GAAG,EAAE,CAAC;AACf,CAAC,EAxBM,MAAM,KAAN,MAAM,QAwBZ;AAED,qBAAqB;AACrB,IAAI,CAAC,GAAW,IAAI,MAAM,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC;AACvC,IAAI,IAAI,GAAG,CAAC,CAAC,OAAO,EAAE,CAAC"} \ No newline at end of file +{"version":3,"file":"sourceMap-FileWithComments.js","sourceRoot":"","sources":["sourceMap-FileWithComments.ts"],"names":[],"mappings":"AAMA,SAAS;AACT,IAAO,MAAM,CAwBZ;AAxBD,WAAO,MAAM,EAAC,CAAC;IAEX,QAAQ;IACR;QACI,cAAc;QACd,eAAmB,CAAS,EAAS,CAAS;YAA3B,MAAC,GAAD,CAAC,CAAQ;YAAS,MAAC,GAAD,CAAC,CAAQ;QAAI,CAAC;QAEnD,kBAAkB;QAClB,uBAAO,GAAP,cAAY,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,GAAG,IAAI,CAAC,CAAC,GAAG,IAAI,CAAC,CAAC,GAAG,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;QAItE,YAAC;IAAD,CAAC,AATD;IAOI,gBAAgB;IACT,YAAM,GAAG,IAAI,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,CAClC;IATY,YAAK,QASjB,CAAA;IAED,+BAA+B;IAC/B,IAAI,CAAC,GAAG,EAAE,CAAC;IAEX;IACA,CAAC;IADe,UAAG,MAClB,CAAA;IAED;;MAEE;IACF,IAAI,CAAC,GAAG,EAAE,CAAC;AACf,CAAC,EAxBM,MAAM,KAAN,MAAM,QAwBZ;AAED,qBAAqB;AACrB,IAAI,CAAC,GAAW,IAAI,MAAM,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC;AACvC,IAAI,IAAI,GAAG,CAAC,CAAC,OAAO,EAAE,CAAC"} \ No newline at end of file diff --git a/tests/baselines/reference/sourceMap-FileWithComments.sourcemap.txt b/tests/baselines/reference/sourceMap-FileWithComments.sourcemap.txt index 3bcf2634507..2abfabff566 100644 --- a/tests/baselines/reference/sourceMap-FileWithComments.sourcemap.txt +++ b/tests/baselines/reference/sourceMap-FileWithComments.sourcemap.txt @@ -271,93 +271,90 @@ sourceFile:sourceMap-FileWithComments.ts 28>Emitted(12, 102) Source(16, 74) + SourceIndex(0) 29>Emitted(12, 103) Source(16, 75) + SourceIndex(0) --- ->>> // Static member -1 >^^^^^^^^ -2 > ^^^^^^^^^^^^^^^^ -3 > ^^^^^^^^^^^^^^^^-> -1 > - > - > -2 > // Static member -1 >Emitted(13, 9) Source(18, 9) + SourceIndex(0) -2 >Emitted(13, 25) Source(18, 25) + SourceIndex(0) ---- ->>> Point.origin = new Point(0, 0); -1->^^^^^^^^ -2 > ^^^^^^^^^^^^ -3 > ^^^ -4 > ^^^^ -5 > ^^^^^ -6 > ^ -7 > ^ -8 > ^^ -9 > ^ -10> ^ -11> ^ -1-> - > static -2 > origin -3 > = -4 > new -5 > Point -6 > ( -7 > 0 -8 > , -9 > 0 -10> ) -11> ; -1->Emitted(14, 9) Source(19, 16) + SourceIndex(0) -2 >Emitted(14, 21) Source(19, 22) + SourceIndex(0) -3 >Emitted(14, 24) Source(19, 25) + SourceIndex(0) -4 >Emitted(14, 28) Source(19, 29) + SourceIndex(0) -5 >Emitted(14, 33) Source(19, 34) + SourceIndex(0) -6 >Emitted(14, 34) Source(19, 35) + SourceIndex(0) -7 >Emitted(14, 35) Source(19, 36) + SourceIndex(0) -8 >Emitted(14, 37) Source(19, 38) + SourceIndex(0) -9 >Emitted(14, 38) Source(19, 39) + SourceIndex(0) -10>Emitted(14, 39) Source(19, 40) + SourceIndex(0) -11>Emitted(14, 40) Source(19, 41) + SourceIndex(0) ---- >>> return Point; 1 >^^^^^^^^ 2 > ^^^^^^^^^^^^ 1 > + > + > // Static member + > static origin = new Point(0, 0); > 2 > } -1 >Emitted(15, 9) Source(20, 5) + SourceIndex(0) -2 >Emitted(15, 21) Source(20, 6) + SourceIndex(0) +1 >Emitted(13, 9) Source(20, 5) + SourceIndex(0) +2 >Emitted(13, 21) Source(20, 6) + SourceIndex(0) --- >>> }()); 1 >^^^^ 2 > ^ 3 > -4 > ^^^^ -5 > ^^^^^^^^^^^^^^^^^-> +4 > ^^^^^^^^^^^^^^^^-> 1 > 2 > } 3 > -4 > export class Point implements IPoint { - > // Constructor - > constructor(public x: number, public y: number) { } - > - > // Instance member - > getDist() { return Math.sqrt(this.x * this.x + this.y * this.y); } - > - > // Static member - > static origin = new Point(0, 0); - > } -1 >Emitted(16, 5) Source(20, 5) + SourceIndex(0) -2 >Emitted(16, 6) Source(20, 6) + SourceIndex(0) -3 >Emitted(16, 6) Source(11, 5) + SourceIndex(0) -4 >Emitted(16, 10) Source(20, 6) + SourceIndex(0) +1 >Emitted(14, 5) Source(20, 5) + SourceIndex(0) +2 >Emitted(14, 6) Source(20, 6) + SourceIndex(0) +3 >Emitted(14, 6) Source(11, 5) + SourceIndex(0) +--- +>>> // Static member +1->^^^^ +2 > ^^^^^^^^^^^^^^^^ +3 > ^^^^^^^^^^^^^^^^-> +1->export class Point implements IPoint { + > // Constructor + > constructor(public x: number, public y: number) { } + > + > // Instance member + > getDist() { return Math.sqrt(this.x * this.x + this.y * this.y); } + > + > +2 > // Static member +1->Emitted(15, 5) Source(18, 9) + SourceIndex(0) +2 >Emitted(15, 21) Source(18, 25) + SourceIndex(0) +--- +>>> Point.origin = new Point(0, 0); +1->^^^^ +2 > ^^^^^^^^^^^^ +3 > ^^^ +4 > ^^^^ +5 > ^^^^^ +6 > ^ +7 > ^ +8 > ^^ +9 > ^ +10> ^ +11> ^ +1-> + > static +2 > origin +3 > = +4 > new +5 > Point +6 > ( +7 > 0 +8 > , +9 > 0 +10> ) +11> ; + > } +1->Emitted(16, 5) Source(19, 16) + SourceIndex(0) +2 >Emitted(16, 17) Source(19, 22) + SourceIndex(0) +3 >Emitted(16, 20) Source(19, 25) + SourceIndex(0) +4 >Emitted(16, 24) Source(19, 29) + SourceIndex(0) +5 >Emitted(16, 29) Source(19, 34) + SourceIndex(0) +6 >Emitted(16, 30) Source(19, 35) + SourceIndex(0) +7 >Emitted(16, 31) Source(19, 36) + SourceIndex(0) +8 >Emitted(16, 33) Source(19, 38) + SourceIndex(0) +9 >Emitted(16, 34) Source(19, 39) + SourceIndex(0) +10>Emitted(16, 35) Source(19, 40) + SourceIndex(0) +11>Emitted(16, 36) Source(20, 6) + SourceIndex(0) --- >>> Shapes.Point = Point; -1->^^^^ +1 >^^^^ 2 > ^^^^^^^^^^^^ 3 > ^^^^^^^^ 4 > ^ 5 > ^^^^^^^^^^^-> -1-> +1 > 2 > Point 3 > implements IPoint { > // Constructor @@ -370,7 +367,7 @@ sourceFile:sourceMap-FileWithComments.ts > static origin = new Point(0, 0); > } 4 > -1->Emitted(17, 5) Source(11, 18) + SourceIndex(0) +1 >Emitted(17, 5) Source(11, 18) + SourceIndex(0) 2 >Emitted(17, 17) Source(11, 23) + SourceIndex(0) 3 >Emitted(17, 25) Source(20, 6) + SourceIndex(0) 4 >Emitted(17, 26) Source(20, 6) + SourceIndex(0) diff --git a/tests/baselines/reference/sourceMapValidationDecorators.js b/tests/baselines/reference/sourceMapValidationDecorators.js index c3bb5cd7225..63cdb25900c 100644 --- a/tests/baselines/reference/sourceMapValidationDecorators.js +++ b/tests/baselines/reference/sourceMapValidationDecorators.js @@ -88,37 +88,37 @@ var Greeter = (function () { enumerable: true, configurable: true }); - Greeter.x1 = 10; - __decorate([ - PropertyDecorator1, - PropertyDecorator2(40) - ], Greeter.prototype, "greet", null); - __decorate([ - PropertyDecorator1, - PropertyDecorator2(50) - ], Greeter.prototype, "x", void 0); - __decorate([ - __param(0, ParameterDecorator1), - __param(0, ParameterDecorator2(70)) - ], Greeter.prototype, "fn", null); - __decorate([ - PropertyDecorator1, - PropertyDecorator2(80), - __param(0, ParameterDecorator1), - __param(0, ParameterDecorator2(90)) - ], Greeter.prototype, "greetings", null); - __decorate([ - PropertyDecorator1, - PropertyDecorator2(60) - ], Greeter, "x1", void 0); - Greeter = __decorate([ - ClassDecorator1, - ClassDecorator2(10), - __param(0, ParameterDecorator1), - __param(0, ParameterDecorator2(20)), - __param(1, ParameterDecorator1), - __param(1, ParameterDecorator2(30)) - ], Greeter); return Greeter; }()); +Greeter.x1 = 10; +__decorate([ + PropertyDecorator1, + PropertyDecorator2(40) +], Greeter.prototype, "greet", null); +__decorate([ + PropertyDecorator1, + PropertyDecorator2(50) +], Greeter.prototype, "x", void 0); +__decorate([ + __param(0, ParameterDecorator1), + __param(0, ParameterDecorator2(70)) +], Greeter.prototype, "fn", null); +__decorate([ + PropertyDecorator1, + PropertyDecorator2(80), + __param(0, ParameterDecorator1), + __param(0, ParameterDecorator2(90)) +], Greeter.prototype, "greetings", null); +__decorate([ + PropertyDecorator1, + PropertyDecorator2(60) +], Greeter, "x1", void 0); +Greeter = __decorate([ + ClassDecorator1, + ClassDecorator2(10), + __param(0, ParameterDecorator1), + __param(0, ParameterDecorator2(20)), + __param(1, ParameterDecorator1), + __param(1, ParameterDecorator2(30)) +], Greeter); //# sourceMappingURL=sourceMapValidationDecorators.js.map \ No newline at end of file diff --git a/tests/baselines/reference/sourceMapValidationDecorators.js.map b/tests/baselines/reference/sourceMapValidationDecorators.js.map index 0a6b45eb383..18b24ddf37e 100644 --- a/tests/baselines/reference/sourceMapValidationDecorators.js.map +++ b/tests/baselines/reference/sourceMapValidationDecorators.js.map @@ -1,2 +1,2 @@ //// [sourceMapValidationDecorators.js.map] -{"version":3,"file":"sourceMapValidationDecorators.js","sourceRoot":"","sources":["sourceMapValidationDecorators.ts"],"names":[],"mappings":";;;;;;;;;AASA;IACI,iBAGS,QAAgB;QAIvB,WAAc;aAAd,WAAc,CAAd,sBAAc,CAAd,IAAc;YAAd,0BAAc;;QAJP,aAAQ,GAAR,QAAQ,CAAQ;IAKzB,CAAC;IAID,uBAAK,GAAL;QACI,MAAM,CAAC,MAAM,GAAG,IAAI,CAAC,QAAQ,GAAG,OAAO,CAAC;IAC5C,CAAC;IAUO,oBAAE,GAAV,UAGE,CAAS;QACP,MAAM,CAAC,IAAI,CAAC,QAAQ,CAAC;IACzB,CAAC;IAID,sBAAI,8BAAS;aAAb;YACI,MAAM,CAAC,IAAI,CAAC,QAAQ,CAAC;QACzB,CAAC;aAED,UAGE,SAAiB;YACf,IAAI,CAAC,QAAQ,GAAG,SAAS,CAAC;QAC9B,CAAC;;;OAPA;IAbc,UAAE,GAAW,EAAE,CAAC;IAZ/B;QAAC,kBAAkB;QAClB,kBAAkB,CAAC,EAAE,CAAC;wCAAA;IAKvB;QAAC,kBAAkB;QAClB,kBAAkB,CAAC,EAAE,CAAC;sCAAA;IAQrB;mBAAC,mBAAmB;mBACnB,mBAAmB,CAAC,EAAE,CAAC;qCAAA;IAK1B;QAAC,kBAAkB;QAClB,kBAAkB,CAAC,EAAE,CAAC;mBAMpB,mBAAmB;mBACnB,mBAAmB,CAAC,EAAE,CAAC;4CAPH;IAZvB;QAAC,kBAAkB;QAClB,kBAAkB,CAAC,EAAE,CAAC;6BAAA;IAxB3B;QAAC,eAAe;QACf,eAAe,CAAC,EAAE,CAAC;mBAGb,mBAAmB;mBACnB,mBAAmB,CAAC,EAAE,CAAC;mBAGvB,mBAAmB;mBACnB,mBAAmB,CAAC,EAAE,CAAC;eARV;IA6CpB,cAAC;AAAD,CAAC,AA5CD,IA4CC"} \ No newline at end of file +{"version":3,"file":"sourceMapValidationDecorators.js","sourceRoot":"","sources":["sourceMapValidationDecorators.ts"],"names":[],"mappings":";;;;;;;;;AASA;IACI,iBAGS,QAAgB;QAIvB,WAAc;aAAd,WAAc,CAAd,sBAAc,CAAd,IAAc;YAAd,0BAAc;;QAJP,aAAQ,GAAR,QAAQ,CAAQ;IAKzB,CAAC;IAID,uBAAK,GAAL;QACI,MAAM,CAAC,MAAM,GAAG,IAAI,CAAC,QAAQ,GAAG,OAAO,CAAC;IAC5C,CAAC;IAUO,oBAAE,GAAV,UAGE,CAAS;QACP,MAAM,CAAC,IAAI,CAAC,QAAQ,CAAC;IACzB,CAAC;IAID,sBAAI,8BAAS;aAAb;YACI,MAAM,CAAC,IAAI,CAAC,QAAQ,CAAC;QACzB,CAAC;aAED,UAGE,SAAiB;YACf,IAAI,CAAC,QAAQ,GAAG,SAAS,CAAC;QAC9B,CAAC;;;OAPA;IAQL,cAAC;AAAD,CAAC,AA5CD;AAuBmB,UAAE,GAAW,EAAE,CAAC;AAZ/B;IAAC,kBAAkB;IAClB,kBAAkB,CAAC,EAAE,CAAC;oCAAA;AAKvB;IAAC,kBAAkB;IAClB,kBAAkB,CAAC,EAAE,CAAC;kCAAA;AAQrB;eAAC,mBAAmB;eACnB,mBAAmB,CAAC,EAAE,CAAC;iCAAA;AAK1B;IAAC,kBAAkB;IAClB,kBAAkB,CAAC,EAAE,CAAC;eAMpB,mBAAmB;eACnB,mBAAmB,CAAC,EAAE,CAAC;wCAPH;AAZvB;IAAC,kBAAkB;IAClB,kBAAkB,CAAC,EAAE,CAAC;yBAAA;AAxB3B;IAAC,eAAe;IACf,eAAe,CAAC,EAAE,CAAC;eAGb,mBAAmB;eACnB,mBAAmB,CAAC,EAAE,CAAC;eAGvB,mBAAmB;eACnB,mBAAmB,CAAC,EAAE,CAAC;WARV;AA6CnB"} \ No newline at end of file diff --git a/tests/baselines/reference/sourceMapValidationDecorators.sourcemap.txt b/tests/baselines/reference/sourceMapValidationDecorators.sourcemap.txt index 16820428856..58b5eaefc7c 100644 --- a/tests/baselines/reference/sourceMapValidationDecorators.sourcemap.txt +++ b/tests/baselines/reference/sourceMapValidationDecorators.sourcemap.txt @@ -356,113 +356,164 @@ sourceFile:sourceMapValidationDecorators.ts >>> configurable: true >>> }); 1->^^^^^^^ -2 > ^^^^^^^^^^^^^^-> +2 > ^^^^^^^^^^^^^-> 1-> 1->Emitted(33, 8) Source(46, 6) + SourceIndex(0) --- ->>> Greeter.x1 = 10; +>>> return Greeter; 1->^^^^ -2 > ^^^^^^^^^^ -3 > ^^^ -4 > ^^ -5 > ^ -1-> -2 > x1 -3 > : number = -4 > 10 -5 > ; -1->Emitted(34, 5) Source(33, 20) + SourceIndex(0) -2 >Emitted(34, 15) Source(33, 22) + SourceIndex(0) -3 >Emitted(34, 18) Source(33, 33) + SourceIndex(0) -4 >Emitted(34, 20) Source(33, 35) + SourceIndex(0) -5 >Emitted(34, 21) Source(33, 36) + SourceIndex(0) +2 > ^^^^^^^^^^^^^^ +1-> + > + > set greetings( + > @ParameterDecorator1 + > @ParameterDecorator2(90) + > greetings: string) { + > this.greeting = greetings; + > } + > +2 > } +1->Emitted(34, 5) Source(54, 1) + SourceIndex(0) +2 >Emitted(34, 19) Source(54, 2) + SourceIndex(0) --- ->>> __decorate([ -1 >^^^^ -2 > ^^^^^^^^^^^^^^^^^^^^^^^^-> +>>>}()); 1 > -1 >Emitted(35, 5) Source(21, 5) + SourceIndex(0) +2 >^ +3 > +4 > ^^^^^^^^^^^^^^^^-> +1 > +2 >} +3 > +1 >Emitted(35, 1) Source(54, 1) + SourceIndex(0) +2 >Emitted(35, 2) Source(54, 2) + SourceIndex(0) +3 >Emitted(35, 2) Source(10, 1) + SourceIndex(0) --- ->>> PropertyDecorator1, -1->^^^^^^^^ -2 > ^^^^^^^^^^^^^^^^^^ -3 > ^^^^^-> +>>>Greeter.x1 = 10; +1-> +2 >^^^^^^^^^^ +3 > ^^^ +4 > ^^ +5 > ^ +1->class Greeter { + > constructor( + > @ParameterDecorator1 + > @ParameterDecorator2(20) + > public greeting: string, + > + > @ParameterDecorator1 + > @ParameterDecorator2(30) + > ...b: string[]) { + > } + > + > @PropertyDecorator1 + > @PropertyDecorator2(40) + > greet() { + > return "

" + this.greeting + "

"; + > } + > + > @PropertyDecorator1 + > @PropertyDecorator2(50) + > private x: string; + > + > @PropertyDecorator1 + > @PropertyDecorator2(60) + > private static +2 >x1 +3 > : number = +4 > 10 +5 > ; +1->Emitted(36, 1) Source(33, 20) + SourceIndex(0) +2 >Emitted(36, 11) Source(33, 22) + SourceIndex(0) +3 >Emitted(36, 14) Source(33, 33) + SourceIndex(0) +4 >Emitted(36, 16) Source(33, 35) + SourceIndex(0) +5 >Emitted(36, 17) Source(33, 36) + SourceIndex(0) +--- +>>>__decorate([ +1 > +2 >^^^^^^^^^^^^^^^^^^^^^^^^-> +1 > +1 >Emitted(37, 1) Source(21, 5) + SourceIndex(0) +--- +>>> PropertyDecorator1, +1->^^^^ +2 > ^^^^^^^^^^^^^^^^^^ +3 > ^^^^^-> 1->@ -2 > PropertyDecorator1 -1->Emitted(36, 9) Source(21, 6) + SourceIndex(0) -2 >Emitted(36, 27) Source(21, 24) + SourceIndex(0) +2 > PropertyDecorator1 +1->Emitted(38, 5) Source(21, 6) + SourceIndex(0) +2 >Emitted(38, 23) Source(21, 24) + SourceIndex(0) --- ->>> PropertyDecorator2(40) -1->^^^^^^^^ -2 > ^^^^^^^^^^^^^^^^^^ -3 > ^ -4 > ^^ -5 > ^ -6 > ^^^^^^^^^^^^-> +>>> PropertyDecorator2(40) +1->^^^^ +2 > ^^^^^^^^^^^^^^^^^^ +3 > ^ +4 > ^^ +5 > ^ +6 > ^^^^^^^^^^^^-> 1-> > @ -2 > PropertyDecorator2 -3 > ( -4 > 40 -5 > ) -1->Emitted(37, 9) Source(22, 6) + SourceIndex(0) -2 >Emitted(37, 27) Source(22, 24) + SourceIndex(0) -3 >Emitted(37, 28) Source(22, 25) + SourceIndex(0) -4 >Emitted(37, 30) Source(22, 27) + SourceIndex(0) -5 >Emitted(37, 31) Source(22, 28) + SourceIndex(0) +2 > PropertyDecorator2 +3 > ( +4 > 40 +5 > ) +1->Emitted(39, 5) Source(22, 6) + SourceIndex(0) +2 >Emitted(39, 23) Source(22, 24) + SourceIndex(0) +3 >Emitted(39, 24) Source(22, 25) + SourceIndex(0) +4 >Emitted(39, 26) Source(22, 27) + SourceIndex(0) +5 >Emitted(39, 27) Source(22, 28) + SourceIndex(0) --- ->>> ], Greeter.prototype, "greet", null); -1->^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +>>>], Greeter.prototype, "greet", null); +1->^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 1-> -1->Emitted(38, 41) Source(22, 28) + SourceIndex(0) +1->Emitted(40, 37) Source(22, 28) + SourceIndex(0) --- ->>> __decorate([ -1 >^^^^ -2 > ^^^^^^^^^^^^^^^^^^^^^^^^-> +>>>__decorate([ +1 > +2 >^^^^^^^^^^^^^^^^^^^^^^^^-> 1 > > greet() { > return "

" + this.greeting + "

"; > } > > -1 >Emitted(39, 5) Source(27, 5) + SourceIndex(0) +1 >Emitted(41, 1) Source(27, 5) + SourceIndex(0) --- ->>> PropertyDecorator1, -1->^^^^^^^^ -2 > ^^^^^^^^^^^^^^^^^^ -3 > ^^^^^-> +>>> PropertyDecorator1, +1->^^^^ +2 > ^^^^^^^^^^^^^^^^^^ +3 > ^^^^^-> 1->@ -2 > PropertyDecorator1 -1->Emitted(40, 9) Source(27, 6) + SourceIndex(0) -2 >Emitted(40, 27) Source(27, 24) + SourceIndex(0) +2 > PropertyDecorator1 +1->Emitted(42, 5) Source(27, 6) + SourceIndex(0) +2 >Emitted(42, 23) Source(27, 24) + SourceIndex(0) --- ->>> PropertyDecorator2(50) -1->^^^^^^^^ -2 > ^^^^^^^^^^^^^^^^^^ -3 > ^ -4 > ^^ -5 > ^ -6 > ^^^^^^^^^^-> +>>> PropertyDecorator2(50) +1->^^^^ +2 > ^^^^^^^^^^^^^^^^^^ +3 > ^ +4 > ^^ +5 > ^ +6 > ^^^^^^^^^^-> 1-> > @ -2 > PropertyDecorator2 -3 > ( -4 > 50 -5 > ) -1->Emitted(41, 9) Source(28, 6) + SourceIndex(0) -2 >Emitted(41, 27) Source(28, 24) + SourceIndex(0) -3 >Emitted(41, 28) Source(28, 25) + SourceIndex(0) -4 >Emitted(41, 30) Source(28, 27) + SourceIndex(0) -5 >Emitted(41, 31) Source(28, 28) + SourceIndex(0) +2 > PropertyDecorator2 +3 > ( +4 > 50 +5 > ) +1->Emitted(43, 5) Source(28, 6) + SourceIndex(0) +2 >Emitted(43, 23) Source(28, 24) + SourceIndex(0) +3 >Emitted(43, 24) Source(28, 25) + SourceIndex(0) +4 >Emitted(43, 26) Source(28, 27) + SourceIndex(0) +5 >Emitted(43, 27) Source(28, 28) + SourceIndex(0) --- ->>> ], Greeter.prototype, "x", void 0); -1->^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +>>>], Greeter.prototype, "x", void 0); +1->^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 1-> -1->Emitted(42, 39) Source(28, 28) + SourceIndex(0) +1->Emitted(44, 35) Source(28, 28) + SourceIndex(0) --- ->>> __decorate([ -1 >^^^^ -2 > ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^-> +>>>__decorate([ +1 > +2 >^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^-> 1 > > private x: string; > @@ -472,83 +523,83 @@ sourceFile:sourceMapValidationDecorators.ts > > private fn( > -1 >Emitted(43, 5) Source(36, 7) + SourceIndex(0) +1 >Emitted(45, 1) Source(36, 7) + SourceIndex(0) --- ->>> __param(0, ParameterDecorator1), -1->^^^^^^^^^^^^^^^^^^^ -2 > ^^^^^^^^^^^^^^^^^^^ -3 > ^^^^^^-> +>>> __param(0, ParameterDecorator1), +1->^^^^^^^^^^^^^^^ +2 > ^^^^^^^^^^^^^^^^^^^ +3 > ^^^^^^-> 1->@ -2 > ParameterDecorator1 -1->Emitted(44, 20) Source(36, 8) + SourceIndex(0) -2 >Emitted(44, 39) Source(36, 27) + SourceIndex(0) +2 > ParameterDecorator1 +1->Emitted(46, 16) Source(36, 8) + SourceIndex(0) +2 >Emitted(46, 35) Source(36, 27) + SourceIndex(0) --- ->>> __param(0, ParameterDecorator2(70)) -1->^^^^^^^^^^^^^^^^^^^ -2 > ^^^^^^^^^^^^^^^^^^^ -3 > ^ -4 > ^^ -5 > ^ +>>> __param(0, ParameterDecorator2(70)) +1->^^^^^^^^^^^^^^^ +2 > ^^^^^^^^^^^^^^^^^^^ +3 > ^ +4 > ^^ +5 > ^ 1-> > @ -2 > ParameterDecorator2 -3 > ( -4 > 70 -5 > ) -1->Emitted(45, 20) Source(37, 8) + SourceIndex(0) -2 >Emitted(45, 39) Source(37, 27) + SourceIndex(0) -3 >Emitted(45, 40) Source(37, 28) + SourceIndex(0) -4 >Emitted(45, 42) Source(37, 30) + SourceIndex(0) -5 >Emitted(45, 43) Source(37, 31) + SourceIndex(0) +2 > ParameterDecorator2 +3 > ( +4 > 70 +5 > ) +1->Emitted(47, 16) Source(37, 8) + SourceIndex(0) +2 >Emitted(47, 35) Source(37, 27) + SourceIndex(0) +3 >Emitted(47, 36) Source(37, 28) + SourceIndex(0) +4 >Emitted(47, 38) Source(37, 30) + SourceIndex(0) +5 >Emitted(47, 39) Source(37, 31) + SourceIndex(0) --- ->>> ], Greeter.prototype, "fn", null); -1 >^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +>>>], Greeter.prototype, "fn", null); +1 >^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 1 > -1 >Emitted(46, 38) Source(37, 31) + SourceIndex(0) +1 >Emitted(48, 34) Source(37, 31) + SourceIndex(0) --- ->>> __decorate([ -1 >^^^^ -2 > ^^^^^^^^^^^^^^^^^^^^^^^^-> +>>>__decorate([ +1 > +2 >^^^^^^^^^^^^^^^^^^^^^^^^-> 1 > > x: number) { > return this.greeting; > } > > -1 >Emitted(47, 5) Source(42, 5) + SourceIndex(0) +1 >Emitted(49, 1) Source(42, 5) + SourceIndex(0) --- ->>> PropertyDecorator1, -1->^^^^^^^^ -2 > ^^^^^^^^^^^^^^^^^^ -3 > ^^^^^^-> +>>> PropertyDecorator1, +1->^^^^ +2 > ^^^^^^^^^^^^^^^^^^ +3 > ^^^^^^-> 1->@ -2 > PropertyDecorator1 -1->Emitted(48, 9) Source(42, 6) + SourceIndex(0) -2 >Emitted(48, 27) Source(42, 24) + SourceIndex(0) +2 > PropertyDecorator1 +1->Emitted(50, 5) Source(42, 6) + SourceIndex(0) +2 >Emitted(50, 23) Source(42, 24) + SourceIndex(0) --- ->>> PropertyDecorator2(80), -1->^^^^^^^^ -2 > ^^^^^^^^^^^^^^^^^^ -3 > ^ -4 > ^^ -5 > ^ -6 > ^^^^^^^^^^^-> +>>> PropertyDecorator2(80), +1->^^^^ +2 > ^^^^^^^^^^^^^^^^^^ +3 > ^ +4 > ^^ +5 > ^ +6 > ^^^^^^^^^^^-> 1-> > @ -2 > PropertyDecorator2 -3 > ( -4 > 80 -5 > ) -1->Emitted(49, 9) Source(43, 6) + SourceIndex(0) -2 >Emitted(49, 27) Source(43, 24) + SourceIndex(0) -3 >Emitted(49, 28) Source(43, 25) + SourceIndex(0) -4 >Emitted(49, 30) Source(43, 27) + SourceIndex(0) -5 >Emitted(49, 31) Source(43, 28) + SourceIndex(0) +2 > PropertyDecorator2 +3 > ( +4 > 80 +5 > ) +1->Emitted(51, 5) Source(43, 6) + SourceIndex(0) +2 >Emitted(51, 23) Source(43, 24) + SourceIndex(0) +3 >Emitted(51, 24) Source(43, 25) + SourceIndex(0) +4 >Emitted(51, 26) Source(43, 27) + SourceIndex(0) +5 >Emitted(51, 27) Source(43, 28) + SourceIndex(0) --- ->>> __param(0, ParameterDecorator1), -1->^^^^^^^^^^^^^^^^^^^ -2 > ^^^^^^^^^^^^^^^^^^^ -3 > ^^^^^^-> +>>> __param(0, ParameterDecorator1), +1->^^^^^^^^^^^^^^^ +2 > ^^^^^^^^^^^^^^^^^^^ +3 > ^^^^^^-> 1-> > get greetings() { > return this.greeting; @@ -556,176 +607,175 @@ sourceFile:sourceMapValidationDecorators.ts > > set greetings( > @ -2 > ParameterDecorator1 -1->Emitted(50, 20) Source(49, 8) + SourceIndex(0) -2 >Emitted(50, 39) Source(49, 27) + SourceIndex(0) +2 > ParameterDecorator1 +1->Emitted(52, 16) Source(49, 8) + SourceIndex(0) +2 >Emitted(52, 35) Source(49, 27) + SourceIndex(0) --- ->>> __param(0, ParameterDecorator2(90)) -1->^^^^^^^^^^^^^^^^^^^ -2 > ^^^^^^^^^^^^^^^^^^^ -3 > ^ -4 > ^^ -5 > ^ -6 > ^^^^-> +>>> __param(0, ParameterDecorator2(90)) +1->^^^^^^^^^^^^^^^ +2 > ^^^^^^^^^^^^^^^^^^^ +3 > ^ +4 > ^^ +5 > ^ +6 > ^^^^-> 1-> > @ -2 > ParameterDecorator2 -3 > ( -4 > 90 -5 > ) -1->Emitted(51, 20) Source(50, 8) + SourceIndex(0) -2 >Emitted(51, 39) Source(50, 27) + SourceIndex(0) -3 >Emitted(51, 40) Source(50, 28) + SourceIndex(0) -4 >Emitted(51, 42) Source(50, 30) + SourceIndex(0) -5 >Emitted(51, 43) Source(50, 31) + SourceIndex(0) +2 > ParameterDecorator2 +3 > ( +4 > 90 +5 > ) +1->Emitted(53, 16) Source(50, 8) + SourceIndex(0) +2 >Emitted(53, 35) Source(50, 27) + SourceIndex(0) +3 >Emitted(53, 36) Source(50, 28) + SourceIndex(0) +4 >Emitted(53, 38) Source(50, 30) + SourceIndex(0) +5 >Emitted(53, 39) Source(50, 31) + SourceIndex(0) --- ->>> ], Greeter.prototype, "greetings", null); -1->^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +>>>], Greeter.prototype, "greetings", null); +1->^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 1-> -1->Emitted(52, 45) Source(43, 28) + SourceIndex(0) +1->Emitted(54, 41) Source(43, 28) + SourceIndex(0) --- ->>> __decorate([ -1 >^^^^ -2 > ^^^^^^^^^^^^^^^^^^^^^^^^-> +>>>__decorate([ 1 > -1 >Emitted(53, 5) Source(31, 5) + SourceIndex(0) +2 >^^^^^^^^^^^^^^^^^^^^^^^^-> +1 > +1 >Emitted(55, 1) Source(31, 5) + SourceIndex(0) --- ->>> PropertyDecorator1, -1->^^^^^^^^ -2 > ^^^^^^^^^^^^^^^^^^ -3 > ^^^^^-> +>>> PropertyDecorator1, +1->^^^^ +2 > ^^^^^^^^^^^^^^^^^^ +3 > ^^^^^-> 1->@ -2 > PropertyDecorator1 -1->Emitted(54, 9) Source(31, 6) + SourceIndex(0) -2 >Emitted(54, 27) Source(31, 24) + SourceIndex(0) +2 > PropertyDecorator1 +1->Emitted(56, 5) Source(31, 6) + SourceIndex(0) +2 >Emitted(56, 23) Source(31, 24) + SourceIndex(0) --- ->>> PropertyDecorator2(60) -1->^^^^^^^^ -2 > ^^^^^^^^^^^^^^^^^^ -3 > ^ -4 > ^^ -5 > ^ -6 > ^-> +>>> PropertyDecorator2(60) +1->^^^^ +2 > ^^^^^^^^^^^^^^^^^^ +3 > ^ +4 > ^^ +5 > ^ +6 > ^-> 1-> > @ -2 > PropertyDecorator2 -3 > ( -4 > 60 -5 > ) -1->Emitted(55, 9) Source(32, 6) + SourceIndex(0) -2 >Emitted(55, 27) Source(32, 24) + SourceIndex(0) -3 >Emitted(55, 28) Source(32, 25) + SourceIndex(0) -4 >Emitted(55, 30) Source(32, 27) + SourceIndex(0) -5 >Emitted(55, 31) Source(32, 28) + SourceIndex(0) +2 > PropertyDecorator2 +3 > ( +4 > 60 +5 > ) +1->Emitted(57, 5) Source(32, 6) + SourceIndex(0) +2 >Emitted(57, 23) Source(32, 24) + SourceIndex(0) +3 >Emitted(57, 24) Source(32, 25) + SourceIndex(0) +4 >Emitted(57, 26) Source(32, 27) + SourceIndex(0) +5 >Emitted(57, 27) Source(32, 28) + SourceIndex(0) --- ->>> ], Greeter, "x1", void 0); -1->^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +>>>], Greeter, "x1", void 0); +1->^^^^^^^^^^^^^^^^^^^^^^^^^ 1-> -1->Emitted(56, 30) Source(32, 28) + SourceIndex(0) +1->Emitted(58, 26) Source(32, 28) + SourceIndex(0) --- ->>> Greeter = __decorate([ -1 >^^^^ -2 > ^^^^^^^^^^^^^^^^^^^^^-> +>>>Greeter = __decorate([ 1 > -1 >Emitted(57, 5) Source(8, 1) + SourceIndex(0) +2 >^^^^^^^^^^^^^^^^^^^^^-> +1 > +1 >Emitted(59, 1) Source(8, 1) + SourceIndex(0) --- ->>> ClassDecorator1, -1->^^^^^^^^ -2 > ^^^^^^^^^^^^^^^ -3 > ^^^^^^-> +>>> ClassDecorator1, +1->^^^^ +2 > ^^^^^^^^^^^^^^^ +3 > ^^^^^^-> 1->@ -2 > ClassDecorator1 -1->Emitted(58, 9) Source(8, 2) + SourceIndex(0) -2 >Emitted(58, 24) Source(8, 17) + SourceIndex(0) +2 > ClassDecorator1 +1->Emitted(60, 5) Source(8, 2) + SourceIndex(0) +2 >Emitted(60, 20) Source(8, 17) + SourceIndex(0) --- ->>> ClassDecorator2(10), -1->^^^^^^^^ -2 > ^^^^^^^^^^^^^^^ -3 > ^ -4 > ^^ -5 > ^ -6 > ^^^^^^^^^^^^^^-> +>>> ClassDecorator2(10), +1->^^^^ +2 > ^^^^^^^^^^^^^^^ +3 > ^ +4 > ^^ +5 > ^ +6 > ^^^^^^^^^^^^^^-> 1-> >@ -2 > ClassDecorator2 -3 > ( -4 > 10 -5 > ) -1->Emitted(59, 9) Source(9, 2) + SourceIndex(0) -2 >Emitted(59, 24) Source(9, 17) + SourceIndex(0) -3 >Emitted(59, 25) Source(9, 18) + SourceIndex(0) -4 >Emitted(59, 27) Source(9, 20) + SourceIndex(0) -5 >Emitted(59, 28) Source(9, 21) + SourceIndex(0) +2 > ClassDecorator2 +3 > ( +4 > 10 +5 > ) +1->Emitted(61, 5) Source(9, 2) + SourceIndex(0) +2 >Emitted(61, 20) Source(9, 17) + SourceIndex(0) +3 >Emitted(61, 21) Source(9, 18) + SourceIndex(0) +4 >Emitted(61, 23) Source(9, 20) + SourceIndex(0) +5 >Emitted(61, 24) Source(9, 21) + SourceIndex(0) --- ->>> __param(0, ParameterDecorator1), -1->^^^^^^^^^^^^^^^^^^^ -2 > ^^^^^^^^^^^^^^^^^^^ -3 > ^^^^^^^-> +>>> __param(0, ParameterDecorator1), +1->^^^^^^^^^^^^^^^ +2 > ^^^^^^^^^^^^^^^^^^^ +3 > ^^^^^^^-> 1-> >class Greeter { > constructor( > @ -2 > ParameterDecorator1 -1->Emitted(60, 20) Source(12, 8) + SourceIndex(0) -2 >Emitted(60, 39) Source(12, 27) + SourceIndex(0) +2 > ParameterDecorator1 +1->Emitted(62, 16) Source(12, 8) + SourceIndex(0) +2 >Emitted(62, 35) Source(12, 27) + SourceIndex(0) --- ->>> __param(0, ParameterDecorator2(20)), -1->^^^^^^^^^^^^^^^^^^^ -2 > ^^^^^^^^^^^^^^^^^^^ -3 > ^ -4 > ^^ -5 > ^ +>>> __param(0, ParameterDecorator2(20)), +1->^^^^^^^^^^^^^^^ +2 > ^^^^^^^^^^^^^^^^^^^ +3 > ^ +4 > ^^ +5 > ^ 1-> > @ -2 > ParameterDecorator2 -3 > ( -4 > 20 -5 > ) -1->Emitted(61, 20) Source(13, 8) + SourceIndex(0) -2 >Emitted(61, 39) Source(13, 27) + SourceIndex(0) -3 >Emitted(61, 40) Source(13, 28) + SourceIndex(0) -4 >Emitted(61, 42) Source(13, 30) + SourceIndex(0) -5 >Emitted(61, 43) Source(13, 31) + SourceIndex(0) +2 > ParameterDecorator2 +3 > ( +4 > 20 +5 > ) +1->Emitted(63, 16) Source(13, 8) + SourceIndex(0) +2 >Emitted(63, 35) Source(13, 27) + SourceIndex(0) +3 >Emitted(63, 36) Source(13, 28) + SourceIndex(0) +4 >Emitted(63, 38) Source(13, 30) + SourceIndex(0) +5 >Emitted(63, 39) Source(13, 31) + SourceIndex(0) --- ->>> __param(1, ParameterDecorator1), -1 >^^^^^^^^^^^^^^^^^^^ -2 > ^^^^^^^^^^^^^^^^^^^ -3 > ^^^^^^-> +>>> __param(1, ParameterDecorator1), +1 >^^^^^^^^^^^^^^^ +2 > ^^^^^^^^^^^^^^^^^^^ +3 > ^^^^^^-> 1 > > public greeting: string, > > @ -2 > ParameterDecorator1 -1 >Emitted(62, 20) Source(16, 8) + SourceIndex(0) -2 >Emitted(62, 39) Source(16, 27) + SourceIndex(0) +2 > ParameterDecorator1 +1 >Emitted(64, 16) Source(16, 8) + SourceIndex(0) +2 >Emitted(64, 35) Source(16, 27) + SourceIndex(0) --- ->>> __param(1, ParameterDecorator2(30)) -1->^^^^^^^^^^^^^^^^^^^ -2 > ^^^^^^^^^^^^^^^^^^^ -3 > ^ -4 > ^^ -5 > ^ +>>> __param(1, ParameterDecorator2(30)) +1->^^^^^^^^^^^^^^^ +2 > ^^^^^^^^^^^^^^^^^^^ +3 > ^ +4 > ^^ +5 > ^ 1-> > @ -2 > ParameterDecorator2 -3 > ( -4 > 30 -5 > ) -1->Emitted(63, 20) Source(17, 8) + SourceIndex(0) -2 >Emitted(63, 39) Source(17, 27) + SourceIndex(0) -3 >Emitted(63, 40) Source(17, 28) + SourceIndex(0) -4 >Emitted(63, 42) Source(17, 30) + SourceIndex(0) -5 >Emitted(63, 43) Source(17, 31) + SourceIndex(0) +2 > ParameterDecorator2 +3 > ( +4 > 30 +5 > ) +1->Emitted(65, 16) Source(17, 8) + SourceIndex(0) +2 >Emitted(65, 35) Source(17, 27) + SourceIndex(0) +3 >Emitted(65, 36) Source(17, 28) + SourceIndex(0) +4 >Emitted(65, 38) Source(17, 30) + SourceIndex(0) +5 >Emitted(65, 39) Source(17, 31) + SourceIndex(0) --- ->>> ], Greeter); -1 >^^^^^^^^^^^^^^^ -2 > ^^^^^-> +>>>], Greeter); +1 >^^^^^^^^^^^ +2 > ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^-> 1 > -1 >Emitted(64, 16) Source(9, 21) + SourceIndex(0) +1 >Emitted(66, 12) Source(9, 21) + SourceIndex(0) --- ->>> return Greeter; -1->^^^^ -2 > ^^^^^^^^^^^^^^ +>>>//# sourceMappingURL=sourceMapValidationDecorators.js.map1-> +2 >^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^-> 1-> >class Greeter { > constructor( @@ -771,68 +821,6 @@ sourceFile:sourceMapValidationDecorators.ts > greetings: string) { > this.greeting = greetings; > } - > -2 > } -1->Emitted(65, 5) Source(54, 1) + SourceIndex(0) -2 >Emitted(65, 19) Source(54, 2) + SourceIndex(0) ---- ->>>}()); -1 > -2 >^ -3 > -4 > ^^^^ -5 > ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^-> -1 > -2 >} -3 > -4 > class Greeter { - > constructor( - > @ParameterDecorator1 - > @ParameterDecorator2(20) - > public greeting: string, - > - > @ParameterDecorator1 - > @ParameterDecorator2(30) - > ...b: string[]) { - > } - > - > @PropertyDecorator1 - > @PropertyDecorator2(40) - > greet() { - > return "

" + this.greeting + "

"; - > } - > - > @PropertyDecorator1 - > @PropertyDecorator2(50) - > private x: string; - > - > @PropertyDecorator1 - > @PropertyDecorator2(60) - > private static x1: number = 10; - > - > private fn( - > @ParameterDecorator1 - > @ParameterDecorator2(70) - > x: number) { - > return this.greeting; - > } - > - > @PropertyDecorator1 - > @PropertyDecorator2(80) - > get greetings() { - > return this.greeting; - > } - > - > set greetings( - > @ParameterDecorator1 - > @ParameterDecorator2(90) - > greetings: string) { - > this.greeting = greetings; - > } - > } -1 >Emitted(66, 1) Source(54, 1) + SourceIndex(0) -2 >Emitted(66, 2) Source(54, 2) + SourceIndex(0) -3 >Emitted(66, 2) Source(10, 1) + SourceIndex(0) -4 >Emitted(66, 6) Source(54, 2) + SourceIndex(0) ---- ->>>//# sourceMappingURL=sourceMapValidationDecorators.js.map \ No newline at end of file + >} +1->Emitted(67, 1) Source(54, 2) + SourceIndex(0) +--- \ No newline at end of file diff --git a/tests/baselines/reference/staticClassProps.js b/tests/baselines/reference/staticClassProps.js index c808e4eb7fd..8a61bb7400f 100644 --- a/tests/baselines/reference/staticClassProps.js +++ b/tests/baselines/reference/staticClassProps.js @@ -13,6 +13,6 @@ var C = (function () { function C() { } C.prototype.foo = function () { }; - C.z = 1; return C; }()); +C.z = 1; diff --git a/tests/baselines/reference/staticMemberAccessOffDerivedType1.js b/tests/baselines/reference/staticMemberAccessOffDerivedType1.js index a05ece1dbbb..1c76a251220 100644 --- a/tests/baselines/reference/staticMemberAccessOffDerivedType1.js +++ b/tests/baselines/reference/staticMemberAccessOffDerivedType1.js @@ -28,6 +28,6 @@ var P = (function (_super) { function P() { _super.apply(this, arguments); } - P.SomeNumber = P.GetNumber(); return P; }(SomeBase)); +P.SomeNumber = P.GetNumber(); diff --git a/tests/baselines/reference/staticMemberInitialization.js b/tests/baselines/reference/staticMemberInitialization.js index c21c29ed4f8..13a5c8c25c6 100644 --- a/tests/baselines/reference/staticMemberInitialization.js +++ b/tests/baselines/reference/staticMemberInitialization.js @@ -10,8 +10,8 @@ var r = C.x; var C = (function () { function C() { } - C.x = 1; return C; }()); +C.x = 1; var c = new C(); var r = C.x; diff --git a/tests/baselines/reference/staticMemberWithStringAndNumberNames.js b/tests/baselines/reference/staticMemberWithStringAndNumberNames.js index 2fdd64ea04b..9d8846ba963 100644 --- a/tests/baselines/reference/staticMemberWithStringAndNumberNames.js +++ b/tests/baselines/reference/staticMemberWithStringAndNumberNames.js @@ -19,10 +19,10 @@ var C = (function () { this.x2 = C['0']; this.x3 = C[0]; } - C["foo"] = 0; - C[0] = 1; - C.s = C['foo']; - C.s2 = C['0']; - C.s3 = C[0]; return C; }()); +C["foo"] = 0; +C[0] = 1; +C.s = C['foo']; +C.s2 = C['0']; +C.s3 = C[0]; diff --git a/tests/baselines/reference/staticModifierAlreadySeen.js b/tests/baselines/reference/staticModifierAlreadySeen.js index 76f8b050d6f..c37d4c0807a 100644 --- a/tests/baselines/reference/staticModifierAlreadySeen.js +++ b/tests/baselines/reference/staticModifierAlreadySeen.js @@ -9,6 +9,6 @@ var C = (function () { function C() { } C.bar = function () { }; - C.foo = 1; return C; }()); +C.foo = 1; diff --git a/tests/baselines/reference/staticPropSuper.js b/tests/baselines/reference/staticPropSuper.js index f4bc5ece8d1..c25c406746d 100644 --- a/tests/baselines/reference/staticPropSuper.js +++ b/tests/baselines/reference/staticPropSuper.js @@ -52,9 +52,9 @@ var B = (function (_super) { var x = 1; // should not error _super.call(this); } - B.s = 9; return B; }(A)); +B.s = 9; var C = (function (_super) { __extends(C, _super); function C() { diff --git a/tests/baselines/reference/statics.js b/tests/baselines/reference/statics.js index 3776c09c8ce..d52a28208e6 100644 --- a/tests/baselines/reference/statics.js +++ b/tests/baselines/reference/statics.js @@ -45,11 +45,11 @@ var M; C.f = function (n) { return "wow: " + (n + C.y + C.pub + C.priv); }; - C.priv = 2; - C.pub = 3; - C.y = C.priv; return C; }()); + C.priv = 2; + C.pub = 3; + C.y = C.priv; M.C = C; var c = C.y; function f() { diff --git a/tests/baselines/reference/staticsInConstructorBodies.js b/tests/baselines/reference/staticsInConstructorBodies.js index 9bc3ed29325..edd49456ef7 100644 --- a/tests/baselines/reference/staticsInConstructorBodies.js +++ b/tests/baselines/reference/staticsInConstructorBodies.js @@ -11,6 +11,6 @@ var C = (function () { function C() { } C.m1 = function () { }; // ERROR - C.p1 = 0; // ERROR return C; }()); +C.p1 = 0; // ERROR diff --git a/tests/baselines/reference/staticsNotInScopeInClodule.js b/tests/baselines/reference/staticsNotInScopeInClodule.js index 150ae8aca5b..e10ed2b31d3 100644 --- a/tests/baselines/reference/staticsNotInScopeInClodule.js +++ b/tests/baselines/reference/staticsNotInScopeInClodule.js @@ -11,9 +11,9 @@ module Clod { var Clod = (function () { function Clod() { } - Clod.x = 10; return Clod; }()); +Clod.x = 10; var Clod; (function (Clod) { var p = x; // x isn't in scope here diff --git a/tests/baselines/reference/strictModeInConstructor.js b/tests/baselines/reference/strictModeInConstructor.js index 3b315861548..30dbfa58d70 100644 --- a/tests/baselines/reference/strictModeInConstructor.js +++ b/tests/baselines/reference/strictModeInConstructor.js @@ -105,18 +105,18 @@ var Bs = (function (_super) { "use strict"; // No error _super.call(this); } - Bs.s = 9; return Bs; }(A)); +Bs.s = 9; var Cs = (function (_super) { __extends(Cs, _super); function Cs() { _super.call(this); // No error "use strict"; } - Cs.s = 9; return Cs; }(A)); +Cs.s = 9; var Ds = (function (_super) { __extends(Ds, _super); function Ds() { @@ -124,6 +124,6 @@ var Ds = (function (_super) { _super.call(this); "use strict"; } - Ds.s = 9; return Ds; }(A)); +Ds.s = 9; diff --git a/tests/baselines/reference/superAccess.js b/tests/baselines/reference/superAccess.js index 37c6a9816a6..6e5cd9aca44 100644 --- a/tests/baselines/reference/superAccess.js +++ b/tests/baselines/reference/superAccess.js @@ -24,9 +24,9 @@ var MyBase = (function () { this.S2 = "test"; this.f = function () { return 5; }; } - MyBase.S1 = 5; return MyBase; }()); +MyBase.S1 = 5; var MyDerived = (function (_super) { __extends(MyDerived, _super); function MyDerived() { diff --git a/tests/baselines/reference/superAccess2.js b/tests/baselines/reference/superAccess2.js index b27d695cb31..c72bf387c24 100644 --- a/tests/baselines/reference/superAccess2.js +++ b/tests/baselines/reference/superAccess2.js @@ -59,6 +59,6 @@ var Q = (function (_super) { _super.x.call(this); // error _super.y.call(this); }; - Q.yy = _super.; // error for static initializer accessing super return Q; }(P)); +Q.yy = _super.; // error for static initializer accessing super diff --git a/tests/baselines/reference/thisInArrowFunctionInStaticInitializer1.js b/tests/baselines/reference/thisInArrowFunctionInStaticInitializer1.js index 4b23326c7a3..07d65c726b3 100644 --- a/tests/baselines/reference/thisInArrowFunctionInStaticInitializer1.js +++ b/tests/baselines/reference/thisInArrowFunctionInStaticInitializer1.js @@ -14,9 +14,9 @@ var Vector = (function () { function Vector() { var _this = this; } - Vector.foo = function () { - // 'this' should not be available in a static initializer. - log(_this); - }; return Vector; }()); +Vector.foo = function () { + // 'this' should not be available in a static initializer. + log(_this); +}; diff --git a/tests/baselines/reference/thisInConstructorParameter2.js b/tests/baselines/reference/thisInConstructorParameter2.js index 7260ecafcb9..ba2917c5a4e 100644 --- a/tests/baselines/reference/thisInConstructorParameter2.js +++ b/tests/baselines/reference/thisInConstructorParameter2.js @@ -25,6 +25,6 @@ var P = (function () { if (zz === void 0) { zz = this; } zz.y; }; - P.y = this; return P; }()); +P.y = this; diff --git a/tests/baselines/reference/thisInInvalidContexts.js b/tests/baselines/reference/thisInInvalidContexts.js index 75ccd12c288..76eeef0139c 100644 --- a/tests/baselines/reference/thisInInvalidContexts.js +++ b/tests/baselines/reference/thisInInvalidContexts.js @@ -58,9 +58,9 @@ var __extends = (this && this.__extends) || function (d, b) { var ErrClass1 = (function () { function ErrClass1() { } - ErrClass1.t = this; // Error return ErrClass1; }()); +ErrClass1.t = this; // Error var BaseErrClass = (function () { function BaseErrClass(t) { } diff --git a/tests/baselines/reference/thisInInvalidContextsExternalModule.js b/tests/baselines/reference/thisInInvalidContextsExternalModule.js index 2e7e6d8b47c..634b5ef0a20 100644 --- a/tests/baselines/reference/thisInInvalidContextsExternalModule.js +++ b/tests/baselines/reference/thisInInvalidContextsExternalModule.js @@ -59,9 +59,9 @@ var __extends = (this && this.__extends) || function (d, b) { var ErrClass1 = (function () { function ErrClass1() { } - ErrClass1.t = this; // Error return ErrClass1; }()); +ErrClass1.t = this; // Error var BaseErrClass = (function () { function BaseErrClass(t) { } diff --git a/tests/baselines/reference/thisInOuterClassBody.js b/tests/baselines/reference/thisInOuterClassBody.js index 40e4a2e2485..40b0e2b78ae 100644 --- a/tests/baselines/reference/thisInOuterClassBody.js +++ b/tests/baselines/reference/thisInOuterClassBody.js @@ -36,6 +36,6 @@ var Foo = (function () { var a = this.y; var b = this.x; }; - Foo.y = this; return Foo; }()); +Foo.y = this; diff --git a/tests/baselines/reference/thisInPropertyBoundDeclarations.js b/tests/baselines/reference/thisInPropertyBoundDeclarations.js index 0b378cec51a..f5967fbb5b2 100644 --- a/tests/baselines/reference/thisInPropertyBoundDeclarations.js +++ b/tests/baselines/reference/thisInPropertyBoundDeclarations.js @@ -74,13 +74,13 @@ var Bug = (function () { Bug.prototype.foo = function (name) { this.name = name; }; - Bug.func = [ - function (that, name) { - that.foo(name); - } - ]; return Bug; }()); +Bug.func = [ + function (that, name) { + that.foo(name); + } +]; // Valid use of this in a property bound decl var A = (function () { function A() { diff --git a/tests/baselines/reference/thisInStaticMethod1.js b/tests/baselines/reference/thisInStaticMethod1.js index a42415c0b62..1e39ded3b61 100644 --- a/tests/baselines/reference/thisInStaticMethod1.js +++ b/tests/baselines/reference/thisInStaticMethod1.js @@ -14,7 +14,7 @@ var foo = (function () { foo.bar = function () { return this.x; }; - foo.x = 3; return foo; }()); +foo.x = 3; var x = foo.bar(); diff --git a/tests/baselines/reference/thisTypeErrors.js b/tests/baselines/reference/thisTypeErrors.js index f246b80f4f4..5811ec6b709 100644 --- a/tests/baselines/reference/thisTypeErrors.js +++ b/tests/baselines/reference/thisTypeErrors.js @@ -75,9 +75,9 @@ var C2 = (function () { C2.foo = function (x) { return undefined; }; - C2.y = undefined; return C2; }()); +C2.y = undefined; var N1; (function (N1) { N1.y = this; diff --git a/tests/baselines/reference/typeArgumentInferenceWithClassExpression1.js b/tests/baselines/reference/typeArgumentInferenceWithClassExpression1.js index d18181dd1dc..44b37cc3be5 100644 --- a/tests/baselines/reference/typeArgumentInferenceWithClassExpression1.js +++ b/tests/baselines/reference/typeArgumentInferenceWithClassExpression1.js @@ -14,9 +14,11 @@ function foo(x) { }()); } return undefined; } -foo((function () { - function class_2() { - } - class_2.prop = "hello"; - return class_2; -}())).length; +foo((_a = (function () { + function class_2() { + } + return class_2; + }()), + _a.prop = "hello", + _a)).length; +var _a; diff --git a/tests/baselines/reference/typeArgumentInferenceWithClassExpression2.js b/tests/baselines/reference/typeArgumentInferenceWithClassExpression2.js index 66da2ffbff6..bd221a30137 100644 --- a/tests/baselines/reference/typeArgumentInferenceWithClassExpression2.js +++ b/tests/baselines/reference/typeArgumentInferenceWithClassExpression2.js @@ -16,9 +16,11 @@ function foo(x) { return undefined; } // Should not infer string because it is a static property -foo((function () { - function class_2() { - } - class_2.prop = "hello"; - return class_2; -}())).length; +foo((_a = (function () { + function class_2() { + } + return class_2; + }()), + _a.prop = "hello", + _a)).length; +var _a; diff --git a/tests/baselines/reference/typeOfPrototype.js b/tests/baselines/reference/typeOfPrototype.js index 3e8b3186936..a0f076113e0 100644 --- a/tests/baselines/reference/typeOfPrototype.js +++ b/tests/baselines/reference/typeOfPrototype.js @@ -11,7 +11,7 @@ var Foo = (function () { function Foo() { this.bar = 3; } - Foo.bar = ''; return Foo; }()); +Foo.bar = ''; Foo.prototype.bar = undefined; // Should be OK diff --git a/tests/baselines/reference/typeOfThisInStaticMembers2.js b/tests/baselines/reference/typeOfThisInStaticMembers2.js index b01770446be..886ea04e23d 100644 --- a/tests/baselines/reference/typeOfThisInStaticMembers2.js +++ b/tests/baselines/reference/typeOfThisInStaticMembers2.js @@ -11,12 +11,12 @@ class C2 { var C = (function () { function C() { } - C.foo = this; // error return C; }()); +C.foo = this; // error var C2 = (function () { function C2() { } - C2.foo = this; // error return C2; }()); +C2.foo = this; // error diff --git a/tests/baselines/reference/typeQueryOnClass.js b/tests/baselines/reference/typeQueryOnClass.js index 85dff0de831..80623af5be8 100644 --- a/tests/baselines/reference/typeQueryOnClass.js +++ b/tests/baselines/reference/typeQueryOnClass.js @@ -99,10 +99,10 @@ var C = (function () { enumerable: true, configurable: true }); - C.sa = 1; - C.sb = function () { return 1; }; return C; }()); +C.sa = 1; +C.sb = function () { return 1; }; var c; // BUG 820454 var r1; diff --git a/tests/baselines/reference/unqualifiedCallToClassStatic1.js b/tests/baselines/reference/unqualifiedCallToClassStatic1.js index 6c78a737fe8..906e9d3795f 100644 --- a/tests/baselines/reference/unqualifiedCallToClassStatic1.js +++ b/tests/baselines/reference/unqualifiedCallToClassStatic1.js @@ -10,9 +10,9 @@ class Vector { var Vector = (function () { function Vector() { } - Vector.foo = function () { - // 'foo' cannot be called in an unqualified manner. - foo(); - }; return Vector; }()); +Vector.foo = function () { + // 'foo' cannot be called in an unqualified manner. + foo(); +}; diff --git a/tests/baselines/reference/witness.js b/tests/baselines/reference/witness.js index e0a4c356873..56294a7cbb9 100644 --- a/tests/baselines/reference/witness.js +++ b/tests/baselines/reference/witness.js @@ -262,9 +262,9 @@ var c2inst; var C3 = (function () { function C3() { } - C3.q = C3.q; return C3; }()); +C3.q = C3.q; var qq = C3.q; var qq; // Parentheses - tested a bunch above diff --git a/tests/cases/unittests/transpile.ts b/tests/cases/unittests/transpile.ts index 6f46bb53405..084b2b08eab 100644 --- a/tests/cases/unittests/transpile.ts +++ b/tests/cases/unittests/transpile.ts @@ -2,26 +2,26 @@ module ts { describe("Transpile", () => { - + interface TranspileTestSettings { options?: TranspileOptions; expectedOutput?: string; expectedDiagnosticCodes?: number[]; } - + function checkDiagnostics(diagnostics: Diagnostic[], expectedDiagnosticCodes?: number[]) { if(!expectedDiagnosticCodes) { return; } - + for (let i = 0; i < expectedDiagnosticCodes.length; i++) { assert.equal(expectedDiagnosticCodes[i], diagnostics[i] && diagnostics[i].code, `Could not find expeced diagnostic.`); } - assert.equal(diagnostics.length, expectedDiagnosticCodes.length, "Resuting diagnostics count does not match expected"); + assert.equal(diagnostics.length, expectedDiagnosticCodes.length, "Resuting diagnostics count does not match expected"); } - + function test(input: string, testSettings: TranspileTestSettings): void { - + let transpileOptions: TranspileOptions = testSettings.options || {}; if (!transpileOptions.compilerOptions) { transpileOptions.compilerOptions = {}; @@ -30,43 +30,43 @@ module ts { // use \r\n as default new line transpileOptions.compilerOptions.newLine = ts.NewLineKind.CarriageReturnLineFeed; } - - let canUseOldTranspile = !transpileOptions.renamedDependencies; - + + let canUseOldTranspile = !transpileOptions.renamedDependencies; + transpileOptions.reportDiagnostics = true; let transpileModuleResult = transpileModule(input, transpileOptions); - + checkDiagnostics(transpileModuleResult.diagnostics, testSettings.expectedDiagnosticCodes); - + if (testSettings.expectedOutput !== undefined) { assert.equal(transpileModuleResult.outputText, testSettings.expectedOutput); } - + if (canUseOldTranspile) { let diagnostics: Diagnostic[] = []; - let transpileResult = transpile(input, transpileOptions.compilerOptions, transpileOptions.fileName, diagnostics, transpileOptions.moduleName); + let transpileResult = transpile(input, transpileOptions.compilerOptions, transpileOptions.fileName, diagnostics, transpileOptions.moduleName); checkDiagnostics(diagnostics, testSettings.expectedDiagnosticCodes); if (testSettings.expectedOutput) { assert.equal(transpileResult, testSettings.expectedOutput); } } - + // check source maps if (!transpileOptions.compilerOptions) { transpileOptions.compilerOptions = {}; } - + if (!transpileOptions.fileName) { transpileOptions.fileName = transpileOptions.compilerOptions.jsx ? "file.tsx" : "file.ts"; } - + transpileOptions.compilerOptions.sourceMap = true; let transpileModuleResultWithSourceMap = transpileModule(input, transpileOptions); assert.isTrue(transpileModuleResultWithSourceMap.sourceMapText !== undefined); - + let expectedSourceMapFileName = removeFileExtension(getBaseFileName(normalizeSlashes(transpileOptions.fileName))) + ".js.map"; let expectedSourceMappingUrlLine = `//# sourceMappingURL=${expectedSourceMapFileName}`; - + if (testSettings.expectedOutput !== undefined) { assert.equal(transpileModuleResultWithSourceMap.outputText, testSettings.expectedOutput + expectedSourceMappingUrlLine); } @@ -81,10 +81,10 @@ module ts { let suffix = getNewLineCharacter(transpileOptions.compilerOptions) + expectedSourceMappingUrlLine assert.isTrue(output.indexOf(suffix, output.length - suffix.length) !== -1); } - } + } } - + it("Generates correct compilerOptions diagnostics", () => { // Expecting 5047: "Option 'isolatedModules' can only be used when either option'--module' is provided or option 'target' is 'ES6' or higher." test(`var x = 0;`, { expectedDiagnosticCodes: [5047] }); @@ -97,7 +97,7 @@ module ts { it("Generates no diagnostics for missing file references", () => { test(`/// -var x = 0;`, +var x = 0;`, { options: { compilerOptions: { module: ModuleKind.CommonJS } } }); }); @@ -117,17 +117,17 @@ var x = 0;`, }); it("Generates module output", () => { - test(`var x = 0;`, - { - options: { compilerOptions: { module: ModuleKind.AMD } }, + test(`var x = 0;`, + { + options: { compilerOptions: { module: ModuleKind.AMD } }, expectedOutput: `define(["require", "exports"], function (require, exports) {\r\n "use strict";\r\n var x = 0;\r\n});\r\n` }); }); it("Uses correct newLine character", () => { - test(`var x = 0;`, - { - options: { compilerOptions: { module: ModuleKind.CommonJS, newLine: NewLineKind.LineFeed } }, + test(`var x = 0;`, + { + options: { compilerOptions: { module: ModuleKind.CommonJS, newLine: NewLineKind.LineFeed } }, expectedOutput: `"use strict";\nvar x = 0;\n` }); }); @@ -145,9 +145,9 @@ var x = 0;`, ` }\n` + ` }\n` + `});\n`; - test("var x = 1;", - { - options: { compilerOptions: { module: ModuleKind.System, newLine: NewLineKind.LineFeed }, moduleName: "NamedModule" }, + test("var x = 1;", + { + options: { compilerOptions: { module: ModuleKind.System, newLine: NewLineKind.LineFeed }, moduleName: "NamedModule" }, expectedOutput: output }) }); @@ -157,7 +157,7 @@ var x = 0;`, }); it("Rename dependencies - System", () => { - let input = + let input = `import {foo} from "SomeName";\n` + `declare function use(a: any);\n` + `use(foo);` @@ -177,15 +177,15 @@ var x = 0;`, ` }\n` + `});\n` - test(input, - { - options: { compilerOptions: { module: ModuleKind.System, newLine: NewLineKind.LineFeed }, renamedDependencies: { "SomeName": "SomeOtherName" } }, + test(input, + { + options: { compilerOptions: { module: ModuleKind.System, newLine: NewLineKind.LineFeed }, renamedDependencies: { "SomeName": "SomeOtherName" } }, expectedOutput: output }); }); it("Rename dependencies - AMD", () => { - let input = + let input = `import {foo} from "SomeName";\n` + `declare function use(a: any);\n` + `use(foo);` @@ -195,15 +195,15 @@ var x = 0;`, ` use(SomeName_1.foo);\n` + `});\n`; - test(input, - { - options: { compilerOptions: { module: ModuleKind.AMD, newLine: NewLineKind.LineFeed }, renamedDependencies: { "SomeName": "SomeOtherName" } }, + test(input, + { + options: { compilerOptions: { module: ModuleKind.AMD, newLine: NewLineKind.LineFeed }, renamedDependencies: { "SomeName": "SomeOtherName" } }, expectedOutput: output }); }); it("Rename dependencies - UMD", () => { - let input = + let input = `import {foo} from "SomeName";\n` + `declare function use(a: any);\n` + `use(foo);` @@ -221,15 +221,15 @@ var x = 0;`, ` use(SomeName_1.foo);\n` + `});\n`; - test(input, - { - options: { compilerOptions: { module: ModuleKind.UMD, newLine: NewLineKind.LineFeed }, renamedDependencies: { "SomeName": "SomeOtherName" } }, + test(input, + { + options: { compilerOptions: { module: ModuleKind.UMD, newLine: NewLineKind.LineFeed }, renamedDependencies: { "SomeName": "SomeOtherName" } }, expectedOutput: output }); }); - + it("Transpile with emit decorators and emit metadata", () => { - let input = + let input = `import {db} from './db';\n` + `function someDecorator(target) {\n` + ` return target;\n` + @@ -245,26 +245,26 @@ var x = 0;`, `export {MyClass}; \n` let output = `"use strict";\n` + - `var db_1 = require(\'./db\');\n` + + `var db_1 = require(\'./db\');\n` + `function someDecorator(target) {\n` + ` return target;\n` + - `}\n` + - `var MyClass = (function () {\n` + - ` function MyClass(db) {\n` + - ` this.db = db;\n` + - ` this.db.doSomething();\n` + - ` }\n` + - ` MyClass = __decorate([\n` + - ` someDecorator, \n` + - ` __metadata(\'design:paramtypes\', [(typeof (_a = typeof db_1.db !== \'undefined\' && db_1.db) === \'function\' && _a) || Object])\n` + - ` ], MyClass);\n` + - ` return MyClass;\n` + - ` var _a;\n` + - `}());\n` + - `exports.MyClass = MyClass;\n`; + `}\n` + + `var MyClass = (function () {\n` + + ` function MyClass(db) {\n` + + ` this.db = db;\n` + + ` this.db.doSomething();\n` + + ` }\n` + + ` return MyClass;\n` + + `}());\n` + + `MyClass = __decorate([\n` + + ` someDecorator, \n` + + ` __metadata(\'design:paramtypes\', [(typeof (_a = typeof db_1.db !== \'undefined\' && db_1.db) === \'function\' && _a) || Object])\n` + + `], MyClass);\n` + + `exports.MyClass = MyClass;\n` + + `var _a;\n`; - test(input, - { + test(input, + { options: { compilerOptions: { module: ModuleKind.CommonJS, @@ -274,7 +274,7 @@ var x = 0;`, experimentalDecorators: true, target: ScriptTarget.ES5, } - }, + }, expectedOutput: output }); }); @@ -282,7 +282,7 @@ var x = 0;`, it("Supports backslashes in file name", () => { test("var x", { expectedOutput: `"use strict";\r\nvar x;\r\n`, options: { fileName: "a\\b.ts" }}); }); - + it("transpile file as 'tsx' if 'jsx' is specified", () => { let input = `var x =
`; let output = `"use strict";\nvar x = React.createElement("div", null);\n`; From 359875b67de61c9acb68ae4f56540730f11e3508 Mon Sep 17 00:00:00 2001 From: Ron Buckton Date: Mon, 29 Feb 2016 15:07:23 -0800 Subject: [PATCH 3/9] PR Feedback --- src/compiler/factory.ts | 2 +- src/compiler/transformers/ts.ts | 47 ++++++++++++++++++++------------- src/compiler/utilities.ts | 4 +++ 3 files changed, 34 insertions(+), 19 deletions(-) diff --git a/src/compiler/factory.ts b/src/compiler/factory.ts index eae769fd562..ef908c40a9b 100644 --- a/src/compiler/factory.ts +++ b/src/compiler/factory.ts @@ -213,7 +213,7 @@ namespace ts { return name; } - export function createGeneratedNameForNode(node: Node, location?: TextRange): Identifier { + export function getGeneratedNameForNode(node: Node, location?: TextRange): Identifier { const name = createNode(SyntaxKind.Identifier, location); name.autoGenerateKind = GeneratedIdentifierKind.Node; name.original = node; diff --git a/src/compiler/transformers/ts.ts b/src/compiler/transformers/ts.ts index d791dd1eb4c..e672a0a79cd 100644 --- a/src/compiler/transformers/ts.ts +++ b/src/compiler/transformers/ts.ts @@ -8,8 +8,6 @@ namespace ts { export function transformTypeScript(context: TransformationContext) { const { - getGeneratedNameForNode, - makeUniqueName, setNodeEmitFlags, startLexicalEnvironment, endLexicalEnvironment, @@ -496,7 +494,7 @@ namespace ts { // Record an alias to avoid class double-binding. if (resolver.getNodeCheckFlags(getOriginalNode(node)) & NodeCheckFlags.ClassWithBodyScopedClassBinding) { enableExpressionSubstitutionForDecoratedClasses(); - decoratedClassAlias = makeUniqueName(node.name ? node.name.text : "default"); + decoratedClassAlias = createUniqueName(node.name && !isGeneratedIdentifier(node.name) ? node.name.text : "default"); decoratedClassAliases[getOriginalNodeId(node)] = decoratedClassAlias; // We emit the class alias as a `let` declaration here so that it has the same @@ -691,7 +689,7 @@ namespace ts { function transformConstructorParameters(constructor: ConstructorDeclaration, hasExtendsClause: boolean) { return constructor ? visitNodes(constructor.parameters, visitor, isParameter) - : hasExtendsClause ? [createRestParameter(makeUniqueName("args"))] : []; + : hasExtendsClause ? [createRestParameter(createUniqueName("args"))] : []; } /** @@ -2103,14 +2101,15 @@ namespace ts { } const savedCurrentNamespaceLocalName = currentNamespaceLocalName; - const modifiers = visitNodes(node.modifiers, visitor, isModifier); const statements: Statement[] = []; let location: TextRange = node; - if (!isNamespaceExport(node)) { + if (!isExported(node) || (isExternalModuleExport(node) && isFirstDeclarationOfKind(node, SyntaxKind.EnumDeclaration))) { + // Emit a VariableStatement if the enum is not exported, or is the first enum + // with the same name exported from an external module. addNode(statements, createVariableStatement( - modifiers, + visitNodes(node.modifiers, visitor, isModifier), createVariableDeclarationList([ createVariableDeclaration(node.name) ]), @@ -2179,7 +2178,7 @@ namespace ts { * * @param member The enum member node. */ - function transformEnumMember(member: EnumMember) { + function transformEnumMember(member: EnumMember): Statement { const name = getExpressionForPropertyName(member); return createStatement( createAssignment( @@ -2443,14 +2442,31 @@ namespace ts { && (isExternalModule(currentSourceFile) || !resolver.isTopLevelValueImportEqualsWithEntityName(node)); } + /** + * Gets a value indicating whether the node is exported. + * + * @param node The node to test. + */ + function isExported(node: Node) { + return (node.flags & NodeFlags.Export) !== 0; + } + + /** + * Gets a value indicating whether the node is exported from a namespace. + * + * @param node The node to test. + */ + function isNamespaceExport(node: Node) { + return currentNamespace !== undefined && isExported(node); + } + /** * Gets a value indicating whether the node is exported from an external module. * * @param node The node to test. */ function isExternalModuleExport(node: Node) { - return currentNamespace === undefined - && (node.flags & NodeFlags.Export) !== 0; + return currentNamespace === undefined && isExported(node); } /** @@ -2473,14 +2489,9 @@ namespace ts { && (node.flags & NodeFlags.Default) !== 0; } - /** - * Gets a value indicating whether the node is exported from a namespace. - * - * @param node The node to test. - */ - function isNamespaceExport(node: Node) { - return currentNamespace !== undefined - && (node.flags & NodeFlags.Export) !== 0; + function isFirstDeclarationOfKind(node: Declaration, kind: SyntaxKind) { + const original = getOriginalNode(node); + return !forEach(original.symbol && original.symbol.declarations, declaration => declaration.kind === kind && declaration.pos < original.pos); } /** diff --git a/src/compiler/utilities.ts b/src/compiler/utilities.ts index b700498cd4d..1b707cedc48 100644 --- a/src/compiler/utilities.ts +++ b/src/compiler/utilities.ts @@ -2865,6 +2865,10 @@ namespace ts { return node.kind === SyntaxKind.Identifier; } + export function isGeneratedIdentifier(node: Node): node is Identifier { + return isIdentifier(node) && node.autoGenerateKind > GeneratedIdentifierKind.Node; + } + // Keywords export function isModifier(node: Node): node is Modifier { From fe7ad5fde3ec24e8caeb7a5ed712119e5606d541 Mon Sep 17 00:00:00 2001 From: Ron Buckton Date: Mon, 29 Feb 2016 15:39:38 -0800 Subject: [PATCH 4/9] Minor tweaks to naming --- src/compiler/factory.ts | 20 +++++++++++++++----- src/compiler/transformers/ts.ts | 10 +++++----- 2 files changed, 20 insertions(+), 10 deletions(-) diff --git a/src/compiler/factory.ts b/src/compiler/factory.ts index ef908c40a9b..0ad04c0a092 100644 --- a/src/compiler/factory.ts +++ b/src/compiler/factory.ts @@ -153,7 +153,21 @@ namespace ts { * Creates a shallow, memberwise clone of a node for mutation. */ export function getMutableNode(node: T): T { - return cloneNode(node, node, node.flags, node.parent, node); + return cloneNode(node, /*location*/ node, node.flags, /*parent*/ undefined, /*original*/ node); + } + + /** + * Creates a shallow, memberwise clone of a node with no source map location. + */ + export function getSynthesizedClone(node: T): T { + return nodeIsSynthesized(node) ? node : cloneNode(node, /*location*/ undefined, node.flags, /*parent*/ undefined, /*original*/ node); + } + + /** + * Creates a shallow, memberwise clone of a node at the specified source map location. + */ + export function getRelocatedClone(node: T, location: TextRange): T { + return cloneNode(node, location, node.flags, /*parent*/ undefined, /*original*/ node); } export function createNodeArrayNode(elements: T[]): NodeArrayNode { @@ -1340,8 +1354,4 @@ namespace ts { node.flags = flags; return node; } - - export function getSynthesizedNode(node: T): T { - return nodeIsSynthesized(node) ? node : cloneNode(node, /*location*/ undefined, node.flags, /*parent*/ undefined, /*original*/ node); - } } \ No newline at end of file diff --git a/src/compiler/transformers/ts.ts b/src/compiler/transformers/ts.ts index e672a0a79cd..b7a180aab92 100644 --- a/src/compiler/transformers/ts.ts +++ b/src/compiler/transformers/ts.ts @@ -1644,7 +1644,7 @@ namespace ts { return createLiteral(name.text); } else { - return getSynthesizedNode(name); + return getSynthesizedClone(name); } } @@ -1813,7 +1813,7 @@ namespace ts { if (isNamespaceExport(node)) { return createNodeArrayNode([ func, - createNamespaceExport(getSynthesizedNode(node.name), getSynthesizedNode(node.name)) + createNamespaceExport(getSynthesizedClone(node.name), getSynthesizedClone(node.name)) ]); } @@ -2420,7 +2420,7 @@ namespace ts { // exports.${name} = ${moduleReference}; return setOriginalNode( createNamespaceExport( - getSynthesizedNode(node.name), + getSynthesizedClone(node.name), moduleReference, node ), @@ -2520,14 +2520,14 @@ namespace ts { } function getNamespaceMemberName(name: Identifier): Expression { - name = getSynthesizedNode(name); + name = getSynthesizedClone(name); return currentNamespaceLocalName ? createPropertyAccess(currentNamespaceLocalName, name) : name; } function getDeclarationName(node: ClassExpression | ClassDeclaration | FunctionDeclaration) { - return node.name ? getSynthesizedNode(node.name) : getGeneratedNameForNode(node); + return node.name ? getSynthesizedClone(node.name) : getGeneratedNameForNode(node); } function getClassPrototype(node: ClassExpression | ClassDeclaration) { From a0dbe7601cf3eb5fff2a5aa61c459cee868b6e25 Mon Sep 17 00:00:00 2001 From: Ron Buckton Date: Mon, 29 Feb 2016 17:35:50 -0800 Subject: [PATCH 5/9] PR Feedback --- src/compiler/checker.ts | 6 +- src/compiler/emitter.ts | 6 +- src/compiler/printer.ts | 2 +- src/compiler/transformers/ts.ts | 458 ++++++++++++++++++-------------- src/compiler/types.ts | 4 +- src/compiler/utilities.ts | 5 +- 6 files changed, 269 insertions(+), 212 deletions(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 3cb9031fd99..278159469e1 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -4846,7 +4846,7 @@ namespace ts { const parent = container && container.parent; if (parent && (isClassLike(parent) || parent.kind === SyntaxKind.InterfaceDeclaration)) { if (!(container.flags & NodeFlags.Static) && - (container.kind !== SyntaxKind.Constructor || isNodeDescendentOf(node, (container).body))) { + (container.kind !== SyntaxKind.Constructor || isNodeDescendantOf(node, (container).body))) { return getDeclaredTypeOfClassOrInterface(getSymbolOfNode(parent)).thisType; } } @@ -7206,8 +7206,8 @@ namespace ts { let container = getContainingClass(node); while (container !== undefined) { if (container === localOrExportSymbol.valueDeclaration && container.name !== node) { - getNodeLinks(container).flags |= NodeCheckFlags.ClassWithBodyScopedClassBinding; - getNodeLinks(node).flags |= NodeCheckFlags.BodyScopedClassBinding; + getNodeLinks(container).flags |= NodeCheckFlags.DecoratedClassWithSelfReference; + getNodeLinks(node).flags |= NodeCheckFlags.SelfReferenceInDecoratedClass; break; } diff --git a/src/compiler/emitter.ts b/src/compiler/emitter.ts index a3c27d8d817..bda2bd79506 100644 --- a/src/compiler/emitter.ts +++ b/src/compiler/emitter.ts @@ -346,7 +346,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge }; function isUniqueLocalName(name: string, container: Node): boolean { - for (let node = container; isNodeDescendentOf(node, container); node = node.nextContainer) { + for (let node = container; isNodeDescendantOf(node, container); node = node.nextContainer) { if (node.locals && hasProperty(node.locals, name)) { // We conservatively include alias symbols to cover cases where they're emitted as locals if (node.locals[name].flags & (SymbolFlags.Value | SymbolFlags.ExportValue | SymbolFlags.Alias)) { @@ -1529,7 +1529,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge return; } } - else if (resolver.getNodeCheckFlags(node) & NodeCheckFlags.BodyScopedClassBinding) { + else if (resolver.getNodeCheckFlags(node) & NodeCheckFlags.SelfReferenceInDecoratedClass) { // Due to the emit for class decorators, any reference to the class from inside of the class body // must instead be rewritten to point to a temporary variable to avoid issues with the double-bind // behavior of class names in ES6. @@ -5203,7 +5203,7 @@ const _super = (function (geti, seti) { // [Example 4] // - if (resolver.getNodeCheckFlags(node) & NodeCheckFlags.ClassWithBodyScopedClassBinding) { + if (resolver.getNodeCheckFlags(node) & NodeCheckFlags.DecoratedClassWithSelfReference) { decoratedClassAlias = unescapeIdentifier(makeUniqueName(node.name ? node.name.text : "default")); decoratedClassAliases[getNodeId(node)] = decoratedClassAlias; write(`let ${decoratedClassAlias};`); diff --git a/src/compiler/printer.ts b/src/compiler/printer.ts index e44e88b4612..331e502b931 100644 --- a/src/compiler/printer.ts +++ b/src/compiler/printer.ts @@ -2368,7 +2368,7 @@ const _super = (function (geti, seti) { } function isUniqueLocalName(name: string, container: Node): boolean { - for (let node = container; isNodeDescendentOf(node, container); node = node.nextContainer) { + for (let node = container; isNodeDescendantOf(node, container); node = node.nextContainer) { if (node.locals && hasProperty(node.locals, name)) { // We conservatively include alias symbols to cover cases where they're emitted as locals if (node.locals[name].flags & (SymbolFlags.Value | SymbolFlags.ExportValue | SymbolFlags.Alias)) { diff --git a/src/compiler/transformers/ts.ts b/src/compiler/transformers/ts.ts index b7a180aab92..58f06cb214e 100644 --- a/src/compiler/transformers/ts.ts +++ b/src/compiler/transformers/ts.ts @@ -6,6 +6,15 @@ namespace ts { type SuperContainer = ClassDeclaration | MethodDeclaration | GetAccessorDeclaration | SetAccessorDeclaration | ConstructorDeclaration; + const enum TypeScriptSubstitutionFlags { + /** Enables substitutions for decorated classes. */ + DecoratedClasses = 1 << 0, + /** Enables substitutions for namespace exports. */ + NamespaceExports = 1 << 1, + /** Enables substitutions for async methods with `super` calls. */ + AsyncMethodsWithSuper = 1 << 2, + } + export function transformTypeScript(context: TransformationContext) { const { setNodeEmitFlags, @@ -19,14 +28,14 @@ namespace ts { const languageVersion = getEmitScriptTarget(compilerOptions); // Save the previous transformation hooks. - const previousExpressionSubstitution = context.expressionSubstitution; const previousOnBeforeEmitNode = context.onBeforeEmitNode; const previousOnAfterEmitNode = context.onAfterEmitNode; + const previousExpressionSubstitution = context.expressionSubstitution; // Set new transformation hooks. - context.expressionSubstitution = substituteExpression; context.onBeforeEmitNode = onBeforeEmitNode; context.onAfterEmitNode = onAfterEmitNode; + context.expressionSubstitution = substituteExpression; // These variables contain state that changes as we descend into the tree. let currentSourceFile: SourceFile; @@ -36,31 +45,46 @@ namespace ts { let currentParent: Node; let currentNode: Node; - // These variables keep track of whether expression substitution has been enabled for - // specific edge cases. They are persisted between each SourceFile transformation and - // should not be reset. - let hasEnabledExpressionSubstitutionForDecoratedClasses = false; - let hasEnabledExpressionSubstitutionForNamespaceExports = false; - let hasEnabledExpressionSubstitutionForAsyncMethodsWithSuper = false; + /** + * Keeps track of whether expression substitution has been enabled for specific edge cases. + * They are persisted between each SourceFile transformation and should not be reset. + */ + let enabledSubstitutions: TypeScriptSubstitutionFlags; - // This map keeps track of aliases created for classes with decorators to avoid issues - // with the double-binding behavior of classes. + /** + * A map that keeps track of aliases created for classes with decorators to avoid issues + * with the double-binding behavior of classes. + */ let decoratedClassAliases: Map; - // This map keeps track of currently active aliases defined in `decoratedClassAliases` - // when just-in-time substitution occurs while printing an expression identifier. + /** + * A map that keeps track of currently active aliases defined in `decoratedClassAliases` + * when just-in-time substitution occurs while printing an expression identifier. + */ let currentDecoratedClassAliases: Map; - // This value keeps track of how deeply nested we are within any containing namespaces - // when performing just-in-time substitution while printing an expression identifier. + /** + * Keeps track of how deeply nested we are within any containing namespaces + * when performing just-in-time substitution while printing an expression identifier. + * If the nest level is greater than zero, then we are performing a substitution + * inside of a namespace and we should perform the more costly checks to determine + * whether the identifier points to an exported declaration. + */ let namespaceNestLevel: number; - // This array keeps track of containers where `super` is valid, for use with - // just-in-time substitution for `super` expressions inside of async methods. + /** + * This array keeps track of containers where `super` is valid, for use with + * just-in-time substitution for `super` expressions inside of async methods. + */ let superContainerStack: SuperContainer[]; return transformSourceFile; + /** + * Transform TypeScript-specific syntax in a SourceFile. + * + * @param node A SourceFile node. + */ function transformSourceFile(node: SourceFile) { currentSourceFile = node; node = visitEachChild(node, visitor, context); @@ -136,8 +160,7 @@ namespace ts { * @param node The node to visit. */ function namespaceElementVisitorWorker(node: Node): Node { - if (node.transformFlags & TransformFlags.TypeScript - || node.flags & NodeFlags.Export) { + if (node.transformFlags & TransformFlags.TypeScript || isExported(node)) { // This node is explicitly marked as TypeScript, or is exported at the namespace // level, so we should transform the node. node = visitTypeScript(node); @@ -165,12 +188,25 @@ namespace ts { * @param node The node to visit. */ function classElementVisitorWorker(node: Node) { - if (node.kind === SyntaxKind.Constructor) { - // TypeScript constructors are elided. - return undefined; - } + switch (node.kind) { + case SyntaxKind.Constructor: + // TypeScript constructors are transformed in `transformClassDeclaration`. + // We elide them here as `visitorWorker` checks transform flags, which could + // erronously include an ES6 constructor without TypeScript syntax. + return undefined; - return visitorWorker(node); + case SyntaxKind.PropertyDeclaration: + case SyntaxKind.IndexSignature: + case SyntaxKind.GetAccessor: + case SyntaxKind.SetAccessor: + case SyntaxKind.MethodDeclaration: + // Fallback to the default visit behavior. + return visitorWorker(node); + + default: + Debug.fail("Unexpected node."); + break; + } } /** @@ -179,9 +215,9 @@ namespace ts { * @param node The node to visit. */ function visitTypeScript(node: Node): Node { - // TypeScript ambient declarations are elided. if (node.flags & NodeFlags.Ambient) { - return; + // TypeScript ambient declarations are elided. + return undefined; } switch (node.kind) { @@ -233,8 +269,7 @@ namespace ts { // TypeScript property declarations are elided. case SyntaxKind.Constructor: - // TypeScript constructors are elided. The constructor of a class will be - // transformed as part of `transformClassDeclaration`. + // TypeScript constructors are transformed in `transformClassDeclaration`. return undefined; case SyntaxKind.ClassDeclaration: @@ -376,11 +411,7 @@ namespace ts { */ function visitClassDeclaration(node: ClassDeclaration): NodeArrayNode { const staticProperties = getInitializedProperties(node, /*isStatic*/ true); - const statements: Statement[] = []; - const modifiers = visitNodes(node.modifiers, visitor, isModifier); - const heritageClauses = visitNodes(node.heritageClauses, visitor, isHeritageClause); - const members = transformClassMembers(node, heritageClauses !== undefined); - let decoratedClassAlias: Identifier; + const hasExtendsClause = getClassExtendsHeritageClauseElement(node) !== undefined; // emit name if // - node has a name @@ -391,166 +422,28 @@ namespace ts { name = getGeneratedNameForNode(node); } - if (node.decorators) { - // When we emit an ES6 class that has a class decorator, we must tailor the - // emit to certain specific cases. - // - // In the simplest case, we emit the class declaration as a let declaration, and - // evaluate decorators after the close of the class body: - // - // [Example 1] - // --------------------------------------------------------------------- - // TypeScript | Javascript - // --------------------------------------------------------------------- - // @dec | let C = class C { - // class C { | } - // } | C = __decorate([dec], C); - // --------------------------------------------------------------------- - // @dec | let C = class C { - // export class C { | } - // } | C = __decorate([dec], C); - // | export { C }; - // --------------------------------------------------------------------- - // - // If a class declaration contains a reference to itself *inside* of the class body, - // this introduces two bindings to the class: One outside of the class body, and one - // inside of the class body. If we apply decorators as in [Example 1] above, there - // is the possibility that the decorator `dec` will return a new value for the - // constructor, which would result in the binding inside of the class no longer - // pointing to the same reference as the binding outside of the class. - // - // As a result, we must instead rewrite all references to the class *inside* of the - // class body to instead point to a local temporary alias for the class: - // - // [Example 2] - // --------------------------------------------------------------------- - // TypeScript | Javascript - // --------------------------------------------------------------------- - // @dec | let C_1; - // class C { | let C = C_1 = class C { - // static x() { return C.y; } | static x() { return C_1.y; } - // static y = 1; | } - // } | C.y = 1; - // | C = C_1 = __decorate([dec], C); - // --------------------------------------------------------------------- - // @dec | let C_1; - // export class C { | let C = C_1 = class C { - // static x() { return C.y; } | static x() { return C_1.y; } - // static y = 1; | } - // } | C.y = 1; - // | C = C_1 = __decorate([dec], C); - // | export { C }; - // --------------------------------------------------------------------- - // - // If a class declaration is the default export of a module, we instead emit - // the export after the decorated declaration: - // - // [Example 3] - // --------------------------------------------------------------------- - // TypeScript | Javascript - // --------------------------------------------------------------------- - // @dec | let default_1 = class { - // export default class { | } - // } | default_1 = __decorate([dec], default_1); - // | export default default_1; - // --------------------------------------------------------------------- - // @dec | let C = class C { - // export default class C { | } - // } | C = __decorate([dec], C); - // | export default C; - // --------------------------------------------------------------------- - // - // If the class declaration is the default export and a reference to itself - // inside of the class body, we must emit both an alias for the class *and* - // move the export after the declaration: - // - // [Example 4] - // --------------------------------------------------------------------- - // TypeScript | Javascript - // --------------------------------------------------------------------- - // @dec | let C_1; - // export default class C { | let C = C_1 = class C { - // static x() { return C.y; } | static x() { return C_1.y; } - // static y = 1; | } - // } | C.y = 1; - // | C = C_1 = __decorate([dec], C); - // | export default C; - // --------------------------------------------------------------------- - // - - // class ${name} ${heritageClauses} { - // ${members} - // } - let classExpression: Expression = setOriginalNode( - createClassExpression( - name, - heritageClauses, - members, - /*location*/ node - ), - node - ); - - // Record an alias to avoid class double-binding. - if (resolver.getNodeCheckFlags(getOriginalNode(node)) & NodeCheckFlags.ClassWithBodyScopedClassBinding) { - enableExpressionSubstitutionForDecoratedClasses(); - decoratedClassAlias = createUniqueName(node.name && !isGeneratedIdentifier(node.name) ? node.name.text : "default"); - decoratedClassAliases[getOriginalNodeId(node)] = decoratedClassAlias; - - // We emit the class alias as a `let` declaration here so that it has the same - // TDZ as the class. - - // let ${decoratedClassAlias}; - addNode(statements, - createVariableStatement( - /*modifiers*/ undefined, - createVariableDeclarationList([ - createVariableDeclaration(decoratedClassAlias) - ], - /*location*/ undefined, - NodeFlags.Let) - ) - ); - - // ${decoratedClassAlias} = ${classExpression} - classExpression = createAssignment( - cloneNode(decoratedClassAlias), - classExpression, - /*location*/ node); - } - - // let ${name} = ${classExpression}; - addNode(statements, - createVariableStatement( - /*modifiers*/ undefined, - createVariableDeclarationList([ - createVariableDeclaration( - name, - classExpression - ) - ], - /*location*/ undefined, - NodeFlags.Let) - ) - ); - } - else { + let decoratedClassAlias: Identifier; + const statements: Statement[] = []; + if (!node.decorators) { // ${modifiers} class ${name} ${heritageClauses} { // ${members} // } addNode(statements, setOriginalNode( createClassDeclaration( - modifiers, + visitNodes(node.modifiers, visitor, isModifier), name, - heritageClauses, - members, + visitNodes(node.heritageClauses, visitor, isHeritageClause), + transformClassMembers(node, hasExtendsClause), /*location*/ node ), node ) ); } + else { + decoratedClassAlias = addClassDeclarationHeadWithDecorators(statements, node, name, hasExtendsClause); + } // Emit static property assignment. Because classDeclaration is lexically evaluated, // it is safe to emit static property assignment after classDeclaration @@ -575,13 +468,168 @@ namespace ts { addNode(statements, createExportDefault(name)); } else if (isNamedExternalModuleExport(node)) { - addNode(statements, createModuleExport(name)); + addNode(statements, createExternalModuleExport(name)); } } return createNodeArrayNode(statements); } + /** + * Transforms a decorated class declaration and appends the resulting statements. If + * the class requires an alias to avoid issues with double-binding, the alias is returned. + * + * @param node A ClassDeclaration node. + * @param name The name of the class. + * @param hasExtendsClause A value indicating whether + */ + function addClassDeclarationHeadWithDecorators(statements: Statement[], node: ClassDeclaration, name: Identifier, hasExtendsClause: boolean) { + // When we emit an ES6 class that has a class decorator, we must tailor the + // emit to certain specific cases. + // + // In the simplest case, we emit the class declaration as a let declaration, and + // evaluate decorators after the close of the class body: + // + // [Example 1] + // --------------------------------------------------------------------- + // TypeScript | Javascript + // --------------------------------------------------------------------- + // @dec | let C = class C { + // class C { | } + // } | C = __decorate([dec], C); + // --------------------------------------------------------------------- + // @dec | let C = class C { + // export class C { | } + // } | C = __decorate([dec], C); + // | export { C }; + // --------------------------------------------------------------------- + // + // If a class declaration contains a reference to itself *inside* of the class body, + // this introduces two bindings to the class: One outside of the class body, and one + // inside of the class body. If we apply decorators as in [Example 1] above, there + // is the possibility that the decorator `dec` will return a new value for the + // constructor, which would result in the binding inside of the class no longer + // pointing to the same reference as the binding outside of the class. + // + // As a result, we must instead rewrite all references to the class *inside* of the + // class body to instead point to a local temporary alias for the class: + // + // [Example 2] + // --------------------------------------------------------------------- + // TypeScript | Javascript + // --------------------------------------------------------------------- + // @dec | let C_1; + // class C { | let C = C_1 = class C { + // static x() { return C.y; } | static x() { return C_1.y; } + // static y = 1; | } + // } | C.y = 1; + // | C = C_1 = __decorate([dec], C); + // --------------------------------------------------------------------- + // @dec | let C_1; + // export class C { | let C = C_1 = class C { + // static x() { return C.y; } | static x() { return C_1.y; } + // static y = 1; | } + // } | C.y = 1; + // | C = C_1 = __decorate([dec], C); + // | export { C }; + // --------------------------------------------------------------------- + // + // If a class declaration is the default export of a module, we instead emit + // the export after the decorated declaration: + // + // [Example 3] + // --------------------------------------------------------------------- + // TypeScript | Javascript + // --------------------------------------------------------------------- + // @dec | let default_1 = class { + // export default class { | } + // } | default_1 = __decorate([dec], default_1); + // | export default default_1; + // --------------------------------------------------------------------- + // @dec | let C = class C { + // export default class C { | } + // } | C = __decorate([dec], C); + // | export default C; + // --------------------------------------------------------------------- + // + // If the class declaration is the default export and a reference to itself + // inside of the class body, we must emit both an alias for the class *and* + // move the export after the declaration: + // + // [Example 4] + // --------------------------------------------------------------------- + // TypeScript | Javascript + // --------------------------------------------------------------------- + // @dec | let C_1; + // export default class C { | let C = C_1 = class C { + // static x() { return C.y; } | static x() { return C_1.y; } + // static y = 1; | } + // } | C.y = 1; + // | C = C_1 = __decorate([dec], C); + // | export default C; + // --------------------------------------------------------------------- + // + + // ... = class ${name} ${heritageClauses} { + // ${members} + // } + let classExpression: Expression = setOriginalNode( + createClassExpression( + name, + visitNodes(node.heritageClauses, visitor, isHeritageClause), + transformClassMembers(node, hasExtendsClause), + /*location*/ node + ), + node + ); + + // Record an alias to avoid class double-binding. + let decoratedClassAlias: Identifier; + if (resolver.getNodeCheckFlags(getOriginalNode(node)) & NodeCheckFlags.DecoratedClassWithSelfReference) { + enableExpressionSubstitutionForDecoratedClasses(); + decoratedClassAlias = createUniqueName(node.name && !isGeneratedIdentifier(node.name) ? node.name.text : "default"); + decoratedClassAliases[getOriginalNodeId(node)] = decoratedClassAlias; + + // We emit the class alias as a `let` declaration here so that it has the same + // TDZ as the class. + + // let ${decoratedClassAlias}; + addNode(statements, + createVariableStatement( + /*modifiers*/ undefined, + createVariableDeclarationList([ + createVariableDeclaration(decoratedClassAlias) + ], + /*location*/ undefined, + NodeFlags.Let) + ) + ); + + // ${decoratedClassAlias} = ${classExpression} + classExpression = createAssignment( + decoratedClassAlias, + classExpression, + /*location*/ node); + } + + // let ${name} = ${classExpression}; + addNode(statements, + createVariableStatement( + /*modifiers*/ undefined, + createVariableDeclarationList([ + createVariableDeclaration( + name, + classExpression + ) + ], + /*location*/ undefined, + NodeFlags.Let) + ) + ); + + return decoratedClassAlias; + } + /** * Transforms a class expression with TypeScript syntax into compatible ES6. * @@ -638,7 +686,7 @@ namespace ts { const members: ClassElement[] = []; addNode(members, transformConstructor(node, hasExtendsClause)); addNodes(members, visitNodes(node.members, classElementVisitor, isClassElement)); - return members; + return createNodeArray(members, /*location*/ node.members); } /** @@ -2489,9 +2537,15 @@ namespace ts { && (node.flags & NodeFlags.Default) !== 0; } + /** + * Gets a value indicating whether a node is the first declaration of its kind. + * + * @param node A Declaration node. + * @param kind The SyntaxKind to find among related declarations. + */ function isFirstDeclarationOfKind(node: Declaration, kind: SyntaxKind) { const original = getOriginalNode(node); - return !forEach(original.symbol && original.symbol.declarations, declaration => declaration.kind === kind && declaration.pos < original.pos); + return original.symbol && getDeclarationOfKind(original.symbol, kind) === original; } /** @@ -2511,7 +2565,7 @@ namespace ts { ); } - function createModuleExport(exportName: Identifier) { + function createExternalModuleExport(exportName: Identifier) { return createExportDeclaration( createNamedExports([ createExportSpecifier(exportName) @@ -2544,12 +2598,13 @@ namespace ts { previousOnBeforeEmitNode(node); const kind = node.kind; - if (hasEnabledExpressionSubstitutionForDecoratedClasses - && kind === SyntaxKind.ClassDeclaration && node.decorators) { + if (enabledSubstitutions & TypeScriptSubstitutionFlags.DecoratedClasses + && kind === SyntaxKind.ClassDeclaration + && node.decorators) { currentDecoratedClassAliases[getOriginalNodeId(node)] = decoratedClassAliases[getOriginalNodeId(node)]; } - if (hasEnabledExpressionSubstitutionForAsyncMethodsWithSuper + if (enabledSubstitutions & TypeScriptSubstitutionFlags.NamespaceExports && (kind === SyntaxKind.ClassDeclaration || kind === SyntaxKind.Constructor || kind === SyntaxKind.MethodDeclaration @@ -2563,7 +2618,7 @@ namespace ts { superContainerStack.push(node); } - if (hasEnabledExpressionSubstitutionForNamespaceExports + if (enabledSubstitutions & TypeScriptSubstitutionFlags.NamespaceExports && kind === SyntaxKind.ModuleDeclaration) { namespaceNestLevel++; } @@ -2573,12 +2628,13 @@ namespace ts { previousOnAfterEmitNode(node); const kind = node.kind; - if (hasEnabledExpressionSubstitutionForDecoratedClasses - && kind === SyntaxKind.ClassDeclaration && node.decorators) { + if (enabledSubstitutions & TypeScriptSubstitutionFlags.DecoratedClasses + && kind === SyntaxKind.ClassDeclaration + && node.decorators) { currentDecoratedClassAliases[getOriginalNodeId(node)] = undefined; } - if (hasEnabledExpressionSubstitutionForAsyncMethodsWithSuper + if (enabledSubstitutions & TypeScriptSubstitutionFlags.NamespaceExports && (kind === SyntaxKind.ClassDeclaration || kind === SyntaxKind.Constructor || kind === SyntaxKind.MethodDeclaration @@ -2590,7 +2646,7 @@ namespace ts { } } - if (hasEnabledExpressionSubstitutionForNamespaceExports + if (enabledSubstitutions & TypeScriptSubstitutionFlags.NamespaceExports && kind === SyntaxKind.ModuleDeclaration) { namespaceNestLevel--; } @@ -2604,7 +2660,7 @@ namespace ts { return substituteExpressionIdentifier(node); } - if (hasEnabledExpressionSubstitutionForAsyncMethodsWithSuper) { + if (enabledSubstitutions & TypeScriptSubstitutionFlags.NamespaceExports) { switch (node.kind) { case SyntaxKind.CallExpression: return substituteCallExpression(node); @@ -2619,9 +2675,9 @@ namespace ts { } function substituteExpressionIdentifier(node: Identifier): Expression { - if (hasEnabledExpressionSubstitutionForDecoratedClasses + if (enabledSubstitutions & TypeScriptSubstitutionFlags.DecoratedClasses && !nodeIsSynthesized(node) - && resolver.getNodeCheckFlags(node) & NodeCheckFlags.BodyScopedClassBinding) { + && resolver.getNodeCheckFlags(node) & NodeCheckFlags.SelfReferenceInDecoratedClass) { // Due to the emit for class decorators, any reference to the class from inside of the class body // must instead be rewritten to point to a temporary variable to avoid issues with the double-bind // behavior of class names in ES6. @@ -2635,7 +2691,7 @@ namespace ts { } } - if (hasEnabledExpressionSubstitutionForNamespaceExports + if (enabledSubstitutions & TypeScriptSubstitutionFlags.NamespaceExports && namespaceNestLevel > 0) { // If we are nested within a namespace declaration, we may need to qualifiy // an identifier that is exported from a merged namespace. @@ -2702,8 +2758,8 @@ namespace ts { } function enableExpressionSubstitutionForAsyncMethodsWithSuper() { - if (!hasEnabledExpressionSubstitutionForAsyncMethodsWithSuper) { - hasEnabledExpressionSubstitutionForAsyncMethodsWithSuper = true; + if ((enabledSubstitutions & TypeScriptSubstitutionFlags.NamespaceExports) === 0) { + enabledSubstitutions |= TypeScriptSubstitutionFlags.NamespaceExports; // We need to enable substitutions for call, property access, and element access // if we need to rewrite super calls. @@ -2721,8 +2777,8 @@ namespace ts { } function enableExpressionSubstitutionForDecoratedClasses() { - if (!hasEnabledExpressionSubstitutionForDecoratedClasses) { - hasEnabledExpressionSubstitutionForDecoratedClasses = true; + if ((enabledSubstitutions & TypeScriptSubstitutionFlags.DecoratedClasses) === 0) { + enabledSubstitutions |= TypeScriptSubstitutionFlags.DecoratedClasses; // We need to enable substitutions for identifiers. This allows us to // substitute class names inside of a class declaration. @@ -2735,8 +2791,8 @@ namespace ts { } function enableExpressionSubstitutionForNamespaceExports() { - if (!hasEnabledExpressionSubstitutionForNamespaceExports) { - hasEnabledExpressionSubstitutionForNamespaceExports = true; + if ((enabledSubstitutions & TypeScriptSubstitutionFlags.NamespaceExports) === 0) { + enabledSubstitutions |= TypeScriptSubstitutionFlags.NamespaceExports; // We need to enable substitutions for identifiers. This allows us to // substitute the names of exported members of a namespace. diff --git a/src/compiler/types.ts b/src/compiler/types.ts index 07d1daec669..5cced242498 100644 --- a/src/compiler/types.ts +++ b/src/compiler/types.ts @@ -2091,8 +2091,8 @@ namespace ts { CapturedBlockScopedBinding = 0x00020000, // Block-scoped binding that is captured in some function BlockScopedBindingInLoop = 0x00040000, // Block-scoped binding with declaration nested inside iteration statement HasSeenSuperCall = 0x00080000, // Set during the binding when encounter 'super' - ClassWithBodyScopedClassBinding = 0x00100000, // Decorated class that contains a binding to itself inside of the class body. - BodyScopedClassBinding = 0x00200000, // Binding to a decorated class inside of the class's body. + DecoratedClassWithSelfReference = 0x00100000, // Decorated class that contains a binding to itself inside of the class body. + SelfReferenceInDecoratedClass = 0x00200000, // Binding to a decorated class inside of the class's body. } /* @internal */ diff --git a/src/compiler/utilities.ts b/src/compiler/utilities.ts index 1b707cedc48..421737553d4 100644 --- a/src/compiler/utilities.ts +++ b/src/compiler/utilities.ts @@ -1352,7 +1352,7 @@ namespace ts { - export function isNodeDescendentOf(node: Node, ancestor: Node): boolean { + export function isNodeDescendantOf(node: Node, ancestor: Node): boolean { while (node) { if (node === ancestor) return true; node = node.parent; @@ -2866,7 +2866,8 @@ namespace ts { } export function isGeneratedIdentifier(node: Node): node is Identifier { - return isIdentifier(node) && node.autoGenerateKind > GeneratedIdentifierKind.Node; + // Using `>` here catches both `GeneratedIdentifierKind.None` and `undefined`. + return isIdentifier(node) && node.autoGenerateKind > GeneratedIdentifierKind.None; } // Keywords From 7d05ba28bf7979c94d4eac7b586ce7c13c6fdfef Mon Sep 17 00:00:00 2001 From: Ron Buckton Date: Tue, 1 Mar 2016 15:16:41 -0800 Subject: [PATCH 6/9] Fixed visitJsxText, plus PR Feedback --- src/compiler/core.ts | 92 ++++++++++- src/compiler/transformers/jsx.ts | 251 ++++++++++++++++--------------- src/compiler/utilities.ts | 4 + 3 files changed, 217 insertions(+), 130 deletions(-) diff --git a/src/compiler/core.ts b/src/compiler/core.ts index a464bd86682..15a8ce87eab 100644 --- a/src/compiler/core.ts +++ b/src/compiler/core.ts @@ -172,25 +172,101 @@ namespace ts { } /** - * Maps an array. If the mapped value is an array, it is spread into the result. + * Flattens an array containing a mix of array or non-array elements. + * + * @param array The array to flatten. */ - export function flatMap(array: T[], f: (x: T, i: number) => U | U[]): U[] { + export function flatten(array: (T | T[])[]): T[] { + let result: T[]; + if (array) { + result = []; + for (const v of array) { + if (v) { + if (isArray(v)) { + addRange(result, v); + } + else { + result.push(v); + } + } + } + } + + return result; + } + + /** + * Maps an array. If the mapped value is an array, it is spread into the result. + * + * @param array The array to map. + * @param mapfn The callback used to map the result into one or more values. + */ + export function flatMap(array: T[], mapfn: (x: T, i: number) => U | U[]): U[] { let result: U[]; if (array) { result = []; for (let i = 0; i < array.length; i++) { - const v = array[i]; - const ar = f(v, i); - if (ar) { - // We cast to here to leverage the behavior of Array#concat - // which will append a single value here. - result = result.concat(ar); + const v = mapfn(array[i], i); + if (v) { + if (isArray(v)) { + addRange(result, v); + } + else { + result.push(v); + } } } } return result; } + /** + * Maps contiguous spans of values with the same key. + * + * @param array The array to map. + * @param keyfn A callback used to select the key for an element. + * @param mapfn A callback used to map a contiguous chunk of values to a single value. + */ + export function spanMap(array: T[], keyfn: (x: T, i: number) => K, mapfn: (chunk: T[], key: K) => U): U[] { + let result: U[]; + if (array) { + result = []; + const len = array.length; + let previousKey: K; + let key: K; + let start = 0; + let pos = 0; + while (start < len) { + while (pos < len) { + const value = array[pos]; + key = keyfn(value, pos); + if (pos === 0) { + previousKey = key; + } + else if (key !== previousKey) { + break; + } + + pos++; + } + + if (start < pos) { + const v = mapfn(array.slice(start, pos), previousKey); + if (v) { + result.push(v); + } + + start = pos; + } + + previousKey = key; + pos++; + } + } + + return result; + } + export function concatenate(array1: T[], array2: T[]): T[] { if (!array2 || !array2.length) return array1; if (!array1 || !array1.length) return array2; diff --git a/src/compiler/transformers/jsx.ts b/src/compiler/transformers/jsx.ts index cb1aef32a97..924cfbfdb90 100644 --- a/src/compiler/transformers/jsx.ts +++ b/src/compiler/transformers/jsx.ts @@ -9,6 +9,11 @@ namespace ts { const compilerOptions = context.getCompilerOptions(); return transformSourceFile; + /** + * Transform JSX-specific syntax in a SourceFile. + * + * @param node A SourceFile node. + */ function transformSourceFile(node: SourceFile) { return visitEachChild(node, visitor, context); } @@ -64,7 +69,6 @@ namespace ts { } function visitJsxOpeningLikeElement(node: JsxOpeningLikeElement, children: JsxChild[]) { - // We must the node onto the node stack if it is not already at the top. const tagName = getTagName(node); let objectProperties: Expression; if (node.attributes.length === 0) { @@ -75,41 +79,35 @@ namespace ts { // Either emit one big object literal (no spread attribs), or // a call to React.__spread const attrs = node.attributes; - if (forEach(attrs, isJsxSpreadAttribute)) { - const segments: Expression[] = []; - let properties: ObjectLiteralElement[] = []; - for (const attr of attrs) { - if (isJsxSpreadAttribute(attr)) { - if (properties) { - segments.push(createObjectLiteral(properties)); - properties = undefined; - } - - addNode(segments, transformJsxSpreadAttributeToExpression(attr)); - } - else { - if (!properties) { - properties = []; - } - - addNode(properties, transformJsxAttributeToObjectLiteralElement(attr)); - } - } - - if (properties) { - segments.push(createObjectLiteral(properties)); - } - - objectProperties = createJsxSpread(compilerOptions.reactNamespace, segments); + if (!forEach(attrs, isJsxSpreadAttribute)) { + objectProperties = createObjectLiteral(map(node.attributes, transformJsxAttributeToObjectLiteralElement)); } else { - const properties = map(node.attributes, transformJsxAttributeToObjectLiteralElement); - objectProperties = createObjectLiteral(properties); + objectProperties = createJsxSpread(compilerOptions.reactNamespace, + concatenate( + // We must always emit at least one object literal before a spread + // argument. + isJsxSpreadAttribute(attrs[0]) ? [createObjectLiteral()] : undefined, + + // Map spans of JsxAttribute nodes into object literals and spans + // of JsxSpreadAttribute nodes into expressions. + flatten( + spanMap(attrs, isJsxSpreadAttribute, (attrs, isSpread) => isSpread + ? map(attrs, transformJsxSpreadAttributeToExpression) + : createObjectLiteral(map(attrs, transformJsxAttributeToObjectLiteralElement)) + ) + ) + ) + ); } } - const childExpressions = filter(map(children, transformJsxChildToExpression), isDefined); - return createJsxCreateElement(compilerOptions.reactNamespace, tagName, objectProperties, childExpressions); + return createJsxCreateElement( + compilerOptions.reactNamespace, + tagName, + objectProperties, + filter(map(children, transformJsxChildToExpression), isDefined) + ); } function transformJsxSpreadAttributeToExpression(node: JsxSpreadAttribute) { @@ -125,39 +123,29 @@ namespace ts { } function visitJsxText(node: JsxText) { - const text = getTextToEmit(node); - if (text !== undefined) { - return createLiteral(text); - } - return undefined; - } - - function getTextToEmit(node: JsxText) { - const text = trimReactWhitespaceAndApplyEntities(node); - if (text === undefined || text.length === 0) { - return undefined; - } - else { - return text; - } - } - - function trimReactWhitespaceAndApplyEntities(node: JsxText): string { const text = getTextOfNode(node, /*includeTrivia*/ true); - let result: string = undefined; + let parts: Expression[]; let firstNonWhitespace = 0; let lastNonWhitespace = -1; // JSX trims whitespace at the end and beginning of lines, except that the // start/end of a tag is considered a start/end of a line only if that line is - // on the same line as the closing tag. See examples in tests/cases/conformance/jsx/tsxReactEmitWhitespace.tsx + // on the same line as the closing tag. See examples in + // tests/cases/conformance/jsx/tsxReactEmitWhitespace.tsx for (let i = 0; i < text.length; i++) { const c = text.charCodeAt(i); if (isLineBreak(c)) { if (firstNonWhitespace !== -1 && (lastNonWhitespace - firstNonWhitespace + 1 > 0)) { const part = text.substr(firstNonWhitespace, lastNonWhitespace - firstNonWhitespace + 1); - result = (result ? result + "\" + ' ' + \"" : "") + part; + if (!parts) { + parts = []; + } + + // We do not escape the string here as that is handled by the printer + // when it emits the literal. We do, however, need to decode JSX entities. + parts.push(createLiteral(decodeEntities(part))); } + firstNonWhitespace = -1; } else if (!isWhiteSpace(c)) { @@ -170,22 +158,41 @@ namespace ts { if (firstNonWhitespace !== -1) { const part = text.substr(firstNonWhitespace); - result = (result ? result + "\" + ' ' + \"" : "") + part; + if (!parts) { + parts = []; + } + + // We do not escape the string here as that is handled by the printer + // when it emits the literal. We do, however, need to decode JSX entities. + parts.push(createLiteral(decodeEntities(part))); } - if (result) { - // Replace entities like   - result = result.replace(/&(\w+);/g, function(s: any, m: string) { - if (entities[m] !== undefined) { - return String.fromCharCode(entities[m]); - } - else { - return s; - } - }); + if (parts) { + return reduceLeft(parts, aggregateJsxTextParts); } - return result; + return undefined; + } + + /** + * Aggregates two expressions by interpolating them with a whitespace literal. + */ + function aggregateJsxTextParts(left: Expression, right: Expression) { + return createAdd(createAdd(left, createLiteral(" ")), right); + } + + /** + * Decodes JSX entities. + */ + function decodeEntities(text: string) { + return text.replace(/&(\w+);/g, function(s: any, m: string) { + if (entities[m] !== undefined) { + return String.fromCharCode(entities[m]); + } + else { + return s; + } + }); } function getTagName(node: JsxElement | JsxOpeningLikeElement): Expression { @@ -210,7 +217,7 @@ namespace ts { */ function getAttributeName(node: JsxAttribute): StringLiteral | Identifier { const name = node.name; - if (/[A-Za-z_]+[\w*]/.test(name.text)) { + if (/^[A-Za-z_]\w*$/.test(name.text)) { return createLiteral(name.text); } else { @@ -422,62 +429,62 @@ namespace ts { "uarr": 0x2191, "rarr": 0x2192, "darr": 0x2193, - "harr": 0x2194, - "crarr": 0x21B5, - "lArr": 0x21D0, - "uArr": 0x21D1, - "rArr": 0x21D2, - "dArr": 0x21D3, - "hArr": 0x21D4, - "forall": 0x2200, - "part": 0x2202, - "exist": 0x2203, - "empty": 0x2205, - "nabla": 0x2207, - "isin": 0x2208, - "notin": 0x2209, - "ni": 0x220B, - "prod": 0x220F, - "sum": 0x2211, - "minus": 0x2212, - "lowast": 0x2217, - "radic": 0x221A, - "prop": 0x221D, - "infin": 0x221E, - "ang": 0x2220, - "and": 0x2227, - "or": 0x2228, - "cap": 0x2229, - "cup": 0x222A, - "int": 0x222B, - "there4": 0x2234, - "sim": 0x223C, - "cong": 0x2245, - "asymp": 0x2248, - "ne": 0x2260, - "equiv": 0x2261, - "le": 0x2264, - "ge": 0x2265, - "sub": 0x2282, - "sup": 0x2283, - "nsub": 0x2284, - "sube": 0x2286, - "supe": 0x2287, - "oplus": 0x2295, - "otimes": 0x2297, - "perp": 0x22A5, - "sdot": 0x22C5, - "lceil": 0x2308, - "rceil": 0x2309, - "lfloor": 0x230A, - "rfloor": 0x230B, - "lang": 0x2329, - "rang": 0x232A, - "loz": 0x25CA, - "spades": 0x2660, - "clubs": 0x2663, - "hearts": 0x2665, - "diams": 0x2666 - }; + "harr": 0x2194, + "crarr": 0x21B5, + "lArr": 0x21D0, + "uArr": 0x21D1, + "rArr": 0x21D2, + "dArr": 0x21D3, + "hArr": 0x21D4, + "forall": 0x2200, + "part": 0x2202, + "exist": 0x2203, + "empty": 0x2205, + "nabla": 0x2207, + "isin": 0x2208, + "notin": 0x2209, + "ni": 0x220B, + "prod": 0x220F, + "sum": 0x2211, + "minus": 0x2212, + "lowast": 0x2217, + "radic": 0x221A, + "prop": 0x221D, + "infin": 0x221E, + "ang": 0x2220, + "and": 0x2227, + "or": 0x2228, + "cap": 0x2229, + "cup": 0x222A, + "int": 0x222B, + "there4": 0x2234, + "sim": 0x223C, + "cong": 0x2245, + "asymp": 0x2248, + "ne": 0x2260, + "equiv": 0x2261, + "le": 0x2264, + "ge": 0x2265, + "sub": 0x2282, + "sup": 0x2283, + "nsub": 0x2284, + "sube": 0x2286, + "supe": 0x2287, + "oplus": 0x2295, + "otimes": 0x2297, + "perp": 0x22A5, + "sdot": 0x22C5, + "lceil": 0x2308, + "rceil": 0x2309, + "lfloor": 0x230A, + "rfloor": 0x230B, + "lang": 0x2329, + "rang": 0x232A, + "loz": 0x25CA, + "spades": 0x2660, + "clubs": 0x2663, + "hearts": 0x2665, + "diams": 0x2666 + }; } } \ No newline at end of file diff --git a/src/compiler/utilities.ts b/src/compiler/utilities.ts index 421737553d4..80cd6c7f8ad 100644 --- a/src/compiler/utilities.ts +++ b/src/compiler/utilities.ts @@ -3268,6 +3268,10 @@ namespace ts { return node.kind === SyntaxKind.JsxSpreadAttribute; } + export function isJsxAttribute(node: Node): node is JsxAttribute { + return node.kind === SyntaxKind.JsxAttribute; + } + // Clauses export function isCaseOrDefaultClause(node: Node): node is CaseOrDefaultClause { From 186f5c8bca792659aabc69c21d9253a6c18256f3 Mon Sep 17 00:00:00 2001 From: Ron Buckton Date: Tue, 1 Mar 2016 15:26:29 -0800 Subject: [PATCH 7/9] PR Feedback --- src/compiler/transformers/jsx.ts | 42 +++++++++++++++----------------- 1 file changed, 19 insertions(+), 23 deletions(-) diff --git a/src/compiler/transformers/jsx.ts b/src/compiler/transformers/jsx.ts index 924cfbfdb90..c5085da5295 100644 --- a/src/compiler/transformers/jsx.ts +++ b/src/compiler/transformers/jsx.ts @@ -71,35 +71,31 @@ namespace ts { function visitJsxOpeningLikeElement(node: JsxOpeningLikeElement, children: JsxChild[]) { const tagName = getTagName(node); let objectProperties: Expression; - if (node.attributes.length === 0) { + const attrs = node.attributes; + if (attrs.length === 0) { // When there are no attributes, React wants "null" objectProperties = createNull(); } else { + // Map spans of JsxAttribute nodes into object literals and spans + // of JsxSpreadAttribute nodes into expressions. + const segments = flatten( + spanMap(attrs, isJsxSpreadAttribute, (attrs, isSpread) => isSpread + ? map(attrs, transformJsxSpreadAttributeToExpression) + : createObjectLiteral(map(attrs, transformJsxAttributeToObjectLiteralElement)) + ) + ); + + if (isJsxSpreadAttribute(attrs[0])) { + // We must always emit at least one object literal before a spread + // argument. + segments.unshift(createObjectLiteral()); + } + // Either emit one big object literal (no spread attribs), or // a call to React.__spread - const attrs = node.attributes; - if (!forEach(attrs, isJsxSpreadAttribute)) { - objectProperties = createObjectLiteral(map(node.attributes, transformJsxAttributeToObjectLiteralElement)); - } - else { - objectProperties = createJsxSpread(compilerOptions.reactNamespace, - concatenate( - // We must always emit at least one object literal before a spread - // argument. - isJsxSpreadAttribute(attrs[0]) ? [createObjectLiteral()] : undefined, - - // Map spans of JsxAttribute nodes into object literals and spans - // of JsxSpreadAttribute nodes into expressions. - flatten( - spanMap(attrs, isJsxSpreadAttribute, (attrs, isSpread) => isSpread - ? map(attrs, transformJsxSpreadAttributeToExpression) - : createObjectLiteral(map(attrs, transformJsxAttributeToObjectLiteralElement)) - ) - ) - ) - ); - } + objectProperties = singleOrUndefined(segments) + || createJsxSpread(compilerOptions.reactNamespace, segments); } return createJsxCreateElement( From 30433c2c67cf8073b087e8ac90e36d1cf3a61c6b Mon Sep 17 00:00:00 2001 From: Ron Buckton Date: Wed, 2 Mar 2016 11:38:30 -0800 Subject: [PATCH 8/9] ES6 cleanup --- src/compiler/binder.ts | 21 +- src/compiler/checker.ts | 2 +- src/compiler/core.ts | 17 + src/compiler/emitter.ts | 2 +- src/compiler/factory.ts | 111 ++- src/compiler/transformers/es6.ts | 1349 ++++++++++++++++++++---------- src/compiler/transformers/ts.ts | 7 +- src/compiler/types.ts | 21 +- src/compiler/utilities.ts | 26 +- src/compiler/visitor.ts | 4 +- 10 files changed, 1053 insertions(+), 507 deletions(-) diff --git a/src/compiler/binder.ts b/src/compiler/binder.ts index 4ea2489de88..f1b6e0053bf 100644 --- a/src/compiler/binder.ts +++ b/src/compiler/binder.ts @@ -1930,7 +1930,8 @@ namespace ts { case SyntaxKind.CallExpression: excludeFlags = TransformFlags.ArrayLiteralOrCallOrNewExcludes; if (subtreeFlags & TransformFlags.ContainsSpreadElementExpression - || isSuperCall(node)) { + || isSuperCall(node) + || isSuperPropertyCall(node)) { // If the this node contains a SpreadElementExpression, or is a super call, then it is an ES6 // node. transformFlags |= TransformFlags.AssertES6; @@ -1969,12 +1970,18 @@ namespace ts { } } + // If the expression of a ParenthesizedExpression is a destructuring assignment, + // then the ParenthesizedExpression is a destructuring assignment. + if ((node).expression.transformFlags & TransformFlags.DestructuringAssignment) { + transformFlags |= TransformFlags.DestructuringAssignment; + } + break; case SyntaxKind.BinaryExpression: if (isDestructuringAssignment(node)) { // Destructuring assignments are ES6 syntax. - transformFlags |= TransformFlags.AssertES6; + transformFlags |= TransformFlags.AssertES6 | TransformFlags.DestructuringAssignment; } else if ((node).operatorToken.kind === SyntaxKind.AsteriskAsteriskToken || (node).operatorToken.kind === SyntaxKind.AsteriskAsteriskEqualsToken) { @@ -1984,6 +1991,16 @@ namespace ts { break; + case SyntaxKind.ExpressionStatement: + // If the expression of an expression statement is a destructuring assignment, + // then we treat the statement as ES6 so that we can indicate that we do not + // need to hold on to the right-hand side. + if ((node).expression.transformFlags & TransformFlags.DestructuringAssignment) { + transformFlags |= TransformFlags.AssertES6; + } + + break; + case SyntaxKind.Parameter: // If the parameter has a question token, then it is TypeScript syntax. if ((node).questionToken) { diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index b7a1bd0b05d..cf90007062e 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -7495,7 +7495,7 @@ namespace ts { // This is required for destructuring assignments, as a call expression cannot be used as the target of a destructuring assignment // while a property access can. if (container.kind === SyntaxKind.MethodDeclaration && container.flags & NodeFlags.Async) { - if (isSuperPropertyOrElementAccess(node.parent) && isAssignmentTarget(node.parent)) { + if (isSuperProperty(node.parent) && isAssignmentTarget(node.parent)) { getNodeLinks(container).flags |= NodeCheckFlags.AsyncMethodWithSuperBinding; } else { diff --git a/src/compiler/core.ts b/src/compiler/core.ts index 15a8ce87eab..aeb908c20cc 100644 --- a/src/compiler/core.ts +++ b/src/compiler/core.ts @@ -220,6 +220,23 @@ namespace ts { return result; } + /** + * Computes the first matching span of elements and returns a tuple of the first span + * and the remaining elements. + */ + export function span(array: T[], f: (x: T, i: number) => boolean): [T[], T[]] { + if (array) { + for (let i = 0; i < array.length; i++) { + if (!f(array[i], i)) { + return [array.slice(0, i), array.slice(i)]; + } + } + return [array.slice(0), []]; + } + + return undefined; + } + /** * Maps contiguous spans of values with the same key. * diff --git a/src/compiler/emitter.ts b/src/compiler/emitter.ts index bda2bd79506..d279c419b53 100644 --- a/src/compiler/emitter.ts +++ b/src/compiler/emitter.ts @@ -2339,7 +2339,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge superCall = true; } else { - superCall = isSuperPropertyOrElementAccess(expression); + superCall = isSuperProperty(expression); isAsyncMethodWithSuper = superCall && isInAsyncMethodWithSuperInES6(node); emit(expression); } diff --git a/src/compiler/factory.ts b/src/compiler/factory.ts index ee886fa334e..c4813ab13c4 100644 --- a/src/compiler/factory.ts +++ b/src/compiler/factory.ts @@ -152,7 +152,7 @@ namespace ts { /** * Creates a shallow, memberwise clone of a node for mutation. */ - export function getMutableNode(node: T): T { + export function getMutableClone(node: T): T { return cloneNode(node, /*location*/ node, node.flags, /*parent*/ undefined, /*original*/ node); } @@ -320,15 +320,21 @@ namespace ts { // Expression - export function createArrayLiteral(elements?: Expression[]) { - const node = createNode(SyntaxKind.ArrayLiteralExpression); + export function createArrayLiteral(elements?: Expression[], location?: TextRange, multiLine?: boolean) { + const node = createNode(SyntaxKind.ArrayLiteralExpression, location); node.elements = parenthesizeListElements(createNodeArray(elements)); + if (multiLine) { + node.multiLine = multiLine; + } return node; } - export function createObjectLiteral(properties?: ObjectLiteralElement[], location?: TextRange) { + export function createObjectLiteral(properties?: ObjectLiteralElement[], location?: TextRange, multiLine?: boolean) { const node = createNode(SyntaxKind.ObjectLiteralExpression, location); node.properties = createNodeArray(properties); + if (multiLine) { + node.multiLine = multiLine; + } return node; } @@ -356,7 +362,7 @@ namespace ts { export function createNew(expression: Expression, argumentsArray: Expression[], location?: TextRange) { const node = createNode(SyntaxKind.NewExpression, location); - node.expression = parenthesizeForAccess(expression); + node.expression = parenthesizeForNew(expression); node.arguments = argumentsArray ? parenthesizeListElements(createNodeArray(argumentsArray)) : undefined; @@ -369,7 +375,7 @@ namespace ts { return node; } - export function createFunctionExpression(asteriskToken: Node, name: string | Identifier, parameters: ParameterDeclaration[], body: Block, location?: TextRange) { + export function createFunctionExpression(asteriskToken: Node, name: string | Identifier, parameters: ParameterDeclaration[], body: Block, location?: TextRange, original?: Node) { const node = createNode(SyntaxKind.FunctionExpression, location); node.modifiers = undefined; node.asteriskToken = asteriskToken; @@ -378,6 +384,10 @@ namespace ts { node.parameters = createNodeArray(parameters); node.type = undefined; node.body = body; + if (original) { + node.original = original; + } + return node; } @@ -468,9 +478,12 @@ namespace ts { // Element - export function createBlock(statements: Statement[], location?: TextRange): Block { + export function createBlock(statements: Statement[], location?: TextRange, multiLine?: boolean): Block { const block = createNode(SyntaxKind.Block, location); block.statements = createNodeArray(statements); + if (multiLine) { + block.multiLine = true; + } return block; } @@ -573,7 +586,7 @@ namespace ts { return node; } - export function createFunctionDeclaration(modifiers: Modifier[], asteriskToken: Node, name: string | Identifier, parameters: ParameterDeclaration[], body: Block, location?: TextRange) { + export function createFunctionDeclaration(modifiers: Modifier[], asteriskToken: Node, name: string | Identifier, parameters: ParameterDeclaration[], body: Block, location?: TextRange, original?: Node) { const node = createNode(SyntaxKind.FunctionDeclaration, location); node.decorators = undefined; setModifiers(node, modifiers); @@ -583,6 +596,9 @@ namespace ts { node.parameters = createNodeArray(parameters); node.type = undefined; node.body = body; + if (original) { + node.original = original; + } return node; } @@ -1068,6 +1084,68 @@ namespace ts { ); } + export interface CallBinding { + target: LeftHandSideExpression; + thisArg: Expression; + } + + export function createCallBinding(expression: Expression, languageVersion?: ScriptTarget): CallBinding { + const callee = skipParentheses(expression); + let thisArg: Expression; + let target: LeftHandSideExpression; + if (isSuperProperty(callee)) { + thisArg = createThis(/*location*/ callee.expression); + target = callee; + } + else if (isSuperCall(callee)) { + thisArg = createThis(/*location*/ callee); + target = languageVersion < ScriptTarget.ES6 ? createIdentifier("_super", /*location*/ callee) : callee; + } + else { + switch (callee.kind) { + case SyntaxKind.PropertyAccessExpression: { + // for `a.b()` target is `(_a = a).b` and thisArg is `_a` + thisArg = createTempVariable(); + target = createPropertyAccess( + createAssignment( + thisArg, + (callee).expression, + /*location*/ (callee).expression + ), + (callee).name, + /*location*/ callee + ); + break; + } + + case SyntaxKind.ElementAccessExpression: { + // for `a[b]()` target is `(_a = a)[b]` and thisArg is `_a` + thisArg = createTempVariable(); + target = createElementAccess( + createAssignment( + thisArg, + (callee).expression, + /*location*/ (callee).expression + ), + (callee).argumentExpression, + /*location*/ callee + ); + + break; + } + + default: { + // for `a()` target is `a` and thisArg is `void 0` + thisArg = createVoidZero(); + target = parenthesizeForAccess(expression); + break; + } + } + } + + return { target, thisArg }; + } + export function inlineExpressions(expressions: Expression[]) { return reduceLeft(expressions, createComma); } @@ -1206,6 +1284,23 @@ namespace ts { || binaryOperator === SyntaxKind.CaretToken; } + /** + * Wraps an expression in parentheses if it is needed in order to use the expression + * as the expression of a NewExpression node. + * + * @param expression The Expression node. + */ + export function parenthesizeForNew(expression: Expression): LeftHandSideExpression { + const lhs = parenthesizeForAccess(expression); + switch (lhs.kind) { + case SyntaxKind.CallExpression: + case SyntaxKind.NewExpression: + return createParen(lhs); + } + + return lhs; + } + /** * Wraps an expression in parentheses if it is needed in order to use the expression for * property or element access. diff --git a/src/compiler/transformers/es6.ts b/src/compiler/transformers/es6.ts index 73282e92ec3..4db823266c9 100644 --- a/src/compiler/transformers/es6.ts +++ b/src/compiler/transformers/es6.ts @@ -3,14 +3,20 @@ /*@internal*/ namespace ts { + + const enum ES6SubstitutionFlags { + /** Enables substitutions for captured `this` */ + CapturedThis = 1 << 0, + /** Enables substitutions for block-scoped bindings. */ + BlockScopedBindings = 1 << 1, + } + export function transformES6(context: TransformationContext) { const { startLexicalEnvironment, endLexicalEnvironment, hoistVariableDeclaration, setNodeEmitFlags, - enableExpressionSubstitution, - enableEmitNotification, } = context; const resolver = context.getEmitResolver(); @@ -18,24 +24,43 @@ namespace ts { const previousExpressionSubstitution = context.expressionSubstitution; const previousOnBeforeEmitNode = context.onBeforeEmitNode; const previousOnAfterEmitNode = context.onAfterEmitNode; - context.enableExpressionSubstitution(SyntaxKind.Identifier); - context.identifierSubstitution = substituteIdentifier; - context.expressionSubstitution = substituteExpression; context.onBeforeEmitNode = onBeforeEmitNode; context.onAfterEmitNode = onAfterEmitNode; + context.identifierSubstitution = substituteIdentifier; + context.expressionSubstitution = substituteExpression; let currentSourceFile: SourceFile; let currentParent: Node; let currentNode: Node; let enclosingBlockScopeContainer: Node; let enclosingBlockScopeContainerParent: Node; - let containingFunction: FunctionLikeDeclaration; let containingNonArrowFunction: FunctionLikeDeclaration; - let combinedNodeFlags: NodeFlags; - // This stack is is used to support substitutions when printing nodes. - let hasEnabledExpressionSubstitutionForCapturedThis = false; - let containingFunctionStack: FunctionLikeDeclaration[]; + /** + * Keeps track of whether substitutions have been enabled for specific cases. + * They are persisted between each SourceFile transformation and should not + * be reset. + */ + let enabledSubstitutions: ES6SubstitutionFlags; + + /** + * Keeps track of how deeply nested we are within function-likes when printing + * nodes. This is used to determine whether we need to emit `_this` instead of + * `this`. + */ + let containingFunctionDepth: number; + + /** + * The first 31 bits are used to determine whether a containing function is an + * arrow function. + */ + let containingFunctionState: number; + + /** + * If the containingFunctionDepth grows beyond 31 nested function-likes, this + * array is used as a stack to track deeper levels of nesting. + */ + let containingFunctionStack: number[]; return transformSourceFile; @@ -45,24 +70,20 @@ namespace ts { } function visitor(node: Node): Node { - const savedContainingFunction = containingFunction; const savedContainingNonArrowFunction = containingNonArrowFunction; const savedCurrentParent = currentParent; const savedCurrentNode = currentNode; const savedEnclosingBlockScopeContainer = enclosingBlockScopeContainer; const savedEnclosingBlockScopeContainerParent = enclosingBlockScopeContainerParent; - const savedCombinedNodeFlags = combinedNodeFlags; onBeforeVisitNode(node); node = visitorWorker(node); - containingFunction = savedContainingFunction; containingNonArrowFunction = savedContainingNonArrowFunction; currentParent = savedCurrentParent; currentNode = savedCurrentNode; enclosingBlockScopeContainer = savedEnclosingBlockScopeContainer; enclosingBlockScopeContainerParent = savedEnclosingBlockScopeContainerParent; - combinedNodeFlags = savedCombinedNodeFlags; return node; } @@ -122,6 +143,9 @@ namespace ts { case SyntaxKind.ForOfStatement: return visitForOfStatement(node); + case SyntaxKind.ExpressionStatement: + return visitExpressionStatement(node); + case SyntaxKind.ObjectLiteralExpression: return visitObjectLiteralExpression(node); @@ -137,8 +161,11 @@ namespace ts { case SyntaxKind.NewExpression: return visitNewExpression(node); + case SyntaxKind.ParenthesizedExpression: + return visitParenthesizedExpression(node, /*needsDestructuringValue*/ true); + case SyntaxKind.BinaryExpression: - return visitBinaryExpression(node); + return visitBinaryExpression(node, /*needsDestructuringValue*/ true); case SyntaxKind.NoSubstitutionTemplateLiteral: case SyntaxKind.TemplateHead: @@ -170,8 +197,6 @@ namespace ts { currentParent = currentNode; currentNode = node; - combinedNodeFlags = combineNodeFlags(currentNode, currentParent, combinedNodeFlags); - if (currentParent) { if (isBlockScope(currentParent, currentGrandparent)) { enclosingBlockScopeContainer = currentParent; @@ -186,17 +211,27 @@ namespace ts { case SyntaxKind.FunctionDeclaration: case SyntaxKind.FunctionExpression: containingNonArrowFunction = currentParent; - containingFunction = currentParent; - break; - - case SyntaxKind.ArrowFunction: - containingFunction = currentParent; break; } } } + /** + * Visits a ClassDeclaration and transforms it into a variable statement. + * + * @parma node A ClassDeclaration node. + */ function visitClassDeclaration(node: ClassDeclaration): Statement { + // [source] + // class C { } + // + // [output] + // var C = (function () { + // function C() { + // } + // return C; + // }()); + return startOnNewLine( createVariableStatement( /*modifiers*/ undefined, @@ -211,11 +246,54 @@ namespace ts { ); } + /** + * Visits a ClassExpression and transforms it into an expression. + * + * @param node A ClassExpression node. + */ function visitClassExpression(node: ClassExpression): Expression { + // [source] + // C = class { } + // + // [output] + // C = (function () { + // function class_1() { + // } + // return class_1; + // }()) + return transformClassLikeDeclarationToExpression(node); } + /** + * Transforms a ClassExpression or ClassDeclaration into an expression. + * + * @param node A ClassExpression or ClassDeclaration node. + */ function transformClassLikeDeclarationToExpression(node: ClassExpression | ClassDeclaration): Expression { + // [source] + // class C extends D { + // constructor() {} + // method() {} + // get prop() {} + // set prop(v) {} + // } + // + // [output] + // (function (_super) { + // __extends(C, _super); + // function C() { + // } + // C.prototype.method = function () {} + // Object.defineProperty(C.prototype, "prop", { + // get: function() {}, + // set: function() {}, + // enumerable: true, + // configurable: true + // }); + // return C; + // }(D)) + const baseTypeNode = getClassExtendsHeritageClauseElement(node); return createParen( createCall( @@ -225,25 +303,40 @@ namespace ts { baseTypeNode ? [createParameter("_super")] : [], transformClassBody(node, baseTypeNode !== undefined) ), - baseTypeNode ? [visitNode(baseTypeNode.expression, visitor, isExpression)] : [] + baseTypeNode + ? [visitNode(baseTypeNode.expression, visitor, isExpression)] + : [] ) ); } + /** + * Transforms a ClassExpression or ClassDeclaration into a function body. + * + * @param node A ClassExpression or ClassDeclaration node. + * @param hasExtendsClause A value indicating whether the class has an `extends` clause. + */ function transformClassBody(node: ClassExpression | ClassDeclaration, hasExtendsClause: boolean): Block { const statements: Statement[] = []; startLexicalEnvironment(); addExtendsHelperIfNeeded(statements, node, hasExtendsClause); addConstructor(statements, node, hasExtendsClause); addClassMembers(statements, node); - addNode(statements, createReturn(getDeclarationName(node))); - addNodes(statements, endLexicalEnvironment()); - return setMultiLine(createBlock(statements), /*multiLine*/ true); + statements.push(createReturn(getDeclarationName(node))); + addRange(statements, endLexicalEnvironment()); + return createBlock(statements, /*location*/ undefined, /*multiLine*/ true); } - function addExtendsHelperIfNeeded(classStatements: Statement[], node: ClassExpression | ClassDeclaration, hasExtendsClause: boolean): void { + /** + * Adds a call to the `__extends` helper if needed for a class. + * + * @param statements The statements of the class body function. + * @param node The ClassExpression or ClassDeclaration node. + * @param hasExtendsClause A value indicating whether the class has an `extends` clause. + */ + function addExtendsHelperIfNeeded(statements: Statement[], node: ClassExpression | ClassDeclaration, hasExtendsClause: boolean): void { if (hasExtendsClause) { - addNode(classStatements, + statements.push( createStatement( createExtendsHelper(getDeclarationName(node)) ) @@ -251,10 +344,17 @@ namespace ts { } } - function addConstructor(classStatements: Statement[], node: ClassExpression | ClassDeclaration, hasExtendsClause: boolean): void { + /** + * Adds the constructor of the class to a class body function. + * + * @param statements The statements of the class body function. + * @param node The ClassExpression or ClassDeclaration node. + * @param hasExtendsClause A value indicating whether the class has an `extends` clause. + */ + function addConstructor(statements: Statement[], node: ClassExpression | ClassDeclaration, hasExtendsClause: boolean): void { const constructor = getFirstConstructorWithBody(node); const hasSynthesizedSuper = hasSynthesizedDefaultSuperCall(constructor, hasExtendsClause); - addNode(classStatements, + statements.push( createFunctionDeclaration( /*modifiers*/ undefined, /*asteriskToken*/ undefined, @@ -266,7 +366,19 @@ namespace ts { ); } + /** + * Transforms the parameters of the constructor declaration of a class. + * + * @param constructor The constructor for the class. + * @param hasSynthesizedSuper A value indicating whether the constructor starts with a + * synthesized `super` call. + */ function transformConstructorParameters(constructor: ConstructorDeclaration, hasSynthesizedSuper: boolean): ParameterDeclaration[] { + // If the TypeScript transformer needed to synthesize a constructor for property + // initializers, it would have also added a synthetic `...args` parameter and + // `super` call. + // If this is the case, we do not include the synthetic `...args` parameter and + // will instead use the `arguments` object in ES5/3. if (constructor && !hasSynthesizedSuper) { return visitNodes(constructor.parameters, visitor, isParameter); } @@ -274,28 +386,50 @@ namespace ts { return []; } + /** + * Transforms the body of a constructor declaration of a class. + * + * @param constructor The constructor for the class. + * @param hasExtendsClause A value indicating whether the class has an `extends` clause. + * @param hasSynthesizedSuper A value indicating whether the constructor starts with a + * synthesized `super` call. + */ function transformConstructorBody(constructor: ConstructorDeclaration, hasExtendsClause: boolean, hasSynthesizedSuper: boolean) { const statements: Statement[] = []; startLexicalEnvironment(); if (constructor) { addCaptureThisForNodeIfNeeded(statements, constructor); - addDefaultValueAssignments(statements, constructor); - addRestParameter(statements, constructor, hasSynthesizedSuper); + addDefaultValueAssignmentsIfNeeded(statements, constructor); + addRestParameterIfNeeded(statements, constructor, hasSynthesizedSuper); } - addDefaultSuperCall(statements, constructor, hasExtendsClause, hasSynthesizedSuper); + addDefaultSuperCallIfNeeded(statements, constructor, hasExtendsClause, hasSynthesizedSuper); if (constructor) { - addNodes(statements, visitNodes(constructor.body.statements, visitor, isStatement, hasSynthesizedSuper ? 1 : 0)); + addRange(statements, visitNodes(constructor.body.statements, visitor, isStatement, hasSynthesizedSuper ? 1 : 0)); } - addNodes(statements, endLexicalEnvironment()); - return setMultiLine(createBlock(statements, /*location*/ constructor && constructor.body), /*multiLine*/ true); + addRange(statements, endLexicalEnvironment()); + return createBlock(statements, /*location*/ constructor && constructor.body, /*multiLine*/ true); } - function addDefaultSuperCall(statements: Statement[], constructor: ConstructorDeclaration, hasExtendsClause: boolean, hasSynthesizedSuper: boolean) { + /** + * Adds a synthesized call to `_super` if it is needed. + * + * @param statements The statements for the new constructor body. + * @param constructor The constructor for the class. + * @param hasExtendsClause A value indicating whether the class has an `extends` clause. + * @param hasSynthesizedSuper A value indicating whether the constructor starts with a + * synthesized `super` call. + */ + function addDefaultSuperCallIfNeeded(statements: Statement[], constructor: ConstructorDeclaration, hasExtendsClause: boolean, hasSynthesizedSuper: boolean) { + // If the TypeScript transformer needed to synthesize a constructor for property + // initializers, it would have also added a synthetic `...args` parameter and + // `super` call. + // If this is the case, or if the class has an `extends` clause but no + // constructor, we emit a synthesized call to `_super`. if (constructor ? hasSynthesizedSuper : hasExtendsClause) { - addNode(statements, + statements.push( createStatement( createFunctionApply( createIdentifier("_super"), @@ -307,6 +441,11 @@ namespace ts { } } + /** + * Visits a parameter declaration. + * + * @param node A ParameterDeclaration node. + */ function visitParameter(node: ParameterDeclaration): ParameterDeclaration { if (isBindingPattern(node.name)) { // Binding patterns are converted into a generated name and are @@ -334,11 +473,24 @@ namespace ts { } } + /** + * Gets a value indicating whether we need to add default value assignments for a + * function-like node. + * + * @param node A function-like node. + */ function shouldAddDefaultValueAssignments(node: FunctionLikeDeclaration): boolean { return (node.transformFlags & TransformFlags.ContainsDefaultValueAssignments) !== 0; } - function addDefaultValueAssignments(statements: Statement[], node: FunctionLikeDeclaration): void { + /** + * Adds statements to the body of a function-like node if it contains parameters with + * binding patterns or initializers. + * + * @param statements The statements for the new function body. + * @param node A function-like node. + */ + function addDefaultValueAssignmentsIfNeeded(statements: Statement[], node: FunctionLikeDeclaration): void { if (!shouldAddDefaultValueAssignments(node)) { return; } @@ -361,6 +513,14 @@ namespace ts { } } + /** + * Adds statements to the body of a function-like node for parameters with binding patterns + * + * @param statements The statements for the new function body. + * @param parameter The parameter for the function. + * @param name The name of the parameter. + * @param initializer The initializer for the parameter. + */ function addDefaultValueAssignmentForBindingPattern(statements: Statement[], parameter: ParameterDeclaration, name: BindingPattern, initializer: Expression): void { const temp = getGeneratedNameForNode(parameter); @@ -368,17 +528,17 @@ namespace ts { // we usually don't want to emit a var declaration; however, in the presence // of an initializer, we must emit that expression to preserve side effects. if (name.elements.length > 0) { - addNode(statements, + statements.push( createVariableStatement( /*modifiers*/ undefined, createVariableDeclarationList( - transformParameterBindingElements(parameter, temp) + flattenParameterDestructuring(parameter, temp, visitor) ) ) ); } else if (initializer) { - addNode(statements, + statements.push( createStatement( createAssignment( temp, @@ -389,12 +549,16 @@ namespace ts { } } - function transformParameterBindingElements(parameter: ParameterDeclaration, name: Identifier) { - return flattenParameterDestructuring(parameter, name, visitor); - } - + /** + * Adds statements to the body of a function-like node for parameters with initializers. + * + * @param statements The statements for the new function body. + * @param parameter The parameter for the function. + * @param name The name of the parameter. + * @param initializer The initializer for the parameter. + */ function addDefaultValueAssignmentForInitializer(statements: Statement[], parameter: ParameterDeclaration, name: Identifier, initializer: Expression): void { - addNode(statements, + statements.push( createIf( createStrictEquality( getSynthesizedClone(name), @@ -415,17 +579,30 @@ namespace ts { ); } - function shouldAddRestParameter(node: ParameterDeclaration) { - return node && node.dotDotDotToken; + /** + * Gets a value indicating whether we need to add statements to handle a rest parameter. + * + * @param node A ParameterDeclaration node. + * @param inConstructorWithSynthesizedSuper A value indicating whether the parameter is + * part of a constructor declaration with a + * synthesized call to `super` + */ + function shouldAddRestParameter(node: ParameterDeclaration, inConstructorWithSynthesizedSuper: boolean) { + return node && node.dotDotDotToken && !inConstructorWithSynthesizedSuper; } - function addRestParameter(statements: Statement[], node: FunctionLikeDeclaration, inConstructorWithSynthesizedSuper?: boolean): void { - if (inConstructorWithSynthesizedSuper) { - return; - } - + /** + * Adds statements to the body of a function-like node if it contains a rest parameter. + * + * @param statements The statements for the new function body. + * @param node A function-like node. + * @param inConstructorWithSynthesizedSuper A value indicating whether the parameter is + * part of a constructor declaration with a + * synthesized call to `super` + */ + function addRestParameterIfNeeded(statements: Statement[], node: FunctionLikeDeclaration, inConstructorWithSynthesizedSuper: boolean): void { const parameter = lastOrUndefined(node.parameters); - if (!shouldAddRestParameter(parameter)) { + if (!shouldAddRestParameter(parameter, inConstructorWithSynthesizedSuper)) { return; } @@ -434,7 +611,7 @@ namespace ts { const temp = createLoopVariable(); // var param = []; - addNode(statements, + statements.push( createVariableStatement( /*modifiers*/ undefined, createVariableDeclarationList([ @@ -449,7 +626,7 @@ namespace ts { // for (var _i = restIndex; _i < arguments.length; _i++) { // param[_i - restIndex] = arguments[_i]; // } - addNode(statements, + statements.push( createFor( createVariableDeclarationList([ createVariableDeclaration(temp, createLiteral(restIndex)) @@ -465,7 +642,7 @@ namespace ts { createAssignment( createElementAccess( name, - restIndex === 0 ? temp : createSubtract(temp, createLiteral(restIndex)) + createSubtract(temp, createLiteral(restIndex)) ), createElementAccess(createIdentifier("arguments"), temp) ) @@ -476,11 +653,16 @@ namespace ts { ); } + /** + * Adds a statement to capture the `this` of a function declaration if it is needed. + * + * @param statements The statements for the new function body. + * @param node A node. + */ function addCaptureThisForNodeIfNeeded(statements: Statement[], node: Node): void { if (node.transformFlags & TransformFlags.ContainsCapturedLexicalThis && node.kind !== SyntaxKind.ArrowFunction) { - enableExpressionSubstitutionForCapturedThis(); - - addNode(statements, + enableSubstitutionsForCapturedThis(); + statements.push( createVariableStatement( /*modifiers*/ undefined, createVariableDeclarationList([ @@ -494,23 +676,29 @@ namespace ts { } } - function addClassMembers(classStatements: Statement[], node: ClassExpression | ClassDeclaration): void { + /** + * Adds statements to the class body function for a class to define the members of the + * class. + * + * @param statements The statements for the class body function. + * @param node The ClassExpression or ClassDeclaration node. + */ + function addClassMembers(statements: Statement[], node: ClassExpression | ClassDeclaration): void { for (const member of node.members) { switch (member.kind) { case SyntaxKind.SemicolonClassElement: - addNode(classStatements, transformSemicolonClassElementToStatement(member)); + statements.push(transformSemicolonClassElementToStatement(member)); break; case SyntaxKind.MethodDeclaration: - addNode(classStatements, transformClassMethodDeclarationToStatement(node, member)); + statements.push(transformClassMethodDeclarationToStatement(getClassMemberPrefix(node, member), member)); break; case SyntaxKind.GetAccessor: case SyntaxKind.SetAccessor: const accessors = getAllAccessorDeclarations(node.members, member); if (member === accessors.firstAccessor) { - const receiver = getClassMemberPrefix(node, member); - addNode(classStatements, transformAccessorsToStatement(receiver, accessors)); + statements.push(transformAccessorsToStatement(getClassMemberPrefix(node, member), accessors)); } break; @@ -526,42 +714,52 @@ namespace ts { } } + /** + * Transforms a SemicolonClassElement into a statement for a class body function. + * + * @param member The SemicolonClassElement node. + */ function transformSemicolonClassElementToStatement(member: SemicolonClassElement) { - return createEmptyStatement(member); + return createEmptyStatement(/*location*/ member); } - function transformClassMethodDeclarationToStatement(node: ClassExpression | ClassDeclaration, member: MethodDeclaration) { - const savedContainingFunction = containingFunction; - const savedContainingNonArrowFunction = containingNonArrowFunction; - containingFunction = containingNonArrowFunction = member; - const statement = createStatement( + /** + * Transforms a MethodDeclaration into a statement for a class body function. + * + * @param receiver The receiver for the member. + * @param member The MethodDeclaration node. + */ + function transformClassMethodDeclarationToStatement(receiver: LeftHandSideExpression, member: MethodDeclaration) { + return createStatement( createAssignment( createMemberAccessForPropertyName( - getClassMemberPrefix(node, member), + receiver, visitNode(member.name, visitor, isPropertyName) ), - transformFunctionLikeToExpression(member) + transformFunctionLikeToExpression(member, /*location*/ undefined, /*name*/ undefined) ), /*location*/ member ); - - containingFunction = savedContainingFunction; - containingNonArrowFunction = savedContainingNonArrowFunction; - return statement; } + /** + * Transforms a set of related of get/set accessors into a statement for a class body function. + * + * @param receiver The receiver for the member. + * @param accessors The set of related get/set accessors. + */ function transformAccessorsToStatement(receiver: LeftHandSideExpression, accessors: AllAccessorDeclarations): Statement { - const savedContainingFunction = containingFunction; - const savedContainingNonArrowFunction = containingNonArrowFunction; - containingFunction = containingNonArrowFunction = accessors.firstAccessor; - const statement = createStatement( + return createStatement( transformAccessorsToExpression(receiver, accessors) ); - containingFunction = savedContainingFunction; - containingNonArrowFunction = savedContainingNonArrowFunction; - return statement; } + /** + * Transforms a set of related get/set accessors into an expression for either a class + * body function or an ObjectLiteralExpression with computed properties. + * + * @param receiver The receiver for the member. + */ function transformAccessorsToExpression(receiver: LeftHandSideExpression, { firstAccessor, getAccessor, setAccessor }: AllAccessorDeclarations): Expression { return createObjectDefineProperty( receiver, @@ -570,8 +768,8 @@ namespace ts { /*location*/ firstAccessor.name ), { - get: getAccessor && transformFunctionLikeToExpression(getAccessor, /*location*/ getAccessor), - set: setAccessor && transformFunctionLikeToExpression(setAccessor, /*location*/ setAccessor), + get: getAccessor && transformFunctionLikeToExpression(getAccessor, /*location*/ getAccessor, /*name*/ undefined), + set: setAccessor && transformFunctionLikeToExpression(setAccessor, /*location*/ setAccessor, /*name*/ undefined), enumerable: true, configurable: true }, @@ -580,175 +778,289 @@ namespace ts { ); } - function transformFunctionLikeToExpression(node: FunctionLikeDeclaration, location?: TextRange, name?: Identifier): FunctionExpression { - return setOriginalNode( - createFunctionExpression( - /*asteriskToken*/ undefined, - name, - visitNodes(node.parameters, visitor, isParameter), - transformFunctionBody(node), - location - ), - node - ); - } - + /** + * Visits an ArrowFunction and transforms it into a FunctionExpression. + * + * @param node An ArrowFunction node. + */ function visitArrowFunction(node: ArrowFunction) { if (node.transformFlags & TransformFlags.ContainsLexicalThis) { - enableExpressionSubstitutionForCapturedThis(); + enableSubstitutionsForCapturedThis(); } return transformFunctionLikeToExpression(node, /*location*/ node, /*name*/ undefined); } + /** + * Visits a FunctionExpression node. + * + * @param node a FunctionExpression node. + */ function visitFunctionExpression(node: FunctionExpression): Expression { return transformFunctionLikeToExpression(node, /*location*/ node, node.name); } + /** + * Visits a FunctionDeclaration node. + * + * @param node a FunctionDeclaration node. + */ function visitFunctionDeclaration(node: FunctionDeclaration): FunctionDeclaration { - return setOriginalNode( - createFunctionDeclaration( - /*modifiers*/ undefined, - node.asteriskToken, // TODO(rbuckton): downlevel support for generators - node.name, - visitNodes(node.parameters, visitor, isParameter), - transformFunctionBody(node), - /*location*/ node - ), - node + return createFunctionDeclaration( + /*modifiers*/ undefined, + node.asteriskToken, + node.name, + visitNodes(node.parameters, visitor, isParameter), + transformFunctionBody(node), + /*location*/ node, + /*original*/ node ); } + /** + * Transforms a function-like node into a FunctionExpression. + * + * @param node The function-like node to transform. + * @param location The source-map location for the new FunctionExpression. + * @param name The name of the new FunctionExpression. + */ + function transformFunctionLikeToExpression(node: FunctionLikeDeclaration, location: TextRange, name: Identifier): FunctionExpression { + const savedContainingNonArrowFunction = containingNonArrowFunction; + if (node.kind !== SyntaxKind.ArrowFunction) { + containingNonArrowFunction = node; + } + + const expression = createFunctionExpression( + /*asteriskToken*/ undefined, + name, + visitNodes(node.parameters, visitor, isParameter), + transformFunctionBody(node), + location, + /*original*/ node + ); + + containingNonArrowFunction = savedContainingNonArrowFunction; + return expression; + } + + /** + * Transforms the body of a function-like node. + * + * @param node A function-like node. + */ function transformFunctionBody(node: FunctionLikeDeclaration) { const statements: Statement[] = []; startLexicalEnvironment(); addCaptureThisForNodeIfNeeded(statements, node); - addDefaultValueAssignments(statements, node); - addRestParameter(statements, node); + addDefaultValueAssignmentsIfNeeded(statements, node); + addRestParameterIfNeeded(statements, node, /*inConstructorWithSynthesizedSuper*/ false); const body = node.body; if (isBlock(body)) { - addNodes(statements, visitNodes(body.statements, visitor, isStatement)); + addRange(statements, visitNodes(body.statements, visitor, isStatement)); } else { const expression = visitNode(body, visitor, isExpression); if (expression) { - addNode(statements, createReturn(expression, /*location*/ body)); + statements.push(createReturn(expression, /*location*/ body)); } } - addNodes(statements, endLexicalEnvironment()); + addRange(statements, endLexicalEnvironment()); return createBlock(statements, node.body); } - function visitBinaryExpression(node: BinaryExpression): Expression { - // If we are here it is because this is a destructuring assignment. - // TODO(rbuckton): Determine whether we need to save the value. - return flattenDestructuringAssignment(node, /*needsValue*/ true, hoistVariableDeclaration, visitor); + /** + * Visits an ExpressionStatement that contains a destructuring assignment. + * + * @param node An ExpressionStatement node. + */ + function visitExpressionStatement(node: ExpressionStatement): ExpressionStatement { + // If we are here it is most likely because our expression is a destructuring assignment. + switch (node.expression.kind) { + case SyntaxKind.ParenthesizedExpression: + return createStatement( + visitParenthesizedExpression(node.expression, /*needsDestructuringValue*/ false), + /*location*/ node + ); + + case SyntaxKind.BinaryExpression: + return createStatement( + visitBinaryExpression(node.expression, /*needsDestructuringValue*/ false), + /*location*/ node + ); + } + + return visitEachChild(node, visitor, context); } + /** + * Visits a ParenthesizedExpression that may contain a destructuring assignment. + * + * @param node A ParenthesizedExpression node. + * @param needsDestructuringValue A value indicating whether we need to hold onto the rhs + * of a destructuring assignment. + */ + function visitParenthesizedExpression(node: ParenthesizedExpression, needsDestructuringValue: boolean): ParenthesizedExpression { + // If we are here it is most likely because our expression is a destructuring assignment. + if (needsDestructuringValue) { + switch (node.expression.kind) { + case SyntaxKind.ParenthesizedExpression: + return createParen( + visitParenthesizedExpression(node.expression, /*needsDestructuringValue*/ true), + /*location*/ node + ); + + case SyntaxKind.BinaryExpression: + return createParen( + visitBinaryExpression(node.expression, /*needsDestructuringValue*/ true), + /*location*/ node + ); + } + } + + return visitEachChild(node, visitor, context); + } + + /** + * Visits a BinaryExpression that contains a destructuring assignment. + * + * @param node A BinaryExpression node. + * @param needsDestructuringValue A value indicating whether we need to hold onto the rhs + * of a destructuring assignment. + */ + function visitBinaryExpression(node: BinaryExpression, needsDestructuringValue: boolean): Expression { + // If we are here it is because this is a destructuring assignment. + Debug.assert(isDestructuringAssignment(node)); + return flattenDestructuringAssignment(node, needsDestructuringValue, hoistVariableDeclaration, visitor); + } + + /** + * Visits a VariableDeclarationList that is block scoped (e.g. `let` or `const`). + * + * @param node A VariableDeclarationList node. + */ function visitVariableDeclarationList(node: VariableDeclarationList): VariableDeclarationList { + // If we are here it is because the list is defined as `let` or `const`. + Debug.assert((node.flags & NodeFlags.BlockScoped) !== 0); + + enableSubstitutionsForBlockScopedBindings(); return setOriginalNode( createVariableDeclarationList( - flattenNodes(map(node.declarations, visitVariableDeclaration)), + flattenNodes(map(node.declarations, visitVariableDeclarationInLetDeclarationList)), /*location*/ node ), node ); } - function visitVariableDeclaration(node: VariableDeclaration): OneOrMany { + /** + * Gets a value indicating whether we should emit an explicit initializer for a variable + * declaration in a `let` declaration list. + * + * @param node A VariableDeclaration node. + */ + function shouldEmitExplicitInitializerForLetDeclaration(node: VariableDeclaration) { + // Nested let bindings might need to be initialized explicitly to preserve + // ES6 semantic: + // + // { let x = 1; } + // { let x; } // x here should be undefined. not 1 + // + // Top level bindings never collide with anything and thus don't require + // explicit initialization. As for nested let bindings there are two cases: + // + // - Nested let bindings that were not renamed definitely should be + // initialized explicitly: + // + // { let x = 1; } + // { let x; if (some-condition) { x = 1}; if (x) { /*1*/ } } + // + // Without explicit initialization code in /*1*/ can be executed even if + // some-condition is evaluated to false. + // + // - Renaming introduces fresh name that should not collide with any + // existing names, however renamed bindings sometimes also should be + // explicitly initialized. One particular case: non-captured binding + // declared inside loop body (but not in loop initializer): + // + // let x; + // for (;;) { + // let x; + // } + // + // In downlevel codegen inner 'x' will be renamed so it won't collide + // with outer 'x' however it will should be reset on every iteration as + // if it was declared anew. + // + // * Why non-captured binding? + // - Because if loop contains block scoped binding captured in some + // function then loop body will be rewritten to have a fresh scope + // on every iteration so everything will just work. + // + // * Why loop initializer is excluded? + // - Since we've introduced a fresh name it already will be undefined. + + const original = getOriginalNode(node); + Debug.assert(isVariableDeclaration(original)); + + const flags = resolver.getNodeCheckFlags(original); + const isCapturedInFunction = flags & NodeCheckFlags.CapturedBlockScopedBinding; + const isDeclaredInLoop = flags & NodeCheckFlags.BlockScopedBindingInLoop; + const emittedAsTopLevel = + isBlockScopedContainerTopLevel(enclosingBlockScopeContainer) + || (isCapturedInFunction + && isDeclaredInLoop + && isBlock(enclosingBlockScopeContainer) + && isIterationStatement(enclosingBlockScopeContainerParent, /*lookInLabeledStatements*/ false)); + + const emitExplicitInitializer = + !emittedAsTopLevel + && enclosingBlockScopeContainer.kind !== SyntaxKind.ForInStatement + && enclosingBlockScopeContainer.kind !== SyntaxKind.ForOfStatement + && (!resolver.isDeclarationWithCollidingName(original) + || (isDeclaredInLoop + && !isCapturedInFunction + && !isIterationStatement(enclosingBlockScopeContainer, /*lookInLabeledStatements*/ false))); + + return emitExplicitInitializer; + } + + /** + * Visits a VariableDeclaration in a `let` declaration list. + * + * @param node A VariableDeclaration node. + */ + function visitVariableDeclarationInLetDeclarationList(node: VariableDeclaration) { + // For binding pattern names that lack initializers there is no point to emit + // explicit initializer since downlevel codegen for destructuring will fail + // in the absence of initializer so all binding elements will say uninitialized const name = node.name; - if (isBindingPattern(name)) { - return createNodeArrayNode( - flattenVariableDestructuring(node, /*value*/ undefined, visitor) - ); + if (isBindingPattern(name) || node.initializer) { + return visitVariableDeclaration(node); } - else { - let initializer = node.initializer; - // For binding pattern names that lack initializer there is no point to emit - // explicit initializer since downlevel codegen for destructuring will fail - // in the absence of initializer so all binding elements will say uninitialized - if (!initializer) { - const original = getOriginalNode(node); - if (isVariableDeclaration(original)) { - // Nested let bindings might need to be initialized explicitly to preserve - // ES6 semantic: - // - // { let x = 1; } - // { let x; } // x here should be undefined. not 1 - // - // Top level bindings never collide with anything and thus don't require - // explicit initialization. As for nested let bindings there are two cases: - // - // - Nested let bindings that were not renamed definitely should be - // initialized explicitly: - // - // { let x = 1; } - // { let x; if (some-condition) { x = 1}; if (x) { /*1*/ } } - // - // Without explicit initialization code in /*1*/ can be executed even if - // some-condition is evaluated to false. - // - // - Renaming introduces fresh name that should not collide with any - // existing names, however renamed bindings sometimes also should be - // explicitly initialized. One particular case: non-captured binding - // declared inside loop body (but not in loop initializer): - // - // let x; - // for (;;) { - // let x; - // } - // - // In downlevel codegen inner 'x' will be renamed so it won't collide - // with outer 'x' however it will should be reset on every iteration as - // if it was declared anew. - // - // * Why non-captured binding? - // - Because if loop contains block scoped binding captured in some - // function then loop body will be rewritten to have a fresh scope - // on every iteration so everything will just work. - // - // * Why loop initializer is excluded? - // - Since we've introduced a fresh name it already will be undefined. - const flags = resolver.getNodeCheckFlags(original); - const isCapturedInFunction = flags & NodeCheckFlags.CapturedBlockScopedBinding; - const isDeclaredInLoop = flags & NodeCheckFlags.BlockScopedBindingInLoop; - - const emittedAsTopLevel = - isBlockScopedContainerTopLevel(enclosingBlockScopeContainer) - || (isCapturedInFunction - && isDeclaredInLoop - && isBlock(enclosingBlockScopeContainer) - && isIterationStatement(enclosingBlockScopeContainerParent, /*lookInLabeledStatements*/ false)); - - const emittedAsNestedLetDeclaration = combinedNodeFlags & NodeFlags.Let && !emittedAsTopLevel; - - const emitExplicitInitializer = - emittedAsNestedLetDeclaration - && enclosingBlockScopeContainer.kind !== SyntaxKind.ForInStatement - && enclosingBlockScopeContainer.kind !== SyntaxKind.ForOfStatement - && (!resolver.isDeclarationWithCollidingName(original) - || (isDeclaredInLoop - && !isCapturedInFunction - && !isIterationStatement(enclosingBlockScopeContainer, /*lookInLabeledStatements*/ false))); - - if (emitExplicitInitializer) { - initializer = createVoidZero(); - } - } - } - - return setOriginalNode( - createVariableDeclaration( - name, - visitNode(initializer, visitor, isExpression, /*optional*/ true), - /*location*/ node - ), - node - ); + if (shouldEmitExplicitInitializerForLetDeclaration(node)) { + const clone = getMutableClone(node); + clone.initializer = createVoidZero(); + return clone; } + + return visitEachChild(node, visitor, context); + } + + /** + * Visits a VariableDeclaration node with a binding pattern. + * + * @param node A VariableDeclaration node. + */ + function visitVariableDeclaration(node: VariableDeclaration): OneOrMany { + // If we are here it is because the name contains a binding pattern. + Debug.assert(isBindingPattern(node.name)); + + return createNodeArrayNode( + flattenVariableDestructuring(node, /*value*/ undefined, visitor) + ); } function visitLabeledStatement(node: LabeledStatement) { @@ -771,12 +1083,16 @@ namespace ts { return visitEachChild(node, visitor, context); } - function visitForInStatement(node: ForInStatement) { // TODO: Convert loop body for block scoped bindings. return visitEachChild(node, visitor, context); } + /** + * Visits a ForOfStatement and converts it into a compatible ForStatement. + * + * @param node A ForOfStatement. + */ function visitForOfStatement(node: ForOfStatement): Statement { // TODO: Convert loop body for block scoped bindings. @@ -803,7 +1119,7 @@ namespace ts { const expression = visitNode(node.expression, visitor, isExpression); const initializer = node.initializer; - const loopBodyStatements: Statement[] = []; + const statements: Statement[] = []; // In the case where the user wrote an identifier as the RHS, like this: // @@ -822,7 +1138,7 @@ namespace ts { if (firstDeclaration && isBindingPattern(firstDeclaration.name)) { // This works whether the declaration is a var, let, or const. // It will use rhsIterationValue _a[_i] as the initializer. - addNode(loopBodyStatements, + statements.push( createVariableStatement( /*modifiers*/ undefined, createVariableDeclarationList( @@ -839,7 +1155,7 @@ namespace ts { else { // The following call does not include the initializer, so we have // to emit it separately. - addNode(loopBodyStatements, + statements.push( createVariableStatement( /*modifiers*/ undefined, createVariableDeclarationList([ @@ -859,7 +1175,7 @@ namespace ts { const assignment = createAssignment(initializer, createElementAccess(rhsReference, counter)); if (isDestructuringAssignment(assignment)) { // This is a destructuring pattern, so we flatten the destructuring instead. - addNode(loopBodyStatements, + statements.push( createStatement( flattenDestructuringAssignment( assignment, @@ -871,16 +1187,16 @@ namespace ts { ); } else { - addNode(loopBodyStatements, createStatement(assignment, /*location*/ node.initializer)); + statements.push(createStatement(assignment, /*location*/ node.initializer)); } } const statement = visitNode(node.statement, visitor, isStatement); if (isBlock(statement)) { - addNodes(loopBodyStatements, statement.statements); + addRange(statements, statement.statements); } else { - addNode(loopBodyStatements, statement); + statements.push(statement); } return createFor( @@ -898,12 +1214,17 @@ namespace ts { ), createPostfixIncrement(counter, /*location*/ initializer), createBlock( - loopBodyStatements + statements ), /*location*/ node ); } + /** + * Visits an ObjectLiteralExpression with computed propety names. + * + * @param node An ObjectLiteralExpression node. + */ function visitObjectLiteralExpression(node: ObjectLiteralExpression): LeftHandSideExpression { // We are here because a ComputedPropertyName was used somewhere in the expression. const properties = node.properties; @@ -931,10 +1252,9 @@ namespace ts { addNode(expressions, createAssignment( temp, - setMultiLine( - createObjectLiteral( - visitNodes(properties, visitor, isObjectLiteralElement, 0, numInitialNonComputedProperties) - ), + createObjectLiteral( + visitNodes(properties, visitor, isObjectLiteralElement, 0, numInitialNonComputedProperties), + /*location*/ undefined, node.multiLine ) ), @@ -945,13 +1265,23 @@ namespace ts { // We need to clone the temporary identifier so that we can write it on a // new line - addNode(expressions, cloneNode(temp), node.multiLine); + addNode(expressions, getMutableClone(temp), node.multiLine); return createParen(inlineExpressions(expressions)); } + /** + * Adds the members of an object literal to an array of expressions. + * + * @param expressions An array of expressions. + * @param node An ObjectLiteralExpression node. + * @param receiver The receiver for members of the ObjectLiteralExpression. + * @param numInitialNonComputedProperties The number of initial properties without + * computed property names. + */ function addObjectLiteralMembers(expressions: Expression[], node: ObjectLiteralExpression, receiver: Identifier, numInitialNonComputedProperties: number) { const properties = node.properties; - for (let i = numInitialNonComputedProperties, len = properties.length; i < len; i++) { + const numProperties = properties.length; + for (let i = numInitialNonComputedProperties; i < numProperties; i++) { const property = properties[i]; switch (property.kind) { case SyntaxKind.GetAccessor: @@ -982,6 +1312,13 @@ namespace ts { } } + /** + * Transforms a PropertyAssignment node into an expression. + * + * @param node The ObjectLiteralExpression that contains the PropertyAssignment. + * @param property The PropertyAssignment node. + * @param receiver The receiver for the assignment. + */ function transformPropertyAssignmentToExpression(node: ObjectLiteralExpression, property: PropertyAssignment, receiver: Expression) { return createAssignment( createMemberAccessForPropertyName( @@ -993,6 +1330,13 @@ namespace ts { ); } + /** + * Transforms a ShorthandPropertyAssignment node into an expression. + * + * @param node The ObjectLiteralExpression that contains the ShorthandPropertyAssignment. + * @param property The ShorthandPropertyAssignment node. + * @param receiver The receiver for the assignment. + */ function transformShorthandPropertyAssignmentToExpression(node: ObjectLiteralExpression, property: ShorthandPropertyAssignment, receiver: Expression) { return createAssignment( createMemberAccessForPropertyName( @@ -1004,29 +1348,47 @@ namespace ts { ); } + /** + * Transforms a MethodDeclaration of an ObjectLiteralExpression into an expression. + * + * @param node The ObjectLiteralExpression that contains the MethodDeclaration. + * @param method The MethodDeclaration node. + * @param receiver The receiver for the assignment. + */ function transformObjectLiteralMethodDeclarationToExpression(node: ObjectLiteralExpression, method: MethodDeclaration, receiver: Expression) { return createAssignment( createMemberAccessForPropertyName( receiver, visitNode(method.name, visitor, isPropertyName) ), - transformFunctionLikeToExpression(method, /*location*/ method), + transformFunctionLikeToExpression(method, /*location*/ method, /*name*/ undefined), /*location*/ method ); } + /** + * Visits a MethodDeclaration of an ObjectLiteralExpression and transforms it into a + * PropertyAssignment. + * + * @param node A MethodDeclaration node. + */ function visitMethodDeclaration(node: MethodDeclaration): ObjectLiteralElement { // We should only get here for methods on an object literal with regular identifier names. // Methods on classes are handled in visitClassDeclaration/visitClassExpression. // Methods with computed property names are handled in visitObjectLiteralExpression. - Debug.assert(isIdentifier(node.name), `Unexpected node kind: ${formatSyntaxKind(node.name.kind)}.`); + Debug.assert(!isComputedPropertyName(node.name)); return createPropertyAssignment( node.name, - transformFunctionLikeToExpression(node, /*location*/ node), + transformFunctionLikeToExpression(node, /*location*/ node, /*name*/ undefined), /*location*/ node ); } + /** + * Visits a ShorthandPropertyAssignment and transforms it into a PropertyAssignment. + * + * @param node A ShorthandPropertyAssignment node. + */ function visitShorthandPropertyAssignment(node: ShorthandPropertyAssignment): ObjectLiteralElement { return createPropertyAssignment( node.name, @@ -1035,197 +1397,148 @@ namespace ts { ); } + /** + * Visits an ArrayLiteralExpression that contains a spread element. + * + * @param node An ArrayLiteralExpression node. + */ function visitArrayLiteralExpression(node: ArrayLiteralExpression): Expression { - // We are here either because SuperKeyword was used somewhere in the expression, or - // because we contain a SpreadElementExpression. - if (node.transformFlags & TransformFlags.ContainsSpreadElementExpression) { - return transformAndSpreadElements(node.elements, /*needsUniqueCopy*/ true, node.multiLine); - } - else { - // We don't handle SuperKeyword here, so fall back. - return visitEachChild(node, visitor, context); - } + // We are here because we contain a SpreadElementExpression. + return transformAndSpreadElements(node.elements, /*needsUniqueCopy*/ true, node.multiLine); } + /** + * Visits a CallExpression that contains either a spread element or `super`. + * + * @param node a CallExpression. + */ function visitCallExpression(node: CallExpression): LeftHandSideExpression { // We are here either because SuperKeyword was used somewhere in the expression, or // because we contain a SpreadElementExpression. - const { target, thisArg } = transformCallTarget(node.expression); + + const { target, thisArg } = createCallBinding(node); if (node.transformFlags & TransformFlags.ContainsSpreadElementExpression) { + // [source] + // f(...a, b) + // x.m(...a, b) + // super(...a, b) + // super.m(...a, b) // in static + // super.m(...a, b) // in instance + // + // [output] + // f.apply(void 0, a.concat([b])) + // (_a = x).m.apply(_a, a.concat([b])) + // _super.apply(this, a.concat([b])) + // _super.m.apply(this, a.concat([b])) + // _super.prototype.m.apply(this, a.concat([b])) + return createFunctionApply( - target, - thisArg, + visitNode(target, visitor, isExpression), + visitNode(thisArg, visitor, isExpression), transformAndSpreadElements(node.arguments, /*needsUniqueCopy*/ false, /*multiLine*/ false) ); } else { - Debug.assert(isSuperCall(node)); + // [source] + // super(a) + // super.m(a) // in static + // super.m(a) // in instance + // + // [output] + // _super.call(this, a) + // _super.m.call(this, a) + // _super.prototype.m.call(this, a) + return createFunctionCall( - target, - thisArg, + visitNode(target, visitor, isExpression), + visitNode(thisArg, visitor, isExpression), visitNodes(node.arguments, visitor, isExpression), /*location*/ node ); } } + /** + * Visits a NewExpression that contains a spread element. + * + * @param node A NewExpression node. + */ function visitNewExpression(node: NewExpression): LeftHandSideExpression { - // We are here either because we contain a SpreadElementExpression. + // We are here because we contain a SpreadElementExpression. Debug.assert((node.transformFlags & TransformFlags.ContainsSpreadElementExpression) !== 0); - // Transforms `new C(...a)` into `new ((_a = C).bind.apply(_a, [void 0].concat(a)))()`. - // Transforms `new x.C(...a)` into `new ((_a = x.C).bind.apply(_a, [void 0].concat(a)))()`. - const { target, thisArg } = transformCallTarget(createPropertyAccess(node.expression, "bind")); + // [source] + // new C(...a) + // + // [output] + // new ((_a = C).bind.apply(_a, [void 0].concat(a)))() + + const { target, thisArg } = createCallBinding(createPropertyAccess(node.expression, "bind")); return createNew( - createParen( - createFunctionApply( - target, - thisArg, - transformAndSpreadElements(node.arguments, /*needsUniqueCopy*/ false, /*multiLine*/ false, createVoidZero()) - ) + createFunctionApply( + visitNode(target, visitor, isExpression), + thisArg, + transformAndSpreadElements(createNodeArray([createVoidZero(), ...node.arguments]), /*needsUniqueCopy*/ false, /*multiLine*/ false) ), [] ); } - interface CallTarget { - target: Expression; - thisArg: Expression; - } + /** + * Transforms an array of Expression nodes that contains a SpreadElementExpression. + * + * @param elements The array of Expression nodes. + * @param needsUniqueCopy A value indicating whether to ensure that the result is a fresh array. + * @param multiLine A value indicating whether the result should be emitted on multiple lines. + */ + function transformAndSpreadElements(elements: NodeArray, needsUniqueCopy: boolean, multiLine: boolean): Expression { + // [source] + // [a, ...b, c] + // + // [output] + // [a].concat(b, [c]) - function transformCallTarget(expression: Expression): CallTarget { - const callee = skipParentheses(expression); - switch (callee.kind) { - case SyntaxKind.PropertyAccessExpression: - return transformPropertyAccessCallTarget(callee); - - case SyntaxKind.ElementAccessExpression: - return transformElementAccessCallTarget(callee); - - case SyntaxKind.SuperKeyword: - return transformSuperCallTarget(callee); - - default: - const thisArg = createVoidZero(); - const target = visitNode(expression, visitor, isExpression); - return { target, thisArg }; - } - } - - function transformPropertyAccessCallTarget(node: PropertyAccessExpression): CallTarget { - if (node.expression.kind === SyntaxKind.SuperKeyword) { - // For `super.b()`, target is either `_super.b` (for static members) or - // `_super.prototype.b` (for instance members), and thisArg is `this`. - const thisArg = createThis(/*location*/ node.expression); - const target = createPropertyAccess( - visitSuperKeyword(node.expression), - node.name - ); - - return { target, thisArg }; - } - else { - // For `a.b()`, target is `(_a = a).b` and thisArg is `_a`. - const thisArg = createTempVariable(); - const target = createPropertyAccess( - createAssignment( - thisArg, - visitNode(node.expression, visitor, isExpression) - ), - node.name - ); - - return { target, thisArg }; - } - } - - function transformElementAccessCallTarget(node: ElementAccessExpression): CallTarget { - if (node.expression.kind === SyntaxKind.SuperKeyword) { - // For `super[b]()`, target is either `_super[b]` (for static members) or - // `_super.prototype[b]` (for instance members), and thisArg is `this`. - const thisArg = createThis(/*location*/ node.expression); - const target = createElementAccess( - visitSuperKeyword(node.expression), - visitNode(node.argumentExpression, visitor, isExpression) - ); - - return { target, thisArg }; - } - else { - // For `a[b]()`, expression is `(_a = a)[b]` and thisArg is `_a`. - const thisArg = createTempVariable(); - const target = createElementAccess( - createAssignment( - thisArg, - visitNode(node.expression, visitor, isExpression) - ), - visitNode(node.argumentExpression, visitor, isExpression) - ); - - return { target, thisArg }; - } - } - - function transformSuperCallTarget(node: PrimaryExpression): CallTarget { - // For `super()`, expression is `_super` and thisArg is `this`. - const thisArg = createThis(/*location*/ node); - const target = createIdentifier("_super"); - return { target, thisArg }; - } - - function transformAndSpreadElements(elements: NodeArray, needsUniqueCopy: boolean, multiLine: boolean, leadingExpression?: Expression): Expression { - const segments: Expression[] = []; - addNode(segments, leadingExpression); - - const length = elements.length; - let start = 0; - for (let i = 0; i < length; i++) { - const element = elements[i]; - if (isSpreadElementExpression(element)) { - if (i > start) { - addNode(segments, - setMultiLine( - createArrayLiteral( - visitNodes(elements, visitor, isExpression, start, i) - ), - multiLine - ) - ); - } - - addNode(segments, visitNode(element.expression, visitor, isExpression)); - start = i + 1; - } - } - - if (start < length) { - addNode(segments, - setMultiLine( - createArrayLiteral( - visitNodes(elements, visitor, isExpression, start, length) - ), - multiLine - ) - ); - } + // Map spans of spread expressions into their expressions and spans of other + // expressions into an array literal. + const segments = flatten( + spanMap(elements, isSpreadElementExpression, (chunk: Expression[], isSpread: boolean) => isSpread + ? map(chunk, visitExpressionOfSpreadElement) + : createArrayLiteral(visitNodes(createNodeArray(chunk), visitor, isExpression), /*location*/ undefined, multiLine))); if (segments.length === 1) { - if (!leadingExpression && needsUniqueCopy && isSpreadElementExpression(elements[0])) { - return createArraySlice(segments[0]); - } - - return segments[0]; + return needsUniqueCopy && isSpreadElementExpression(elements[0]) + ? createArraySlice(segments[0]) + : segments[0]; } // Rewrite using the pattern .concat(, , ...) return createArrayConcat(segments.shift(), segments); } + /** + * Transforms the expression of a SpreadElementExpression node. + * + * @param node A SpreadElementExpression node. + */ + function visitExpressionOfSpreadElement(node: SpreadElementExpression) { + return visitNode(node.expression, visitor, isExpression); + } + + /** + * Visits a template literal. + * + * @param node A template literal. + */ function visitTemplateLiteral(node: LiteralExpression): LeftHandSideExpression { return createLiteral(node.text); } - function visitTaggedTemplateExpression(node: TaggedTemplateExpression): LeftHandSideExpression { + /** + * Visits a TaggedTemplateExpression node. + * + * @param node A TaggedTemplateExpression node. + */ + function visitTaggedTemplateExpression(node: TaggedTemplateExpression) { // Visit the tag expression const tag = visitNode(node.tag, visitor, isExpression); @@ -1239,31 +1552,31 @@ namespace ts { const rawStrings: Expression[] = []; const template = node.template; if (isNoSubstitutionTemplateLiteral(template)) { - addNode(cookedStrings, createLiteral(template.text)); - addNode(rawStrings, getRawLiteral(template)); + cookedStrings.push(createLiteral(template.text)); + rawStrings.push(getRawLiteral(template)); } else { - addNode(cookedStrings, createLiteral(template.head.text)); - addNode(rawStrings, getRawLiteral(template.head)); + cookedStrings.push(createLiteral(template.head.text)); + rawStrings.push(getRawLiteral(template.head)); for (const templateSpan of template.templateSpans) { - addNode(cookedStrings, createLiteral(templateSpan.literal.text)); - addNode(rawStrings, getRawLiteral(templateSpan.literal)); - addNode(templateArguments, visitNode(templateSpan.expression, visitor, isExpression)); + cookedStrings.push(createLiteral(templateSpan.literal.text)); + rawStrings.push(getRawLiteral(templateSpan.literal)); + templateArguments.push(visitNode(templateSpan.expression, visitor, isExpression)); } } - return createParen( - inlineExpressions([ - createAssignment(temp, createArrayLiteral(cookedStrings)), - createAssignment(createPropertyAccess(temp, "raw"), createArrayLiteral(rawStrings)), - createCall( - tag, - templateArguments - ) - ]) - ); + return inlineExpressions([ + createAssignment(temp, createArrayLiteral(cookedStrings)), + createAssignment(createPropertyAccess(temp, "raw"), createArrayLiteral(rawStrings)), + createCall(tag, templateArguments) + ]); } + /** + * Creates an ES5 compatible literal from an ES6 template literal. + * + * @param node The ES6 template literal. + */ function getRawLiteral(node: LiteralLikeNode) { // Find original source text, since we need to emit the raw strings of the tagged template. // The raw strings contain the (escaped) strings of what the user wrote. @@ -1285,10 +1598,15 @@ namespace ts { return createLiteral(text); } + /** + * Visits a TemplateExpression node. + * + * @param node A TemplateExpression node. + */ function visitTemplateExpression(node: TemplateExpression): Expression { const expressions: Expression[] = []; addTemplateHead(expressions, node); - addTemplateSpans(expressions, node.templateSpans); + addTemplateSpans(expressions, node); // createAdd will check if each expression binds less closely than binary '+'. // If it does, it wraps the expression in parentheses. Otherwise, something like @@ -1307,6 +1625,11 @@ namespace ts { return expression; } + /** + * Gets a value indicating whether we need to include the head of a TemplateExpression. + * + * @param node A TemplateExpression node. + */ function shouldAddTemplateHead(node: TemplateExpression) { // If this expression has an empty head literal and the first template span has a non-empty // literal, then emitting the empty head literal is not necessary. @@ -1329,28 +1652,43 @@ namespace ts { return node.head.text.length !== 0 || node.templateSpans[0].literal.text.length === 0; } + /** + * Adds the head of a TemplateExpression to an array of expressions. + * + * @param expressions An array of expressions. + * @param node A TemplateExpression node. + */ function addTemplateHead(expressions: Expression[], node: TemplateExpression): void { if (!shouldAddTemplateHead(node)) { return; } - addNode(expressions, createLiteral(node.head.text)); + expressions.push(createLiteral(node.head.text)); } - function addTemplateSpans(expressions: Expression[], nodes: TemplateSpan[]): void { - for (const node of nodes) { - addNode(expressions, visitNode(node.expression, visitor, isExpression)); + /** + * Visits and adds the template spans of a TemplateExpression to an array of expressions. + * + * @param expressions An array of expressions. + * @param node A TemplateExpression node. + */ + function addTemplateSpans(expressions: Expression[], node: TemplateExpression): void { + for (const span of node.templateSpans) { + expressions.push(visitNode(span.expression, visitor, isExpression)); // Only emit if the literal is non-empty. // The binary '+' operator is left-associative, so the first string concatenation // with the head will force the result up to this point to be a string. // Emitting a '+ ""' has no semantic effect for middles and tails. - if (node.literal.text.length !== 0) { - addNode(expressions, createLiteral(node.literal.text)); + if (span.literal.text.length !== 0) { + expressions.push(createLiteral(span.literal.text)); } } } + /** + * Visits the `super` keyword + */ function visitSuperKeyword(node: PrimaryExpression): LeftHandSideExpression { return containingNonArrowFunction && isClassElement(containingNonArrowFunction) @@ -1360,89 +1698,120 @@ namespace ts { } function visitSourceFileNode(node: SourceFile): SourceFile { - const clone = cloneNode(node, node, node.flags, /*parent*/ undefined, node); + const [prologue, remaining] = span(node.statements, isPrologueDirective); const statements: Statement[] = []; startLexicalEnvironment(); - const statementOffset = addPrologueDirectives(statements, node.statements); + addRange(statements, prologue); addCaptureThisForNodeIfNeeded(statements, node); - addNodes(statements, visitNodes(node.statements, visitor, isStatement, statementOffset)); - addNodes(statements, endLexicalEnvironment()); - clone.statements = createNodeArray(statements, node.statements); + addRange(statements, visitNodes(createNodeArray(remaining), visitor, isStatement)); + addRange(statements, endLexicalEnvironment()); + const clone = cloneNode(node, node, node.flags, /*parent*/ undefined, node); + clone.statements = createNodeArray(statements, /*location*/ node.statements); return clone; } - function addPrologueDirectives(to: Statement[], from: NodeArray): number { - for (let i = 0; i < from.length; i++) { - if (isPrologueDirective(from[i])) { - addNode(to, from[i]); - } - else { - return i; - } - } - - return from.length; - } - + /** + * Called by the printer just before a node is printed. + * + * @param node The node to be printed. + */ function onBeforeEmitNode(node: Node) { previousOnBeforeEmitNode(node); - if (containingFunctionStack && isFunctionLike(node)) { - containingFunctionStack.push(node); + if (enabledSubstitutions & ES6SubstitutionFlags.CapturedThis && isFunctionLike(node)) { + // If we are tracking a captured `this`, push a bit that indicates whether the + // containing function is an arrow function. + pushContainingFunction(node.kind === SyntaxKind.ArrowFunction); } } + /** + * Called by the printer just after a node is printed. + * + * @param node The node that was printed. + */ function onAfterEmitNode(node: Node) { previousOnAfterEmitNode(node); - if (containingFunctionStack && isFunctionLike(node)) { - containingFunctionStack.pop(); + if (enabledSubstitutions & ES6SubstitutionFlags.CapturedThis && isFunctionLike(node)) { + // If we are tracking a captured `this`, pop the last containing function bit. + popContainingFunction(); } } - function enableExpressionSubstitutionForCapturedThis() { - if (!hasEnabledExpressionSubstitutionForCapturedThis) { - hasEnabledExpressionSubstitutionForCapturedThis = true; - enableExpressionSubstitution(SyntaxKind.ThisKeyword); - enableEmitNotification(SyntaxKind.Constructor); - enableEmitNotification(SyntaxKind.MethodDeclaration); - enableEmitNotification(SyntaxKind.GetAccessor); - enableEmitNotification(SyntaxKind.SetAccessor); - enableEmitNotification(SyntaxKind.ArrowFunction); - enableEmitNotification(SyntaxKind.FunctionExpression); - enableEmitNotification(SyntaxKind.FunctionDeclaration); - containingFunctionStack = []; + /** + * Enables a more costly code path for substitutions when we determine a source file + * contains block-scoped bindings (e.g. `let` or `const`). + */ + function enableSubstitutionsForBlockScopedBindings() { + if ((enabledSubstitutions & ES6SubstitutionFlags.BlockScopedBindings) === 0) { + enabledSubstitutions |= ES6SubstitutionFlags.BlockScopedBindings; + context.enableExpressionSubstitution(SyntaxKind.Identifier); } } + /** + * Enables a more costly code path for substitutions when we determine a source file + * contains a captured `this`. + */ + function enableSubstitutionsForCapturedThis() { + if ((enabledSubstitutions & ES6SubstitutionFlags.CapturedThis) === 0) { + enabledSubstitutions |= ES6SubstitutionFlags.CapturedThis; + containingFunctionDepth = 0; + context.enableExpressionSubstitution(SyntaxKind.ThisKeyword); + context.enableEmitNotification(SyntaxKind.Constructor); + context.enableEmitNotification(SyntaxKind.MethodDeclaration); + context.enableEmitNotification(SyntaxKind.GetAccessor); + context.enableEmitNotification(SyntaxKind.SetAccessor); + context.enableEmitNotification(SyntaxKind.ArrowFunction); + context.enableEmitNotification(SyntaxKind.FunctionExpression); + context.enableEmitNotification(SyntaxKind.FunctionDeclaration); + } + } + + /** + * Hooks substitutions for non-expression identifiers. + */ function substituteIdentifier(node: Identifier) { node = previousIdentifierSubstitution(node); - const original = getOriginalNode(node); - if (isIdentifier(original) && isNameOfDeclarationWithCollidingName(original)) { - return getGeneratedNameForNode(original); + // Only substitute the identifier if we have enabled substitutions for block-scoped + // bindings. + if (enabledSubstitutions & ES6SubstitutionFlags.BlockScopedBindings) { + const original = getOriginalNode(node); + if (isIdentifier(original) && !nodeIsSynthesized(original) && original.parent && isNameOfDeclarationWithCollidingName(original)) { + return getGeneratedNameForNode(original); + } } return node; } + /** + * Determines whether a name is the name of a declaration with a colliding name. + * NOTE: This function expects to be called with an original source tree node. + * + * @param node An original source tree node. + */ function isNameOfDeclarationWithCollidingName(node: Identifier) { const parent = node.parent; - if (parent) { - switch (parent.kind) { - case SyntaxKind.BindingElement: - case SyntaxKind.ClassDeclaration: - case SyntaxKind.EnumDeclaration: - case SyntaxKind.VariableDeclaration: - return (parent).name === node - && resolver.isDeclarationWithCollidingName(parent); - } + switch (parent.kind) { + case SyntaxKind.BindingElement: + case SyntaxKind.ClassDeclaration: + case SyntaxKind.EnumDeclaration: + case SyntaxKind.VariableDeclaration: + return (parent).name === node + && resolver.isDeclarationWithCollidingName(parent); } return false; } - + /** + * Substitutes an expression. + * + * @param node An Expression node. + */ function substituteExpression(node: Expression): Expression { node = previousExpressionSubstitution(node); switch (node.kind) { @@ -1456,29 +1825,93 @@ namespace ts { return node; } + /** + * Substitutes an expression identifier. + * + * @param node An Identifier node. + */ function substituteExpressionIdentifier(node: Identifier): Identifier { - const original = getOriginalNode(node); - if (isIdentifier(original)) { - const declaration = resolver.getReferencedDeclarationWithCollidingName(original); - if (declaration) { - return getGeneratedNameForNode(declaration.name); + if (enabledSubstitutions & ES6SubstitutionFlags.BlockScopedBindings) { + const original = getOriginalNode(node); + if (isIdentifier(original)) { + const declaration = resolver.getReferencedDeclarationWithCollidingName(original); + if (declaration) { + return getGeneratedNameForNode(declaration.name); + } } } return node; } + /** + * Substitutes `this` when contained within an arrow function. + * + * @param node The ThisKeyword node. + */ function substituteThisKeyword(node: PrimaryExpression): PrimaryExpression { - if (containingFunctionStack) { - const containingFunction = lastOrUndefined(containingFunctionStack); - if (containingFunction && getOriginalNode(containingFunction).kind === SyntaxKind.ArrowFunction) { - return createIdentifier("_this"); - } + if (enabledSubstitutions & ES6SubstitutionFlags.CapturedThis && isContainedInArrowFunction()) { + return createIdentifier("_this", /*location*/ node); } return node; } + /** + * Pushes a value onto a stack that indicates whether we are currently printing a node + * within an arrow function. This is used to determine whether we need to capture `this`. + * + * @param isArrowFunction A value indicating whether the current function container is + * an arrow function. + */ + function pushContainingFunction(isArrowFunction: boolean) { + // Encode whether the containing function is an arrow function in the first 31 bits of + // an integer. If the stack grows beyond a depth of 31 functions, use an array. + if (containingFunctionDepth > 0 && containingFunctionDepth % 31 === 0) { + if (!containingFunctionStack) { + containingFunctionStack = [containingFunctionState]; + } + else { + containingFunctionStack.push(containingFunctionState); + } + + containingFunctionState = 0; + } + + if (isArrowFunction) { + containingFunctionState |= 1 << (containingFunctionDepth % 31); + } + + containingFunctionDepth++; + } + + /** + * Pops a value off of the containing function stack. + */ + function popContainingFunction() { + if (containingFunctionDepth > 0) { + containingFunctionDepth--; + if (containingFunctionDepth === 0) { + containingFunctionState = 0; + } + else if (containingFunctionDepth % 31 === 0) { + containingFunctionState = containingFunctionStack.pop(); + } + else { + containingFunctionState &= ~(1 << containingFunctionDepth % 31); + } + } + } + + /** + * Gets a value indicating whether we are currently printing a node inside of an arrow + * function. + */ + function isContainedInArrowFunction() { + return containingFunctionDepth > 0 + && containingFunctionState & (1 << (containingFunctionDepth - 1) % 31); + } + function getDeclarationName(node: ClassExpression | ClassDeclaration | FunctionDeclaration) { return node.name ? getSynthesizedClone(node.name) : getGeneratedNameForNode(node); } diff --git a/src/compiler/transformers/ts.ts b/src/compiler/transformers/ts.ts index 84bfb04976d..a32b13a2551 100644 --- a/src/compiler/transformers/ts.ts +++ b/src/compiler/transformers/ts.ts @@ -44,7 +44,6 @@ namespace ts { let currentScope: SourceFile | Block | ModuleBlock | CaseBlock; let currentParent: Node; let currentNode: Node; - let combinedNodeFlags: NodeFlags; /** * Keeps track of whether expression substitution has been enabled for specific edge cases. @@ -104,7 +103,6 @@ namespace ts { const savedCurrentScope = currentScope; const savedCurrentParent = currentParent; const savedCurrentNode = currentNode; - const savedCombinedNodeFlags = combinedNodeFlags; // Handle state changes before visiting a node. onBeforeVisitNode(node); @@ -116,7 +114,6 @@ namespace ts { currentScope = savedCurrentScope; currentParent = savedCurrentParent; currentNode = savedCurrentNode; - combinedNodeFlags = savedCombinedNodeFlags; return node; } @@ -392,8 +389,6 @@ namespace ts { currentParent = currentNode; currentNode = node; - combinedNodeFlags = combineNodeFlags(currentNode, currentParent, combinedNodeFlags); - switch (node.kind) { case SyntaxKind.SourceFile: case SyntaxKind.CaseBlock: @@ -2758,7 +2753,7 @@ namespace ts { function substituteCallExpression(node: CallExpression): Expression { const expression = node.expression; - if (isSuperPropertyOrElementAccess(expression)) { + if (isSuperProperty(expression)) { const flags = getSuperContainerAsyncMethodFlags(); if (flags) { const argumentExpression = isPropertyAccessExpression(expression) diff --git a/src/compiler/types.ts b/src/compiler/types.ts index 5cced242498..da0f983298f 100644 --- a/src/compiler/types.ts +++ b/src/compiler/types.ts @@ -2761,18 +2761,19 @@ namespace ts { ContainsES7 = 1 << 5, ES6 = 1 << 6, ContainsES6 = 1 << 7, + DestructuringAssignment = 1 << 8, // Markers // - Flags used to indicate that a subtree contains a specific transformation. - ContainsDecorators = 1 << 8, - ContainsPropertyInitializer = 1 << 9, - ContainsLexicalThis = 1 << 10, - ContainsCapturedLexicalThis = 1 << 11, - ContainsDefaultValueAssignments = 1 << 12, - ContainsParameterPropertyAssignments = 1 << 13, - ContainsSpreadElementExpression = 1 << 14, - ContainsComputedPropertyName = 1 << 15, - ContainsBlockScopedBinding = 1 << 16, + ContainsDecorators = 1 << 9, + ContainsPropertyInitializer = 1 << 10, + ContainsLexicalThis = 1 << 11, + ContainsCapturedLexicalThis = 1 << 12, + ContainsDefaultValueAssignments = 1 << 13, + ContainsParameterPropertyAssignments = 1 << 14, + ContainsSpreadElementExpression = 1 << 15, + ContainsComputedPropertyName = 1 << 16, + ContainsBlockScopedBinding = 1 << 17, // Assertions // - Bitmasks that are used to assert facts about the syntax of a node and its subtree. @@ -2784,7 +2785,7 @@ namespace ts { // Scope Exclusions // - Bitmasks that exclude flags from propagating out of a specific context // into the subtree flags of their container. - NodeExcludes = TypeScript | Jsx | ES7 | ES6, + NodeExcludes = TypeScript | Jsx | ES7 | ES6 | DestructuringAssignment, ArrowFunctionExcludes = ContainsDecorators | ContainsDefaultValueAssignments | ContainsLexicalThis | ContainsParameterPropertyAssignments | ContainsBlockScopedBinding, FunctionExcludes = ContainsDecorators | ContainsDefaultValueAssignments | ContainsCapturedLexicalThis | ContainsLexicalThis | ContainsParameterPropertyAssignments | ContainsBlockScopedBinding, ConstructorExcludes = ContainsDefaultValueAssignments | ContainsLexicalThis | ContainsCapturedLexicalThis | ContainsBlockScopedBinding, diff --git a/src/compiler/utilities.ts b/src/compiler/utilities.ts index 11aa14cf5b8..9568a863503 100644 --- a/src/compiler/utilities.ts +++ b/src/compiler/utilities.ts @@ -491,19 +491,6 @@ namespace ts { return node; } - /** - * Combines the flags of a node with the combined flags of its parent if they can be combined. - */ - export function combineNodeFlags(node: Node, parentNode: Node, previousNodeFlags: NodeFlags) { - if ((node.kind === SyntaxKind.VariableDeclarationList && parentNode.kind === SyntaxKind.VariableStatement) || - (node.kind === SyntaxKind.VariableDeclaration && parentNode.kind === SyntaxKind.VariableDeclarationList) || - (node.kind === SyntaxKind.BindingElement)) { - return node.flags | previousNodeFlags; - } - - return node.flags; - } - // Returns the node flags for this node and all relevant parent nodes. This is done so that // nodes like variable declarations and binding elements can returned a view of their flags // that includes the modifiers from their container. i.e. flags like export/declare aren't @@ -948,19 +935,20 @@ namespace ts { /** * Determines whether a node is a property or element access expression for super. */ - export function isSuperPropertyOrElementAccess(node: Node): node is (PropertyAccessExpression | ElementAccessExpression) { + export function isSuperProperty(node: Node): node is (PropertyAccessExpression | ElementAccessExpression) { return (node.kind === SyntaxKind.PropertyAccessExpression || node.kind === SyntaxKind.ElementAccessExpression) && (node).expression.kind === SyntaxKind.SuperKeyword; } - /** - * Determines whether a node is a call to either `super`, or a super property or element access. - */ + export function isSuperPropertyCall(node: Node): node is CallExpression { + return node.kind === SyntaxKind.CallExpression + && isSuperProperty((node).expression); + } + export function isSuperCall(node: Node): node is CallExpression { return node.kind === SyntaxKind.CallExpression - && ((node).expression.kind === SyntaxKind.SuperKeyword - || isSuperPropertyOrElementAccess((node).expression)); + && (node).expression.kind === SyntaxKind.SuperKeyword; } export function getEntityNameFromTypeNode(node: TypeNode): EntityName | Expression { diff --git a/src/compiler/visitor.ts b/src/compiler/visitor.ts index 40568b6fa63..5bbf82865e6 100644 --- a/src/compiler/visitor.ts +++ b/src/compiler/visitor.ts @@ -134,7 +134,7 @@ namespace ts { { name: "arguments", test: isExpression }, ], [SyntaxKind.NewExpression]: [ - { name: "expression", test: isLeftHandSideExpression, parenthesize: parenthesizeForAccess }, + { name: "expression", test: isLeftHandSideExpression, parenthesize: parenthesizeForNew }, { name: "typeArguments", test: isTypeNode }, { name: "arguments", test: isExpression }, ], @@ -630,7 +630,7 @@ namespace ts { if (updated !== undefined || visited !== value) { if (updated === undefined) { - updated = getMutableNode(node); + updated = getMutableClone(node); updated.flags &= ~NodeFlags.Modifier; } From 2d2709f8a5a3923d74dd24084c65b87e777f8e8d Mon Sep 17 00:00:00 2001 From: Ron Buckton Date: Wed, 2 Mar 2016 12:05:28 -0800 Subject: [PATCH 9/9] Fixed typo in visitCallExpression --- src/compiler/printer.ts | 14 ++++++++++---- src/compiler/transformers/es6.ts | 6 +++--- src/compiler/types.ts | 1 + 3 files changed, 14 insertions(+), 7 deletions(-) diff --git a/src/compiler/printer.ts b/src/compiler/printer.ts index 331e502b931..0242437c615 100644 --- a/src/compiler/printer.ts +++ b/src/compiler/printer.ts @@ -147,6 +147,7 @@ const _super = (function (geti, seti) { let startLexicalEnvironment: () => void; let endLexicalEnvironment: () => Statement[]; let getNodeEmitFlags: (node: Node) => NodeEmitFlags; + let setNodeEmitFlags: (node: Node, flags: NodeEmitFlags) => void; let isExpressionSubstitutionEnabled: (node: Node) => boolean; let isEmitNotificationEnabled: (node: Node) => boolean; let expressionSubstitution: (node: Expression) => Expression; @@ -209,6 +210,7 @@ const _super = (function (geti, seti) { startLexicalEnvironment = undefined; endLexicalEnvironment = undefined; getNodeEmitFlags = undefined; + setNodeEmitFlags = undefined; isExpressionSubstitutionEnabled = undefined; isEmitNotificationEnabled = undefined; expressionSubstitution = undefined; @@ -230,6 +232,7 @@ const _super = (function (geti, seti) { startLexicalEnvironment = context.startLexicalEnvironment; endLexicalEnvironment = context.endLexicalEnvironment; getNodeEmitFlags = context.getNodeEmitFlags; + setNodeEmitFlags = context.setNodeEmitFlags; isExpressionSubstitutionEnabled = context.isExpressionSubstitutionEnabled; isEmitNotificationEnabled = context.isEmitNotificationEnabled; expressionSubstitution = context.expressionSubstitution; @@ -1968,10 +1971,13 @@ const _super = (function (geti, seti) { } function tryEmitSubstitute(node: Node, substitution: (node: Node) => Node) { - const substitute = substitution ? substitution(node) : node; - if (substitute && substitute !== node) { - emitWorker(substitute); - return true; + if (substitution && (getNodeEmitFlags(node) & NodeEmitFlags.NoSubstitution) === 0) { + const substitute = substitution(node); + if (substitute !== node) { + setNodeEmitFlags(substitute, NodeEmitFlags.NoSubstitution); + emitWorker(substitute); + return true; + } } return false; diff --git a/src/compiler/transformers/es6.ts b/src/compiler/transformers/es6.ts index 4db823266c9..11337d07264 100644 --- a/src/compiler/transformers/es6.ts +++ b/src/compiler/transformers/es6.ts @@ -1036,11 +1036,11 @@ namespace ts { // explicit initializer since downlevel codegen for destructuring will fail // in the absence of initializer so all binding elements will say uninitialized const name = node.name; - if (isBindingPattern(name) || node.initializer) { + if (isBindingPattern(name)) { return visitVariableDeclaration(node); } - if (shouldEmitExplicitInitializerForLetDeclaration(node)) { + if (!node.initializer && shouldEmitExplicitInitializerForLetDeclaration(node)) { const clone = getMutableClone(node); clone.initializer = createVoidZero(); return clone; @@ -1416,7 +1416,7 @@ namespace ts { // We are here either because SuperKeyword was used somewhere in the expression, or // because we contain a SpreadElementExpression. - const { target, thisArg } = createCallBinding(node); + const { target, thisArg } = createCallBinding(node.expression); if (node.transformFlags & TransformFlags.ContainsSpreadElementExpression) { // [source] // f(...a, b) diff --git a/src/compiler/types.ts b/src/compiler/types.ts index da0f983298f..516e90af2dd 100644 --- a/src/compiler/types.ts +++ b/src/compiler/types.ts @@ -2809,6 +2809,7 @@ namespace ts { AdviseOnEmitNode = 1 << 7, // The node printer should invoke the onBeforeEmitNode and onAfterEmitNode callbacks when printing this node. IsNotEmittedNode = 1 << 8, // Is a node that is not emitted but whose comments should be preserved if possible. EmitCommentsOfNotEmittedParent = 1 << 9, // Emits comments of missing parent nodes. + NoSubstitution = 1 << 10, // Disables further substitution of an expression. } /** Additional context provided to `visitEachChild` */