From e35dd79c041c2bb46e2f65c0c0cd3bb3be055a38 Mon Sep 17 00:00:00 2001 From: Yui Date: Thu, 2 Jun 2016 10:57:28 -0700 Subject: [PATCH] [Transforms] Update baselines from merging with master round 2 (#8926) * update baselines from merging with master * Correctly fix#8786 * Fix up linting errors * Fix spelling error in comment * Remove usage of null * Revert "Remove usage of null" This reverts commit d9102d1e3f28d4f2791b7eb99c737e0004f01463. * Disable using null in unittest as we use null to signal to not generate baselines * Remove setting disable comment as we already done so in createCommentWriter * Address linting * Fix travis failure * Fix travis failure --- Jakefile.js | 3 +- src/compiler/binder.ts | 2 +- src/compiler/comments.ts | 3 - src/compiler/printer.ts | 15 +--- src/compiler/transformers/ts.ts | 75 ++++++++++--------- src/harness/harness.ts | 2 +- src/harness/projectsRunner.ts | 2 +- ...omputedPropertyNamesContextualType7_ES5.js | 36 ++++----- .../reference/decoratorOnClass6.es6.js | 16 ++-- .../parameterReferenceInInitializer1.js | 4 +- tests/cases/unittests/jsDocParsing.ts | 18 ++--- tests/cases/unittests/transpile.ts | 4 + 12 files changed, 88 insertions(+), 92 deletions(-) diff --git a/Jakefile.js b/Jakefile.js index 3652b41cfc7..b853cecb8d7 100644 --- a/Jakefile.js +++ b/Jakefile.js @@ -782,7 +782,8 @@ function runTestsAndWriteOutput(file, defaultSubsets) { subsets = []; subsetRegexes = []; negations = []; - for (const subset of defaultSubsets) { + for (var i = 0; i < defaultSubsets.length; ++i) { + var subset = defaultSubsets[i]; subsets.push(subset.name); subsetRegexes.push(subset.pattern); negations.push(subset.pattern); diff --git a/src/compiler/binder.ts b/src/compiler/binder.ts index b01c2e6efc3..191479b1fae 100644 --- a/src/compiler/binder.ts +++ b/src/compiler/binder.ts @@ -506,7 +506,7 @@ namespace ts { container = saveContainer; blockScopeContainer = savedBlockScopeContainer; } - + function bindChildren(node: Node): void { if (skipTransformFlagAggregation) { bindChildrenWorker(node); diff --git a/src/compiler/comments.ts b/src/compiler/comments.ts index 57611d1498a..f60260a19a1 100644 --- a/src/compiler/comments.ts +++ b/src/compiler/comments.ts @@ -24,8 +24,6 @@ namespace ts { let currentLineMap: number[]; let detachedCommentsInfo: { nodePos: number, detachedCommentEndPos: number}[]; let hasWrittenComment = false; - let hasLastComment: boolean; - let lastCommentEnd: number; let disabled: boolean = compilerOptions.removeComments; return { @@ -287,7 +285,6 @@ namespace ts { currentText = currentSourceFile.text; currentLineMap = getLineStarts(currentSourceFile); detachedCommentsInfo = undefined; - disabled = false; } function disableCommentsAndEmit(node: Node, emitCallback: (node: Node) => void): void { diff --git a/src/compiler/printer.ts b/src/compiler/printer.ts index 6a72181373a..4a8b1d6b1e9 100644 --- a/src/compiler/printer.ts +++ b/src/compiler/printer.ts @@ -389,19 +389,6 @@ const _super = (function (geti, seti) { || (getNodeEmitFlags(node) & NodeEmitFlags.NoLeadingComments) !== 0; } - /** - * Determines whether to skip trailing comment emit for a node. - * - * We do not emit comments for NotEmittedStatement nodes or any node that has - * NodeEmitFlags.NoTrailingComments. - * - * @param node A Node. - */ - function shouldSkipTrailingCommentsForNode(node: Node) { - return isNotEmittedStatement(node) - || (getNodeEmitFlags(node) & NodeEmitFlags.NoTrailingComments) !== 0; - } - /** * Determines whether to skip source map emit for the start position of a node. * @@ -2897,7 +2884,7 @@ const _super = (function (geti, seti) { // Other PreferNewLine = 1 << 15, // Prefer adding a LineTerminator between synthesized nodes. NoTrailingNewLine = 1 << 16, // Do not emit a trailing NewLine for a MultiLine list. - NoInterveningComments = 1 << 17,// Do not emit comments between each node + NoInterveningComments = 1 << 17, // Do not emit comments between each node // Precomputed Formats Modifiers = SingleLine | SpaceBetweenSiblings, diff --git a/src/compiler/transformers/ts.ts b/src/compiler/transformers/ts.ts index d11b2f5663d..4df58376b3c 100644 --- a/src/compiler/transformers/ts.ts +++ b/src/compiler/transformers/ts.ts @@ -570,17 +570,17 @@ namespace ts { // --------------------------------------------------------------------- // 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; | } + // @dec | let C_1 = class C { + // class C { | static x() { return C_1.y; } + // static x() { return C.y; } | } + // static y = 1; | let C = C_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; | } + // @dec | let C_1 = class C { + // export class C { | static x() { return C_1.y; } + // static x() { return C.y; } | } + // static y = 1; | let C = C_1; // } | C.y = 1; // | C = C_1 = __decorate([dec], C); // | export { C }; @@ -612,10 +612,10 @@ namespace ts { // --------------------------------------------------------------------- // 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; | } + // @dec | let C_1 = class C { + // export default class C { | static x() { return C_1.y; } + // static x() { return C.y; } | } + // static y = 1; | let C = C_1; // } | C.y = 1; // | C = C_1 = __decorate([dec], C); // | export default C; @@ -627,7 +627,7 @@ namespace ts { // ... = class ${name} ${heritageClauses} { // ${members} // } - let classExpression: Expression = setOriginalNode( + const classExpression: Expression = setOriginalNode( createClassExpression( name, visitNodes(node.heritageClauses, visitor, isHeritageClause), @@ -647,35 +647,19 @@ namespace ts { enableSubstitutionForDecoratedClasses(); 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, - createLetDeclarationList([ - createVariableDeclaration(decoratedClassAlias) - ]) - ) - ); - - // ${decoratedClassAlias} = ${classExpression} - classExpression = createAssignment( - decoratedClassAlias, - classExpression, - /*location*/ location); } - // let ${name} = ${classExpression}; + const declaredName = getDeclarationName(node, /*allowComments*/ true); + + // let ${name} = ${classExpression} where name is either declaredName if the class doesn't contain self-reference + // or decoratedClassAlias if the class contain self-reference. addNode(statements, setOriginalNode( createVariableStatement( /*modifiers*/ undefined, createLetDeclarationList([ createVariableDeclaration( - getDeclarationName(node, /*allowComments*/ true), + decoratedClassAlias || declaredName, /*type*/ undefined, classExpression ) @@ -686,6 +670,29 @@ namespace ts { ) ); + if (decoratedClassAlias) { + // We emit the class alias as a `let` declaration here so that it has the same + // TDZ as the class. + + // let ${declaredName} = ${decoratedClassAlias} + addNode(statements, + setOriginalNode( + createVariableStatement( + /*modifiers*/ undefined, + createLetDeclarationList([ + createVariableDeclaration( + declaredName, + /*type*/ undefined, + decoratedClassAlias + ) + ]), + /*location*/ location + ), + /*original*/ node + ) + ); + } + return decoratedClassAlias; } diff --git a/src/harness/harness.ts b/src/harness/harness.ts index 49dcab4d80b..caafe629f30 100644 --- a/src/harness/harness.ts +++ b/src/harness/harness.ts @@ -769,7 +769,7 @@ namespace Harness { return response.responseText; } else { - return null; + return undefined; } } diff --git a/src/harness/projectsRunner.ts b/src/harness/projectsRunner.ts index 21f3f144b74..4bfd75c1dd0 100644 --- a/src/harness/projectsRunner.ts +++ b/src/harness/projectsRunner.ts @@ -472,7 +472,7 @@ class ProjectRunner extends RunnerBase { it("Baseline of emitted result (" + moduleNameToString(moduleKind) + "): " + testCaseFileName, () => { if (testCase.baselineCheck) { - var lastError: any = undefined; + let lastError: any = undefined; ts.forEach(compilerResult.outputFiles, outputFile => { try { Harness.Baseline.runBaseline("Baseline of emitted result (" + moduleNameToString(compilerResult.moduleKind) + "): " + testCaseFileName, getBaselineFolder(compilerResult.moduleKind) + outputFile.fileName, () => { diff --git a/tests/baselines/reference/computedPropertyNamesContextualType7_ES5.js b/tests/baselines/reference/computedPropertyNamesContextualType7_ES5.js index 2eddbbed14c..14165302d3b 100644 --- a/tests/baselines/reference/computedPropertyNamesContextualType7_ES5.js +++ b/tests/baselines/reference/computedPropertyNamesContextualType7_ES5.js @@ -1,22 +1,22 @@ //// [computedPropertyNamesContextualType7_ES5.ts] -interface I { - [n: number]: T; -} -interface J { - [s: string]: T; -} - -declare function foo(obj: I): T; -declare function g(obj: J): T; - -foo({ - 0: () => { }, - ["hi" + "bye"]: true, - [0 + 1]: 0, - [+"hi"]: [0] -}); - -g({ p: "" }); +interface I { + [n: number]: T; +} +interface J { + [s: string]: T; +} + +declare function foo(obj: I): T; +declare function g(obj: J): T; + +foo({ + 0: () => { }, + ["hi" + "bye"]: true, + [0 + 1]: 0, + [+"hi"]: [0] +}); + +g({ p: "" }); //// [computedPropertyNamesContextualType7_ES5.js] diff --git a/tests/baselines/reference/decoratorOnClass6.es6.js b/tests/baselines/reference/decoratorOnClass6.es6.js index 4e4197bb601..fff39d85916 100644 --- a/tests/baselines/reference/decoratorOnClass6.es6.js +++ b/tests/baselines/reference/decoratorOnClass6.es6.js @@ -1,12 +1,12 @@ //// [decoratorOnClass6.es6.ts] -declare function dec(target: T): T; - -@dec -export class C { - static x() { return C.y; } - static y = 1; -} - +declare function dec(target: T): T; + +@dec +export class C { + static x() { return C.y; } + static y = 1; +} + let c = new C(); //// [decoratorOnClass6.es6.js] diff --git a/tests/baselines/reference/parameterReferenceInInitializer1.js b/tests/baselines/reference/parameterReferenceInInitializer1.js index ee49eb83fe1..c1ebb1722d6 100644 --- a/tests/baselines/reference/parameterReferenceInInitializer1.js +++ b/tests/baselines/reference/parameterReferenceInInitializer1.js @@ -19,8 +19,8 @@ function fn(y, set) { var C = (function () { function C(y, x // expected to work, but actually doesn't ) { - if (x === void 0) { x = fn(y, function (y, x) { return y.x = x; }); } - this.x = x; + if (x === void 0) { x = fn(y, function (y, x) { return y.x = x; }); } // expected to work, but actually doesn't + this.x = x; // expected to work, but actually doesn't } return C; }()); diff --git a/tests/cases/unittests/jsDocParsing.ts b/tests/cases/unittests/jsDocParsing.ts index a99f1bad881..f87b20f804f 100644 --- a/tests/cases/unittests/jsDocParsing.ts +++ b/tests/cases/unittests/jsDocParsing.ts @@ -3,7 +3,7 @@ /// /// -module ts { +namespace ts { describe("JSDocParsing", () => { describe("TypeExpressions", () => { function parsesCorrectly(name: string, content: string) { @@ -95,10 +95,10 @@ module ts { it(name, () => { const comment = parseIsolatedJSDocComment(content); if (!comment) { - Debug.fail('Comment failed to parse entirely'); + Debug.fail("Comment failed to parse entirely"); } if (comment.diagnostics.length > 0) { - Debug.fail('Comment has at least one diagnostic: ' + comment.diagnostics[0].messageText); + Debug.fail("Comment has at least one diagnostic: " + comment.diagnostics[0].messageText); } Harness.Baseline.runBaseline("parseCorrectly", "JSDocParsing/DocComments.parsesCorrectly." + name + ".json", @@ -118,29 +118,29 @@ module ts { parsesIncorrectly("emptyComment", "/***/"); parsesIncorrectly("threeAsterisks", "/*** */"); parsesIncorrectly("asteriskAfterPreamble", "/** * @type {number} */"); - parsesIncorrectly("multipleTypes", + parsesIncorrectly("multipleTypes", `/** * @type {number} * @type {string} */`); - parsesIncorrectly("multipleReturnTypes", + parsesIncorrectly("multipleReturnTypes", `/** * @return {number} * @return {string} */`); - parsesIncorrectly("noTypeParameters", + parsesIncorrectly("noTypeParameters", `/** * @template */`); - parsesIncorrectly("trailingTypeParameterComma", + parsesIncorrectly("trailingTypeParameterComma", `/** * @template T, */`); - parsesIncorrectly("paramWithoutName", + parsesIncorrectly("paramWithoutName", `/** * @param {number} */`); - parsesIncorrectly("paramWithoutTypeOrName", + parsesIncorrectly("paramWithoutTypeOrName", `/** * @param */`); diff --git a/tests/cases/unittests/transpile.ts b/tests/cases/unittests/transpile.ts index af275b545c0..67db6ea5333 100644 --- a/tests/cases/unittests/transpile.ts +++ b/tests/cases/unittests/transpile.ts @@ -64,7 +64,9 @@ namespace ts { it("Correct errors for " + justName, () => { Harness.Baseline.runBaseline("Correct errors", justName.replace(/\.tsx?$/, ".errors.txt"), () => { if (transpileResult.diagnostics.length === 0) { + /* tslint:disable:no-null-keyword */ return null; + /* tslint:enable:no-null-keyword */ } return Harness.Compiler.getErrorBaseline(toBeCompiled, transpileResult.diagnostics); @@ -75,7 +77,9 @@ namespace ts { it("Correct errors (old transpile) for " + justName, () => { Harness.Baseline.runBaseline("Correct errors", justName.replace(/\.tsx?$/, ".oldTranspile.errors.txt"), () => { if (oldTranspileDiagnostics.length === 0) { + /* tslint:disable:no-null-keyword */ return null; + /* tslint:enable:no-null-keyword */ } return Harness.Compiler.getErrorBaseline(toBeCompiled, oldTranspileDiagnostics);