From 9d2f0b37c0b67741398b0f812a720bbc1cdf1343 Mon Sep 17 00:00:00 2001 From: Ron Buckton Date: Thu, 7 Apr 2016 12:27:44 -0700 Subject: [PATCH 01/58] Emits class name with comments. --- src/compiler/transformers/es6.ts | 2 +- .../variableDeclaratorResolvedDuringContextualTyping.js | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/compiler/transformers/es6.ts b/src/compiler/transformers/es6.ts index d8bbdd4c326..7c4081c54bf 100644 --- a/src/compiler/transformers/es6.ts +++ b/src/compiler/transformers/es6.ts @@ -549,7 +549,7 @@ namespace ts { /*modifiers*/ undefined, createVariableDeclarationList([ createVariableDeclaration( - getDeclarationName(node), + node.name || getGeneratedNameForNode(node), transformClassLikeDeclarationToExpression(node) ) ]), diff --git a/tests/baselines/reference/variableDeclaratorResolvedDuringContextualTyping.js b/tests/baselines/reference/variableDeclaratorResolvedDuringContextualTyping.js index 692c4e3aebe..ed6111ec3c5 100644 --- a/tests/baselines/reference/variableDeclaratorResolvedDuringContextualTyping.js +++ b/tests/baselines/reference/variableDeclaratorResolvedDuringContextualTyping.js @@ -132,11 +132,11 @@ var WinJS; var Errors; (function (Errors) { var ConnectionError /* extends Error */ = (function () { - function ConnectionError /* extends Error */(request) { + function ConnectionError(request) { } - return ConnectionError /* extends Error */; + return ConnectionError; }()); - Errors.ConnectionError /* extends Error */ = ConnectionError /* extends Error */; + Errors.ConnectionError = ConnectionError; })(Errors || (Errors = {})); var FileService = (function () { function FileService() { From cbc2452409630a9b23152513f7478f16bb35567f Mon Sep 17 00:00:00 2001 From: Ron Buckton Date: Thu, 7 Apr 2016 14:25:24 -0700 Subject: [PATCH 02/58] Changed getDeclarationName to allow comments if requested --- src/compiler/transformers/es6.ts | 23 ++++++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) diff --git a/src/compiler/transformers/es6.ts b/src/compiler/transformers/es6.ts index 7c4081c54bf..60dce220593 100644 --- a/src/compiler/transformers/es6.ts +++ b/src/compiler/transformers/es6.ts @@ -549,7 +549,7 @@ namespace ts { /*modifiers*/ undefined, createVariableDeclarationList([ createVariableDeclaration( - node.name || getGeneratedNameForNode(node), + getDeclarationName(node, /*allowComments*/ true), transformClassLikeDeclarationToExpression(node) ) ]), @@ -2688,8 +2688,25 @@ namespace ts { return node; } - function getDeclarationName(node: ClassExpression | ClassDeclaration | FunctionDeclaration) { - return node.name ? getSynthesizedClone(node.name) : getGeneratedNameForNode(node); + /** + * Gets the name of a declaration, without source map or comments. + * + * @param node The declaration. + * @param allowComments Allow comments for the name. + */ + function getDeclarationName(node: DeclarationStatement | ClassExpression, allowComments?: boolean) { + if (node.name) { + const name = getMutableClone(node.name); + let flags = NodeEmitFlags.NoSourceMap; + if (!allowComments) { + flags |= NodeEmitFlags.NoComments; + } + + setNodeEmitFlags(name, flags | getNodeEmitFlags(name)); + return name; + } + + return getGeneratedNameForNode(node); } function getClassMemberPrefix(node: ClassExpression | ClassDeclaration, member: ClassElement) { From 3507ed021c504196fbab625f51db919a9ad7e209 Mon Sep 17 00:00:00 2001 From: Ron Buckton Date: Thu, 7 Apr 2016 16:13:28 -0700 Subject: [PATCH 03/58] Fixes issues that were causing runtests-browser to fail --- Jakefile.js | 2 +- scripts/browserify-optional.js | 24 ++++++++++++++++++++++++ src/compiler/program.ts | 5 +++-- src/compiler/sys.ts | 5 ++--- src/compiler/types.ts | 1 + src/compiler/utilities.ts | 12 ++++++++++++ src/harness/harness.ts | 2 +- 7 files changed, 44 insertions(+), 7 deletions(-) create mode 100644 scripts/browserify-optional.js diff --git a/Jakefile.js b/Jakefile.js index 53c6bb964b0..191441dbe36 100644 --- a/Jakefile.js +++ b/Jakefile.js @@ -909,7 +909,7 @@ compileFile(nodeServerOutFile, [nodeServerInFile], [builtLocalDirectory, tscFile desc("Runs browserify on run.js to produce a file suitable for running tests in the browser"); task("browserify", ["tests", builtLocalDirectory, nodeServerOutFile], function() { - var cmd = 'browserify built/local/run.js -o built/local/bundle.js'; + var cmd = 'browserify built/local/run.js -t ./scripts/browserify-optional -o built/local/bundle.js'; exec(cmd); }, {async: true}); diff --git a/scripts/browserify-optional.js b/scripts/browserify-optional.js new file mode 100644 index 00000000000..43997c7803c --- /dev/null +++ b/scripts/browserify-optional.js @@ -0,0 +1,24 @@ +// simple script to optionally elide source-map-support (or other optional modules) when running browserify. + +var stream = require("stream"), + Transform = stream.Transform, + resolve = require("browser-resolve"); + +var requirePattern = /require\s*\(\s*['"](source-map-support)['"]\s*\)/; +module.exports = function (file) { + return new Transform({ + transform: function (data, encoding, cb) { + var text = encoding === "buffer" ? data.toString("utf8") : data; + this.push(new Buffer(text.replace(requirePattern, function (originalText, moduleName) { + try { + resolve.sync(moduleName, { filename: file }); + return originalText; + } + catch (e) { + return "(function () { throw new Error(\"module '" + moduleName + "' not found.\"); })()"; + } + }), "utf8")); + cb(); + } + }); +}; \ No newline at end of file diff --git a/src/compiler/program.ts b/src/compiler/program.ts index 17155281dbb..a3c2320e833 100644 --- a/src/compiler/program.ts +++ b/src/compiler/program.ts @@ -644,7 +644,8 @@ namespace ts { fileExists: fileName => sys.fileExists(fileName), readFile: fileName => sys.readFile(fileName), trace: (s: string) => sys.write(s + newLine), - directoryExists: directoryName => sys.directoryExists(directoryName) + directoryExists: directoryName => sys.directoryExists(directoryName), + getEnvironmentVariable: sys.getEnvironmentVariable }; } @@ -995,7 +996,7 @@ namespace ts { const start = new Date().getTime(); // TODO(rbuckton): remove USE_TRANSFORMS condition when we switch to transforms permanently. - if (/^(y(es)?|t(rue|ransforms?)?|1|\+)$/i.test(sys.getEnvironmentVariable("USE_TRANSFORMS"))) { + if (/^(y(es)?|t(rue|ransforms?)?|1|\+)$/i.test(getEnvironmentVariable("USE_TRANSFORMS", host))) { options.experimentalTransforms = true; } diff --git a/src/compiler/sys.ts b/src/compiler/sys.ts index fce9408caf0..416eca8880d 100644 --- a/src/compiler/sys.ts +++ b/src/compiler/sys.ts @@ -74,6 +74,7 @@ namespace ts { readDirectory(path: string, extension?: string, exclude?: string[]): string[]; watchFile?(path: string, callback: FileWatcherCallback): FileWatcher; watchDirectory?(path: string, callback: DirectoryWatcherCallback, recursive?: boolean): FileWatcher; + getEnvironmentVariable?(name: string): string; }; export var sys: System = (function () { @@ -632,9 +633,7 @@ namespace ts { createDirectory: ChakraHost.createDirectory, getExecutingFilePath: () => ChakraHost.executingFile, getCurrentDirectory: () => ChakraHost.currentDirectory, - getEnvironmentVariable(name: string) { - return ""; - }, + getEnvironmentVariable: ChakraHost.getEnvironmentVariable || ((name: string) => ""), readDirectory: ChakraHost.readDirectory, exit: ChakraHost.quit, }; diff --git a/src/compiler/types.ts b/src/compiler/types.ts index ad304ac8150..b303f09f82d 100644 --- a/src/compiler/types.ts +++ b/src/compiler/types.ts @@ -2805,6 +2805,7 @@ namespace ts { * 'throw new Error("NotImplemented")' */ resolveModuleNames?(moduleNames: string[], containingFile: string): ResolvedModule[]; + getEnvironmentVariable?(name: string): string; } /* @internal */ diff --git a/src/compiler/utilities.ts b/src/compiler/utilities.ts index 0504aca9223..aaaf699834d 100644 --- a/src/compiler/utilities.ts +++ b/src/compiler/utilities.ts @@ -169,6 +169,18 @@ namespace ts { return `${ file.fileName }(${ loc.line + 1 },${ loc.character + 1 })`; } + export function getEnvironmentVariable(name: string, host?: CompilerHost) { + if (host && host.getEnvironmentVariable) { + return host.getEnvironmentVariable(name); + } + + if (sys && sys.getEnvironmentVariable) { + return sys.getEnvironmentVariable(name); + } + + return ""; + } + export function getStartPosOfNode(node: Node): number { return node.pos; } diff --git a/src/harness/harness.ts b/src/harness/harness.ts index 5d8e051124c..c77599bb659 100644 --- a/src/harness/harness.ts +++ b/src/harness/harness.ts @@ -1681,7 +1681,7 @@ namespace Harness { if (Error) (Error).stackTraceLimit = 1; } -if (ts.sys.tryEnableSourceMapsForHost && /^development$/i.test(ts.sys.getEnvironmentVariable("NODE_ENV"))) { +if (ts.sys && ts.sys.tryEnableSourceMapsForHost && /^development$/i.test(ts.sys.getEnvironmentVariable("NODE_ENV"))) { ts.sys.tryEnableSourceMapsForHost(); } From 018a0d1d3a47b2e75a07cb079fee6a287612f0a8 Mon Sep 17 00:00:00 2001 From: Ron Buckton Date: Thu, 7 Apr 2016 16:56:22 -0700 Subject: [PATCH 04/58] Adds IO mappings for tryEnableSourceMapsForHost --- src/harness/harness.ts | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/src/harness/harness.ts b/src/harness/harness.ts index c77599bb659..27dc06135fc 100644 --- a/src/harness/harness.ts +++ b/src/harness/harness.ts @@ -480,6 +480,8 @@ namespace Harness { getExecutingFilePath(): string; exit(exitCode?: number): void; readDirectory(path: string, extension?: string, exclude?: string[]): string[]; + tryEnableSourceMapsForHost?(): void; + getEnvironmentVariable?(name: string): string; } export var IO: IO; @@ -518,6 +520,7 @@ namespace Harness { export const fileExists: typeof IO.fileExists = fso.FileExists; export const log: typeof IO.log = global.WScript && global.WScript.StdOut.WriteLine; export const readDirectory: typeof IO.readDirectory = (path, extension, exclude) => ts.sys.readDirectory(path, extension, exclude); + export const getEnvironmentVariable: typeof IO.getEnvironmentVariable = name => ts.sys.getEnvironmentVariable(name); export function createDirectory(path: string) { if (directoryExists(path)) { @@ -587,6 +590,13 @@ namespace Harness { export const log: typeof IO.log = s => console.log(s); export const readDirectory: typeof IO.readDirectory = (path, extension, exclude) => ts.sys.readDirectory(path, extension, exclude); + export const getEnvironmentVariable: typeof IO.getEnvironmentVariable = name => ts.sys.getEnvironmentVariable(name); + + export function tryEnableSourceMapsForHost() { + if (ts.sys.tryEnableSourceMapsForHost) { + ts.sys.tryEnableSourceMapsForHost(); + } + } export function createDirectory(path: string) { if (!directoryExists(path)) { @@ -1681,8 +1691,8 @@ namespace Harness { if (Error) (Error).stackTraceLimit = 1; } -if (ts.sys && ts.sys.tryEnableSourceMapsForHost && /^development$/i.test(ts.sys.getEnvironmentVariable("NODE_ENV"))) { - ts.sys.tryEnableSourceMapsForHost(); +if (Harness.IO.tryEnableSourceMapsForHost && /^development$/i.test(Harness.IO.getEnvironmentVariable("NODE_ENV"))) { + Harness.IO.tryEnableSourceMapsForHost(); } // TODO: not sure why Utils.evalFile isn't working with this, eventually will concat it like old compiler instead of eval From 1aa69921c6a7abd7e9b1e082e7f798845f9dcef9 Mon Sep 17 00:00:00 2001 From: Ron Buckton Date: Thu, 7 Apr 2016 17:07:12 -0700 Subject: [PATCH 05/58] Makes transforms the default --- Jakefile.js | 4 ++-- src/compiler/commandLineParser.ts | 7 +++---- src/compiler/core.ts | 4 ++-- src/compiler/diagnosticMessages.json | 4 ++++ src/compiler/program.ts | 9 +++++---- src/compiler/types.ts | 2 +- 6 files changed, 17 insertions(+), 13 deletions(-) diff --git a/Jakefile.js b/Jakefile.js index 191441dbe36..c88d6933d55 100644 --- a/Jakefile.js +++ b/Jakefile.js @@ -309,8 +309,8 @@ function compileFile(outFile, sources, prereqs, prefixes, useBuiltCompiler, opts options += " --stripInternal" } - if (useBuiltCompiler && Boolean(process.env.USE_TRANSFORMS)) { - console.warn("\u001b[93mwarning: Found 'USE_TRANSFORMS' environment variable. Experimental transforms will be enabled by default.\u001b[0m"); + if (useBuiltCompiler && !/^(no?|f(alse)?|0|-)$/i.test(process.env.USE_TRANSFORMS)) { + console.warn("\u001b[93mwarning: 'USE_TRANSFORMS' environment variable is not set to 'false'. Experimental transforms will be enabled by default.\u001b[0m"); } var cmd = host + " " + compilerPath + " " + options + " "; diff --git a/src/compiler/commandLineParser.ts b/src/compiler/commandLineParser.ts index 21e84f5fddc..32423d08d1b 100644 --- a/src/compiler/commandLineParser.ts +++ b/src/compiler/commandLineParser.ts @@ -333,11 +333,10 @@ namespace ts { description: Diagnostics.Do_not_emit_use_strict_directives_in_module_output }, { - // 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: "experimentalTransforms", + name: "useLegacyEmitter", type: "boolean", - experimental: true + experimental: true, + description: Diagnostics.Use_the_legacy_emitter_instead_of_the_transforming_emitter } ]; diff --git a/src/compiler/core.ts b/src/compiler/core.ts index ca3f76eeaed..bae17c642d2 100644 --- a/src/compiler/core.ts +++ b/src/compiler/core.ts @@ -1105,11 +1105,11 @@ namespace ts { return currentAssertionLevel; } - const developmentMode = sys && /^development$/i.test(sys.getEnvironmentVariable("NODE_ENV")); - if (developmentMode === undefined) { + if (sys === undefined) { return AssertionLevel.None; } + const developmentMode = /^development$/i.test(getEnvironmentVariable("NODE_ENV")); currentAssertionLevel = developmentMode ? AssertionLevel.Normal : AssertionLevel.None; diff --git a/src/compiler/diagnosticMessages.json b/src/compiler/diagnosticMessages.json index b8dd62efa8e..1410cd41428 100644 --- a/src/compiler/diagnosticMessages.json +++ b/src/compiler/diagnosticMessages.json @@ -2604,6 +2604,10 @@ "category": "Message", "code": 6112 }, + "Use the legacy emitter instead of the transforming emitter.": { + "category": "Message", + "code": 6113 + }, "Variable '{0}' implicitly has an '{1}' type.": { "category": "Error", "code": 7005 diff --git a/src/compiler/program.ts b/src/compiler/program.ts index a3c2320e833..7c1db7d1032 100644 --- a/src/compiler/program.ts +++ b/src/compiler/program.ts @@ -645,7 +645,7 @@ namespace ts { readFile: fileName => sys.readFile(fileName), trace: (s: string) => sys.write(s + newLine), directoryExists: directoryName => sys.directoryExists(directoryName), - getEnvironmentVariable: sys.getEnvironmentVariable + getEnvironmentVariable: name => getEnvironmentVariable(name, /*host*/ undefined) }; } @@ -996,11 +996,12 @@ namespace ts { const start = new Date().getTime(); // TODO(rbuckton): remove USE_TRANSFORMS condition when we switch to transforms permanently. - if (/^(y(es)?|t(rue|ransforms?)?|1|\+)$/i.test(getEnvironmentVariable("USE_TRANSFORMS", host))) { - options.experimentalTransforms = true; + let useLegacyEmitter = options.useLegacyEmitter; + if (/^(no?|f(alse)?|0|-)$/i.test(getEnvironmentVariable("USE_TRANSFORMS", host))) { + useLegacyEmitter = true; } - const fileEmitter = options.experimentalTransforms ? printFiles : emitFiles; + const fileEmitter = useLegacyEmitter ? emitFiles : printFiles; const emitResult = fileEmitter( emitResolver, getEmitHost(writeFileCallback), diff --git a/src/compiler/types.ts b/src/compiler/types.ts index b303f09f82d..7723abfe270 100644 --- a/src/compiler/types.ts +++ b/src/compiler/types.ts @@ -2498,7 +2498,7 @@ namespace ts { noImplicitUseStrict?: boolean; lib?: string[]; /* @internal */ stripInternal?: boolean; - /* @internal */ experimentalTransforms?: boolean; + /* @internal */ useLegacyEmitter?: boolean; // Skip checking lib.d.ts to help speed up tests. /* @internal */ skipDefaultLibCheck?: boolean; From dc30aa37da3d63c5f94b84dacbc15be79499f4e0 Mon Sep 17 00:00:00 2001 From: Ron Buckton Date: Thu, 7 Apr 2016 18:22:49 -0700 Subject: [PATCH 06/58] Fixes detached comment emit for constructors --- src/compiler/transformers/es6.ts | 9 ++++++++- src/compiler/transformers/ts.ts | 8 +++++++- 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/src/compiler/transformers/es6.ts b/src/compiler/transformers/es6.ts index f93c69b8d69..82b60cf8a08 100644 --- a/src/compiler/transformers/es6.ts +++ b/src/compiler/transformers/es6.ts @@ -735,7 +735,14 @@ namespace ts { } addRange(statements, endLexicalEnvironment()); - return createBlock(statements, /*location*/ constructor && constructor.body, /*multiLine*/ true); + return createBlock( + createNodeArray( + statements, + /*location*/ constructor ? constructor.body.statements : undefined + ), + /*location*/ constructor ? constructor.body : undefined, + /*multiLine*/ true + ); } function transformConstructorBodyWithSynthesizedSuper(node: ConstructorDeclaration) { diff --git a/src/compiler/transformers/ts.ts b/src/compiler/transformers/ts.ts index a2fc0b56763..0b8c11a66e2 100644 --- a/src/compiler/transformers/ts.ts +++ b/src/compiler/transformers/ts.ts @@ -829,7 +829,13 @@ namespace ts { // End the lexical environment. addNodes(statements, endLexicalEnvironment()); return setMultiLine( - createBlock(statements, constructor ? constructor.body : undefined), + createBlock( + createNodeArray( + statements, + /*location*/ constructor ? constructor.body.statements : undefined + ), + /*location*/ constructor ? constructor.body : undefined + ), true ); } From 1696446b54ced7a34a8c4125096260e0de80acee Mon Sep 17 00:00:00 2001 From: Ron Buckton Date: Fri, 8 Apr 2016 10:39:59 -0700 Subject: [PATCH 07/58] Fixes comment emit for super property call --- src/compiler/factory.ts | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/compiler/factory.ts b/src/compiler/factory.ts index 4c07e227398..0b32988a6ee 100644 --- a/src/compiler/factory.ts +++ b/src/compiler/factory.ts @@ -1163,11 +1163,11 @@ namespace ts { let thisArg: Expression; let target: LeftHandSideExpression; if (isSuperProperty(callee)) { - thisArg = createThis(/*location*/ callee.expression); + thisArg = createThis(); target = callee; } else if (callee.kind === SyntaxKind.SuperKeyword) { - thisArg = createThis(/*location*/ callee); + thisArg = createThis(); target = languageVersion < ScriptTarget.ES6 ? createIdentifier("_super", /*location*/ callee) : callee; } else { @@ -1180,15 +1180,15 @@ namespace ts { createAssignment( thisArg, (callee).expression, - /*location*/(callee).expression + /*location*/ (callee).expression ), (callee).name, - /*location*/ callee + /*location*/ callee ); } else { thisArg = (callee).expression; - target = callee; + target = callee; } break; } @@ -1201,10 +1201,10 @@ namespace ts { createAssignment( thisArg, (callee).expression, - /*location*/(callee).expression + /*location*/ (callee).expression ), (callee).argumentExpression, - /*location*/ callee + /*location*/ callee ); } else { From 381c0260ff919a9d9e3da93ac820726276bed64a Mon Sep 17 00:00:00 2001 From: Yui Date: Fri, 8 Apr 2016 11:30:08 -0700 Subject: [PATCH 08/58] Accept correct baseline (#7967) --- tests/baselines/reference/superInObjectLiterals_ES5.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tests/baselines/reference/superInObjectLiterals_ES5.js b/tests/baselines/reference/superInObjectLiterals_ES5.js index f701ca7df7b..5d1fed24b4f 100644 --- a/tests/baselines/reference/superInObjectLiterals_ES5.js +++ b/tests/baselines/reference/superInObjectLiterals_ES5.js @@ -65,6 +65,7 @@ var __extends = (this && this.__extends) || function (d, b) { function __() { this.constructor = d; } d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); }; +var _this = this; var obj = { __proto__: { method: function () { @@ -87,7 +88,7 @@ var obj = { _super.method.call(this); }, p3: function () { - _super.method.call(this); + _super.method.call(_this); } }; var A = (function () { From 6f766c2872c1c43e96b2692ac3bf07a38b32e877 Mon Sep 17 00:00:00 2001 From: Nathan Shively-Sanders Date: Fri, 8 Apr 2016 12:50:07 -0700 Subject: [PATCH 09/58] Correct destructuring assignment to empty object Previously, chained destructuring object assignments would fail when the leftmost target was empty because the shortcut code would forget to check whether the right-hand side was also a destructuring assignment. --- src/compiler/transformers/destructuring.ts | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/src/compiler/transformers/destructuring.ts b/src/compiler/transformers/destructuring.ts index 7cd37bade6c..06e8a354d85 100644 --- a/src/compiler/transformers/destructuring.ts +++ b/src/compiler/transformers/destructuring.ts @@ -17,10 +17,16 @@ namespace ts { node: BinaryExpression, needsValue: boolean, recordTempVariable: (node: Identifier) => void, - visitor?: (node: Node) => VisitResult) { + visitor?: (node: Node) => VisitResult): Expression { if (isEmptyObjectLiteralOrArrayLiteral(node.left)) { - return node.right; + const right = node.right; + if (isDestructuringAssignment(right)) { + return flattenDestructuringAssignment(context, right, needsValue, recordTempVariable, visitor); + } + else { + return node.right; + } } let location: TextRange = node; @@ -401,4 +407,4 @@ namespace ts { return emitTempVariableAssignment(value, location); } } -} \ No newline at end of file +} From 43051eab84e093ac4a20f9db60c85d04e83f7bf3 Mon Sep 17 00:00:00 2001 From: Vladimir Matveev Date: Fri, 8 Apr 2016 14:29:16 -0700 Subject: [PATCH 10/58] emit export star only if export will yield anything with value side --- src/compiler/transformers/module/module.ts | 12 ++++++------ src/compiler/transformers/module/system.ts | 8 ++++---- src/compiler/utilities.ts | 10 ++++++---- 3 files changed, 16 insertions(+), 14 deletions(-) diff --git a/src/compiler/transformers/module/module.ts b/src/compiler/transformers/module/module.ts index ad6fd2000fb..440aec62e3b 100644 --- a/src/compiler/transformers/module/module.ts +++ b/src/compiler/transformers/module/module.ts @@ -31,7 +31,7 @@ namespace ts { let externalImports: (ImportDeclaration | ImportEqualsDeclaration | ExportDeclaration)[]; let exportSpecifiers: Map; let exportEquals: ExportAssignment; - let hasExportStars: boolean; + let hasExportStarsToExportValues: boolean; return transformSourceFile; @@ -45,7 +45,7 @@ namespace ts { currentSourceFile = node; // Collect information about the external module. - ({ externalImports, exportSpecifiers, exportEquals, hasExportStars } = collectExternalModuleInfo(node, resolver)); + ({ externalImports, exportSpecifiers, exportEquals, hasExportStarsToExportValues } = collectExternalModuleInfo(node, resolver)); // Perform the transformation. const updated = transformModuleDelegates[moduleKind](node); @@ -55,7 +55,7 @@ namespace ts { externalImports = undefined; exportSpecifiers = undefined; exportEquals = undefined; - hasExportStars = false; + hasExportStarsToExportValues = false; return updated; } @@ -77,7 +77,7 @@ namespace ts { addExportEqualsIfNeeded(statements, /*emitAsReturn*/ false); const updated = updateSourceFile(node, statements); - if (hasExportStars) { + if (hasExportStarsToExportValues) { setNodeEmitFlags(updated, NodeEmitFlags.EmitExportStar | getNodeEmitFlags(node)); } @@ -200,7 +200,7 @@ namespace ts { addExportEqualsIfNeeded(statements, /*emitAsReturn*/ true); const body = createBlock(statements, /*location*/ undefined, /*multiLine*/ true); - if (hasExportStars) { + if (hasExportStarsToExportValues) { // If we have any `export * from ...` declarations // we need to inform the emitter to add the __export helper. setNodeEmitFlags(body, NodeEmitFlags.EmitExportStar); @@ -442,7 +442,7 @@ namespace ts { return singleOrMany(statements); } - else { + else if (resolver.moduleExportsSomeValue(node.moduleSpecifier)) { // export * from "mod"; return createStatement( createCall( diff --git a/src/compiler/transformers/module/system.ts b/src/compiler/transformers/module/system.ts index 81c657b158c..c18425a8bda 100644 --- a/src/compiler/transformers/module/system.ts +++ b/src/compiler/transformers/module/system.ts @@ -37,7 +37,7 @@ namespace ts { let externalImports: (ImportDeclaration | ImportEqualsDeclaration | ExportDeclaration)[]; let exportSpecifiers: Map; let exportEquals: ExportAssignment; - let hasExportStars: boolean; + let hasExportStarsToExportValues: boolean; let exportFunctionForFile: Identifier; let contextObjectForFile: Identifier; let exportedLocalNames: Identifier[]; @@ -62,7 +62,7 @@ namespace ts { externalImports = undefined; exportSpecifiers = undefined; exportEquals = undefined; - hasExportStars = false; + hasExportStarsToExportValues = false; exportFunctionForFile = undefined; contextObjectForFile = undefined; exportedLocalNames = undefined; @@ -89,7 +89,7 @@ namespace ts { Debug.assert(!exportFunctionForFile); // Collect information about the external module and dependency groups. - ({ externalImports, exportSpecifiers, exportEquals, hasExportStars } = collectExternalModuleInfo(node, resolver)); + ({ externalImports, exportSpecifiers, exportEquals, hasExportStarsToExportValues } = collectExternalModuleInfo(node, resolver)); // Make sure that the name of the 'exports' function does not conflict with // existing identifiers. @@ -253,7 +253,7 @@ namespace ts { } function addExportStarIfNeeded(statements: Statement[]) { - if (!hasExportStars) { + if (!hasExportStarsToExportValues) { return; } // when resolving exports local exported entries/indirect exported entries in the module diff --git a/src/compiler/utilities.ts b/src/compiler/utilities.ts index aaaf699834d..a3d07142875 100644 --- a/src/compiler/utilities.ts +++ b/src/compiler/utilities.ts @@ -2984,7 +2984,7 @@ namespace ts { const externalImports: (ImportDeclaration | ImportEqualsDeclaration | ExportDeclaration)[] = []; const exportSpecifiers: Map = {}; let exportEquals: ExportAssignment = undefined; - let hasExportStars = false; + let hasExportStarsToExportValues = false; for (const node of sourceFile.statements) { switch (node.kind) { case SyntaxKind.ImportDeclaration: @@ -3009,8 +3009,10 @@ namespace ts { if ((node).moduleSpecifier) { if (!(node).exportClause) { // export * from "mod" - externalImports.push(node); - hasExportStars = true; + if (resolver.moduleExportsSomeValue((node).moduleSpecifier)) { + externalImports.push(node); + hasExportStarsToExportValues = true; + } } else if (resolver.isValueAliasDeclaration(getOriginalNode(node))) { // export { x, y } from "mod" where at least one export is a value symbol @@ -3040,7 +3042,7 @@ namespace ts { } } - return { externalImports, exportSpecifiers, exportEquals, hasExportStars }; + return { externalImports, exportSpecifiers, exportEquals, hasExportStarsToExportValues }; } export function getInitializedVariables(node: VariableDeclarationList) { From a282468b060298727844213e8a0ab47d376fb9fd Mon Sep 17 00:00:00 2001 From: Nathan Shively-Sanders Date: Fri, 8 Apr 2016 14:36:43 -0700 Subject: [PATCH 11/58] Only emit rest param code for identifiers. Destructuring of array binding and object binding patterns is not supported yet. --- src/compiler/transformers/es6.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/compiler/transformers/es6.ts b/src/compiler/transformers/es6.ts index f93c69b8d69..a60eddb0bf5 100644 --- a/src/compiler/transformers/es6.ts +++ b/src/compiler/transformers/es6.ts @@ -924,7 +924,7 @@ namespace ts { * synthesized call to `super` */ function shouldAddRestParameter(node: ParameterDeclaration, inConstructorWithSynthesizedSuper: boolean) { - return node && node.dotDotDotToken && !inConstructorWithSynthesizedSuper; + return node && node.dotDotDotToken && node.name.kind === SyntaxKind.Identifier && !inConstructorWithSynthesizedSuper; } /** @@ -2746,4 +2746,4 @@ namespace ts { return isIdentifier(expression) && expression === parameter.name; } } -} \ No newline at end of file +} From 8b506c7b052a6da791ec9d3b6c5130f7af88b201 Mon Sep 17 00:00:00 2001 From: Ron Buckton Date: Fri, 8 Apr 2016 15:31:31 -0700 Subject: [PATCH 12/58] Cleans up a few things and fixes #7868. --- Jakefile.js | 40 ++++--- src/compiler/checker.ts | 126 ++++++++++++++------- src/compiler/transformers/es6.ts | 24 ++-- src/compiler/transformers/module/module.ts | 70 ++++++------ src/compiler/transformers/module/system.ts | 6 +- src/compiler/transformers/ts.ts | 81 +++++++------ src/compiler/types.ts | 7 +- src/compiler/utilities.ts | 34 +++++- 8 files changed, 236 insertions(+), 152 deletions(-) diff --git a/Jakefile.js b/Jakefile.js index c88d6933d55..6ed276c73c0 100644 --- a/Jakefile.js +++ b/Jakefile.js @@ -309,7 +309,7 @@ function compileFile(outFile, sources, prereqs, prefixes, useBuiltCompiler, opts options += " --stripInternal" } - if (useBuiltCompiler && !/^(no?|f(alse)?|0|-)$/i.test(process.env.USE_TRANSFORMS)) { + if (useBuiltCompiler && !environmentVariableIsDisabled("USE_TRANSFORMS")) { console.warn("\u001b[93mwarning: 'USE_TRANSFORMS' environment variable is not set to 'false'. Experimental transforms will be enabled by default.\u001b[0m"); } @@ -658,19 +658,21 @@ function exec(cmd, completeHandler, errorHandler) { } function cleanTestDirs() { - // Clean the local baselines directory - if (fs.existsSync(localBaseline)) { - jake.rmRf(localBaseline); - } + if (!environmentVariableIsDisabled("CLEAN_TESTS")) { + // Clean the local baselines directory + if (fs.existsSync(localBaseline)) { + jake.rmRf(localBaseline); + } - // Clean the local Rwc baselines directory - if (fs.existsSync(localRwcBaseline)) { - jake.rmRf(localRwcBaseline); - } + // Clean the local Rwc baselines directory + if (fs.existsSync(localRwcBaseline)) { + jake.rmRf(localRwcBaseline); + } - jake.mkdirP(localRwcBaseline); - jake.mkdirP(localTest262Baseline); - jake.mkdirP(localBaseline); + jake.mkdirP(localRwcBaseline); + jake.mkdirP(localTest262Baseline); + jake.mkdirP(localBaseline); + } } // used to pass data from jake command line directly to run.js @@ -833,7 +835,7 @@ function runConsoleTests(defaultReporter, defaultSubsets) { var light = process.env.light || false; var stackTraceLimit = process.env.stackTraceLimit || 1; var testConfigFile = 'test.config'; - if(fs.existsSync(testConfigFile)) { + if (fs.existsSync(testConfigFile)) { fs.unlinkSync(testConfigFile); } @@ -866,7 +868,7 @@ function runConsoleTests(defaultReporter, defaultSubsets) { console.log(cmd); exec(cmd, function () { deleteTemporaryProjectOutput(); - if (i === 0) { + if (i === 0 && !environmentVariableIsDisabled("lint")) { var lint = jake.Task['lint']; lint.addListener('complete', function () { complete(); @@ -1258,4 +1260,12 @@ ProgressBar.prototype = { this._lastProgress = progress; this.visible = true; } -}; \ No newline at end of file +}; + +function environmentVariableIsEnabled(name) { + return /^(y(es)?|t(rue)?|on|enabled?|1|\+)$/.test(process.env[name]); +} + +function environmentVariableIsDisabled(name) { + return /^(no?|f(alse)?|off|disabled?|0|-)$/.test(process.env[name]); +} \ No newline at end of file diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index aeaad03267b..10e3c19497d 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -1118,7 +1118,7 @@ namespace ts { } // Resolves a qualified name and any involved aliases - function resolveEntityName(name: EntityName | Expression, meaning: SymbolFlags, ignoreErrors?: boolean): Symbol { + function resolveEntityName(name: EntityName | Expression, meaning: SymbolFlags, ignoreErrors?: boolean, location?: Node): Symbol { if (nodeIsMissing(name)) { return undefined; } @@ -1127,7 +1127,7 @@ namespace ts { if (name.kind === SyntaxKind.Identifier) { const message = meaning === SymbolFlags.Namespace ? Diagnostics.Cannot_find_namespace_0 : Diagnostics.Cannot_find_name_0; - symbol = resolveName(name, (name).text, meaning, ignoreErrors ? undefined : message, name); + symbol = resolveName(location || name, (name).text, meaning, ignoreErrors ? undefined : message, name); if (!symbol) { return undefined; } @@ -1136,7 +1136,7 @@ namespace ts { const left = name.kind === SyntaxKind.QualifiedName ? (name).left : (name).expression; const right = name.kind === SyntaxKind.QualifiedName ? (name).right : (name).name; - const namespace = resolveEntityName(left, SymbolFlags.Namespace, ignoreErrors); + const namespace = resolveEntityName(left, SymbolFlags.Namespace, ignoreErrors, location); if (!namespace || namespace === unknownSymbol || nodeIsMissing(right)) { return undefined; } @@ -16042,7 +16042,14 @@ namespace ts { // Emitter support function isArgumentsLocalBinding(node: Identifier): boolean { - return getReferencedValueSymbol(node) === argumentsSymbol; + if (!isGeneratedIdentifier(node)) { + node = getSourceTreeNodeOfType(node, isIdentifier); + if (node) { + return getReferencedValueSymbol(node) === argumentsSymbol; + } + } + + return false; } function moduleExportsSomeValue(moduleReferenceExpression: Expression): boolean { @@ -16077,37 +16084,49 @@ namespace ts { // When resolved as an expression identifier, if the given node references an exported entity, return the declaration // node of the exported entity's container. Otherwise, return undefined. function getReferencedExportContainer(node: Identifier, prefixLocals?: boolean): SourceFile | ModuleDeclaration | EnumDeclaration { - let symbol = getReferencedValueSymbol(node); - if (symbol) { - if (symbol.flags & SymbolFlags.ExportValue) { - // If we reference an exported entity within the same module declaration, then whether - // we prefix depends on the kind of entity. SymbolFlags.ExportHasLocal encompasses all the - // kinds that we do NOT prefix. - const exportSymbol = getMergedSymbol(symbol.exportSymbol); - if (exportSymbol.flags & SymbolFlags.ExportHasLocal && !prefixLocals) { - return undefined; + node = getSourceTreeNodeOfType(node, isIdentifier); + if (node) { + let symbol = getReferencedValueSymbol(node); + if (symbol) { + if (symbol.flags & SymbolFlags.ExportValue) { + // If we reference an exported entity within the same module declaration, then whether + // we prefix depends on the kind of entity. SymbolFlags.ExportHasLocal encompasses all the + // kinds that we do NOT prefix. + const exportSymbol = getMergedSymbol(symbol.exportSymbol); + if (exportSymbol.flags & SymbolFlags.ExportHasLocal && !prefixLocals) { + return undefined; + } + symbol = exportSymbol; } - symbol = exportSymbol; - } - const parentSymbol = getParentOfSymbol(symbol); - if (parentSymbol) { - if (parentSymbol.flags & SymbolFlags.ValueModule && parentSymbol.valueDeclaration.kind === SyntaxKind.SourceFile) { - return parentSymbol.valueDeclaration; - } - for (let n = node.parent; n; n = n.parent) { - if ((n.kind === SyntaxKind.ModuleDeclaration || n.kind === SyntaxKind.EnumDeclaration) && getSymbolOfNode(n) === parentSymbol) { - return n; + const parentSymbol = getParentOfSymbol(symbol); + if (parentSymbol) { + if (parentSymbol.flags & SymbolFlags.ValueModule && parentSymbol.valueDeclaration.kind === SyntaxKind.SourceFile) { + return parentSymbol.valueDeclaration; + } + for (let n = node.parent; n; n = n.parent) { + if ((n.kind === SyntaxKind.ModuleDeclaration || n.kind === SyntaxKind.EnumDeclaration) && getSymbolOfNode(n) === parentSymbol) { + return n; + } } } } } + + return undefined; } // When resolved as an expression identifier, if the given node references an import, return the declaration of // that import. Otherwise, return undefined. function getReferencedImportDeclaration(node: Identifier): Declaration { - const symbol = getReferencedValueSymbol(node); - return symbol && symbol.flags & SymbolFlags.Alias ? getDeclarationOfAliasSymbol(symbol) : undefined; + node = getSourceTreeNodeOfType(node, isIdentifier); + if (node) { + const symbol = getReferencedValueSymbol(node); + if (symbol && symbol.flags & SymbolFlags.Alias) { + return getDeclarationOfAliasSymbol(symbol); + } + } + + return undefined; } function isSymbolOfDeclarationWithCollidingName(symbol: Symbol): boolean { @@ -16157,35 +16176,54 @@ namespace ts { // a name that either hides an existing name or might hide it when compiled downlevel, // return the declaration of that entity. Otherwise, return undefined. function getReferencedDeclarationWithCollidingName(node: Identifier): Declaration { - const symbol = getReferencedValueSymbol(node); - return symbol && isSymbolOfDeclarationWithCollidingName(symbol) ? symbol.valueDeclaration : undefined; + if (!isGeneratedIdentifier(node)) { + node = getSourceTreeNodeOfType(node, isIdentifier); + if (node) { + const symbol = getReferencedValueSymbol(node); + if (symbol && isSymbolOfDeclarationWithCollidingName(symbol)) { + return symbol.valueDeclaration; + } + } + } + + return undefined; } // Return true if the given node is a declaration of a nested block scoped entity with a name that either hides an // existing name or might hide a name when compiled downlevel function isDeclarationWithCollidingName(node: Declaration): boolean { - return isSymbolOfDeclarationWithCollidingName(getSymbolOfNode(node)); + node = getSourceTreeNodeOfType(node, isDeclaration); + if (node) { + const symbol = getSymbolOfNode(node); + if (symbol) { + return isSymbolOfDeclarationWithCollidingName(symbol); + } + } + + return false; } function isValueAliasDeclaration(node: Node): boolean { + node = getSourceTreeNode(node); switch (node.kind) { case SyntaxKind.ImportEqualsDeclaration: case SyntaxKind.ImportClause: case SyntaxKind.NamespaceImport: case SyntaxKind.ImportSpecifier: case SyntaxKind.ExportSpecifier: - return isAliasResolvedToValue(getSymbolOfNode(node)); + return isAliasResolvedToValue(getSymbolOfNode(node) || unknownSymbol); case SyntaxKind.ExportDeclaration: const exportClause = (node).exportClause; return exportClause && forEach(exportClause.elements, isValueAliasDeclaration); case SyntaxKind.ExportAssignment: - return (node).expression && (node).expression.kind === SyntaxKind.Identifier ? isAliasResolvedToValue(getSymbolOfNode(node)) : true; + return (node).expression && (node).expression.kind === SyntaxKind.Identifier ? isAliasResolvedToValue(getSymbolOfNode(node) || unknownSymbol) : true; } return false; } function isTopLevelValueImportEqualsWithEntityName(node: ImportEqualsDeclaration): boolean { - if (node.parent.kind !== SyntaxKind.SourceFile || !isInternalModuleImportEqualsDeclaration(node)) { + node = getSourceTreeNodeOfType(node, isImportEqualsDeclaration); + if (node === undefined || node.parent.kind !== SyntaxKind.SourceFile || !isInternalModuleImportEqualsDeclaration(node)) { // parent is not source file or it is not reference to internal module return false; } @@ -16212,9 +16250,10 @@ namespace ts { } function isReferencedAliasDeclaration(node: Node, checkChildren?: boolean): boolean { + node = getSourceTreeNode(node); if (isAliasSymbolDeclaration(node)) { const symbol = getSymbolOfNode(node); - if (getSymbolLinks(symbol).referenced) { + if (symbol && getSymbolLinks(symbol).referenced) { return true; } } @@ -16247,7 +16286,8 @@ namespace ts { } function getNodeCheckFlags(node: Node): NodeCheckFlags { - return getNodeLinks(node).flags; + node = getSourceTreeNode(node); + return node ? getNodeLinks(node).flags : undefined; } function getEnumMemberValue(node: EnumMember): number { @@ -16275,16 +16315,16 @@ namespace ts { return type.flags & TypeFlags.ObjectType && getSignaturesOfType(type, SignatureKind.Call).length > 0; } - function getTypeReferenceSerializationKind(typeName: EntityName): TypeReferenceSerializationKind { + function getTypeReferenceSerializationKind(typeName: EntityName, location?: Node): TypeReferenceSerializationKind { // Resolve the symbol as a value to ensure the type can be reached at runtime during emit. - const valueSymbol = resolveEntityName(typeName, SymbolFlags.Value, /*ignoreErrors*/ true); + const valueSymbol = resolveEntityName(typeName, SymbolFlags.Value, /*ignoreErrors*/ true, location); const constructorType = valueSymbol ? getTypeOfSymbol(valueSymbol) : undefined; if (constructorType && isConstructorType(constructorType)) { return TypeReferenceSerializationKind.TypeWithConstructSignatureAndValue; } // Resolve the symbol as a type so that we can provide a more useful hint for the type serializer. - const typeSymbol = resolveEntityName(typeName, SymbolFlags.Type, /*ignoreErrors*/ true); + const typeSymbol = resolveEntityName(typeName, SymbolFlags.Type, /*ignoreErrors*/ true, location); // We might not be able to resolve type symbol so use unknown type in that case (eg error case) if (!typeSymbol) { return TypeReferenceSerializationKind.ObjectType; @@ -16363,9 +16403,17 @@ namespace ts { } function getReferencedValueDeclaration(reference: Identifier): Declaration { - Debug.assert(!nodeIsSynthesized(reference)); - const symbol = getReferencedValueSymbol(reference); - return symbol && getExportSymbolOfValueSymbolIfExported(symbol).valueDeclaration; + if (!isGeneratedIdentifier(reference)) { + reference = getSourceTreeNodeOfType(reference, isIdentifier); + if (reference) { + const symbol = getReferencedValueSymbol(reference); + if (symbol) { + return getExportSymbolOfValueSymbolIfExported(symbol).valueDeclaration; + } + } + } + + return undefined; } function createResolver(): EmitResolver { diff --git a/src/compiler/transformers/es6.ts b/src/compiler/transformers/es6.ts index 82b60cf8a08..5f6c953cbc8 100644 --- a/src/compiler/transformers/es6.ts +++ b/src/compiler/transformers/es6.ts @@ -467,7 +467,7 @@ namespace ts { if (isGeneratedIdentifier(node)) { return node; } - if (node.text !== "arguments" && !resolver.isArgumentsLocalBinding(getOriginalNode(node))) { + if (node.text !== "arguments" && !resolver.isArgumentsLocalBinding(node)) { return node; } return convertedLoopState.argumentsName || (convertedLoopState.argumentsName = createUniqueName("arguments")); @@ -1426,10 +1426,7 @@ namespace ts { // * 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 flags = resolver.getNodeCheckFlags(node); const isCapturedInFunction = flags & NodeCheckFlags.CapturedBlockScopedBinding; const isDeclaredInLoop = flags & NodeCheckFlags.BlockScopedBindingInLoop; const emittedAsTopLevel = @@ -1443,7 +1440,7 @@ namespace ts { !emittedAsTopLevel && enclosingBlockScopeContainer.kind !== SyntaxKind.ForInStatement && enclosingBlockScopeContainer.kind !== SyntaxKind.ForOfStatement - && (!resolver.isDeclarationWithCollidingName(original) + && (!resolver.isDeclarationWithCollidingName(node) || (isDeclaredInLoop && !isCapturedInFunction && !isIterationStatement(enclosingBlockScopeContainer, /*lookInLabeledStatements*/ false))); @@ -1721,7 +1718,7 @@ namespace ts { } function shouldConvertIterationStatementBody(node: IterationStatement): boolean { - return (resolver.getNodeCheckFlags(getOriginalNode(node)) & NodeCheckFlags.LoopWithCapturedBlockScopedBinding) !== 0; + return (resolver.getNodeCheckFlags(node) & NodeCheckFlags.LoopWithCapturedBlockScopedBinding) !== 0; } /** @@ -2614,8 +2611,8 @@ namespace ts { // 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)) { + const original = getSourceTreeNodeOfType(node, isIdentifier); + if (original && isNameOfDeclarationWithCollidingName(original)) { return getGeneratedNameForNode(original); } } @@ -2668,12 +2665,9 @@ namespace ts { */ function substituteExpressionIdentifier(node: Identifier): Identifier { if (enabledSubstitutions & ES6SubstitutionFlags.BlockScopedBindings) { - const original = getOriginalNode(node); - if (isIdentifier(original)) { - const declaration = resolver.getReferencedDeclarationWithCollidingName(original); - if (declaration) { - return getGeneratedNameForNode(declaration.name); - } + const declaration = resolver.getReferencedDeclarationWithCollidingName(node); + if (declaration) { + return getGeneratedNameForNode(declaration.name); } } diff --git a/src/compiler/transformers/module/module.ts b/src/compiler/transformers/module/module.ts index ad6fd2000fb..196ddb059b7 100644 --- a/src/compiler/transformers/module/module.ts +++ b/src/compiler/transformers/module/module.ts @@ -460,8 +460,7 @@ namespace ts { function visitExportAssignment(node: ExportAssignment): VisitResult { if (!node.isExportEquals) { - const original = getOriginalNode(node); - if (nodeIsSynthesized(original) || resolver.isValueAliasDeclaration(original)) { + if (nodeIsSynthesized(node) || resolver.isValueAliasDeclaration(node)) { const statements: Statement[] = []; addExportDefault(statements, node.expression, /*location*/ node); return statements; @@ -713,46 +712,43 @@ namespace ts { } function substituteExpressionIdentifier(node: Identifier): Expression { - const original = getOriginalNode(node); - if (isIdentifier(original)) { - const container = resolver.getReferencedExportContainer(original, (getNodeEmitFlags(node) & NodeEmitFlags.PrefixExportedLocal) !== 0); - if (container) { - if (container.kind === SyntaxKind.SourceFile) { - return createPropertyAccess( - createIdentifier("exports"), - getSynthesizedClone(node), - /*location*/ node - ); - } + const container = resolver.getReferencedExportContainer(node, (getNodeEmitFlags(node) & NodeEmitFlags.ExportName) !== 0); + if (container) { + if (container.kind === SyntaxKind.SourceFile) { + return createPropertyAccess( + createIdentifier("exports"), + getSynthesizedClone(node), + /*location*/ node + ); } - else { - const declaration = resolver.getReferencedImportDeclaration(node.parent ? node : original); - if (declaration) { - if (declaration.kind === SyntaxKind.ImportClause) { - if (languageVersion >= ScriptTarget.ES5) { - return createPropertyAccess( - getGeneratedNameForNode(declaration.parent), - createIdentifier("default"), - /*location*/ node - ); - } - else { - return createElementAccess( - getGeneratedNameForNode(declaration.parent), - createLiteral("default"), - /*location*/ node - ); - } - } - else if (declaration.kind === SyntaxKind.ImportSpecifier) { - const name = (declaration).propertyName - || (declaration).name; + } + else { + const declaration = resolver.getReferencedImportDeclaration(node); + if (declaration) { + if (declaration.kind === SyntaxKind.ImportClause) { + if (languageVersion >= ScriptTarget.ES5) { return createPropertyAccess( - getGeneratedNameForNode(declaration.parent.parent.parent), - getSynthesizedClone(name), + getGeneratedNameForNode(declaration.parent), + createIdentifier("default"), /*location*/ node ); } + else { + return createElementAccess( + getGeneratedNameForNode(declaration.parent), + createLiteral("default"), + /*location*/ node + ); + } + } + else if (declaration.kind === SyntaxKind.ImportSpecifier) { + const name = (declaration).propertyName + || (declaration).name; + return createPropertyAccess( + getGeneratedNameForNode(declaration.parent.parent.parent), + getSynthesizedClone(name), + /*location*/ node + ); } } } diff --git a/src/compiler/transformers/module/system.ts b/src/compiler/transformers/module/system.ts index 81c657b158c..3bda78830e7 100644 --- a/src/compiler/transformers/module/system.ts +++ b/src/compiler/transformers/module/system.ts @@ -570,8 +570,7 @@ namespace ts { function visitExportAssignment(node: ExportAssignment): Statement { if (!node.isExportEquals) { - const original = getOriginalNode(node); - if (nodeIsSynthesized(original) || resolver.isValueAliasDeclaration(original)) { + if (nodeIsSynthesized(node) || resolver.isValueAliasDeclaration(node)) { return createExportStatement( createLiteral("default"), node.expression @@ -1012,8 +1011,7 @@ namespace ts { const left = node.left; switch (left.kind) { case SyntaxKind.Identifier: - const originalNode = getOriginalNode(left); - const exportDeclaration = resolver.getReferencedExportContainer(originalNode); + const exportDeclaration = resolver.getReferencedExportContainer(left); if (exportDeclaration) { return createExportExpression(left, node); } diff --git a/src/compiler/transformers/ts.ts b/src/compiler/transformers/ts.ts index 0b8c11a66e2..78536f56697 100644 --- a/src/compiler/transformers/ts.ts +++ b/src/compiler/transformers/ts.ts @@ -596,7 +596,7 @@ namespace ts { // Record an alias to avoid class double-binding. let decoratedClassAlias: Identifier; - if (resolver.getNodeCheckFlags(getOriginalNode(node)) & NodeCheckFlags.DecoratedClassWithSelfReference) { + if (resolver.getNodeCheckFlags(node) & NodeCheckFlags.DecoratedClassWithSelfReference) { enableExpressionSubstitutionForDecoratedClasses(); decoratedClassAlias = createUniqueName(node.name && !isGeneratedIdentifier(node.name) ? node.name.text : "default"); decoratedClassAliases[getOriginalNodeId(node)] = decoratedClassAlias; @@ -1380,7 +1380,6 @@ namespace ts { function addOldTypeMetadata(node: Declaration, decoratorExpressions: Expression[]) { if (compilerOptions.emitDecoratorMetadata) { - let properties: ObjectLiteralElement[]; if (shouldAddTypeMetadata(node)) { decoratorExpressions.push(createMetadataHelper("design:type", serializeTypeOfNode(node))); } @@ -1614,11 +1613,9 @@ namespace ts { * @param node The type reference node. */ function serializeTypeReferenceNode(node: TypeReferenceNode) { - // Clone the type name and parent it to a location outside of the current declaration. - const typeName = cloneEntityName(node.typeName, currentScope); - switch (resolver.getTypeReferenceSerializationKind(typeName)) { + switch (resolver.getTypeReferenceSerializationKind(node.typeName, currentScope)) { case TypeReferenceSerializationKind.Unknown: - const serialized = serializeEntityNameAsExpression(typeName, /*useFallback*/ true); + const serialized = serializeEntityNameAsExpression(node.typeName, /*useFallback*/ true); const temp = createTempVariable(hoistVariableDeclaration); return createLogicalOr( createLogicalAnd( @@ -1634,7 +1631,7 @@ namespace ts { ); case TypeReferenceSerializationKind.TypeWithConstructSignatureAndValue: - return serializeEntityNameAsExpression(typeName, /*useFallback*/ false); + return serializeEntityNameAsExpression(node.typeName, /*useFallback*/ false); case TypeReferenceSerializationKind.VoidType: return createVoidZero(); @@ -1675,17 +1672,20 @@ namespace ts { function serializeEntityNameAsExpression(node: EntityName, useFallback: boolean): Expression { switch (node.kind) { case SyntaxKind.Identifier: + const name = getMutableClone(node); + name.original = undefined; + name.parent = currentScope; if (useFallback) { return createLogicalAnd( createStrictInequality( - createTypeOf(node), + createTypeOf(name), createLiteral("undefined") ), - node + name ); } - return node; + return name; case SyntaxKind.QualifiedName: return serializeQualifiedNameAsExpression(node, useFallback); @@ -2646,7 +2646,7 @@ namespace ts { else { // We set the "PrefixExportedLocal" flag to indicate to any module transformer // downstream that any `exports.` prefix should be added. - setNodeEmitFlags(name, getNodeEmitFlags(name) | NodeEmitFlags.PrefixExportedLocal); + setNodeEmitFlags(name, getNodeEmitFlags(name) | NodeEmitFlags.ExportName); return name; } } @@ -2738,41 +2738,52 @@ namespace ts { } function substituteExpressionIdentifier(node: Identifier): Expression { + return trySubstituteDecoratedClassName(node) + || trySubstituteNamespaceExportedName(node) + || node; + } + + function trySubstituteDecoratedClassName(node: Identifier): Expression { if (enabledSubstitutions & TypeScriptSubstitutionFlags.DecoratedClasses) { - const original = getOriginalNode(node); - if (isIdentifier(original)) { - if (resolver.getNodeCheckFlags(original) & 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. - const declaration = resolver.getReferencedValueDeclaration(original); - if (declaration) { - const classAlias = currentDecoratedClassAliases[getNodeId(declaration)]; - if (classAlias) { - return getRelocatedClone(classAlias, /*location*/ node); - } + 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. + const declaration = resolver.getReferencedValueDeclaration(node); + if (declaration) { + const classAlias = currentDecoratedClassAliases[getNodeId(declaration)]; + if (classAlias) { + return getRelocatedClone(classAlias, /*location*/ node); } } } } + return undefined; + } + + function trySubstituteNamespaceExportedName(node: Identifier): Expression { if (enabledSubstitutions & applicableSubstitutions) { + // If this is explicitly a local name, do not substitute. + if (getNodeEmitFlags(node) & NodeEmitFlags.LocalName) { + return node; + } + // If we are nested within a namespace declaration, we may need to qualifiy // an identifier that is exported from a merged namespace. - const original = getOriginalNode(node); - if (isIdentifier(original) && original.parent) { - const container = resolver.getReferencedExportContainer(original); - if (container) { - const substitute = - (applicableSubstitutions & TypeScriptSubstitutionFlags.NamespaceExports && container.kind === SyntaxKind.ModuleDeclaration) || - (applicableSubstitutions & TypeScriptSubstitutionFlags.NonQualifiedEnumMembers && container.kind === SyntaxKind.EnumDeclaration); - if (substitute) { - return createPropertyAccess(getGeneratedNameForNode(container), node, /*location*/ node); - } + const original = getSourceTreeNodeOfType(node, isIdentifier); + const container = resolver.getReferencedExportContainer(original, /*prefixLocals*/ false); + if (container && original !== container.name) { + const substitute = + (applicableSubstitutions & TypeScriptSubstitutionFlags.NamespaceExports && container.kind === SyntaxKind.ModuleDeclaration) || + (applicableSubstitutions & TypeScriptSubstitutionFlags.NonQualifiedEnumMembers && container.kind === SyntaxKind.EnumDeclaration); + if (substitute) { + return createPropertyAccess(getGeneratedNameForNode(container), node, /*location*/ node); } } } - return node; + + return undefined; } function substituteCallExpression(node: CallExpression): Expression { @@ -2900,7 +2911,7 @@ namespace ts { function getSuperContainerAsyncMethodFlags() { return currentSuperContainer !== undefined - && resolver.getNodeCheckFlags(getOriginalNode(currentSuperContainer)) & (NodeCheckFlags.AsyncMethodWithSuper | NodeCheckFlags.AsyncMethodWithSuperBinding); + && resolver.getNodeCheckFlags(currentSuperContainer) & (NodeCheckFlags.AsyncMethodWithSuper | NodeCheckFlags.AsyncMethodWithSuperBinding); } } } \ No newline at end of file diff --git a/src/compiler/types.ts b/src/compiler/types.ts index 7723abfe270..ab63484a812 100644 --- a/src/compiler/types.ts +++ b/src/compiler/types.ts @@ -1963,7 +1963,7 @@ namespace ts { // Returns the constant value this property access resolves to, or 'undefined' for a non-constant getConstantValue(node: EnumMember | PropertyAccessExpression | ElementAccessExpression): number; getReferencedValueDeclaration(reference: Identifier): Declaration; - getTypeReferenceSerializationKind(typeName: EntityName): TypeReferenceSerializationKind; + getTypeReferenceSerializationKind(typeName: EntityName, location?: Node): TypeReferenceSerializationKind; isOptionalParameter(node: ParameterDeclaration): boolean; moduleExportsSomeValue(moduleReferenceExpression: Expression): boolean; isArgumentsLocalBinding(node: Identifier): boolean; @@ -2875,8 +2875,9 @@ namespace ts { NoSourceMap = 1 << 10, // Do not emit a source map location for this node. NoNestedSourceMaps = 1 << 11, // Do not emit source map locations for children of this node. NoComments = 1 << 12, // Do not emit comments for this node. - PrefixExportedLocal = 1 << 13, // Ensure an export prefix is added for an identifier that points to an exported declaration with a local name (see SymbolFlags.ExportHasLocal). - Indented = 1 << 14, // Adds an explicit extra indentation level for class and function bodies when printing (used to match old emitter). + ExportName = 1 << 13, // Ensure an export prefix is added for an identifier that points to an exported declaration with a local name (see SymbolFlags.ExportHasLocal). + LocalName = 1 << 14, // Ensure an export prefix is not added for an identifier that points to an exported declaration. + Indented = 1 << 15, // Adds an explicit extra indentation level for class and function bodies when printing (used to match old emitter). } /** Additional context provided to `visitEachChild` */ diff --git a/src/compiler/utilities.ts b/src/compiler/utilities.ts index aaaf699834d..fd1ad48a74f 100644 --- a/src/compiler/utilities.ts +++ b/src/compiler/utilities.ts @@ -1713,16 +1713,20 @@ namespace ts { /** * Creates a deep clone of an EntityName, with new parent pointers. + * NOTE: The new entity name will *not* have "original" pointers. + * * @param node The EntityName to clone. * @param parent The parent for the cloned node. */ export function cloneEntityName(node: EntityName, parent?: Node): EntityName { const clone = getMutableClone(node); + clone.original = undefined; clone.parent = parent; if (isQualifiedName(clone)) { const { left, right } = clone; clone.left = cloneEntityName(left, clone); clone.right = getMutableClone(right); + clone.right.original = undefined; clone.right.parent = clone; } @@ -1741,13 +1745,31 @@ namespace ts { } export function getOriginalNode(node: Node): Node { - while (node.original !== undefined) { - node = node.original; + if (node) { + while (node.original !== undefined) { + node = node.original; + } } return node; } + export function getSourceTreeNode(node: Node): Node { + node = getOriginalNode(node); + if (node) { + if (node.parent || node.kind === SyntaxKind.SourceFile) { + return node; + } + } + + return undefined; + } + + export function getSourceTreeNodeOfType(node: T, nodeTest: (node: Node) => node is T): T { + const source = getSourceTreeNode(node); + return source && nodeTest(source) ? source : undefined; + } + export function getOriginalNodeId(node: Node) { node = getOriginalNode(node); return node ? getNodeId(node) : 0; @@ -2999,7 +3021,7 @@ namespace ts { break; case SyntaxKind.ImportEqualsDeclaration: - if ((node).moduleReference.kind === SyntaxKind.ExternalModuleReference && resolver.isReferencedAliasDeclaration(getOriginalNode(node))) { + if ((node).moduleReference.kind === SyntaxKind.ExternalModuleReference && resolver.isReferencedAliasDeclaration(node)) { // import x = require("mod") where x is referenced externalImports.push(node); } @@ -3012,7 +3034,7 @@ namespace ts { externalImports.push(node); hasExportStars = true; } - else if (resolver.isValueAliasDeclaration(getOriginalNode(node))) { + else if (resolver.isValueAliasDeclaration(node)) { // export { x, y } from "mod" where at least one export is a value symbol externalImports.push(node); } @@ -3414,6 +3436,10 @@ namespace ts { || kind === SyntaxKind.ModuleDeclaration; } + export function isImportEqualsDeclaration(node: Node): node is ImportEqualsDeclaration { + return node.kind === SyntaxKind.ImportEqualsDeclaration; + } + export function isImportClause(node: Node): node is ImportClause { return node.kind === SyntaxKind.ImportClause; } From 2d3e943ae6d768f7e043684860c4ffb9d55ea14e Mon Sep 17 00:00:00 2001 From: Mohamed Hegazy Date: Fri, 8 Apr 2016 15:37:13 -0700 Subject: [PATCH 13/58] JS style changes --- Jakefile.js | 50 +++++++++++++++++++++++++------------------------- 1 file changed, 25 insertions(+), 25 deletions(-) diff --git a/Jakefile.js b/Jakefile.js index c88d6933d55..1f786fb230c 100644 --- a/Jakefile.js +++ b/Jakefile.js @@ -187,20 +187,20 @@ var harnessSources = harnessCoreSources.concat([ "protocol.d.ts", "session.ts", "client.ts", - "editorServices.ts", + "editorServices.ts" ].map(function (f) { return path.join(serverDirectory, f); })); var librarySourceMap = [ { target: "lib.core.d.ts", sources: ["header.d.ts", "core.d.ts"] }, - { target: "lib.dom.d.ts", sources: ["importcore.d.ts", "intl.d.ts", "dom.generated.d.ts"], }, - { target: "lib.webworker.d.ts", sources: ["importcore.d.ts", "intl.d.ts", "webworker.generated.d.ts"], }, - { target: "lib.scriptHost.d.ts", sources: ["importcore.d.ts", "scriptHost.d.ts"], }, - { target: "lib.d.ts", sources: ["header.d.ts", "core.d.ts", "intl.d.ts", "dom.generated.d.ts", "webworker.importscripts.d.ts", "scriptHost.d.ts"], }, - { target: "lib.core.es6.d.ts", sources: ["header.d.ts", "core.d.ts", "es6.d.ts"]}, + { target: "lib.dom.d.ts", sources: ["importcore.d.ts", "intl.d.ts", "dom.generated.d.ts"] }, + { target: "lib.webworker.d.ts", sources: ["importcore.d.ts", "intl.d.ts", "webworker.generated.d.ts"] }, + { target: "lib.scriptHost.d.ts", sources: ["importcore.d.ts", "scriptHost.d.ts"] }, + { target: "lib.d.ts", sources: ["header.d.ts", "core.d.ts", "intl.d.ts", "dom.generated.d.ts", "webworker.importscripts.d.ts", "scriptHost.d.ts"] }, + { target: "lib.core.es6.d.ts", sources: ["header.d.ts", "core.d.ts", "es6.d.ts"] }, { target: "lib.es6.d.ts", sources: ["header.d.ts", "es6.d.ts", "core.d.ts", "intl.d.ts", "dom.generated.d.ts", "dom.es6.d.ts", "webworker.importscripts.d.ts", "scriptHost.d.ts"] }, - { target: "lib.core.es7.d.ts", sources: ["header.d.ts", "core.d.ts", "es6.d.ts", "es7.d.ts"]}, + { target: "lib.core.es7.d.ts", sources: ["header.d.ts", "core.d.ts", "es6.d.ts", "es7.d.ts"] }, { target: "lib.es7.d.ts", sources: ["header.d.ts", "es6.d.ts", "es7.d.ts", "core.d.ts", "intl.d.ts", "dom.generated.d.ts", "dom.es6.d.ts", "webworker.importscripts.d.ts", "scriptHost.d.ts"] } ]; @@ -242,7 +242,7 @@ function concatenateFiles(destinationFile, sourceFiles) { } var useDebugMode = true; -var host = (process.env.host || process.env.TYPESCRIPT_HOST || "node"); +var host = process.env.host || process.env.TYPESCRIPT_HOST || "node"; var compilerFilename = "tsc.js"; var LKGCompiler = path.join(LKGDirectory, compilerFilename); var builtLocalCompiler = path.join(builtLocalDirectory, compilerFilename); @@ -291,7 +291,7 @@ function compileFile(outFile, sources, prereqs, prefixes, useBuiltCompiler, opts options += " --out " + outFile; } else { - options += " --module commonjs" + options += " --module commonjs"; } if(opts.noResolve) { @@ -306,7 +306,7 @@ function compileFile(outFile, sources, prereqs, prefixes, useBuiltCompiler, opts } if (opts.stripInternal) { - options += " --stripInternal" + options += " --stripInternal"; } if (useBuiltCompiler && !/^(no?|f(alse)?|0|-)$/i.test(process.env.USE_TRANSFORMS)) { @@ -448,9 +448,9 @@ file(scriptsTsdJson); task("tsd-scripts", [scriptsTsdJson], function () { var cmd = "tsd --config " + scriptsTsdJson + " install"; - console.log(cmd) + console.log(cmd); exec(cmd); -}, { async: true }) +}, { async: true }); var importDefinitelyTypedTestsDirectory = path.join(scriptsDirectory, "importDefinitelyTypedTests"); var importDefinitelyTypedTestsJs = path.join(importDefinitelyTypedTestsDirectory, "importDefinitelyTypedTests.js"); @@ -617,7 +617,7 @@ directory(builtLocalDirectory); var run = path.join(builtLocalDirectory, "run.js"); compileFile(run, harnessSources, [builtLocalDirectory, tscFile].concat(libraryTargets).concat(harnessSources), [], /*useBuiltCompiler:*/ true); -var internalTests = "internal/" +var internalTests = "internal/"; var localBaseline = "tests/baselines/local/"; var refBaseline = "tests/baselines/reference/"; @@ -845,7 +845,7 @@ function runConsoleTests(defaultReporter, defaultSubsets) { testTimeout = 100000; } - colors = process.env.colors || process.env.color + colors = process.env.colors || process.env.color; colors = colors ? ' --no-colors ' : ' --colors '; reporter = process.env.reporter || process.env.r || defaultReporter; @@ -853,7 +853,7 @@ function runConsoleTests(defaultReporter, defaultSubsets) { // default timeout is 2sec which really should be enough, but maybe we just need a small amount longer var subsetRegexes; if(defaultSubsets.length === 0) { - subsetRegexes = [tests] + subsetRegexes = [tests]; } else { var subsets = tests ? tests.split("|") : defaultSubsets; @@ -903,8 +903,8 @@ task("generate-code-coverage", ["tests", builtLocalDirectory], function () { }, { async: true }); // Browser tests -var nodeServerOutFile = 'tests/webTestServer.js' -var nodeServerInFile = 'tests/webTestServer.ts' +var nodeServerOutFile = 'tests/webTestServer.js'; +var nodeServerInFile = 'tests/webTestServer.ts'; compileFile(nodeServerOutFile, [nodeServerInFile], [builtLocalDirectory, tscFile], [], /*useBuiltCompiler:*/ true, { noOutFile: true }); desc("Runs browserify on run.js to produce a file suitable for running tests in the browser"); @@ -916,7 +916,7 @@ task("browserify", ["tests", builtLocalDirectory, nodeServerOutFile], function() desc("Runs the tests using the built run.js file like 'jake runtests'. Syntax is jake runtests-browser. Additional optional parameters tests=[regex], port=, browser=[chrome|IE]"); task("runtests-browser", ["tests", "browserify", builtLocalDirectory, servicesFileInBrowserTest], function() { cleanTestDirs(); - host = "node" + host = "node"; port = process.env.port || process.env.p || '8888'; browser = process.env.browser || process.env.b || "IE"; tests = process.env.test || process.env.tests || process.env.t; @@ -930,13 +930,13 @@ task("runtests-browser", ["tests", "browserify", builtLocalDirectory, servicesFi } tests = tests ? tests : ''; - var cmd = host + " tests/webTestServer.js " + port + " " + browser + " " + tests + var cmd = host + " tests/webTestServer.js " + port + " " + browser + " " + tests; console.log(cmd); exec(cmd); }, {async: true}); function getDiffTool() { - var program = process.env['DIFF'] + var program = process.env['DIFF']; if (!program) { fail("Add the 'DIFF' environment variable to the path of the program you want to use."); } @@ -965,11 +965,11 @@ task("tests-debug", ["setDebugMode", "tests"]); // Makes the test results the new baseline desc("Makes the most recent test results the new baseline, overwriting the old baseline"); task("baseline-accept", function(hardOrSoft) { - if (!hardOrSoft || hardOrSoft == "hard") { + if (!hardOrSoft || hardOrSoft === "hard") { jake.rmRf(refBaseline); fs.renameSync(localBaseline, refBaseline); } - else if (hardOrSoft == "soft") { + else if (hardOrSoft === "soft") { var files = jake.readdirR(localBaseline); for (var i in files) { jake.cpR(files[i], refBaseline); @@ -1048,7 +1048,7 @@ task("update-sublime", ["local", serverFile], function() { }); var tslintRuleDir = "scripts/tslint"; -var tslintRules = ([ +var tslintRules = [ "nextLineRule", "noNullRule", "preferConstRule", @@ -1056,7 +1056,7 @@ var tslintRules = ([ "typeOperatorSpacingRule", "noInOperatorRule", "noIncrementDecrementRule" -]); +]; var tslintRulesFiles = tslintRules.map(function(p) { return path.join(tslintRuleDir, p + ".ts"); }); @@ -1081,7 +1081,7 @@ function getLinterOptions() { function lintFileContents(options, path, contents) { var ll = new Linter(path, contents, options); - console.log("Linting '" + path + "'.") + console.log("Linting '" + path + "'."); return ll.lint(); } From 02d07a165d1b6b302c222f43dce72969173d156a Mon Sep 17 00:00:00 2001 From: Mohamed Hegazy Date: Fri, 8 Apr 2016 16:53:52 -0700 Subject: [PATCH 14/58] Make project tests run in the server --- src/harness/harness.ts | 13 ++++++-- src/harness/runner.ts | 14 ++++++--- tests/webTestServer.ts | 70 ++++++++++++++++++++++++++++++++---------- 3 files changed, 74 insertions(+), 23 deletions(-) diff --git a/src/harness/harness.ts b/src/harness/harness.ts index 27dc06135fc..80848d6bbed 100644 --- a/src/harness/harness.ts +++ b/src/harness/harness.ts @@ -424,7 +424,7 @@ namespace Utils { filtered.push(line); } - (error).stack = filtered.join(ts.sys.newLine); + (error).stack = filtered.join(Harness.IO.newLine()); } return error; @@ -751,7 +751,16 @@ namespace Harness { return dirPath; } export let directoryName: typeof IO.directoryName = Utils.memoize(directoryNameImpl); - export const resolvePath = (path: string) => directoryName(path); + + export function resolvePath(path: string) { + const response = Http.getFileFromServerSync(serverRoot + path + "?resolve=true"); + if (response.status === 200) { + return response.responseText; + } + else { + return null; + } + } export function fileExists(path: string): boolean { const response = Http.getFileFromServerSync(serverRoot + path); diff --git a/src/harness/runner.ts b/src/harness/runner.ts index 04af7b6f066..2182c401348 100644 --- a/src/harness/runner.ts +++ b/src/harness/runner.ts @@ -40,8 +40,14 @@ let testConfigFile = Harness.IO.fileExists(mytestconfig) ? Harness.IO.readFile(mytestconfig) : (Harness.IO.fileExists(testconfig) ? Harness.IO.readFile(testconfig) : ""); +type TestConfig = { + tests?: string[]; + stackTraceLimit?: number | "full"; + light?: boolean; +}; + if (testConfigFile !== "") { - const testConfig = JSON.parse(testConfigFile); + const testConfig = JSON.parse(testConfigFile); if (testConfig.light) { Harness.lightMode = true; } @@ -49,12 +55,12 @@ if (testConfigFile !== "") { if (testConfig.stackTraceLimit === "full") { (Error).stackTraceLimit = Infinity; } - else if ((testConfig.stackTraceLimit | 0) > 0) { + else if ((+testConfig.stackTraceLimit | 0) > 0) { (Error).stackTraceLimit = testConfig.stackTraceLimit; } - if (testConfig.test && testConfig.test.length > 0) { - for (const option of testConfig.test) { + if (testConfig.tests && testConfig.tests.length > 0) { + for (const option of testConfig.tests) { if (!option) { continue; } diff --git a/tests/webTestServer.ts b/tests/webTestServer.ts index dab552e2619..9eaddc3c638 100644 --- a/tests/webTestServer.ts +++ b/tests/webTestServer.ts @@ -48,6 +48,53 @@ function log(msg: string) { } } + +let directorySeparator = "/"; + +function getRootLength(path: string): number { + if (path.charAt(0) === directorySeparator) { + if (path.charAt(1) !== directorySeparator) return 1; + const p1 = path.indexOf("/", 2); + if (p1 < 0) return 2; + const p2 = path.indexOf("/", p1 + 1); + if (p2 < 0) return p1 + 1; + return p2 + 1; + } + if (path.charAt(1) === ":") { + if (path.charAt(2) === directorySeparator) return 3; + return 2; + } + // Per RFC 1738 'file' URI schema has the shape file:/// + // if is omitted then it is assumed that host value is 'localhost', + // however slash after the omitted is not removed. + // file:///folder1/file1 - this is a correct URI + // file://folder2/file2 - this is an incorrect URI + if (path.lastIndexOf("file:///", 0) === 0) { + return "file:///".length; + } + const idx = path.indexOf("://"); + if (idx !== -1) { + return idx + "://".length; + } + return 0; +} + +function getDirectoryPath(path: string): any { + path = switchToForwardSlashes(path); + return path.substr(0, Math.max(getRootLength(path), path.lastIndexOf(directorySeparator))); +} + +function ensureDirectoriesExist(path: string) { + path = switchToForwardSlashes(path); + if (path.length > getRootLength(path) && !fs.existsSync(path)) { + const parentDirectory = getDirectoryPath(path); + ensureDirectoriesExist(parentDirectory); + if (!fs.existsSync(path)) { + fs.mkdirSync(path); + } + } +} + // Copied from the compiler sources function dir(path: string, spec?: string, options?: any) { options = options || <{ recursive?: boolean; }>{}; @@ -94,28 +141,16 @@ function deleteFolderRecursive(path: string) { }; function writeFile(path: string, data: any, opts: { recursive: boolean }) { - try { - fs.writeFileSync(path, data); - } catch (e) { - // assume file was written to a directory that exists, if not, start recursively creating them as necessary - var parts = switchToForwardSlashes(path).split('/'); - for (var i = 0; i < parts.length; i++) { - var subDir = parts.slice(0, i).join('/'); - if (!fs.existsSync(subDir)) { - fs.mkdir(subDir); - } - } - fs.writeFileSync(path, data); - } + ensureDirectoriesExist(getDirectoryPath(path)); + fs.writeFileSync(path, data); } /// Request Handling /// function handleResolutionRequest(filePath: string, res: http.ServerResponse) { - var resolvedPath = path.resolve(filePath, ''); - resolvedPath = resolvedPath.substring(resolvedPath.indexOf('tests')); + var resolvedPath = path.resolve(filePath); resolvedPath = switchToForwardSlashes(resolvedPath); - send('success', res, resolvedPath); + send('success', res, resolvedPath, 'text/javascript'); return; } @@ -174,6 +209,7 @@ function getRequestOperation(req: http.ServerRequest, filename: string) { else return RequestType.GetDir; } else { + var queryData: any = url.parse(req.url, true).query; if (req.method === 'GET' && queryData.resolve !== undefined) return RequestType.ResolveFile // mocha uses ?grep= query string as equivalent to the --grep command line option used to filter tests @@ -223,7 +259,7 @@ function handleRequestOperation(req: http.ServerRequest, res: http.ServerRespons send('success', res, null); break; case RequestType.WriteDir: - fs.mkdirSync(reqPath); + ensureDirectoriesExist(reqPath); send('success', res, null); break; case RequestType.DeleteFile: From f3c86148d2e9e34ce3fcefed8c7c90a9607c88e7 Mon Sep 17 00:00:00 2001 From: Mohamed Hegazy Date: Fri, 8 Apr 2016 16:54:59 -0700 Subject: [PATCH 15/58] Fix for https://github.com/Microsoft/TypeScript/issues/4697, do not stop running the tests on the first failure --- src/harness/projectsRunner.ts | 29 ++++++++++++++++++----------- 1 file changed, 18 insertions(+), 11 deletions(-) diff --git a/src/harness/projectsRunner.ts b/src/harness/projectsRunner.ts index f5df92bedbf..02dcb7822ee 100644 --- a/src/harness/projectsRunner.ts +++ b/src/harness/projectsRunner.ts @@ -463,24 +463,31 @@ class ProjectRunner extends RunnerBase { } }); - it("Baseline of emitted result (" + moduleNameToString(moduleKind) + "): " + testCaseFileName, () => { if (testCase.baselineCheck) { + var lastError: any = undefined; ts.forEach(compilerResult.outputFiles, outputFile => { - - Harness.Baseline.runBaseline("Baseline of emitted result (" + moduleNameToString(compilerResult.moduleKind) + "): " + testCaseFileName, getBaselineFolder(compilerResult.moduleKind) + outputFile.fileName, () => { - try { - return Harness.IO.readFile(getProjectOutputFolder(outputFile.fileName, compilerResult.moduleKind)); - } - catch (e) { - return undefined; - } - }); + try { + Harness.Baseline.runBaseline("Baseline of emitted result (" + moduleNameToString(compilerResult.moduleKind) + "): " + testCaseFileName, getBaselineFolder(compilerResult.moduleKind) + outputFile.fileName, () => { + try { + return Harness.IO.readFile(getProjectOutputFolder(outputFile.fileName, compilerResult.moduleKind)); + } + catch (e) { + return undefined; + } + }); + } + catch (e) { + lastError = e; + } }); + + if (lastError) { + throw lastError; + } } }); - it("SourceMapRecord for (" + moduleNameToString(moduleKind) + "): " + testCaseFileName, () => { if (compilerResult.sourceMapData) { Harness.Baseline.runBaseline("SourceMapRecord for (" + moduleNameToString(compilerResult.moduleKind) + "): " + testCaseFileName, getBaselineFolder(compilerResult.moduleKind) + testCaseJustName + ".sourcemap.txt", () => { From 42fbe823c02af6d4e511ff916cf0f8de1db75710 Mon Sep 17 00:00:00 2001 From: Mohamed Hegazy Date: Fri, 8 Apr 2016 17:23:58 -0700 Subject: [PATCH 16/58] Disable sourcemap text tests for now to limit noise --- src/harness/projectsRunner.ts | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/src/harness/projectsRunner.ts b/src/harness/projectsRunner.ts index 02dcb7822ee..12a581f6520 100644 --- a/src/harness/projectsRunner.ts +++ b/src/harness/projectsRunner.ts @@ -488,14 +488,14 @@ class ProjectRunner extends RunnerBase { } }); - it("SourceMapRecord for (" + moduleNameToString(moduleKind) + "): " + testCaseFileName, () => { - if (compilerResult.sourceMapData) { - Harness.Baseline.runBaseline("SourceMapRecord for (" + moduleNameToString(compilerResult.moduleKind) + "): " + testCaseFileName, getBaselineFolder(compilerResult.moduleKind) + testCaseJustName + ".sourcemap.txt", () => { - return Harness.SourceMapRecorder.getSourceMapRecord(compilerResult.sourceMapData, compilerResult.program, - ts.filter(compilerResult.outputFiles, outputFile => Harness.Compiler.isJS(outputFile.emittedFileName))); - }); - } - }); + // it("SourceMapRecord for (" + moduleNameToString(moduleKind) + "): " + testCaseFileName, () => { + // if (compilerResult.sourceMapData) { + // Harness.Baseline.runBaseline("SourceMapRecord for (" + moduleNameToString(compilerResult.moduleKind) + "): " + testCaseFileName, getBaselineFolder(compilerResult.moduleKind) + testCaseJustName + ".sourcemap.txt", () => { + // return Harness.SourceMapRecorder.getSourceMapRecord(compilerResult.sourceMapData, compilerResult.program, + // ts.filter(compilerResult.outputFiles, outputFile => Harness.Compiler.isJS(outputFile.emittedFileName))); + // }); + // } + // }); // Verify that all the generated .d.ts files compile From c0a89aad1c7ea1185f9dae52b6b051102b763a35 Mon Sep 17 00:00:00 2001 From: Vladimir Matveev Date: Fri, 8 Apr 2016 17:25:40 -0700 Subject: [PATCH 17/58] handle export default --- src/compiler/transformers/module/es6.ts | 16 ++++++++++++++++ tests/baselines/reference/es6ExportEquals.js | 1 - 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/src/compiler/transformers/module/es6.ts b/src/compiler/transformers/module/es6.ts index 944e8cd6b5d..9355b476247 100644 --- a/src/compiler/transformers/module/es6.ts +++ b/src/compiler/transformers/module/es6.ts @@ -23,6 +23,8 @@ namespace ts { switch (node.kind) { case SyntaxKind.ImportDeclaration: return visitImportDeclaration(node); + case SyntaxKind.ImportEqualsDeclaration: + return visitImportEqualsDeclaration(node); case SyntaxKind.ImportClause: return visitImportClause(node); case SyntaxKind.NamedImports: @@ -30,11 +32,25 @@ namespace ts { return visitNamedBindings(node); case SyntaxKind.ImportSpecifier: return visitImportSpecifier(node); + case SyntaxKind.ExportAssignment: + return visitExportAssignment(node); } return node; } + function visitExportAssignment(node: ExportAssignment): ExportDeclaration { + if (node.isExportEquals) { + return undefined; // do not emit export equals for ES6 + } + const original = getOriginalNode(node); + return nodeIsSynthesized(original) || resolver.isValueAliasDeclaration(original) ? node: undefined; + } + + function visitImportEqualsDeclaration(node: ImportEqualsDeclaration): ImportEqualsDeclaration { + return !isExternalModuleImportEqualsDeclaration(node) || resolver.isReferencedAliasDeclaration(node) ? node : undefined; + } + function visitImportDeclaration(node: ImportDeclaration) { if (node.importClause) { const newImportClause = visitNode(node.importClause, visitor, isImportClause); diff --git a/tests/baselines/reference/es6ExportEquals.js b/tests/baselines/reference/es6ExportEquals.js index 5b9944a5a12..e4cf13758ff 100644 --- a/tests/baselines/reference/es6ExportEquals.js +++ b/tests/baselines/reference/es6ExportEquals.js @@ -7,7 +7,6 @@ export = f; //// [es6ExportEquals.js] export function f() { } -export = f; //// [es6ExportEquals.d.ts] From fab09b08106d3920041867e4b7d024bcd494fa19 Mon Sep 17 00:00:00 2001 From: Yui Date: Fri, 8 Apr 2016 18:12:25 -0700 Subject: [PATCH 18/58] Update baselines (#7981) --- .../baselines/reference/YieldExpression3_es6.js | 2 +- .../baselines/reference/YieldExpression4_es6.js | 2 +- .../baselines/reference/YieldExpression5_es6.js | 2 +- .../baselines/reference/YieldExpression6_es6.js | 2 +- .../baselines/reference/YieldExpression7_es6.js | 2 +- .../baselines/reference/YieldExpression8_es6.js | 2 +- .../baselines/reference/YieldExpression9_es6.js | 2 +- .../reference/YieldStarExpression3_es6.js | 2 +- .../reference/YieldStarExpression4_es6.js | 2 +- .../reference/arrowFunctionContexts.js | 8 ++++++-- .../reference/emitThisInSuperMethodCall.js | 3 ++- tests/baselines/reference/exportEqualsUmd.js | 6 +++--- .../reference/functionExpressionInWithBlock.js | 3 ++- .../reference/isolatedModulesPlainFile-UMD.js | 6 +++--- tests/baselines/reference/modulePrologueUmd.js | 6 +++--- ...LinePropertyAccessAndArrowFunctionIndent1.js | 3 ++- tests/baselines/reference/noEmitHelpers2.js | 4 ++-- .../reference/noImplicitUseStrict_system.js | 8 ++++---- .../reference/noImplicitUseStrict_umd.js | 6 +++--- .../reference/objectLiteralWithSemicolons4.js | 3 ++- tests/baselines/reference/superErrors.js | 17 +++++++++++++---- 21 files changed, 54 insertions(+), 37 deletions(-) diff --git a/tests/baselines/reference/YieldExpression3_es6.js b/tests/baselines/reference/YieldExpression3_es6.js index c69e8b29700..737b3534886 100644 --- a/tests/baselines/reference/YieldExpression3_es6.js +++ b/tests/baselines/reference/YieldExpression3_es6.js @@ -5,7 +5,7 @@ function* foo() { } //// [YieldExpression3_es6.js] -function foo() { +function* foo() { yield; yield; } diff --git a/tests/baselines/reference/YieldExpression4_es6.js b/tests/baselines/reference/YieldExpression4_es6.js index 5f50b721bc8..c97a7949b2b 100644 --- a/tests/baselines/reference/YieldExpression4_es6.js +++ b/tests/baselines/reference/YieldExpression4_es6.js @@ -5,7 +5,7 @@ function* foo() { } //// [YieldExpression4_es6.js] -function foo() { +function* foo() { yield; yield; } diff --git a/tests/baselines/reference/YieldExpression5_es6.js b/tests/baselines/reference/YieldExpression5_es6.js index 82b405a4cda..8599cfdb6bb 100644 --- a/tests/baselines/reference/YieldExpression5_es6.js +++ b/tests/baselines/reference/YieldExpression5_es6.js @@ -4,6 +4,6 @@ function* foo() { } //// [YieldExpression5_es6.js] -function foo() { +function* foo() { yield* ; } diff --git a/tests/baselines/reference/YieldExpression6_es6.js b/tests/baselines/reference/YieldExpression6_es6.js index 67d5a745e72..c511daec989 100644 --- a/tests/baselines/reference/YieldExpression6_es6.js +++ b/tests/baselines/reference/YieldExpression6_es6.js @@ -4,6 +4,6 @@ function* foo() { } //// [YieldExpression6_es6.js] -function foo() { +function* foo() { yield* foo; } diff --git a/tests/baselines/reference/YieldExpression7_es6.js b/tests/baselines/reference/YieldExpression7_es6.js index 226555dd6ef..8055b96ec73 100644 --- a/tests/baselines/reference/YieldExpression7_es6.js +++ b/tests/baselines/reference/YieldExpression7_es6.js @@ -4,6 +4,6 @@ function* foo() { } //// [YieldExpression7_es6.js] -function foo() { +function* foo() { yield foo; } diff --git a/tests/baselines/reference/YieldExpression8_es6.js b/tests/baselines/reference/YieldExpression8_es6.js index 990164af20d..cc92b79c722 100644 --- a/tests/baselines/reference/YieldExpression8_es6.js +++ b/tests/baselines/reference/YieldExpression8_es6.js @@ -6,6 +6,6 @@ function* foo() { //// [YieldExpression8_es6.js] yield(foo); -function foo() { +function* foo() { yield (foo); } diff --git a/tests/baselines/reference/YieldExpression9_es6.js b/tests/baselines/reference/YieldExpression9_es6.js index f38aa811fec..a2ffa0fa01b 100644 --- a/tests/baselines/reference/YieldExpression9_es6.js +++ b/tests/baselines/reference/YieldExpression9_es6.js @@ -4,6 +4,6 @@ var v = function*() { } //// [YieldExpression9_es6.js] -var v = function () { +var v = function* () { yield (foo); }; diff --git a/tests/baselines/reference/YieldStarExpression3_es6.js b/tests/baselines/reference/YieldStarExpression3_es6.js index 7463fc01bc1..e64306dc4cf 100644 --- a/tests/baselines/reference/YieldStarExpression3_es6.js +++ b/tests/baselines/reference/YieldStarExpression3_es6.js @@ -4,6 +4,6 @@ function *g() { } //// [YieldStarExpression3_es6.js] -function g() { +function* g() { yield* ; } diff --git a/tests/baselines/reference/YieldStarExpression4_es6.js b/tests/baselines/reference/YieldStarExpression4_es6.js index 6283b81cca3..8ec5fa0c933 100644 --- a/tests/baselines/reference/YieldStarExpression4_es6.js +++ b/tests/baselines/reference/YieldStarExpression4_es6.js @@ -4,6 +4,6 @@ function *g() { } //// [YieldStarExpression4_es6.js] -function g() { +function* g() { yield* []; } diff --git a/tests/baselines/reference/arrowFunctionContexts.js b/tests/baselines/reference/arrowFunctionContexts.js index 7b424107bd1..73e3be15e11 100644 --- a/tests/baselines/reference/arrowFunctionContexts.js +++ b/tests/baselines/reference/arrowFunctionContexts.js @@ -102,9 +102,10 @@ var __extends = (this && this.__extends) || function (d, b) { function __() { this.constructor = d; } d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); }; +var _this = this; // Arrow function used in with statement with (window) { - var p = function () { return this; }; + var p = function () { return _this; }; } // Arrow function as argument to super call var Base = (function () { @@ -130,6 +131,7 @@ var arr; // Incorrect error here (bug 829597) // Arrow function as enum value var E; (function (E) { + var _this = this; E[E["x"] = function () { return 4; }] = "x"; E[E["y"] = (function () { return _this; }).length] = "y"; // error, can't use this in enum })(E || (E = {})); @@ -142,9 +144,10 @@ var M; // Repeat above for module members that are functions? (necessary to redo all of them?) var M2; (function (M2) { + var _this = this; // Arrow function used in with statement with (window) { - var p = function () { return this; }; + var p = function () { return _this; }; } // Arrow function as argument to super call var Base = (function () { @@ -170,6 +173,7 @@ var M2; // Arrow function as enum value var E; (function (E) { + var _this = this; E[E["x"] = function () { return 4; }] = "x"; E[E["y"] = (function () { return _this; }).length] = "y"; })(E || (E = {})); diff --git a/tests/baselines/reference/emitThisInSuperMethodCall.js b/tests/baselines/reference/emitThisInSuperMethodCall.js index ba648b12d86..1350ed9d4c8 100644 --- a/tests/baselines/reference/emitThisInSuperMethodCall.js +++ b/tests/baselines/reference/emitThisInSuperMethodCall.js @@ -54,8 +54,9 @@ var RegisteredUser = (function (_super) { }; RegisteredUser.prototype.g = function () { function inner() { + var _this = this; (function () { - _super.sayHello.call(this); + _super.sayHello.call(_this); }); } }; diff --git a/tests/baselines/reference/exportEqualsUmd.js b/tests/baselines/reference/exportEqualsUmd.js index 615cc2cddbe..a9b75978d06 100644 --- a/tests/baselines/reference/exportEqualsUmd.js +++ b/tests/baselines/reference/exportEqualsUmd.js @@ -2,14 +2,14 @@ export = { ["hi"]: "there" }; //// [exportEqualsUmd.js] -(function (factory) { +(function (dependencies, factory) { if (typeof module === 'object' && typeof module.exports === 'object') { var v = factory(require, exports); if (v !== undefined) module.exports = v; } else if (typeof define === 'function' && define.amd) { - define(["require", "exports"], factory); + define(dependencies, factory); } -})(function (require, exports) { +})(["require", "exports"], function (require, exports) { "use strict"; return (_a = {}, _a["hi"] = "there", _a); var _a; diff --git a/tests/baselines/reference/functionExpressionInWithBlock.js b/tests/baselines/reference/functionExpressionInWithBlock.js index f2353412d5c..2fae2384313 100644 --- a/tests/baselines/reference/functionExpressionInWithBlock.js +++ b/tests/baselines/reference/functionExpressionInWithBlock.js @@ -11,7 +11,8 @@ function x() { function x() { with ({}) { function f() { - (function () { return this; }); + var _this = this; + (function () { return _this; }); } } } diff --git a/tests/baselines/reference/isolatedModulesPlainFile-UMD.js b/tests/baselines/reference/isolatedModulesPlainFile-UMD.js index 08ec75c48f0..ecc8ade69b7 100644 --- a/tests/baselines/reference/isolatedModulesPlainFile-UMD.js +++ b/tests/baselines/reference/isolatedModulesPlainFile-UMD.js @@ -5,14 +5,14 @@ run(1); //// [isolatedModulesPlainFile-UMD.js] -(function (factory) { +(function (dependencies, factory) { if (typeof module === 'object' && typeof module.exports === 'object') { var v = factory(require, exports); if (v !== undefined) module.exports = v; } else if (typeof define === 'function' && define.amd) { - define(["require", "exports"], factory); + define(dependencies, factory); } -})(function (require, exports) { +})(["require", "exports"], function (require, exports) { "use strict"; run(1); }); diff --git a/tests/baselines/reference/modulePrologueUmd.js b/tests/baselines/reference/modulePrologueUmd.js index a573559b7e9..fb366945d66 100644 --- a/tests/baselines/reference/modulePrologueUmd.js +++ b/tests/baselines/reference/modulePrologueUmd.js @@ -4,14 +4,14 @@ export class Foo {} //// [modulePrologueUmd.js] -(function (factory) { +(function (dependencies, factory) { if (typeof module === 'object' && typeof module.exports === 'object') { var v = factory(require, exports); if (v !== undefined) module.exports = v; } else if (typeof define === 'function' && define.amd) { - define(["require", "exports"], factory); + define(dependencies, factory); } -})(function (require, exports) { +})(["require", "exports"], function (require, exports) { "use strict"; var Foo = (function () { function Foo() { diff --git a/tests/baselines/reference/multiLinePropertyAccessAndArrowFunctionIndent1.js b/tests/baselines/reference/multiLinePropertyAccessAndArrowFunctionIndent1.js index 4821f1fe69c..2ada9f1bb52 100644 --- a/tests/baselines/reference/multiLinePropertyAccessAndArrowFunctionIndent1.js +++ b/tests/baselines/reference/multiLinePropertyAccessAndArrowFunctionIndent1.js @@ -6,8 +6,9 @@ return this.edit(role) //// [multiLinePropertyAccessAndArrowFunctionIndent1.js] +var _this = this; return this.edit(role) .then(function (role) { - return this.roleService.add(role) + return _this.roleService.add(role) .then(function (data) { return data.data; }); }); diff --git a/tests/baselines/reference/noEmitHelpers2.js b/tests/baselines/reference/noEmitHelpers2.js index fc4baf334c3..64acadf07e3 100644 --- a/tests/baselines/reference/noEmitHelpers2.js +++ b/tests/baselines/reference/noEmitHelpers2.js @@ -16,6 +16,6 @@ var A = (function () { }()); A = __decorate([ decorator, - __param(1, decorator), - __metadata('design:paramtypes', [Number, String]) + __param(1, decorator), + __metadata("design:paramtypes", [Number, String]) ], A); diff --git a/tests/baselines/reference/noImplicitUseStrict_system.js b/tests/baselines/reference/noImplicitUseStrict_system.js index cf5a7e1b261..f1100e20fd7 100644 --- a/tests/baselines/reference/noImplicitUseStrict_system.js +++ b/tests/baselines/reference/noImplicitUseStrict_system.js @@ -3,13 +3,13 @@ export var x = 0; //// [noImplicitUseStrict_system.js] -System.register([], function(exports_1, context_1) { +System.register([], function (exports_1, context_1) { var __moduleName = context_1 && context_1.id; var x; return { - setters:[], - execute: function() { + setters: [], + execute: function () { exports_1("x", x = 0); } - } + }; }); diff --git a/tests/baselines/reference/noImplicitUseStrict_umd.js b/tests/baselines/reference/noImplicitUseStrict_umd.js index ca252daeb9d..566c3bbe0b6 100644 --- a/tests/baselines/reference/noImplicitUseStrict_umd.js +++ b/tests/baselines/reference/noImplicitUseStrict_umd.js @@ -3,13 +3,13 @@ export var x = 0; //// [noImplicitUseStrict_umd.js] -(function (factory) { +(function (dependencies, factory) { if (typeof module === 'object' && typeof module.exports === 'object') { var v = factory(require, exports); if (v !== undefined) module.exports = v; } else if (typeof define === 'function' && define.amd) { - define(["require", "exports"], factory); + define(dependencies, factory); } -})(function (require, exports) { +})(["require", "exports"], function (require, exports) { exports.x = 0; }); diff --git a/tests/baselines/reference/objectLiteralWithSemicolons4.js b/tests/baselines/reference/objectLiteralWithSemicolons4.js index a01d52548ee..9e1e3dea4b9 100644 --- a/tests/baselines/reference/objectLiteralWithSemicolons4.js +++ b/tests/baselines/reference/objectLiteralWithSemicolons4.js @@ -5,4 +5,5 @@ var v = { //// [objectLiteralWithSemicolons4.js] var v = { - a: }; + a: +}; diff --git a/tests/baselines/reference/superErrors.js b/tests/baselines/reference/superErrors.js index 0208e720b0c..fd70114d0fd 100644 --- a/tests/baselines/reference/superErrors.js +++ b/tests/baselines/reference/superErrors.js @@ -58,6 +58,7 @@ var __extends = (this && this.__extends) || function (d, b) { d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); }; function foo() { + var _this = this; // super in a non class context var x = _super.; var y = function () { return _super.; }; @@ -83,20 +84,28 @@ var RegisteredUser = (function (_super) { } // super call in a lambda in an inner function in a constructor function inner2() { - var x = function () { return _super.sayHello.call(this); }; + var _this = this; + var x = function () { return _super.sayHello.call(_this); }; } // super call in a lambda in a function expression in a constructor - (function () { return function () { return _super.; }; })(); + (function () { + var _this = this; + return function () { return _super.; }; + })(); } RegisteredUser.prototype.sayHello = function () { // super call in a method _super.prototype.sayHello.call(this); // super call in a lambda in an inner function in a method function inner() { - var x = function () { return _super.sayHello.call(this); }; + var _this = this; + var x = function () { return _super.sayHello.call(_this); }; } // super call in a lambda in a function expression in a constructor - (function () { return function () { return _super.; }; })(); + (function () { + var _this = this; + return function () { return _super.; }; + })(); }; RegisteredUser.staticFunction = function () { var _this = this; From a27b4d07ae2e9e26ec3d600376b102940e8dd2a6 Mon Sep 17 00:00:00 2001 From: Yui Date: Mon, 11 Apr 2016 15:36:49 -0700 Subject: [PATCH 19/58] [Transform]: fix emit __extends within system.registry (#7973) * Fix 7912: emit extends-helper inside System.registry * Fix 7912: emit extends-helper inside System.registry * Address PR: move setEmitNodeFlag into updateSourceFile * Address PR: fix comment --- src/compiler/transformers/module/system.ts | 8 ++++++-- tests/baselines/reference/systemModuleWithSuperClass.js | 4 ++-- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/src/compiler/transformers/module/system.ts b/src/compiler/transformers/module/system.ts index c18425a8bda..be9390beba8 100644 --- a/src/compiler/transformers/module/system.ts +++ b/src/compiler/transformers/module/system.ts @@ -10,6 +10,7 @@ namespace ts { } const { + getNodeEmitFlags, startLexicalEnvironment, endLexicalEnvironment, hoistVariableDeclaration, @@ -120,6 +121,8 @@ namespace ts { ); // Write the call to `System.register` + // Clear the emit-helpers flag for later passes since we'll have already used it in the module body + // So the helper will be emit at the correct position instead of at the top of the source-file return updateSourceFile(node, [ createStatement( createCall( @@ -129,7 +132,7 @@ namespace ts { : [dependencies, body] ) ) - ]); + ], /*nodeEmitFlags*/ ~NodeEmitFlags.EmitEmitHelpers & getNodeEmitFlags(node)); } /** @@ -1374,9 +1377,10 @@ namespace ts { hoistBindingElement(node, /*isExported*/ false); } - function updateSourceFile(node: SourceFile, statements: Statement[]) { + function updateSourceFile(node: SourceFile, statements: Statement[], nodeEmitFlags: NodeEmitFlags) { const updated = getMutableClone(node); updated.statements = createNodeArray(statements, node.statements); + setNodeEmitFlags(updated, nodeEmitFlags); return updated; } } diff --git a/tests/baselines/reference/systemModuleWithSuperClass.js b/tests/baselines/reference/systemModuleWithSuperClass.js index a9bb4418608..31cd542d2e2 100644 --- a/tests/baselines/reference/systemModuleWithSuperClass.js +++ b/tests/baselines/reference/systemModuleWithSuperClass.js @@ -30,14 +30,14 @@ System.register([], function (exports_1, context_1) { }; }); //// [bar.js] -System.register(['./foo'], function(exports_1, context_1) { +System.register(["./foo"], function (exports_1, context_1) { "use strict"; - var __moduleName = context_1 && context_1.id; var __extends = (this && this.__extends) || function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; function __() { this.constructor = d; } d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); }; + var __moduleName = context_1 && context_1.id; var foo_1, Bar; return { setters: [ From 2cb7401a56d89bb80ed58c9d0ede7dfbf63c933b Mon Sep 17 00:00:00 2001 From: Nathan Shively-Sanders Date: Mon, 11 Apr 2016 14:27:18 -0700 Subject: [PATCH 20/58] Do not emit ES6 import/export inside namespaces ES6 imports and exports are illegal inside namespaces. In order to emit syntactically legal code, skip emit for these incorrect statements. --- src/compiler/transformers/ts.ts | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/src/compiler/transformers/ts.ts b/src/compiler/transformers/ts.ts index 0b8c11a66e2..90bac017d5a 100644 --- a/src/compiler/transformers/ts.ts +++ b/src/compiler/transformers/ts.ts @@ -157,7 +157,15 @@ namespace ts { * @param node The node to visit. */ function namespaceElementVisitorWorker(node: Node): VisitResult { - if (node.transformFlags & TransformFlags.TypeScript || hasModifier(node, ModifierFlags.Export)) { + if (node.kind === SyntaxKind.ExportDeclaration || + node.kind === SyntaxKind.ImportDeclaration || + node.kind === SyntaxKind.ImportClause || + (node.kind === SyntaxKind.ImportEqualsDeclaration && + (node).moduleReference.kind === SyntaxKind.ExternalModuleReference)) { + // do not emit ES6 imports and exports since they are illegal inside a namespace + return createNotEmittedStatement(node); + } + else if (node.transformFlags & TransformFlags.TypeScript || hasModifier(node, ModifierFlags.Export)) { // This node is explicitly marked as TypeScript, or is exported at the namespace // level, so we should transform the node. return visitTypeScript(node); @@ -2903,4 +2911,4 @@ namespace ts { && resolver.getNodeCheckFlags(getOriginalNode(currentSuperContainer)) & (NodeCheckFlags.AsyncMethodWithSuper | NodeCheckFlags.AsyncMethodWithSuperBinding); } } -} \ No newline at end of file +} From 221c0f36564729313900558c89a13342a43c12a6 Mon Sep 17 00:00:00 2001 From: Nathan Shively-Sanders Date: Tue, 12 Apr 2016 09:56:51 -0700 Subject: [PATCH 21/58] Update es5 module internal imports test and related baselines --- .../es5ModuleInternalNamedImports.errors.txt | 18 +++++++++++++++++- .../reference/es5ModuleInternalNamedImports.js | 5 ++++- .../reference/es6ModuleInternalNamedImports.js | 7 ------- .../es6ModuleInternalNamedImports2.js | 7 ------- .../exportDeclarationInInternalModule.js | 1 - .../compiler/es5ModuleInternalNamedImports.ts | 4 ++++ 6 files changed, 25 insertions(+), 17 deletions(-) diff --git a/tests/baselines/reference/es5ModuleInternalNamedImports.errors.txt b/tests/baselines/reference/es5ModuleInternalNamedImports.errors.txt index f51ff27a412..936f381628d 100644 --- a/tests/baselines/reference/es5ModuleInternalNamedImports.errors.txt +++ b/tests/baselines/reference/es5ModuleInternalNamedImports.errors.txt @@ -6,9 +6,13 @@ tests/cases/compiler/es5ModuleInternalNamedImports.ts(27,5): error TS1194: Expor tests/cases/compiler/es5ModuleInternalNamedImports.ts(28,5): error TS1194: Export declarations are not permitted in a namespace. tests/cases/compiler/es5ModuleInternalNamedImports.ts(29,5): error TS1194: Export declarations are not permitted in a namespace. tests/cases/compiler/es5ModuleInternalNamedImports.ts(30,5): error TS1194: Export declarations are not permitted in a namespace. +tests/cases/compiler/es5ModuleInternalNamedImports.ts(31,25): error TS1147: Import declarations in a namespace cannot reference a module. +tests/cases/compiler/es5ModuleInternalNamedImports.ts(32,20): error TS1147: Import declarations in a namespace cannot reference a module. +tests/cases/compiler/es5ModuleInternalNamedImports.ts(33,32): error TS1147: Import declarations in a namespace cannot reference a module. +tests/cases/compiler/es5ModuleInternalNamedImports.ts(35,16): error TS2307: Cannot find module 'M3'. -==== tests/cases/compiler/es5ModuleInternalNamedImports.ts (8 errors) ==== +==== tests/cases/compiler/es5ModuleInternalNamedImports.ts (12 errors) ==== export module M { // variable @@ -55,5 +59,17 @@ tests/cases/compiler/es5ModuleInternalNamedImports.ts(30,5): error TS1194: Expor export {M_A as a}; ~~~~~~~~~~~~~~~~~~ !!! error TS1194: Export declarations are not permitted in a namespace. + import * as M2 from "M2"; + ~~~~ +!!! error TS1147: Import declarations in a namespace cannot reference a module. + import M4 from "M4"; + ~~~~ +!!! error TS1147: Import declarations in a namespace cannot reference a module. + export import M5 = require("M5"); + ~~~~ +!!! error TS1147: Import declarations in a namespace cannot reference a module. } + import M3 from "M3"; + ~~~~ +!!! error TS2307: Cannot find module 'M3'. \ No newline at end of file diff --git a/tests/baselines/reference/es5ModuleInternalNamedImports.js b/tests/baselines/reference/es5ModuleInternalNamedImports.js index e8963b7db40..2fcbd5a53d8 100644 --- a/tests/baselines/reference/es5ModuleInternalNamedImports.js +++ b/tests/baselines/reference/es5ModuleInternalNamedImports.js @@ -29,7 +29,11 @@ export module M { export {M_F as f}; export {M_E as e}; export {M_A as a}; + import * as M2 from "M2"; + import M4 from "M4"; + export import M5 = require("M5"); } +import M3 from "M3"; //// [es5ModuleInternalNamedImports.js] @@ -60,6 +64,5 @@ define(["require", "exports"], function (require, exports) { var M_E = M.M_E; // alias M.M_A = M_M; - // Reexports })(M = exports.M || (exports.M = {})); }); diff --git a/tests/baselines/reference/es6ModuleInternalNamedImports.js b/tests/baselines/reference/es6ModuleInternalNamedImports.js index 98504601d02..22d15b9fd61 100644 --- a/tests/baselines/reference/es6ModuleInternalNamedImports.js +++ b/tests/baselines/reference/es6ModuleInternalNamedImports.js @@ -55,11 +55,4 @@ export var M; var M_E = M.M_E; // alias M.M_A = M_M; - // Reexports - export { M_V as v }; - export { M_C as c }; - export { M_M as m }; - export { M_F as f }; - export { M_E as e }; - export { M_A as a }; })(M || (M = {})); diff --git a/tests/baselines/reference/es6ModuleInternalNamedImports2.js b/tests/baselines/reference/es6ModuleInternalNamedImports2.js index 98226a1e52b..35eabc9a65e 100644 --- a/tests/baselines/reference/es6ModuleInternalNamedImports2.js +++ b/tests/baselines/reference/es6ModuleInternalNamedImports2.js @@ -59,11 +59,4 @@ export var M; M.M_A = M_M; })(M || (M = {})); (function (M) { - // Reexports - export { M_V as v }; - export { M_C as c }; - export { M_M as m }; - export { M_F as f }; - export { M_E as e }; - export { M_A as a }; })(M || (M = {})); diff --git a/tests/baselines/reference/exportDeclarationInInternalModule.js b/tests/baselines/reference/exportDeclarationInInternalModule.js index ecd9d5adf4d..a9ea4bf5eda 100644 --- a/tests/baselines/reference/exportDeclarationInInternalModule.js +++ b/tests/baselines/reference/exportDeclarationInInternalModule.js @@ -53,7 +53,6 @@ var Bbb; return SomeType; }()); Bbb.SomeType = SomeType; - // this line causes the nullref })(Bbb || (Bbb = {})); var a; diff --git a/tests/cases/compiler/es5ModuleInternalNamedImports.ts b/tests/cases/compiler/es5ModuleInternalNamedImports.ts index 05943d1c67e..62b976a7df7 100644 --- a/tests/cases/compiler/es5ModuleInternalNamedImports.ts +++ b/tests/cases/compiler/es5ModuleInternalNamedImports.ts @@ -30,4 +30,8 @@ export module M { export {M_F as f}; export {M_E as e}; export {M_A as a}; + import * as M2 from "M2"; + import M4 from "M4"; + export import M5 = require("M5"); } +import M3 from "M3"; From e6670811b0b762b953ea3f7fe3bd53b00aa688ad Mon Sep 17 00:00:00 2001 From: Nathan Shively-Sanders Date: Tue, 12 Apr 2016 10:46:27 -0700 Subject: [PATCH 22/58] Remove parentheses and accept baselines --- tests/baselines/reference/emptyAssignmentPatterns02_ES5.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/baselines/reference/emptyAssignmentPatterns02_ES5.js b/tests/baselines/reference/emptyAssignmentPatterns02_ES5.js index 27a0b5f9b61..370e019104f 100644 --- a/tests/baselines/reference/emptyAssignmentPatterns02_ES5.js +++ b/tests/baselines/reference/emptyAssignmentPatterns02_ES5.js @@ -9,8 +9,8 @@ let x, y, z, a1, a2, a3; //// [emptyAssignmentPatterns02_ES5.js] var a; var x, y, z, a1, a2, a3; -((x = a.x, y = a.y, z = a.z, a)); -((a1 = a[0], a2 = a[1], a3 = a[2], a)); +(x = a.x, y = a.y, z = a.z, a); +(a1 = a[0], a2 = a[1], a3 = a[2], a); //// [emptyAssignmentPatterns02_ES5.d.ts] From 5e308b9b9a8fb8dfd777660687c255409dee0dff Mon Sep 17 00:00:00 2001 From: Sheetal Nandi Date: Tue, 12 Apr 2016 10:52:00 -0700 Subject: [PATCH 23/58] Fix the AV when accessing edge on IE debugger --- src/compiler/visitor.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/compiler/visitor.ts b/src/compiler/visitor.ts index 81f36399b62..6acf8fcf17d 100644 --- a/src/compiler/visitor.ts +++ b/src/compiler/visitor.ts @@ -461,7 +461,7 @@ namespace ts { const edgeTraversalPath = nodeEdgeTraversalMap[node.kind]; if (edgeTraversalPath) { for (const edge of edgeTraversalPath) { - const value = (>node)[edge.name]; + const value = edge && (>node)[edge.name]; if (value !== undefined) { result = isArray(value) ? reduceLeft(>value, f, result) @@ -619,7 +619,7 @@ namespace ts { const edgeTraversalPath = nodeEdgeTraversalMap[node.kind]; if (edgeTraversalPath) { for (const edge of edgeTraversalPath) { - const value = >node[edge.name]; + const value = edge && >node[edge.name]; if (value !== undefined) { let visited: Node | NodeArray; if (isArray(value)) { From 5cd5976650ec3b137707b474b304963c26b983b4 Mon Sep 17 00:00:00 2001 From: Mohamed Hegazy Date: Tue, 12 Apr 2016 11:45:53 -0700 Subject: [PATCH 24/58] Emit module names when --out is specified for system and amd modules --- src/compiler/transformer.ts | 1 + src/compiler/transformers/module/module.ts | 25 ++++++++++++++++++--- src/compiler/transformers/module/system.ts | 26 +++++++++++++++++++--- src/compiler/types.ts | 1 + 4 files changed, 47 insertions(+), 6 deletions(-) diff --git a/src/compiler/transformer.ts b/src/compiler/transformer.ts index ebacacf6c5f..1f4764da688 100644 --- a/src/compiler/transformer.ts +++ b/src/compiler/transformer.ts @@ -68,6 +68,7 @@ namespace ts { const context: TransformationContext = { getCompilerOptions: () => host.getCompilerOptions(), getEmitResolver: () => resolver, + getEmitHost: () => host, getNodeEmitFlags, setNodeEmitFlags, hoistVariableDeclaration, diff --git a/src/compiler/transformers/module/module.ts b/src/compiler/transformers/module/module.ts index 440aec62e3b..ee4722b8708 100644 --- a/src/compiler/transformers/module/module.ts +++ b/src/compiler/transformers/module/module.ts @@ -21,6 +21,7 @@ namespace ts { const compilerOptions = context.getCompilerOptions(); const resolver = context.getEmitResolver(); + const host = context.getEmitHost(); const languageVersion = getEmitScriptTarget(compilerOptions); const moduleKind = getEmitModuleKind(compilerOptions); const previousExpressionSubstitution = context.expressionSubstitution; @@ -91,7 +92,7 @@ namespace ts { */ function transformAMDModule(node: SourceFile) { const define = createIdentifier("define"); - const moduleName = node.moduleName ? createLiteral(node.moduleName) : undefined; + const moduleName = tryGetModuleNameFromFile(node, host, compilerOptions); return transformAsynchronousModule(node, define, moduleName, /*includeNonAmdDependencies*/ true); } @@ -771,8 +772,9 @@ namespace ts { function getExternalModuleNameLiteral(importNode: ImportDeclaration | ExportDeclaration | ImportEqualsDeclaration) { const moduleName = getExternalModuleName(importNode); if (moduleName.kind === SyntaxKind.StringLiteral) { - return tryRenameExternalModule(moduleName) - || createLiteral(moduleName); + return tryGetModuleNameFromDeclaration(importNode, host, resolver, compilerOptions) + || tryRenameExternalModule(moduleName) + || getSynthesizedClone(moduleName); } return undefined; @@ -802,6 +804,23 @@ namespace ts { } } + function tryGetModuleNameFromFile(file: SourceFile, host: EmitHost, options: CompilerOptions): StringLiteral { + if (!file) { + return undefined; + } + if (file.moduleName) { + return createLiteral(file.moduleName); + } + if (!isDeclarationFile(file) && (options.out || options.outFile)) { + return createLiteral(getExternalModuleNameFromPath(host, file.fileName)); + } + return undefined; + } + + function tryGetModuleNameFromDeclaration(declaration: ImportEqualsDeclaration | ImportDeclaration | ExportDeclaration, host: EmitHost, resolver: EmitResolver, compilerOptions: CompilerOptions) { + return tryGetModuleNameFromFile(resolver.getExternalModuleFileFromDeclaration(declaration), host, compilerOptions); + } + function createRequireCall(importNode: ImportDeclaration | ImportEqualsDeclaration | ExportDeclaration) { const moduleName = getExternalModuleNameLiteral(importNode); const args: Expression[] = []; diff --git a/src/compiler/transformers/module/system.ts b/src/compiler/transformers/module/system.ts index be9390beba8..5712b01f513 100644 --- a/src/compiler/transformers/module/system.ts +++ b/src/compiler/transformers/module/system.ts @@ -20,6 +20,7 @@ namespace ts { const compilerOptions = context.getCompilerOptions(); const resolver = context.getEmitResolver(); + const host = context.getEmitHost(); const languageVersion = getEmitScriptTarget(compilerOptions); const previousExpressionSubstitution = context.expressionSubstitution; context.enableExpressionSubstitution(SyntaxKind.Identifier); @@ -106,6 +107,7 @@ namespace ts { // Add the body of the module. addSystemModuleBody(statements, node, dependencyGroups); + const moduleName = tryGetModuleNameFromFile(node, host, compilerOptions); const dependencies = createArrayLiteral(map(dependencyGroups, getNameOfDependencyGroup)); const body = createFunctionExpression( /*asteriskToken*/ undefined, @@ -127,8 +129,8 @@ namespace ts { createStatement( createCall( createPropertyAccess(createIdentifier("System"), "register"), - node.moduleName - ? [createLiteral(node.moduleName), dependencies, body] + moduleName + ? [moduleName, dependencies, body] : [dependencies, body] ) ) @@ -1155,7 +1157,8 @@ namespace ts { function getExternalModuleNameLiteral(importNode: ImportDeclaration | ExportDeclaration | ImportEqualsDeclaration) { const moduleName = getExternalModuleName(importNode); if (moduleName.kind === SyntaxKind.StringLiteral) { - return tryRenameExternalModule(moduleName) + return tryGetModuleNameFromDeclaration(importNode, host, resolver, compilerOptions) + || tryRenameExternalModule(moduleName) || getSynthesizedClone(moduleName); } @@ -1187,6 +1190,23 @@ namespace ts { } } + function tryGetModuleNameFromFile(file: SourceFile, host: EmitHost, options: CompilerOptions): StringLiteral { + if (!file) { + return undefined; + } + if (file.moduleName) { + return createLiteral(file.moduleName); + } + if (!isDeclarationFile(file) && (options.out || options.outFile)) { + return createLiteral(getExternalModuleNameFromPath(host, file.fileName)); + } + return undefined; + } + + function tryGetModuleNameFromDeclaration(declaration: ImportEqualsDeclaration | ImportDeclaration | ExportDeclaration, host: EmitHost, resolver: EmitResolver, compilerOptions: CompilerOptions) { + return tryGetModuleNameFromFile(resolver.getExternalModuleFileFromDeclaration(declaration), host, compilerOptions); + } + /** * Gets a name to use for a DeclarationStatement. * @param node The declaration statement. diff --git a/src/compiler/types.ts b/src/compiler/types.ts index 7723abfe270..2238cd4f22b 100644 --- a/src/compiler/types.ts +++ b/src/compiler/types.ts @@ -2892,6 +2892,7 @@ namespace ts { export interface TransformationContext extends LexicalEnvironment { getCompilerOptions(): CompilerOptions; getEmitResolver(): EmitResolver; + getEmitHost(): EmitHost; getNodeEmitFlags(node: Node): NodeEmitFlags; setNodeEmitFlags(node: T, flags: NodeEmitFlags): T; hoistFunctionDeclaration(node: FunctionDeclaration): void; From 219f1b01663650da7a1b9208378ea41627fa6049 Mon Sep 17 00:00:00 2001 From: Sheetal Nandi Date: Tue, 12 Apr 2016 14:15:41 -0700 Subject: [PATCH 25/58] Fix the name when synthesized node is clone of auto generate identifier kind This fixes variable declaration created for default exported class without name Fixes #7875 --- src/compiler/printer.ts | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/compiler/printer.ts b/src/compiler/printer.ts index f39793a80af..398908edd82 100644 --- a/src/compiler/printer.ts +++ b/src/compiler/printer.ts @@ -2607,8 +2607,10 @@ const _super = (function (geti, seti) { function getSourceNodeForGeneratedName(name: Identifier) { let node: Node = name; while (node.original !== undefined) { + const nodeId = node.id; node = node.original; - if (isIdentifier(node) && node.autoGenerateKind === GeneratedIdentifierKind.Node) { + // If this is not the exact clone of identifier use this identifier to generate the name + if (isIdentifier(node) && node.autoGenerateKind === GeneratedIdentifierKind.Node && node.id !== nodeId) { break; } } From 286d9079eb9005637e08c9cc1c168241d51d644f Mon Sep 17 00:00:00 2001 From: Vladimir Matveev Date: Tue, 12 Apr 2016 14:18:58 -0700 Subject: [PATCH 26/58] don't generate temp variables for computed property names in enums --- src/compiler/transformers/ts.ts | 13 +++++++++---- .../reference/literalsInComputedProperties1.js | 2 +- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/src/compiler/transformers/ts.ts b/src/compiler/transformers/ts.ts index 0b8c11a66e2..7c2cd76912c 100644 --- a/src/compiler/transformers/ts.ts +++ b/src/compiler/transformers/ts.ts @@ -1268,7 +1268,7 @@ namespace ts { // const prefix = getClassMemberPrefix(node, member); - const memberName = getExpressionForPropertyName(member); + const memberName = getExpressionForPropertyName(member, /*generateNameForComputedPropertyName*/ true); const descriptor = languageVersion > ScriptTarget.ES3 ? member.kind === SyntaxKind.PropertyDeclaration // We emit `void 0` here to indicate to `__decorate` that it can invoke `Object.defineProperty` directly, but that it @@ -1742,10 +1742,12 @@ namespace ts { * * @param member The member whose name should be converted into an expression. */ - function getExpressionForPropertyName(member: ClassElement | EnumMember): Expression { + function getExpressionForPropertyName(member: ClassElement | EnumMember, generateNameForComputedPropertyName: boolean): Expression { const name = member.name; if (isComputedPropertyName(name)) { - return getGeneratedNameForNode(name); + return generateNameForComputedPropertyName + ? getGeneratedNameForNode(name) + : (name).expression; } else if (isIdentifier(name)) { return createLiteral(name.text); @@ -2329,7 +2331,10 @@ namespace ts { * @param member The enum member node. */ function transformEnumMember(member: EnumMember): Statement { - const name = getExpressionForPropertyName(member); + // enums don't support computed properties + // we pass false as 'generateNameForComputedPropertyName' for a backward compatibility purposes + // old emitter always generate 'expression' part of the name as-is. + const name = getExpressionForPropertyName(member, /*generateNameForComputedPropertyName*/ false); return createStatement( createAssignment( createElementAccess( diff --git a/tests/baselines/reference/literalsInComputedProperties1.js b/tests/baselines/reference/literalsInComputedProperties1.js index 4c28a5e9083..77eb70c2396 100644 --- a/tests/baselines/reference/literalsInComputedProperties1.js +++ b/tests/baselines/reference/literalsInComputedProperties1.js @@ -80,7 +80,7 @@ z[3].toExponential(); z[4].toExponential(); var X; (function (X) { - X[X["1"] = 1] = "1"; + X[X[1] = 1] = 1; X[X[2] = 2] = 2; X[X["3"] = 3] = "3"; X[X["4"] = 4] = "4"; From 349ced2d402b43df21b63cfff22bc39f42788a45 Mon Sep 17 00:00:00 2001 From: Sheetal Nandi Date: Tue, 12 Apr 2016 14:39:50 -0700 Subject: [PATCH 27/58] Do not emit "from" if import clause is missing in import declaration --- src/compiler/printer.ts | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/compiler/printer.ts b/src/compiler/printer.ts index f39793a80af..512951a65e7 100644 --- a/src/compiler/printer.ts +++ b/src/compiler/printer.ts @@ -1643,8 +1643,10 @@ const _super = (function (geti, seti) { function emitImportDeclaration(node: ImportDeclaration) { emitModifiers(node, node.modifiers); write("import "); - emit(node.importClause); - write(" from "); + if (node.importClause) { + emit(node.importClause); + write(" from "); + } emitExpression(node.moduleSpecifier); write(";"); } From 80fab7c5a41534e3c506a90b7375a3cb753aae05 Mon Sep 17 00:00:00 2001 From: Vladimir Matveev Date: Tue, 12 Apr 2016 15:19:05 -0700 Subject: [PATCH 28/58] elide exports with no value side --- src/compiler/transformers/module/es6.ts | 36 ++++++++++++++++++++++++- 1 file changed, 35 insertions(+), 1 deletion(-) diff --git a/src/compiler/transformers/module/es6.ts b/src/compiler/transformers/module/es6.ts index 9355b476247..d2f4ca4f224 100644 --- a/src/compiler/transformers/module/es6.ts +++ b/src/compiler/transformers/module/es6.ts @@ -34,12 +34,18 @@ namespace ts { return visitImportSpecifier(node); case SyntaxKind.ExportAssignment: return visitExportAssignment(node); + case SyntaxKind.ExportDeclaration: + return visitExportDeclaration(node); + case SyntaxKind.NamedExports: + return visitNamedExports(node); + case SyntaxKind.ExportSpecifier: + return visitExportSpecifier(node); } return node; } - function visitExportAssignment(node: ExportAssignment): ExportDeclaration { + function visitExportAssignment(node: ExportAssignment): ExportAssignment { if (node.isExportEquals) { return undefined; // do not emit export equals for ES6 } @@ -47,6 +53,34 @@ namespace ts { return nodeIsSynthesized(original) || resolver.isValueAliasDeclaration(original) ? node: undefined; } + function visitExportDeclaration(node: ExportDeclaration): ExportDeclaration { + if (!node.exportClause) { + return node; // export * is always emitted + } + if (!resolver.isValueAliasDeclaration(node)) { + return undefined; + } + const newExportClause = visitNode(node.exportClause, visitor, isNamedExports, /*optional*/ true); + if (node.exportClause === newExportClause) { + return node; + } + return newExportClause + ? createExportDeclaration(newExportClause, node.moduleSpecifier) + : undefined; + } + + function visitNamedExports(node: NamedExports): NamedExports { + const newExports = visitNodes(node.elements, visitor, isExportSpecifier); + if (node.elements === newExports) { + return node; + } + return newExports.length ? createNamedExports(newExports) : undefined; + } + + function visitExportSpecifier(node: ExportSpecifier): ExportSpecifier { + return resolver.isValueAliasDeclaration(node) ? node : undefined; + } + function visitImportEqualsDeclaration(node: ImportEqualsDeclaration): ImportEqualsDeclaration { return !isExternalModuleImportEqualsDeclaration(node) || resolver.isReferencedAliasDeclaration(node) ? node : undefined; } From 9547d0de0df15e50ce777675d8736745219fa9ee Mon Sep 17 00:00:00 2001 From: Mohamed Hegazy Date: Tue, 12 Apr 2016 16:14:35 -0700 Subject: [PATCH 29/58] Move helpers to factory.ts --- src/compiler/factory.ts | 52 ++++++++++++++++++ src/compiler/transformers/module/module.ts | 58 ++------------------ src/compiler/transformers/module/system.ts | 63 ++-------------------- 3 files changed, 60 insertions(+), 113 deletions(-) diff --git a/src/compiler/factory.ts b/src/compiler/factory.ts index 0b32988a6ee..b620be2ed5e 100644 --- a/src/compiler/factory.ts +++ b/src/compiler/factory.ts @@ -1707,4 +1707,56 @@ namespace ts { nodes.hasTrailingComma = hasTrailingComma; return nodes; } + + export function getLocalNameForExternalImport(node: ImportDeclaration | ExportDeclaration | ImportEqualsDeclaration, sourceFile: SourceFile): Identifier { + const namespaceDeclaration = getNamespaceDeclarationNode(node); + if (namespaceDeclaration && !isDefaultImport(node)) { + return createIdentifier(getSourceTextOfNodeFromSourceFile(sourceFile, namespaceDeclaration.name)); + } + if (node.kind === SyntaxKind.ImportDeclaration && (node).importClause) { + return getGeneratedNameForNode(node); + } + if (node.kind === SyntaxKind.ExportDeclaration && (node).moduleSpecifier) { + return getGeneratedNameForNode(node); + } + } + + export function getExternalModuleNameLiteral(importNode: ImportDeclaration | ExportDeclaration | ImportEqualsDeclaration, sourceFile: SourceFile, host: EmitHost, resolver: EmitResolver, compilerOptions: CompilerOptions) { + const moduleName = getExternalModuleName(importNode); + if (moduleName.kind === SyntaxKind.StringLiteral) { + return tryGetModuleNameFromDeclaration(importNode, host, resolver, compilerOptions) + || tryRenameExternalModule(moduleName, sourceFile) + || getSynthesizedClone(moduleName); + } + + return undefined; + } + + /** + * Some bundlers (SystemJS builder) sometimes want to rename dependencies. + * Here we check if alternative name was provided for a given moduleName and return it if possible. + */ + function tryRenameExternalModule(moduleName: LiteralExpression, sourceFile: SourceFile) { + if (sourceFile.renamedDependencies && hasProperty(sourceFile.renamedDependencies, moduleName.text)) { + return createLiteral(sourceFile.renamedDependencies[moduleName.text]); + } + return undefined; + } + + export function tryGetModuleNameFromFile(file: SourceFile, host: EmitHost, options: CompilerOptions): StringLiteral { + if (!file) { + return undefined; + } + if (file.moduleName) { + return createLiteral(file.moduleName); + } + if (!isDeclarationFile(file) && (options.out || options.outFile)) { + return createLiteral(getExternalModuleNameFromPath(host, file.fileName)); + } + return undefined; + } + + function tryGetModuleNameFromDeclaration(declaration: ImportEqualsDeclaration | ImportDeclaration | ExportDeclaration, host: EmitHost, resolver: EmitResolver, compilerOptions: CompilerOptions) { + return tryGetModuleNameFromFile(resolver.getExternalModuleFileFromDeclaration(declaration), host, compilerOptions); + } } \ No newline at end of file diff --git a/src/compiler/transformers/module/module.ts b/src/compiler/transformers/module/module.ts index ee4722b8708..c0a021ec8de 100644 --- a/src/compiler/transformers/module/module.ts +++ b/src/compiler/transformers/module/module.ts @@ -769,60 +769,8 @@ namespace ts { ); } - function getExternalModuleNameLiteral(importNode: ImportDeclaration | ExportDeclaration | ImportEqualsDeclaration) { - const moduleName = getExternalModuleName(importNode); - if (moduleName.kind === SyntaxKind.StringLiteral) { - return tryGetModuleNameFromDeclaration(importNode, host, resolver, compilerOptions) - || tryRenameExternalModule(moduleName) - || getSynthesizedClone(moduleName); - } - - return undefined; - } - - /** - * Some bundlers (SystemJS builder) sometimes want to rename dependencies. - * Here we check if alternative name was provided for a given moduleName and return it if possible. - */ - function tryRenameExternalModule(moduleName: LiteralExpression) { - if (currentSourceFile.renamedDependencies && hasProperty(currentSourceFile.renamedDependencies, moduleName.text)) { - return createLiteral(currentSourceFile.renamedDependencies[moduleName.text]); - } - return undefined; - } - - function getLocalNameForExternalImport(node: ImportDeclaration | ExportDeclaration | ImportEqualsDeclaration): Identifier { - const namespaceDeclaration = getNamespaceDeclarationNode(node); - if (namespaceDeclaration && !isDefaultImport(node)) { - return createIdentifier(getSourceTextOfNodeFromSourceFile(currentSourceFile, namespaceDeclaration.name)); - } - if (node.kind === SyntaxKind.ImportDeclaration && (node).importClause) { - return getGeneratedNameForNode(node); - } - if (node.kind === SyntaxKind.ExportDeclaration && (node).moduleSpecifier) { - return getGeneratedNameForNode(node); - } - } - - function tryGetModuleNameFromFile(file: SourceFile, host: EmitHost, options: CompilerOptions): StringLiteral { - if (!file) { - return undefined; - } - if (file.moduleName) { - return createLiteral(file.moduleName); - } - if (!isDeclarationFile(file) && (options.out || options.outFile)) { - return createLiteral(getExternalModuleNameFromPath(host, file.fileName)); - } - return undefined; - } - - function tryGetModuleNameFromDeclaration(declaration: ImportEqualsDeclaration | ImportDeclaration | ExportDeclaration, host: EmitHost, resolver: EmitResolver, compilerOptions: CompilerOptions) { - return tryGetModuleNameFromFile(resolver.getExternalModuleFileFromDeclaration(declaration), host, compilerOptions); - } - function createRequireCall(importNode: ImportDeclaration | ImportEqualsDeclaration | ExportDeclaration) { - const moduleName = getExternalModuleNameLiteral(importNode); + const moduleName = getExternalModuleNameLiteral(importNode, currentSourceFile, host, resolver, compilerOptions); const args: Expression[] = []; if (isDefined(moduleName)) { args.push(moduleName); @@ -881,10 +829,10 @@ namespace ts { for (const importNode of externalImports) { // Find the name of the external module - const externalModuleName = getExternalModuleNameLiteral(importNode); + const externalModuleName = getExternalModuleNameLiteral(importNode, currentSourceFile, host, resolver, compilerOptions); // Find the name of the module alias, if there is one - const importAliasName = getLocalNameForExternalImport(importNode); + const importAliasName = getLocalNameForExternalImport(importNode, currentSourceFile); if (includeNonAmdDependencies && importAliasName) { aliasedModuleNames.push(externalModuleName); importAliasNames.push(createParameter(importAliasName)); diff --git a/src/compiler/transformers/module/system.ts b/src/compiler/transformers/module/system.ts index 5712b01f513..ca2c9e2b70e 100644 --- a/src/compiler/transformers/module/system.ts +++ b/src/compiler/transformers/module/system.ts @@ -343,11 +343,11 @@ namespace ts { const setters: Expression[] = []; for (const group of dependencyGroups) { // derive a unique name for parameter from the first named entry in the group - const localName = forEach(group.externalImports, getLocalNameForExternalImport); + const localName = forEach(group.externalImports, i => getLocalNameForExternalImport(i, currentSourceFile)); const parameterName = localName ? getGeneratedNameForNode(localName) : createUniqueName(""); const statements: Statement[] = []; for (const entry of group.externalImports) { - const importVariableName = getLocalNameForExternalImport(entry); + const importVariableName = getLocalNameForExternalImport(entry, currentSourceFile); switch (entry.kind) { case SyntaxKind.ImportDeclaration: if (!(entry).importClause) { @@ -536,7 +536,7 @@ namespace ts { function visitImportDeclaration(node: ImportDeclaration): Node { if (node.importClause && contains(externalImports, node)) { - hoistVariableDeclaration(getLocalNameForExternalImport(node)); + hoistVariableDeclaration(getLocalNameForExternalImport(node, currentSourceFile)); } return undefined; @@ -544,7 +544,7 @@ namespace ts { function visitImportEqualsDeclaration(node: ImportEqualsDeclaration): Node { if (contains(externalImports, node)) { - hoistVariableDeclaration(getLocalNameForExternalImport(node)); + hoistVariableDeclaration(getLocalNameForExternalImport(node, currentSourceFile)); } // NOTE(rbuckton): Do we support export import = require('') in System? @@ -1154,59 +1154,6 @@ namespace ts { return node; } - function getExternalModuleNameLiteral(importNode: ImportDeclaration | ExportDeclaration | ImportEqualsDeclaration) { - const moduleName = getExternalModuleName(importNode); - if (moduleName.kind === SyntaxKind.StringLiteral) { - return tryGetModuleNameFromDeclaration(importNode, host, resolver, compilerOptions) - || tryRenameExternalModule(moduleName) - || getSynthesizedClone(moduleName); - } - - return undefined; - } - - /** - * Some bundlers (SystemJS builder) sometimes want to rename dependencies. - * Here we check if alternative name was provided for a given moduleName and return it if possible. - */ - function tryRenameExternalModule(moduleName: LiteralExpression) { - if (currentSourceFile.renamedDependencies && hasProperty(currentSourceFile.renamedDependencies, moduleName.text)) { - return createLiteral(currentSourceFile.renamedDependencies[moduleName.text]); - } - - return undefined; - } - - function getLocalNameForExternalImport(node: ImportDeclaration | ExportDeclaration | ImportEqualsDeclaration): Identifier { - const namespaceDeclaration = getNamespaceDeclarationNode(node); - if (namespaceDeclaration && !isDefaultImport(node)) { - return createIdentifier(getSourceTextOfNodeFromSourceFile(currentSourceFile, namespaceDeclaration.name)); - } - if (node.kind === SyntaxKind.ImportDeclaration && (node).importClause) { - return getGeneratedNameForNode(node); - } - if (node.kind === SyntaxKind.ExportDeclaration && (node).moduleSpecifier) { - return getGeneratedNameForNode(node); - } - } - - function tryGetModuleNameFromFile(file: SourceFile, host: EmitHost, options: CompilerOptions): StringLiteral { - if (!file) { - return undefined; - } - if (file.moduleName) { - return createLiteral(file.moduleName); - } - if (!isDeclarationFile(file) && (options.out || options.outFile)) { - return createLiteral(getExternalModuleNameFromPath(host, file.fileName)); - } - return undefined; - } - - function tryGetModuleNameFromDeclaration(declaration: ImportEqualsDeclaration | ImportDeclaration | ExportDeclaration, host: EmitHost, resolver: EmitResolver, compilerOptions: CompilerOptions) { - return tryGetModuleNameFromFile(resolver.getExternalModuleFileFromDeclaration(declaration), host, compilerOptions); - } - /** * Gets a name to use for a DeclarationStatement. * @param node The declaration statement. @@ -1336,7 +1283,7 @@ namespace ts { const dependencyGroups: DependencyGroup[] = []; for (let i = 0; i < externalImports.length; i++) { const externalImport = externalImports[i]; - const externalModuleName = getExternalModuleNameLiteral(externalImport); + const externalModuleName = getExternalModuleNameLiteral(externalImport, currentSourceFile, host, resolver, compilerOptions); const text = externalModuleName.text; if (hasProperty(groupIndices, text)) { // deduplicate/group entries in dependency list by the dependency name From 3f3a61ba264156ecebaa3fc8867928532f3b86a1 Mon Sep 17 00:00:00 2001 From: Mohamed Hegazy Date: Tue, 12 Apr 2016 16:21:27 -0700 Subject: [PATCH 30/58] Use double quotes consistently for module names --- .../reference/ambientDeclarationsExternal.js | 2 +- ...rnalModuleWithInternalImportDeclaration.js | 2 +- ...lModuleWithoutInternalImportDeclaration.js | 2 +- tests/baselines/reference/asOperator4.js | 2 +- .../baselines/reference/chainedImportAlias.js | 2 +- .../baselines/reference/circularReference.js | 4 +-- .../reference/classExtendsAcrossFiles.js | 4 +-- .../collisionExportsRequireAndAlias.js | 2 +- .../baselines/reference/commonjsSafeImport.js | 2 +- .../reference/constDeclarations-access5.js | 2 +- .../reference/declFileForExportedImport.js | 2 +- .../declarationEmit_nameConflicts.js | 2 +- ...ratorInstantiateModulesInFunctionBodies.js | 2 +- ...adataWithImportDeclarationNameCollision.js | 6 ++--- ...dataWithImportDeclarationNameCollision2.js | 6 ++--- ...dataWithImportDeclarationNameCollision3.js | 6 ++--- ...dataWithImportDeclarationNameCollision4.js | 6 ++--- ...dataWithImportDeclarationNameCollision5.js | 6 ++--- ...dataWithImportDeclarationNameCollision6.js | 6 ++--- ...dataWithImportDeclarationNameCollision7.js | 6 ++--- ...dataWithImportDeclarationNameCollision8.js | 6 ++--- .../reference/dependencyViaImportAlias.js | 2 +- .../baselines/reference/elidingImportNames.js | 4 +-- .../reference/enumFromExternalModule.js | 2 +- .../reference/exportAssignDottedName.js | 2 +- .../exportAssignImportedIdentifier.js | 4 +-- .../baselines/reference/exportAssignTypes.js | 14 +++++----- .../exportAssignmentCircularModules.js | 2 +- .../reference/exportDeclaredModule.js | 2 +- .../reference/exportEqualCallable.js | 2 +- .../reference/exportEqualErrorType.js | 2 +- .../reference/exportEqualMemberMissing.js | 2 +- tests/baselines/reference/exportImport.js | 4 +-- .../reference/exportImportMultipleFiles.js | 2 +- .../extendClassExpressionFromModule.js | 2 +- .../reference/externalModuleAssignToVar.js | 2 +- .../externalModuleExportingGenericClass.js | 2 +- .../externalModuleImmutableBindings.js | 2 +- ...ceOfImportDeclarationWithExportModifier.js | 2 +- ...ernceResolutionOrderInImportDeclaration.js | 2 +- .../reference/externalModuleResolution.js | 2 +- .../reference/externalModuleResolution2.js | 2 +- ...sAnExternalModuleInsideAnInternalModule.js | 2 +- .../reference/importShadowsGlobalName.js | 2 +- .../reference/importUsedInExtendsList1.js | 2 +- .../reference/jsxImportInAttribute.js | 2 +- tests/baselines/reference/jsxViaImport.js | 2 +- .../reference/localAliasExportAssignment.js | 2 +- .../memberAccessMustUseModuleInstances.js | 2 +- .../reference/mergedDeclarations6.js | 2 +- .../moduleAliasAsFunctionArgument.js | 2 +- tests/baselines/reference/moduleScoping.js | 2 +- .../baselines/reference/multiImportExport.js | 6 ++--- .../reference/nameDelimitedBySlashes.js | 2 +- .../reference/nameWithFileExtension.js | 2 +- .../reference/nameWithRelativePaths.js | 6 ++--- .../outFilerootDirModuleNamesSystem.js | 27 ++++++++++--------- .../reference/outModuleConcatSystem.js | 22 +++++++-------- .../reference/reexportClassDefinition.js | 4 +-- .../reference/relativePathMustResolve.js | 2 +- .../relativePathToDeclarationFile.js | 6 ++--- .../reference/shorthand-property-es6-amd.js | 2 +- .../shorthandPropertyAssignmentInES6Module.js | 4 +-- .../reference/staticInstanceResolution3.js | 2 +- ... with emit decorators and emit metadata.js | 2 +- .../reference/tsxElementResolution17.js | 2 +- .../reference/tsxElementResolution19.js | 2 +- .../reference/tsxExternalModuleEmit1.js | 6 ++--- .../reference/tsxExternalModuleEmit2.js | 2 +- tests/baselines/reference/tsxPreserveEmit1.js | 2 +- .../tsxStatelessFunctionComponents2.js | 2 +- .../tsxStatelessFunctionComponents3.js | 2 +- ...pressionWithUndefinedCallResolutionData.js | 2 +- .../reference/typeofAmbientExternalModules.js | 4 +-- .../reference/typeofExternalModules.js | 4 +-- ...typesOnlyExternalModuleStillHasInstance.js | 2 +- .../baselines/reference/umd-augmentation-1.js | 2 +- .../baselines/reference/umd-augmentation-3.js | 2 +- tests/baselines/reference/umd3.js | 2 +- tests/baselines/reference/umd4.js | 2 +- tests/baselines/reference/umd5.js | 2 +- .../reference/undeclaredModuleError.js | 2 +- 82 files changed, 144 insertions(+), 143 deletions(-) diff --git a/tests/baselines/reference/ambientDeclarationsExternal.js b/tests/baselines/reference/ambientDeclarationsExternal.js index 42375bc1d09..b92993128ab 100644 --- a/tests/baselines/reference/ambientDeclarationsExternal.js +++ b/tests/baselines/reference/ambientDeclarationsExternal.js @@ -29,6 +29,6 @@ var n: number; //// [consumer.js] "use strict"; // Ambient external module members are always exported with or without export keyword when module lacks export assignment -var imp3 = require('equ2'); +var imp3 = require("equ2"); var n = imp3.x; var n; diff --git a/tests/baselines/reference/ambientExternalModuleWithInternalImportDeclaration.js b/tests/baselines/reference/ambientExternalModuleWithInternalImportDeclaration.js index 77d8e2d830d..c91adaff864 100644 --- a/tests/baselines/reference/ambientExternalModuleWithInternalImportDeclaration.js +++ b/tests/baselines/reference/ambientExternalModuleWithInternalImportDeclaration.js @@ -20,7 +20,7 @@ var c = new A(); //// [ambientExternalModuleWithInternalImportDeclaration_0.js] //// [ambientExternalModuleWithInternalImportDeclaration_1.js] -define(["require", "exports", 'M'], function (require, exports, A) { +define(["require", "exports", "M"], function (require, exports, A) { "use strict"; var c = new A(); }); diff --git a/tests/baselines/reference/ambientExternalModuleWithoutInternalImportDeclaration.js b/tests/baselines/reference/ambientExternalModuleWithoutInternalImportDeclaration.js index 158992234a2..4c70a338bc3 100644 --- a/tests/baselines/reference/ambientExternalModuleWithoutInternalImportDeclaration.js +++ b/tests/baselines/reference/ambientExternalModuleWithoutInternalImportDeclaration.js @@ -19,7 +19,7 @@ var c = new A(); //// [ambientExternalModuleWithoutInternalImportDeclaration_0.js] //// [ambientExternalModuleWithoutInternalImportDeclaration_1.js] -define(["require", "exports", 'M'], function (require, exports, A) { +define(["require", "exports", "M"], function (require, exports, A) { "use strict"; var c = new A(); }); diff --git a/tests/baselines/reference/asOperator4.js b/tests/baselines/reference/asOperator4.js index 14978ce285c..41edf92416b 100644 --- a/tests/baselines/reference/asOperator4.js +++ b/tests/baselines/reference/asOperator4.js @@ -18,7 +18,7 @@ function foo() { } exports.foo = foo; //// [bar.js] "use strict"; -var foo_1 = require('./foo'); +var foo_1 = require("./foo"); // These should emit identically foo_1.foo; foo_1.foo; diff --git a/tests/baselines/reference/chainedImportAlias.js b/tests/baselines/reference/chainedImportAlias.js index 2b1111f3096..a6113d5f241 100644 --- a/tests/baselines/reference/chainedImportAlias.js +++ b/tests/baselines/reference/chainedImportAlias.js @@ -20,6 +20,6 @@ var m; })(m = exports.m || (exports.m = {})); //// [chainedImportAlias_file1.js] "use strict"; -var x = require('./chainedImportAlias_file0'); +var x = require("./chainedImportAlias_file0"); var y = x; y.m.foo(); diff --git a/tests/baselines/reference/circularReference.js b/tests/baselines/reference/circularReference.js index 52fe5f3ef54..193b3e1da07 100644 --- a/tests/baselines/reference/circularReference.js +++ b/tests/baselines/reference/circularReference.js @@ -35,7 +35,7 @@ export module M1 { //// [foo1.js] "use strict"; -var foo2 = require('./foo2'); +var foo2 = require("./foo2"); var M1; (function (M1) { var C1 = (function () { @@ -50,7 +50,7 @@ var M1; })(M1 = exports.M1 || (exports.M1 = {})); //// [foo2.js] "use strict"; -var foo1 = require('./foo1'); +var foo1 = require("./foo1"); var M1; (function (M1) { var C1 = (function () { diff --git a/tests/baselines/reference/classExtendsAcrossFiles.js b/tests/baselines/reference/classExtendsAcrossFiles.js index b533b880036..0805389f268 100644 --- a/tests/baselines/reference/classExtendsAcrossFiles.js +++ b/tests/baselines/reference/classExtendsAcrossFiles.js @@ -26,7 +26,7 @@ var __extends = (this && this.__extends) || function (d, b) { function __() { this.constructor = d; } d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); }; -var a_1 = require('./a'); +var a_1 = require("./a"); exports.b = { f: function () { var A = (function () { @@ -51,7 +51,7 @@ var __extends = (this && this.__extends) || function (d, b) { function __() { this.constructor = d; } d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); }; -var b_1 = require('./b'); +var b_1 = require("./b"); exports.a = { f: function () { var A = (function () { diff --git a/tests/baselines/reference/collisionExportsRequireAndAlias.js b/tests/baselines/reference/collisionExportsRequireAndAlias.js index cbf9633b314..d7785dc73cf 100644 --- a/tests/baselines/reference/collisionExportsRequireAndAlias.js +++ b/tests/baselines/reference/collisionExportsRequireAndAlias.js @@ -32,7 +32,7 @@ define(["require", "exports"], function (require, exports) { exports.bar2 = bar2; }); //// [collisionExportsRequireAndAlias_file2.js] -define(["require", "exports", 'collisionExportsRequireAndAlias_file1', 'collisionExportsRequireAndAlias_file3333'], function (require, exports, require, exports) { +define(["require", "exports", "collisionExportsRequireAndAlias_file1", "collisionExportsRequireAndAlias_file3333"], function (require, exports, require, exports) { "use strict"; function foo() { require.bar(); diff --git a/tests/baselines/reference/commonjsSafeImport.js b/tests/baselines/reference/commonjsSafeImport.js index dd5acba597c..93439a418f6 100644 --- a/tests/baselines/reference/commonjsSafeImport.js +++ b/tests/baselines/reference/commonjsSafeImport.js @@ -16,7 +16,7 @@ function Foo() { } exports.Foo = Foo; //// [main.js] "use strict"; -var _10_lib_1 = require('./10_lib'); +var _10_lib_1 = require("./10_lib"); _10_lib_1.Foo(); diff --git a/tests/baselines/reference/constDeclarations-access5.js b/tests/baselines/reference/constDeclarations-access5.js index 8ebd1716005..1da0cf40fcd 100644 --- a/tests/baselines/reference/constDeclarations-access5.js +++ b/tests/baselines/reference/constDeclarations-access5.js @@ -54,7 +54,7 @@ define(["require", "exports"], function (require, exports) { exports.x = 0; }); //// [constDeclarations_access_2.js] -define(["require", "exports", 'constDeclarations_access_1'], function (require, exports, m) { +define(["require", "exports", "constDeclarations_access_1"], function (require, exports, m) { "use strict"; // Errors m.x = 1; diff --git a/tests/baselines/reference/declFileForExportedImport.js b/tests/baselines/reference/declFileForExportedImport.js index 266e030128e..6870e16f941 100644 --- a/tests/baselines/reference/declFileForExportedImport.js +++ b/tests/baselines/reference/declFileForExportedImport.js @@ -16,7 +16,7 @@ var z = b.x; //// [declFileForExportedImport_1.js] "use strict"; /// -exports.a = require('./declFileForExportedImport_0'); +exports.a = require("./declFileForExportedImport_0"); var y = exports.a.x; exports.b = exports.a; var z = exports.b.x; diff --git a/tests/baselines/reference/declarationEmit_nameConflicts.js b/tests/baselines/reference/declarationEmit_nameConflicts.js index 5004ded4837..957a0da472a 100644 --- a/tests/baselines/reference/declarationEmit_nameConflicts.js +++ b/tests/baselines/reference/declarationEmit_nameConflicts.js @@ -63,7 +63,7 @@ var f; module.exports = f; //// [declarationEmit_nameConflicts_0.js] "use strict"; -var im = require('./declarationEmit_nameConflicts_1'); +var im = require("./declarationEmit_nameConflicts_1"); var M; (function (M) { function f() { } diff --git a/tests/baselines/reference/decoratorInstantiateModulesInFunctionBodies.js b/tests/baselines/reference/decoratorInstantiateModulesInFunctionBodies.js index 28b620a3e8c..fc8dc1c5515 100644 --- a/tests/baselines/reference/decoratorInstantiateModulesInFunctionBodies.js +++ b/tests/baselines/reference/decoratorInstantiateModulesInFunctionBodies.js @@ -33,7 +33,7 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key, else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r; return c > 3 && r && Object.defineProperty(target, key, r), r; }; -var a_1 = require('./a'); +var a_1 = require("./a"); function filter(handler) { return function (target, propertyKey) { // ... diff --git a/tests/baselines/reference/decoratorMetadataWithImportDeclarationNameCollision.js b/tests/baselines/reference/decoratorMetadataWithImportDeclarationNameCollision.js index a0bc68bd8d8..258635a5f3a 100644 --- a/tests/baselines/reference/decoratorMetadataWithImportDeclarationNameCollision.js +++ b/tests/baselines/reference/decoratorMetadataWithImportDeclarationNameCollision.js @@ -35,7 +35,7 @@ var db = (function () { exports.db = db; //// [service.js] "use strict"; -var db_1 = require('./db'); +var db_1 = require("./db"); function someDecorator(target) { return target; } @@ -47,7 +47,7 @@ var MyClass = (function () { return MyClass; }()); MyClass = __decorate([ - someDecorator, - __metadata('design:paramtypes', [db_1.db]) + 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 49a2983ce70..104e449bc0c 100644 --- a/tests/baselines/reference/decoratorMetadataWithImportDeclarationNameCollision2.js +++ b/tests/baselines/reference/decoratorMetadataWithImportDeclarationNameCollision2.js @@ -35,7 +35,7 @@ var db = (function () { exports.db = db; //// [service.js] "use strict"; -var db_1 = require('./db'); +var db_1 = require("./db"); function someDecorator(target) { return target; } @@ -47,7 +47,7 @@ var MyClass = (function () { return MyClass; }()); MyClass = __decorate([ - someDecorator, - __metadata('design:paramtypes', [db_1.db]) + 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 f3c1d1b5da5..2925cad6afe 100644 --- a/tests/baselines/reference/decoratorMetadataWithImportDeclarationNameCollision3.js +++ b/tests/baselines/reference/decoratorMetadataWithImportDeclarationNameCollision3.js @@ -35,7 +35,7 @@ var db = (function () { exports.db = db; //// [service.js] "use strict"; -var db = require('./db'); +var db = require("./db"); function someDecorator(target) { return target; } @@ -47,7 +47,7 @@ var MyClass = (function () { return MyClass; }()); MyClass = __decorate([ - someDecorator, - __metadata('design:paramtypes', [db.db]) + 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 3448352eaaf..73ae697f396 100644 --- a/tests/baselines/reference/decoratorMetadataWithImportDeclarationNameCollision4.js +++ b/tests/baselines/reference/decoratorMetadataWithImportDeclarationNameCollision4.js @@ -35,7 +35,7 @@ var db = (function () { exports.db = db; //// [service.js] "use strict"; -var db_1 = require('./db'); // error no default export +var db_1 = require("./db"); // error no default export function someDecorator(target) { return target; } @@ -47,7 +47,7 @@ var MyClass = (function () { return MyClass; }()); MyClass = __decorate([ - someDecorator, - __metadata('design:paramtypes', [Object]) + someDecorator, + __metadata("design:paramtypes", [Object]) ], MyClass); exports.MyClass = MyClass; diff --git a/tests/baselines/reference/decoratorMetadataWithImportDeclarationNameCollision5.js b/tests/baselines/reference/decoratorMetadataWithImportDeclarationNameCollision5.js index 8eae92ec4d1..b99621fd7e2 100644 --- a/tests/baselines/reference/decoratorMetadataWithImportDeclarationNameCollision5.js +++ b/tests/baselines/reference/decoratorMetadataWithImportDeclarationNameCollision5.js @@ -36,7 +36,7 @@ Object.defineProperty(exports, "__esModule", { value: true }); exports.default = db; //// [service.js] "use strict"; -var db_1 = require('./db'); +var db_1 = require("./db"); function someDecorator(target) { return target; } @@ -48,7 +48,7 @@ var MyClass = (function () { return MyClass; }()); MyClass = __decorate([ - someDecorator, - __metadata('design:paramtypes', [db_1.default]) + 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 26e714c16a1..4970dca3201 100644 --- a/tests/baselines/reference/decoratorMetadataWithImportDeclarationNameCollision6.js +++ b/tests/baselines/reference/decoratorMetadataWithImportDeclarationNameCollision6.js @@ -36,7 +36,7 @@ Object.defineProperty(exports, "__esModule", { value: true }); exports.default = db; //// [service.js] "use strict"; -var db_1 = require('./db'); +var db_1 = require("./db"); function someDecorator(target) { return target; } @@ -48,7 +48,7 @@ var MyClass = (function () { return MyClass; }()); MyClass = __decorate([ - someDecorator, - __metadata('design:paramtypes', [db_1.default]) + 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 1d3b8a92349..28d403044bb 100644 --- a/tests/baselines/reference/decoratorMetadataWithImportDeclarationNameCollision7.js +++ b/tests/baselines/reference/decoratorMetadataWithImportDeclarationNameCollision7.js @@ -36,7 +36,7 @@ Object.defineProperty(exports, "__esModule", { value: true }); exports.default = db; //// [service.js] "use strict"; -var db_1 = require('./db'); +var db_1 = require("./db"); function someDecorator(target) { return target; } @@ -48,7 +48,7 @@ var MyClass = (function () { return MyClass; }()); MyClass = __decorate([ - someDecorator, - __metadata('design:paramtypes', [Object]) + someDecorator, + __metadata("design:paramtypes", [Object]) ], MyClass); exports.MyClass = MyClass; diff --git a/tests/baselines/reference/decoratorMetadataWithImportDeclarationNameCollision8.js b/tests/baselines/reference/decoratorMetadataWithImportDeclarationNameCollision8.js index 910008b9c27..dd5cee66f8b 100644 --- a/tests/baselines/reference/decoratorMetadataWithImportDeclarationNameCollision8.js +++ b/tests/baselines/reference/decoratorMetadataWithImportDeclarationNameCollision8.js @@ -35,7 +35,7 @@ var db = (function () { exports.db = db; //// [service.js] "use strict"; -var database = require('./db'); +var database = require("./db"); function someDecorator(target) { return target; } @@ -47,7 +47,7 @@ var MyClass = (function () { return MyClass; }()); MyClass = __decorate([ - someDecorator, - __metadata('design:paramtypes', [database.db]) + someDecorator, + __metadata("design:paramtypes", [database.db]) ], MyClass); exports.MyClass = MyClass; diff --git a/tests/baselines/reference/dependencyViaImportAlias.js b/tests/baselines/reference/dependencyViaImportAlias.js index fad51e2ee1f..8e12bb9bd2c 100644 --- a/tests/baselines/reference/dependencyViaImportAlias.js +++ b/tests/baselines/reference/dependencyViaImportAlias.js @@ -21,7 +21,7 @@ define(["require", "exports"], function (require, exports) { exports.A = A; }); //// [B.js] -define(["require", "exports", 'A'], function (require, exports, a) { +define(["require", "exports", "A"], function (require, exports, a) { "use strict"; var A = a.A; return A; diff --git a/tests/baselines/reference/elidingImportNames.js b/tests/baselines/reference/elidingImportNames.js index 573c86425dc..94fa1f7e852 100644 --- a/tests/baselines/reference/elidingImportNames.js +++ b/tests/baselines/reference/elidingImportNames.js @@ -23,8 +23,8 @@ exports.main = 10; exports.main = 10; //// [elidingImportNames_test.js] "use strict"; -var a = require('./elidingImportNames_main'); // alias used in typeof +var a = require("./elidingImportNames_main"); // alias used in typeof var b = a; var x; -var a2 = require('./elidingImportNames_main1'); // alias not used in typeof +var a2 = require("./elidingImportNames_main1"); // alias not used in typeof var b2 = a2; diff --git a/tests/baselines/reference/enumFromExternalModule.js b/tests/baselines/reference/enumFromExternalModule.js index 5561517341d..77f0e643969 100644 --- a/tests/baselines/reference/enumFromExternalModule.js +++ b/tests/baselines/reference/enumFromExternalModule.js @@ -19,5 +19,5 @@ var Mode = exports.Mode; //// [enumFromExternalModule_1.js] "use strict"; /// -var f = require('./enumFromExternalModule_0'); +var f = require("./enumFromExternalModule_0"); var x = f.Mode.Open; diff --git a/tests/baselines/reference/exportAssignDottedName.js b/tests/baselines/reference/exportAssignDottedName.js index 39fd33b0131..c9c3ffa80c4 100644 --- a/tests/baselines/reference/exportAssignDottedName.js +++ b/tests/baselines/reference/exportAssignDottedName.js @@ -18,5 +18,5 @@ function x() { exports.x = x; //// [foo2.js] "use strict"; -var foo1 = require('./foo1'); +var foo1 = require("./foo1"); module.exports = foo1.x; diff --git a/tests/baselines/reference/exportAssignImportedIdentifier.js b/tests/baselines/reference/exportAssignImportedIdentifier.js index 334f33fdc34..a469e90b619 100644 --- a/tests/baselines/reference/exportAssignImportedIdentifier.js +++ b/tests/baselines/reference/exportAssignImportedIdentifier.js @@ -22,10 +22,10 @@ function x() { exports.x = x; //// [foo2.js] "use strict"; -var foo1 = require('./foo1'); +var foo1 = require("./foo1"); var x = foo1.x; module.exports = x; //// [foo3.js] "use strict"; -var foo2 = require('./foo2'); +var foo2 = require("./foo2"); var x = foo2(); // should be boolean diff --git a/tests/baselines/reference/exportAssignTypes.js b/tests/baselines/reference/exportAssignTypes.js index 60cf4e7eef5..02b34715483 100644 --- a/tests/baselines/reference/exportAssignTypes.js +++ b/tests/baselines/reference/exportAssignTypes.js @@ -85,17 +85,17 @@ function x(a) { module.exports = x; //// [consumer.js] "use strict"; -var iString = require('./expString'); +var iString = require("./expString"); var v1 = iString; -var iNumber = require('./expNumber'); +var iNumber = require("./expNumber"); var v2 = iNumber; -var iBoolean = require('./expBoolean'); +var iBoolean = require("./expBoolean"); var v3 = iBoolean; -var iArray = require('./expArray'); +var iArray = require("./expArray"); var v4 = iArray; -var iObject = require('./expObject'); +var iObject = require("./expObject"); var v5 = iObject; -var iAny = require('./expAny'); +var iAny = require("./expAny"); var v6 = iAny; -var iGeneric = require('./expGeneric'); +var iGeneric = require("./expGeneric"); var v7 = iGeneric; diff --git a/tests/baselines/reference/exportAssignmentCircularModules.js b/tests/baselines/reference/exportAssignmentCircularModules.js index 73338840590..696c746f104 100644 --- a/tests/baselines/reference/exportAssignmentCircularModules.js +++ b/tests/baselines/reference/exportAssignmentCircularModules.js @@ -32,7 +32,7 @@ define(["require", "exports", "./foo_2"], function (require, exports, foo2) { return Foo; }); //// [foo_0.js] -define(["require", "exports", './foo_1'], function (require, exports, foo1) { +define(["require", "exports", "./foo_1"], function (require, exports, foo1) { "use strict"; var Foo; (function (Foo) { diff --git a/tests/baselines/reference/exportDeclaredModule.js b/tests/baselines/reference/exportDeclaredModule.js index af0f1b9eca1..419fecf42e0 100644 --- a/tests/baselines/reference/exportDeclaredModule.js +++ b/tests/baselines/reference/exportDeclaredModule.js @@ -17,5 +17,5 @@ var x: number = foo1.b(); module.exports = M1; //// [foo2.js] "use strict"; -var foo1 = require('./foo1'); +var foo1 = require("./foo1"); var x = foo1.b(); diff --git a/tests/baselines/reference/exportEqualCallable.js b/tests/baselines/reference/exportEqualCallable.js index 681c3ca4c19..9138da0d33d 100644 --- a/tests/baselines/reference/exportEqualCallable.js +++ b/tests/baselines/reference/exportEqualCallable.js @@ -20,7 +20,7 @@ define(["require", "exports"], function (require, exports) { return server; }); //// [exportEqualCallable_1.js] -define(["require", "exports", 'exportEqualCallable_0'], function (require, exports, connect) { +define(["require", "exports", "exportEqualCallable_0"], function (require, exports, connect) { "use strict"; connect(); }); diff --git a/tests/baselines/reference/exportEqualErrorType.js b/tests/baselines/reference/exportEqualErrorType.js index 653c7052153..aa715b7d9f2 100644 --- a/tests/baselines/reference/exportEqualErrorType.js +++ b/tests/baselines/reference/exportEqualErrorType.js @@ -28,7 +28,7 @@ define(["require", "exports"], function (require, exports) { return server; }); //// [exportEqualErrorType_1.js] -define(["require", "exports", 'exportEqualErrorType_0'], function (require, exports, connect) { +define(["require", "exports", "exportEqualErrorType_0"], function (require, exports, connect) { "use strict"; connect().use(connect.static('foo')); // Error 1 The property 'static' does not exist on value of type ''. }); diff --git a/tests/baselines/reference/exportEqualMemberMissing.js b/tests/baselines/reference/exportEqualMemberMissing.js index b25ef1d3083..39074e10372 100644 --- a/tests/baselines/reference/exportEqualMemberMissing.js +++ b/tests/baselines/reference/exportEqualMemberMissing.js @@ -28,5 +28,5 @@ module.exports = server; //// [exportEqualMemberMissing_1.js] "use strict"; /// -var connect = require('./exportEqualMemberMissing_0'); +var connect = require("./exportEqualMemberMissing_0"); connect().use(connect.static('foo')); // Error 1 The property 'static' does not exist on value of type ''. diff --git a/tests/baselines/reference/exportImport.js b/tests/baselines/reference/exportImport.js index eb0623efced..8f785282080 100644 --- a/tests/baselines/reference/exportImport.js +++ b/tests/baselines/reference/exportImport.js @@ -27,12 +27,12 @@ define(["require", "exports"], function (require, exports) { return Widget1; }); //// [exporter.js] -define(["require", "exports", './w1'], function (require, exports, w) { +define(["require", "exports", "./w1"], function (require, exports, w) { "use strict"; exports.w = w; }); //// [consumer.js] -define(["require", "exports", './exporter'], function (require, exports, e) { +define(["require", "exports", "./exporter"], function (require, exports, e) { "use strict"; function w() { return new e.w(); diff --git a/tests/baselines/reference/exportImportMultipleFiles.js b/tests/baselines/reference/exportImportMultipleFiles.js index 6a0bf61459e..345d2a6885a 100644 --- a/tests/baselines/reference/exportImportMultipleFiles.js +++ b/tests/baselines/reference/exportImportMultipleFiles.js @@ -25,7 +25,7 @@ define(["require", "exports", "exportImportMultipleFiles_math"], function (requi exports.math.add(3, 4); // OK }); //// [exportImportMultipleFiles_userCode.js] -define(["require", "exports", './exportImportMultipleFiles_library'], function (require, exports, lib) { +define(["require", "exports", "./exportImportMultipleFiles_library"], function (require, exports, lib) { "use strict"; lib.math.add(3, 4); // Shouldnt be error }); diff --git a/tests/baselines/reference/extendClassExpressionFromModule.js b/tests/baselines/reference/extendClassExpressionFromModule.js index 56b54d2821f..6532603b73c 100644 --- a/tests/baselines/reference/extendClassExpressionFromModule.js +++ b/tests/baselines/reference/extendClassExpressionFromModule.js @@ -26,7 +26,7 @@ var __extends = (this && this.__extends) || function (d, b) { function __() { this.constructor = d; } d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); }; -var foo1 = require('./foo1'); +var foo1 = require("./foo1"); var x = foo1; var y = (function (_super) { __extends(y, _super); diff --git a/tests/baselines/reference/externalModuleAssignToVar.js b/tests/baselines/reference/externalModuleAssignToVar.js index e621b7c930b..47958ddd2ff 100644 --- a/tests/baselines/reference/externalModuleAssignToVar.js +++ b/tests/baselines/reference/externalModuleAssignToVar.js @@ -57,7 +57,7 @@ define(["require", "exports"], function (require, exports) { return D; }); //// [externalModuleAssignToVar_core.js] -define(["require", "exports", 'externalModuleAssignToVar_core_require', 'externalModuleAssignToVar_core_require2', 'externalModuleAssignToVar_ext'], function (require, exports, ext, ext2, ext3) { +define(["require", "exports", "externalModuleAssignToVar_core_require", "externalModuleAssignToVar_core_require2", "externalModuleAssignToVar_ext"], function (require, exports, ext, ext2, ext3) { "use strict"; var y1 = ext; y1 = ext; // ok diff --git a/tests/baselines/reference/externalModuleExportingGenericClass.js b/tests/baselines/reference/externalModuleExportingGenericClass.js index c4b8556bb80..e327e17160e 100644 --- a/tests/baselines/reference/externalModuleExportingGenericClass.js +++ b/tests/baselines/reference/externalModuleExportingGenericClass.js @@ -25,7 +25,7 @@ var C = (function () { module.exports = C; //// [externalModuleExportingGenericClass_file1.js] "use strict"; -var a = require('./externalModuleExportingGenericClass_file0'); +var a = require("./externalModuleExportingGenericClass_file0"); var v; // this should report error var v2 = (new a()).foo; var v3 = (new a()).foo; diff --git a/tests/baselines/reference/externalModuleImmutableBindings.js b/tests/baselines/reference/externalModuleImmutableBindings.js index 4193a71cc90..b50845024f4 100644 --- a/tests/baselines/reference/externalModuleImmutableBindings.js +++ b/tests/baselines/reference/externalModuleImmutableBindings.js @@ -57,7 +57,7 @@ exports.x = 1; //// [f2.js] "use strict"; // all mutations below are illegal and should be fixed -var stuff = require('./f1'); +var stuff = require("./f1"); var n = 'baz'; stuff.x = 0; stuff['x'] = 1; diff --git a/tests/baselines/reference/externalModuleReferenceOfImportDeclarationWithExportModifier.js b/tests/baselines/reference/externalModuleReferenceOfImportDeclarationWithExportModifier.js index cdcc0842b08..8a25c3711b2 100644 --- a/tests/baselines/reference/externalModuleReferenceOfImportDeclarationWithExportModifier.js +++ b/tests/baselines/reference/externalModuleReferenceOfImportDeclarationWithExportModifier.js @@ -16,7 +16,7 @@ define(["require", "exports"], function (require, exports) { ; }); //// [externalModuleReferenceOfImportDeclarationWithExportModifier_1.js] -define(["require", "exports", 'externalModuleReferenceOfImportDeclarationWithExportModifier_0'], function (require, exports, file1) { +define(["require", "exports", "externalModuleReferenceOfImportDeclarationWithExportModifier_0"], function (require, exports, file1) { "use strict"; exports.file1 = file1; exports.file1.foo(); diff --git a/tests/baselines/reference/externalModuleRefernceResolutionOrderInImportDeclaration.js b/tests/baselines/reference/externalModuleRefernceResolutionOrderInImportDeclaration.js index 1b5d41d8be4..5b0de7324ac 100644 --- a/tests/baselines/reference/externalModuleRefernceResolutionOrderInImportDeclaration.js +++ b/tests/baselines/reference/externalModuleRefernceResolutionOrderInImportDeclaration.js @@ -26,6 +26,6 @@ exports.foo = foo; //// [externalModuleRefernceResolutionOrderInImportDeclaration_file3.js] "use strict"; /// -var file1 = require('./externalModuleRefernceResolutionOrderInImportDeclaration_file1'); +var file1 = require("./externalModuleRefernceResolutionOrderInImportDeclaration_file1"); file1.foo(); file1.bar(); diff --git a/tests/baselines/reference/externalModuleResolution.js b/tests/baselines/reference/externalModuleResolution.js index 20dc7fa8dda..40b320ee37e 100644 --- a/tests/baselines/reference/externalModuleResolution.js +++ b/tests/baselines/reference/externalModuleResolution.js @@ -25,5 +25,5 @@ var M2; module.exports = M2; //// [consumer.js] "use strict"; -var x = require('./foo'); +var x = require("./foo"); x.Y; // .ts should be picked diff --git a/tests/baselines/reference/externalModuleResolution2.js b/tests/baselines/reference/externalModuleResolution2.js index 13560105544..44753c9f16d 100644 --- a/tests/baselines/reference/externalModuleResolution2.js +++ b/tests/baselines/reference/externalModuleResolution2.js @@ -26,5 +26,5 @@ var M2; module.exports = M2; //// [consumer.js] "use strict"; -var x = require('./foo'); +var x = require("./foo"); x.X; // .ts should be picked diff --git a/tests/baselines/reference/importAliasAnExternalModuleInsideAnInternalModule.js b/tests/baselines/reference/importAliasAnExternalModuleInsideAnInternalModule.js index 94c084df512..c7dd59f9ab7 100644 --- a/tests/baselines/reference/importAliasAnExternalModuleInsideAnInternalModule.js +++ b/tests/baselines/reference/importAliasAnExternalModuleInsideAnInternalModule.js @@ -23,7 +23,7 @@ var m; })(m = exports.m || (exports.m = {})); //// [importAliasAnExternalModuleInsideAnInternalModule_file1.js] "use strict"; -var r = require('./importAliasAnExternalModuleInsideAnInternalModule_file0'); +var r = require("./importAliasAnExternalModuleInsideAnInternalModule_file0"); var m_private; (function (m_private) { //import r2 = require('m'); // would be error diff --git a/tests/baselines/reference/importShadowsGlobalName.js b/tests/baselines/reference/importShadowsGlobalName.js index dbbf1710632..316a94d9069 100644 --- a/tests/baselines/reference/importShadowsGlobalName.js +++ b/tests/baselines/reference/importShadowsGlobalName.js @@ -26,7 +26,7 @@ var __extends = (this && this.__extends) || function (d, b) { function __() { this.constructor = d; } d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); }; -define(["require", "exports", 'Foo'], function (require, exports, Error) { +define(["require", "exports", "Foo"], function (require, exports, Error) { "use strict"; var Bar = (function (_super) { __extends(Bar, _super); diff --git a/tests/baselines/reference/importUsedInExtendsList1.js b/tests/baselines/reference/importUsedInExtendsList1.js index 1d242a53023..b9827d5bc93 100644 --- a/tests/baselines/reference/importUsedInExtendsList1.js +++ b/tests/baselines/reference/importUsedInExtendsList1.js @@ -27,7 +27,7 @@ var __extends = (this && this.__extends) || function (d, b) { d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); }; /// -var foo = require('./importUsedInExtendsList1_require'); +var foo = require("./importUsedInExtendsList1_require"); var Sub = (function (_super) { __extends(Sub, _super); function Sub() { diff --git a/tests/baselines/reference/jsxImportInAttribute.js b/tests/baselines/reference/jsxImportInAttribute.js index 552c7e26f12..c204ea7880d 100644 --- a/tests/baselines/reference/jsxImportInAttribute.js +++ b/tests/baselines/reference/jsxImportInAttribute.js @@ -17,6 +17,6 @@ let x = Test; // emit test_1.default //// [consumer.jsx] "use strict"; /// -var Test_1 = require('Test'); +var Test_1 = require("Test"); var x = Test_1["default"]; // emit test_1.default ; // ? diff --git a/tests/baselines/reference/jsxViaImport.js b/tests/baselines/reference/jsxViaImport.js index ba8efc9e7ab..63c84090c9c 100644 --- a/tests/baselines/reference/jsxViaImport.js +++ b/tests/baselines/reference/jsxViaImport.js @@ -31,7 +31,7 @@ var __extends = (this && this.__extends) || function (d, b) { d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); }; /// -var BaseComponent = require('BaseComponent'); +var BaseComponent = require("BaseComponent"); var TestComponent = (function (_super) { __extends(TestComponent, _super); function TestComponent() { diff --git a/tests/baselines/reference/localAliasExportAssignment.js b/tests/baselines/reference/localAliasExportAssignment.js index 4a8c519dc77..46ca09c2caa 100644 --- a/tests/baselines/reference/localAliasExportAssignment.js +++ b/tests/baselines/reference/localAliasExportAssignment.js @@ -23,5 +23,5 @@ module.exports = server; //// [localAliasExportAssignment_1.js] "use strict"; /// -var connect = require('./localAliasExportAssignment_0'); +var connect = require("./localAliasExportAssignment_0"); connect(); diff --git a/tests/baselines/reference/memberAccessMustUseModuleInstances.js b/tests/baselines/reference/memberAccessMustUseModuleInstances.js index 0071d0dfef0..00f913219a4 100644 --- a/tests/baselines/reference/memberAccessMustUseModuleInstances.js +++ b/tests/baselines/reference/memberAccessMustUseModuleInstances.js @@ -28,7 +28,7 @@ define(["require", "exports"], function (require, exports) { exports.Promise = Promise; }); //// [memberAccessMustUseModuleInstances_1.js] -define(["require", "exports", 'memberAccessMustUseModuleInstances_0'], function (require, exports, WinJS) { +define(["require", "exports", "memberAccessMustUseModuleInstances_0"], function (require, exports, WinJS) { "use strict"; WinJS.Promise.timeout(10); }); diff --git a/tests/baselines/reference/mergedDeclarations6.js b/tests/baselines/reference/mergedDeclarations6.js index 696ad27b2a6..2ff9d3e6604 100644 --- a/tests/baselines/reference/mergedDeclarations6.js +++ b/tests/baselines/reference/mergedDeclarations6.js @@ -42,7 +42,7 @@ var __extends = (this && this.__extends) || function (d, b) { function __() { this.constructor = d; } d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); }; -define(["require", "exports", './a'], function (require, exports, a_1) { +define(["require", "exports", "./a"], function (require, exports, a_1) { "use strict"; var B = (function (_super) { __extends(B, _super); diff --git a/tests/baselines/reference/moduleAliasAsFunctionArgument.js b/tests/baselines/reference/moduleAliasAsFunctionArgument.js index 3706eae6ae2..b75161da458 100644 --- a/tests/baselines/reference/moduleAliasAsFunctionArgument.js +++ b/tests/baselines/reference/moduleAliasAsFunctionArgument.js @@ -19,7 +19,7 @@ define(["require", "exports"], function (require, exports) { "use strict"; }); //// [moduleAliasAsFunctionArgument_1.js] -define(["require", "exports", 'moduleAliasAsFunctionArgument_0'], function (require, exports, a) { +define(["require", "exports", "moduleAliasAsFunctionArgument_0"], function (require, exports, a) { "use strict"; function fn(arg) { } diff --git a/tests/baselines/reference/moduleScoping.js b/tests/baselines/reference/moduleScoping.js index adfcd3673a8..f987c0c652d 100644 --- a/tests/baselines/reference/moduleScoping.js +++ b/tests/baselines/reference/moduleScoping.js @@ -33,7 +33,7 @@ exports.v3 = true; var v2 = [1, 2, 3]; // Module scope. Should not appear in global scope //// [file4.js] "use strict"; -var file3 = require('./file3'); +var file3 = require("./file3"); var t1 = v1; var t2 = v2; var t3 = file3.v3; diff --git a/tests/baselines/reference/multiImportExport.js b/tests/baselines/reference/multiImportExport.js index 34832c93966..2cd5440ce6e 100644 --- a/tests/baselines/reference/multiImportExport.js +++ b/tests/baselines/reference/multiImportExport.js @@ -37,17 +37,17 @@ var Adder = (function () { module.exports = Adder; //// [Math.js] "use strict"; -var Adder = require('./Adder'); +var Adder = require("./Adder"); var Math = { Adder: Adder }; module.exports = Math; //// [Drawing.js] "use strict"; -exports.Math = require('./Math/Math'); +exports.Math = require("./Math/Math"); //// [consumer.js] "use strict"; -var Drawing = require('./Drawing'); +var Drawing = require("./Drawing"); var addr = new Drawing.Math.Adder(); diff --git a/tests/baselines/reference/nameDelimitedBySlashes.js b/tests/baselines/reference/nameDelimitedBySlashes.js index 6d00b54d69b..93cf4e29d49 100644 --- a/tests/baselines/reference/nameDelimitedBySlashes.js +++ b/tests/baselines/reference/nameDelimitedBySlashes.js @@ -13,5 +13,5 @@ var x = foo.foo + 42; exports.foo = 42; //// [foo_1.js] "use strict"; -var foo = require('./test/foo_0'); +var foo = require("./test/foo_0"); var x = foo.foo + 42; diff --git a/tests/baselines/reference/nameWithFileExtension.js b/tests/baselines/reference/nameWithFileExtension.js index 2d487ede245..b76a9edadc2 100644 --- a/tests/baselines/reference/nameWithFileExtension.js +++ b/tests/baselines/reference/nameWithFileExtension.js @@ -10,5 +10,5 @@ var x = foo.foo + 42; //// [foo_1.js] "use strict"; -var foo = require('./foo_0.js'); +var foo = require("./foo_0.js"); var x = foo.foo + 42; diff --git a/tests/baselines/reference/nameWithRelativePaths.js b/tests/baselines/reference/nameWithRelativePaths.js index e348c5b1ced..d8b0eed43cf 100644 --- a/tests/baselines/reference/nameWithRelativePaths.js +++ b/tests/baselines/reference/nameWithRelativePaths.js @@ -40,9 +40,9 @@ var M2; })(M2 = exports.M2 || (exports.M2 = {})); //// [foo_3.js] "use strict"; -var foo0 = require('../foo_0'); -var foo1 = require('./test/foo_1'); -var foo2 = require('./.././test/foo_2'); +var foo0 = require("../foo_0"); +var foo1 = require("./test/foo_1"); +var foo2 = require("./.././test/foo_2"); if (foo2.M2.x) { var x = foo0.foo + foo1.f(); } diff --git a/tests/baselines/reference/outFilerootDirModuleNamesSystem.js b/tests/baselines/reference/outFilerootDirModuleNamesSystem.js index 18ec6ecc19b..6754f3ef89a 100644 --- a/tests/baselines/reference/outFilerootDirModuleNamesSystem.js +++ b/tests/baselines/reference/outFilerootDirModuleNamesSystem.js @@ -11,36 +11,37 @@ export default function foo() { new Foo(); } //// [output.js] -System.register("b", ["a"], function(exports_1, context_1) { +System.register("b", ["a"], function (exports_1, context_1) { "use strict"; var __moduleName = context_1 && context_1.id; - var a_1; function foo() { new a_1.default(); } + var a_1; exports_1("default", foo); return { - setters:[ + setters: [ function (a_1_1) { a_1 = a_1_1; - }], - execute: function() { + } + ], + execute: function () { } - } + }; }); -System.register("a", ["b"], function(exports_2, context_2) { +System.register("a", ["b"], function (exports_2, context_2) { "use strict"; var __moduleName = context_2 && context_2.id; - var b_1; - var Foo; + var b_1, Foo; return { - setters:[ + setters: [ function (b_1_1) { b_1 = b_1_1; - }], - execute: function() { + } + ], + execute: function () { Foo = class Foo { }; exports_2("default", Foo); b_1.default(); } - } + }; }); diff --git a/tests/baselines/reference/outModuleConcatSystem.js b/tests/baselines/reference/outModuleConcatSystem.js index 59bbb363022..b23b73caf83 100644 --- a/tests/baselines/reference/outModuleConcatSystem.js +++ b/tests/baselines/reference/outModuleConcatSystem.js @@ -14,13 +14,13 @@ var __extends = (this && this.__extends) || function (d, b) { function __() { this.constructor = d; } d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); }; -System.register("ref/a", [], function(exports_1, context_1) { +System.register("ref/a", [], function (exports_1, context_1) { "use strict"; var __moduleName = context_1 && context_1.id; var A; return { - setters:[], - execute: function() { + setters: [], + execute: function () { A = (function () { function A() { } @@ -28,19 +28,19 @@ System.register("ref/a", [], function(exports_1, context_1) { }()); exports_1("A", A); } - } + }; }); -System.register("b", ["ref/a"], function(exports_2, context_2) { +System.register("b", ["ref/a"], function (exports_2, context_2) { "use strict"; var __moduleName = context_2 && context_2.id; - var a_1; - var B; + var a_1, B; return { - setters:[ + setters: [ function (a_1_1) { a_1 = a_1_1; - }], - execute: function() { + } + ], + execute: function () { B = (function (_super) { __extends(B, _super); function B() { @@ -50,7 +50,7 @@ System.register("b", ["ref/a"], function(exports_2, context_2) { }(a_1.A)); exports_2("B", B); } - } + }; }); //# sourceMappingURL=all.js.map diff --git a/tests/baselines/reference/reexportClassDefinition.js b/tests/baselines/reference/reexportClassDefinition.js index ab5279d1d47..a4b68115ac2 100644 --- a/tests/baselines/reference/reexportClassDefinition.js +++ b/tests/baselines/reference/reexportClassDefinition.js @@ -27,7 +27,7 @@ var x = (function () { module.exports = x; //// [foo2.js] "use strict"; -var foo1 = require('./foo1'); +var foo1 = require("./foo1"); module.exports = { x: foo1 }; @@ -38,7 +38,7 @@ var __extends = (this && this.__extends) || function (d, b) { function __() { this.constructor = d; } d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); }; -var foo2 = require('./foo2'); +var foo2 = require("./foo2"); var x = (function (_super) { __extends(x, _super); function x() { diff --git a/tests/baselines/reference/relativePathMustResolve.js b/tests/baselines/reference/relativePathMustResolve.js index c25ffd4ab65..6986d8ddb68 100644 --- a/tests/baselines/reference/relativePathMustResolve.js +++ b/tests/baselines/reference/relativePathMustResolve.js @@ -10,5 +10,5 @@ var z = foo.x + 10; //// [foo_1.js] "use strict"; -var foo = require('./test/foo'); +var foo = require("./test/foo"); var z = foo.x + 10; diff --git a/tests/baselines/reference/relativePathToDeclarationFile.js b/tests/baselines/reference/relativePathToDeclarationFile.js index 75d6539cb3c..36673510aef 100644 --- a/tests/baselines/reference/relativePathToDeclarationFile.js +++ b/tests/baselines/reference/relativePathToDeclarationFile.js @@ -28,9 +28,9 @@ if(foo.M2.x){ //// [file1.js] "use strict"; -var foo = require('foo'); -var other = require('./other'); -var relMod = require('./sub/relMod'); +var foo = require("foo"); +var other = require("./other"); +var relMod = require("./sub/relMod"); if (foo.M2.x) { var x = new relMod(other.M2.x.charCodeAt(0)); } diff --git a/tests/baselines/reference/shorthand-property-es6-amd.js b/tests/baselines/reference/shorthand-property-es6-amd.js index 3cecc18b661..383d5d99e9e 100644 --- a/tests/baselines/reference/shorthand-property-es6-amd.js +++ b/tests/baselines/reference/shorthand-property-es6-amd.js @@ -6,7 +6,7 @@ const bar = { foo, baz }; //// [test.js] -define(["require", "exports", './foo'], function (require, exports, foo_1) { +define(["require", "exports", "./foo"], function (require, exports, foo_1) { "use strict"; const baz = 42; const bar = { foo: foo_1.foo, baz }; diff --git a/tests/baselines/reference/shorthandPropertyAssignmentInES6Module.js b/tests/baselines/reference/shorthandPropertyAssignmentInES6Module.js index d52622dffc7..fad9c37ea8f 100644 --- a/tests/baselines/reference/shorthandPropertyAssignmentInES6Module.js +++ b/tests/baselines/reference/shorthandPropertyAssignmentInES6Module.js @@ -20,8 +20,8 @@ use(foo); exports.x = 1; //// [test.js] "use strict"; -const existingModule_1 = require('./existingModule'); -const missingModule_1 = require('./missingModule'); +const existingModule_1 = require("./existingModule"); +const missingModule_1 = require("./missingModule"); const test = { x: existingModule_1.x, foo: missingModule_1.foo }; use(existingModule_1.x); use(missingModule_1.foo); diff --git a/tests/baselines/reference/staticInstanceResolution3.js b/tests/baselines/reference/staticInstanceResolution3.js index 238d1bdad13..c480fd33285 100644 --- a/tests/baselines/reference/staticInstanceResolution3.js +++ b/tests/baselines/reference/staticInstanceResolution3.js @@ -26,5 +26,5 @@ exports.Promise = Promise; //// [staticInstanceResolution3_1.js] "use strict"; /// -var WinJS = require('./staticInstanceResolution3_0'); +var WinJS = require("./staticInstanceResolution3_0"); WinJS.Promise.timeout(10); diff --git a/tests/baselines/reference/transpile/Transpile with emit decorators and emit metadata.js b/tests/baselines/reference/transpile/Transpile with emit decorators and emit metadata.js index be5c936010d..b6b17292c12 100644 --- a/tests/baselines/reference/transpile/Transpile with emit decorators and emit metadata.js +++ b/tests/baselines/reference/transpile/Transpile with emit decorators and emit metadata.js @@ -1,5 +1,5 @@ "use strict"; -var db_1 = require('./db'); +var db_1 = require("./db"); function someDecorator(target) { return target; } diff --git a/tests/baselines/reference/tsxElementResolution17.js b/tests/baselines/reference/tsxElementResolution17.js index 270c9254cbb..1f813b7e24b 100644 --- a/tests/baselines/reference/tsxElementResolution17.js +++ b/tests/baselines/reference/tsxElementResolution17.js @@ -29,7 +29,7 @@ import s2 = require('elements2'); //// [file.jsx] //// [consumer.jsx] -define(["require", "exports", 'elements1'], function (require, exports, s1) { +define(["require", "exports", "elements1"], function (require, exports, s1) { "use strict"; ; }); diff --git a/tests/baselines/reference/tsxElementResolution19.js b/tests/baselines/reference/tsxElementResolution19.js index 8114c5e4be5..f8c3f4b25be 100644 --- a/tests/baselines/reference/tsxElementResolution19.js +++ b/tests/baselines/reference/tsxElementResolution19.js @@ -32,7 +32,7 @@ define(["require", "exports"], function (require, exports) { exports.MyClass = MyClass; }); //// [file2.js] -define(["require", "exports", 'react', './file1'], function (require, exports, React, file1_1) { +define(["require", "exports", "react", "./file1"], function (require, exports, React, file1_1) { "use strict"; React.createElement(file1_1.MyClass, null); }); diff --git a/tests/baselines/reference/tsxExternalModuleEmit1.js b/tests/baselines/reference/tsxExternalModuleEmit1.js index 29aee544b3c..0d4e58d7008 100644 --- a/tests/baselines/reference/tsxExternalModuleEmit1.js +++ b/tests/baselines/reference/tsxExternalModuleEmit1.js @@ -38,7 +38,7 @@ var __extends = (this && this.__extends) || function (d, b) { function __() { this.constructor = d; } d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); }; -var React = require('react'); +var React = require("react"); var Button = (function (_super) { __extends(Button, _super); function Button() { @@ -57,9 +57,9 @@ var __extends = (this && this.__extends) || function (d, b) { function __() { this.constructor = d; } d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); }; -var React = require('react'); +var React = require("react"); // Should see var button_1 = require('./button') here -var button_1 = require('./button'); +var button_1 = require("./button"); var App = (function (_super) { __extends(App, _super); function App() { diff --git a/tests/baselines/reference/tsxExternalModuleEmit2.js b/tests/baselines/reference/tsxExternalModuleEmit2.js index 669152e02c3..4d511cdf81b 100644 --- a/tests/baselines/reference/tsxExternalModuleEmit2.js +++ b/tests/baselines/reference/tsxExternalModuleEmit2.js @@ -19,7 +19,7 @@ declare var Foo, React; //// [app.js] "use strict"; -var mod_1 = require('mod'); +var mod_1 = require("mod"); // Should see mod_1['default'] in emit here React.createElement(Foo, { handler: mod_1["default"] }); // Should see mod_1['default'] in emit here diff --git a/tests/baselines/reference/tsxPreserveEmit1.js b/tests/baselines/reference/tsxPreserveEmit1.js index 6d795c946c3..b9a7d369fc0 100644 --- a/tests/baselines/reference/tsxPreserveEmit1.js +++ b/tests/baselines/reference/tsxPreserveEmit1.js @@ -34,7 +34,7 @@ module M { //// [test.jsx] -define(["require", "exports", 'react', 'react-router'], function (require, exports, React, ReactRouter) { +define(["require", "exports", "react", "react-router"], function (require, exports, React, ReactRouter) { "use strict"; var Route = ReactRouter.Route; var routes1 = ; diff --git a/tests/baselines/reference/tsxStatelessFunctionComponents2.js b/tests/baselines/reference/tsxStatelessFunctionComponents2.js index 04d61d41218..b93832567d5 100644 --- a/tests/baselines/reference/tsxStatelessFunctionComponents2.js +++ b/tests/baselines/reference/tsxStatelessFunctionComponents2.js @@ -45,7 +45,7 @@ var __extends = (this && this.__extends) || function (d, b) { function __() { this.constructor = d; } d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); }; -var React = require('react'); +var React = require("react"); function Greet(x) { return
Hello, {x}
; } diff --git a/tests/baselines/reference/tsxStatelessFunctionComponents3.js b/tests/baselines/reference/tsxStatelessFunctionComponents3.js index d58586dd1ee..02ddcc8a58e 100644 --- a/tests/baselines/reference/tsxStatelessFunctionComponents3.js +++ b/tests/baselines/reference/tsxStatelessFunctionComponents3.js @@ -19,7 +19,7 @@ var App: React.StatelessComponent<{ children }> = ({children}) => ( ); //// [file.jsx] -define(["require", "exports", 'react'], function (require, exports, React) { +define(["require", "exports", "react"], function (require, exports, React) { "use strict"; var Foo = function (props) { return
; }; // Should be OK diff --git a/tests/baselines/reference/typeCheckObjectCreationExpressionWithUndefinedCallResolutionData.js b/tests/baselines/reference/typeCheckObjectCreationExpressionWithUndefinedCallResolutionData.js index 90470f58124..5590dac249f 100644 --- a/tests/baselines/reference/typeCheckObjectCreationExpressionWithUndefinedCallResolutionData.js +++ b/tests/baselines/reference/typeCheckObjectCreationExpressionWithUndefinedCallResolutionData.js @@ -20,7 +20,7 @@ function foo() { exports.foo = foo; //// [file2.js] "use strict"; -var f = require('./file1'); +var f = require("./file1"); f.foo(); diff --git a/tests/baselines/reference/typeofAmbientExternalModules.js b/tests/baselines/reference/typeofAmbientExternalModules.js index 9bcc5a2fa15..de158544d0d 100644 --- a/tests/baselines/reference/typeofAmbientExternalModules.js +++ b/tests/baselines/reference/typeofAmbientExternalModules.js @@ -38,8 +38,8 @@ module.exports = D; "use strict"; /// /// -var ext = require('./typeofAmbientExternalModules_0'); -var exp = require('./typeofAmbientExternalModules_1'); +var ext = require("./typeofAmbientExternalModules_0"); +var exp = require("./typeofAmbientExternalModules_1"); var y1 = ext; y1 = exp; var y2 = exp; diff --git a/tests/baselines/reference/typeofExternalModules.js b/tests/baselines/reference/typeofExternalModules.js index 0bb9f6820f6..1c43d28be8b 100644 --- a/tests/baselines/reference/typeofExternalModules.js +++ b/tests/baselines/reference/typeofExternalModules.js @@ -34,8 +34,8 @@ var D = (function () { module.exports = D; //// [typeofExternalModules_core.js] "use strict"; -var ext = require('./typeofExternalModules_external'); -var exp = require('./typeofExternalModules_exportAssign'); +var ext = require("./typeofExternalModules_external"); +var exp = require("./typeofExternalModules_exportAssign"); var y1 = ext; y1 = exp; var y2 = exp; diff --git a/tests/baselines/reference/typesOnlyExternalModuleStillHasInstance.js b/tests/baselines/reference/typesOnlyExternalModuleStillHasInstance.js index a90cf63bac4..1424f9343aa 100644 --- a/tests/baselines/reference/typesOnlyExternalModuleStillHasInstance.js +++ b/tests/baselines/reference/typesOnlyExternalModuleStillHasInstance.js @@ -24,7 +24,7 @@ var y: {M2: Object} = foo0; "use strict"; //// [foo_1.js] "use strict"; -var foo0 = require('./foo_0'); +var foo0 = require("./foo_0"); // Per 11.2.3, foo_0 should still be "instantiated", albeit with no members var x = {}; var y = foo0; diff --git a/tests/baselines/reference/umd-augmentation-1.js b/tests/baselines/reference/umd-augmentation-1.js index b3ffcf670a8..ee4c143486c 100644 --- a/tests/baselines/reference/umd-augmentation-1.js +++ b/tests/baselines/reference/umd-augmentation-1.js @@ -42,7 +42,7 @@ var t = p.x; //// [b.js] "use strict"; /// -var m = require('math2d'); +var m = require("math2d"); var v = new m.Vector(3, 2); var magnitude = m.getLength(v); var p = v.translate(5, 5); diff --git a/tests/baselines/reference/umd-augmentation-3.js b/tests/baselines/reference/umd-augmentation-3.js index 2b8eac7bf63..e9abf724881 100644 --- a/tests/baselines/reference/umd-augmentation-3.js +++ b/tests/baselines/reference/umd-augmentation-3.js @@ -48,7 +48,7 @@ var t = p.x; //// [b.js] "use strict"; /// -var m = require('math2d'); +var m = require("math2d"); var v = new m.Vector(3, 2); var magnitude = m.getLength(v); var p = v.translate(5, 5); diff --git a/tests/baselines/reference/umd3.js b/tests/baselines/reference/umd3.js index 5e869148beb..03e15be2ecf 100644 --- a/tests/baselines/reference/umd3.js +++ b/tests/baselines/reference/umd3.js @@ -16,7 +16,7 @@ let y: number = x.n; //// [a.js] "use strict"; -var Foo = require('./foo'); +var Foo = require("./foo"); Foo.fn(); var x; var y = x.n; diff --git a/tests/baselines/reference/umd4.js b/tests/baselines/reference/umd4.js index b7a7d1da0e2..d06fc3aba93 100644 --- a/tests/baselines/reference/umd4.js +++ b/tests/baselines/reference/umd4.js @@ -16,7 +16,7 @@ let y: number = x.n; //// [a.js] "use strict"; -var Bar = require('./foo'); +var Bar = require("./foo"); Bar.fn(); var x; var y = x.n; diff --git a/tests/baselines/reference/umd5.js b/tests/baselines/reference/umd5.js index d054daf93fd..95626132f77 100644 --- a/tests/baselines/reference/umd5.js +++ b/tests/baselines/reference/umd5.js @@ -18,7 +18,7 @@ let z = Foo; //// [a.js] "use strict"; -var Bar = require('./foo'); +var Bar = require("./foo"); Bar.fn(); var x; var y = x.n; diff --git a/tests/baselines/reference/undeclaredModuleError.js b/tests/baselines/reference/undeclaredModuleError.js index b768b0d9114..c9a43ab4ce6 100644 --- a/tests/baselines/reference/undeclaredModuleError.js +++ b/tests/baselines/reference/undeclaredModuleError.js @@ -16,7 +16,7 @@ function instrumentFile(covFileDir: string, covFileName: string, originalFilePat } //// [undeclaredModuleError.js] -define(["require", "exports", 'fs'], function (require, exports, fs) { +define(["require", "exports", "fs"], function (require, exports, fs) { "use strict"; function readdir(path, accept, callback) { } function join() { From 7c3df5acc7cebef0c351c80e101bcd1599eeec26 Mon Sep 17 00:00:00 2001 From: Mohamed Hegazy Date: Tue, 12 Apr 2016 16:21:51 -0700 Subject: [PATCH 31/58] Accept baseline: use strict in an empty module --- tests/baselines/reference/visibilityOfCrossModuleTypeUsage.js | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/baselines/reference/visibilityOfCrossModuleTypeUsage.js b/tests/baselines/reference/visibilityOfCrossModuleTypeUsage.js index cd654006403..c80d65158dc 100644 --- a/tests/baselines/reference/visibilityOfCrossModuleTypeUsage.js +++ b/tests/baselines/reference/visibilityOfCrossModuleTypeUsage.js @@ -26,6 +26,7 @@ function run(configuration: commands.IConfiguration) { } //// [visibilityOfCrossModuleTypeUsage_server.js] +"use strict"; //// [visibilityOfCrossModuleTypeUsage_commands.js] //visibilityOfCrossModuleTypeUsage "use strict"; From 7077003731be2256cc2f71891a97e0ab07de4eda Mon Sep 17 00:00:00 2001 From: Mohamed Hegazy Date: Tue, 12 Apr 2016 16:25:19 -0700 Subject: [PATCH 32/58] Accept baselines: syntactically invalid input --- tests/baselines/reference/constructorArgsErrors1.js | 2 +- tests/baselines/reference/constructorArgsErrors5.js | 2 +- .../reference/destructuringParameterDeclaration6.js | 7 +++++++ tests/baselines/reference/enumIdentifierLiterals.js | 8 ++++---- .../reference/exportDeclarationInInternalModule.js | 2 +- tests/baselines/reference/generatorTypeCheck56.js | 3 +-- tests/baselines/reference/importInsideModule.js | 1 + .../baselines/reference/invalidLetInForOfAndForIn_ES5.js | 4 ++-- .../baselines/reference/invalidLetInForOfAndForIn_ES6.js | 4 ++-- .../baselines/reference/invalidModuleWithVarStatements.js | 4 ++-- tests/baselines/reference/multipleExports.js | 1 + .../reference/objectTypesWithOptionalProperties2.js | 7 +++---- tests/baselines/reference/overloadConsecutiveness.js | 6 ++++-- tests/baselines/reference/parserExportAssignment5.js | 1 + tests/baselines/reference/parserForInStatement3.js | 2 +- tests/baselines/reference/parserForInStatement6.js | 2 +- tests/baselines/reference/parserForInStatement7.js | 2 +- tests/baselines/reference/parserForOfStatement3.js | 2 +- tests/baselines/reference/parserForOfStatement6.js | 2 +- tests/baselines/reference/parserForOfStatement7.js | 2 +- .../reference/parserMemberAccessorDeclaration3.js | 2 +- .../reference/parserMemberAccessorDeclaration6.js | 2 +- .../reference/parserModifierOnStatementInBlock1.js | 2 +- tests/baselines/reference/reservedWords2.js | 1 + tests/baselines/reference/restParamModifier.js | 2 +- tests/baselines/reference/restParameterNotLast.js | 2 +- .../reference/restParameterWithoutAnnotationIsAnyArray.js | 4 ++-- .../baselines/reference/restParametersOfNonArrayTypes.js | 4 ++-- .../baselines/reference/restParametersOfNonArrayTypes2.js | 8 ++++---- .../reference/restParametersWithArrayTypeAnnotations.js | 8 ++++---- 30 files changed, 55 insertions(+), 44 deletions(-) diff --git a/tests/baselines/reference/constructorArgsErrors1.js b/tests/baselines/reference/constructorArgsErrors1.js index bb0725ab8b9..15c5e64952b 100644 --- a/tests/baselines/reference/constructorArgsErrors1.js +++ b/tests/baselines/reference/constructorArgsErrors1.js @@ -6,7 +6,7 @@ class foo { //// [constructorArgsErrors1.js] var foo = (function () { - function foo(a) { + function foo(static a) { } return foo; }()); diff --git a/tests/baselines/reference/constructorArgsErrors5.js b/tests/baselines/reference/constructorArgsErrors5.js index c481d6f323c..6ba68cb88b4 100644 --- a/tests/baselines/reference/constructorArgsErrors5.js +++ b/tests/baselines/reference/constructorArgsErrors5.js @@ -7,7 +7,7 @@ class foo { //// [constructorArgsErrors5.js] var foo = (function () { - function foo(a) { + function foo(export a) { } return foo; }()); diff --git a/tests/baselines/reference/destructuringParameterDeclaration6.js b/tests/baselines/reference/destructuringParameterDeclaration6.js index f34f2d695ce..ad86b2983b3 100644 --- a/tests/baselines/reference/destructuringParameterDeclaration6.js +++ b/tests/baselines/reference/destructuringParameterDeclaration6.js @@ -32,10 +32,17 @@ function a(_a) { function a1(_a) { var public = _a.public; } +function a4(_a) { } while (, ) for (, public; ; ) ; { } +function a5() { + var = []; + for (var _i = 0; _i < arguments.length; _i++) { + [_i - 0] = arguments[_i]; + } +} while () { } function a6() { var public = []; diff --git a/tests/baselines/reference/enumIdentifierLiterals.js b/tests/baselines/reference/enumIdentifierLiterals.js index 72a8a56570c..5f132b965f2 100644 --- a/tests/baselines/reference/enumIdentifierLiterals.js +++ b/tests/baselines/reference/enumIdentifierLiterals.js @@ -10,9 +10,9 @@ enum Nums { //// [enumIdentifierLiterals.js] var Nums; (function (Nums) { - Nums[Nums["1"] = 0] = "1"; - Nums[Nums["1.1"] = 1] = "1.1"; - Nums[Nums["1.2"] = 2] = "1.2"; + Nums[Nums[1] = 0] = 1; + Nums[Nums[1.1] = 1] = 1.1; + Nums[Nums[1.2] = 2] = 1.2; Nums[Nums["13e-1"] = 3] = "13e-1"; - Nums[Nums["61453"] = 4] = "61453"; + Nums[Nums[61453] = 4] = 61453; })(Nums || (Nums = {})); diff --git a/tests/baselines/reference/exportDeclarationInInternalModule.js b/tests/baselines/reference/exportDeclarationInInternalModule.js index ecd9d5adf4d..9f469ccac3c 100644 --- a/tests/baselines/reference/exportDeclarationInInternalModule.js +++ b/tests/baselines/reference/exportDeclarationInInternalModule.js @@ -53,7 +53,7 @@ var Bbb; return SomeType; }()); Bbb.SomeType = SomeType; - // this line causes the nullref + export * from Aaa; // this line causes the nullref })(Bbb || (Bbb = {})); var a; diff --git a/tests/baselines/reference/generatorTypeCheck56.js b/tests/baselines/reference/generatorTypeCheck56.js index c1b0f98f5e7..9d8d00e01e7 100644 --- a/tests/baselines/reference/generatorTypeCheck56.js +++ b/tests/baselines/reference/generatorTypeCheck56.js @@ -13,6 +13,5 @@ function* g() { *[yield 0]() { yield 0; } - } - ; + }; } diff --git a/tests/baselines/reference/importInsideModule.js b/tests/baselines/reference/importInsideModule.js index d4f12d0c1b6..32fe7f5ddb3 100644 --- a/tests/baselines/reference/importInsideModule.js +++ b/tests/baselines/reference/importInsideModule.js @@ -13,5 +13,6 @@ export module myModule { "use strict"; var myModule; (function (myModule) { + import foo = require("importInsideModule_file1"); var a = foo.x; })(myModule = exports.myModule || (exports.myModule = {})); diff --git a/tests/baselines/reference/invalidLetInForOfAndForIn_ES5.js b/tests/baselines/reference/invalidLetInForOfAndForIn_ES5.js index 729cb246a85..b9f4c126015 100644 --- a/tests/baselines/reference/invalidLetInForOfAndForIn_ES5.js +++ b/tests/baselines/reference/invalidLetInForOfAndForIn_ES5.js @@ -14,5 +14,5 @@ for (let in [1,2,3]) {} // This should be an error // More details: http://www.ecma-international.org/ecma-262/6.0/#sec-iteration-statements var let = 10; -for (let of = [1, 2, 3], { }; ; ) - for ( in [1, 2, 3]) { } +for (let of = [1, 2, 3], {}; ; ) + for (let in [1, 2, 3]) { } diff --git a/tests/baselines/reference/invalidLetInForOfAndForIn_ES6.js b/tests/baselines/reference/invalidLetInForOfAndForIn_ES6.js index 93258d6b225..be59a37d1a8 100644 --- a/tests/baselines/reference/invalidLetInForOfAndForIn_ES6.js +++ b/tests/baselines/reference/invalidLetInForOfAndForIn_ES6.js @@ -14,5 +14,5 @@ for (let in [1,2,3]) {} // This should be an error // More details: http://www.ecma-international.org/ecma-262/6.0/#sec-iteration-statements var let = 10; -for (let of = [1, 2, 3], { }; ; ) - for ( in [1, 2, 3]) { } +for (let of = [1, 2, 3], {}; ; ) + for (let in [1, 2, 3]) { } diff --git a/tests/baselines/reference/invalidModuleWithVarStatements.js b/tests/baselines/reference/invalidModuleWithVarStatements.js index caa6b24f00f..ce5fbd54ed1 100644 --- a/tests/baselines/reference/invalidModuleWithVarStatements.js +++ b/tests/baselines/reference/invalidModuleWithVarStatements.js @@ -39,11 +39,11 @@ var Y2; })(Y2 || (Y2 = {})); var Y4; (function (Y4) { - var x = 0; + static var x = 0; })(Y4 || (Y4 = {})); var YY; (function (YY) { - function fn(x) { } + static function fn(x) { } })(YY || (YY = {})); var YY2; (function (YY2) { diff --git a/tests/baselines/reference/multipleExports.js b/tests/baselines/reference/multipleExports.js index c70a5005aab..2e287aa241c 100644 --- a/tests/baselines/reference/multipleExports.js +++ b/tests/baselines/reference/multipleExports.js @@ -22,4 +22,5 @@ var x = 0; var M; (function (M) { M.v; + export { x }; })(M = exports.M || (exports.M = {})); diff --git a/tests/baselines/reference/objectTypesWithOptionalProperties2.js b/tests/baselines/reference/objectTypesWithOptionalProperties2.js index eabb1a153a6..1612e6785c7 100644 --- a/tests/baselines/reference/objectTypesWithOptionalProperties2.js +++ b/tests/baselines/reference/objectTypesWithOptionalProperties2.js @@ -32,16 +32,15 @@ var a; var C = (function () { function C() { } - C.prototype.x = ; + C.prototype.x = function () { }; return C; }()); var C2 = (function () { function C2() { } - C2.prototype.x = ; + C2.prototype.x = function () { }; return C2; }()); var b = { - x: function () { }, 1: // error - // error + x: function () { }, 1: // error }; diff --git a/tests/baselines/reference/overloadConsecutiveness.js b/tests/baselines/reference/overloadConsecutiveness.js index 68e478a30b5..6a245ea18fa 100644 --- a/tests/baselines/reference/overloadConsecutiveness.js +++ b/tests/baselines/reference/overloadConsecutiveness.js @@ -14,13 +14,15 @@ class C { //// [overloadConsecutiveness.js] // Making sure compiler won't break with declarations that are consecutive in the AST but not consecutive in the source. Syntax errors intentional. +function f1() { } +function f2() { } function f2() { } function f3() { } var C = (function () { function C() { } - C.prototype.m1 = ; - C.prototype.m2 = ; + C.prototype.m1 = function () { }; + C.prototype.m2 = function () { }; C.prototype.m2 = function () { }; C.prototype.m3 = function () { }; return C; diff --git a/tests/baselines/reference/parserExportAssignment5.js b/tests/baselines/reference/parserExportAssignment5.js index ac2a1202e5e..03b1d798d5d 100644 --- a/tests/baselines/reference/parserExportAssignment5.js +++ b/tests/baselines/reference/parserExportAssignment5.js @@ -6,4 +6,5 @@ module M { //// [parserExportAssignment5.js] var M; (function (M) { + export = A; })(M || (M = {})); diff --git a/tests/baselines/reference/parserForInStatement3.js b/tests/baselines/reference/parserForInStatement3.js index 4964c108ca0..076acbf68e8 100644 --- a/tests/baselines/reference/parserForInStatement3.js +++ b/tests/baselines/reference/parserForInStatement3.js @@ -3,5 +3,5 @@ for (var a, b in X) { } //// [parserForInStatement3.js] -for (var a in X) { +for (var a, b in X) { } diff --git a/tests/baselines/reference/parserForInStatement6.js b/tests/baselines/reference/parserForInStatement6.js index b80d13f3184..f35a550252e 100644 --- a/tests/baselines/reference/parserForInStatement6.js +++ b/tests/baselines/reference/parserForInStatement6.js @@ -3,5 +3,5 @@ for (var a = 1, b = 2 in X) { } //// [parserForInStatement6.js] -for (var a = 1 in X) { +for (var a = 1, b = 2 in X) { } diff --git a/tests/baselines/reference/parserForInStatement7.js b/tests/baselines/reference/parserForInStatement7.js index 5c056abedb6..ee8c948a9d2 100644 --- a/tests/baselines/reference/parserForInStatement7.js +++ b/tests/baselines/reference/parserForInStatement7.js @@ -3,5 +3,5 @@ for (var a: number = 1, b: string = "" in X) { } //// [parserForInStatement7.js] -for (var a = 1 in X) { +for (var a = 1, b = "" in X) { } diff --git a/tests/baselines/reference/parserForOfStatement3.js b/tests/baselines/reference/parserForOfStatement3.js index 206e8fe5af8..497eef03142 100644 --- a/tests/baselines/reference/parserForOfStatement3.js +++ b/tests/baselines/reference/parserForOfStatement3.js @@ -3,5 +3,5 @@ for (var a, b of X) { } //// [parserForOfStatement3.js] -for (var a of X) { +for (var a, b of X) { } diff --git a/tests/baselines/reference/parserForOfStatement6.js b/tests/baselines/reference/parserForOfStatement6.js index 37f3560a29c..0268b1dc676 100644 --- a/tests/baselines/reference/parserForOfStatement6.js +++ b/tests/baselines/reference/parserForOfStatement6.js @@ -3,5 +3,5 @@ for (var a = 1, b = 2 of X) { } //// [parserForOfStatement6.js] -for (var a = 1 of X) { +for (var a = 1, b = 2 of X) { } diff --git a/tests/baselines/reference/parserForOfStatement7.js b/tests/baselines/reference/parserForOfStatement7.js index 0b18d0358b4..a8867d6974c 100644 --- a/tests/baselines/reference/parserForOfStatement7.js +++ b/tests/baselines/reference/parserForOfStatement7.js @@ -3,5 +3,5 @@ for (var a: number = 1, b: string = "" of X) { } //// [parserForOfStatement7.js] -for (var a = 1 of X) { +for (var a = 1, b = "" of X) { } diff --git a/tests/baselines/reference/parserMemberAccessorDeclaration3.js b/tests/baselines/reference/parserMemberAccessorDeclaration3.js index acde7a1daed..c8c87111d92 100644 --- a/tests/baselines/reference/parserMemberAccessorDeclaration3.js +++ b/tests/baselines/reference/parserMemberAccessorDeclaration3.js @@ -7,7 +7,7 @@ class C { var C = (function () { function C() { } - Object.defineProperty(C.prototype, "0", { + Object.defineProperty(C.prototype, 0, { get: function () { }, enumerable: true, configurable: true diff --git a/tests/baselines/reference/parserMemberAccessorDeclaration6.js b/tests/baselines/reference/parserMemberAccessorDeclaration6.js index 3f9f6d9bea9..52977e1b7dc 100644 --- a/tests/baselines/reference/parserMemberAccessorDeclaration6.js +++ b/tests/baselines/reference/parserMemberAccessorDeclaration6.js @@ -7,7 +7,7 @@ class C { var C = (function () { function C() { } - Object.defineProperty(C.prototype, "0", { + Object.defineProperty(C.prototype, 0, { set: function (i) { }, enumerable: true, configurable: true diff --git a/tests/baselines/reference/parserModifierOnStatementInBlock1.js b/tests/baselines/reference/parserModifierOnStatementInBlock1.js index e7234a4d274..352ee0cc511 100644 --- a/tests/baselines/reference/parserModifierOnStatementInBlock1.js +++ b/tests/baselines/reference/parserModifierOnStatementInBlock1.js @@ -7,6 +7,6 @@ export function foo() { //// [parserModifierOnStatementInBlock1.js] "use strict"; function foo() { - exports.x = this; + export var x = this; } exports.foo = foo; diff --git a/tests/baselines/reference/reservedWords2.js b/tests/baselines/reference/reservedWords2.js index 69b071c9115..a5f8a680bcc 100644 --- a/tests/baselines/reference/reservedWords2.js +++ b/tests/baselines/reference/reservedWords2.js @@ -23,6 +23,7 @@ while (from) var ; typeof ; 10; +function () { } throw function () { }; module; void {}; diff --git a/tests/baselines/reference/restParamModifier.js b/tests/baselines/reference/restParamModifier.js index 3e0f7f7878a..ed7307fcdef 100644 --- a/tests/baselines/reference/restParamModifier.js +++ b/tests/baselines/reference/restParamModifier.js @@ -5,7 +5,7 @@ class C { //// [restParamModifier.js] var C = (function () { - function C(public, string) { + function C(string) { if (string === void 0) { string = []; } } return C; diff --git a/tests/baselines/reference/restParameterNotLast.js b/tests/baselines/reference/restParameterNotLast.js index 4ca416a47ec..d879bc12cd3 100644 --- a/tests/baselines/reference/restParameterNotLast.js +++ b/tests/baselines/reference/restParameterNotLast.js @@ -2,4 +2,4 @@ function f(...x, y) { } //// [restParameterNotLast.js] -function f(x, y) { } +function f(y) { } diff --git a/tests/baselines/reference/restParameterWithoutAnnotationIsAnyArray.js b/tests/baselines/reference/restParameterWithoutAnnotationIsAnyArray.js index 26774b6c2f2..c6b5fa2ae41 100644 --- a/tests/baselines/reference/restParameterWithoutAnnotationIsAnyArray.js +++ b/tests/baselines/reference/restParameterWithoutAnnotationIsAnyArray.js @@ -40,7 +40,7 @@ var f = function foo() { x[_i - 0] = arguments[_i]; } }; -var f2 = function (x) { +var f2 = function () { var y = []; for (var _i = 1; _i < arguments.length; _i++) { y[_i - 1] = arguments[_i]; @@ -65,7 +65,7 @@ var b = { x[_i - 0] = arguments[_i]; } }, - a: function foo(x) { + a: function foo() { var y = []; for (var _i = 1; _i < arguments.length; _i++) { y[_i - 1] = arguments[_i]; diff --git a/tests/baselines/reference/restParametersOfNonArrayTypes.js b/tests/baselines/reference/restParametersOfNonArrayTypes.js index d6235194b30..5400a8b43cc 100644 --- a/tests/baselines/reference/restParametersOfNonArrayTypes.js +++ b/tests/baselines/reference/restParametersOfNonArrayTypes.js @@ -39,7 +39,7 @@ var f = function foo() { x[_i - 0] = arguments[_i]; } }; -var f2 = function (x) { +var f2 = function () { var y = []; for (var _i = 1; _i < arguments.length; _i++) { y[_i - 1] = arguments[_i]; @@ -64,7 +64,7 @@ var b = { x[_i - 0] = arguments[_i]; } }, - a: function foo(x) { + a: function foo() { var y = []; for (var _i = 1; _i < arguments.length; _i++) { y[_i - 1] = arguments[_i]; diff --git a/tests/baselines/reference/restParametersOfNonArrayTypes2.js b/tests/baselines/reference/restParametersOfNonArrayTypes2.js index 598c8f2fe3d..d405c13db5a 100644 --- a/tests/baselines/reference/restParametersOfNonArrayTypes2.js +++ b/tests/baselines/reference/restParametersOfNonArrayTypes2.js @@ -71,7 +71,7 @@ var f = function foo() { x[_i - 0] = arguments[_i]; } }; -var f2 = function (x) { +var f2 = function () { var y = []; for (var _i = 1; _i < arguments.length; _i++) { y[_i - 1] = arguments[_i]; @@ -96,7 +96,7 @@ var b = { x[_i - 0] = arguments[_i]; } }, - a: function foo(x) { + a: function foo() { var y = []; for (var _i = 1; _i < arguments.length; _i++) { y[_i - 1] = arguments[_i]; @@ -121,7 +121,7 @@ var f3 = function foo() { x[_i - 0] = arguments[_i]; } }; -var f4 = function (x) { +var f4 = function () { var y = []; for (var _i = 1; _i < arguments.length; _i++) { y[_i - 1] = arguments[_i]; @@ -146,7 +146,7 @@ var b2 = { x[_i - 0] = arguments[_i]; } }, - a: function foo(x) { + a: function foo() { var y = []; for (var _i = 1; _i < arguments.length; _i++) { y[_i - 1] = arguments[_i]; diff --git a/tests/baselines/reference/restParametersWithArrayTypeAnnotations.js b/tests/baselines/reference/restParametersWithArrayTypeAnnotations.js index 11208f1fb83..3f1cf33e7ba 100644 --- a/tests/baselines/reference/restParametersWithArrayTypeAnnotations.js +++ b/tests/baselines/reference/restParametersWithArrayTypeAnnotations.js @@ -66,7 +66,7 @@ var f = function foo() { x[_i - 0] = arguments[_i]; } }; -var f2 = function (x) { +var f2 = function () { var y = []; for (var _i = 1; _i < arguments.length; _i++) { y[_i - 1] = arguments[_i]; @@ -91,7 +91,7 @@ var b = { x[_i - 0] = arguments[_i]; } }, - a: function foo(x) { + a: function foo() { var y = []; for (var _i = 1; _i < arguments.length; _i++) { y[_i - 1] = arguments[_i]; @@ -116,7 +116,7 @@ var f3 = function foo() { x[_i - 0] = arguments[_i]; } }; -var f4 = function (x) { +var f4 = function () { var y = []; for (var _i = 1; _i < arguments.length; _i++) { y[_i - 1] = arguments[_i]; @@ -141,7 +141,7 @@ var b2 = { x[_i - 0] = arguments[_i]; } }, - a: function foo(x) { + a: function foo() { var y = []; for (var _i = 1; _i < arguments.length; _i++) { y[_i - 1] = arguments[_i]; From 05dc168e251a8a24ca74f79816d38b27eb2aaf24 Mon Sep 17 00:00:00 2001 From: Mohamed Hegazy Date: Tue, 12 Apr 2016 16:26:48 -0700 Subject: [PATCH 33/58] Accept baseline: Static properties after export --- .../reference/amdImportNotAsPrimaryExpression.js | 2 +- .../reference/commonJSImportAsPrimaryExpression.js | 2 +- .../reference/commonJSImportNotAsPrimaryExpression.js | 2 +- .../reference/decoratorMetadataOnInferredType.js | 8 ++++---- .../reference/decoratorMetadataWithConstructorType.js | 8 ++++---- tests/baselines/reference/systemModuleTargetES6.js | 2 +- 6 files changed, 12 insertions(+), 12 deletions(-) diff --git a/tests/baselines/reference/amdImportNotAsPrimaryExpression.js b/tests/baselines/reference/amdImportNotAsPrimaryExpression.js index 0739792fddd..b8e9f5346b0 100644 --- a/tests/baselines/reference/amdImportNotAsPrimaryExpression.js +++ b/tests/baselines/reference/amdImportNotAsPrimaryExpression.js @@ -40,8 +40,8 @@ define(["require", "exports"], function (require, exports) { } return C1; }()); - C1.s1 = true; exports.C1 = C1; + C1.s1 = true; (function (E1) { E1[E1["A"] = 0] = "A"; E1[E1["B"] = 1] = "B"; diff --git a/tests/baselines/reference/commonJSImportAsPrimaryExpression.js b/tests/baselines/reference/commonJSImportAsPrimaryExpression.js index b8cf42ea762..d22b5b2855b 100644 --- a/tests/baselines/reference/commonJSImportAsPrimaryExpression.js +++ b/tests/baselines/reference/commonJSImportAsPrimaryExpression.js @@ -21,8 +21,8 @@ var C1 = (function () { } return C1; }()); -C1.s1 = true; exports.C1 = C1; +C1.s1 = true; //// [foo_1.js] "use strict"; var foo = require("./foo_0"); diff --git a/tests/baselines/reference/commonJSImportNotAsPrimaryExpression.js b/tests/baselines/reference/commonJSImportNotAsPrimaryExpression.js index 34d5c343b3c..e7496f3445f 100644 --- a/tests/baselines/reference/commonJSImportNotAsPrimaryExpression.js +++ b/tests/baselines/reference/commonJSImportNotAsPrimaryExpression.js @@ -39,8 +39,8 @@ var C1 = (function () { } return C1; }()); -C1.s1 = true; exports.C1 = C1; +C1.s1 = true; (function (E1) { E1[E1["A"] = 0] = "A"; E1[E1["B"] = 1] = "B"; diff --git a/tests/baselines/reference/decoratorMetadataOnInferredType.js b/tests/baselines/reference/decoratorMetadataOnInferredType.js index 47b6c45e806..0c63bcf49da 100644 --- a/tests/baselines/reference/decoratorMetadataOnInferredType.js +++ b/tests/baselines/reference/decoratorMetadataOnInferredType.js @@ -33,8 +33,8 @@ var B = (function () { } return B; }()); -__decorate([ - decorator, - __metadata('design:type', Object) -], B.prototype, "x", void 0); exports.B = B; +__decorate([ + decorator, + __metadata("design:type", Object) +], B.prototype, "x", void 0); diff --git a/tests/baselines/reference/decoratorMetadataWithConstructorType.js b/tests/baselines/reference/decoratorMetadataWithConstructorType.js index 0559e62754c..49b72e39a09 100644 --- a/tests/baselines/reference/decoratorMetadataWithConstructorType.js +++ b/tests/baselines/reference/decoratorMetadataWithConstructorType.js @@ -33,8 +33,8 @@ var B = (function () { } return B; }()); -__decorate([ - decorator, - __metadata('design:type', A) -], B.prototype, "x", void 0); exports.B = B; +__decorate([ + decorator, + __metadata("design:type", A) +], B.prototype, "x", void 0); diff --git a/tests/baselines/reference/systemModuleTargetES6.js b/tests/baselines/reference/systemModuleTargetES6.js index 3380c53a970..a049ea78395 100644 --- a/tests/baselines/reference/systemModuleTargetES6.js +++ b/tests/baselines/reference/systemModuleTargetES6.js @@ -35,8 +35,8 @@ System.register([], function (exports_1, context_1) { MyClass2 = class MyClass2 { static getInstance() { return MyClass2.value; } }; - MyClass2.value = 42; exports_1("MyClass2", MyClass2); + MyClass2.value = 42; } }; }); From b3878a8ec29380029a608c56f1eae851c9f5f2d6 Mon Sep 17 00:00:00 2001 From: Mohamed Hegazy Date: Tue, 12 Apr 2016 16:27:14 -0700 Subject: [PATCH 34/58] Accept baselines: using dots consistenlly for numeric literals --- .../reference/numericLiteralsWithTrailingDecimalPoints01.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tests/baselines/reference/numericLiteralsWithTrailingDecimalPoints01.js b/tests/baselines/reference/numericLiteralsWithTrailingDecimalPoints01.js index 0b1ce1f0736..54a0328c27c 100644 --- a/tests/baselines/reference/numericLiteralsWithTrailingDecimalPoints01.js +++ b/tests/baselines/reference/numericLiteralsWithTrailingDecimalPoints01.js @@ -28,9 +28,9 @@ toString(); var i = 1; var test1 = i.toString(); var test2 = 2., toString = (); -var test3 = 3 .toString(); -var test4 = 3 .toString(); -var test5 = 3 .toString(); +var test3 = 3..toString(); +var test4 = 3..toString(); +var test5 = 3..toString(); var test6 = 3.['toString'](); var test7 = 3 .toString(); From 6a39c30bbc9e0c3fc8be1bfb21d7656a23e5d36d Mon Sep 17 00:00:00 2001 From: Mohamed Hegazy Date: Tue, 12 Apr 2016 16:28:51 -0700 Subject: [PATCH 35/58] Accept baselines: output formatting changes --- .../reference/capturedLetConstInLoop1.js | 44 +++--- .../reference/capturedLetConstInLoop6.js | 104 ++++++++----- .../reference/capturedLetConstInLoop7.js | 144 ++++++++++-------- tests/baselines/reference/commentsFunction.js | 2 +- .../reference/emitRestParametersMethodES6.js | 6 +- .../reference/exportStarForValues10.js | 32 ++-- .../reference/exportStarForValues6.js | 16 +- .../reference/exportStarForValuesInSystem.js | 16 +- .../reference/generatorTypeCheck55.js | 3 +- .../isolatedModulesPlainFile-System.js | 8 +- .../baselines/reference/localClassesInLoop.js | 2 +- .../reference/modulePrologueSystem.js | 8 +- 12 files changed, 212 insertions(+), 173 deletions(-) diff --git a/tests/baselines/reference/capturedLetConstInLoop1.js b/tests/baselines/reference/capturedLetConstInLoop1.js index fe76bdd5c91..e526092d082 100644 --- a/tests/baselines/reference/capturedLetConstInLoop1.js +++ b/tests/baselines/reference/capturedLetConstInLoop1.js @@ -114,15 +114,15 @@ for (const y = 0; y < 1;) { } //// [capturedLetConstInLoop1.js] -//==== let -var _loop_1 = function(x) { +var _loop_1 = function (x) { (function () { return x; }); (function () { return x; }); }; +//==== let for (var x in {}) { _loop_1(x); } -var _loop_2 = function(x) { +var _loop_2 = function (x) { (function () { return x; }); (function () { return x; }); }; @@ -130,14 +130,14 @@ for (var _i = 0, _a = []; _i < _a.length; _i++) { var x = _a[_i]; _loop_2(x); } -var _loop_3 = function(x) { +var _loop_3 = function (x) { (function () { return x; }); (function () { return x; }); }; for (var x = 0; x < 1; ++x) { _loop_3(x); } -var _loop_4 = function() { +var _loop_4 = function () { var x; (function () { return x; }); (function () { return x; }); @@ -145,7 +145,7 @@ var _loop_4 = function() { while (1 === 1) { _loop_4(); } -var _loop_5 = function() { +var _loop_5 = function () { var x; (function () { return x; }); (function () { return x; }); @@ -153,7 +153,7 @@ var _loop_5 = function() { do { _loop_5(); } while (1 === 1); -var _loop_6 = function(y) { +var _loop_6 = function (y) { var x = 1; (function () { return x; }); (function () { return x; }); @@ -161,14 +161,14 @@ var _loop_6 = function(y) { for (var y = 0; y < 1; ++y) { _loop_6(y); } -var _loop_7 = function(x, y) { +var _loop_7 = function (x, y) { (function () { return x + y; }); (function () { return x + y; }); }; for (var x = 0, y = 1; x < 1; ++x) { _loop_7(x, y); } -var _loop_8 = function() { +var _loop_8 = function () { var x, y; (function () { return x + y; }); (function () { return x + y; }); @@ -176,7 +176,7 @@ var _loop_8 = function() { while (1 === 1) { _loop_8(); } -var _loop_9 = function() { +var _loop_9 = function () { var x, y; (function () { return x + y; }); (function () { return x + y; }); @@ -184,7 +184,7 @@ var _loop_9 = function() { do { _loop_9(); } while (1 === 1); -var _loop_10 = function(y) { +var _loop_10 = function (y) { var x = 1; (function () { return x + y; }); (function () { return x + y; }); @@ -192,15 +192,15 @@ var _loop_10 = function(y) { for (var y = 0; y < 1; ++y) { _loop_10(y); } -//=========const -var _loop_11 = function(x) { +var _loop_11 = function (x) { (function () { return x; }); (function () { return x; }); }; +//=========const for (var x in {}) { _loop_11(x); } -var _loop_12 = function(x) { +var _loop_12 = function (x) { (function () { return x; }); (function () { return x; }); }; @@ -208,14 +208,14 @@ for (var _b = 0, _c = []; _b < _c.length; _b++) { var x = _c[_b]; _loop_12(x); } -var _loop_13 = function(x) { +var _loop_13 = function (x) { (function () { return x; }); (function () { return x; }); }; for (var x = 0; x < 1;) { _loop_13(x); } -var _loop_14 = function() { +var _loop_14 = function () { var x = 1; (function () { return x; }); (function () { return x; }); @@ -223,7 +223,7 @@ var _loop_14 = function() { while (1 === 1) { _loop_14(); } -var _loop_15 = function() { +var _loop_15 = function () { var x = 1; (function () { return x; }); (function () { return x; }); @@ -231,7 +231,7 @@ var _loop_15 = function() { do { _loop_15(); } while (1 === 1); -var _loop_16 = function(y) { +var _loop_16 = function (y) { var x = 1; (function () { return x; }); (function () { return x; }); @@ -239,14 +239,14 @@ var _loop_16 = function(y) { for (var y = 0; y < 1;) { _loop_16(y); } -var _loop_17 = function(x, y) { +var _loop_17 = function (x, y) { (function () { return x + y; }); (function () { return x + y; }); }; for (var x = 0, y = 1; x < 1;) { _loop_17(x, y); } -var _loop_18 = function() { +var _loop_18 = function () { var x = 1, y = 1; (function () { return x + y; }); (function () { return x + y; }); @@ -254,7 +254,7 @@ var _loop_18 = function() { while (1 === 1) { _loop_18(); } -var _loop_19 = function() { +var _loop_19 = function () { var x = 1, y = 1; (function () { return x + y; }); (function () { return x + y; }); @@ -262,7 +262,7 @@ var _loop_19 = function() { do { _loop_19(); } while (1 === 1); -var _loop_20 = function(y) { +var _loop_20 = function (y) { var x = 1; (function () { return x + y; }); (function () { return x + y; }); diff --git a/tests/baselines/reference/capturedLetConstInLoop6.js b/tests/baselines/reference/capturedLetConstInLoop6.js index 6a2b4c9a335..cf813da44e1 100644 --- a/tests/baselines/reference/capturedLetConstInLoop6.js +++ b/tests/baselines/reference/capturedLetConstInLoop6.js @@ -239,8 +239,7 @@ for (const y = 0; y < 1;) { //// [capturedLetConstInLoop6.js] -// ====let -var _loop_1 = function(x) { +var _loop_1 = function (x) { (function () { return x; }); (function () { return x; }); if (x == 1) { @@ -250,12 +249,14 @@ var _loop_1 = function(x) { return "continue"; } }; +// ====let for (var _i = 0, _a = []; _i < _a.length; _i++) { var x = _a[_i]; var state_1 = _loop_1(x); - if (state_1 === "break") break; + if (state_1 === "break") + break; } -var _loop_2 = function(x) { +var _loop_2 = function (x) { (function () { return x; }); (function () { return x; }); if (x == "1") { @@ -267,9 +268,10 @@ var _loop_2 = function(x) { }; for (var x in []) { var state_2 = _loop_2(x); - if (state_2 === "break") break; + if (state_2 === "break") + break; } -var _loop_3 = function(x) { +var _loop_3 = function (x) { (function () { return x; }); (function () { return x; }); if (x == 1) { @@ -281,9 +283,10 @@ var _loop_3 = function(x) { }; for (var x = 0; x < 1; ++x) { var state_3 = _loop_3(x); - if (state_3 === "break") break; + if (state_3 === "break") + break; } -var _loop_4 = function() { +var _loop_4 = function () { var x; (function () { return x; }); (function () { return x; }); @@ -296,9 +299,10 @@ var _loop_4 = function() { }; while (1 === 1) { var state_4 = _loop_4(); - if (state_4 === "break") break; + if (state_4 === "break") + break; } -var _loop_5 = function() { +var _loop_5 = function () { var x; (function () { return x; }); (function () { return x; }); @@ -311,9 +315,10 @@ var _loop_5 = function() { }; do { var state_5 = _loop_5(); - if (state_5 === "break") break; + if (state_5 === "break") + break; } while (1 === 1); -var _loop_6 = function(y) { +var _loop_6 = function (y) { var x = 1; (function () { return x; }); (function () { return x; }); @@ -326,9 +331,10 @@ var _loop_6 = function(y) { }; for (var y = 0; y < 1; ++y) { var state_6 = _loop_6(y); - if (state_6 === "break") break; + if (state_6 === "break") + break; } -var _loop_7 = function(x, y) { +var _loop_7 = function (x, y) { (function () { return x + y; }); (function () { return x + y; }); if (x == 1) { @@ -340,9 +346,10 @@ var _loop_7 = function(x, y) { }; for (var x = 0, y = 1; x < 1; ++x) { var state_7 = _loop_7(x, y); - if (state_7 === "break") break; + if (state_7 === "break") + break; } -var _loop_8 = function() { +var _loop_8 = function () { var x, y; (function () { return x + y; }); (function () { return x + y; }); @@ -355,9 +362,10 @@ var _loop_8 = function() { }; while (1 === 1) { var state_8 = _loop_8(); - if (state_8 === "break") break; + if (state_8 === "break") + break; } -var _loop_9 = function() { +var _loop_9 = function () { var x, y; (function () { return x + y; }); (function () { return x + y; }); @@ -370,9 +378,10 @@ var _loop_9 = function() { }; do { var state_9 = _loop_9(); - if (state_9 === "break") break; + if (state_9 === "break") + break; } while (1 === 1); -var _loop_10 = function(y) { +var _loop_10 = function (y) { var x = 1; (function () { return x + y; }); (function () { return x + y; }); @@ -385,10 +394,10 @@ var _loop_10 = function(y) { }; for (var y = 0; y < 1; ++y) { var state_10 = _loop_10(y); - if (state_10 === "break") break; + if (state_10 === "break") + break; } -// ====const -var _loop_11 = function(x) { +var _loop_11 = function (x) { (function () { return x; }); (function () { return x; }); if (x == 1) { @@ -398,12 +407,14 @@ var _loop_11 = function(x) { return "continue"; } }; +// ====const for (var _b = 0, _c = []; _b < _c.length; _b++) { var x = _c[_b]; var state_11 = _loop_11(x); - if (state_11 === "break") break; + if (state_11 === "break") + break; } -var _loop_12 = function(x) { +var _loop_12 = function (x) { (function () { return x; }); (function () { return x; }); if (x == "1") { @@ -415,9 +426,10 @@ var _loop_12 = function(x) { }; for (var x in []) { var state_12 = _loop_12(x); - if (state_12 === "break") break; + if (state_12 === "break") + break; } -var _loop_13 = function(x) { +var _loop_13 = function (x) { (function () { return x; }); (function () { return x; }); if (x == 1) { @@ -429,9 +441,10 @@ var _loop_13 = function(x) { }; for (var x = 0; x < 1;) { var state_13 = _loop_13(x); - if (state_13 === "break") break; + if (state_13 === "break") + break; } -var _loop_14 = function() { +var _loop_14 = function () { var x = 1; (function () { return x; }); (function () { return x; }); @@ -444,9 +457,10 @@ var _loop_14 = function() { }; while (1 === 1) { var state_14 = _loop_14(); - if (state_14 === "break") break; + if (state_14 === "break") + break; } -var _loop_15 = function() { +var _loop_15 = function () { var x = 1; (function () { return x; }); (function () { return x; }); @@ -459,9 +473,10 @@ var _loop_15 = function() { }; do { var state_15 = _loop_15(); - if (state_15 === "break") break; + if (state_15 === "break") + break; } while (1 === 1); -var _loop_16 = function(y) { +var _loop_16 = function (y) { var x = 1; (function () { return x; }); (function () { return x; }); @@ -474,9 +489,10 @@ var _loop_16 = function(y) { }; for (var y = 0; y < 1;) { var state_16 = _loop_16(y); - if (state_16 === "break") break; + if (state_16 === "break") + break; } -var _loop_17 = function(x, y) { +var _loop_17 = function (x, y) { (function () { return x + y; }); (function () { return x + y; }); if (x == 1) { @@ -488,9 +504,10 @@ var _loop_17 = function(x, y) { }; for (var x = 0, y = 1; x < 1;) { var state_17 = _loop_17(x, y); - if (state_17 === "break") break; + if (state_17 === "break") + break; } -var _loop_18 = function() { +var _loop_18 = function () { var x = 1, y = 1; (function () { return x + y; }); (function () { return x + y; }); @@ -503,9 +520,10 @@ var _loop_18 = function() { }; while (1 === 1) { var state_18 = _loop_18(); - if (state_18 === "break") break; + if (state_18 === "break") + break; } -var _loop_19 = function() { +var _loop_19 = function () { var x = 1, y = 1; (function () { return x + y; }); (function () { return x + y; }); @@ -518,9 +536,10 @@ var _loop_19 = function() { }; do { var state_19 = _loop_19(); - if (state_19 === "break") break; + if (state_19 === "break") + break; } while (1 === 1); -var _loop_20 = function(y) { +var _loop_20 = function (y) { var x = 1; (function () { return x + y; }); (function () { return x + y; }); @@ -533,5 +552,6 @@ var _loop_20 = function(y) { }; for (var y = 0; y < 1;) { var state_20 = _loop_20(y); - if (state_20 === "break") break; + if (state_20 === "break") + break; } diff --git a/tests/baselines/reference/capturedLetConstInLoop7.js b/tests/baselines/reference/capturedLetConstInLoop7.js index 56b84e7802d..c4bd9b2d2b9 100644 --- a/tests/baselines/reference/capturedLetConstInLoop7.js +++ b/tests/baselines/reference/capturedLetConstInLoop7.js @@ -376,8 +376,7 @@ for (const y = 0; y < 1;) { } //// [capturedLetConstInLoop7.js] -//===let -var _loop_1 = function(x) { +var _loop_1 = function (x) { (function () { return x; }); (function () { return x; }); if (x == 1) { @@ -393,16 +392,18 @@ var _loop_1 = function(x) { return "continue-l0"; } }; +//===let l0: for (var _i = 0, _a = []; _i < _a.length; _i++) { var x = _a[_i]; var state_1 = _loop_1(x); - if (state_1 === "break") break; - switch(state_1) { + if (state_1 === "break") + break; + switch (state_1) { case "break-l0": break l0; case "continue-l0": continue l0; } } -var _loop_2 = function(x) { +var _loop_2 = function (x) { (function () { return x; }); (function () { return x; }); if (x == "1") { @@ -420,13 +421,14 @@ var _loop_2 = function(x) { }; l00: for (var x in []) { var state_2 = _loop_2(x); - if (state_2 === "break") break; - switch(state_2) { + if (state_2 === "break") + break; + switch (state_2) { case "break-l00": break l00; case "continue-l00": continue l00; } } -var _loop_3 = function(x) { +var _loop_3 = function (x) { (function () { return x; }); (function () { return x; }); if (x == 1) { @@ -444,13 +446,14 @@ var _loop_3 = function(x) { }; l1: for (var x = 0; x < 1; ++x) { var state_3 = _loop_3(x); - if (state_3 === "break") break; - switch(state_3) { + if (state_3 === "break") + break; + switch (state_3) { case "break-l1": break l1; case "continue-l1": continue l1; } } -var _loop_4 = function() { +var _loop_4 = function () { var x; (function () { return x; }); (function () { return x; }); @@ -469,13 +472,14 @@ var _loop_4 = function() { }; l2: while (1 === 1) { var state_4 = _loop_4(); - if (state_4 === "break") break; - switch(state_4) { + if (state_4 === "break") + break; + switch (state_4) { case "break-l2": break l2; case "continue-l2": continue l2; } } -var _loop_5 = function() { +var _loop_5 = function () { var x; (function () { return x; }); (function () { return x; }); @@ -494,13 +498,14 @@ var _loop_5 = function() { }; l3: do { var state_5 = _loop_5(); - if (state_5 === "break") break; - switch(state_5) { + if (state_5 === "break") + break; + switch (state_5) { case "break-l3": break l3; case "continue-l3": continue l3; } } while (1 === 1); -var _loop_6 = function(y) { +var _loop_6 = function (y) { var x = 1; (function () { return x; }); (function () { return x; }); @@ -519,13 +524,14 @@ var _loop_6 = function(y) { }; l4: for (var y = 0; y < 1; ++y) { var state_6 = _loop_6(y); - if (state_6 === "break") break; - switch(state_6) { + if (state_6 === "break") + break; + switch (state_6) { case "break-l4": break l4; case "continue-l4": continue l4; } } -var _loop_7 = function(x, y) { +var _loop_7 = function (x, y) { (function () { return x + y; }); (function () { return x + y; }); if (x == 1) { @@ -543,13 +549,14 @@ var _loop_7 = function(x, y) { }; l5: for (var x = 0, y = 1; x < 1; ++x) { var state_7 = _loop_7(x, y); - if (state_7 === "break") break; - switch(state_7) { + if (state_7 === "break") + break; + switch (state_7) { case "break-l5": break l5; case "continue-l5": continue l5; } } -var _loop_8 = function() { +var _loop_8 = function () { var x, y; (function () { return x + y; }); (function () { return x + y; }); @@ -568,13 +575,14 @@ var _loop_8 = function() { }; l6: while (1 === 1) { var state_8 = _loop_8(); - if (state_8 === "break") break; - switch(state_8) { + if (state_8 === "break") + break; + switch (state_8) { case "break-l6": break l6; case "continue-l6": continue l6; } } -var _loop_9 = function() { +var _loop_9 = function () { var x, y; (function () { return x + y; }); (function () { return x + y; }); @@ -593,13 +601,14 @@ var _loop_9 = function() { }; l7: do { var state_9 = _loop_9(); - if (state_9 === "break") break; - switch(state_9) { + if (state_9 === "break") + break; + switch (state_9) { case "break-l7": break l7; case "continue-l7": continue l7; } } while (1 === 1); -var _loop_10 = function(y) { +var _loop_10 = function (y) { var x = 1; (function () { return x + y; }); (function () { return x + y; }); @@ -618,14 +627,14 @@ var _loop_10 = function(y) { }; l8: for (var y = 0; y < 1; ++y) { var state_10 = _loop_10(y); - if (state_10 === "break") break; - switch(state_10) { + if (state_10 === "break") + break; + switch (state_10) { case "break-l8": break l8; case "continue-l8": continue l8; } } -//===const -var _loop_11 = function(x) { +var _loop_11 = function (x) { (function () { return x; }); (function () { return x; }); if (x == 1) { @@ -641,16 +650,18 @@ var _loop_11 = function(x) { return "continue-l0_c"; } }; +//===const l0_c: for (var _b = 0, _c = []; _b < _c.length; _b++) { var x = _c[_b]; var state_11 = _loop_11(x); - if (state_11 === "break") break; - switch(state_11) { + if (state_11 === "break") + break; + switch (state_11) { case "break-l0_c": break l0_c; case "continue-l0_c": continue l0_c; } } -var _loop_12 = function(x) { +var _loop_12 = function (x) { (function () { return x; }); (function () { return x; }); if (x == "1") { @@ -668,13 +679,14 @@ var _loop_12 = function(x) { }; l00_c: for (var x in []) { var state_12 = _loop_12(x); - if (state_12 === "break") break; - switch(state_12) { + if (state_12 === "break") + break; + switch (state_12) { case "break-l00_c": break l00_c; case "continue-l00_c": continue l00_c; } } -var _loop_13 = function(x) { +var _loop_13 = function (x) { (function () { return x; }); (function () { return x; }); if (x == 1) { @@ -692,13 +704,14 @@ var _loop_13 = function(x) { }; l1_c: for (var x = 0; x < 1;) { var state_13 = _loop_13(x); - if (state_13 === "break") break; - switch(state_13) { + if (state_13 === "break") + break; + switch (state_13) { case "break-l1_c": break l1_c; case "continue-l1_c": continue l1_c; } } -var _loop_14 = function() { +var _loop_14 = function () { var x = 1; (function () { return x; }); (function () { return x; }); @@ -717,13 +730,14 @@ var _loop_14 = function() { }; l2_c: while (1 === 1) { var state_14 = _loop_14(); - if (state_14 === "break") break; - switch(state_14) { + if (state_14 === "break") + break; + switch (state_14) { case "break-l2_c": break l2_c; case "continue-l2_c": continue l2_c; } } -var _loop_15 = function() { +var _loop_15 = function () { var x = 1; (function () { return x; }); (function () { return x; }); @@ -742,13 +756,14 @@ var _loop_15 = function() { }; l3_c: do { var state_15 = _loop_15(); - if (state_15 === "break") break; - switch(state_15) { + if (state_15 === "break") + break; + switch (state_15) { case "break-l3_c": break l3_c; case "continue-l3_c": continue l3_c; } } while (1 === 1); -var _loop_16 = function(y) { +var _loop_16 = function (y) { var x = 1; (function () { return x; }); (function () { return x; }); @@ -767,13 +782,14 @@ var _loop_16 = function(y) { }; l4_c: for (var y = 0; y < 1;) { var state_16 = _loop_16(y); - if (state_16 === "break") break; - switch(state_16) { + if (state_16 === "break") + break; + switch (state_16) { case "break-l4_c": break l4_c; case "continue-l4_c": continue l4_c; } } -var _loop_17 = function(x, y) { +var _loop_17 = function (x, y) { (function () { return x + y; }); (function () { return x + y; }); if (x == 1) { @@ -791,13 +807,14 @@ var _loop_17 = function(x, y) { }; l5_c: for (var x = 0, y = 1; x < 1;) { var state_17 = _loop_17(x, y); - if (state_17 === "break") break; - switch(state_17) { + if (state_17 === "break") + break; + switch (state_17) { case "break-l5_c": break l5_c; case "continue-l5_c": continue l5_c; } } -var _loop_18 = function() { +var _loop_18 = function () { var x = 1, y = 1; (function () { return x + y; }); (function () { return x + y; }); @@ -816,13 +833,14 @@ var _loop_18 = function() { }; l6_c: while (1 === 1) { var state_18 = _loop_18(); - if (state_18 === "break") break; - switch(state_18) { + if (state_18 === "break") + break; + switch (state_18) { case "break-l6_c": break l6_c; case "continue-l6_c": continue l6_c; } } -var _loop_19 = function() { +var _loop_19 = function () { var x = 1, y = 1; (function () { return x + y; }); (function () { return x + y; }); @@ -841,13 +859,14 @@ var _loop_19 = function() { }; l7_c: do { var state_19 = _loop_19(); - if (state_19 === "break") break; - switch(state_19) { + if (state_19 === "break") + break; + switch (state_19) { case "break-l7_c": break l7_c; case "continue-l7_c": continue l7_c; } } while (1 === 1); -var _loop_20 = function(y) { +var _loop_20 = function (y) { var x = 1; (function () { return x + y; }); (function () { return x + y; }); @@ -866,8 +885,9 @@ var _loop_20 = function(y) { }; l8_c: for (var y = 0; y < 1;) { var state_20 = _loop_20(y); - if (state_20 === "break") break; - switch(state_20) { + if (state_20 === "break") + break; + switch (state_20) { case "break-l8_c": break l8_c; case "continue-l8_c": continue l8_c; } diff --git a/tests/baselines/reference/commentsFunction.js b/tests/baselines/reference/commentsFunction.js index 0ffb2714108..d9e9ccd15ea 100644 --- a/tests/baselines/reference/commentsFunction.js +++ b/tests/baselines/reference/commentsFunction.js @@ -84,7 +84,7 @@ function blah(a /* multiline trailing comment function blah2(a /* single line multiple trailing comments */ /* second */) { } function blah3(a // trailing commen single line - ) { +) { } lambdaFoo = function (a, b) { return a * b; }; // This is trailing comment /*leading comment*/ (function () { return 0; }); // Needs to be wrapped in parens to be a valid expression (not declaration) diff --git a/tests/baselines/reference/emitRestParametersMethodES6.js b/tests/baselines/reference/emitRestParametersMethodES6.js index 930cd109b6e..b7c98ac9d19 100644 --- a/tests/baselines/reference/emitRestParametersMethodES6.js +++ b/tests/baselines/reference/emitRestParametersMethodES6.js @@ -16,14 +16,12 @@ class D { //// [emitRestParametersMethodES6.js] class C { - constructor(name, ...rest) { - } + constructor(name, ...rest) { } bar(...rest) { } foo(x, ...rest) { } } class D { - constructor(...rest) { - } + constructor(...rest) { } bar(...rest) { } foo(x, ...rest) { } } diff --git a/tests/baselines/reference/exportStarForValues10.js b/tests/baselines/reference/exportStarForValues10.js index d37ca3304f3..3da80002780 100644 --- a/tests/baselines/reference/exportStarForValues10.js +++ b/tests/baselines/reference/exportStarForValues10.js @@ -13,46 +13,48 @@ export * from "file1"; var x = 1; //// [file0.js] -System.register([], function(exports_1, context_1) { +System.register([], function (exports_1, context_1) { "use strict"; var __moduleName = context_1 && context_1.id; var v; return { - setters:[], - execute: function() { + setters: [], + execute: function () { exports_1("v", v = 1); } - } + }; }); //// [file1.js] -System.register([], function(exports_1, context_1) { +System.register([], function (exports_1, context_1) { "use strict"; var __moduleName = context_1 && context_1.id; return { - setters:[], - execute: function() { + setters: [], + execute: function () { } - } + }; }); //// [file2.js] -System.register(["file0"], function(exports_1, context_1) { +System.register(["file0"], function (exports_1, context_1) { "use strict"; var __moduleName = context_1 && context_1.id; var x; function exportStar_1(m) { var exports = {}; - for(var n in m) { - if (n !== "default") exports[n] = m[n]; + for (var n in m) { + if (n !== "default") + exports[n] = m[n]; } exports_1(exports); } return { - setters:[ + setters: [ function (file0_1_1) { exportStar_1(file0_1_1); - }], - execute: function() { + } + ], + execute: function () { x = 1; } - } + }; }); diff --git a/tests/baselines/reference/exportStarForValues6.js b/tests/baselines/reference/exportStarForValues6.js index 8c31f6b4d16..dd17fbcddb2 100644 --- a/tests/baselines/reference/exportStarForValues6.js +++ b/tests/baselines/reference/exportStarForValues6.js @@ -9,24 +9,24 @@ export * from "file1" export var x = 1; //// [file1.js] -System.register([], function(exports_1, context_1) { +System.register([], function (exports_1, context_1) { "use strict"; var __moduleName = context_1 && context_1.id; return { - setters:[], - execute: function() { + setters: [], + execute: function () { } - } + }; }); //// [file2.js] -System.register([], function(exports_1, context_1) { +System.register([], function (exports_1, context_1) { "use strict"; var __moduleName = context_1 && context_1.id; var x; return { - setters:[], - execute: function() { + setters: [], + execute: function () { exports_1("x", x = 1); } - } + }; }); diff --git a/tests/baselines/reference/exportStarForValuesInSystem.js b/tests/baselines/reference/exportStarForValuesInSystem.js index 49c6877377a..4fbd3ca0066 100644 --- a/tests/baselines/reference/exportStarForValuesInSystem.js +++ b/tests/baselines/reference/exportStarForValuesInSystem.js @@ -9,24 +9,24 @@ export * from "file1" var x = 1; //// [file1.js] -System.register([], function(exports_1, context_1) { +System.register([], function (exports_1, context_1) { "use strict"; var __moduleName = context_1 && context_1.id; return { - setters:[], - execute: function() { + setters: [], + execute: function () { } - } + }; }); //// [file2.js] -System.register([], function(exports_1, context_1) { +System.register([], function (exports_1, context_1) { "use strict"; var __moduleName = context_1 && context_1.id; var x; return { - setters:[], - execute: function() { + setters: [], + execute: function () { x = 1; } - } + }; }); diff --git a/tests/baselines/reference/generatorTypeCheck55.js b/tests/baselines/reference/generatorTypeCheck55.js index dd7cd33af29..4943791d354 100644 --- a/tests/baselines/reference/generatorTypeCheck55.js +++ b/tests/baselines/reference/generatorTypeCheck55.js @@ -6,6 +6,5 @@ function* g() { //// [generatorTypeCheck55.js] function* g() { var x = class C extends (yield) { - } - ; + }; } diff --git a/tests/baselines/reference/isolatedModulesPlainFile-System.js b/tests/baselines/reference/isolatedModulesPlainFile-System.js index 39320759740..39b648e071a 100644 --- a/tests/baselines/reference/isolatedModulesPlainFile-System.js +++ b/tests/baselines/reference/isolatedModulesPlainFile-System.js @@ -5,13 +5,13 @@ run(1); //// [isolatedModulesPlainFile-System.js] -System.register([], function(exports_1, context_1) { +System.register([], function (exports_1, context_1) { "use strict"; var __moduleName = context_1 && context_1.id; return { - setters:[], - execute: function() { + setters: [], + execute: function () { run(1); } - } + }; }); diff --git a/tests/baselines/reference/localClassesInLoop.js b/tests/baselines/reference/localClassesInLoop.js index 0090ada863d..d01d86da8d1 100644 --- a/tests/baselines/reference/localClassesInLoop.js +++ b/tests/baselines/reference/localClassesInLoop.js @@ -13,7 +13,7 @@ use(data[0]() === data[1]()); //// [localClassesInLoop.js] "use strict"; var data = []; -var _loop_1 = function(x) { +var _loop_1 = function (x) { var C = (function () { function C() { } diff --git a/tests/baselines/reference/modulePrologueSystem.js b/tests/baselines/reference/modulePrologueSystem.js index 13f7d35b001..c3919669a8d 100644 --- a/tests/baselines/reference/modulePrologueSystem.js +++ b/tests/baselines/reference/modulePrologueSystem.js @@ -4,13 +4,13 @@ export class Foo {} //// [modulePrologueSystem.js] -System.register([], function(exports_1, context_1) { +System.register([], function (exports_1, context_1) { "use strict"; var __moduleName = context_1 && context_1.id; var Foo; return { - setters:[], - execute: function() { + setters: [], + execute: function () { Foo = (function () { function Foo() { } @@ -18,5 +18,5 @@ System.register([], function(exports_1, context_1) { }()); exports_1("Foo", Foo); } - } + }; }); From b9c311cffe357c91f0282cc1f0d58a26106be17a Mon Sep 17 00:00:00 2001 From: Mohamed Hegazy Date: Tue, 12 Apr 2016 16:31:05 -0700 Subject: [PATCH 36/58] Accept baselines: extra parens --- .../baselines/reference/arrowFunctionWithObjectLiteralBody1.js | 2 +- .../baselines/reference/arrowFunctionWithObjectLiteralBody2.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/baselines/reference/arrowFunctionWithObjectLiteralBody1.js b/tests/baselines/reference/arrowFunctionWithObjectLiteralBody1.js index d53f33deadc..85c0b85daea 100644 --- a/tests/baselines/reference/arrowFunctionWithObjectLiteralBody1.js +++ b/tests/baselines/reference/arrowFunctionWithObjectLiteralBody1.js @@ -2,4 +2,4 @@ var v = a => {} //// [arrowFunctionWithObjectLiteralBody1.js] -var v = function (a) { return {}; }; +var v = function (a) { return ({}); }; diff --git a/tests/baselines/reference/arrowFunctionWithObjectLiteralBody2.js b/tests/baselines/reference/arrowFunctionWithObjectLiteralBody2.js index f2fc086c082..5164a98331c 100644 --- a/tests/baselines/reference/arrowFunctionWithObjectLiteralBody2.js +++ b/tests/baselines/reference/arrowFunctionWithObjectLiteralBody2.js @@ -2,4 +2,4 @@ var v = a => {} //// [arrowFunctionWithObjectLiteralBody2.js] -var v = function (a) { return {}; }; +var v = function (a) { return ({}); }; From 00a4aab88da937e0adb0ad22a12f02390f6ca4a7 Mon Sep 17 00:00:00 2001 From: Mohamed Hegazy Date: Tue, 12 Apr 2016 16:32:24 -0700 Subject: [PATCH 37/58] Accept baselines: better comment output --- ...WithStaticFunctionAndExportedFunctionThatShareAName.js | 8 ++++---- tests/baselines/reference/bind1.js | 4 ++-- .../reference/callSignaturesWithParameterInitializers2.js | 3 ++- .../reference/declarationEmit_inferedDefaultExportType.js | 1 + .../duplicateIdentifiersAcrossContainerBoundaries.js | 8 ++++---- .../baselines/reference/duplicateSymbolsExportMatching.js | 4 ++-- .../emitArrowFunctionWhenUsingArguments01_ES6.js | 8 ++++---- tests/baselines/reference/invalidTryStatements2.js | 2 +- tests/baselines/reference/modifierOnParameter1.js | 2 +- tests/baselines/reference/promiseChaining.js | 2 +- tests/baselines/reference/promiseChaining1.js | 2 +- tests/baselines/reference/qualifiedModuleLocals.js | 4 ++-- .../stringIndexerConstrainsPropertyDeclarations.js | 3 ++- 13 files changed, 27 insertions(+), 24 deletions(-) diff --git a/tests/baselines/reference/ClassAndModuleThatMergeWithStaticFunctionAndExportedFunctionThatShareAName.js b/tests/baselines/reference/ClassAndModuleThatMergeWithStaticFunctionAndExportedFunctionThatShareAName.js index d971dd160db..b8e332f1932 100644 --- a/tests/baselines/reference/ClassAndModuleThatMergeWithStaticFunctionAndExportedFunctionThatShareAName.js +++ b/tests/baselines/reference/ClassAndModuleThatMergeWithStaticFunctionAndExportedFunctionThatShareAName.js @@ -33,8 +33,8 @@ var Point = (function () { }()); var Point; (function (Point) { - function Origin() { return null; } - Point.Origin = Origin; //expected duplicate identifier error + function Origin() { return null; } //expected duplicate identifier error + Point.Origin = Origin; })(Point || (Point = {})); var A; (function (A) { @@ -49,7 +49,7 @@ var A; A.Point = Point; var Point; (function (Point) { - function Origin() { return ""; } - Point.Origin = Origin; //expected duplicate identifier error + function Origin() { return ""; } //expected duplicate identifier error + Point.Origin = Origin; })(Point = A.Point || (A.Point = {})); })(A || (A = {})); diff --git a/tests/baselines/reference/bind1.js b/tests/baselines/reference/bind1.js index c658384db85..93eafedf81b 100644 --- a/tests/baselines/reference/bind1.js +++ b/tests/baselines/reference/bind1.js @@ -12,6 +12,6 @@ var M; function C() { } return C; - }()); - M.C = C; // this should be an unresolved symbol I error + }()); // this should be an unresolved symbol I error + M.C = C; })(M || (M = {})); diff --git a/tests/baselines/reference/callSignaturesWithParameterInitializers2.js b/tests/baselines/reference/callSignaturesWithParameterInitializers2.js index fd1dd369010..10fd481d7c6 100644 --- a/tests/baselines/reference/callSignaturesWithParameterInitializers2.js +++ b/tests/baselines/reference/callSignaturesWithParameterInitializers2.js @@ -48,7 +48,8 @@ var b = { foo: function (x) { if (x === void 0) { x = 1; } }, - foo: function (x) { + foo: // error + function (x) { if (x === void 0) { x = 1; } } }; diff --git a/tests/baselines/reference/declarationEmit_inferedDefaultExportType.js b/tests/baselines/reference/declarationEmit_inferedDefaultExportType.js index ee80738a269..4fa998f86b8 100644 --- a/tests/baselines/reference/declarationEmit_inferedDefaultExportType.js +++ b/tests/baselines/reference/declarationEmit_inferedDefaultExportType.js @@ -10,6 +10,7 @@ export default { //// [declarationEmit_inferedDefaultExportType.js] "use strict"; exports.__esModule = true; +// test.ts exports["default"] = { foo: [], bar: undefined, diff --git a/tests/baselines/reference/duplicateIdentifiersAcrossContainerBoundaries.js b/tests/baselines/reference/duplicateIdentifiersAcrossContainerBoundaries.js index 21733e2cebf..eae9e9e4de1 100644 --- a/tests/baselines/reference/duplicateIdentifiersAcrossContainerBoundaries.js +++ b/tests/baselines/reference/duplicateIdentifiersAcrossContainerBoundaries.js @@ -73,8 +73,8 @@ var M; function f() { } return f; - }()); - M.f = f; // error + }()); // error + M.f = f; })(M || (M = {})); var M; (function (M) { @@ -86,8 +86,8 @@ var M; function g() { } return g; - }()); - M.g = g; // no error + }()); // no error + M.g = g; })(M || (M = {})); var M; (function (M) { diff --git a/tests/baselines/reference/duplicateSymbolsExportMatching.js b/tests/baselines/reference/duplicateSymbolsExportMatching.js index d37d1efb3bb..bb04e3c72a4 100644 --- a/tests/baselines/reference/duplicateSymbolsExportMatching.js +++ b/tests/baselines/reference/duplicateSymbolsExportMatching.js @@ -92,8 +92,8 @@ define(["require", "exports"], function (require, exports) { (function (F) { var t; })(F || (F = {})); - function F() { } - M.F = F; // Only one error for duplicate identifier (don't consider visibility) + function F() { } // Only one error for duplicate identifier (don't consider visibility) + M.F = F; })(M || (M = {})); var M; (function (M) { diff --git a/tests/baselines/reference/emitArrowFunctionWhenUsingArguments01_ES6.js b/tests/baselines/reference/emitArrowFunctionWhenUsingArguments01_ES6.js index 6641e28b867..8434d0a5251 100644 --- a/tests/baselines/reference/emitArrowFunctionWhenUsingArguments01_ES6.js +++ b/tests/baselines/reference/emitArrowFunctionWhenUsingArguments01_ES6.js @@ -41,9 +41,9 @@ var b = function () { }; }; function baz() { - (() => { + () => { var arg = arguments[0]; - }); + }; } function foo(inputFunc) { } foo(() => { @@ -52,8 +52,8 @@ foo(() => { function bar() { var arg = arguments[0]; // no error } -(() => { +() => { function foo() { var arg = arguments[0]; // no error } -}); +}; diff --git a/tests/baselines/reference/invalidTryStatements2.js b/tests/baselines/reference/invalidTryStatements2.js index 1b2976dc4e7..118b607817a 100644 --- a/tests/baselines/reference/invalidTryStatements2.js +++ b/tests/baselines/reference/invalidTryStatements2.js @@ -44,7 +44,7 @@ function fn2() { } finally { } // error missing try try { - } // error missing try + } catch (x) { } // error missing try // no error try { diff --git a/tests/baselines/reference/modifierOnParameter1.js b/tests/baselines/reference/modifierOnParameter1.js index 7b76a805c99..dd800aeb886 100644 --- a/tests/baselines/reference/modifierOnParameter1.js +++ b/tests/baselines/reference/modifierOnParameter1.js @@ -5,7 +5,7 @@ class C { //// [modifierOnParameter1.js] var C = (function () { - function C() { + function C(p) { } return C; }()); diff --git a/tests/baselines/reference/promiseChaining.js b/tests/baselines/reference/promiseChaining.js index 3f0900f7748..afa55acb894 100644 --- a/tests/baselines/reference/promiseChaining.js +++ b/tests/baselines/reference/promiseChaining.js @@ -19,7 +19,7 @@ var Chain = (function () { Chain.prototype.then = function (cb) { var result = cb(this.value); // should get a fresh type parameter which each then call - var z = this.then(function (x) { return result; }) /*S*/.then(function (x) { return "abc"; }) /*string*/.then(function (x) { return x.length; }); // No error + var z = this.then(function (x) { return result; }) /*S*/.then(function (x) { return "abc"; }) /*string*/.then(function (x) { return x.length; }) /*number*/; // No error return new Chain(result); }; return Chain; diff --git a/tests/baselines/reference/promiseChaining1.js b/tests/baselines/reference/promiseChaining1.js index b396261a59e..ad2ddcf694b 100644 --- a/tests/baselines/reference/promiseChaining1.js +++ b/tests/baselines/reference/promiseChaining1.js @@ -19,7 +19,7 @@ var Chain2 = (function () { Chain2.prototype.then = function (cb) { var result = cb(this.value); // should get a fresh type parameter which each then call - var z = this.then(function (x) { return result; }) /*S*/.then(function (x) { return "abc"; }) /*Function*/.then(function (x) { return x.length; }); // Should error on "abc" because it is not a Function + var z = this.then(function (x) { return result; }) /*S*/.then(function (x) { return "abc"; }) /*Function*/.then(function (x) { return x.length; }) /*number*/; // Should error on "abc" because it is not a Function return new Chain2(result); }; return Chain2; diff --git a/tests/baselines/reference/qualifiedModuleLocals.js b/tests/baselines/reference/qualifiedModuleLocals.js index b7ba5b70e81..7fcbc0700f8 100644 --- a/tests/baselines/reference/qualifiedModuleLocals.js +++ b/tests/baselines/reference/qualifiedModuleLocals.js @@ -14,7 +14,7 @@ A.a(); var A; (function (A) { function b() { } - function a() { A.b(); } - A.a = a; // A.b should be an unresolved symbol error + function a() { A.b(); } // A.b should be an unresolved symbol error + A.a = a; })(A || (A = {})); A.a(); diff --git a/tests/baselines/reference/stringIndexerConstrainsPropertyDeclarations.js b/tests/baselines/reference/stringIndexerConstrainsPropertyDeclarations.js index 57df8ce2883..92a7f353ba5 100644 --- a/tests/baselines/reference/stringIndexerConstrainsPropertyDeclarations.js +++ b/tests/baselines/reference/stringIndexerConstrainsPropertyDeclarations.js @@ -103,7 +103,8 @@ var C = (function () { function C() { } // ok Object.defineProperty(C.prototype, "X", { - get: function () { + get: // error + function () { return ''; }, set: function (v) { } // ok From bc29c55882fd9120a8444fff0f1499ee17efc347 Mon Sep 17 00:00:00 2001 From: Mohamed Hegazy Date: Tue, 12 Apr 2016 16:33:06 -0700 Subject: [PATCH 38/58] Accept baselines --- .../reference/assignmentLHSIsValue.js | 2 +- .../reference/castExpressionParentheses.js | 2 +- .../reference/computedPropertyNames11_ES5.js | 10 +++++++++ ...TypedClassExpressionMethodDeclaration01.js | 8 +++---- .../declarationEmit_invalidExport.js | 2 +- ...ecoratedDefaultExportsGetExportedSystem.js | 22 +++++++++---------- ...onentiationAssignmentWithIndexingOnLHS2.js | 14 ++++++------ ...onentiationAssignmentWithIndexingOnLHS3.js | 8 +++---- .../emptyAssignmentPatterns03_ES5.js | 4 ++-- .../emptyAssignmentPatterns04_ES5.js | 4 ++-- .../noImplicitAnyInCastExpression.js | 6 ++--- 11 files changed, 46 insertions(+), 36 deletions(-) diff --git a/tests/baselines/reference/assignmentLHSIsValue.js b/tests/baselines/reference/assignmentLHSIsValue.js index 8a3b4b35d0b..ecc1cded2cc 100644 --- a/tests/baselines/reference/assignmentLHSIsValue.js +++ b/tests/baselines/reference/assignmentLHSIsValue.js @@ -113,7 +113,7 @@ false = value; } value; // array literals -'' = value[0], '' = value[1]; +"" = value[0], "" = value[1]; // super var Derived = (function (_super) { __extends(Derived, _super); diff --git a/tests/baselines/reference/castExpressionParentheses.js b/tests/baselines/reference/castExpressionParentheses.js index b4754d0ad41..94d5daafb0a 100644 --- a/tests/baselines/reference/castExpressionParentheses.js +++ b/tests/baselines/reference/castExpressionParentheses.js @@ -53,7 +53,7 @@ new (A()); //// [castExpressionParentheses.js] // parentheses should be omitted // literals -{ a: 0 }; +({ a: 0 }); [1, 3,]; "string"; 23.0; diff --git a/tests/baselines/reference/computedPropertyNames11_ES5.js b/tests/baselines/reference/computedPropertyNames11_ES5.js index c569c1f080c..568cce441e1 100644 --- a/tests/baselines/reference/computedPropertyNames11_ES5.js +++ b/tests/baselines/reference/computedPropertyNames11_ES5.js @@ -46,6 +46,16 @@ var v = (_a = {}, enumerable: true, configurable: true }), + Object.defineProperty(_a, "", { + set: function (v) { }, + enumerable: true, + configurable: true + }), + Object.defineProperty(_a, 0, { + get: function () { return 0; }, + enumerable: true, + configurable: true + }), Object.defineProperty(_a, a, { set: function (v) { }, enumerable: true, diff --git a/tests/baselines/reference/contextuallyTypedClassExpressionMethodDeclaration01.js b/tests/baselines/reference/contextuallyTypedClassExpressionMethodDeclaration01.js index 2c8efdd424a..a6eaa048093 100644 --- a/tests/baselines/reference/contextuallyTypedClassExpressionMethodDeclaration01.js +++ b/tests/baselines/reference/contextuallyTypedClassExpressionMethodDeclaration01.js @@ -61,7 +61,7 @@ function getFoo1() { }()); } function getFoo2() { - return (_a = (function () { + return _a = (function () { function class_2() { } return class_2; @@ -72,11 +72,11 @@ function getFoo2() { _a.method2 = function (arg) { arg.strProp = "hello"; }, - _a); + _a; var _a; } function getFoo3() { - return (_a = (function () { + return _a = (function () { function class_3() { } return class_3; @@ -87,6 +87,6 @@ function getFoo3() { _a.method2 = function (arg) { arg.strProp = "hello"; }, - _a); + _a; var _a; } diff --git a/tests/baselines/reference/declarationEmit_invalidExport.js b/tests/baselines/reference/declarationEmit_invalidExport.js index 61682ca5642..74b5bfd8019 100644 --- a/tests/baselines/reference/declarationEmit_invalidExport.js +++ b/tests/baselines/reference/declarationEmit_invalidExport.js @@ -10,5 +10,5 @@ export type MyClass = typeof myClass; //// [declarationEmit_invalidExport.js] "use strict"; if (false) { - exports.myClass = 0; + export var myClass = 0; } diff --git a/tests/baselines/reference/decoratedDefaultExportsGetExportedSystem.js b/tests/baselines/reference/decoratedDefaultExportsGetExportedSystem.js index d5cd115edc0..0b336bdd546 100644 --- a/tests/baselines/reference/decoratedDefaultExportsGetExportedSystem.js +++ b/tests/baselines/reference/decoratedDefaultExportsGetExportedSystem.js @@ -13,19 +13,19 @@ var decorator: ClassDecorator; export default class {} //// [a.js] -System.register([], function(exports_1, context_1) { +System.register([], function (exports_1, context_1) { "use strict"; - var __moduleName = context_1 && context_1.id; var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) { var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d; if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc); else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r; return c > 3 && r && Object.defineProperty(target, key, r), r; }; + var __moduleName = context_1 && context_1.id; var decorator, Foo; return { - setters:[], - execute: function() { + setters: [], + execute: function () { Foo = class Foo { }; Foo = __decorate([ @@ -33,22 +33,22 @@ System.register([], function(exports_1, context_1) { ], Foo); exports_1("default", Foo); } - } + }; }); //// [b.js] -System.register([], function(exports_1, context_1) { +System.register([], function (exports_1, context_1) { "use strict"; - var __moduleName = context_1 && context_1.id; var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) { var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d; if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc); else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r; return c > 3 && r && Object.defineProperty(target, key, r), r; }; - var decorator, default_1; + var __moduleName = context_1 && context_1.id; + var decorator, default_1_1; return { - setters:[], - execute: function() { + setters: [], + execute: function () { default_1 = class { }; default_1 = __decorate([ @@ -56,5 +56,5 @@ System.register([], function(exports_1, context_1) { ], default_1); exports_1("default", default_1); } - } + }; }); diff --git a/tests/baselines/reference/emitCompoundExponentiationAssignmentWithIndexingOnLHS2.js b/tests/baselines/reference/emitCompoundExponentiationAssignmentWithIndexingOnLHS2.js index 83e0b2473e8..54ef77b0467 100644 --- a/tests/baselines/reference/emitCompoundExponentiationAssignmentWithIndexingOnLHS2.js +++ b/tests/baselines/reference/emitCompoundExponentiationAssignmentWithIndexingOnLHS2.js @@ -17,10 +17,10 @@ function foo() { globalCounter += 1; return { 0: 2 }; } -(_a = foo(), _a[0] = Math.pow(_a[0], foo()[0])); -var result_foo1 = (_b = foo(), _b[0] = Math.pow(_b[0], foo()[0])); -(_c = foo(), _c[0] = Math.pow(_c[0], (_d = foo(), _d[0] = Math.pow(_d[0], 2)))); -var result_foo2 = (_e = foo(), _e[0] = Math.pow(_e[0], (_f = foo(), _f[0] = Math.pow(_f[0], 2)))); -(_g = foo(), _g[0] = Math.pow(_g[0], Math.pow(foo()[0], 2))); -var result_foo3 = (_h = foo(), _h[0] = Math.pow(_h[0], Math.pow(foo()[0], 2))); -var _a, _b, _c, _d, _e, _f, _g, _h; +(_a = foo())[_b = 0] = Math.pow(_a[_b], foo()[0]); +var result_foo1 = (_c = foo())[_d = 0] = Math.pow(_c[_d], foo()[0]); +(_e = foo())[_f = 0] = Math.pow(_e[_f], (_g = foo())[_h = 0] = Math.pow(_g[_h], 2)); +var result_foo2 = (_j = foo())[_k = 0] = Math.pow(_j[_k], (_l = foo())[_m = 0] = Math.pow(_l[_m], 2)); +(_o = foo())[_p = 0] = Math.pow(_o[_p], Math.pow(foo()[0], 2)); +var result_foo3 = (_q = foo())[_r = 0] = Math.pow(_q[_r], Math.pow(foo()[0], 2)); +var _a, _b, _c, _d, _g, _h, _e, _f, _l, _m, _j, _k, _o, _p, _q, _r; diff --git a/tests/baselines/reference/emitCompoundExponentiationAssignmentWithIndexingOnLHS3.js b/tests/baselines/reference/emitCompoundExponentiationAssignmentWithIndexingOnLHS3.js index 797ccccc331..66b9a7018fc 100644 --- a/tests/baselines/reference/emitCompoundExponentiationAssignmentWithIndexingOnLHS3.js +++ b/tests/baselines/reference/emitCompoundExponentiationAssignmentWithIndexingOnLHS3.js @@ -23,7 +23,7 @@ var object = { this._0 = x; }, }; -(_a = object, _a[0] = Math.pow(_a[0], object[0])); -(_b = object, _b[0] = Math.pow(_b[0], (_c = object, _c[0] = Math.pow(_c[0], 2)))); -(_d = object, _d[0] = Math.pow(_d[0], Math.pow(object[0], 2))); -var _a, _b, _c, _d; +(_a = object)[_b = 0] = Math.pow(_a[_b], object[0]); +(_c = object)[_d = 0] = Math.pow(_c[_d], (_e = object)[_f = 0] = Math.pow(_e[_f], 2)); +(_g = object)[_h = 0] = Math.pow(_g[_h], Math.pow(object[0], 2)); +var _a, _b, _e, _f, _c, _d, _g, _h; diff --git a/tests/baselines/reference/emptyAssignmentPatterns03_ES5.js b/tests/baselines/reference/emptyAssignmentPatterns03_ES5.js index adaad2e3b63..a1b605fa2e0 100644 --- a/tests/baselines/reference/emptyAssignmentPatterns03_ES5.js +++ b/tests/baselines/reference/emptyAssignmentPatterns03_ES5.js @@ -7,8 +7,8 @@ var a: any; //// [emptyAssignmentPatterns03_ES5.js] var a; -(a); -(a); +({} = a); +([] = a); //// [emptyAssignmentPatterns03_ES5.d.ts] diff --git a/tests/baselines/reference/emptyAssignmentPatterns04_ES5.js b/tests/baselines/reference/emptyAssignmentPatterns04_ES5.js index e6b3cc7e3f2..f76420844a3 100644 --- a/tests/baselines/reference/emptyAssignmentPatterns04_ES5.js +++ b/tests/baselines/reference/emptyAssignmentPatterns04_ES5.js @@ -9,8 +9,8 @@ let x, y, z, a1, a2, a3; //// [emptyAssignmentPatterns04_ES5.js] var a; var x, y, z, a1, a2, a3; -(_a = a, x = _a.x, y = _a.y, z = _a.z, _a); -(_b = a, a1 = _b[0], a2 = _b[1], a3 = _b[2], _b); +(_a = {} = a, x = _a.x, y = _a.y, z = _a.z, _a); +(_b = [] = a, a1 = _b[0], a2 = _b[1], a3 = _b[2], _b); var _a, _b; diff --git a/tests/baselines/reference/noImplicitAnyInCastExpression.js b/tests/baselines/reference/noImplicitAnyInCastExpression.js index 1b7cc59c7c0..b0a6907a5b4 100644 --- a/tests/baselines/reference/noImplicitAnyInCastExpression.js +++ b/tests/baselines/reference/noImplicitAnyInCastExpression.js @@ -19,8 +19,8 @@ interface IFoo { //// [noImplicitAnyInCastExpression.js] // verify no noImplictAny errors reported with cast expression // Expr type not assignable to target type -{ a: null }; +({ a: null }); // Expr type assignable to target type -{ a: 2, b: undefined }; +({ a: 2, b: undefined }); // Neither types is assignable to each other -{ c: null }; +({ c: null }); From 446494060d2b4e66b423b2a98e014e7d5ecd82a5 Mon Sep 17 00:00:00 2001 From: Ron Buckton Date: Tue, 12 Apr 2016 18:40:39 -0700 Subject: [PATCH 39/58] PR feedback --- Jakefile.js | 38 +++++++++++++++++++++----------------- 1 file changed, 21 insertions(+), 17 deletions(-) diff --git a/Jakefile.js b/Jakefile.js index 6ed276c73c0..dd0d7643fb3 100644 --- a/Jakefile.js +++ b/Jakefile.js @@ -658,21 +658,19 @@ function exec(cmd, completeHandler, errorHandler) { } function cleanTestDirs() { - if (!environmentVariableIsDisabled("CLEAN_TESTS")) { - // Clean the local baselines directory - if (fs.existsSync(localBaseline)) { - jake.rmRf(localBaseline); - } - - // Clean the local Rwc baselines directory - if (fs.existsSync(localRwcBaseline)) { - jake.rmRf(localRwcBaseline); - } - - jake.mkdirP(localRwcBaseline); - jake.mkdirP(localTest262Baseline); - jake.mkdirP(localBaseline); + // Clean the local baselines directory + if (fs.existsSync(localBaseline)) { + jake.rmRf(localBaseline); } + + // Clean the local Rwc baselines directory + if (fs.existsSync(localRwcBaseline)) { + jake.rmRf(localRwcBaseline); + } + + jake.mkdirP(localRwcBaseline); + jake.mkdirP(localTest262Baseline); + jake.mkdirP(localBaseline); } // used to pass data from jake command line directly to run.js @@ -828,8 +826,11 @@ function runTestsAndWriteOutput(file) { }); } -function runConsoleTests(defaultReporter, defaultSubsets) { - cleanTestDirs(); +function runConsoleTests(defaultReporter, defaultSubsets, dirty) { + if (!dirty) { + cleanTestDirs(); + } + var debug = process.env.debug || process.env.d; tests = process.env.test || process.env.tests || process.env.t; var light = process.env.light || false; @@ -868,7 +869,7 @@ function runConsoleTests(defaultReporter, defaultSubsets) { console.log(cmd); exec(cmd, function () { deleteTemporaryProjectOutput(); - if (i === 0 && !environmentVariableIsDisabled("lint")) { + if (i === 0 && !dirty) { var lint = jake.Task['lint']; lint.addListener('complete', function () { complete(); @@ -896,6 +897,9 @@ task("runtests", ["build-rules", "tests", builtLocalDirectory], function() { task("runtests-file", ["build-rules", "tests", builtLocalDirectory], function () { runTestsAndWriteOutput("tests/baselines/local/testresults.tap"); }, { async: true }); +task("runtests-dirty", ["build-rules", "tests", builtLocalDirectory], function () { + runConsoleTests("mocha-fivemat-progress-reporter", [], /*dirty*/ true); +}, { async: true }); desc("Generates code coverage data via instanbul"); task("generate-code-coverage", ["tests", builtLocalDirectory], function () { From a96c5845290e557f3bf238b0176a690b781b58b0 Mon Sep 17 00:00:00 2001 From: Sheetal Nandi Date: Wed, 13 Apr 2016 10:16:41 -0700 Subject: [PATCH 40/58] Commend rewording per PR feedback --- src/compiler/printer.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/compiler/printer.ts b/src/compiler/printer.ts index 398908edd82..532237ff081 100644 --- a/src/compiler/printer.ts +++ b/src/compiler/printer.ts @@ -2609,7 +2609,7 @@ const _super = (function (geti, seti) { while (node.original !== undefined) { const nodeId = node.id; node = node.original; - // If this is not the exact clone of identifier use this identifier to generate the name + // If "node" is not the exact clone of "original" identifier, use "original" identifier to generate the name if (isIdentifier(node) && node.autoGenerateKind === GeneratedIdentifierKind.Node && node.id !== nodeId) { break; } From 9899cda6d3eaefd685443e791d73135a31d2d613 Mon Sep 17 00:00:00 2001 From: Ron Buckton Date: Wed, 13 Apr 2016 10:43:01 -0700 Subject: [PATCH 41/58] PR Feedback, also removes cloneEntityName. --- src/compiler/checker.ts | 5 ++++- src/compiler/emitter.ts | 31 +++++++++++++++++++------------ src/compiler/transformers/ts.ts | 2 +- src/compiler/utilities.ts | 22 ---------------------- 4 files changed, 24 insertions(+), 36 deletions(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 10e3c19497d..e339cd390f5 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -16216,7 +16216,10 @@ namespace ts { const exportClause = (node).exportClause; return exportClause && forEach(exportClause.elements, isValueAliasDeclaration); case SyntaxKind.ExportAssignment: - return (node).expression && (node).expression.kind === SyntaxKind.Identifier ? isAliasResolvedToValue(getSymbolOfNode(node) || unknownSymbol) : true; + return (node).expression + && (node).expression.kind === SyntaxKind.Identifier + ? isAliasResolvedToValue(getSymbolOfNode(node) || unknownSymbol) + : true; } return false; } diff --git a/src/compiler/emitter.ts b/src/compiler/emitter.ts index bb4d179704c..e3f9838cf26 100644 --- a/src/compiler/emitter.ts +++ b/src/compiler/emitter.ts @@ -2240,41 +2240,49 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge emit(node.right); } - function emitQualifiedNameAsExpression(node: QualifiedName, useFallback: boolean) { + function emitQualifiedNameAsExpression(node: QualifiedName, useFallback: boolean, location?: Node) { if (node.left.kind === SyntaxKind.Identifier) { - emitEntityNameAsExpression(node.left, useFallback); + emitEntityNameAsExpression(node.left, useFallback, location); } else if (useFallback) { const temp = createAndRecordTempVariable(TempFlags.Auto); write("("); emitNodeWithoutSourceMap(temp); write(" = "); - emitEntityNameAsExpression(node.left, /*useFallback*/ true); + emitEntityNameAsExpression(node.left, /*useFallback*/ true, location); write(") && "); emitNodeWithoutSourceMap(temp); } else { - emitEntityNameAsExpression(node.left, /*useFallback*/ false); + emitEntityNameAsExpression(node.left, /*useFallback*/ false, location); } write("."); emit(node.right); } - function emitEntityNameAsExpression(node: EntityName | Expression, useFallback: boolean) { + function emitEntityNameAsExpression(node: EntityName | Expression, useFallback: boolean, location?: Node) { switch (node.kind) { case SyntaxKind.Identifier: + let name = node; + if (location) { + // to resolve the expression to the correct container, create a shallow + // clone of `node` with a new parent. + name = clone(name); + name.parent = location; + } + if (useFallback) { write("typeof "); - emitExpressionIdentifier(node); + emitExpressionIdentifier(name); write(" !== 'undefined' && "); } - emitExpressionIdentifier(node); + emitExpressionIdentifier(name); break; case SyntaxKind.QualifiedName: - emitQualifiedNameAsExpression(node, useFallback); + emitQualifiedNameAsExpression(node, useFallback, location); break; default: @@ -5943,22 +5951,21 @@ const _super = (function (geti, seti) { } // Clone the type name and parent it to a location outside of the current declaration. - const typeName = cloneEntityName(node.typeName, location); - const result = resolver.getTypeReferenceSerializationKind(typeName); + const result = resolver.getTypeReferenceSerializationKind(node.typeName, location); switch (result) { case TypeReferenceSerializationKind.Unknown: let temp = createAndRecordTempVariable(TempFlags.Auto); write("(typeof ("); emitNodeWithoutSourceMap(temp); write(" = "); - emitEntityNameAsExpression(typeName, /*useFallback*/ true); + emitEntityNameAsExpression(node.typeName, /*useFallback*/ true, location); write(") === 'function' && "); emitNodeWithoutSourceMap(temp); write(") || Object"); break; case TypeReferenceSerializationKind.TypeWithConstructSignatureAndValue: - emitEntityNameAsExpression(typeName, /*useFallback*/ false); + emitEntityNameAsExpression(node.typeName, /*useFallback*/ false, location); break; case TypeReferenceSerializationKind.VoidType: diff --git a/src/compiler/transformers/ts.ts b/src/compiler/transformers/ts.ts index 78536f56697..710edd77504 100644 --- a/src/compiler/transformers/ts.ts +++ b/src/compiler/transformers/ts.ts @@ -2644,7 +2644,7 @@ namespace ts { return getNamespaceMemberName(name); } else { - // We set the "PrefixExportedLocal" flag to indicate to any module transformer + // We set the "ExportName" flag to indicate to any module transformer // downstream that any `exports.` prefix should be added. setNodeEmitFlags(name, getNodeEmitFlags(name) | NodeEmitFlags.ExportName); return name; diff --git a/src/compiler/utilities.ts b/src/compiler/utilities.ts index fd1ad48a74f..83038f1e3df 100644 --- a/src/compiler/utilities.ts +++ b/src/compiler/utilities.ts @@ -1711,28 +1711,6 @@ namespace ts { || kind === SyntaxKind.SourceFile; } - /** - * Creates a deep clone of an EntityName, with new parent pointers. - * NOTE: The new entity name will *not* have "original" pointers. - * - * @param node The EntityName to clone. - * @param parent The parent for the cloned node. - */ - export function cloneEntityName(node: EntityName, parent?: Node): EntityName { - const clone = getMutableClone(node); - clone.original = undefined; - clone.parent = parent; - if (isQualifiedName(clone)) { - const { left, right } = clone; - clone.left = cloneEntityName(left, clone); - clone.right = getMutableClone(right); - clone.right.original = undefined; - clone.right.parent = clone; - } - - return clone; - } - export function nodeIsSynthesized(node: TextRange): boolean { return positionIsSynthesized(node.pos) || positionIsSynthesized(node.end); From bdb76400f316813e290865941ff8bb2449354003 Mon Sep 17 00:00:00 2001 From: Nathan Shively-Sanders Date: Wed, 13 Apr 2016 11:38:21 -0700 Subject: [PATCH 42/58] Return undefined instead of createNotEmittedStatement --- src/compiler/transformers/ts.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/compiler/transformers/ts.ts b/src/compiler/transformers/ts.ts index 90bac017d5a..1cf93f050c9 100644 --- a/src/compiler/transformers/ts.ts +++ b/src/compiler/transformers/ts.ts @@ -163,7 +163,7 @@ namespace ts { (node.kind === SyntaxKind.ImportEqualsDeclaration && (node).moduleReference.kind === SyntaxKind.ExternalModuleReference)) { // do not emit ES6 imports and exports since they are illegal inside a namespace - return createNotEmittedStatement(node); + return undefined; } else if (node.transformFlags & TransformFlags.TypeScript || hasModifier(node, ModifierFlags.Export)) { // This node is explicitly marked as TypeScript, or is exported at the namespace From 7b07d3ce27e75c165b60b4dc06a84352941f793c Mon Sep 17 00:00:00 2001 From: Sheetal Nandi Date: Wed, 13 Apr 2016 11:59:29 -0700 Subject: [PATCH 43/58] Fix the trailing comment emit for module declaration Fixes #8045 Fixes: - tests\cases\compiler\augmentedTypesClass3.ts - tests\cases\compiler\augmentedTypesModules.ts - tests\cases\compiler\commentsModules.ts --- src/compiler/comments.ts | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/src/compiler/comments.ts b/src/compiler/comments.ts index 1baf1847f04..4ecf2dd6935 100644 --- a/src/compiler/comments.ts +++ b/src/compiler/comments.ts @@ -117,6 +117,25 @@ namespace ts { return undefined; } + const node = range as Node; + if (node.kind === SyntaxKind.VariableStatement && + node.original && + node.original.kind === SyntaxKind.ModuleDeclaration) { + // Trailing comments for module declaration should be emitted with function closure instead of variable statement + // /** Module comment*/ + // module m1 { + // function foo4Export() { + // } + // } // trailing comment module + // Should emit + // /** Module comment*/ + // var m1; + // (function (m1) { + // function foo4Export() { + // } + // })(m1 || (m1 = {})); // trailing comment module + return undefined; + } return getTrailingCommentsOfPosition(range.end); } From 27adb8c363c6a172a5a489929251f569666bd2d2 Mon Sep 17 00:00:00 2001 From: Sheetal Nandi Date: Wed, 13 Apr 2016 12:05:21 -0700 Subject: [PATCH 44/58] Fix the trailing comments for enum declaration Fixes #8045 Tests fixed: - tests\cases\compiler\augmentedTypesClass.ts - tests\cases\compiler\augmentedTypesEnum.ts - tests\cases\compiler\augmentedTypesEnum2.ts - tests\cases\compiler\augmentedTypesFunction.ts - tests\cases\compiler\augmentedTypesVar.ts - tests\cases\compiler\commentsEnums.ts --- src/compiler/comments.ts | 2 +- src/compiler/transformers/ts.ts | 26 ++++---------------------- 2 files changed, 5 insertions(+), 23 deletions(-) diff --git a/src/compiler/comments.ts b/src/compiler/comments.ts index 4ecf2dd6935..f5f8549dd28 100644 --- a/src/compiler/comments.ts +++ b/src/compiler/comments.ts @@ -120,7 +120,7 @@ namespace ts { const node = range as Node; if (node.kind === SyntaxKind.VariableStatement && node.original && - node.original.kind === SyntaxKind.ModuleDeclaration) { + (node.original.kind === SyntaxKind.ModuleDeclaration || node.original.kind === SyntaxKind.EnumDeclaration)) { // Trailing comments for module declaration should be emitted with function closure instead of variable statement // /** Module comment*/ // module m1 { diff --git a/src/compiler/transformers/ts.ts b/src/compiler/transformers/ts.ts index 0b8c11a66e2..8a915484a79 100644 --- a/src/compiler/transformers/ts.ts +++ b/src/compiler/transformers/ts.ts @@ -2213,24 +2213,6 @@ namespace ts { || (isES6ExportedDeclaration(node) && isFirstDeclarationOfKind(node, node.kind)); } - /** - * Adds a leading VariableStatement for an enum or module declaration. - */ - function addVarForEnumDeclaration(statements: Statement[], node: EnumDeclaration) { - // Emit a variable statement for the enum. - statements.push( - createVariableStatement( - isES6ExportedDeclaration(node) - ? visitNodes(node.modifiers, visitor, isModifier) - : undefined, - [createVariableDeclaration( - getDeclarationName(node) - )], - /*location*/ node - ) - ); - } - /** * Adds a trailing VariableStatement for an enum or module declaration. */ @@ -2261,7 +2243,7 @@ namespace ts { const statements: Statement[] = []; if (shouldEmitVarForEnumDeclaration(node)) { - addVarForEnumDeclaration(statements, node); + addVarForEnumOrModuleDeclaration(statements, node); } const localName = getGeneratedNameForNode(node); @@ -2395,9 +2377,9 @@ namespace ts { } /** - * Adds a leading VariableStatement for a module declaration. + * Adds a leading VariableStatement for a enum or module declaration. */ - function addVarForModuleDeclaration(statements: Statement[], node: ModuleDeclaration) { + function addVarForEnumOrModuleDeclaration(statements: Statement[], node: ModuleDeclaration | EnumDeclaration) { // Emit a variable statement for the module. statements.push( setOriginalNode( @@ -2433,7 +2415,7 @@ namespace ts { const statements: Statement[] = []; if (shouldEmitVarForModuleDeclaration(node)) { - addVarForModuleDeclaration(statements, node); + addVarForEnumOrModuleDeclaration(statements, node); } const localName = getGeneratedNameForNode(node); From cf859be9dad88fe3f6f56ace8faf27123ab3b60e Mon Sep 17 00:00:00 2001 From: Mohamed Hegazy Date: Wed, 13 Apr 2016 12:13:26 -0700 Subject: [PATCH 45/58] Review comments --- src/compiler/factory.ts | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/src/compiler/factory.ts b/src/compiler/factory.ts index b620be2ed5e..e35c5a08297 100644 --- a/src/compiler/factory.ts +++ b/src/compiler/factory.ts @@ -1708,6 +1708,9 @@ namespace ts { return nodes; } + /** + * Get the name of that target module from an import or export declaration + */ export function getLocalNameForExternalImport(node: ImportDeclaration | ExportDeclaration | ImportEqualsDeclaration, sourceFile: SourceFile): Identifier { const namespaceDeclaration = getNamespaceDeclarationNode(node); if (namespaceDeclaration && !isDefaultImport(node)) { @@ -1719,8 +1722,17 @@ namespace ts { if (node.kind === SyntaxKind.ExportDeclaration && (node).moduleSpecifier) { return getGeneratedNameForNode(node); } + return undefined; } + /** + * Get the name of a target module from an import/export declaration as should be written in the emitted output. + * The emitted output name can be different from the input if: + * 1. The module has a /// + * 2. --out or --outFile is used, making the name relative to the rootDir + * 3- The containing SourceFile has an entry in renamedDependencies for the import as requested by some module loaders (e.g. System). + * Otherwise, a new StringLiteral node representing the module name will be returned. + */ export function getExternalModuleNameLiteral(importNode: ImportDeclaration | ExportDeclaration | ImportEqualsDeclaration, sourceFile: SourceFile, host: EmitHost, resolver: EmitResolver, compilerOptions: CompilerOptions) { const moduleName = getExternalModuleName(importNode); if (moduleName.kind === SyntaxKind.StringLiteral) { @@ -1743,6 +1755,13 @@ namespace ts { return undefined; } + /** + * Get the name of a module as should be written in the emitted output. + * The emitted output name can be different from the input if: + * 1. The module has a /// + * 2. --out or --outFile is used, making the name relative to the rootDir + * Otherwise, a new StringLiteral node representing the module name will be returned. + */ export function tryGetModuleNameFromFile(file: SourceFile, host: EmitHost, options: CompilerOptions): StringLiteral { if (!file) { return undefined; From 47e9ee57c825c94b6700c5c6b549dcc19124a544 Mon Sep 17 00:00:00 2001 From: Mohamed Hegazy Date: Wed, 13 Apr 2016 12:45:05 -0700 Subject: [PATCH 46/58] Remove commas from nodeEdgeTraversalMap manually for now --- src/compiler/visitor.ts | 178 ++++++++++++++++++++-------------------- 1 file changed, 89 insertions(+), 89 deletions(-) diff --git a/src/compiler/visitor.ts b/src/compiler/visitor.ts index 81f36399b62..d55357bed8d 100644 --- a/src/compiler/visitor.ts +++ b/src/compiler/visitor.ts @@ -46,27 +46,27 @@ namespace ts { const nodeEdgeTraversalMap: Map = { [SyntaxKind.QualifiedName]: [ { name: "left", test: isEntityName }, - { name: "right", test: isIdentifier }, + { name: "right", test: isIdentifier } ], [SyntaxKind.ComputedPropertyName]: [ - { name: "expression", test: isExpression }, + { name: "expression", test: isExpression } ], [SyntaxKind.Parameter]: [ { name: "decorators", test: isDecorator }, { name: "modifiers", test: isModifier }, { name: "name", test: isBindingName }, { name: "type", test: isTypeNode, optional: true }, - { name: "initializer", test: isExpression, optional: true, parenthesize: parenthesizeExpressionForList }, + { name: "initializer", test: isExpression, optional: true, parenthesize: parenthesizeExpressionForList } ], [SyntaxKind.Decorator]: [ - { name: "expression", test: isLeftHandSideExpression }, + { name: "expression", test: isLeftHandSideExpression } ], [SyntaxKind.PropertyDeclaration]: [ { name: "decorators", test: isDecorator }, { name: "modifiers", test: isModifier }, { name: "name", test: isPropertyName }, { name: "type", test: isTypeNode, optional: true }, - { name: "initializer", test: isExpression, optional: true }, + { name: "initializer", test: isExpression, optional: true } ], [SyntaxKind.MethodDeclaration]: [ { name: "decorators", test: isDecorator }, @@ -75,7 +75,7 @@ namespace ts { { name: "typeParameters", test: isTypeParameter }, { name: "parameters", test: isParameter }, { name: "type", test: isTypeNode, optional: true }, - { name: "body", test: isBlock, optional: true }, + { name: "body", test: isBlock, optional: true } ], [SyntaxKind.Constructor]: [ { name: "decorators", test: isDecorator }, @@ -83,7 +83,7 @@ namespace ts { { name: "typeParameters", test: isTypeParameter }, { name: "parameters", test: isParameter }, { name: "type", test: isTypeNode, optional: true }, - { name: "body", test: isBlock, optional: true }, + { name: "body", test: isBlock, optional: true } ], [SyntaxKind.GetAccessor]: [ { name: "decorators", test: isDecorator }, @@ -92,7 +92,7 @@ namespace ts { { name: "typeParameters", test: isTypeParameter }, { name: "parameters", test: isParameter }, { name: "type", test: isTypeNode, optional: true }, - { name: "body", test: isBlock, optional: true }, + { name: "body", test: isBlock, optional: true } ], [SyntaxKind.SetAccessor]: [ { name: "decorators", test: isDecorator }, @@ -101,53 +101,53 @@ namespace ts { { name: "typeParameters", test: isTypeParameter }, { name: "parameters", test: isParameter }, { name: "type", test: isTypeNode, optional: true }, - { name: "body", test: isBlock, optional: true }, + { name: "body", test: isBlock, optional: true } ], [SyntaxKind.ObjectBindingPattern]: [ - { name: "elements", test: isBindingElement }, + { name: "elements", test: isBindingElement } ], [SyntaxKind.ArrayBindingPattern]: [ - { name: "elements", test: isBindingElement }, + { name: "elements", test: isBindingElement } ], [SyntaxKind.BindingElement]: [ { name: "propertyName", test: isPropertyName, optional: true }, { name: "name", test: isBindingName }, - { name: "initializer", test: isExpression, optional: true, parenthesize: parenthesizeExpressionForList }, + { name: "initializer", test: isExpression, optional: true, parenthesize: parenthesizeExpressionForList } ], [SyntaxKind.ArrayLiteralExpression]: [ - { name: "elements", test: isExpression, parenthesize: parenthesizeExpressionForList }, + { name: "elements", test: isExpression, parenthesize: parenthesizeExpressionForList } ], [SyntaxKind.ObjectLiteralExpression]: [ - { name: "properties", test: isObjectLiteralElement }, + { name: "properties", test: isObjectLiteralElement } ], [SyntaxKind.PropertyAccessExpression]: [ { name: "expression", test: isLeftHandSideExpression, parenthesize: parenthesizeForAccess }, - { name: "name", test: isIdentifier }, + { name: "name", test: isIdentifier } ], [SyntaxKind.ElementAccessExpression]: [ { name: "expression", test: isLeftHandSideExpression, parenthesize: parenthesizeForAccess }, - { name: "argumentExpression", test: isExpression }, + { name: "argumentExpression", test: isExpression } ], [SyntaxKind.CallExpression]: [ { name: "expression", test: isLeftHandSideExpression, parenthesize: parenthesizeForAccess }, { name: "typeArguments", test: isTypeNode }, - { name: "arguments", test: isExpression, parenthesize: parenthesizeExpressionForList }, + { name: "arguments", test: isExpression, parenthesize: parenthesizeExpressionForList } ], [SyntaxKind.NewExpression]: [ { name: "expression", test: isLeftHandSideExpression, parenthesize: parenthesizeForNew }, { name: "typeArguments", test: isTypeNode }, - { name: "arguments", test: isExpression, parenthesize: parenthesizeExpressionForList }, + { name: "arguments", test: isExpression, parenthesize: parenthesizeExpressionForList } ], [SyntaxKind.TaggedTemplateExpression]: [ { name: "tag", test: isLeftHandSideExpression, parenthesize: parenthesizeForAccess }, - { name: "template", test: isTemplate }, + { name: "template", test: isTemplate } ], [SyntaxKind.TypeAssertionExpression]: [ { name: "type", test: isTypeNode }, - { name: "expression", test: isUnaryExpression }, + { name: "expression", test: isUnaryExpression } ], [SyntaxKind.ParenthesizedExpression]: [ - { name: "expression", test: isExpression }, + { name: "expression", test: isExpression } ], [SyntaxKind.FunctionExpression]: [ { name: "decorators", test: isDecorator }, @@ -156,7 +156,7 @@ namespace ts { { name: "typeParameters", test: isTypeParameter }, { name: "parameters", test: isParameter }, { name: "type", test: isTypeNode, optional: true }, - { name: "body", test: isBlock, optional: true }, + { name: "body", test: isBlock, optional: true } ], [SyntaxKind.ArrowFunction]: [ { name: "decorators", test: isDecorator }, @@ -164,44 +164,44 @@ namespace ts { { name: "typeParameters", test: isTypeParameter }, { name: "parameters", test: isParameter }, { name: "type", test: isTypeNode, optional: true }, - { name: "body", test: isConciseBody, lift: liftToBlock, parenthesize: parenthesizeConciseBody }, + { name: "body", test: isConciseBody, lift: liftToBlock, parenthesize: parenthesizeConciseBody } ], [SyntaxKind.DeleteExpression]: [ - { name: "expression", test: isUnaryExpression, parenthesize: parenthesizePrefixOperand }, + { name: "expression", test: isUnaryExpression, parenthesize: parenthesizePrefixOperand } ], [SyntaxKind.TypeOfExpression]: [ - { name: "expression", test: isUnaryExpression, parenthesize: parenthesizePrefixOperand }, + { name: "expression", test: isUnaryExpression, parenthesize: parenthesizePrefixOperand } ], [SyntaxKind.VoidExpression]: [ - { name: "expression", test: isUnaryExpression, parenthesize: parenthesizePrefixOperand }, + { name: "expression", test: isUnaryExpression, parenthesize: parenthesizePrefixOperand } ], [SyntaxKind.AwaitExpression]: [ - { name: "expression", test: isUnaryExpression, parenthesize: parenthesizePrefixOperand }, + { name: "expression", test: isUnaryExpression, parenthesize: parenthesizePrefixOperand } ], [SyntaxKind.PrefixUnaryExpression]: [ - { name: "operand", test: isUnaryExpression, parenthesize: parenthesizePrefixOperand }, + { name: "operand", test: isUnaryExpression, parenthesize: parenthesizePrefixOperand } ], [SyntaxKind.PostfixUnaryExpression]: [ - { name: "operand", test: isLeftHandSideExpression, parenthesize: parenthesizePostfixOperand }, + { name: "operand", test: isLeftHandSideExpression, parenthesize: parenthesizePostfixOperand } ], [SyntaxKind.BinaryExpression]: [ { name: "left", test: isExpression, parenthesize: (node: Expression, parent: BinaryExpression) => parenthesizeBinaryOperand(getOperator(parent), node, true, /*leftOperand*/ undefined) }, - { name: "right", test: isExpression, parenthesize: (node: Expression, parent: BinaryExpression) => parenthesizeBinaryOperand(getOperator(parent), node, false, parent.left) }, + { name: "right", test: isExpression, parenthesize: (node: Expression, parent: BinaryExpression) => parenthesizeBinaryOperand(getOperator(parent), node, false, parent.left) } ], [SyntaxKind.ConditionalExpression]: [ { name: "condition", test: isExpression }, { name: "whenTrue", test: isExpression }, - { name: "whenFalse", test: isExpression }, + { name: "whenFalse", test: isExpression } ], [SyntaxKind.TemplateExpression]: [ { name: "head", test: isTemplateLiteralFragment }, - { name: "templateSpans", test: isTemplateSpan }, + { name: "templateSpans", test: isTemplateSpan } ], [SyntaxKind.YieldExpression]: [ - { name: "expression", test: isExpression, optional: true }, + { name: "expression", test: isExpression, optional: true } ], [SyntaxKind.SpreadElementExpression]: [ - { name: "expression", test: isExpression, parenthesize: parenthesizeExpressionForList }, + { name: "expression", test: isExpression, parenthesize: parenthesizeExpressionForList } ], [SyntaxKind.ClassExpression]: [ { name: "decorators", test: isDecorator }, @@ -209,96 +209,96 @@ namespace ts { { name: "name", test: isIdentifier, optional: true }, { name: "typeParameters", test: isTypeParameter }, { name: "heritageClauses", test: isHeritageClause }, - { name: "members", test: isClassElement }, + { name: "members", test: isClassElement } ], [SyntaxKind.ExpressionWithTypeArguments]: [ { name: "expression", test: isLeftHandSideExpression, parenthesize: parenthesizeForAccess }, - { name: "typeArguments", test: isTypeNode }, + { name: "typeArguments", test: isTypeNode } ], [SyntaxKind.AsExpression]: [ { name: "expression", test: isExpression }, - { name: "type", test: isTypeNode }, + { name: "type", test: isTypeNode } ], [SyntaxKind.TemplateSpan]: [ { name: "expression", test: isExpression }, - { name: "literal", test: isTemplateLiteralFragment }, + { name: "literal", test: isTemplateLiteralFragment } ], [SyntaxKind.Block]: [ - { name: "statements", test: isStatement }, + { name: "statements", test: isStatement } ], [SyntaxKind.VariableStatement]: [ { name: "decorators", test: isDecorator }, { name: "modifiers", test: isModifier }, - { name: "declarationList", test: isVariableDeclarationList }, + { name: "declarationList", test: isVariableDeclarationList } ], [SyntaxKind.ExpressionStatement]: [ - { name: "expression", test: isExpression, parenthesize: parenthesizeExpressionForExpressionStatement }, + { name: "expression", test: isExpression, parenthesize: parenthesizeExpressionForExpressionStatement } ], [SyntaxKind.IfStatement]: [ { name: "expression", test: isExpression }, { name: "thenStatement", test: isStatement, lift: liftToBlock }, - { name: "elseStatement", test: isStatement, lift: liftToBlock, optional: true }, + { name: "elseStatement", test: isStatement, lift: liftToBlock, optional: true } ], [SyntaxKind.DoStatement]: [ { name: "statement", test: isStatement, lift: liftToBlock }, - { name: "expression", test: isExpression }, + { name: "expression", test: isExpression } ], [SyntaxKind.WhileStatement]: [ { name: "expression", test: isExpression }, - { name: "statement", test: isStatement, lift: liftToBlock }, + { name: "statement", test: isStatement, lift: liftToBlock } ], [SyntaxKind.ForStatement]: [ { name: "initializer", test: isForInitializer, optional: true }, { name: "condition", test: isExpression, optional: true }, { name: "incrementor", test: isExpression, optional: true }, - { name: "statement", test: isStatement, lift: liftToBlock }, + { name: "statement", test: isStatement, lift: liftToBlock } ], [SyntaxKind.ForInStatement]: [ { name: "initializer", test: isForInitializer }, { name: "expression", test: isExpression }, - { name: "statement", test: isStatement, lift: liftToBlock }, + { name: "statement", test: isStatement, lift: liftToBlock } ], [SyntaxKind.ForOfStatement]: [ { name: "initializer", test: isForInitializer }, { name: "expression", test: isExpression }, - { name: "statement", test: isStatement, lift: liftToBlock }, + { name: "statement", test: isStatement, lift: liftToBlock } ], [SyntaxKind.ContinueStatement]: [ - { name: "label", test: isIdentifier, optional: true }, + { name: "label", test: isIdentifier, optional: true } ], [SyntaxKind.BreakStatement]: [ - { name: "label", test: isIdentifier, optional: true }, + { name: "label", test: isIdentifier, optional: true } ], [SyntaxKind.ReturnStatement]: [ - { name: "expression", test: isExpression, optional: true }, + { name: "expression", test: isExpression, optional: true } ], [SyntaxKind.WithStatement]: [ { name: "expression", test: isExpression }, - { name: "statement", test: isStatement, lift: liftToBlock }, + { name: "statement", test: isStatement, lift: liftToBlock } ], [SyntaxKind.SwitchStatement]: [ { name: "expression", test: isExpression }, - { name: "caseBlock", test: isCaseBlock }, + { name: "caseBlock", test: isCaseBlock } ], [SyntaxKind.LabeledStatement]: [ { name: "label", test: isIdentifier }, - { name: "statement", test: isStatement, lift: liftToBlock }, + { name: "statement", test: isStatement, lift: liftToBlock } ], [SyntaxKind.ThrowStatement]: [ - { name: "expression", test: isExpression }, + { name: "expression", test: isExpression } ], [SyntaxKind.TryStatement]: [ { name: "tryBlock", test: isBlock }, { name: "catchClause", test: isCatchClause, optional: true }, - { name: "finallyBlock", test: isBlock, optional: true }, + { name: "finallyBlock", test: isBlock, optional: true } ], [SyntaxKind.VariableDeclaration]: [ { name: "name", test: isBindingName }, { name: "type", test: isTypeNode, optional: true }, - { name: "initializer", test: isExpression, optional: true, parenthesize: parenthesizeExpressionForList }, + { name: "initializer", test: isExpression, optional: true, parenthesize: parenthesizeExpressionForList } ], [SyntaxKind.VariableDeclarationList]: [ - { name: "declarations", test: isVariableDeclaration }, + { name: "declarations", test: isVariableDeclaration } ], [SyntaxKind.FunctionDeclaration]: [ { name: "decorators", test: isDecorator }, @@ -307,7 +307,7 @@ namespace ts { { name: "typeParameters", test: isTypeParameter }, { name: "parameters", test: isParameter }, { name: "type", test: isTypeNode, optional: true }, - { name: "body", test: isBlock, optional: true }, + { name: "body", test: isBlock, optional: true } ], [SyntaxKind.ClassDeclaration]: [ { name: "decorators", test: isDecorator }, @@ -315,127 +315,127 @@ namespace ts { { name: "name", test: isIdentifier, optional: true }, { name: "typeParameters", test: isTypeParameter }, { name: "heritageClauses", test: isHeritageClause }, - { name: "members", test: isClassElement }, + { name: "members", test: isClassElement } ], [SyntaxKind.EnumDeclaration]: [ { name: "decorators", test: isDecorator }, { name: "modifiers", test: isModifier }, { name: "name", test: isIdentifier }, - { name: "members", test: isEnumMember }, + { name: "members", test: isEnumMember } ], [SyntaxKind.ModuleDeclaration]: [ { name: "decorators", test: isDecorator }, { name: "modifiers", test: isModifier }, { name: "name", test: isModuleName }, - { name: "body", test: isModuleBody }, + { name: "body", test: isModuleBody } ], [SyntaxKind.ModuleBlock]: [ - { name: "statements", test: isStatement }, + { name: "statements", test: isStatement } ], [SyntaxKind.CaseBlock]: [ - { name: "clauses", test: isCaseOrDefaultClause }, + { name: "clauses", test: isCaseOrDefaultClause } ], [SyntaxKind.ImportEqualsDeclaration]: [ { name: "decorators", test: isDecorator }, { name: "modifiers", test: isModifier }, { name: "name", test: isIdentifier }, - { name: "moduleReference", test: isModuleReference }, + { name: "moduleReference", test: isModuleReference } ], [SyntaxKind.ImportDeclaration]: [ { name: "decorators", test: isDecorator }, { name: "modifiers", test: isModifier }, { name: "importClause", test: isImportClause, optional: true }, - { name: "moduleSpecifier", test: isExpression }, + { name: "moduleSpecifier", test: isExpression } ], [SyntaxKind.ImportClause]: [ { name: "name", test: isIdentifier, optional: true }, - { name: "namedBindings", test: isNamedImportBindings, optional: true }, + { name: "namedBindings", test: isNamedImportBindings, optional: true } ], [SyntaxKind.NamespaceImport]: [ - { name: "name", test: isIdentifier }, + { name: "name", test: isIdentifier } ], [SyntaxKind.NamedImports]: [ - { name: "elements", test: isImportSpecifier }, + { name: "elements", test: isImportSpecifier } ], [SyntaxKind.ImportSpecifier]: [ { name: "propertyName", test: isIdentifier, optional: true }, - { name: "name", test: isIdentifier }, + { name: "name", test: isIdentifier } ], [SyntaxKind.ExportAssignment]: [ { name: "decorators", test: isDecorator }, { name: "modifiers", test: isModifier }, - { name: "expression", test: isExpression }, + { name: "expression", test: isExpression } ], [SyntaxKind.ExportDeclaration]: [ { name: "decorators", test: isDecorator }, { name: "modifiers", test: isModifier }, { name: "exportClause", test: isNamedExports, optional: true }, - { name: "moduleSpecifier", test: isExpression, optional: true }, + { name: "moduleSpecifier", test: isExpression, optional: true } ], [SyntaxKind.NamedExports]: [ - { name: "elements", test: isExportSpecifier }, + { name: "elements", test: isExportSpecifier } ], [SyntaxKind.ExportSpecifier]: [ { name: "propertyName", test: isIdentifier, optional: true }, - { name: "name", test: isIdentifier }, + { name: "name", test: isIdentifier } ], [SyntaxKind.ExternalModuleReference]: [ - { name: "expression", test: isExpression, optional: true }, + { name: "expression", test: isExpression, optional: true } ], [SyntaxKind.JsxElement]: [ { name: "openingElement", test: isJsxOpeningElement }, { name: "children", test: isJsxChild }, - { name: "closingElement", test: isJsxClosingElement }, + { name: "closingElement", test: isJsxClosingElement } ], [SyntaxKind.JsxSelfClosingElement]: [ { name: "tagName", test: isEntityName }, - { name: "attributes", test: isJsxAttributeLike }, + { name: "attributes", test: isJsxAttributeLike } ], [SyntaxKind.JsxOpeningElement]: [ { name: "tagName", test: isEntityName }, - { name: "attributes", test: isJsxAttributeLike }, + { name: "attributes", test: isJsxAttributeLike } ], [SyntaxKind.JsxClosingElement]: [ - { name: "tagName", test: isEntityName }, + { name: "tagName", test: isEntityName } ], [SyntaxKind.JsxAttribute]: [ { name: "name", test: isIdentifier }, - { name: "initializer", test: isStringLiteralOrJsxExpression, optional: true }, + { name: "initializer", test: isStringLiteralOrJsxExpression, optional: true } ], [SyntaxKind.JsxSpreadAttribute]: [ - { name: "expression", test: isExpression }, + { name: "expression", test: isExpression } ], [SyntaxKind.JsxExpression]: [ - { name: "expression", test: isExpression, optional: true }, + { name: "expression", test: isExpression, optional: true } ], [SyntaxKind.CaseClause]: [ { name: "expression", test: isExpression, parenthesize: parenthesizeExpressionForList }, - { name: "statements", test: isStatement }, + { name: "statements", test: isStatement } ], [SyntaxKind.DefaultClause]: [ - { name: "statements", test: isStatement }, + { name: "statements", test: isStatement } ], [SyntaxKind.HeritageClause]: [ - { name: "types", test: isExpressionWithTypeArguments }, + { name: "types", test: isExpressionWithTypeArguments } ], [SyntaxKind.CatchClause]: [ { name: "variableDeclaration", test: isVariableDeclaration }, - { name: "block", test: isBlock }, + { name: "block", test: isBlock } ], [SyntaxKind.PropertyAssignment]: [ { name: "name", test: isPropertyName }, - { name: "initializer", test: isExpression, parenthesize: parenthesizeExpressionForList }, + { name: "initializer", test: isExpression, parenthesize: parenthesizeExpressionForList } ], [SyntaxKind.ShorthandPropertyAssignment]: [ { name: "name", test: isIdentifier }, - { name: "objectAssignmentInitializer", test: isExpression, optional: true }, + { name: "objectAssignmentInitializer", test: isExpression, optional: true } ], [SyntaxKind.EnumMember]: [ { name: "name", test: isPropertyName }, - { name: "initializer", test: isExpression, optional: true, parenthesize: parenthesizeExpressionForList }, + { name: "initializer", test: isExpression, optional: true, parenthesize: parenthesizeExpressionForList } ], [SyntaxKind.SourceFile]: [ - { name: "statements", test: isStatement }, + { name: "statements", test: isStatement } ], [SyntaxKind.NotEmittedStatement]: [], [SyntaxKind.PartiallyEmittedExpression]: [ From a721a223da3b8d6610010ec15fb0cd8f451ed539 Mon Sep 17 00:00:00 2001 From: Nathan Shively-Sanders Date: Wed, 13 Apr 2016 11:31:09 -0700 Subject: [PATCH 47/58] Set LocalName flag for exported local then skip it The module transformer now skips substitution of LocalName, just like ts transformer already does. --- src/compiler/transformers/module/module.ts | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/compiler/transformers/module/module.ts b/src/compiler/transformers/module/module.ts index 1de4de782cb..31f68a4cb5e 100644 --- a/src/compiler/transformers/module/module.ts +++ b/src/compiler/transformers/module/module.ts @@ -552,7 +552,7 @@ namespace ts { } else { statements.push( - createExportStatement(node.name, node.name, /*location*/ node) + createExportStatement(node.name, setNodeEmitFlags(getSynthesizedClone(node.name), NodeEmitFlags.LocalName), /*location*/ node) ); } } @@ -712,6 +712,10 @@ namespace ts { } function substituteExpressionIdentifier(node: Identifier): Expression { + if (getNodeEmitFlags(node) & NodeEmitFlags.LocalName) { + return node; + } + const container = resolver.getReferencedExportContainer(node, (getNodeEmitFlags(node) & NodeEmitFlags.ExportName) !== 0); if (container) { if (container.kind === SyntaxKind.SourceFile) { From 5ea65855b0169c577ef8820df047044495702716 Mon Sep 17 00:00:00 2001 From: Sheetal Nandi Date: Wed, 13 Apr 2016 14:01:09 -0700 Subject: [PATCH 48/58] Revert changes from 5e308b9 --- src/compiler/visitor.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/compiler/visitor.ts b/src/compiler/visitor.ts index 6acf8fcf17d..81f36399b62 100644 --- a/src/compiler/visitor.ts +++ b/src/compiler/visitor.ts @@ -461,7 +461,7 @@ namespace ts { const edgeTraversalPath = nodeEdgeTraversalMap[node.kind]; if (edgeTraversalPath) { for (const edge of edgeTraversalPath) { - const value = edge && (>node)[edge.name]; + const value = (>node)[edge.name]; if (value !== undefined) { result = isArray(value) ? reduceLeft(>value, f, result) @@ -619,7 +619,7 @@ namespace ts { const edgeTraversalPath = nodeEdgeTraversalMap[node.kind]; if (edgeTraversalPath) { for (const edge of edgeTraversalPath) { - const value = edge && >node[edge.name]; + const value = >node[edge.name]; if (value !== undefined) { let visited: Node | NodeArray; if (isArray(value)) { From 2e47f22fcc75cc0989dfb5f44ec372896bb38447 Mon Sep 17 00:00:00 2001 From: Sheetal Nandi Date: Wed, 13 Apr 2016 14:14:00 -0700 Subject: [PATCH 49/58] Set the end position of variable statement as -1 so the trailing comments are not emitted --- src/compiler/comments.ts | 19 ------------------- src/compiler/transformers/ts.ts | 16 +++++++++++++++- 2 files changed, 15 insertions(+), 20 deletions(-) diff --git a/src/compiler/comments.ts b/src/compiler/comments.ts index f5f8549dd28..1baf1847f04 100644 --- a/src/compiler/comments.ts +++ b/src/compiler/comments.ts @@ -117,25 +117,6 @@ namespace ts { return undefined; } - const node = range as Node; - if (node.kind === SyntaxKind.VariableStatement && - node.original && - (node.original.kind === SyntaxKind.ModuleDeclaration || node.original.kind === SyntaxKind.EnumDeclaration)) { - // Trailing comments for module declaration should be emitted with function closure instead of variable statement - // /** Module comment*/ - // module m1 { - // function foo4Export() { - // } - // } // trailing comment module - // Should emit - // /** Module comment*/ - // var m1; - // (function (m1) { - // function foo4Export() { - // } - // })(m1 || (m1 = {})); // trailing comment module - return undefined; - } return getTrailingCommentsOfPosition(range.end); } diff --git a/src/compiler/transformers/ts.ts b/src/compiler/transformers/ts.ts index 8a915484a79..539061dd481 100644 --- a/src/compiler/transformers/ts.ts +++ b/src/compiler/transformers/ts.ts @@ -2390,7 +2390,21 @@ namespace ts { [createVariableDeclaration( getDeclarationName(node) )], - /*location*/ node + // Trailing comments for module declaration should be emitted with function closure instead of variable statement + // So do not set the end position for the variable statement node + // /** Module comment*/ + // module m1 { + // function foo4Export() { + // } + // } // trailing comment module + // Should emit + // /** Module comment*/ + // var m1; + // (function (m1) { + // function foo4Export() { + // } + // })(m1 || (m1 = {})); // trailing comment module + /*location*/ { pos: node.pos, end: -1 } ), node ) From f4066e57da3e02086189c5727c030bdfd0cc393d Mon Sep 17 00:00:00 2001 From: Yui Date: Wed, 13 Apr 2016 14:41:56 -0700 Subject: [PATCH 50/58] [Transforms] updatebaseline (#8067) * Emit comment at the end of function declaration * Use double quote * Fix formatting * Emit incorrrect code as-is * Fix emit comment From 3de310af066b852008b0462fd271d4357970bf3e Mon Sep 17 00:00:00 2001 From: Vladimir Matveev Date: Wed, 13 Apr 2016 15:14:35 -0700 Subject: [PATCH 51/58] emit 'export *' for es6 only if module exports some value --- src/compiler/transformers/module/es6.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/compiler/transformers/module/es6.ts b/src/compiler/transformers/module/es6.ts index d2f4ca4f224..742f208d61c 100644 --- a/src/compiler/transformers/module/es6.ts +++ b/src/compiler/transformers/module/es6.ts @@ -55,7 +55,7 @@ namespace ts { function visitExportDeclaration(node: ExportDeclaration): ExportDeclaration { if (!node.exportClause) { - return node; // export * is always emitted + return resolver.moduleExportsSomeValue(node.moduleSpecifier) ? node : undefined; } if (!resolver.isValueAliasDeclaration(node)) { return undefined; From 8fa44c3b06c798b6d4399d7836320df38f5fb4ec Mon Sep 17 00:00:00 2001 From: Nathan Shively-Sanders Date: Wed, 13 Apr 2016 15:49:02 -0700 Subject: [PATCH 52/58] Capture `this` in computed property names in arrow functions --- src/compiler/binder.ts | 12 ++++++++++++ src/compiler/types.ts | 15 ++++++++------- .../reference/computedPropertyNames29_ES5.js | 3 ++- .../reference/computedPropertyNames31_ES5.js | 3 ++- 4 files changed, 24 insertions(+), 9 deletions(-) diff --git a/src/compiler/binder.ts b/src/compiler/binder.ts index 1cff02ffc48..b48b320d0d1 100644 --- a/src/compiler/binder.ts +++ b/src/compiler/binder.ts @@ -1910,6 +1910,9 @@ namespace ts { // This is so that they can flow through PropertyName transforms unaffected. // Instead, we mark the container as ES6, so that it can properly handle the transform. transformFlags = TransformFlags.ContainsComputedPropertyName; + if (subtreeFlags & TransformFlags.ContainsLexicalThis) { + transformFlags |= TransformFlags.ContainsLexicalThisInComputedPropertyName; + } break; case SyntaxKind.SpreadElementExpression: @@ -1945,6 +1948,9 @@ namespace ts { // is an ES6 node. transformFlags = TransformFlags.AssertES6; } + if (subtreeFlags & TransformFlags.ContainsLexicalThisInComputedPropertyName) { + transformFlags |= TransformFlags.ContainsLexicalThis; + } break; case SyntaxKind.CallExpression: @@ -2256,6 +2262,9 @@ namespace ts { || hasModifier(node, ModifierFlags.Export)) { transformFlags |= TransformFlags.AssertTypeScript; } + if (subtreeFlags & TransformFlags.ContainsLexicalThisInComputedPropertyName) { + transformFlags |= TransformFlags.ContainsLexicalThis; + } return updateTransformFlags(node, subtreeFlags, transformFlags, TransformFlags.ClassExcludes); } @@ -2272,6 +2281,9 @@ namespace ts { | TransformFlags.ContainsDecorators)) { transformFlags |= TransformFlags.AssertTypeScript; } + if (subtreeFlags & TransformFlags.ContainsLexicalThisInComputedPropertyName) { + transformFlags |= TransformFlags.ContainsLexicalThis; + } return updateTransformFlags(node, subtreeFlags, transformFlags, TransformFlags.ClassExcludes); } diff --git a/src/compiler/types.ts b/src/compiler/types.ts index 627b33f0d34..4c99417950d 100644 --- a/src/compiler/types.ts +++ b/src/compiler/types.ts @@ -2830,11 +2830,12 @@ namespace ts { ContainsPropertyInitializer = 1 << 10, ContainsLexicalThis = 1 << 11, ContainsCapturedLexicalThis = 1 << 12, - ContainsDefaultValueAssignments = 1 << 13, - ContainsParameterPropertyAssignments = 1 << 14, - ContainsSpreadElementExpression = 1 << 15, - ContainsComputedPropertyName = 1 << 16, - ContainsBlockScopedBinding = 1 << 17, + ContainsLexicalThisInComputedPropertyName = 1 << 13, + ContainsDefaultValueAssignments = 1 << 14, + ContainsParameterPropertyAssignments = 1 << 15, + ContainsSpreadElementExpression = 1 << 16, + ContainsComputedPropertyName = 1 << 17, + ContainsBlockScopedBinding = 1 << 18, HasComputedFlags = 1 << 31, // Transform flags have been computed. @@ -2853,10 +2854,10 @@ namespace ts { FunctionExcludes = ContainsDecorators | ContainsDefaultValueAssignments | ContainsCapturedLexicalThis | ContainsLexicalThis | ContainsParameterPropertyAssignments | ContainsBlockScopedBinding, ConstructorExcludes = ContainsDefaultValueAssignments | ContainsLexicalThis | ContainsCapturedLexicalThis | ContainsBlockScopedBinding, MethodOrAccessorExcludes = ContainsDefaultValueAssignments | ContainsLexicalThis | ContainsCapturedLexicalThis | ContainsBlockScopedBinding, - ClassExcludes = ContainsDecorators | ContainsPropertyInitializer | ContainsLexicalThis | ContainsCapturedLexicalThis | ContainsComputedPropertyName | ContainsParameterPropertyAssignments, + ClassExcludes = ContainsDecorators | ContainsPropertyInitializer | ContainsLexicalThis | ContainsCapturedLexicalThis | ContainsComputedPropertyName | ContainsParameterPropertyAssignments | ContainsLexicalThisInComputedPropertyName, ModuleExcludes = ContainsDecorators | ContainsLexicalThis | ContainsCapturedLexicalThis | ContainsBlockScopedBinding, TypeExcludes = ~ContainsTypeScript, - ObjectLiteralExcludes = ContainsDecorators | ContainsComputedPropertyName, + ObjectLiteralExcludes = ContainsDecorators | ContainsComputedPropertyName | ContainsLexicalThisInComputedPropertyName, ArrayLiteralOrCallOrNewExcludes = ContainsSpreadElementExpression, } diff --git a/tests/baselines/reference/computedPropertyNames29_ES5.js b/tests/baselines/reference/computedPropertyNames29_ES5.js index af6f93c8ad9..966081ae035 100644 --- a/tests/baselines/reference/computedPropertyNames29_ES5.js +++ b/tests/baselines/reference/computedPropertyNames29_ES5.js @@ -18,7 +18,8 @@ var C = (function () { var _this = this; (function () { var obj = (_a = {}, - _a[_this.bar()] = function () { }, + _a[_this.bar()] = function () { } // needs capture + , _a); var _a; }); diff --git a/tests/baselines/reference/computedPropertyNames31_ES5.js b/tests/baselines/reference/computedPropertyNames31_ES5.js index 86fb6655a27..2e38e2a131f 100644 --- a/tests/baselines/reference/computedPropertyNames31_ES5.js +++ b/tests/baselines/reference/computedPropertyNames31_ES5.js @@ -38,7 +38,8 @@ var C = (function (_super) { var _this = this; (function () { var obj = (_a = {}, - _a[_super.prototype.bar.call(_this)] = function () { }, + _a[_super.prototype.bar.call(_this)] = function () { } // needs capture + , _a); var _a; }); From 7bb3a5a514dd7e6800f9f9a8adc346c85b6afe5a Mon Sep 17 00:00:00 2001 From: Nathan Shively-Sanders Date: Wed, 13 Apr 2016 16:03:53 -0700 Subject: [PATCH 53/58] Fix case of mocha TAP -> tap --- Jakefile.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Jakefile.js b/Jakefile.js index 46f2a0fca96..9106c3c619d 100644 --- a/Jakefile.js +++ b/Jakefile.js @@ -717,7 +717,7 @@ function runTestsAndWriteOutput(file) { } var args = []; - args.push("-R", "TAP"); + args.push("-R", "tap"); args.push("--no-colors"); args.push("-t", testTimeout); if (tests) { @@ -1272,4 +1272,4 @@ function environmentVariableIsEnabled(name) { function environmentVariableIsDisabled(name) { return /^(no?|f(alse)?|off|disabled?|0|-)$/.test(process.env[name]); -} \ No newline at end of file +} From e5e8c6b0b936d07365bfcc07b7363380998da163 Mon Sep 17 00:00:00 2001 From: Nathan Shively-Sanders Date: Wed, 13 Apr 2016 16:14:29 -0700 Subject: [PATCH 54/58] Add explanatory comment when adding ContainsLexicalThisInComputedPropertyName --- src/compiler/binder.ts | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/compiler/binder.ts b/src/compiler/binder.ts index b48b320d0d1..5ed1e9665d5 100644 --- a/src/compiler/binder.ts +++ b/src/compiler/binder.ts @@ -1911,6 +1911,9 @@ namespace ts { // Instead, we mark the container as ES6, so that it can properly handle the transform. transformFlags = TransformFlags.ContainsComputedPropertyName; if (subtreeFlags & TransformFlags.ContainsLexicalThis) { + // A computed method name that contains `this` needs to + // distinguish itself from the normal case of a method body containing `this`. + // So convert ContainsLexicalThis to ContainsLexicalThisInComputedPropertyName transformFlags |= TransformFlags.ContainsLexicalThisInComputedPropertyName; } break; From 2c95ea966cb347373b033c557855d40deca9da17 Mon Sep 17 00:00:00 2001 From: Yui Date: Thu, 14 Apr 2016 09:27:08 -0700 Subject: [PATCH 55/58] [Transforms] fix Not correctly emitting local name for exported class (#8048) * Fix 7864: by set emitFlags to not substitute the node * Address PR: fix comment --- src/compiler/transformers/module/module.ts | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/compiler/transformers/module/module.ts b/src/compiler/transformers/module/module.ts index 9d7dc0b2a82..563733a9c97 100644 --- a/src/compiler/transformers/module/module.ts +++ b/src/compiler/transformers/module/module.ts @@ -358,6 +358,9 @@ namespace ts { return undefined; } + // Set emitFlags on the name of the importEqualsDeclaration + // This is so the printer will not substitute the identifier + setNodeEmitFlags(node.name, NodeEmitFlags.NoSubstitution); const statements: Statement[] = []; if (moduleKind !== ModuleKind.AMD) { if (hasModifier(node, ModifierFlags.Export)) { @@ -639,6 +642,9 @@ namespace ts { function visitClassDeclaration(node: ClassDeclaration): VisitResult { const statements: Statement[] = []; const name = node.name || getGeneratedNameForNode(node); + // Set emitFlags on the name of the classDeclaration + // This is so that when printer will not substitute the identifier + setNodeEmitFlags(name, NodeEmitFlags.NoSubstitution); if (hasModifier(node, ModifierFlags.Export)) { statements.push( createClassDeclaration( @@ -834,6 +840,9 @@ namespace ts { // Find the name of the module alias, if there is one const importAliasName = getLocalNameForExternalImport(importNode, currentSourceFile); if (includeNonAmdDependencies && importAliasName) { + // Set emitFlags on the name of the classDeclaration + // This is so that when printer will not substitute the identifier + setNodeEmitFlags(importAliasName, NodeEmitFlags.NoSubstitution); aliasedModuleNames.push(externalModuleName); importAliasNames.push(createParameter(importAliasName)); } From c21ff6421cff8896358a0f134965c4fabbe215c2 Mon Sep 17 00:00:00 2001 From: Yui Date: Thu, 14 Apr 2016 09:30:19 -0700 Subject: [PATCH 56/58] [Transforms] fix8038 and 8047 (#8071) * Fix 8047: stop "require" is paranthesized * Fix 8038: quote "default" in es3 output --- src/compiler/transformers/module/module.ts | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/src/compiler/transformers/module/module.ts b/src/compiler/transformers/module/module.ts index 563733a9c97..83604946102 100644 --- a/src/compiler/transformers/module/module.ts +++ b/src/compiler/transformers/module/module.ts @@ -755,11 +755,20 @@ namespace ts { else if (declaration.kind === SyntaxKind.ImportSpecifier) { const name = (declaration).propertyName || (declaration).name; - return createPropertyAccess( - getGeneratedNameForNode(declaration.parent.parent.parent), - getSynthesizedClone(name), - /*location*/ node - ); + if (name.originalKeywordKind === SyntaxKind.DefaultKeyword && languageVersion <= ScriptTarget.ES3) { + return createElementAccess( + getGeneratedNameForNode(declaration.parent.parent.parent), + createLiteral(name.text), + /*location*/ node + ); + } + else { + return createPropertyAccess( + getGeneratedNameForNode(declaration.parent.parent.parent), + getSynthesizedClone(name), + /*location*/ node + ); + } } } } @@ -791,7 +800,7 @@ namespace ts { function createExportAssignment(name: Identifier, value: Expression) { return createAssignment( - name.originalKeywordKind && languageVersion === ScriptTarget.ES3 + name.originalKeywordKind === SyntaxKind.DefaultKeyword && languageVersion === ScriptTarget.ES3 ? createElementAccess( createIdentifier("exports"), createLiteral(name.text) From d56ac44a27d54a7050ffaa8c29d037e0a8ffc466 Mon Sep 17 00:00:00 2001 From: Yui Date: Thu, 14 Apr 2016 09:41:12 -0700 Subject: [PATCH 57/58] [Transforms] fix `_this = this` capture emitted before `"use strict"` directives in AMD module output (#7953) * Fix 7913: emit prologue directives as a first statement in emitted AMD module * Do not ensure that prologue-directive is added when using it when transforming function body * Address PR: preserve prologue directives location and make sure it is the first statement in the result statements array * Address PR: fix comment --- src/compiler/factory.ts | 11 +++++++++++ src/compiler/transformers/es6.ts | 11 +++++++++-- src/compiler/transformers/module/system.ts | 2 +- 3 files changed, 21 insertions(+), 3 deletions(-) diff --git a/src/compiler/factory.ts b/src/compiler/factory.ts index e35c5a08297..928ba76699e 100644 --- a/src/compiler/factory.ts +++ b/src/compiler/factory.ts @@ -1252,7 +1252,18 @@ namespace ts { return (node.expression as StringLiteral).text === "use strict"; } + /** + * Add any necessary prologue-directives into target statement-array. + * The function needs to be called during each transformation step. + * This function needs to be called whenever we transform the statement + * list of a source file, namespace, or function-like body. + * + * @param target: result statements array + * @param source: origin statements array + * @param ensureUseStrict: boolean determining whether the function need to add prologue-directives + */ export function addPrologueDirectives(target: Statement[], source: Statement[], ensureUseStrict?: boolean): number { + Debug.assert(target.length === 0, "PrologueDirectives should be at the first statement in the target statements array"); let foundUseStrict = false; for (let i = 0; i < source.length; i++) { if (isPrologueDirective(source[i])) { diff --git a/src/compiler/transformers/es6.ts b/src/compiler/transformers/es6.ts index 796dd9529ad..7b769889dca 100644 --- a/src/compiler/transformers/es6.ts +++ b/src/compiler/transformers/es6.ts @@ -1211,7 +1211,15 @@ namespace ts { let statementsLocation: TextRange; const statements: Statement[] = []; + const body = node.body; + let statementOffset: number; + startLexicalEnvironment(); + if (isBlock(body)) { + // ensureUseStrict is false because no new prologue-directive should be added. + // addPrologueDirectives will simply put already-existing directives at the beginning of the target statement-array + statementOffset = addPrologueDirectives(statements, body.statements, /*ensureUseStrict*/ false); + } addCaptureThisForNodeIfNeeded(statements, node); addDefaultValueAssignmentsIfNeeded(statements, node); addRestParameterIfNeeded(statements, node, /*inConstructorWithSynthesizedSuper*/ false); @@ -1221,10 +1229,9 @@ namespace ts { multiLine = true; } - const body = node.body; if (isBlock(body)) { statementsLocation = body.statements; - addRange(statements, visitNodes(body.statements, visitor, isStatement)); + addRange(statements, visitNodes(body.statements, visitor, isStatement, statementOffset)); // If the original body was a multi-line block, this must be a multi-line block. if (!multiLine && body.multiLine) { diff --git a/src/compiler/transformers/module/system.ts b/src/compiler/transformers/module/system.ts index 663917170ef..eee50781f32 100644 --- a/src/compiler/transformers/module/system.ts +++ b/src/compiler/transformers/module/system.ts @@ -193,7 +193,7 @@ namespace ts { startLexicalEnvironment(); // Add any prologue directives. - const statementOffset = addPrologueDirectives(statements, node.statements, !compilerOptions.noImplicitUseStrict); + const statementOffset = addPrologueDirectives(statements, node.statements, /*ensureUseStrict*/ !compilerOptions.noImplicitUseStrict); // var __moduleName = context_1 && context_1.id; addNode(statements, From 0d5bf0ee32a39288cee795f190cae5c36eaf2c86 Mon Sep 17 00:00:00 2001 From: Nathan Shively-Sanders Date: Thu, 14 Apr 2016 09:51:21 -0700 Subject: [PATCH 58/58] Improve comment explaining ContainsLexicalThisInComputedPropertyName --- src/compiler/binder.ts | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/src/compiler/binder.ts b/src/compiler/binder.ts index 5ed1e9665d5..f92f6789d29 100644 --- a/src/compiler/binder.ts +++ b/src/compiler/binder.ts @@ -1911,9 +1911,14 @@ namespace ts { // Instead, we mark the container as ES6, so that it can properly handle the transform. transformFlags = TransformFlags.ContainsComputedPropertyName; if (subtreeFlags & TransformFlags.ContainsLexicalThis) { - // A computed method name that contains `this` needs to - // distinguish itself from the normal case of a method body containing `this`. - // So convert ContainsLexicalThis to ContainsLexicalThisInComputedPropertyName + // A computed method name like `[this.getName()](x: string) { ... }` needs to + // distinguish itself from the normal case of a method body containing `this`: + // `this` inside a method doesn't need to be rewritten (the method provides `this`), + // whereas `this` inside a computed name *might* need to be rewritten if the class/object + // is inside an arrow function: + // `_this = this; () => class K { [_this.getName()]() { ... } }` + // To make this distinction, use ContainsLexicalThisInComputedPropertyName + // instead of ContainsLexicalThis for computed property names transformFlags |= TransformFlags.ContainsLexicalThisInComputedPropertyName; } break; @@ -1952,6 +1957,8 @@ namespace ts { transformFlags = TransformFlags.AssertES6; } if (subtreeFlags & TransformFlags.ContainsLexicalThisInComputedPropertyName) { + // A computed property name containing `this` might need to be rewritten, + // so propagate the ContainsLexicalThis flag upward. transformFlags |= TransformFlags.ContainsLexicalThis; } break; @@ -2266,6 +2273,8 @@ namespace ts { transformFlags |= TransformFlags.AssertTypeScript; } if (subtreeFlags & TransformFlags.ContainsLexicalThisInComputedPropertyName) { + // A computed property name containing `this` might need to be rewritten, + // so propagate the ContainsLexicalThis flag upward. transformFlags |= TransformFlags.ContainsLexicalThis; } @@ -2285,6 +2294,8 @@ namespace ts { transformFlags |= TransformFlags.AssertTypeScript; } if (subtreeFlags & TransformFlags.ContainsLexicalThisInComputedPropertyName) { + // A computed property name containing `this` might need to be rewritten, + // so propagate the ContainsLexicalThis flag upward. transformFlags |= TransformFlags.ContainsLexicalThis; }