diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 5de2bd87e63..41a16fff3eb 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -31,44 +31,75 @@ Your pull request should: ## Running the Tests To run all tests, invoke the runtests target using jake: -`jake runtests` +```Shell +jake runtests +``` This run will all tests; to run only a specific subset of tests, use: -`jake runtests tests=` +```Shell +jake runtests tests= +``` e.g. to run all compiler baseline tests: -`jake runtests tests=compiler` +```Shell +jake runtests tests=compiler +``` -or to run specifc test:tests\cases\compiler\2dArrays.ts +or to run specifc test: `tests\cases\compiler\2dArrays.ts` -`jake runtests tests=2dArrays` +```Shell +jake runtests tests=2dArrays +``` ## Adding a Test -To add a new testcase, simply place a .ts file in tests\cases\compiler containing code that exemplifies the bugfix or change you are making. +To add a new testcase, simply place a `.ts` file in `tests\cases\compiler` containing code that exemplifies the bugfix or change you are making. -These files support metadata tags in the format // @name: value . The supported names and values are: +These files support metadata tags in the format `// @metaDataName: value`. The supported names and values are: -* comments, sourcemap, noimplicitany, declaration: true or false (corresponds to the compiler command-line options of the same name) -* target: ES3 or ES5 (same as compiler) -* out, outDir: path (same as compiler) -* module: local, commonjs, or amd (local corresponds to not passing any compiler --module flag) +* `comments`, `sourcemap`, `noimplicitany`, `declaration`: true or false (corresponds to the compiler command-line options of the same name) +* `target`: ES3 or ES5 (same as compiler) +* `out`, outDir: path (same as compiler) +* `module`: local, commonjs, or amd (local corresponds to not passing any compiler --module flag) +* `fileName`: path + * These tags delimit sections of a file to be used as separate compilation units. They are useful for tests relating to modules. See below for examples. -**Note** that if you have a test corresponding to a specific spec compliance item, you can place it in tests\cases\conformance in an appropriately-named subfolder. +**Note** that if you have a test corresponding to a specific spec compliance item, you can place it in `tests\cases\conformance` in an appropriately-named subfolder. **Note** that filenames here must be distinct from all other compiler testcase names, so you may have to work a bit to find a unique name if it's something common. +### Tests for multiple files + +When one needs to test for scenarios which require multiple files, it is useful to use the `fileName` metadata tag as such: + +```TypeScript +// @fileName: file1.ts +export function f() { +} + +// @fileName: file2.ts +import { f as g } from "file1"; + +var x = g(); +``` + +One can also write a project test, but it is slightly more involved. + ## Managing the Baselines -Compiler testcases generate baselines that track the emitted .js, the errors produced by the compiler, and the type of each expression in the file. Additionally, some testcases opt in to baselining the source map output. +Compiler testcases generate baselines that track the emitted `.js`, the errors produced by the compiler, and the type of each expression in the file. Additionally, some testcases opt in to baselining the source map output. When a change in the baselines is detected, the test will fail. To inspect changes vs the expected baselines, use -`jake diff` +```Shell +jake diff +``` After verifying that the changes in the baselines are correct, run -`jake baseline-accept` +```Shell +jake baseline-accept +``` -to establish the new baselines as the desired behavior. This will change the files in tests\baselines\reference, which should be included as part of your commit. It's important to carefully validate changes in the baselines. +to establish the new baselines as the desired behavior. This will change the files in `tests\baselines\reference`, which should be included as part of your commit. It's important to carefully validate changes in the baselines. **Note** that baseline-accept should only be run after a full test run! Accepting baselines after running a subset of tests will delete baseline files for the tests that didn't run. diff --git a/Jakefile.js b/Jakefile.js index afe0ffd3ce5..d447ac660ef 100644 --- a/Jakefile.js +++ b/Jakefile.js @@ -129,7 +129,8 @@ var harnessSources = [ "services/preProcessFile.ts", "services/patternMatcher.ts", "versionCache.ts", - "convertToBase64.ts" + "convertToBase64.ts", + "transpile.ts" ].map(function (f) { return path.join(unittestsDirectory, f); })).concat([ @@ -506,7 +507,7 @@ function cleanTestDirs() { // used to pass data from jake command line directly to run.js function writeTestConfigFile(tests, testConfigFile) { console.log('Running test(s): ' + tests); - var testConfigContents = '{\n' + '\ttest: [\'' + tests + '\']\n}'; + var testConfigContents = JSON.stringify({ test: [tests]}); fs.writeFileSync('test.config', testConfigContents); } @@ -689,4 +690,4 @@ task('tsc-instrumented', [loggedIOJsPath, instrumenterJsPath, tscFile], function complete(); }); ex.run(); -}, { async: true }); +}, { async: true }); diff --git a/README.md b/README.md index ee32547ca95..31b1a21f64d 100644 --- a/README.md +++ b/README.md @@ -5,8 +5,8 @@ [![Downloads](http://img.shields.io/npm/dm/TypeScript.svg)](https://npmjs.org/package/typescript) # TypeScript - -[![Join the chat at https://gitter.im/Microsoft/TypeScript](https://badges.gitter.im/Join%20Chat.svg)](https://gitter.im/Microsoft/TypeScript?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge) + +[![Join the chat at https://gitter.im/Microsoft/TypeScript](https://badges.gitter.im/Join%20Chat.svg)](https://gitter.im/Microsoft/TypeScript?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge) [TypeScript](http://www.typescriptlang.org/) is a language for application-scale JavaScript. TypeScript adds optional types, classes, and modules to JavaScript. TypeScript supports tools for large-scale JavaScript applications for any browser, for any host, on any OS. TypeScript compiles to readable, standards-based JavaScript. Try it out at the [playground](http://www.typescriptlang.org/Playground), and stay up to date via [our blog](http://blogs.msdn.com/typescript) and [twitter account](https://twitter.com/typescriptlang). @@ -31,7 +31,7 @@ There are many ways to [contribute](https://github.com/Microsoft/TypeScript/blob ## Building -In order to build the TypeScript compiler, ensure that you have [Git](http://git-scm.com/downloads) and [Node.js](http://nodejs.org/) installed. Note that you need to have autocrlf off as we track whitespace changes (`git config --global core.autocrlf false`). +In order to build the TypeScript compiler, ensure that you have [Git](http://git-scm.com/downloads) and [Node.js](http://nodejs.org/) installed. Clone a copy of the repo: diff --git a/bin/lib.d.ts b/bin/lib.d.ts index 7497c306161..0e1176377b5 100644 --- a/bin/lib.d.ts +++ b/bin/lib.d.ts @@ -11335,10 +11335,10 @@ declare var MediaQueryList: { interface MediaSource extends EventTarget { activeSourceBuffers: SourceBufferList; duration: number; - readyState: string; + readyState: number; sourceBuffers: SourceBufferList; addSourceBuffer(type: string): SourceBuffer; - endOfStream(error?: string): void; + endOfStream(error?: number): void; removeSourceBuffer(sourceBuffer: SourceBuffer): void; } @@ -12067,7 +12067,7 @@ declare var PopStateEvent: { interface Position { coords: Coordinates; - timestamp: Date; + timestamp: number; } declare var Position: { @@ -14748,9 +14748,17 @@ interface WebGLRenderingContext { stencilMaskSeparate(face: number, mask: number): void; stencilOp(fail: number, zfail: number, zpass: number): void; stencilOpSeparate(face: number, fail: number, zfail: number, zpass: number): void; + texImage2D(target: number, level: number, internalformat: number, width: number, height: number, border: number, format: number, type: number, pixels: ArrayBufferView): void; + texImage2D(target: number, level: number, internalformat: number, format: number, type: number, image: HTMLImageElement): void; + texImage2D(target: number, level: number, internalformat: number, format: number, type: number, canvas: HTMLCanvasElement): void; + texImage2D(target: number, level: number, internalformat: number, format: number, type: number, video: HTMLVideoElement): void; texImage2D(target: number, level: number, internalformat: number, format: number, type: number, pixels: ImageData): void; texParameterf(target: number, pname: number, param: number): void; texParameteri(target: number, pname: number, param: number): void; + texSubImage2D(target: number, level: number, xoffset: number, yoffset: number, width: number, height: number, format: number, type: number, pixels: ArrayBufferView): void; + texSubImage2D(target: number, level: number, xoffset: number, yoffset: number, format: number, type: number, image: HTMLImageElement): void; + texSubImage2D(target: number, level: number, xoffset: number, yoffset: number, format: number, type: number, canvas: HTMLCanvasElement): void; + texSubImage2D(target: number, level: number, xoffset: number, yoffset: number, format: number, type: number, video: HTMLVideoElement): void; texSubImage2D(target: number, level: number, xoffset: number, yoffset: number, format: number, type: number, pixels: ImageData): void; uniform1f(location: WebGLUniformLocation, x: number): void; uniform1fv(location: WebGLUniformLocation, v: any): void; @@ -15990,10 +15998,11 @@ interface DocumentEvent { createEvent(eventInterface:"AriaRequestEvent"): AriaRequestEvent; createEvent(eventInterface:"AudioProcessingEvent"): AudioProcessingEvent; createEvent(eventInterface:"BeforeUnloadEvent"): BeforeUnloadEvent; + createEvent(eventInterface:"ClipboardEvent"): ClipboardEvent; createEvent(eventInterface:"CloseEvent"): CloseEvent; createEvent(eventInterface:"CommandEvent"): CommandEvent; createEvent(eventInterface:"CompositionEvent"): CompositionEvent; - createEvent(eventInterface: "CustomEvent"): CustomEvent; + createEvent(eventInterface:"CustomEvent"): CustomEvent; createEvent(eventInterface:"DeviceMotionEvent"): DeviceMotionEvent; createEvent(eventInterface:"DeviceOrientationEvent"): DeviceOrientationEvent; createEvent(eventInterface:"DragEvent"): DragEvent; @@ -16016,8 +16025,6 @@ interface DocumentEvent { createEvent(eventInterface:"MouseEvent"): MouseEvent; createEvent(eventInterface:"MouseEvents"): MouseEvent; createEvent(eventInterface:"MouseWheelEvent"): MouseWheelEvent; - createEvent(eventInterface:"MSGestureEvent"): MSGestureEvent; - createEvent(eventInterface:"MSPointerEvent"): MSPointerEvent; createEvent(eventInterface:"MutationEvent"): MutationEvent; createEvent(eventInterface:"MutationEvents"): MutationEvent; createEvent(eventInterface:"NavigationCompletedEvent"): NavigationCompletedEvent; @@ -16630,6 +16637,7 @@ declare function addEventListener(type: "volumechange", listener: (ev: Event) => declare function addEventListener(type: "waiting", listener: (ev: Event) => any, useCapture?: boolean): void; declare function addEventListener(type: "wheel", listener: (ev: WheelEvent) => any, useCapture?: boolean): void; declare function addEventListener(type: string, listener: EventListenerOrEventListenerObject, useCapture?: boolean): void; + ///////////////////////////// /// WorkerGlobalScope APIs ///////////////////////////// diff --git a/bin/lib.dom.d.ts b/bin/lib.dom.d.ts index 1df0e2f736c..7638f0fba4c 100644 --- a/bin/lib.dom.d.ts +++ b/bin/lib.dom.d.ts @@ -10165,10 +10165,10 @@ declare var MediaQueryList: { interface MediaSource extends EventTarget { activeSourceBuffers: SourceBufferList; duration: number; - readyState: string; + readyState: number; sourceBuffers: SourceBufferList; addSourceBuffer(type: string): SourceBuffer; - endOfStream(error?: string): void; + endOfStream(error?: number): void; removeSourceBuffer(sourceBuffer: SourceBuffer): void; } @@ -10897,7 +10897,7 @@ declare var PopStateEvent: { interface Position { coords: Coordinates; - timestamp: Date; + timestamp: number; } declare var Position: { @@ -13578,9 +13578,17 @@ interface WebGLRenderingContext { stencilMaskSeparate(face: number, mask: number): void; stencilOp(fail: number, zfail: number, zpass: number): void; stencilOpSeparate(face: number, fail: number, zfail: number, zpass: number): void; + texImage2D(target: number, level: number, internalformat: number, width: number, height: number, border: number, format: number, type: number, pixels: ArrayBufferView): void; + texImage2D(target: number, level: number, internalformat: number, format: number, type: number, image: HTMLImageElement): void; + texImage2D(target: number, level: number, internalformat: number, format: number, type: number, canvas: HTMLCanvasElement): void; + texImage2D(target: number, level: number, internalformat: number, format: number, type: number, video: HTMLVideoElement): void; texImage2D(target: number, level: number, internalformat: number, format: number, type: number, pixels: ImageData): void; texParameterf(target: number, pname: number, param: number): void; texParameteri(target: number, pname: number, param: number): void; + texSubImage2D(target: number, level: number, xoffset: number, yoffset: number, width: number, height: number, format: number, type: number, pixels: ArrayBufferView): void; + texSubImage2D(target: number, level: number, xoffset: number, yoffset: number, format: number, type: number, image: HTMLImageElement): void; + texSubImage2D(target: number, level: number, xoffset: number, yoffset: number, format: number, type: number, canvas: HTMLCanvasElement): void; + texSubImage2D(target: number, level: number, xoffset: number, yoffset: number, format: number, type: number, video: HTMLVideoElement): void; texSubImage2D(target: number, level: number, xoffset: number, yoffset: number, format: number, type: number, pixels: ImageData): void; uniform1f(location: WebGLUniformLocation, x: number): void; uniform1fv(location: WebGLUniformLocation, v: any): void; @@ -14820,10 +14828,11 @@ interface DocumentEvent { createEvent(eventInterface:"AriaRequestEvent"): AriaRequestEvent; createEvent(eventInterface:"AudioProcessingEvent"): AudioProcessingEvent; createEvent(eventInterface:"BeforeUnloadEvent"): BeforeUnloadEvent; + createEvent(eventInterface:"ClipboardEvent"): ClipboardEvent; createEvent(eventInterface:"CloseEvent"): CloseEvent; createEvent(eventInterface:"CommandEvent"): CommandEvent; createEvent(eventInterface:"CompositionEvent"): CompositionEvent; - createEvent(eventInterface: "CustomEvent"): CustomEvent; + createEvent(eventInterface:"CustomEvent"): CustomEvent; createEvent(eventInterface:"DeviceMotionEvent"): DeviceMotionEvent; createEvent(eventInterface:"DeviceOrientationEvent"): DeviceOrientationEvent; createEvent(eventInterface:"DragEvent"): DragEvent; @@ -14846,8 +14855,6 @@ interface DocumentEvent { createEvent(eventInterface:"MouseEvent"): MouseEvent; createEvent(eventInterface:"MouseEvents"): MouseEvent; createEvent(eventInterface:"MouseWheelEvent"): MouseWheelEvent; - createEvent(eventInterface:"MSGestureEvent"): MSGestureEvent; - createEvent(eventInterface:"MSPointerEvent"): MSPointerEvent; createEvent(eventInterface:"MutationEvent"): MutationEvent; createEvent(eventInterface:"MutationEvents"): MutationEvent; createEvent(eventInterface:"NavigationCompletedEvent"): NavigationCompletedEvent; @@ -15459,4 +15466,4 @@ declare function addEventListener(type: "unload", listener: (ev: Event) => any, declare function addEventListener(type: "volumechange", listener: (ev: Event) => any, useCapture?: boolean): void; declare function addEventListener(type: "waiting", listener: (ev: Event) => any, useCapture?: boolean): void; declare function addEventListener(type: "wheel", listener: (ev: WheelEvent) => any, useCapture?: boolean): void; -declare function addEventListener(type: string, listener: EventListenerOrEventListenerObject, useCapture?: boolean): void; \ No newline at end of file +declare function addEventListener(type: string, listener: EventListenerOrEventListenerObject, useCapture?: boolean): void; diff --git a/bin/lib.es6.d.ts b/bin/lib.es6.d.ts index b91bd34cf5d..2326b43207d 100644 --- a/bin/lib.es6.d.ts +++ b/bin/lib.es6.d.ts @@ -12713,10 +12713,10 @@ declare var MediaQueryList: { interface MediaSource extends EventTarget { activeSourceBuffers: SourceBufferList; duration: number; - readyState: string; + readyState: number; sourceBuffers: SourceBufferList; addSourceBuffer(type: string): SourceBuffer; - endOfStream(error?: string): void; + endOfStream(error?: number): void; removeSourceBuffer(sourceBuffer: SourceBuffer): void; } @@ -13445,7 +13445,7 @@ declare var PopStateEvent: { interface Position { coords: Coordinates; - timestamp: Date; + timestamp: number; } declare var Position: { @@ -16126,9 +16126,17 @@ interface WebGLRenderingContext { stencilMaskSeparate(face: number, mask: number): void; stencilOp(fail: number, zfail: number, zpass: number): void; stencilOpSeparate(face: number, fail: number, zfail: number, zpass: number): void; + texImage2D(target: number, level: number, internalformat: number, width: number, height: number, border: number, format: number, type: number, pixels: ArrayBufferView): void; + texImage2D(target: number, level: number, internalformat: number, format: number, type: number, image: HTMLImageElement): void; + texImage2D(target: number, level: number, internalformat: number, format: number, type: number, canvas: HTMLCanvasElement): void; + texImage2D(target: number, level: number, internalformat: number, format: number, type: number, video: HTMLVideoElement): void; texImage2D(target: number, level: number, internalformat: number, format: number, type: number, pixels: ImageData): void; texParameterf(target: number, pname: number, param: number): void; texParameteri(target: number, pname: number, param: number): void; + texSubImage2D(target: number, level: number, xoffset: number, yoffset: number, width: number, height: number, format: number, type: number, pixels: ArrayBufferView): void; + texSubImage2D(target: number, level: number, xoffset: number, yoffset: number, format: number, type: number, image: HTMLImageElement): void; + texSubImage2D(target: number, level: number, xoffset: number, yoffset: number, format: number, type: number, canvas: HTMLCanvasElement): void; + texSubImage2D(target: number, level: number, xoffset: number, yoffset: number, format: number, type: number, video: HTMLVideoElement): void; texSubImage2D(target: number, level: number, xoffset: number, yoffset: number, format: number, type: number, pixels: ImageData): void; uniform1f(location: WebGLUniformLocation, x: number): void; uniform1fv(location: WebGLUniformLocation, v: any): void; @@ -17368,10 +17376,11 @@ interface DocumentEvent { createEvent(eventInterface:"AriaRequestEvent"): AriaRequestEvent; createEvent(eventInterface:"AudioProcessingEvent"): AudioProcessingEvent; createEvent(eventInterface:"BeforeUnloadEvent"): BeforeUnloadEvent; + createEvent(eventInterface:"ClipboardEvent"): ClipboardEvent; createEvent(eventInterface:"CloseEvent"): CloseEvent; createEvent(eventInterface:"CommandEvent"): CommandEvent; createEvent(eventInterface:"CompositionEvent"): CompositionEvent; - createEvent(eventInterface: "CustomEvent"): CustomEvent; + createEvent(eventInterface:"CustomEvent"): CustomEvent; createEvent(eventInterface:"DeviceMotionEvent"): DeviceMotionEvent; createEvent(eventInterface:"DeviceOrientationEvent"): DeviceOrientationEvent; createEvent(eventInterface:"DragEvent"): DragEvent; @@ -17394,8 +17403,6 @@ interface DocumentEvent { createEvent(eventInterface:"MouseEvent"): MouseEvent; createEvent(eventInterface:"MouseEvents"): MouseEvent; createEvent(eventInterface:"MouseWheelEvent"): MouseWheelEvent; - createEvent(eventInterface:"MSGestureEvent"): MSGestureEvent; - createEvent(eventInterface:"MSPointerEvent"): MSPointerEvent; createEvent(eventInterface:"MutationEvent"): MutationEvent; createEvent(eventInterface:"MutationEvents"): MutationEvent; createEvent(eventInterface:"NavigationCompletedEvent"): NavigationCompletedEvent; @@ -18008,6 +18015,7 @@ declare function addEventListener(type: "volumechange", listener: (ev: Event) => declare function addEventListener(type: "waiting", listener: (ev: Event) => any, useCapture?: boolean): void; declare function addEventListener(type: "wheel", listener: (ev: WheelEvent) => any, useCapture?: boolean): void; declare function addEventListener(type: string, listener: EventListenerOrEventListenerObject, useCapture?: boolean): void; + ///////////////////////////// /// WorkerGlobalScope APIs ///////////////////////////// diff --git a/bin/tsc.js b/bin/tsc.js index ef13d5d9e31..c55b3be37ba 100644 --- a/bin/tsc.js +++ b/bin/tsc.js @@ -738,6 +738,9 @@ var ts; fileStream.Close(); } } + function getCanonicalPath(path) { + return path.toLowerCase(); + } function getNames(collection) { var result = []; for (var e = new Enumerator(collection); !e.atEnd(); e.moveNext()) { @@ -745,23 +748,28 @@ var ts; } return result.sort(); } - function readDirectory(path, extension) { + function readDirectory(path, extension, exclude) { var result = []; + exclude = ts.map(exclude, function (s) { return getCanonicalPath(ts.combinePaths(path, s)); }); visitDirectory(path); return result; function visitDirectory(path) { var folder = fso.GetFolder(path || "."); var files = getNames(folder.files); for (var _i = 0; _i < files.length; _i++) { - var name_1 = files[_i]; - if (!extension || ts.fileExtensionIs(name_1, extension)) { - result.push(ts.combinePaths(path, name_1)); + var current = files[_i]; + var name_1 = ts.combinePaths(path, current); + if ((!extension || ts.fileExtensionIs(name_1, extension)) && !ts.contains(exclude, getCanonicalPath(name_1))) { + result.push(name_1); } } var subfolders = getNames(folder.subfolders); for (var _a = 0; _a < subfolders.length; _a++) { var current = subfolders[_a]; - visitDirectory(ts.combinePaths(path, current)); + var name_2 = ts.combinePaths(path, current); + if (!ts.contains(exclude, getCanonicalPath(name_2))) { + visitDirectory(name_2); + } } } } @@ -839,8 +847,12 @@ var ts; } _fs.writeFileSync(fileName, data, "utf8"); } - function readDirectory(path, extension) { + function getCanonicalPath(path) { + return useCaseSensitiveFileNames ? path.toLowerCase() : path; + } + function readDirectory(path, extension, exclude) { var result = []; + exclude = ts.map(exclude, function (s) { return getCanonicalPath(ts.combinePaths(path, s)); }); visitDirectory(path); return result; function visitDirectory(path) { @@ -849,14 +861,16 @@ var ts; for (var _i = 0; _i < files.length; _i++) { var current = files[_i]; var name = ts.combinePaths(path, current); - var stat = _fs.statSync(name); - if (stat.isFile()) { - if (!extension || ts.fileExtensionIs(name, extension)) { - result.push(name); + if (!ts.contains(exclude, getCanonicalPath(name))) { + var stat = _fs.statSync(name); + if (stat.isFile()) { + if (!extension || ts.fileExtensionIs(name, extension)) { + result.push(name); + } + } + else if (stat.isDirectory()) { + directories.push(name); } - } - else if (stat.isDirectory()) { - directories.push(name); } } for (var _a = 0; _a < directories.length; _a++) { @@ -1460,7 +1474,7 @@ var ts; Object_literal_s_property_0_implicitly_has_an_1_type: { code: 7018, category: ts.DiagnosticCategory.Error, key: "Object literal's property '{0}' implicitly has an '{1}' type." }, Rest_parameter_0_implicitly_has_an_any_type: { code: 7019, category: ts.DiagnosticCategory.Error, key: "Rest parameter '{0}' implicitly has an 'any[]' type." }, Call_signature_which_lacks_return_type_annotation_implicitly_has_an_any_return_type: { code: 7020, category: ts.DiagnosticCategory.Error, key: "Call signature, which lacks return-type annotation, implicitly has an 'any' return type." }, - _0_implicitly_has_type_any_because_it_is_does_not_have_a_type_annotation_and_is_referenced_directly_or_indirectly_in_its_own_initializer: { code: 7022, category: ts.DiagnosticCategory.Error, key: "'{0}' implicitly has type 'any' because it is does not have a type annotation and is referenced directly or indirectly in its own initializer." }, + _0_implicitly_has_type_any_because_it_does_not_have_a_type_annotation_and_is_referenced_directly_or_indirectly_in_its_own_initializer: { code: 7022, category: ts.DiagnosticCategory.Error, key: "'{0}' implicitly has type 'any' because it does not have a type annotation and is referenced directly or indirectly in its own initializer." }, _0_implicitly_has_return_type_any_because_it_does_not_have_a_return_type_annotation_and_is_referenced_directly_or_indirectly_in_one_of_its_return_expressions: { code: 7023, category: ts.DiagnosticCategory.Error, key: "'{0}' implicitly has return type 'any' because it does not have a return type annotation and is referenced directly or indirectly in one of its return expressions." }, Function_implicitly_has_return_type_any_because_it_does_not_have_a_return_type_annotation_and_is_referenced_directly_or_indirectly_in_one_of_its_return_expressions: { code: 7024, category: ts.DiagnosticCategory.Error, key: "Function implicitly has return type 'any' because it does not have a return type annotation and is referenced directly or indirectly in one of its return expressions." }, Generator_implicitly_has_type_0_because_it_does_not_yield_any_values_Consider_supplying_a_return_type: { code: 7025, category: ts.DiagnosticCategory.Error, key: "Generator implicitly has type '{0}' because it does not yield any values. Consider supplying a return type." }, @@ -1642,9 +1656,9 @@ var ts; } function makeReverseMap(source) { var result = []; - for (var name_2 in source) { - if (source.hasOwnProperty(name_2)) { - result[source[name_2]] = name_2; + for (var name_3 in source) { + if (source.hasOwnProperty(name_3)) { + result[source[name_3]] = name_3; } } return result; @@ -3661,9 +3675,9 @@ var ts; return; default: if (isFunctionLike(node)) { - var name_3 = node.name; - if (name_3 && name_3.kind === 128) { - traverse(name_3.expression); + var name_4 = node.name; + if (name_4 && name_4.kind === 128) { + traverse(name_4.expression); return; } } @@ -4073,8 +4087,8 @@ var ts; return ts.forEach(docComment.tags, function (t) { if (t.kind === 247) { var parameterTag = t; - var name_4 = parameterTag.preParameterName || parameterTag.postParameterName; - if (name_4.text === parameterName) { + var name_5 = parameterTag.preParameterName || parameterTag.postParameterName; + if (name_5.text === parameterName) { return t; } } @@ -4884,6 +4898,21 @@ var ts; return result; } ts.convertToBase64 = convertToBase64; + var carriageReturnLineFeed = "\r\n"; + var lineFeed = "\n"; + function getNewLineCharacter(options) { + if (options.newLine === 0) { + return carriageReturnLineFeed; + } + else if (options.newLine === 1) { + return lineFeed; + } + else if (ts.sys) { + return ts.sys.newLine; + } + return carriageReturnLineFeed; + } + ts.getNewLineCharacter = getNewLineCharacter; })(ts || (ts = {})); var ts; (function (ts) { @@ -8149,8 +8178,8 @@ var ts; return parsePropertyOrMethodDeclaration(fullStart, decorators, modifiers); } if (decorators) { - var name_5 = createMissingNode(65, true, ts.Diagnostics.Declaration_expected); - return parsePropertyDeclaration(fullStart, decorators, modifiers, name_5, undefined); + var name_6 = createMissingNode(65, true, ts.Diagnostics.Declaration_expected); + return parsePropertyDeclaration(fullStart, decorators, modifiers, name_6, undefined); } ts.Debug.fail("Should not have attempted to parse class member declaration."); } @@ -8986,13 +9015,13 @@ var ts; while (true) { skipWhitespace(); var startPos = pos; - var name_6 = scanIdentifier(); - if (!name_6) { + var name_7 = scanIdentifier(); + if (!name_7) { parseErrorAtPosition(startPos, 0, ts.Diagnostics.Identifier_expected); return undefined; } - var typeParameter = createNode(129, name_6.pos); - typeParameter.name = name_6; + var typeParameter = createNode(129, name_7.pos); + typeParameter.name = name_7; finishNode(typeParameter, pos); typeParameters.push(typeParameter); skipWhitespace(); @@ -9386,10 +9415,10 @@ var ts; var stringType = createIntrinsicType(2, "string"); var numberType = createIntrinsicType(4, "number"); var booleanType = createIntrinsicType(8, "boolean"); - var esSymbolType = createIntrinsicType(1048576, "symbol"); + var esSymbolType = createIntrinsicType(2097152, "symbol"); var voidType = createIntrinsicType(16, "void"); - var undefinedType = createIntrinsicType(32 | 262144, "undefined"); - var nullType = createIntrinsicType(64 | 262144, "null"); + var undefinedType = createIntrinsicType(32 | 524288, "undefined"); + var nullType = createIntrinsicType(64 | 524288, "null"); var unknownType = createIntrinsicType(1, "unknown"); var circularType = createIntrinsicType(1, "__circular__"); var emptyObjectType = createAnonymousType(undefined, emptySymbols, emptyArray, emptyArray, undefined, undefined); @@ -9446,7 +9475,7 @@ var ts; }, "symbol": { type: esSymbolType, - flags: 1048576 + flags: 2097152 } }; function getEmitResolver(sourceFile) { @@ -9871,15 +9900,15 @@ var ts; var moduleSymbol = resolveExternalModuleName(node, node.moduleSpecifier); var targetSymbol = resolveESModuleSymbol(moduleSymbol, node.moduleSpecifier); if (targetSymbol) { - var name_7 = specifier.propertyName || specifier.name; - if (name_7.text) { - var symbolFromModule = getExportOfModule(targetSymbol, name_7.text); - var symbolFromVariable = getPropertyOfVariable(targetSymbol, name_7.text); + var name_8 = specifier.propertyName || specifier.name; + if (name_8.text) { + var symbolFromModule = getExportOfModule(targetSymbol, name_8.text); + var symbolFromVariable = getPropertyOfVariable(targetSymbol, name_8.text); var symbol = symbolFromModule && symbolFromVariable ? combineValueAndTypeSymbols(symbolFromVariable, symbolFromModule) : symbolFromModule || symbolFromVariable; if (!symbol) { - error(name_7, ts.Diagnostics.Module_0_has_no_exported_member_1, getFullyQualifiedName(moduleSymbol), ts.declarationNameToString(name_7)); + error(name_8, ts.Diagnostics.Module_0_has_no_exported_member_1, getFullyQualifiedName(moduleSymbol), ts.declarationNameToString(name_8)); } return symbol; } @@ -10481,13 +10510,14 @@ var ts; } return appendParentTypeArgumentsAndSymbolName(symbol); } - function buildTypeDisplay(type, writer, enclosingDeclaration, globalFlags, typeStack) { + function buildTypeDisplay(type, writer, enclosingDeclaration, globalFlags, symbolStack) { var globalFlagsToPass = globalFlags & 16; return writeType(type, globalFlags); function writeType(type, flags) { - if (type.flags & 1048703) { - writer.writeKeyword(!(globalFlags & 16) && - (type.flags & 1) ? "any" : type.intrinsicName); + if (type.flags & 2097279) { + writer.writeKeyword(!(globalFlags & 16) && isTypeAny(type) + ? "any" + : type.intrinsicName); } else if (type.flags & 4096) { writeTypeReference(type, flags); @@ -10584,42 +10614,46 @@ var ts; } } function writeAnonymousType(type, flags) { - if (type.symbol && type.symbol.flags & (32 | 384 | 512)) { - writeTypeofSymbol(type, flags); - } - else if (shouldWriteTypeOfFunctionSymbol()) { - writeTypeofSymbol(type, flags); - } - else if (typeStack && ts.contains(typeStack, type)) { - var typeAlias = getTypeAliasForTypeLiteral(type); - if (typeAlias) { - buildSymbolDisplay(typeAlias, writer, enclosingDeclaration, 793056, 0, flags); + var symbol = type.symbol; + if (symbol) { + if (symbol.flags & (32 | 384 | 512)) { + writeTypeofSymbol(type, flags); + } + else if (shouldWriteTypeOfFunctionSymbol()) { + writeTypeofSymbol(type, flags); + } + else if (ts.contains(symbolStack, symbol)) { + var typeAlias = getTypeAliasForTypeLiteral(type); + if (typeAlias) { + buildSymbolDisplay(typeAlias, writer, enclosingDeclaration, 793056, 0, flags); + } + else { + writeKeyword(writer, 112); + } } else { - writeKeyword(writer, 112); + if (!symbolStack) { + symbolStack = []; + } + symbolStack.push(symbol); + writeLiteralType(type, flags); + symbolStack.pop(); } } else { - if (!typeStack) { - typeStack = []; - } - typeStack.push(type); writeLiteralType(type, flags); - typeStack.pop(); } function shouldWriteTypeOfFunctionSymbol() { - if (type.symbol) { - var isStaticMethodSymbol = !!(type.symbol.flags & 8192 && - ts.forEach(type.symbol.declarations, function (declaration) { return declaration.flags & 128; })); - var isNonLocalFunctionSymbol = !!(type.symbol.flags & 16) && - (type.symbol.parent || - ts.forEach(type.symbol.declarations, function (declaration) { - return declaration.parent.kind === 228 || declaration.parent.kind === 207; - })); - if (isStaticMethodSymbol || isNonLocalFunctionSymbol) { - return !!(flags & 2) || - (typeStack && ts.contains(typeStack, type)); - } + var isStaticMethodSymbol = !!(symbol.flags & 8192 && + ts.forEach(symbol.declarations, function (declaration) { return declaration.flags & 128; })); + var isNonLocalFunctionSymbol = !!(symbol.flags & 16) && + (symbol.parent || + ts.forEach(symbol.declarations, function (declaration) { + return declaration.parent.kind === 228 || declaration.parent.kind === 207; + })); + if (isStaticMethodSymbol || isNonLocalFunctionSymbol) { + return !!(flags & 2) || + (ts.contains(symbolStack, symbol)); } } } @@ -10648,7 +10682,7 @@ var ts; if (flags & 64) { writePunctuation(writer, 16); } - buildSignatureDisplay(resolved.callSignatures[0], writer, enclosingDeclaration, globalFlagsToPass | 8, typeStack); + buildSignatureDisplay(resolved.callSignatures[0], writer, enclosingDeclaration, globalFlagsToPass | 8, symbolStack); if (flags & 64) { writePunctuation(writer, 17); } @@ -10660,7 +10694,7 @@ var ts; } writeKeyword(writer, 88); writeSpace(writer); - buildSignatureDisplay(resolved.constructSignatures[0], writer, enclosingDeclaration, globalFlagsToPass | 8, typeStack); + buildSignatureDisplay(resolved.constructSignatures[0], writer, enclosingDeclaration, globalFlagsToPass | 8, symbolStack); if (flags & 64) { writePunctuation(writer, 17); } @@ -10672,7 +10706,7 @@ var ts; writer.increaseIndent(); for (var _i = 0, _a = resolved.callSignatures; _i < _a.length; _i++) { var signature = _a[_i]; - buildSignatureDisplay(signature, writer, enclosingDeclaration, globalFlagsToPass, typeStack); + buildSignatureDisplay(signature, writer, enclosingDeclaration, globalFlagsToPass, symbolStack); writePunctuation(writer, 22); writer.writeLine(); } @@ -10680,7 +10714,7 @@ var ts; var signature = _c[_b]; writeKeyword(writer, 88); writeSpace(writer); - buildSignatureDisplay(signature, writer, enclosingDeclaration, globalFlagsToPass, typeStack); + buildSignatureDisplay(signature, writer, enclosingDeclaration, globalFlagsToPass, symbolStack); writePunctuation(writer, 22); writer.writeLine(); } @@ -10721,7 +10755,7 @@ var ts; if (p.flags & 536870912) { writePunctuation(writer, 50); } - buildSignatureDisplay(signature, writer, enclosingDeclaration, globalFlagsToPass, typeStack); + buildSignatureDisplay(signature, writer, enclosingDeclaration, globalFlagsToPass, symbolStack); writePunctuation(writer, 22); writer.writeLine(); } @@ -10748,17 +10782,17 @@ var ts; buildDisplayForTypeParametersAndDelimiters(getLocalTypeParametersOfClassOrInterface(symbol), writer, enclosingDeclaraiton, flags); } } - function buildTypeParameterDisplay(tp, writer, enclosingDeclaration, flags, typeStack) { + function buildTypeParameterDisplay(tp, writer, enclosingDeclaration, flags, symbolStack) { appendSymbolNameOnly(tp.symbol, writer); var constraint = getConstraintOfTypeParameter(tp); if (constraint) { writeSpace(writer); writeKeyword(writer, 79); writeSpace(writer); - buildTypeDisplay(constraint, writer, enclosingDeclaration, flags, typeStack); + buildTypeDisplay(constraint, writer, enclosingDeclaration, flags, symbolStack); } } - function buildParameterDisplay(p, writer, enclosingDeclaration, flags, typeStack) { + function buildParameterDisplay(p, writer, enclosingDeclaration, flags, symbolStack) { var parameterNode = p.valueDeclaration; if (ts.isRestParameter(parameterNode)) { writePunctuation(writer, 21); @@ -10769,9 +10803,9 @@ var ts; } writePunctuation(writer, 51); writeSpace(writer); - buildTypeDisplay(getTypeOfSymbol(p), writer, enclosingDeclaration, flags, typeStack); + buildTypeDisplay(getTypeOfSymbol(p), writer, enclosingDeclaration, flags, symbolStack); } - function buildDisplayForTypeParametersAndDelimiters(typeParameters, writer, enclosingDeclaration, flags, typeStack) { + function buildDisplayForTypeParametersAndDelimiters(typeParameters, writer, enclosingDeclaration, flags, symbolStack) { if (typeParameters && typeParameters.length) { writePunctuation(writer, 24); for (var i = 0; i < typeParameters.length; i++) { @@ -10779,12 +10813,12 @@ var ts; writePunctuation(writer, 23); writeSpace(writer); } - buildTypeParameterDisplay(typeParameters[i], writer, enclosingDeclaration, flags, typeStack); + buildTypeParameterDisplay(typeParameters[i], writer, enclosingDeclaration, flags, symbolStack); } writePunctuation(writer, 25); } } - function buildDisplayForTypeArgumentsAndDelimiters(typeParameters, mapper, writer, enclosingDeclaration, flags, typeStack) { + function buildDisplayForTypeArgumentsAndDelimiters(typeParameters, mapper, writer, enclosingDeclaration, flags, symbolStack) { if (typeParameters && typeParameters.length) { writePunctuation(writer, 24); for (var i = 0; i < typeParameters.length; i++) { @@ -10797,18 +10831,18 @@ var ts; writePunctuation(writer, 25); } } - function buildDisplayForParametersAndDelimiters(parameters, writer, enclosingDeclaration, flags, typeStack) { + function buildDisplayForParametersAndDelimiters(parameters, writer, enclosingDeclaration, flags, symbolStack) { writePunctuation(writer, 16); for (var i = 0; i < parameters.length; i++) { if (i > 0) { writePunctuation(writer, 23); writeSpace(writer); } - buildParameterDisplay(parameters[i], writer, enclosingDeclaration, flags, typeStack); + buildParameterDisplay(parameters[i], writer, enclosingDeclaration, flags, symbolStack); } writePunctuation(writer, 17); } - function buildReturnTypeDisplay(signature, writer, enclosingDeclaration, flags, typeStack) { + function buildReturnTypeDisplay(signature, writer, enclosingDeclaration, flags, symbolStack) { if (flags & 8) { writeSpace(writer); writePunctuation(writer, 32); @@ -10817,17 +10851,17 @@ var ts; writePunctuation(writer, 51); } writeSpace(writer); - buildTypeDisplay(getReturnTypeOfSignature(signature), writer, enclosingDeclaration, flags, typeStack); + buildTypeDisplay(getReturnTypeOfSignature(signature), writer, enclosingDeclaration, flags, symbolStack); } - function buildSignatureDisplay(signature, writer, enclosingDeclaration, flags, typeStack) { + function buildSignatureDisplay(signature, writer, enclosingDeclaration, flags, symbolStack) { if (signature.target && (flags & 32)) { buildDisplayForTypeArgumentsAndDelimiters(signature.target.typeParameters, signature.mapper, writer, enclosingDeclaration); } else { - buildDisplayForTypeParametersAndDelimiters(signature.typeParameters, writer, enclosingDeclaration, flags, typeStack); + buildDisplayForTypeParametersAndDelimiters(signature.typeParameters, writer, enclosingDeclaration, flags, symbolStack); } - buildDisplayForParametersAndDelimiters(signature.parameters, writer, enclosingDeclaration, flags, typeStack); - buildReturnTypeDisplay(signature, writer, enclosingDeclaration, flags, typeStack); + buildDisplayForParametersAndDelimiters(signature.parameters, writer, enclosingDeclaration, flags, symbolStack); + buildReturnTypeDisplay(signature, writer, enclosingDeclaration, flags, symbolStack); } return _displayBuilder || (_displayBuilder = { symbolToString: symbolToString, @@ -11021,13 +11055,16 @@ var ts; var prop = getPropertyOfType(type, name); return prop ? getTypeOfSymbol(prop) : undefined; } + function isTypeAny(type) { + return type && (type.flags & 1) !== 0; + } function getTypeForBindingElement(declaration) { var pattern = declaration.parent; var parentType = getTypeForVariableLikeDeclaration(pattern.parent); if (parentType === unknownType) { return unknownType; } - if (!parentType || parentType === anyType) { + if (!parentType || isTypeAny(parentType)) { if (declaration.initializer) { return checkExpressionCached(declaration.initializer); } @@ -11035,19 +11072,19 @@ var ts; } var type; if (pattern.kind === 151) { - var name_8 = declaration.propertyName || declaration.name; - type = getTypeOfPropertyOfType(parentType, name_8.text) || - isNumericLiteralName(name_8.text) && getIndexTypeOfType(parentType, 1) || + var name_9 = declaration.propertyName || declaration.name; + type = getTypeOfPropertyOfType(parentType, name_9.text) || + isNumericLiteralName(name_9.text) && getIndexTypeOfType(parentType, 1) || getIndexTypeOfType(parentType, 0); if (!type) { - error(name_8, ts.Diagnostics.Type_0_has_no_property_1_and_no_string_index_signature, typeToString(parentType), ts.declarationNameToString(name_8)); + error(name_9, ts.Diagnostics.Type_0_has_no_property_1_and_no_string_index_signature, typeToString(parentType), ts.declarationNameToString(name_9)); return unknownType; } } else { var elementType = checkIteratedTypeOrElementType(parentType, pattern, false); if (!declaration.dotDotDotToken) { - if (elementType.flags & 1) { + if (isTypeAny(elementType)) { return elementType; } var propName = "" + ts.indexOf(pattern.elements, declaration); @@ -11192,7 +11229,7 @@ var ts; else { type = anyType; if (compilerOptions.noImplicitAny) { - error(symbol.valueDeclaration, ts.Diagnostics._0_implicitly_has_type_any_because_it_is_does_not_have_a_type_annotation_and_is_referenced_directly_or_indirectly_in_its_own_initializer, symbolToString(symbol)); + error(symbol.valueDeclaration, ts.Diagnostics._0_implicitly_has_type_any_because_it_does_not_have_a_type_annotation_and_is_referenced_directly_or_indirectly_in_its_own_initializer, symbolToString(symbol)); } } } @@ -11802,7 +11839,7 @@ var ts; else if (type.flags & 8) { type = globalBooleanType; } - else if (type.flags & 1048576) { + else if (type.flags & 2097152) { type = globalESSymbolType; } return type; @@ -12059,7 +12096,7 @@ var ts; function getOrCreateTypeFromSignature(signature) { if (!signature.isolatedSignatureType) { var isConstructor = signature.declaration.kind === 136 || signature.declaration.kind === 140; - var type = createObjectType(32768 | 65536); + var type = createObjectType(32768 | 131072); type.members = emptySymbols; type.properties = emptyArray; type.callSignatures = !isConstructor ? [signature] : emptyArray; @@ -12133,7 +12170,7 @@ var ts; var type = types[_i]; result |= type.flags; } - return result & 786432; + return result & 1572864; } function createTypeReference(target, typeArguments) { var id = getTypeListId(typeArguments); @@ -12349,10 +12386,10 @@ var ts; } } } - function containsAnyType(types) { + function containsTypeAny(types) { for (var _i = 0; _i < types.length; _i++) { var type = types[_i]; - if (type.flags & 1) { + if (isTypeAny(type)) { return true; } } @@ -12374,7 +12411,7 @@ var ts; var sortedTypes = []; addTypesToSortedSet(sortedTypes, types); if (noSubtypeReduction) { - if (containsAnyType(sortedTypes)) { + if (containsTypeAny(sortedTypes)) { return anyType; } removeAllButLast(sortedTypes, undefinedType); @@ -12588,16 +12625,7 @@ var ts; return result; } function instantiateAnonymousType(type, mapper) { - if (mapper.mappings) { - var cached = mapper.mappings[type.id]; - if (cached) { - return cached; - } - } - else { - mapper.mappings = {}; - } - var result = createObjectType(32768, type.symbol); + var result = createObjectType(32768 | 65536, type.symbol); result.properties = instantiateList(getPropertiesOfObjectType(type), mapper, instantiateSymbol); result.members = createSymbolTable(result.properties); result.callSignatures = instantiateList(getSignaturesOfType(type, 0), mapper, instantiateSignature); @@ -12608,7 +12636,6 @@ var ts; result.stringIndexType = instantiateType(stringIndexType, mapper); if (numberIndexType) result.numberIndexType = instantiateType(numberIndexType, mapper); - mapper.mappings[type.id] = result; return result; } function instantiateType(type, mapper) { @@ -12735,7 +12762,7 @@ var ts; if (source === target) return -1; if (relation !== identityRelation) { - if (target.flags & 1) + if (isTypeAny(target)) return -1; if (source === undefinedType) return -1; @@ -12746,7 +12773,7 @@ var ts; if (source.flags & 256 && target === stringType) return -1; if (relation === assignableRelation) { - if (source.flags & 1) + if (isTypeAny(source)) return -1; if (source === numberType && target.flags & 128) return -1; @@ -12964,12 +12991,12 @@ var ts; return result; } function isDeeplyNestedGeneric(type, stack) { - if (type.flags & 4096 && depth >= 10) { - var target_1 = type.target; + if (type.flags & (4096 | 65536) && depth >= 10) { + var symbol = type.symbol; var count = 0; for (var i = 0; i < depth; i++) { var t = stack[i]; - if (t.flags & 4096 && t.target === target_1) { + if (t.flags & (4096 | 65536) && t.symbol === symbol) { count++; if (count >= 10) return true; @@ -12984,7 +13011,7 @@ var ts; } var result = -1; var properties = getPropertiesOfObjectType(target); - var requireOptionalProperties = relation === subtypeRelation && !(source.flags & 131072); + var requireOptionalProperties = relation === subtypeRelation && !(source.flags & 262144); for (var _i = 0; _i < properties.length; _i++) { var targetProp = properties[_i]; var sourceProp = getPropertyOfType(source, targetProp.name); @@ -13083,11 +13110,11 @@ var ts; var saveErrorInfo = errorInfo; outer: for (var _i = 0; _i < targetSignatures.length; _i++) { var t = targetSignatures[_i]; - if (!t.hasStringLiterals || target.flags & 65536) { + if (!t.hasStringLiterals || target.flags & 131072) { var localErrors = reportErrors; for (var _a = 0; _a < sourceSignatures.length; _a++) { var s = sourceSignatures[_a]; - if (!s.hasStringLiterals || source.flags & 65536) { + if (!s.hasStringLiterals || source.flags & 131072) { var related = signatureRelatedTo(s, t, localErrors); if (related) { result &= related; @@ -13379,11 +13406,11 @@ var ts; return createAnonymousType(type.symbol, members, emptyArray, emptyArray, stringIndexType, numberIndexType); } function getWidenedType(type) { - if (type.flags & 786432) { + if (type.flags & 1572864) { if (type.flags & (32 | 64)) { return anyType; } - if (type.flags & 131072) { + if (type.flags & 262144) { return getWidenedTypeOfObjectLiteral(type); } if (type.flags & 16384) { @@ -13408,11 +13435,11 @@ var ts; if (isArrayType(type)) { return reportWideningErrorsInType(type.typeArguments[0]); } - if (type.flags & 131072) { + if (type.flags & 262144) { var errorReported = false; ts.forEach(getPropertiesOfObjectType(type), function (p) { var t = getTypeOfSymbol(p); - if (t.flags & 262144) { + if (t.flags & 524288) { if (!reportWideningErrorsInType(t)) { error(p.valueDeclaration, ts.Diagnostics.Object_literal_s_property_0_implicitly_has_an_1_type, p.name, typeToString(getWidenedType(t))); } @@ -13455,7 +13482,7 @@ var ts; error(declaration, diagnostic, ts.declarationNameToString(declaration.name), typeAsString); } function reportErrorsFromWidening(declaration, type) { - if (produceDiagnostics && compilerOptions.noImplicitAny && type.flags & 262144) { + if (produceDiagnostics && compilerOptions.noImplicitAny && type.flags & 524288) { if (!reportWideningErrorsInType(type)) { reportImplicitAnyError(declaration, type); } @@ -13516,11 +13543,11 @@ var ts; } function isWithinDepthLimit(type, stack) { if (depth >= 5) { - var target_2 = type.target; + var target_1 = type.target; var count = 0; for (var i = 0; i < depth; i++) { var t = stack[i]; - if (t.flags & 4096 && t.target === target_2) { + if (t.flags & 4096 && t.target === target_1) { count++; } } @@ -13816,47 +13843,49 @@ var ts; } function getNarrowedTypeOfSymbol(symbol, node) { var type = getTypeOfSymbol(symbol); - if (node && symbol.flags & 3 && type.flags & (1 | 48128 | 16384 | 512)) { - loop: while (node.parent) { - var child = node; - node = node.parent; - var narrowedType = type; - switch (node.kind) { - case 184: - if (child !== node.expression) { - narrowedType = narrowType(type, node.expression, child === node.thenStatement); - } - break; - case 171: - if (child !== node.condition) { - narrowedType = narrowType(type, node.condition, child === node.whenTrue); - } - break; - case 170: - if (child === node.right) { - if (node.operatorToken.kind === 48) { - narrowedType = narrowType(type, node.left, true); + if (node && symbol.flags & 3) { + if (isTypeAny(type) || type.flags & (48128 | 16384 | 512)) { + loop: while (node.parent) { + var child = node; + node = node.parent; + var narrowedType = type; + switch (node.kind) { + case 184: + if (child !== node.expression) { + narrowedType = narrowType(type, node.expression, child === node.thenStatement); } - else if (node.operatorToken.kind === 49) { - narrowedType = narrowType(type, node.left, false); + break; + case 171: + if (child !== node.condition) { + narrowedType = narrowType(type, node.condition, child === node.whenTrue); } - } - break; - case 228: - case 206: - case 201: - case 135: - case 134: - case 137: - case 138: - case 136: - break loop; - } - if (narrowedType !== type) { - if (isVariableAssignedWithin(symbol, node)) { - break; + break; + case 170: + if (child === node.right) { + if (node.operatorToken.kind === 48) { + narrowedType = narrowType(type, node.left, true); + } + else if (node.operatorToken.kind === 49) { + narrowedType = narrowType(type, node.left, false); + } + } + break; + case 228: + case 206: + case 201: + case 135: + case 134: + case 137: + case 138: + case 136: + break loop; + } + if (narrowedType !== type) { + if (isVariableAssignedWithin(symbol, node)) { + break; + } + type = narrowedType; } - type = narrowedType; } } } @@ -13876,7 +13905,7 @@ var ts; } if (assumeTrue) { if (!typeInfo) { - return removeTypesFromUnionType(type, 258 | 132 | 8 | 1048576, true, false); + return removeTypesFromUnionType(type, 258 | 132 | 8 | 2097152, true, false); } if (isTypeSubtypeOf(typeInfo.type, type)) { return typeInfo.type; @@ -13913,7 +13942,7 @@ var ts; } } function narrowTypeByInstanceof(type, expr, assumeTrue) { - if (type.flags & 1 || !assumeTrue || expr.left.kind !== 65 || getResolvedSymbol(expr.left) !== symbol) { + if (isTypeAny(type) || !assumeTrue || expr.left.kind !== 65 || getResolvedSymbol(expr.left) !== symbol) { return type; } var rightType = checkExpression(expr.right); @@ -13924,7 +13953,7 @@ var ts; var prototypeProperty = getPropertyOfType(rightType, "prototype"); if (prototypeProperty) { var prototypePropertyType = getTypeOfSymbol(prototypeProperty); - if (prototypePropertyType !== anyType) { + if (!isTypeAny(prototypePropertyType)) { targetType = prototypePropertyType; } } @@ -14495,7 +14524,10 @@ var ts; return name.kind === 128 ? isNumericComputedName(name) : isNumericLiteralName(name.text); } function isNumericComputedName(name) { - return allConstituentTypesHaveKind(checkComputedPropertyName(name), 1 | 132); + return isTypeAnyOrAllConstituentTypesHaveKind(checkComputedPropertyName(name), 132); + } + function isTypeAnyOrAllConstituentTypesHaveKind(type, kind) { + return isTypeAny(type) || allConstituentTypesHaveKind(type, kind); } function isNumericLiteralName(name) { return (+name).toString() === name; @@ -14504,7 +14536,7 @@ var ts; var links = getNodeLinks(node.expression); if (!links.resolvedType) { links.resolvedType = checkExpression(node.expression); - if (!allConstituentTypesHaveKind(links.resolvedType, 1 | 132 | 258 | 1048576)) { + if (!isTypeAnyOrAllConstituentTypesHaveKind(links.resolvedType, 132 | 258 | 2097152)) { error(node, ts.Diagnostics.A_computed_property_name_must_be_of_type_string_number_symbol_or_any); } else { @@ -14559,7 +14591,7 @@ var ts; var stringIndexType = getIndexType(0); var numberIndexType = getIndexType(1); var result = createAnonymousType(node.symbol, propertiesTable, emptyArray, emptyArray, stringIndexType, numberIndexType); - result.flags |= 131072 | 524288 | (typeFlags & 262144); + result.flags |= 262144 | 1048576 | (typeFlags & 524288); return result; function getIndexType(kind) { if (contextualType && contextualTypeHasIndexSignature(contextualType, kind)) { @@ -14622,39 +14654,37 @@ var ts; } function checkPropertyAccessExpressionOrQualifiedName(node, left, right) { var type = checkExpressionOrQualifiedName(left); - if (type === unknownType) + if (isTypeAny(type)) { return type; - if (type !== anyType) { - var apparentType = getApparentType(getWidenedType(type)); - if (apparentType === unknownType) { - return unknownType; - } - var prop = getPropertyOfType(apparentType, right.text); - if (!prop) { - if (right.text) { - error(right, ts.Diagnostics.Property_0_does_not_exist_on_type_1, ts.declarationNameToString(right), typeToString(type)); - } - return unknownType; - } - getNodeLinks(node).resolvedSymbol = prop; - if (prop.parent && prop.parent.flags & 32) { - if (left.kind === 91 && getDeclarationKindFromSymbol(prop) !== 135) { - error(right, ts.Diagnostics.Only_public_and_protected_methods_of_the_base_class_are_accessible_via_the_super_keyword); - } - else { - checkClassPropertyAccess(node, left, type, prop); - } - } - return getTypeOfSymbol(prop); } - return anyType; + var apparentType = getApparentType(getWidenedType(type)); + if (apparentType === unknownType) { + return unknownType; + } + var prop = getPropertyOfType(apparentType, right.text); + if (!prop) { + if (right.text) { + error(right, ts.Diagnostics.Property_0_does_not_exist_on_type_1, ts.declarationNameToString(right), typeToString(type)); + } + return unknownType; + } + getNodeLinks(node).resolvedSymbol = prop; + if (prop.parent && prop.parent.flags & 32) { + if (left.kind === 91 && getDeclarationKindFromSymbol(prop) !== 135) { + error(right, ts.Diagnostics.Only_public_and_protected_methods_of_the_base_class_are_accessible_via_the_super_keyword); + } + else { + checkClassPropertyAccess(node, left, type, prop); + } + } + return getTypeOfSymbol(prop); } function isValidPropertyAccess(node, propertyName) { var left = node.kind === 156 ? node.expression : node.left; var type = checkExpressionOrQualifiedName(left); - if (type !== unknownType && type !== anyType) { + if (type !== unknownType && !isTypeAny(type)) { var prop = getPropertyOfType(getWidenedType(type), propertyName); if (prop && prop.parent && prop.parent.flags & 32) { if (left.kind === 91 && getDeclarationKindFromSymbol(prop) !== 135) { @@ -14695,21 +14725,21 @@ var ts; return unknownType; } if (node.argumentExpression) { - var name_9 = getPropertyNameForIndexedAccess(node.argumentExpression, indexType); - if (name_9 !== undefined) { - var prop = getPropertyOfType(objectType, name_9); + var name_10 = getPropertyNameForIndexedAccess(node.argumentExpression, indexType); + if (name_10 !== undefined) { + var prop = getPropertyOfType(objectType, name_10); if (prop) { getNodeLinks(node).resolvedSymbol = prop; return getTypeOfSymbol(prop); } else if (isConstEnum) { - error(node.argumentExpression, ts.Diagnostics.Property_0_does_not_exist_on_const_enum_1, name_9, symbolToString(objectType.symbol)); + error(node.argumentExpression, ts.Diagnostics.Property_0_does_not_exist_on_const_enum_1, name_10, symbolToString(objectType.symbol)); return unknownType; } } } - if (allConstituentTypesHaveKind(indexType, 1 | 258 | 132 | 1048576)) { - if (allConstituentTypesHaveKind(indexType, 1 | 132)) { + if (isTypeAnyOrAllConstituentTypesHaveKind(indexType, 258 | 132 | 2097152)) { + if (isTypeAnyOrAllConstituentTypesHaveKind(indexType, 132)) { var numberIndexType = getIndexTypeOfType(objectType, 1); if (numberIndexType) { return numberIndexType; @@ -14719,7 +14749,7 @@ var ts; if (stringIndexType) { return stringIndexType; } - if (compilerOptions.noImplicitAny && !compilerOptions.suppressImplicitAnyIndexErrors && objectType !== anyType) { + if (compilerOptions.noImplicitAny && !compilerOptions.suppressImplicitAnyIndexErrors && !isTypeAny(objectType)) { error(node, ts.Diagnostics.Index_signature_of_object_type_implicitly_has_an_any_type); } return anyType; @@ -14744,7 +14774,7 @@ var ts; if (!ts.isWellKnownSymbolSyntactically(expression)) { return false; } - if ((expressionType.flags & 1048576) === 0) { + if ((expressionType.flags & 2097152) === 0) { if (reportError) { error(expression, ts.Diagnostics.A_computed_property_name_of_the_form_0_must_be_of_type_symbol, ts.getTextOfNode(expression)); } @@ -15126,8 +15156,8 @@ var ts; } var callSignatures = getSignaturesOfType(apparentType, 0); var constructSignatures = getSignaturesOfType(apparentType, 1); - if (funcType === anyType || (!callSignatures.length && !constructSignatures.length && !(funcType.flags & 16384) && isTypeAssignableTo(funcType, globalFunctionType))) { - if (node.typeArguments) { + if (isTypeAny(funcType) || (!callSignatures.length && !constructSignatures.length && !(funcType.flags & 16384) && isTypeAssignableTo(funcType, globalFunctionType))) { + if (funcType !== unknownType && node.typeArguments) { error(node, ts.Diagnostics.Untyped_function_calls_may_not_accept_type_arguments); } return resolveUntypedCall(node); @@ -15151,16 +15181,16 @@ var ts; } } var expressionType = checkExpression(node.expression); - if (expressionType === anyType) { + expressionType = getApparentType(expressionType); + if (expressionType === unknownType) { + return resolveErrorCall(node); + } + if (isTypeAny(expressionType)) { if (node.typeArguments) { error(node, ts.Diagnostics.Untyped_function_calls_may_not_accept_type_arguments); } return resolveUntypedCall(node); } - expressionType = getApparentType(expressionType); - if (expressionType === unknownType) { - return resolveErrorCall(node); - } var constructSignatures = getSignaturesOfType(expressionType, 1); if (constructSignatures.length) { return resolveCall(node, constructSignatures, candidatesOutArray); @@ -15183,7 +15213,7 @@ var ts; return resolveErrorCall(node); } var callSignatures = getSignaturesOfType(apparentType, 0); - if (tagType === anyType || (!callSignatures.length && !(tagType.flags & 16384) && isTypeAssignableTo(tagType, globalFunctionType))) { + if (isTypeAny(tagType) || (!callSignatures.length && !(tagType.flags & 16384) && isTypeAssignableTo(tagType, globalFunctionType))) { return resolveUntypedCall(node); } if (!callSignatures.length) { @@ -15352,7 +15382,7 @@ var ts; if (!produceDiagnostics) { return; } - if (returnType === voidType || returnType === anyType) { + if (returnType === voidType || isTypeAny(returnType)) { return; } if (ts.nodeIsMissing(func.body) || func.body.kind !== 180) { @@ -15409,6 +15439,9 @@ var ts; checkIfNonVoidFunctionHasReturnExpressionsOrSingleThrowStatment(node, getTypeFromTypeNode(node.type)); } if (node.body) { + if (!node.type) { + getReturnTypeOfSignature(getSignatureFromDeclaration(node)); + } if (node.body.kind === 180) { checkSourceElement(node.body); } @@ -15422,7 +15455,7 @@ var ts; } } function checkArithmeticOperandType(operand, type, diagnostic) { - if (!allConstituentTypesHaveKind(type, 1 | 132)) { + if (!isTypeAnyOrAllConstituentTypesHaveKind(type, 132)) { error(operand, diagnostic); return false; } @@ -15462,8 +15495,8 @@ var ts; var index = n.argumentExpression; var symbol = findSymbol(n.expression); if (symbol && index && index.kind === 8) { - var name_10 = index.text; - var prop = getPropertyOfType(getTypeOfSymbol(symbol), name_10); + var name_11 = index.text; + var prop = getPropertyOfType(getTypeOfSymbol(symbol), name_11); return prop && (prop.flags & 3) !== 0 && (getDeclarationFlagsFromSymbol(prop) & 8192) !== 0; } return false; @@ -15508,7 +15541,7 @@ var ts; case 33: case 34: case 47: - if (someConstituentTypeHasKind(operandType, 1048576)) { + if (someConstituentTypeHasKind(operandType, 2097152)) { error(node.operand, ts.Diagnostics.The_0_operator_cannot_be_applied_to_type_symbol, ts.tokenToString(node.operator)); } return numberType; @@ -15572,19 +15605,19 @@ var ts; return (symbol.flags & 128) !== 0; } function checkInstanceOfExpression(node, leftType, rightType) { - if (allConstituentTypesHaveKind(leftType, 1049086)) { + if (allConstituentTypesHaveKind(leftType, 2097662)) { error(node.left, ts.Diagnostics.The_left_hand_side_of_an_instanceof_expression_must_be_of_type_any_an_object_type_or_a_type_parameter); } - if (!(rightType.flags & 1 || isTypeSubtypeOf(rightType, globalFunctionType))) { + if (!(isTypeAny(rightType) || isTypeSubtypeOf(rightType, globalFunctionType))) { error(node.right, ts.Diagnostics.The_right_hand_side_of_an_instanceof_expression_must_be_of_type_any_or_of_a_type_assignable_to_the_Function_interface_type); } return booleanType; } function checkInExpression(node, leftType, rightType) { - if (!allConstituentTypesHaveKind(leftType, 1 | 258 | 132 | 1048576)) { + if (!isTypeAnyOrAllConstituentTypesHaveKind(leftType, 258 | 132 | 2097152)) { error(node.left, ts.Diagnostics.The_left_hand_side_of_an_in_expression_must_be_of_type_any_string_number_or_symbol); } - if (!allConstituentTypesHaveKind(rightType, 1 | 48128 | 512)) { + if (!isTypeAnyOrAllConstituentTypesHaveKind(rightType, 48128 | 512)) { error(node.right, ts.Diagnostics.The_right_hand_side_of_an_in_expression_must_be_of_type_any_an_object_type_or_a_type_parameter); } return booleanType; @@ -15594,16 +15627,17 @@ var ts; for (var _i = 0; _i < properties.length; _i++) { var p = properties[_i]; if (p.kind === 225 || p.kind === 226) { - var name_11 = p.name; - var type = sourceType.flags & 1 ? sourceType : - getTypeOfPropertyOfType(sourceType, name_11.text) || - isNumericLiteralName(name_11.text) && getIndexTypeOfType(sourceType, 1) || + var name_12 = p.name; + var type = isTypeAny(sourceType) + ? sourceType + : getTypeOfPropertyOfType(sourceType, name_12.text) || + isNumericLiteralName(name_12.text) && getIndexTypeOfType(sourceType, 1) || getIndexTypeOfType(sourceType, 0); if (type) { - checkDestructuringAssignment(p.initializer || name_11, type); + checkDestructuringAssignment(p.initializer || name_12, type); } else { - error(name_11, ts.Diagnostics.Type_0_has_no_property_1_and_no_string_index_signature, typeToString(sourceType), ts.declarationNameToString(name_11)); + error(name_12, ts.Diagnostics.Type_0_has_no_property_1_and_no_string_index_signature, typeToString(sourceType), ts.declarationNameToString(name_12)); } } else { @@ -15620,8 +15654,9 @@ var ts; if (e.kind !== 176) { if (e.kind !== 174) { var propName = "" + i; - var type = sourceType.flags & 1 ? sourceType : - isTupleLikeType(sourceType) + var type = isTypeAny(sourceType) + ? sourceType + : isTupleLikeType(sourceType) ? getTypeOfPropertyOfType(sourceType, propName) : elementType; if (type) { @@ -15737,8 +15772,8 @@ var ts; if (allConstituentTypesHaveKind(leftType, 258) || allConstituentTypesHaveKind(rightType, 258)) { resultType = stringType; } - else if (leftType.flags & 1 || rightType.flags & 1) { - resultType = anyType; + else if (isTypeAny(leftType) || isTypeAny(rightType)) { + resultType = leftType === unknownType || rightType === unknownType ? unknownType : anyType; } if (resultType && !checkForDisallowedESSymbolOperand(operator)) { return resultType; @@ -15782,8 +15817,8 @@ var ts; return rightType; } function checkForDisallowedESSymbolOperand(operator) { - var offendingSymbolOperand = someConstituentTypeHasKind(leftType, 1048576) ? node.left : - someConstituentTypeHasKind(rightType, 1048576) ? node.right : + var offendingSymbolOperand = someConstituentTypeHasKind(leftType, 2097152) ? node.left : + someConstituentTypeHasKind(rightType, 2097152) ? node.right : undefined; if (offendingSymbolOperand) { error(offendingSymbolOperand, ts.Diagnostics.The_0_operator_cannot_be_applied_to_type_symbol, ts.tokenToString(operator)); @@ -16562,7 +16597,7 @@ var ts; if (node && node.kind === 142) { var type = getTypeFromTypeNode(node); var shouldCheckIfUnknownType = type === unknownType && compilerOptions.isolatedModules; - if (!type || (!shouldCheckIfUnknownType && type.flags & (1048703 | 132 | 258))) { + if (!type || (!shouldCheckIfUnknownType && type.flags & (2097279 | 132 | 258))) { return; } if (shouldCheckIfUnknownType || type.symbol.valueDeclaration) { @@ -16790,8 +16825,8 @@ var ts; container.kind === 206 || container.kind === 228); if (!namesShareScope) { - var name_12 = symbolToString(localDeclarationSymbol); - error(node, ts.Diagnostics.Cannot_initialize_outer_scoped_variable_0_in_the_same_scope_as_block_scoped_declaration_1, name_12, name_12); + var name_13 = symbolToString(localDeclarationSymbol); + error(node, ts.Diagnostics.Cannot_initialize_outer_scoped_variable_0_in_the_same_scope_as_block_scoped_declaration_1, name_13, name_13); } } } @@ -16978,7 +17013,7 @@ var ts; if (varExpr.kind === 154 || varExpr.kind === 155) { error(varExpr, ts.Diagnostics.The_left_hand_side_of_a_for_in_statement_cannot_be_a_destructuring_pattern); } - else if (!allConstituentTypesHaveKind(leftType, 1 | 258)) { + else if (!isTypeAnyOrAllConstituentTypesHaveKind(leftType, 258)) { error(varExpr, ts.Diagnostics.The_left_hand_side_of_a_for_in_statement_must_be_of_type_string_or_any); } else { @@ -16986,7 +17021,7 @@ var ts; } } var rightType = checkExpression(node.expression); - if (!allConstituentTypesHaveKind(rightType, 1 | 48128 | 512)) { + if (!isTypeAnyOrAllConstituentTypesHaveKind(rightType, 48128 | 512)) { error(node.expression, ts.Diagnostics.The_right_hand_side_of_a_for_in_statement_must_be_of_type_any_an_object_type_or_a_type_parameter); } checkSourceElement(node.statement); @@ -17003,7 +17038,7 @@ var ts; return checkIteratedTypeOrElementType(expressionType, rhsExpression, true); } function checkIteratedTypeOrElementType(inputType, errorNode, allowStringInput) { - if (inputType.flags & 1) { + if (isTypeAny(inputType)) { return inputType; } if (languageVersion >= 2) { @@ -17029,7 +17064,7 @@ var ts; return elementType || anyType; } function getElementTypeOfIterable(type, errorNode) { - if (type.flags & 1) { + if (isTypeAny(type)) { return undefined; } var typeAsIterable = type; @@ -17039,7 +17074,7 @@ var ts; } else { var iteratorFunction = getTypeOfPropertyOfType(type, ts.getPropertyNameForKnownSymbolName("iterator")); - if (iteratorFunction && iteratorFunction.flags & 1) { + if (isTypeAny(iteratorFunction)) { return undefined; } var iteratorFunctionSignatures = iteratorFunction ? getSignaturesOfType(iteratorFunction, 0) : emptyArray; @@ -17055,7 +17090,7 @@ var ts; return typeAsIterable.iterableElementType; } function getElementTypeOfIterator(type, errorNode) { - if (type.flags & 1) { + if (isTypeAny(type)) { return undefined; } var typeAsIterator = type; @@ -17065,7 +17100,7 @@ var ts; } else { var iteratorNextFunction = getTypeOfPropertyOfType(type, "next"); - if (iteratorNextFunction && iteratorNextFunction.flags & 1) { + if (isTypeAny(iteratorNextFunction)) { return undefined; } var iteratorNextFunctionSignatures = iteratorNextFunction ? getSignaturesOfType(iteratorNextFunction, 0) : emptyArray; @@ -17076,7 +17111,7 @@ var ts; return undefined; } var iteratorNextResult = getUnionType(ts.map(iteratorNextFunctionSignatures, getReturnTypeOfSignature)); - if (iteratorNextResult.flags & 1) { + if (isTypeAny(iteratorNextResult)) { return undefined; } var iteratorNextValue = getTypeOfPropertyOfType(iteratorNextResult, "value"); @@ -17092,7 +17127,7 @@ var ts; return typeAsIterator.iteratorElementType; } function getElementTypeOfIterableIterator(type) { - if (type.flags & 1) { + if (isTypeAny(type)) { return undefined; } if ((type.flags & 4096) && type.target === globalIterableIteratorType) { @@ -18571,9 +18606,9 @@ var ts; function getRootSymbols(symbol) { if (symbol.flags & 268435456) { var symbols = []; - var name_13 = symbol.name; + var name_14 = symbol.name; ts.forEach(getSymbolLinks(symbol).unionType.types, function (t) { - symbols.push(getPropertyOfType(t, name_13)); + symbols.push(getPropertyOfType(t, name_14)); }); return symbols; } @@ -18751,7 +18786,7 @@ var ts; else if (type.flags & 8192) { return "Array"; } - else if (type.flags & 1048576) { + else if (type.flags & 2097152) { return "Symbol"; } else if (type === unknownType) { @@ -18996,20 +19031,20 @@ var ts; if (impotClause.namedBindings) { var nameBindings = impotClause.namedBindings; if (nameBindings.kind === 212) { - var name_14 = nameBindings.name; - if (isReservedWordInStrictMode(name_14)) { - var nameText = ts.declarationNameToString(name_14); - return grammarErrorOnNode(name_14, ts.Diagnostics.Identifier_expected_0_is_a_reserved_word_in_strict_mode, nameText); + var name_15 = nameBindings.name; + if (isReservedWordInStrictMode(name_15)) { + var nameText = ts.declarationNameToString(name_15); + return grammarErrorOnNode(name_15, ts.Diagnostics.Identifier_expected_0_is_a_reserved_word_in_strict_mode, nameText); } } else if (nameBindings.kind === 213) { var reportError = false; for (var _i = 0, _a = nameBindings.elements; _i < _a.length; _i++) { var element = _a[_i]; - var name_15 = element.name; - if (isReservedWordInStrictMode(name_15)) { - var nameText = ts.declarationNameToString(name_15); - reportError = reportError || grammarErrorOnNode(name_15, ts.Diagnostics.Identifier_expected_0_is_a_reserved_word_in_strict_mode, nameText); + var name_16 = element.name; + if (isReservedWordInStrictMode(name_16)) { + var nameText = ts.declarationNameToString(name_16); + reportError = reportError || grammarErrorOnNode(name_16, ts.Diagnostics.Identifier_expected_0_is_a_reserved_word_in_strict_mode, nameText); } } return reportError; @@ -19468,17 +19503,17 @@ var ts; var inStrictMode = (node.parserContextFlags & 1) !== 0; for (var _i = 0, _a = node.properties; _i < _a.length; _i++) { var prop = _a[_i]; - var name_16 = prop.name; + var name_17 = prop.name; if (prop.kind === 176 || - name_16.kind === 128) { - checkGrammarComputedPropertyName(name_16); + name_17.kind === 128) { + checkGrammarComputedPropertyName(name_17); continue; } var currentKind = void 0; if (prop.kind === 225 || prop.kind === 226) { checkGrammarForInvalidQuestionMark(prop, prop.questionToken, ts.Diagnostics.An_object_member_cannot_be_declared_optional); - if (name_16.kind === 7) { - checkGrammarNumericLiteral(name_16); + if (name_17.kind === 7) { + checkGrammarNumericLiteral(name_17); } currentKind = Property; } @@ -19494,26 +19529,26 @@ var ts; else { ts.Debug.fail("Unexpected syntax kind:" + prop.kind); } - if (!ts.hasProperty(seen, name_16.text)) { - seen[name_16.text] = currentKind; + if (!ts.hasProperty(seen, name_17.text)) { + seen[name_17.text] = currentKind; } else { - var existingKind = seen[name_16.text]; + var existingKind = seen[name_17.text]; if (currentKind === Property && existingKind === Property) { if (inStrictMode) { - grammarErrorOnNode(name_16, ts.Diagnostics.An_object_literal_cannot_have_multiple_properties_with_the_same_name_in_strict_mode); + grammarErrorOnNode(name_17, ts.Diagnostics.An_object_literal_cannot_have_multiple_properties_with_the_same_name_in_strict_mode); } } else if ((currentKind & GetOrSetAccessor) && (existingKind & GetOrSetAccessor)) { if (existingKind !== GetOrSetAccessor && currentKind !== existingKind) { - seen[name_16.text] = currentKind | existingKind; + seen[name_17.text] = currentKind | existingKind; } else { - return grammarErrorOnNode(name_16, ts.Diagnostics.An_object_literal_cannot_have_multiple_get_Slashset_accessors_with_the_same_name); + return grammarErrorOnNode(name_17, ts.Diagnostics.An_object_literal_cannot_have_multiple_get_Slashset_accessors_with_the_same_name); } } else { - return grammarErrorOnNode(name_16, ts.Diagnostics.An_object_literal_cannot_have_property_and_accessor_with_the_same_name); + return grammarErrorOnNode(name_17, ts.Diagnostics.An_object_literal_cannot_have_property_and_accessor_with_the_same_name); } } } @@ -20292,9 +20327,9 @@ var ts; } var count = 0; while (true) { - var name_17 = baseName + "_" + (++count); - if (!ts.hasProperty(currentSourceFile.identifiers, name_17)) { - return name_17; + var name_18 = baseName + "_" + (++count); + if (!ts.hasProperty(currentSourceFile.identifiers, name_18)) { + return name_18; } } } @@ -21378,9 +21413,9 @@ var ts; var count = tempFlags & 268435455; tempFlags++; if (count !== 8 && count !== 13) { - var name_18 = count < 26 ? "_" + String.fromCharCode(97 + count) : "_" + (count - 26); - if (isUniqueName(name_18)) { - return name_18; + var name_19 = count < 26 ? "_" + String.fromCharCode(97 + count) : "_" + (count - 26); + if (isUniqueName(name_19)) { + return name_19; } } } @@ -21408,8 +21443,8 @@ var ts; } function generateNameForModuleOrEnum(node) { if (node.name.kind === 65) { - var name_19 = node.name.text; - assignGeneratedName(node, isUniqueLocalName(name_19, node) ? name_19 : makeUniqueName(name_19)); + var name_20 = node.name.text; + assignGeneratedName(node, isUniqueLocalName(name_20, node) ? name_20 : makeUniqueName(name_20)); } } function generateNameForImportOrExportDeclaration(node) { @@ -21595,8 +21630,8 @@ var ts; if (scopeName) { var parentIndex = getSourceMapNameIndex(); if (parentIndex !== -1) { - var name_20 = node.name; - if (!name_20 || name_20.kind !== 128) { + var name_21 = node.name; + if (!name_21 || name_21.kind !== 128) { scopeName = "." + scopeName; } scopeName = sourceMapData.sourceMapNames[parentIndex] + scopeName; @@ -21623,9 +21658,9 @@ var ts; node.kind === 202 || node.kind === 205) { if (node.name) { - var name_21 = node.name; - scopeName = name_21.kind === 128 - ? ts.getTextOfNode(name_21) + var name_22 = node.name; + scopeName = name_22.kind === 128 + ? ts.getTextOfNode(name_22) : node.name.text; } recordScopeNameStart(scopeName); @@ -22475,7 +22510,12 @@ var ts; return result; } function parenthesizeForAccess(expr) { - if (ts.isLeftHandSideExpression(expr) && expr.kind !== 159 && expr.kind !== 7) { + while (expr.kind === 161) { + expr = expr.expression; + } + if (ts.isLeftHandSideExpression(expr) && + expr.kind !== 159 && + expr.kind !== 7) { return expr; } var node = ts.createSynthesizedNode(162); @@ -22696,7 +22736,7 @@ var ts; } } function emitParenExpression(node) { - if (!node.parent || node.parent.kind !== 164) { + if (!ts.nodeIsSynthesized(node) && node.parent.kind !== 164) { if (node.expression.kind === 161) { var operand = node.expression.expression; while (operand.kind == 161) { @@ -23652,12 +23692,12 @@ var ts; function emitParameter(node) { if (languageVersion < 2) { if (ts.isBindingPattern(node.name)) { - var name_22 = createTempVariable(0); + var name_23 = createTempVariable(0); if (!tempParameters) { tempParameters = []; } - tempParameters.push(name_22); - emit(name_22); + tempParameters.push(name_23); + emit(name_23); } else { emit(node.name); @@ -25117,8 +25157,8 @@ var ts; else { for (var _c = 0, _d = node.exportClause.elements; _c < _d.length; _c++) { var specifier = _d[_c]; - var name_23 = (specifier.propertyName || specifier.name).text; - (exportSpecifiers[name_23] || (exportSpecifiers[name_23] = [])).push(specifier); + var name_24 = (specifier.propertyName || specifier.name).text; + (exportSpecifiers[name_24] || (exportSpecifiers[name_24] = [])).push(specifier); } } break; @@ -25291,11 +25331,11 @@ var ts; var seen = {}; for (var i = 0; i < hoistedVars.length; ++i) { var local = hoistedVars[i]; - var name_24 = local.kind === 65 + var name_25 = local.kind === 65 ? local : local.name; - if (name_24) { - var text = ts.unescapeIdentifier(name_24.text); + if (name_25) { + var text = ts.unescapeIdentifier(name_25.text); if (ts.hasProperty(seen, text)) { continue; } @@ -25374,15 +25414,15 @@ var ts; } if (node.kind === 199 || node.kind === 153) { if (shouldHoistVariable(node, false)) { - var name_25 = node.name; - if (name_25.kind === 65) { + var name_26 = node.name; + if (name_26.kind === 65) { if (!hoistedVars) { hoistedVars = []; } - hoistedVars.push(name_25); + hoistedVars.push(name_26); } else { - ts.forEachChild(name_25, visit); + ts.forEachChild(name_26, visit); } } return; @@ -26055,8 +26095,6 @@ var ts; ts.ioReadTime = 0; ts.ioWriteTime = 0; ts.version = "1.5.3"; - var carriageReturnLineFeed = "\r\n"; - var lineFeed = "\n"; function findConfigFile(searchPath) { var fileName = "tsconfig.json"; while (true) { @@ -26127,9 +26165,7 @@ var ts; } } } - var newLine = options.newLine === 0 ? carriageReturnLineFeed : - options.newLine === 1 ? lineFeed : - ts.sys.newLine; + var newLine = ts.getNewLineCharacter(options); return { getSourceFile: getSourceFile, getDefaultLibFileName: function (options) { return ts.combinePaths(ts.getDirectoryPath(ts.normalizePath(ts.sys.getExecutingFilePath())), ts.getDefaultLibFileName(options)); }, @@ -26197,6 +26233,7 @@ var ts; getGlobalDiagnostics: getGlobalDiagnostics, getSemanticDiagnostics: getSemanticDiagnostics, getDeclarationDiagnostics: getDeclarationDiagnostics, + getCompilerOptionsDiagnostics: getCompilerOptionsDiagnostics, getTypeChecker: getTypeChecker, getDiagnosticsProducingTypeChecker: getDiagnosticsProducingTypeChecker, getCommonSourceDirectory: function () { return commonSourceDirectory; }, @@ -26277,6 +26314,11 @@ var ts; return ts.getDeclarationDiagnostics(getEmitHost(writeFile), resolver, sourceFile); } } + function getCompilerOptionsDiagnostics() { + var allDiagnostics = []; + ts.addRange(allDiagnostics, diagnostics.getGlobalDiagnostics()); + return ts.sortAndDeduplicateDiagnostics(allDiagnostics); + } function getGlobalDiagnostics() { var typeChecker = getDiagnosticsProducingTypeChecker(); var allDiagnostics = []; @@ -26889,7 +26931,7 @@ var ts; var errors = []; return { options: getCompilerOptions(), - fileNames: getFiles(), + fileNames: getFileNames(), errors: errors }; function getCompilerOptions() { @@ -26933,23 +26975,24 @@ var ts; } return options; } - function getFiles() { - var files = []; + function getFileNames() { + var fileNames = []; if (ts.hasProperty(json, "files")) { if (json["files"] instanceof Array) { - var files = ts.map(json["files"], function (s) { return ts.combinePaths(basePath, s); }); + fileNames = ts.map(json["files"], function (s) { return ts.combinePaths(basePath, s); }); } } else { - var sysFiles = host.readDirectory(basePath, ".ts"); + var exclude = json["exclude"] instanceof Array ? ts.map(json["exclude"], ts.normalizeSlashes) : undefined; + var sysFiles = host.readDirectory(basePath, ".ts", exclude); for (var i = 0; i < sysFiles.length; i++) { var name = sysFiles[i]; if (!ts.fileExtensionIs(name, ".d.ts") || !ts.contains(sysFiles, name.substr(0, name.length - 5) + ".ts")) { - files.push(name); + fileNames.push(name); } } } - return files; + return fileNames; } } ts.parseConfigFile = parseConfigFile; diff --git a/bin/tsserver.js b/bin/tsserver.js index a6d4dc601d7..71ff883dbce 100644 --- a/bin/tsserver.js +++ b/bin/tsserver.js @@ -738,6 +738,9 @@ var ts; fileStream.Close(); } } + function getCanonicalPath(path) { + return path.toLowerCase(); + } function getNames(collection) { var result = []; for (var e = new Enumerator(collection); !e.atEnd(); e.moveNext()) { @@ -745,23 +748,28 @@ var ts; } return result.sort(); } - function readDirectory(path, extension) { + function readDirectory(path, extension, exclude) { var result = []; + exclude = ts.map(exclude, function (s) { return getCanonicalPath(ts.combinePaths(path, s)); }); visitDirectory(path); return result; function visitDirectory(path) { var folder = fso.GetFolder(path || "."); var files = getNames(folder.files); for (var _i = 0; _i < files.length; _i++) { - var name_1 = files[_i]; - if (!extension || ts.fileExtensionIs(name_1, extension)) { - result.push(ts.combinePaths(path, name_1)); + var current = files[_i]; + var name_1 = ts.combinePaths(path, current); + if ((!extension || ts.fileExtensionIs(name_1, extension)) && !ts.contains(exclude, getCanonicalPath(name_1))) { + result.push(name_1); } } var subfolders = getNames(folder.subfolders); for (var _a = 0; _a < subfolders.length; _a++) { var current = subfolders[_a]; - visitDirectory(ts.combinePaths(path, current)); + var name_2 = ts.combinePaths(path, current); + if (!ts.contains(exclude, getCanonicalPath(name_2))) { + visitDirectory(name_2); + } } } } @@ -839,8 +847,12 @@ var ts; } _fs.writeFileSync(fileName, data, "utf8"); } - function readDirectory(path, extension) { + function getCanonicalPath(path) { + return useCaseSensitiveFileNames ? path.toLowerCase() : path; + } + function readDirectory(path, extension, exclude) { var result = []; + exclude = ts.map(exclude, function (s) { return getCanonicalPath(ts.combinePaths(path, s)); }); visitDirectory(path); return result; function visitDirectory(path) { @@ -849,14 +861,16 @@ var ts; for (var _i = 0; _i < files.length; _i++) { var current = files[_i]; var name = ts.combinePaths(path, current); - var stat = _fs.statSync(name); - if (stat.isFile()) { - if (!extension || ts.fileExtensionIs(name, extension)) { - result.push(name); + if (!ts.contains(exclude, getCanonicalPath(name))) { + var stat = _fs.statSync(name); + if (stat.isFile()) { + if (!extension || ts.fileExtensionIs(name, extension)) { + result.push(name); + } + } + else if (stat.isDirectory()) { + directories.push(name); } - } - else if (stat.isDirectory()) { - directories.push(name); } } for (var _a = 0; _a < directories.length; _a++) { @@ -1460,7 +1474,7 @@ var ts; Object_literal_s_property_0_implicitly_has_an_1_type: { code: 7018, category: ts.DiagnosticCategory.Error, key: "Object literal's property '{0}' implicitly has an '{1}' type." }, Rest_parameter_0_implicitly_has_an_any_type: { code: 7019, category: ts.DiagnosticCategory.Error, key: "Rest parameter '{0}' implicitly has an 'any[]' type." }, Call_signature_which_lacks_return_type_annotation_implicitly_has_an_any_return_type: { code: 7020, category: ts.DiagnosticCategory.Error, key: "Call signature, which lacks return-type annotation, implicitly has an 'any' return type." }, - _0_implicitly_has_type_any_because_it_is_does_not_have_a_type_annotation_and_is_referenced_directly_or_indirectly_in_its_own_initializer: { code: 7022, category: ts.DiagnosticCategory.Error, key: "'{0}' implicitly has type 'any' because it is does not have a type annotation and is referenced directly or indirectly in its own initializer." }, + _0_implicitly_has_type_any_because_it_does_not_have_a_type_annotation_and_is_referenced_directly_or_indirectly_in_its_own_initializer: { code: 7022, category: ts.DiagnosticCategory.Error, key: "'{0}' implicitly has type 'any' because it does not have a type annotation and is referenced directly or indirectly in its own initializer." }, _0_implicitly_has_return_type_any_because_it_does_not_have_a_return_type_annotation_and_is_referenced_directly_or_indirectly_in_one_of_its_return_expressions: { code: 7023, category: ts.DiagnosticCategory.Error, key: "'{0}' implicitly has return type 'any' because it does not have a return type annotation and is referenced directly or indirectly in one of its return expressions." }, Function_implicitly_has_return_type_any_because_it_does_not_have_a_return_type_annotation_and_is_referenced_directly_or_indirectly_in_one_of_its_return_expressions: { code: 7024, category: ts.DiagnosticCategory.Error, key: "Function implicitly has return type 'any' because it does not have a return type annotation and is referenced directly or indirectly in one of its return expressions." }, Generator_implicitly_has_type_0_because_it_does_not_yield_any_values_Consider_supplying_a_return_type: { code: 7025, category: ts.DiagnosticCategory.Error, key: "Generator implicitly has type '{0}' because it does not yield any values. Consider supplying a return type." }, @@ -1642,9 +1656,9 @@ var ts; } function makeReverseMap(source) { var result = []; - for (var name_2 in source) { - if (source.hasOwnProperty(name_2)) { - result[source[name_2]] = name_2; + for (var name_3 in source) { + if (source.hasOwnProperty(name_3)) { + result[source[name_3]] = name_3; } } return result; @@ -3056,7 +3070,7 @@ var ts; var errors = []; return { options: getCompilerOptions(), - fileNames: getFiles(), + fileNames: getFileNames(), errors: errors }; function getCompilerOptions() { @@ -3100,23 +3114,24 @@ var ts; } return options; } - function getFiles() { - var files = []; + function getFileNames() { + var fileNames = []; if (ts.hasProperty(json, "files")) { if (json["files"] instanceof Array) { - var files = ts.map(json["files"], function (s) { return ts.combinePaths(basePath, s); }); + fileNames = ts.map(json["files"], function (s) { return ts.combinePaths(basePath, s); }); } } else { - var sysFiles = host.readDirectory(basePath, ".ts"); + var exclude = json["exclude"] instanceof Array ? ts.map(json["exclude"], ts.normalizeSlashes) : undefined; + var sysFiles = host.readDirectory(basePath, ".ts", exclude); for (var i = 0; i < sysFiles.length; i++) { var name = sysFiles[i]; if (!ts.fileExtensionIs(name, ".d.ts") || !ts.contains(sysFiles, name.substr(0, name.length - 5) + ".ts")) { - files.push(name); + fileNames.push(name); } } } - return files; + return fileNames; } } ts.parseConfigFile = parseConfigFile; @@ -3536,9 +3551,9 @@ var ts; return; default: if (isFunctionLike(node)) { - var name_3 = node.name; - if (name_3 && name_3.kind === 128) { - traverse(name_3.expression); + var name_4 = node.name; + if (name_4 && name_4.kind === 128) { + traverse(name_4.expression); return; } } @@ -3948,8 +3963,8 @@ var ts; return ts.forEach(docComment.tags, function (t) { if (t.kind === 247) { var parameterTag = t; - var name_4 = parameterTag.preParameterName || parameterTag.postParameterName; - if (name_4.text === parameterName) { + var name_5 = parameterTag.preParameterName || parameterTag.postParameterName; + if (name_5.text === parameterName) { return t; } } @@ -4759,6 +4774,21 @@ var ts; return result; } ts.convertToBase64 = convertToBase64; + var carriageReturnLineFeed = "\r\n"; + var lineFeed = "\n"; + function getNewLineCharacter(options) { + if (options.newLine === 0) { + return carriageReturnLineFeed; + } + else if (options.newLine === 1) { + return lineFeed; + } + else if (ts.sys) { + return ts.sys.newLine; + } + return carriageReturnLineFeed; + } + ts.getNewLineCharacter = getNewLineCharacter; })(ts || (ts = {})); var ts; (function (ts) { @@ -8024,8 +8054,8 @@ var ts; return parsePropertyOrMethodDeclaration(fullStart, decorators, modifiers); } if (decorators) { - var name_5 = createMissingNode(65, true, ts.Diagnostics.Declaration_expected); - return parsePropertyDeclaration(fullStart, decorators, modifiers, name_5, undefined); + var name_6 = createMissingNode(65, true, ts.Diagnostics.Declaration_expected); + return parsePropertyDeclaration(fullStart, decorators, modifiers, name_6, undefined); } ts.Debug.fail("Should not have attempted to parse class member declaration."); } @@ -8861,13 +8891,13 @@ var ts; while (true) { skipWhitespace(); var startPos = pos; - var name_6 = scanIdentifier(); - if (!name_6) { + var name_7 = scanIdentifier(); + if (!name_7) { parseErrorAtPosition(startPos, 0, ts.Diagnostics.Identifier_expected); return undefined; } - var typeParameter = createNode(129, name_6.pos); - typeParameter.name = name_6; + var typeParameter = createNode(129, name_7.pos); + typeParameter.name = name_7; finishNode(typeParameter, pos); typeParameters.push(typeParameter); skipWhitespace(); @@ -9776,10 +9806,10 @@ var ts; var stringType = createIntrinsicType(2, "string"); var numberType = createIntrinsicType(4, "number"); var booleanType = createIntrinsicType(8, "boolean"); - var esSymbolType = createIntrinsicType(1048576, "symbol"); + var esSymbolType = createIntrinsicType(2097152, "symbol"); var voidType = createIntrinsicType(16, "void"); - var undefinedType = createIntrinsicType(32 | 262144, "undefined"); - var nullType = createIntrinsicType(64 | 262144, "null"); + var undefinedType = createIntrinsicType(32 | 524288, "undefined"); + var nullType = createIntrinsicType(64 | 524288, "null"); var unknownType = createIntrinsicType(1, "unknown"); var circularType = createIntrinsicType(1, "__circular__"); var emptyObjectType = createAnonymousType(undefined, emptySymbols, emptyArray, emptyArray, undefined, undefined); @@ -9836,7 +9866,7 @@ var ts; }, "symbol": { type: esSymbolType, - flags: 1048576 + flags: 2097152 } }; function getEmitResolver(sourceFile) { @@ -10261,15 +10291,15 @@ var ts; var moduleSymbol = resolveExternalModuleName(node, node.moduleSpecifier); var targetSymbol = resolveESModuleSymbol(moduleSymbol, node.moduleSpecifier); if (targetSymbol) { - var name_7 = specifier.propertyName || specifier.name; - if (name_7.text) { - var symbolFromModule = getExportOfModule(targetSymbol, name_7.text); - var symbolFromVariable = getPropertyOfVariable(targetSymbol, name_7.text); + var name_8 = specifier.propertyName || specifier.name; + if (name_8.text) { + var symbolFromModule = getExportOfModule(targetSymbol, name_8.text); + var symbolFromVariable = getPropertyOfVariable(targetSymbol, name_8.text); var symbol = symbolFromModule && symbolFromVariable ? combineValueAndTypeSymbols(symbolFromVariable, symbolFromModule) : symbolFromModule || symbolFromVariable; if (!symbol) { - error(name_7, ts.Diagnostics.Module_0_has_no_exported_member_1, getFullyQualifiedName(moduleSymbol), ts.declarationNameToString(name_7)); + error(name_8, ts.Diagnostics.Module_0_has_no_exported_member_1, getFullyQualifiedName(moduleSymbol), ts.declarationNameToString(name_8)); } return symbol; } @@ -10871,13 +10901,14 @@ var ts; } return appendParentTypeArgumentsAndSymbolName(symbol); } - function buildTypeDisplay(type, writer, enclosingDeclaration, globalFlags, typeStack) { + function buildTypeDisplay(type, writer, enclosingDeclaration, globalFlags, symbolStack) { var globalFlagsToPass = globalFlags & 16; return writeType(type, globalFlags); function writeType(type, flags) { - if (type.flags & 1048703) { - writer.writeKeyword(!(globalFlags & 16) && - (type.flags & 1) ? "any" : type.intrinsicName); + if (type.flags & 2097279) { + writer.writeKeyword(!(globalFlags & 16) && isTypeAny(type) + ? "any" + : type.intrinsicName); } else if (type.flags & 4096) { writeTypeReference(type, flags); @@ -10974,42 +11005,46 @@ var ts; } } function writeAnonymousType(type, flags) { - if (type.symbol && type.symbol.flags & (32 | 384 | 512)) { - writeTypeofSymbol(type, flags); - } - else if (shouldWriteTypeOfFunctionSymbol()) { - writeTypeofSymbol(type, flags); - } - else if (typeStack && ts.contains(typeStack, type)) { - var typeAlias = getTypeAliasForTypeLiteral(type); - if (typeAlias) { - buildSymbolDisplay(typeAlias, writer, enclosingDeclaration, 793056, 0, flags); + var symbol = type.symbol; + if (symbol) { + if (symbol.flags & (32 | 384 | 512)) { + writeTypeofSymbol(type, flags); + } + else if (shouldWriteTypeOfFunctionSymbol()) { + writeTypeofSymbol(type, flags); + } + else if (ts.contains(symbolStack, symbol)) { + var typeAlias = getTypeAliasForTypeLiteral(type); + if (typeAlias) { + buildSymbolDisplay(typeAlias, writer, enclosingDeclaration, 793056, 0, flags); + } + else { + writeKeyword(writer, 112); + } } else { - writeKeyword(writer, 112); + if (!symbolStack) { + symbolStack = []; + } + symbolStack.push(symbol); + writeLiteralType(type, flags); + symbolStack.pop(); } } else { - if (!typeStack) { - typeStack = []; - } - typeStack.push(type); writeLiteralType(type, flags); - typeStack.pop(); } function shouldWriteTypeOfFunctionSymbol() { - if (type.symbol) { - var isStaticMethodSymbol = !!(type.symbol.flags & 8192 && - ts.forEach(type.symbol.declarations, function (declaration) { return declaration.flags & 128; })); - var isNonLocalFunctionSymbol = !!(type.symbol.flags & 16) && - (type.symbol.parent || - ts.forEach(type.symbol.declarations, function (declaration) { - return declaration.parent.kind === 228 || declaration.parent.kind === 207; - })); - if (isStaticMethodSymbol || isNonLocalFunctionSymbol) { - return !!(flags & 2) || - (typeStack && ts.contains(typeStack, type)); - } + var isStaticMethodSymbol = !!(symbol.flags & 8192 && + ts.forEach(symbol.declarations, function (declaration) { return declaration.flags & 128; })); + var isNonLocalFunctionSymbol = !!(symbol.flags & 16) && + (symbol.parent || + ts.forEach(symbol.declarations, function (declaration) { + return declaration.parent.kind === 228 || declaration.parent.kind === 207; + })); + if (isStaticMethodSymbol || isNonLocalFunctionSymbol) { + return !!(flags & 2) || + (ts.contains(symbolStack, symbol)); } } } @@ -11038,7 +11073,7 @@ var ts; if (flags & 64) { writePunctuation(writer, 16); } - buildSignatureDisplay(resolved.callSignatures[0], writer, enclosingDeclaration, globalFlagsToPass | 8, typeStack); + buildSignatureDisplay(resolved.callSignatures[0], writer, enclosingDeclaration, globalFlagsToPass | 8, symbolStack); if (flags & 64) { writePunctuation(writer, 17); } @@ -11050,7 +11085,7 @@ var ts; } writeKeyword(writer, 88); writeSpace(writer); - buildSignatureDisplay(resolved.constructSignatures[0], writer, enclosingDeclaration, globalFlagsToPass | 8, typeStack); + buildSignatureDisplay(resolved.constructSignatures[0], writer, enclosingDeclaration, globalFlagsToPass | 8, symbolStack); if (flags & 64) { writePunctuation(writer, 17); } @@ -11062,7 +11097,7 @@ var ts; writer.increaseIndent(); for (var _i = 0, _a = resolved.callSignatures; _i < _a.length; _i++) { var signature = _a[_i]; - buildSignatureDisplay(signature, writer, enclosingDeclaration, globalFlagsToPass, typeStack); + buildSignatureDisplay(signature, writer, enclosingDeclaration, globalFlagsToPass, symbolStack); writePunctuation(writer, 22); writer.writeLine(); } @@ -11070,7 +11105,7 @@ var ts; var signature = _c[_b]; writeKeyword(writer, 88); writeSpace(writer); - buildSignatureDisplay(signature, writer, enclosingDeclaration, globalFlagsToPass, typeStack); + buildSignatureDisplay(signature, writer, enclosingDeclaration, globalFlagsToPass, symbolStack); writePunctuation(writer, 22); writer.writeLine(); } @@ -11111,7 +11146,7 @@ var ts; if (p.flags & 536870912) { writePunctuation(writer, 50); } - buildSignatureDisplay(signature, writer, enclosingDeclaration, globalFlagsToPass, typeStack); + buildSignatureDisplay(signature, writer, enclosingDeclaration, globalFlagsToPass, symbolStack); writePunctuation(writer, 22); writer.writeLine(); } @@ -11138,17 +11173,17 @@ var ts; buildDisplayForTypeParametersAndDelimiters(getLocalTypeParametersOfClassOrInterface(symbol), writer, enclosingDeclaraiton, flags); } } - function buildTypeParameterDisplay(tp, writer, enclosingDeclaration, flags, typeStack) { + function buildTypeParameterDisplay(tp, writer, enclosingDeclaration, flags, symbolStack) { appendSymbolNameOnly(tp.symbol, writer); var constraint = getConstraintOfTypeParameter(tp); if (constraint) { writeSpace(writer); writeKeyword(writer, 79); writeSpace(writer); - buildTypeDisplay(constraint, writer, enclosingDeclaration, flags, typeStack); + buildTypeDisplay(constraint, writer, enclosingDeclaration, flags, symbolStack); } } - function buildParameterDisplay(p, writer, enclosingDeclaration, flags, typeStack) { + function buildParameterDisplay(p, writer, enclosingDeclaration, flags, symbolStack) { var parameterNode = p.valueDeclaration; if (ts.isRestParameter(parameterNode)) { writePunctuation(writer, 21); @@ -11159,9 +11194,9 @@ var ts; } writePunctuation(writer, 51); writeSpace(writer); - buildTypeDisplay(getTypeOfSymbol(p), writer, enclosingDeclaration, flags, typeStack); + buildTypeDisplay(getTypeOfSymbol(p), writer, enclosingDeclaration, flags, symbolStack); } - function buildDisplayForTypeParametersAndDelimiters(typeParameters, writer, enclosingDeclaration, flags, typeStack) { + function buildDisplayForTypeParametersAndDelimiters(typeParameters, writer, enclosingDeclaration, flags, symbolStack) { if (typeParameters && typeParameters.length) { writePunctuation(writer, 24); for (var i = 0; i < typeParameters.length; i++) { @@ -11169,12 +11204,12 @@ var ts; writePunctuation(writer, 23); writeSpace(writer); } - buildTypeParameterDisplay(typeParameters[i], writer, enclosingDeclaration, flags, typeStack); + buildTypeParameterDisplay(typeParameters[i], writer, enclosingDeclaration, flags, symbolStack); } writePunctuation(writer, 25); } } - function buildDisplayForTypeArgumentsAndDelimiters(typeParameters, mapper, writer, enclosingDeclaration, flags, typeStack) { + function buildDisplayForTypeArgumentsAndDelimiters(typeParameters, mapper, writer, enclosingDeclaration, flags, symbolStack) { if (typeParameters && typeParameters.length) { writePunctuation(writer, 24); for (var i = 0; i < typeParameters.length; i++) { @@ -11187,18 +11222,18 @@ var ts; writePunctuation(writer, 25); } } - function buildDisplayForParametersAndDelimiters(parameters, writer, enclosingDeclaration, flags, typeStack) { + function buildDisplayForParametersAndDelimiters(parameters, writer, enclosingDeclaration, flags, symbolStack) { writePunctuation(writer, 16); for (var i = 0; i < parameters.length; i++) { if (i > 0) { writePunctuation(writer, 23); writeSpace(writer); } - buildParameterDisplay(parameters[i], writer, enclosingDeclaration, flags, typeStack); + buildParameterDisplay(parameters[i], writer, enclosingDeclaration, flags, symbolStack); } writePunctuation(writer, 17); } - function buildReturnTypeDisplay(signature, writer, enclosingDeclaration, flags, typeStack) { + function buildReturnTypeDisplay(signature, writer, enclosingDeclaration, flags, symbolStack) { if (flags & 8) { writeSpace(writer); writePunctuation(writer, 32); @@ -11207,17 +11242,17 @@ var ts; writePunctuation(writer, 51); } writeSpace(writer); - buildTypeDisplay(getReturnTypeOfSignature(signature), writer, enclosingDeclaration, flags, typeStack); + buildTypeDisplay(getReturnTypeOfSignature(signature), writer, enclosingDeclaration, flags, symbolStack); } - function buildSignatureDisplay(signature, writer, enclosingDeclaration, flags, typeStack) { + function buildSignatureDisplay(signature, writer, enclosingDeclaration, flags, symbolStack) { if (signature.target && (flags & 32)) { buildDisplayForTypeArgumentsAndDelimiters(signature.target.typeParameters, signature.mapper, writer, enclosingDeclaration); } else { - buildDisplayForTypeParametersAndDelimiters(signature.typeParameters, writer, enclosingDeclaration, flags, typeStack); + buildDisplayForTypeParametersAndDelimiters(signature.typeParameters, writer, enclosingDeclaration, flags, symbolStack); } - buildDisplayForParametersAndDelimiters(signature.parameters, writer, enclosingDeclaration, flags, typeStack); - buildReturnTypeDisplay(signature, writer, enclosingDeclaration, flags, typeStack); + buildDisplayForParametersAndDelimiters(signature.parameters, writer, enclosingDeclaration, flags, symbolStack); + buildReturnTypeDisplay(signature, writer, enclosingDeclaration, flags, symbolStack); } return _displayBuilder || (_displayBuilder = { symbolToString: symbolToString, @@ -11411,13 +11446,16 @@ var ts; var prop = getPropertyOfType(type, name); return prop ? getTypeOfSymbol(prop) : undefined; } + function isTypeAny(type) { + return type && (type.flags & 1) !== 0; + } function getTypeForBindingElement(declaration) { var pattern = declaration.parent; var parentType = getTypeForVariableLikeDeclaration(pattern.parent); if (parentType === unknownType) { return unknownType; } - if (!parentType || parentType === anyType) { + if (!parentType || isTypeAny(parentType)) { if (declaration.initializer) { return checkExpressionCached(declaration.initializer); } @@ -11425,19 +11463,19 @@ var ts; } var type; if (pattern.kind === 151) { - var name_8 = declaration.propertyName || declaration.name; - type = getTypeOfPropertyOfType(parentType, name_8.text) || - isNumericLiteralName(name_8.text) && getIndexTypeOfType(parentType, 1) || + var name_9 = declaration.propertyName || declaration.name; + type = getTypeOfPropertyOfType(parentType, name_9.text) || + isNumericLiteralName(name_9.text) && getIndexTypeOfType(parentType, 1) || getIndexTypeOfType(parentType, 0); if (!type) { - error(name_8, ts.Diagnostics.Type_0_has_no_property_1_and_no_string_index_signature, typeToString(parentType), ts.declarationNameToString(name_8)); + error(name_9, ts.Diagnostics.Type_0_has_no_property_1_and_no_string_index_signature, typeToString(parentType), ts.declarationNameToString(name_9)); return unknownType; } } else { var elementType = checkIteratedTypeOrElementType(parentType, pattern, false); if (!declaration.dotDotDotToken) { - if (elementType.flags & 1) { + if (isTypeAny(elementType)) { return elementType; } var propName = "" + ts.indexOf(pattern.elements, declaration); @@ -11582,7 +11620,7 @@ var ts; else { type = anyType; if (compilerOptions.noImplicitAny) { - error(symbol.valueDeclaration, ts.Diagnostics._0_implicitly_has_type_any_because_it_is_does_not_have_a_type_annotation_and_is_referenced_directly_or_indirectly_in_its_own_initializer, symbolToString(symbol)); + error(symbol.valueDeclaration, ts.Diagnostics._0_implicitly_has_type_any_because_it_does_not_have_a_type_annotation_and_is_referenced_directly_or_indirectly_in_its_own_initializer, symbolToString(symbol)); } } } @@ -12192,7 +12230,7 @@ var ts; else if (type.flags & 8) { type = globalBooleanType; } - else if (type.flags & 1048576) { + else if (type.flags & 2097152) { type = globalESSymbolType; } return type; @@ -12449,7 +12487,7 @@ var ts; function getOrCreateTypeFromSignature(signature) { if (!signature.isolatedSignatureType) { var isConstructor = signature.declaration.kind === 136 || signature.declaration.kind === 140; - var type = createObjectType(32768 | 65536); + var type = createObjectType(32768 | 131072); type.members = emptySymbols; type.properties = emptyArray; type.callSignatures = !isConstructor ? [signature] : emptyArray; @@ -12523,7 +12561,7 @@ var ts; var type = types[_i]; result |= type.flags; } - return result & 786432; + return result & 1572864; } function createTypeReference(target, typeArguments) { var id = getTypeListId(typeArguments); @@ -12739,10 +12777,10 @@ var ts; } } } - function containsAnyType(types) { + function containsTypeAny(types) { for (var _i = 0; _i < types.length; _i++) { var type = types[_i]; - if (type.flags & 1) { + if (isTypeAny(type)) { return true; } } @@ -12764,7 +12802,7 @@ var ts; var sortedTypes = []; addTypesToSortedSet(sortedTypes, types); if (noSubtypeReduction) { - if (containsAnyType(sortedTypes)) { + if (containsTypeAny(sortedTypes)) { return anyType; } removeAllButLast(sortedTypes, undefinedType); @@ -12978,16 +13016,7 @@ var ts; return result; } function instantiateAnonymousType(type, mapper) { - if (mapper.mappings) { - var cached = mapper.mappings[type.id]; - if (cached) { - return cached; - } - } - else { - mapper.mappings = {}; - } - var result = createObjectType(32768, type.symbol); + var result = createObjectType(32768 | 65536, type.symbol); result.properties = instantiateList(getPropertiesOfObjectType(type), mapper, instantiateSymbol); result.members = createSymbolTable(result.properties); result.callSignatures = instantiateList(getSignaturesOfType(type, 0), mapper, instantiateSignature); @@ -12998,7 +13027,6 @@ var ts; result.stringIndexType = instantiateType(stringIndexType, mapper); if (numberIndexType) result.numberIndexType = instantiateType(numberIndexType, mapper); - mapper.mappings[type.id] = result; return result; } function instantiateType(type, mapper) { @@ -13125,7 +13153,7 @@ var ts; if (source === target) return -1; if (relation !== identityRelation) { - if (target.flags & 1) + if (isTypeAny(target)) return -1; if (source === undefinedType) return -1; @@ -13136,7 +13164,7 @@ var ts; if (source.flags & 256 && target === stringType) return -1; if (relation === assignableRelation) { - if (source.flags & 1) + if (isTypeAny(source)) return -1; if (source === numberType && target.flags & 128) return -1; @@ -13354,12 +13382,12 @@ var ts; return result; } function isDeeplyNestedGeneric(type, stack) { - if (type.flags & 4096 && depth >= 10) { - var target_1 = type.target; + if (type.flags & (4096 | 65536) && depth >= 10) { + var symbol = type.symbol; var count = 0; for (var i = 0; i < depth; i++) { var t = stack[i]; - if (t.flags & 4096 && t.target === target_1) { + if (t.flags & (4096 | 65536) && t.symbol === symbol) { count++; if (count >= 10) return true; @@ -13374,7 +13402,7 @@ var ts; } var result = -1; var properties = getPropertiesOfObjectType(target); - var requireOptionalProperties = relation === subtypeRelation && !(source.flags & 131072); + var requireOptionalProperties = relation === subtypeRelation && !(source.flags & 262144); for (var _i = 0; _i < properties.length; _i++) { var targetProp = properties[_i]; var sourceProp = getPropertyOfType(source, targetProp.name); @@ -13473,11 +13501,11 @@ var ts; var saveErrorInfo = errorInfo; outer: for (var _i = 0; _i < targetSignatures.length; _i++) { var t = targetSignatures[_i]; - if (!t.hasStringLiterals || target.flags & 65536) { + if (!t.hasStringLiterals || target.flags & 131072) { var localErrors = reportErrors; for (var _a = 0; _a < sourceSignatures.length; _a++) { var s = sourceSignatures[_a]; - if (!s.hasStringLiterals || source.flags & 65536) { + if (!s.hasStringLiterals || source.flags & 131072) { var related = signatureRelatedTo(s, t, localErrors); if (related) { result &= related; @@ -13769,11 +13797,11 @@ var ts; return createAnonymousType(type.symbol, members, emptyArray, emptyArray, stringIndexType, numberIndexType); } function getWidenedType(type) { - if (type.flags & 786432) { + if (type.flags & 1572864) { if (type.flags & (32 | 64)) { return anyType; } - if (type.flags & 131072) { + if (type.flags & 262144) { return getWidenedTypeOfObjectLiteral(type); } if (type.flags & 16384) { @@ -13798,11 +13826,11 @@ var ts; if (isArrayType(type)) { return reportWideningErrorsInType(type.typeArguments[0]); } - if (type.flags & 131072) { + if (type.flags & 262144) { var errorReported = false; ts.forEach(getPropertiesOfObjectType(type), function (p) { var t = getTypeOfSymbol(p); - if (t.flags & 262144) { + if (t.flags & 524288) { if (!reportWideningErrorsInType(t)) { error(p.valueDeclaration, ts.Diagnostics.Object_literal_s_property_0_implicitly_has_an_1_type, p.name, typeToString(getWidenedType(t))); } @@ -13845,7 +13873,7 @@ var ts; error(declaration, diagnostic, ts.declarationNameToString(declaration.name), typeAsString); } function reportErrorsFromWidening(declaration, type) { - if (produceDiagnostics && compilerOptions.noImplicitAny && type.flags & 262144) { + if (produceDiagnostics && compilerOptions.noImplicitAny && type.flags & 524288) { if (!reportWideningErrorsInType(type)) { reportImplicitAnyError(declaration, type); } @@ -13906,11 +13934,11 @@ var ts; } function isWithinDepthLimit(type, stack) { if (depth >= 5) { - var target_2 = type.target; + var target_1 = type.target; var count = 0; for (var i = 0; i < depth; i++) { var t = stack[i]; - if (t.flags & 4096 && t.target === target_2) { + if (t.flags & 4096 && t.target === target_1) { count++; } } @@ -14206,47 +14234,49 @@ var ts; } function getNarrowedTypeOfSymbol(symbol, node) { var type = getTypeOfSymbol(symbol); - if (node && symbol.flags & 3 && type.flags & (1 | 48128 | 16384 | 512)) { - loop: while (node.parent) { - var child = node; - node = node.parent; - var narrowedType = type; - switch (node.kind) { - case 184: - if (child !== node.expression) { - narrowedType = narrowType(type, node.expression, child === node.thenStatement); - } - break; - case 171: - if (child !== node.condition) { - narrowedType = narrowType(type, node.condition, child === node.whenTrue); - } - break; - case 170: - if (child === node.right) { - if (node.operatorToken.kind === 48) { - narrowedType = narrowType(type, node.left, true); + if (node && symbol.flags & 3) { + if (isTypeAny(type) || type.flags & (48128 | 16384 | 512)) { + loop: while (node.parent) { + var child = node; + node = node.parent; + var narrowedType = type; + switch (node.kind) { + case 184: + if (child !== node.expression) { + narrowedType = narrowType(type, node.expression, child === node.thenStatement); } - else if (node.operatorToken.kind === 49) { - narrowedType = narrowType(type, node.left, false); + break; + case 171: + if (child !== node.condition) { + narrowedType = narrowType(type, node.condition, child === node.whenTrue); } - } - break; - case 228: - case 206: - case 201: - case 135: - case 134: - case 137: - case 138: - case 136: - break loop; - } - if (narrowedType !== type) { - if (isVariableAssignedWithin(symbol, node)) { - break; + break; + case 170: + if (child === node.right) { + if (node.operatorToken.kind === 48) { + narrowedType = narrowType(type, node.left, true); + } + else if (node.operatorToken.kind === 49) { + narrowedType = narrowType(type, node.left, false); + } + } + break; + case 228: + case 206: + case 201: + case 135: + case 134: + case 137: + case 138: + case 136: + break loop; + } + if (narrowedType !== type) { + if (isVariableAssignedWithin(symbol, node)) { + break; + } + type = narrowedType; } - type = narrowedType; } } } @@ -14266,7 +14296,7 @@ var ts; } if (assumeTrue) { if (!typeInfo) { - return removeTypesFromUnionType(type, 258 | 132 | 8 | 1048576, true, false); + return removeTypesFromUnionType(type, 258 | 132 | 8 | 2097152, true, false); } if (isTypeSubtypeOf(typeInfo.type, type)) { return typeInfo.type; @@ -14303,7 +14333,7 @@ var ts; } } function narrowTypeByInstanceof(type, expr, assumeTrue) { - if (type.flags & 1 || !assumeTrue || expr.left.kind !== 65 || getResolvedSymbol(expr.left) !== symbol) { + if (isTypeAny(type) || !assumeTrue || expr.left.kind !== 65 || getResolvedSymbol(expr.left) !== symbol) { return type; } var rightType = checkExpression(expr.right); @@ -14314,7 +14344,7 @@ var ts; var prototypeProperty = getPropertyOfType(rightType, "prototype"); if (prototypeProperty) { var prototypePropertyType = getTypeOfSymbol(prototypeProperty); - if (prototypePropertyType !== anyType) { + if (!isTypeAny(prototypePropertyType)) { targetType = prototypePropertyType; } } @@ -14885,7 +14915,10 @@ var ts; return name.kind === 128 ? isNumericComputedName(name) : isNumericLiteralName(name.text); } function isNumericComputedName(name) { - return allConstituentTypesHaveKind(checkComputedPropertyName(name), 1 | 132); + return isTypeAnyOrAllConstituentTypesHaveKind(checkComputedPropertyName(name), 132); + } + function isTypeAnyOrAllConstituentTypesHaveKind(type, kind) { + return isTypeAny(type) || allConstituentTypesHaveKind(type, kind); } function isNumericLiteralName(name) { return (+name).toString() === name; @@ -14894,7 +14927,7 @@ var ts; var links = getNodeLinks(node.expression); if (!links.resolvedType) { links.resolvedType = checkExpression(node.expression); - if (!allConstituentTypesHaveKind(links.resolvedType, 1 | 132 | 258 | 1048576)) { + if (!isTypeAnyOrAllConstituentTypesHaveKind(links.resolvedType, 132 | 258 | 2097152)) { error(node, ts.Diagnostics.A_computed_property_name_must_be_of_type_string_number_symbol_or_any); } else { @@ -14949,7 +14982,7 @@ var ts; var stringIndexType = getIndexType(0); var numberIndexType = getIndexType(1); var result = createAnonymousType(node.symbol, propertiesTable, emptyArray, emptyArray, stringIndexType, numberIndexType); - result.flags |= 131072 | 524288 | (typeFlags & 262144); + result.flags |= 262144 | 1048576 | (typeFlags & 524288); return result; function getIndexType(kind) { if (contextualType && contextualTypeHasIndexSignature(contextualType, kind)) { @@ -15012,39 +15045,37 @@ var ts; } function checkPropertyAccessExpressionOrQualifiedName(node, left, right) { var type = checkExpressionOrQualifiedName(left); - if (type === unknownType) + if (isTypeAny(type)) { return type; - if (type !== anyType) { - var apparentType = getApparentType(getWidenedType(type)); - if (apparentType === unknownType) { - return unknownType; - } - var prop = getPropertyOfType(apparentType, right.text); - if (!prop) { - if (right.text) { - error(right, ts.Diagnostics.Property_0_does_not_exist_on_type_1, ts.declarationNameToString(right), typeToString(type)); - } - return unknownType; - } - getNodeLinks(node).resolvedSymbol = prop; - if (prop.parent && prop.parent.flags & 32) { - if (left.kind === 91 && getDeclarationKindFromSymbol(prop) !== 135) { - error(right, ts.Diagnostics.Only_public_and_protected_methods_of_the_base_class_are_accessible_via_the_super_keyword); - } - else { - checkClassPropertyAccess(node, left, type, prop); - } - } - return getTypeOfSymbol(prop); } - return anyType; + var apparentType = getApparentType(getWidenedType(type)); + if (apparentType === unknownType) { + return unknownType; + } + var prop = getPropertyOfType(apparentType, right.text); + if (!prop) { + if (right.text) { + error(right, ts.Diagnostics.Property_0_does_not_exist_on_type_1, ts.declarationNameToString(right), typeToString(type)); + } + return unknownType; + } + getNodeLinks(node).resolvedSymbol = prop; + if (prop.parent && prop.parent.flags & 32) { + if (left.kind === 91 && getDeclarationKindFromSymbol(prop) !== 135) { + error(right, ts.Diagnostics.Only_public_and_protected_methods_of_the_base_class_are_accessible_via_the_super_keyword); + } + else { + checkClassPropertyAccess(node, left, type, prop); + } + } + return getTypeOfSymbol(prop); } function isValidPropertyAccess(node, propertyName) { var left = node.kind === 156 ? node.expression : node.left; var type = checkExpressionOrQualifiedName(left); - if (type !== unknownType && type !== anyType) { + if (type !== unknownType && !isTypeAny(type)) { var prop = getPropertyOfType(getWidenedType(type), propertyName); if (prop && prop.parent && prop.parent.flags & 32) { if (left.kind === 91 && getDeclarationKindFromSymbol(prop) !== 135) { @@ -15085,21 +15116,21 @@ var ts; return unknownType; } if (node.argumentExpression) { - var name_9 = getPropertyNameForIndexedAccess(node.argumentExpression, indexType); - if (name_9 !== undefined) { - var prop = getPropertyOfType(objectType, name_9); + var name_10 = getPropertyNameForIndexedAccess(node.argumentExpression, indexType); + if (name_10 !== undefined) { + var prop = getPropertyOfType(objectType, name_10); if (prop) { getNodeLinks(node).resolvedSymbol = prop; return getTypeOfSymbol(prop); } else if (isConstEnum) { - error(node.argumentExpression, ts.Diagnostics.Property_0_does_not_exist_on_const_enum_1, name_9, symbolToString(objectType.symbol)); + error(node.argumentExpression, ts.Diagnostics.Property_0_does_not_exist_on_const_enum_1, name_10, symbolToString(objectType.symbol)); return unknownType; } } } - if (allConstituentTypesHaveKind(indexType, 1 | 258 | 132 | 1048576)) { - if (allConstituentTypesHaveKind(indexType, 1 | 132)) { + if (isTypeAnyOrAllConstituentTypesHaveKind(indexType, 258 | 132 | 2097152)) { + if (isTypeAnyOrAllConstituentTypesHaveKind(indexType, 132)) { var numberIndexType = getIndexTypeOfType(objectType, 1); if (numberIndexType) { return numberIndexType; @@ -15109,7 +15140,7 @@ var ts; if (stringIndexType) { return stringIndexType; } - if (compilerOptions.noImplicitAny && !compilerOptions.suppressImplicitAnyIndexErrors && objectType !== anyType) { + if (compilerOptions.noImplicitAny && !compilerOptions.suppressImplicitAnyIndexErrors && !isTypeAny(objectType)) { error(node, ts.Diagnostics.Index_signature_of_object_type_implicitly_has_an_any_type); } return anyType; @@ -15134,7 +15165,7 @@ var ts; if (!ts.isWellKnownSymbolSyntactically(expression)) { return false; } - if ((expressionType.flags & 1048576) === 0) { + if ((expressionType.flags & 2097152) === 0) { if (reportError) { error(expression, ts.Diagnostics.A_computed_property_name_of_the_form_0_must_be_of_type_symbol, ts.getTextOfNode(expression)); } @@ -15516,8 +15547,8 @@ var ts; } var callSignatures = getSignaturesOfType(apparentType, 0); var constructSignatures = getSignaturesOfType(apparentType, 1); - if (funcType === anyType || (!callSignatures.length && !constructSignatures.length && !(funcType.flags & 16384) && isTypeAssignableTo(funcType, globalFunctionType))) { - if (node.typeArguments) { + if (isTypeAny(funcType) || (!callSignatures.length && !constructSignatures.length && !(funcType.flags & 16384) && isTypeAssignableTo(funcType, globalFunctionType))) { + if (funcType !== unknownType && node.typeArguments) { error(node, ts.Diagnostics.Untyped_function_calls_may_not_accept_type_arguments); } return resolveUntypedCall(node); @@ -15541,16 +15572,16 @@ var ts; } } var expressionType = checkExpression(node.expression); - if (expressionType === anyType) { + expressionType = getApparentType(expressionType); + if (expressionType === unknownType) { + return resolveErrorCall(node); + } + if (isTypeAny(expressionType)) { if (node.typeArguments) { error(node, ts.Diagnostics.Untyped_function_calls_may_not_accept_type_arguments); } return resolveUntypedCall(node); } - expressionType = getApparentType(expressionType); - if (expressionType === unknownType) { - return resolveErrorCall(node); - } var constructSignatures = getSignaturesOfType(expressionType, 1); if (constructSignatures.length) { return resolveCall(node, constructSignatures, candidatesOutArray); @@ -15573,7 +15604,7 @@ var ts; return resolveErrorCall(node); } var callSignatures = getSignaturesOfType(apparentType, 0); - if (tagType === anyType || (!callSignatures.length && !(tagType.flags & 16384) && isTypeAssignableTo(tagType, globalFunctionType))) { + if (isTypeAny(tagType) || (!callSignatures.length && !(tagType.flags & 16384) && isTypeAssignableTo(tagType, globalFunctionType))) { return resolveUntypedCall(node); } if (!callSignatures.length) { @@ -15742,7 +15773,7 @@ var ts; if (!produceDiagnostics) { return; } - if (returnType === voidType || returnType === anyType) { + if (returnType === voidType || isTypeAny(returnType)) { return; } if (ts.nodeIsMissing(func.body) || func.body.kind !== 180) { @@ -15799,6 +15830,9 @@ var ts; checkIfNonVoidFunctionHasReturnExpressionsOrSingleThrowStatment(node, getTypeFromTypeNode(node.type)); } if (node.body) { + if (!node.type) { + getReturnTypeOfSignature(getSignatureFromDeclaration(node)); + } if (node.body.kind === 180) { checkSourceElement(node.body); } @@ -15812,7 +15846,7 @@ var ts; } } function checkArithmeticOperandType(operand, type, diagnostic) { - if (!allConstituentTypesHaveKind(type, 1 | 132)) { + if (!isTypeAnyOrAllConstituentTypesHaveKind(type, 132)) { error(operand, diagnostic); return false; } @@ -15852,8 +15886,8 @@ var ts; var index = n.argumentExpression; var symbol = findSymbol(n.expression); if (symbol && index && index.kind === 8) { - var name_10 = index.text; - var prop = getPropertyOfType(getTypeOfSymbol(symbol), name_10); + var name_11 = index.text; + var prop = getPropertyOfType(getTypeOfSymbol(symbol), name_11); return prop && (prop.flags & 3) !== 0 && (getDeclarationFlagsFromSymbol(prop) & 8192) !== 0; } return false; @@ -15898,7 +15932,7 @@ var ts; case 33: case 34: case 47: - if (someConstituentTypeHasKind(operandType, 1048576)) { + if (someConstituentTypeHasKind(operandType, 2097152)) { error(node.operand, ts.Diagnostics.The_0_operator_cannot_be_applied_to_type_symbol, ts.tokenToString(node.operator)); } return numberType; @@ -15962,19 +15996,19 @@ var ts; return (symbol.flags & 128) !== 0; } function checkInstanceOfExpression(node, leftType, rightType) { - if (allConstituentTypesHaveKind(leftType, 1049086)) { + if (allConstituentTypesHaveKind(leftType, 2097662)) { error(node.left, ts.Diagnostics.The_left_hand_side_of_an_instanceof_expression_must_be_of_type_any_an_object_type_or_a_type_parameter); } - if (!(rightType.flags & 1 || isTypeSubtypeOf(rightType, globalFunctionType))) { + if (!(isTypeAny(rightType) || isTypeSubtypeOf(rightType, globalFunctionType))) { error(node.right, ts.Diagnostics.The_right_hand_side_of_an_instanceof_expression_must_be_of_type_any_or_of_a_type_assignable_to_the_Function_interface_type); } return booleanType; } function checkInExpression(node, leftType, rightType) { - if (!allConstituentTypesHaveKind(leftType, 1 | 258 | 132 | 1048576)) { + if (!isTypeAnyOrAllConstituentTypesHaveKind(leftType, 258 | 132 | 2097152)) { error(node.left, ts.Diagnostics.The_left_hand_side_of_an_in_expression_must_be_of_type_any_string_number_or_symbol); } - if (!allConstituentTypesHaveKind(rightType, 1 | 48128 | 512)) { + if (!isTypeAnyOrAllConstituentTypesHaveKind(rightType, 48128 | 512)) { error(node.right, ts.Diagnostics.The_right_hand_side_of_an_in_expression_must_be_of_type_any_an_object_type_or_a_type_parameter); } return booleanType; @@ -15984,16 +16018,17 @@ var ts; for (var _i = 0; _i < properties.length; _i++) { var p = properties[_i]; if (p.kind === 225 || p.kind === 226) { - var name_11 = p.name; - var type = sourceType.flags & 1 ? sourceType : - getTypeOfPropertyOfType(sourceType, name_11.text) || - isNumericLiteralName(name_11.text) && getIndexTypeOfType(sourceType, 1) || + var name_12 = p.name; + var type = isTypeAny(sourceType) + ? sourceType + : getTypeOfPropertyOfType(sourceType, name_12.text) || + isNumericLiteralName(name_12.text) && getIndexTypeOfType(sourceType, 1) || getIndexTypeOfType(sourceType, 0); if (type) { - checkDestructuringAssignment(p.initializer || name_11, type); + checkDestructuringAssignment(p.initializer || name_12, type); } else { - error(name_11, ts.Diagnostics.Type_0_has_no_property_1_and_no_string_index_signature, typeToString(sourceType), ts.declarationNameToString(name_11)); + error(name_12, ts.Diagnostics.Type_0_has_no_property_1_and_no_string_index_signature, typeToString(sourceType), ts.declarationNameToString(name_12)); } } else { @@ -16010,8 +16045,9 @@ var ts; if (e.kind !== 176) { if (e.kind !== 174) { var propName = "" + i; - var type = sourceType.flags & 1 ? sourceType : - isTupleLikeType(sourceType) + var type = isTypeAny(sourceType) + ? sourceType + : isTupleLikeType(sourceType) ? getTypeOfPropertyOfType(sourceType, propName) : elementType; if (type) { @@ -16127,8 +16163,8 @@ var ts; if (allConstituentTypesHaveKind(leftType, 258) || allConstituentTypesHaveKind(rightType, 258)) { resultType = stringType; } - else if (leftType.flags & 1 || rightType.flags & 1) { - resultType = anyType; + else if (isTypeAny(leftType) || isTypeAny(rightType)) { + resultType = leftType === unknownType || rightType === unknownType ? unknownType : anyType; } if (resultType && !checkForDisallowedESSymbolOperand(operator)) { return resultType; @@ -16172,8 +16208,8 @@ var ts; return rightType; } function checkForDisallowedESSymbolOperand(operator) { - var offendingSymbolOperand = someConstituentTypeHasKind(leftType, 1048576) ? node.left : - someConstituentTypeHasKind(rightType, 1048576) ? node.right : + var offendingSymbolOperand = someConstituentTypeHasKind(leftType, 2097152) ? node.left : + someConstituentTypeHasKind(rightType, 2097152) ? node.right : undefined; if (offendingSymbolOperand) { error(offendingSymbolOperand, ts.Diagnostics.The_0_operator_cannot_be_applied_to_type_symbol, ts.tokenToString(operator)); @@ -16952,7 +16988,7 @@ var ts; if (node && node.kind === 142) { var type = getTypeFromTypeNode(node); var shouldCheckIfUnknownType = type === unknownType && compilerOptions.isolatedModules; - if (!type || (!shouldCheckIfUnknownType && type.flags & (1048703 | 132 | 258))) { + if (!type || (!shouldCheckIfUnknownType && type.flags & (2097279 | 132 | 258))) { return; } if (shouldCheckIfUnknownType || type.symbol.valueDeclaration) { @@ -17180,8 +17216,8 @@ var ts; container.kind === 206 || container.kind === 228); if (!namesShareScope) { - var name_12 = symbolToString(localDeclarationSymbol); - error(node, ts.Diagnostics.Cannot_initialize_outer_scoped_variable_0_in_the_same_scope_as_block_scoped_declaration_1, name_12, name_12); + var name_13 = symbolToString(localDeclarationSymbol); + error(node, ts.Diagnostics.Cannot_initialize_outer_scoped_variable_0_in_the_same_scope_as_block_scoped_declaration_1, name_13, name_13); } } } @@ -17368,7 +17404,7 @@ var ts; if (varExpr.kind === 154 || varExpr.kind === 155) { error(varExpr, ts.Diagnostics.The_left_hand_side_of_a_for_in_statement_cannot_be_a_destructuring_pattern); } - else if (!allConstituentTypesHaveKind(leftType, 1 | 258)) { + else if (!isTypeAnyOrAllConstituentTypesHaveKind(leftType, 258)) { error(varExpr, ts.Diagnostics.The_left_hand_side_of_a_for_in_statement_must_be_of_type_string_or_any); } else { @@ -17376,7 +17412,7 @@ var ts; } } var rightType = checkExpression(node.expression); - if (!allConstituentTypesHaveKind(rightType, 1 | 48128 | 512)) { + if (!isTypeAnyOrAllConstituentTypesHaveKind(rightType, 48128 | 512)) { error(node.expression, ts.Diagnostics.The_right_hand_side_of_a_for_in_statement_must_be_of_type_any_an_object_type_or_a_type_parameter); } checkSourceElement(node.statement); @@ -17393,7 +17429,7 @@ var ts; return checkIteratedTypeOrElementType(expressionType, rhsExpression, true); } function checkIteratedTypeOrElementType(inputType, errorNode, allowStringInput) { - if (inputType.flags & 1) { + if (isTypeAny(inputType)) { return inputType; } if (languageVersion >= 2) { @@ -17419,7 +17455,7 @@ var ts; return elementType || anyType; } function getElementTypeOfIterable(type, errorNode) { - if (type.flags & 1) { + if (isTypeAny(type)) { return undefined; } var typeAsIterable = type; @@ -17429,7 +17465,7 @@ var ts; } else { var iteratorFunction = getTypeOfPropertyOfType(type, ts.getPropertyNameForKnownSymbolName("iterator")); - if (iteratorFunction && iteratorFunction.flags & 1) { + if (isTypeAny(iteratorFunction)) { return undefined; } var iteratorFunctionSignatures = iteratorFunction ? getSignaturesOfType(iteratorFunction, 0) : emptyArray; @@ -17445,7 +17481,7 @@ var ts; return typeAsIterable.iterableElementType; } function getElementTypeOfIterator(type, errorNode) { - if (type.flags & 1) { + if (isTypeAny(type)) { return undefined; } var typeAsIterator = type; @@ -17455,7 +17491,7 @@ var ts; } else { var iteratorNextFunction = getTypeOfPropertyOfType(type, "next"); - if (iteratorNextFunction && iteratorNextFunction.flags & 1) { + if (isTypeAny(iteratorNextFunction)) { return undefined; } var iteratorNextFunctionSignatures = iteratorNextFunction ? getSignaturesOfType(iteratorNextFunction, 0) : emptyArray; @@ -17466,7 +17502,7 @@ var ts; return undefined; } var iteratorNextResult = getUnionType(ts.map(iteratorNextFunctionSignatures, getReturnTypeOfSignature)); - if (iteratorNextResult.flags & 1) { + if (isTypeAny(iteratorNextResult)) { return undefined; } var iteratorNextValue = getTypeOfPropertyOfType(iteratorNextResult, "value"); @@ -17482,7 +17518,7 @@ var ts; return typeAsIterator.iteratorElementType; } function getElementTypeOfIterableIterator(type) { - if (type.flags & 1) { + if (isTypeAny(type)) { return undefined; } if ((type.flags & 4096) && type.target === globalIterableIteratorType) { @@ -18961,9 +18997,9 @@ var ts; function getRootSymbols(symbol) { if (symbol.flags & 268435456) { var symbols = []; - var name_13 = symbol.name; + var name_14 = symbol.name; ts.forEach(getSymbolLinks(symbol).unionType.types, function (t) { - symbols.push(getPropertyOfType(t, name_13)); + symbols.push(getPropertyOfType(t, name_14)); }); return symbols; } @@ -19141,7 +19177,7 @@ var ts; else if (type.flags & 8192) { return "Array"; } - else if (type.flags & 1048576) { + else if (type.flags & 2097152) { return "Symbol"; } else if (type === unknownType) { @@ -19386,20 +19422,20 @@ var ts; if (impotClause.namedBindings) { var nameBindings = impotClause.namedBindings; if (nameBindings.kind === 212) { - var name_14 = nameBindings.name; - if (isReservedWordInStrictMode(name_14)) { - var nameText = ts.declarationNameToString(name_14); - return grammarErrorOnNode(name_14, ts.Diagnostics.Identifier_expected_0_is_a_reserved_word_in_strict_mode, nameText); + var name_15 = nameBindings.name; + if (isReservedWordInStrictMode(name_15)) { + var nameText = ts.declarationNameToString(name_15); + return grammarErrorOnNode(name_15, ts.Diagnostics.Identifier_expected_0_is_a_reserved_word_in_strict_mode, nameText); } } else if (nameBindings.kind === 213) { var reportError = false; for (var _i = 0, _a = nameBindings.elements; _i < _a.length; _i++) { var element = _a[_i]; - var name_15 = element.name; - if (isReservedWordInStrictMode(name_15)) { - var nameText = ts.declarationNameToString(name_15); - reportError = reportError || grammarErrorOnNode(name_15, ts.Diagnostics.Identifier_expected_0_is_a_reserved_word_in_strict_mode, nameText); + var name_16 = element.name; + if (isReservedWordInStrictMode(name_16)) { + var nameText = ts.declarationNameToString(name_16); + reportError = reportError || grammarErrorOnNode(name_16, ts.Diagnostics.Identifier_expected_0_is_a_reserved_word_in_strict_mode, nameText); } } return reportError; @@ -19858,17 +19894,17 @@ var ts; var inStrictMode = (node.parserContextFlags & 1) !== 0; for (var _i = 0, _a = node.properties; _i < _a.length; _i++) { var prop = _a[_i]; - var name_16 = prop.name; + var name_17 = prop.name; if (prop.kind === 176 || - name_16.kind === 128) { - checkGrammarComputedPropertyName(name_16); + name_17.kind === 128) { + checkGrammarComputedPropertyName(name_17); continue; } var currentKind = void 0; if (prop.kind === 225 || prop.kind === 226) { checkGrammarForInvalidQuestionMark(prop, prop.questionToken, ts.Diagnostics.An_object_member_cannot_be_declared_optional); - if (name_16.kind === 7) { - checkGrammarNumericLiteral(name_16); + if (name_17.kind === 7) { + checkGrammarNumericLiteral(name_17); } currentKind = Property; } @@ -19884,26 +19920,26 @@ var ts; else { ts.Debug.fail("Unexpected syntax kind:" + prop.kind); } - if (!ts.hasProperty(seen, name_16.text)) { - seen[name_16.text] = currentKind; + if (!ts.hasProperty(seen, name_17.text)) { + seen[name_17.text] = currentKind; } else { - var existingKind = seen[name_16.text]; + var existingKind = seen[name_17.text]; if (currentKind === Property && existingKind === Property) { if (inStrictMode) { - grammarErrorOnNode(name_16, ts.Diagnostics.An_object_literal_cannot_have_multiple_properties_with_the_same_name_in_strict_mode); + grammarErrorOnNode(name_17, ts.Diagnostics.An_object_literal_cannot_have_multiple_properties_with_the_same_name_in_strict_mode); } } else if ((currentKind & GetOrSetAccessor) && (existingKind & GetOrSetAccessor)) { if (existingKind !== GetOrSetAccessor && currentKind !== existingKind) { - seen[name_16.text] = currentKind | existingKind; + seen[name_17.text] = currentKind | existingKind; } else { - return grammarErrorOnNode(name_16, ts.Diagnostics.An_object_literal_cannot_have_multiple_get_Slashset_accessors_with_the_same_name); + return grammarErrorOnNode(name_17, ts.Diagnostics.An_object_literal_cannot_have_multiple_get_Slashset_accessors_with_the_same_name); } } else { - return grammarErrorOnNode(name_16, ts.Diagnostics.An_object_literal_cannot_have_property_and_accessor_with_the_same_name); + return grammarErrorOnNode(name_17, ts.Diagnostics.An_object_literal_cannot_have_property_and_accessor_with_the_same_name); } } } @@ -20682,9 +20718,9 @@ var ts; } var count = 0; while (true) { - var name_17 = baseName + "_" + (++count); - if (!ts.hasProperty(currentSourceFile.identifiers, name_17)) { - return name_17; + var name_18 = baseName + "_" + (++count); + if (!ts.hasProperty(currentSourceFile.identifiers, name_18)) { + return name_18; } } } @@ -21768,9 +21804,9 @@ var ts; var count = tempFlags & 268435455; tempFlags++; if (count !== 8 && count !== 13) { - var name_18 = count < 26 ? "_" + String.fromCharCode(97 + count) : "_" + (count - 26); - if (isUniqueName(name_18)) { - return name_18; + var name_19 = count < 26 ? "_" + String.fromCharCode(97 + count) : "_" + (count - 26); + if (isUniqueName(name_19)) { + return name_19; } } } @@ -21798,8 +21834,8 @@ var ts; } function generateNameForModuleOrEnum(node) { if (node.name.kind === 65) { - var name_19 = node.name.text; - assignGeneratedName(node, isUniqueLocalName(name_19, node) ? name_19 : makeUniqueName(name_19)); + var name_20 = node.name.text; + assignGeneratedName(node, isUniqueLocalName(name_20, node) ? name_20 : makeUniqueName(name_20)); } } function generateNameForImportOrExportDeclaration(node) { @@ -21985,8 +22021,8 @@ var ts; if (scopeName) { var parentIndex = getSourceMapNameIndex(); if (parentIndex !== -1) { - var name_20 = node.name; - if (!name_20 || name_20.kind !== 128) { + var name_21 = node.name; + if (!name_21 || name_21.kind !== 128) { scopeName = "." + scopeName; } scopeName = sourceMapData.sourceMapNames[parentIndex] + scopeName; @@ -22013,9 +22049,9 @@ var ts; node.kind === 202 || node.kind === 205) { if (node.name) { - var name_21 = node.name; - scopeName = name_21.kind === 128 - ? ts.getTextOfNode(name_21) + var name_22 = node.name; + scopeName = name_22.kind === 128 + ? ts.getTextOfNode(name_22) : node.name.text; } recordScopeNameStart(scopeName); @@ -22865,7 +22901,12 @@ var ts; return result; } function parenthesizeForAccess(expr) { - if (ts.isLeftHandSideExpression(expr) && expr.kind !== 159 && expr.kind !== 7) { + while (expr.kind === 161) { + expr = expr.expression; + } + if (ts.isLeftHandSideExpression(expr) && + expr.kind !== 159 && + expr.kind !== 7) { return expr; } var node = ts.createSynthesizedNode(162); @@ -23086,7 +23127,7 @@ var ts; } } function emitParenExpression(node) { - if (!node.parent || node.parent.kind !== 164) { + if (!ts.nodeIsSynthesized(node) && node.parent.kind !== 164) { if (node.expression.kind === 161) { var operand = node.expression.expression; while (operand.kind == 161) { @@ -24042,12 +24083,12 @@ var ts; function emitParameter(node) { if (languageVersion < 2) { if (ts.isBindingPattern(node.name)) { - var name_22 = createTempVariable(0); + var name_23 = createTempVariable(0); if (!tempParameters) { tempParameters = []; } - tempParameters.push(name_22); - emit(name_22); + tempParameters.push(name_23); + emit(name_23); } else { emit(node.name); @@ -25507,8 +25548,8 @@ var ts; else { for (var _c = 0, _d = node.exportClause.elements; _c < _d.length; _c++) { var specifier = _d[_c]; - var name_23 = (specifier.propertyName || specifier.name).text; - (exportSpecifiers[name_23] || (exportSpecifiers[name_23] = [])).push(specifier); + var name_24 = (specifier.propertyName || specifier.name).text; + (exportSpecifiers[name_24] || (exportSpecifiers[name_24] = [])).push(specifier); } } break; @@ -25681,11 +25722,11 @@ var ts; var seen = {}; for (var i = 0; i < hoistedVars.length; ++i) { var local = hoistedVars[i]; - var name_24 = local.kind === 65 + var name_25 = local.kind === 65 ? local : local.name; - if (name_24) { - var text = ts.unescapeIdentifier(name_24.text); + if (name_25) { + var text = ts.unescapeIdentifier(name_25.text); if (ts.hasProperty(seen, text)) { continue; } @@ -25764,15 +25805,15 @@ var ts; } if (node.kind === 199 || node.kind === 153) { if (shouldHoistVariable(node, false)) { - var name_25 = node.name; - if (name_25.kind === 65) { + var name_26 = node.name; + if (name_26.kind === 65) { if (!hoistedVars) { hoistedVars = []; } - hoistedVars.push(name_25); + hoistedVars.push(name_26); } else { - ts.forEachChild(name_25, visit); + ts.forEachChild(name_26, visit); } } return; @@ -26445,8 +26486,6 @@ var ts; ts.ioReadTime = 0; ts.ioWriteTime = 0; ts.version = "1.5.3"; - var carriageReturnLineFeed = "\r\n"; - var lineFeed = "\n"; function findConfigFile(searchPath) { var fileName = "tsconfig.json"; while (true) { @@ -26517,9 +26556,7 @@ var ts; } } } - var newLine = options.newLine === 0 ? carriageReturnLineFeed : - options.newLine === 1 ? lineFeed : - ts.sys.newLine; + var newLine = ts.getNewLineCharacter(options); return { getSourceFile: getSourceFile, getDefaultLibFileName: function (options) { return ts.combinePaths(ts.getDirectoryPath(ts.normalizePath(ts.sys.getExecutingFilePath())), ts.getDefaultLibFileName(options)); }, @@ -26587,6 +26624,7 @@ var ts; getGlobalDiagnostics: getGlobalDiagnostics, getSemanticDiagnostics: getSemanticDiagnostics, getDeclarationDiagnostics: getDeclarationDiagnostics, + getCompilerOptionsDiagnostics: getCompilerOptionsDiagnostics, getTypeChecker: getTypeChecker, getDiagnosticsProducingTypeChecker: getDiagnosticsProducingTypeChecker, getCommonSourceDirectory: function () { return commonSourceDirectory; }, @@ -26667,6 +26705,11 @@ var ts; return ts.getDeclarationDiagnostics(getEmitHost(writeFile), resolver, sourceFile); } } + function getCompilerOptionsDiagnostics() { + var allDiagnostics = []; + ts.addRange(allDiagnostics, diagnostics.getGlobalDiagnostics()); + return ts.sortAndDeduplicateDiagnostics(allDiagnostics); + } function getGlobalDiagnostics() { var typeChecker = getDiagnosticsProducingTypeChecker(); var allDiagnostics = []; @@ -27479,10 +27522,10 @@ var ts; ts.forEach(program.getSourceFiles(), function (sourceFile) { cancellationToken.throwIfCancellationRequested(); var nameToDeclarations = sourceFile.getNamedDeclarations(); - for (var name_26 in nameToDeclarations) { - var declarations = ts.getProperty(nameToDeclarations, name_26); + for (var name_27 in nameToDeclarations) { + var declarations = ts.getProperty(nameToDeclarations, name_27); if (declarations) { - var matches = patternMatcher.getMatchesForLastSegmentOfPattern(name_26); + var matches = patternMatcher.getMatchesForLastSegmentOfPattern(name_27); if (!matches) { continue; } @@ -27493,14 +27536,14 @@ var ts; if (!containers) { return undefined; } - matches = patternMatcher.getMatches(containers, name_26); + matches = patternMatcher.getMatches(containers, name_27); if (!matches) { continue; } } var fileName = sourceFile.fileName; var matchKind = bestMatchKind(matches); - rawItems.push({ name: name_26, fileName: fileName, matchKind: matchKind, isCaseSensitive: allMatchesAreCaseSensitive(matches), declaration: declaration }); + rawItems.push({ name: name_27, fileName: fileName, matchKind: matchKind, isCaseSensitive: allMatchesAreCaseSensitive(matches), declaration: declaration }); } } } @@ -27830,9 +27873,9 @@ var ts; case 199: case 153: var variableDeclarationNode; - var name_27; + var name_28; if (node.kind === 153) { - name_27 = node.name; + name_28 = node.name; variableDeclarationNode = node; while (variableDeclarationNode && variableDeclarationNode.kind !== 199) { variableDeclarationNode = variableDeclarationNode.parent; @@ -27842,16 +27885,16 @@ var ts; else { ts.Debug.assert(!ts.isBindingPattern(node.name)); variableDeclarationNode = node; - name_27 = node.name; + name_28 = node.name; } if (ts.isConst(variableDeclarationNode)) { - return createItem(node, getTextOfNode(name_27), ts.ScriptElementKind.constElement); + return createItem(node, getTextOfNode(name_28), ts.ScriptElementKind.constElement); } else if (ts.isLet(variableDeclarationNode)) { - return createItem(node, getTextOfNode(name_27), ts.ScriptElementKind.letElement); + return createItem(node, getTextOfNode(name_28), ts.ScriptElementKind.letElement); } else { - return createItem(node, getTextOfNode(name_27), ts.ScriptElementKind.variableElement); + return createItem(node, getTextOfNode(name_28), ts.ScriptElementKind.variableElement); } case 136: return createItem(node, "constructor", ts.ScriptElementKind.constructorImplementationElement); @@ -29845,9 +29888,9 @@ var ts; } Rules.prototype.getRuleName = function (rule) { var o = this; - for (var name_28 in o) { - if (o[name_28] === rule) { - return name_28; + for (var name_29 in o) { + if (o[name_29] === rule) { + return name_29; } } throw new Error("Unknown rule"); @@ -32389,11 +32432,14 @@ var ts; var options = compilerOptions ? ts.clone(compilerOptions) : getDefaultCompilerOptions(); options.isolatedModules = true; options.allowNonTsExtensions = true; + options.noLib = true; + options.noResolve = true; var inputFileName = fileName || "module.ts"; var sourceFile = ts.createSourceFile(inputFileName, input, options.target); if (diagnostics && sourceFile.parseDiagnostics) { diagnostics.push.apply(diagnostics, sourceFile.parseDiagnostics); } + var newLine = ts.getNewLineCharacter(options); var outputText; var compilerHost = { getSourceFile: function (fileName, target) { return fileName === inputFileName ? sourceFile : undefined; }, @@ -32405,11 +32451,11 @@ var ts; useCaseSensitiveFileNames: function () { return false; }, getCanonicalFileName: function (fileName) { return fileName; }, getCurrentDirectory: function () { return ""; }, - getNewLine: function () { return (ts.sys && ts.sys.newLine) || "\r\n"; } + getNewLine: function () { return newLine; } }; var program = ts.createProgram([inputFileName], options, compilerHost); if (diagnostics) { - diagnostics.push.apply(diagnostics, program.getGlobalDiagnostics()); + diagnostics.push.apply(diagnostics, program.getCompilerOptionsDiagnostics()); } program.emit(); ts.Debug.assert(outputText !== undefined, "Output generation failed"); @@ -33589,10 +33635,10 @@ var ts; for (var _i = 0, _a = program.getSourceFiles(); _i < _a.length; _i++) { var sourceFile = _a[_i]; var nameTable = getNameTable(sourceFile); - for (var name_29 in nameTable) { - if (!allNames[name_29]) { - allNames[name_29] = name_29; - var displayName = getCompletionEntryDisplayName(name_29, target, true); + for (var name_30 in nameTable) { + if (!allNames[name_30]) { + allNames[name_30] = name_30; + var displayName = getCompletionEntryDisplayName(name_30, target, true); if (displayName) { var entry = { name: displayName, @@ -35271,17 +35317,17 @@ var ts; if (isNameOfPropertyAssignment(node)) { var objectLiteral = node.parent.parent; var contextualType = typeChecker.getContextualType(objectLiteral); - var name_30 = node.text; + var name_31 = node.text; if (contextualType) { if (contextualType.flags & 16384) { - var unionProperty = contextualType.getProperty(name_30); + var unionProperty = contextualType.getProperty(name_31); if (unionProperty) { return [unionProperty]; } else { var result_4 = []; ts.forEach(contextualType.types, function (t) { - var symbol = t.getProperty(name_30); + var symbol = t.getProperty(name_31); if (symbol) { result_4.push(symbol); } @@ -35290,7 +35336,7 @@ var ts; } } else { - var symbol_1 = contextualType.getProperty(name_30); + var symbol_1 = contextualType.getProperty(name_31); if (symbol_1) { return [symbol_1]; } diff --git a/bin/typescript.d.ts b/bin/typescript.d.ts index 58b03102d38..c8e4ae8bc69 100644 --- a/bin/typescript.d.ts +++ b/bin/typescript.d.ts @@ -857,7 +857,7 @@ declare module "typescript" { getCurrentDirectory(): string; } interface ParseConfigHost { - readDirectory(rootDir: string, extension: string): string[]; + readDirectory(rootDir: string, extension: string, exclude: string[]): string[]; } interface WriteFileCallback { (fileName: string, data: string, writeByteOrderMark: boolean, onError?: (message: string) => void): void; @@ -1091,8 +1091,9 @@ declare module "typescript" { Tuple = 8192, Union = 16384, Anonymous = 32768, - ObjectLiteral = 131072, - ESSymbol = 1048576, + Instantiated = 65536, + ObjectLiteral = 262144, + ESSymbol = 2097152, StringLike = 258, NumberLike = 132, ObjectType = 48128, @@ -1281,7 +1282,7 @@ declare module "typescript" { createDirectory(path: string): void; getExecutingFilePath(): string; getCurrentDirectory(): string; - readDirectory(path: string, extension?: string): string[]; + readDirectory(path: string, extension?: string, exclude?: string[]): string[]; getMemoryUsage?(): number; exit(exitCode?: number): void; } diff --git a/bin/typescript.js b/bin/typescript.js index 2b3f25998a5..3dd6dd919be 100644 --- a/bin/typescript.js +++ b/bin/typescript.js @@ -532,23 +532,24 @@ var ts; TypeFlags[TypeFlags["Tuple"] = 8192] = "Tuple"; TypeFlags[TypeFlags["Union"] = 16384] = "Union"; TypeFlags[TypeFlags["Anonymous"] = 32768] = "Anonymous"; + TypeFlags[TypeFlags["Instantiated"] = 65536] = "Instantiated"; /* @internal */ - TypeFlags[TypeFlags["FromSignature"] = 65536] = "FromSignature"; - TypeFlags[TypeFlags["ObjectLiteral"] = 131072] = "ObjectLiteral"; + TypeFlags[TypeFlags["FromSignature"] = 131072] = "FromSignature"; + TypeFlags[TypeFlags["ObjectLiteral"] = 262144] = "ObjectLiteral"; /* @internal */ - TypeFlags[TypeFlags["ContainsUndefinedOrNull"] = 262144] = "ContainsUndefinedOrNull"; + TypeFlags[TypeFlags["ContainsUndefinedOrNull"] = 524288] = "ContainsUndefinedOrNull"; /* @internal */ - TypeFlags[TypeFlags["ContainsObjectLiteral"] = 524288] = "ContainsObjectLiteral"; - TypeFlags[TypeFlags["ESSymbol"] = 1048576] = "ESSymbol"; + TypeFlags[TypeFlags["ContainsObjectLiteral"] = 1048576] = "ContainsObjectLiteral"; + TypeFlags[TypeFlags["ESSymbol"] = 2097152] = "ESSymbol"; /* @internal */ - TypeFlags[TypeFlags["Intrinsic"] = 1048703] = "Intrinsic"; + TypeFlags[TypeFlags["Intrinsic"] = 2097279] = "Intrinsic"; /* @internal */ - TypeFlags[TypeFlags["Primitive"] = 1049086] = "Primitive"; + TypeFlags[TypeFlags["Primitive"] = 2097662] = "Primitive"; TypeFlags[TypeFlags["StringLike"] = 258] = "StringLike"; TypeFlags[TypeFlags["NumberLike"] = 132] = "NumberLike"; TypeFlags[TypeFlags["ObjectType"] = 48128] = "ObjectType"; /* @internal */ - TypeFlags[TypeFlags["RequiresWidening"] = 786432] = "RequiresWidening"; + TypeFlags[TypeFlags["RequiresWidening"] = 1572864] = "RequiresWidening"; })(ts.TypeFlags || (ts.TypeFlags = {})); var TypeFlags = ts.TypeFlags; (function (SignatureKind) { @@ -1506,6 +1507,9 @@ var ts; fileStream.Close(); } } + function getCanonicalPath(path) { + return path.toLowerCase(); + } function getNames(collection) { var result = []; for (var e = new Enumerator(collection); !e.atEnd(); e.moveNext()) { @@ -1513,23 +1517,28 @@ var ts; } return result.sort(); } - function readDirectory(path, extension) { + function readDirectory(path, extension, exclude) { var result = []; + exclude = ts.map(exclude, function (s) { return getCanonicalPath(ts.combinePaths(path, s)); }); visitDirectory(path); return result; function visitDirectory(path) { var folder = fso.GetFolder(path || "."); var files = getNames(folder.files); for (var _i = 0; _i < files.length; _i++) { - var name_1 = files[_i]; - if (!extension || ts.fileExtensionIs(name_1, extension)) { - result.push(ts.combinePaths(path, name_1)); + var current = files[_i]; + var name_1 = ts.combinePaths(path, current); + if ((!extension || ts.fileExtensionIs(name_1, extension)) && !ts.contains(exclude, getCanonicalPath(name_1))) { + result.push(name_1); } } var subfolders = getNames(folder.subfolders); for (var _a = 0; _a < subfolders.length; _a++) { var current = subfolders[_a]; - visitDirectory(ts.combinePaths(path, current)); + var name_2 = ts.combinePaths(path, current); + if (!ts.contains(exclude, getCanonicalPath(name_2))) { + visitDirectory(name_2); + } } } } @@ -1614,8 +1623,12 @@ var ts; } _fs.writeFileSync(fileName, data, "utf8"); } - function readDirectory(path, extension) { + function getCanonicalPath(path) { + return useCaseSensitiveFileNames ? path.toLowerCase() : path; + } + function readDirectory(path, extension, exclude) { var result = []; + exclude = ts.map(exclude, function (s) { return getCanonicalPath(ts.combinePaths(path, s)); }); visitDirectory(path); return result; function visitDirectory(path) { @@ -1624,14 +1637,16 @@ var ts; for (var _i = 0; _i < files.length; _i++) { var current = files[_i]; var name = ts.combinePaths(path, current); - var stat = _fs.statSync(name); - if (stat.isFile()) { - if (!extension || ts.fileExtensionIs(name, extension)) { - result.push(name); + if (!ts.contains(exclude, getCanonicalPath(name))) { + var stat = _fs.statSync(name); + if (stat.isFile()) { + if (!extension || ts.fileExtensionIs(name, extension)) { + result.push(name); + } + } + else if (stat.isDirectory()) { + directories.push(name); } - } - else if (stat.isDirectory()) { - directories.push(name); } } for (var _a = 0; _a < directories.length; _a++) { @@ -2239,7 +2254,7 @@ var ts; Object_literal_s_property_0_implicitly_has_an_1_type: { code: 7018, category: ts.DiagnosticCategory.Error, key: "Object literal's property '{0}' implicitly has an '{1}' type." }, Rest_parameter_0_implicitly_has_an_any_type: { code: 7019, category: ts.DiagnosticCategory.Error, key: "Rest parameter '{0}' implicitly has an 'any[]' type." }, Call_signature_which_lacks_return_type_annotation_implicitly_has_an_any_return_type: { code: 7020, category: ts.DiagnosticCategory.Error, key: "Call signature, which lacks return-type annotation, implicitly has an 'any' return type." }, - _0_implicitly_has_type_any_because_it_is_does_not_have_a_type_annotation_and_is_referenced_directly_or_indirectly_in_its_own_initializer: { code: 7022, category: ts.DiagnosticCategory.Error, key: "'{0}' implicitly has type 'any' because it is does not have a type annotation and is referenced directly or indirectly in its own initializer." }, + _0_implicitly_has_type_any_because_it_does_not_have_a_type_annotation_and_is_referenced_directly_or_indirectly_in_its_own_initializer: { code: 7022, category: ts.DiagnosticCategory.Error, key: "'{0}' implicitly has type 'any' because it does not have a type annotation and is referenced directly or indirectly in its own initializer." }, _0_implicitly_has_return_type_any_because_it_does_not_have_a_return_type_annotation_and_is_referenced_directly_or_indirectly_in_one_of_its_return_expressions: { code: 7023, category: ts.DiagnosticCategory.Error, key: "'{0}' implicitly has return type 'any' because it does not have a return type annotation and is referenced directly or indirectly in one of its return expressions." }, Function_implicitly_has_return_type_any_because_it_does_not_have_a_return_type_annotation_and_is_referenced_directly_or_indirectly_in_one_of_its_return_expressions: { code: 7024, category: ts.DiagnosticCategory.Error, key: "Function implicitly has return type 'any' because it does not have a return type annotation and is referenced directly or indirectly in one of its return expressions." }, Generator_implicitly_has_type_0_because_it_does_not_yield_any_values_Consider_supplying_a_return_type: { code: 7025, category: ts.DiagnosticCategory.Error, key: "Generator implicitly has type '{0}' because it does not yield any values. Consider supplying a return type." }, @@ -2466,9 +2481,9 @@ var ts; } function makeReverseMap(source) { var result = []; - for (var name_2 in source) { - if (source.hasOwnProperty(name_2)) { - result[source[name_2]] = name_2; + for (var name_3 in source) { + if (source.hasOwnProperty(name_3)) { + result[source[name_3]] = name_3; } } return result; @@ -4815,11 +4830,11 @@ var ts; return; default: if (isFunctionLike(node)) { - var name_3 = node.name; - if (name_3 && name_3.kind === 128 /* ComputedPropertyName */) { + var name_4 = node.name; + if (name_4 && name_4.kind === 128 /* ComputedPropertyName */) { // Note that we will not include methods/accessors of a class because they would require // first descending into the class. This is by design. - traverse(name_3.expression); + traverse(name_4.expression); return; } } @@ -5268,8 +5283,8 @@ var ts; return ts.forEach(docComment.tags, function (t) { if (t.kind === 247 /* JSDocParameterTag */) { var parameterTag = t; - var name_4 = parameterTag.preParameterName || parameterTag.postParameterName; - if (name_4.text === parameterName) { + var name_5 = parameterTag.preParameterName || parameterTag.postParameterName; + if (name_5.text === parameterName) { return t; } } @@ -6159,6 +6174,21 @@ var ts; return result; } ts.convertToBase64 = convertToBase64; + var carriageReturnLineFeed = "\r\n"; + var lineFeed = "\n"; + function getNewLineCharacter(options) { + if (options.newLine === 0 /* CarriageReturnLineFeed */) { + return carriageReturnLineFeed; + } + else if (options.newLine === 1 /* LineFeed */) { + return lineFeed; + } + else if (ts.sys) { + return ts.sys.newLine; + } + return carriageReturnLineFeed; + } + ts.getNewLineCharacter = getNewLineCharacter; })(ts || (ts = {})); var ts; (function (ts) { @@ -10274,8 +10304,8 @@ var ts; } if (decorators) { // treat this as a property declaration with a missing name. - var name_5 = createMissingNode(65 /* Identifier */, true, ts.Diagnostics.Declaration_expected); - return parsePropertyDeclaration(fullStart, decorators, modifiers, name_5, undefined); + var name_6 = createMissingNode(65 /* Identifier */, true, ts.Diagnostics.Declaration_expected); + return parsePropertyDeclaration(fullStart, decorators, modifiers, name_6, undefined); } // 'isClassMemberStart' should have hinted not to attempt parsing. ts.Debug.fail("Should not have attempted to parse class member declaration."); @@ -11225,13 +11255,13 @@ var ts; while (true) { skipWhitespace(); var startPos = pos; - var name_6 = scanIdentifier(); - if (!name_6) { + var name_7 = scanIdentifier(); + if (!name_7) { parseErrorAtPosition(startPos, 0, ts.Diagnostics.Identifier_expected); return undefined; } - var typeParameter = createNode(129 /* TypeParameter */, name_6.pos); - typeParameter.name = name_6; + var typeParameter = createNode(129 /* TypeParameter */, name_7.pos); + typeParameter.name = name_7; finishNode(typeParameter, pos); typeParameters.push(typeParameter); skipWhitespace(); @@ -11816,10 +11846,10 @@ var ts; var stringType = createIntrinsicType(2 /* String */, "string"); var numberType = createIntrinsicType(4 /* Number */, "number"); var booleanType = createIntrinsicType(8 /* Boolean */, "boolean"); - var esSymbolType = createIntrinsicType(1048576 /* ESSymbol */, "symbol"); + var esSymbolType = createIntrinsicType(2097152 /* ESSymbol */, "symbol"); var voidType = createIntrinsicType(16 /* Void */, "void"); - var undefinedType = createIntrinsicType(32 /* Undefined */ | 262144 /* ContainsUndefinedOrNull */, "undefined"); - var nullType = createIntrinsicType(64 /* Null */ | 262144 /* ContainsUndefinedOrNull */, "null"); + var undefinedType = createIntrinsicType(32 /* Undefined */ | 524288 /* ContainsUndefinedOrNull */, "undefined"); + var nullType = createIntrinsicType(64 /* Null */ | 524288 /* ContainsUndefinedOrNull */, "null"); var unknownType = createIntrinsicType(1 /* Any */, "unknown"); var circularType = createIntrinsicType(1 /* Any */, "__circular__"); var emptyObjectType = createAnonymousType(undefined, emptySymbols, emptyArray, emptyArray, undefined, undefined); @@ -11876,7 +11906,7 @@ var ts; }, "symbol": { type: esSymbolType, - flags: 1048576 /* ESSymbol */ + flags: 2097152 /* ESSymbol */ } }; function getEmitResolver(sourceFile) { @@ -12383,15 +12413,15 @@ var ts; var moduleSymbol = resolveExternalModuleName(node, node.moduleSpecifier); var targetSymbol = resolveESModuleSymbol(moduleSymbol, node.moduleSpecifier); if (targetSymbol) { - var name_7 = specifier.propertyName || specifier.name; - if (name_7.text) { - var symbolFromModule = getExportOfModule(targetSymbol, name_7.text); - var symbolFromVariable = getPropertyOfVariable(targetSymbol, name_7.text); + var name_8 = specifier.propertyName || specifier.name; + if (name_8.text) { + var symbolFromModule = getExportOfModule(targetSymbol, name_8.text); + var symbolFromVariable = getPropertyOfVariable(targetSymbol, name_8.text); var symbol = symbolFromModule && symbolFromVariable ? combineValueAndTypeSymbols(symbolFromVariable, symbolFromModule) : symbolFromModule || symbolFromVariable; if (!symbol) { - error(name_7, ts.Diagnostics.Module_0_has_no_exported_member_1, getFullyQualifiedName(moduleSymbol), ts.declarationNameToString(name_7)); + error(name_8, ts.Diagnostics.Module_0_has_no_exported_member_1, getFullyQualifiedName(moduleSymbol), ts.declarationNameToString(name_8)); } return symbol; } @@ -13097,15 +13127,16 @@ var ts; } return appendParentTypeArgumentsAndSymbolName(symbol); } - function buildTypeDisplay(type, writer, enclosingDeclaration, globalFlags, typeStack) { + function buildTypeDisplay(type, writer, enclosingDeclaration, globalFlags, symbolStack) { var globalFlagsToPass = globalFlags & 16 /* WriteOwnNameForAnyLike */; return writeType(type, globalFlags); function writeType(type, flags) { // Write undefined/null type as any - if (type.flags & 1048703 /* Intrinsic */) { + if (type.flags & 2097279 /* Intrinsic */) { // Special handling for unknown / resolving types, they should show up as any and not unknown or __resolving - writer.writeKeyword(!(globalFlags & 16 /* WriteOwnNameForAnyLike */) && - (type.flags & 1 /* Any */) ? "any" : type.intrinsicName); + writer.writeKeyword(!(globalFlags & 16 /* WriteOwnNameForAnyLike */) && isTypeAny(type) + ? "any" + : type.intrinsicName); } else if (type.flags & 4096 /* Reference */) { writeTypeReference(type, flags); @@ -13213,47 +13244,54 @@ var ts; } } function writeAnonymousType(type, flags) { - // Always use 'typeof T' for type of class, enum, and module objects - if (type.symbol && type.symbol.flags & (32 /* Class */ | 384 /* Enum */ | 512 /* ValueModule */)) { - writeTypeofSymbol(type, flags); - } - else if (shouldWriteTypeOfFunctionSymbol()) { - writeTypeofSymbol(type, flags); - } - else if (typeStack && ts.contains(typeStack, type)) { - // If type is an anonymous type literal in a type alias declaration, use type alias name - var typeAlias = getTypeAliasForTypeLiteral(type); - if (typeAlias) { - // The specified symbol flags need to be reinterpreted as type flags - buildSymbolDisplay(typeAlias, writer, enclosingDeclaration, 793056 /* Type */, 0 /* None */, flags); + var symbol = type.symbol; + if (symbol) { + // Always use 'typeof T' for type of class, enum, and module objects + if (symbol.flags & (32 /* Class */ | 384 /* Enum */ | 512 /* ValueModule */)) { + writeTypeofSymbol(type, flags); + } + else if (shouldWriteTypeOfFunctionSymbol()) { + writeTypeofSymbol(type, flags); + } + else if (ts.contains(symbolStack, symbol)) { + // If type is an anonymous type literal in a type alias declaration, use type alias name + var typeAlias = getTypeAliasForTypeLiteral(type); + if (typeAlias) { + // The specified symbol flags need to be reinterpreted as type flags + buildSymbolDisplay(typeAlias, writer, enclosingDeclaration, 793056 /* Type */, 0 /* None */, flags); + } + else { + // Recursive usage, use any + writeKeyword(writer, 112 /* AnyKeyword */); + } } else { - // Recursive usage, use any - writeKeyword(writer, 112 /* AnyKeyword */); + // Since instantiations of the same anonymous type have the same symbol, tracking symbols instead + // of types allows us to catch circular references to instantiations of the same anonymous type + if (!symbolStack) { + symbolStack = []; + } + symbolStack.push(symbol); + writeLiteralType(type, flags); + symbolStack.pop(); } } else { - if (!typeStack) { - typeStack = []; - } - typeStack.push(type); + // Anonymous types with no symbol are never circular writeLiteralType(type, flags); - typeStack.pop(); } function shouldWriteTypeOfFunctionSymbol() { - if (type.symbol) { - var isStaticMethodSymbol = !!(type.symbol.flags & 8192 /* Method */ && - ts.forEach(type.symbol.declarations, function (declaration) { return declaration.flags & 128 /* Static */; })); - var isNonLocalFunctionSymbol = !!(type.symbol.flags & 16 /* Function */) && - (type.symbol.parent || - ts.forEach(type.symbol.declarations, function (declaration) { - return declaration.parent.kind === 228 /* SourceFile */ || declaration.parent.kind === 207 /* ModuleBlock */; - })); - if (isStaticMethodSymbol || isNonLocalFunctionSymbol) { - // typeof is allowed only for static/non local functions - return !!(flags & 2 /* UseTypeOfFunction */) || - (typeStack && ts.contains(typeStack, type)); // it is type of the symbol uses itself recursively - } + var isStaticMethodSymbol = !!(symbol.flags & 8192 /* Method */ && + ts.forEach(symbol.declarations, function (declaration) { return declaration.flags & 128 /* Static */; })); + var isNonLocalFunctionSymbol = !!(symbol.flags & 16 /* Function */) && + (symbol.parent || + ts.forEach(symbol.declarations, function (declaration) { + return declaration.parent.kind === 228 /* SourceFile */ || declaration.parent.kind === 207 /* ModuleBlock */; + })); + if (isStaticMethodSymbol || isNonLocalFunctionSymbol) { + // typeof is allowed only for static/non local functions + return !!(flags & 2 /* UseTypeOfFunction */) || + (ts.contains(symbolStack, symbol)); // it is type of the symbol uses itself recursively } } } @@ -13284,7 +13322,7 @@ var ts; if (flags & 64 /* InElementType */) { writePunctuation(writer, 16 /* OpenParenToken */); } - buildSignatureDisplay(resolved.callSignatures[0], writer, enclosingDeclaration, globalFlagsToPass | 8 /* WriteArrowStyleSignature */, typeStack); + buildSignatureDisplay(resolved.callSignatures[0], writer, enclosingDeclaration, globalFlagsToPass | 8 /* WriteArrowStyleSignature */, symbolStack); if (flags & 64 /* InElementType */) { writePunctuation(writer, 17 /* CloseParenToken */); } @@ -13296,7 +13334,7 @@ var ts; } writeKeyword(writer, 88 /* NewKeyword */); writeSpace(writer); - buildSignatureDisplay(resolved.constructSignatures[0], writer, enclosingDeclaration, globalFlagsToPass | 8 /* WriteArrowStyleSignature */, typeStack); + buildSignatureDisplay(resolved.constructSignatures[0], writer, enclosingDeclaration, globalFlagsToPass | 8 /* WriteArrowStyleSignature */, symbolStack); if (flags & 64 /* InElementType */) { writePunctuation(writer, 17 /* CloseParenToken */); } @@ -13308,7 +13346,7 @@ var ts; writer.increaseIndent(); for (var _i = 0, _a = resolved.callSignatures; _i < _a.length; _i++) { var signature = _a[_i]; - buildSignatureDisplay(signature, writer, enclosingDeclaration, globalFlagsToPass, typeStack); + buildSignatureDisplay(signature, writer, enclosingDeclaration, globalFlagsToPass, symbolStack); writePunctuation(writer, 22 /* SemicolonToken */); writer.writeLine(); } @@ -13316,7 +13354,7 @@ var ts; var signature = _c[_b]; writeKeyword(writer, 88 /* NewKeyword */); writeSpace(writer); - buildSignatureDisplay(signature, writer, enclosingDeclaration, globalFlagsToPass, typeStack); + buildSignatureDisplay(signature, writer, enclosingDeclaration, globalFlagsToPass, symbolStack); writePunctuation(writer, 22 /* SemicolonToken */); writer.writeLine(); } @@ -13359,7 +13397,7 @@ var ts; if (p.flags & 536870912 /* Optional */) { writePunctuation(writer, 50 /* QuestionToken */); } - buildSignatureDisplay(signature, writer, enclosingDeclaration, globalFlagsToPass, typeStack); + buildSignatureDisplay(signature, writer, enclosingDeclaration, globalFlagsToPass, symbolStack); writePunctuation(writer, 22 /* SemicolonToken */); writer.writeLine(); } @@ -13386,17 +13424,17 @@ var ts; buildDisplayForTypeParametersAndDelimiters(getLocalTypeParametersOfClassOrInterface(symbol), writer, enclosingDeclaraiton, flags); } } - function buildTypeParameterDisplay(tp, writer, enclosingDeclaration, flags, typeStack) { + function buildTypeParameterDisplay(tp, writer, enclosingDeclaration, flags, symbolStack) { appendSymbolNameOnly(tp.symbol, writer); var constraint = getConstraintOfTypeParameter(tp); if (constraint) { writeSpace(writer); writeKeyword(writer, 79 /* ExtendsKeyword */); writeSpace(writer); - buildTypeDisplay(constraint, writer, enclosingDeclaration, flags, typeStack); + buildTypeDisplay(constraint, writer, enclosingDeclaration, flags, symbolStack); } } - function buildParameterDisplay(p, writer, enclosingDeclaration, flags, typeStack) { + function buildParameterDisplay(p, writer, enclosingDeclaration, flags, symbolStack) { var parameterNode = p.valueDeclaration; if (ts.isRestParameter(parameterNode)) { writePunctuation(writer, 21 /* DotDotDotToken */); @@ -13407,9 +13445,9 @@ var ts; } writePunctuation(writer, 51 /* ColonToken */); writeSpace(writer); - buildTypeDisplay(getTypeOfSymbol(p), writer, enclosingDeclaration, flags, typeStack); + buildTypeDisplay(getTypeOfSymbol(p), writer, enclosingDeclaration, flags, symbolStack); } - function buildDisplayForTypeParametersAndDelimiters(typeParameters, writer, enclosingDeclaration, flags, typeStack) { + function buildDisplayForTypeParametersAndDelimiters(typeParameters, writer, enclosingDeclaration, flags, symbolStack) { if (typeParameters && typeParameters.length) { writePunctuation(writer, 24 /* LessThanToken */); for (var i = 0; i < typeParameters.length; i++) { @@ -13417,12 +13455,12 @@ var ts; writePunctuation(writer, 23 /* CommaToken */); writeSpace(writer); } - buildTypeParameterDisplay(typeParameters[i], writer, enclosingDeclaration, flags, typeStack); + buildTypeParameterDisplay(typeParameters[i], writer, enclosingDeclaration, flags, symbolStack); } writePunctuation(writer, 25 /* GreaterThanToken */); } } - function buildDisplayForTypeArgumentsAndDelimiters(typeParameters, mapper, writer, enclosingDeclaration, flags, typeStack) { + function buildDisplayForTypeArgumentsAndDelimiters(typeParameters, mapper, writer, enclosingDeclaration, flags, symbolStack) { if (typeParameters && typeParameters.length) { writePunctuation(writer, 24 /* LessThanToken */); for (var i = 0; i < typeParameters.length; i++) { @@ -13435,18 +13473,18 @@ var ts; writePunctuation(writer, 25 /* GreaterThanToken */); } } - function buildDisplayForParametersAndDelimiters(parameters, writer, enclosingDeclaration, flags, typeStack) { + function buildDisplayForParametersAndDelimiters(parameters, writer, enclosingDeclaration, flags, symbolStack) { writePunctuation(writer, 16 /* OpenParenToken */); for (var i = 0; i < parameters.length; i++) { if (i > 0) { writePunctuation(writer, 23 /* CommaToken */); writeSpace(writer); } - buildParameterDisplay(parameters[i], writer, enclosingDeclaration, flags, typeStack); + buildParameterDisplay(parameters[i], writer, enclosingDeclaration, flags, symbolStack); } writePunctuation(writer, 17 /* CloseParenToken */); } - function buildReturnTypeDisplay(signature, writer, enclosingDeclaration, flags, typeStack) { + function buildReturnTypeDisplay(signature, writer, enclosingDeclaration, flags, symbolStack) { if (flags & 8 /* WriteArrowStyleSignature */) { writeSpace(writer); writePunctuation(writer, 32 /* EqualsGreaterThanToken */); @@ -13455,19 +13493,19 @@ var ts; writePunctuation(writer, 51 /* ColonToken */); } writeSpace(writer); - buildTypeDisplay(getReturnTypeOfSignature(signature), writer, enclosingDeclaration, flags, typeStack); + buildTypeDisplay(getReturnTypeOfSignature(signature), writer, enclosingDeclaration, flags, symbolStack); } - function buildSignatureDisplay(signature, writer, enclosingDeclaration, flags, typeStack) { + function buildSignatureDisplay(signature, writer, enclosingDeclaration, flags, symbolStack) { if (signature.target && (flags & 32 /* WriteTypeArgumentsOfSignature */)) { // Instantiated signature, write type arguments instead // This is achieved by passing in the mapper separately buildDisplayForTypeArgumentsAndDelimiters(signature.target.typeParameters, signature.mapper, writer, enclosingDeclaration); } else { - buildDisplayForTypeParametersAndDelimiters(signature.typeParameters, writer, enclosingDeclaration, flags, typeStack); + buildDisplayForTypeParametersAndDelimiters(signature.typeParameters, writer, enclosingDeclaration, flags, symbolStack); } - buildDisplayForParametersAndDelimiters(signature.parameters, writer, enclosingDeclaration, flags, typeStack); - buildReturnTypeDisplay(signature, writer, enclosingDeclaration, flags, typeStack); + buildDisplayForParametersAndDelimiters(signature.parameters, writer, enclosingDeclaration, flags, symbolStack); + buildReturnTypeDisplay(signature, writer, enclosingDeclaration, flags, symbolStack); } return _displayBuilder || (_displayBuilder = { symbolToString: symbolToString, @@ -13695,6 +13733,9 @@ var ts; var prop = getPropertyOfType(type, name); return prop ? getTypeOfSymbol(prop) : undefined; } + function isTypeAny(type) { + return type && (type.flags & 1 /* Any */) !== 0; + } // Return the inferred type for a binding element function getTypeForBindingElement(declaration) { var pattern = declaration.parent; @@ -13706,7 +13747,7 @@ var ts; // If no type was specified or inferred for parent, or if the specified or inferred type is any, // infer from the initializer of the binding element if one is present. Otherwise, go with the // undefined or any type of the parent. - if (!parentType || parentType === anyType) { + if (!parentType || isTypeAny(parentType)) { if (declaration.initializer) { return checkExpressionCached(declaration.initializer); } @@ -13715,14 +13756,14 @@ var ts; var type; if (pattern.kind === 151 /* ObjectBindingPattern */) { // Use explicitly specified property name ({ p: xxx } form), or otherwise the implied name ({ p } form) - var name_8 = declaration.propertyName || declaration.name; + var name_9 = declaration.propertyName || declaration.name; // Use type of the specified property, or otherwise, for a numeric name, the type of the numeric index signature, // or otherwise the type of the string index signature. - type = getTypeOfPropertyOfType(parentType, name_8.text) || - isNumericLiteralName(name_8.text) && getIndexTypeOfType(parentType, 1 /* Number */) || + type = getTypeOfPropertyOfType(parentType, name_9.text) || + isNumericLiteralName(name_9.text) && getIndexTypeOfType(parentType, 1 /* Number */) || getIndexTypeOfType(parentType, 0 /* String */); if (!type) { - error(name_8, ts.Diagnostics.Type_0_has_no_property_1_and_no_string_index_signature, typeToString(parentType), ts.declarationNameToString(name_8)); + error(name_9, ts.Diagnostics.Type_0_has_no_property_1_and_no_string_index_signature, typeToString(parentType), ts.declarationNameToString(name_9)); return unknownType; } } @@ -13732,7 +13773,7 @@ var ts; // fact an iterable or array (depending on target language). var elementType = checkIteratedTypeOrElementType(parentType, pattern, false); if (!declaration.dotDotDotToken) { - if (elementType.flags & 1 /* Any */) { + if (isTypeAny(elementType)) { return elementType; } // Use specific property type when parent is a tuple or numeric index type when parent is an array @@ -13926,7 +13967,7 @@ var ts; // Variable has initializer that circularly references the variable itself type = anyType; if (compilerOptions.noImplicitAny) { - error(symbol.valueDeclaration, ts.Diagnostics._0_implicitly_has_type_any_because_it_is_does_not_have_a_type_annotation_and_is_referenced_directly_or_indirectly_in_its_own_initializer, symbolToString(symbol)); + error(symbol.valueDeclaration, ts.Diagnostics._0_implicitly_has_type_any_because_it_does_not_have_a_type_annotation_and_is_referenced_directly_or_indirectly_in_its_own_initializer, symbolToString(symbol)); } } } @@ -14569,7 +14610,7 @@ var ts; else if (type.flags & 8 /* Boolean */) { type = globalBooleanType; } - else if (type.flags & 1048576 /* ESSymbol */) { + else if (type.flags & 2097152 /* ESSymbol */) { type = globalESSymbolType; } return type; @@ -14844,7 +14885,7 @@ var ts; // will result in a different declaration kind. if (!signature.isolatedSignatureType) { var isConstructor = signature.declaration.kind === 136 /* Constructor */ || signature.declaration.kind === 140 /* ConstructSignature */; - var type = createObjectType(32768 /* Anonymous */ | 65536 /* FromSignature */); + var type = createObjectType(32768 /* Anonymous */ | 131072 /* FromSignature */); type.members = emptySymbols; type.properties = emptyArray; type.callSignatures = !isConstructor ? [signature] : emptyArray; @@ -14921,7 +14962,7 @@ var ts; var type = types[_i]; result |= type.flags; } - return result & 786432 /* RequiresWidening */; + return result & 1572864 /* RequiresWidening */; } function createTypeReference(target, typeArguments) { var id = getTypeListId(typeArguments); @@ -15165,10 +15206,10 @@ var ts; } } } - function containsAnyType(types) { + function containsTypeAny(types) { for (var _i = 0; _i < types.length; _i++) { var type = types[_i]; - if (type.flags & 1 /* Any */) { + if (isTypeAny(type)) { return true; } } @@ -15194,7 +15235,7 @@ var ts; var sortedTypes = []; addTypesToSortedSet(sortedTypes, types); if (noSubtypeReduction) { - if (containsAnyType(sortedTypes)) { + if (containsTypeAny(sortedTypes)) { return anyType; } removeAllButLast(sortedTypes, undefinedType); @@ -15420,19 +15461,8 @@ var ts; return result; } function instantiateAnonymousType(type, mapper) { - // If this type has already been instantiated using this mapper, returned the cached result. This guards against - // infinite instantiations of cyclic types, e.g. "var x: { a: T, b: typeof x };" - if (mapper.mappings) { - var cached = mapper.mappings[type.id]; - if (cached) { - return cached; - } - } - else { - mapper.mappings = {}; - } - // Instantiate the given type using the given mapper and cache the result - var result = createObjectType(32768 /* Anonymous */, type.symbol); + // Mark the anonymous type as instantiated such that our infinite instantiation detection logic can recognize it + var result = createObjectType(32768 /* Anonymous */ | 65536 /* Instantiated */, type.symbol); result.properties = instantiateList(getPropertiesOfObjectType(type), mapper, instantiateSymbol); result.members = createSymbolTable(result.properties); result.callSignatures = instantiateList(getSignaturesOfType(type, 0 /* Call */), mapper, instantiateSignature); @@ -15443,7 +15473,6 @@ var ts; result.stringIndexType = instantiateType(stringIndexType, mapper); if (numberIndexType) result.numberIndexType = instantiateType(numberIndexType, mapper); - mapper.mappings[type.id] = result; return result; } function instantiateType(type, mapper) { @@ -15582,7 +15611,7 @@ var ts; if (source === target) return -1 /* True */; if (relation !== identityRelation) { - if (target.flags & 1 /* Any */) + if (isTypeAny(target)) return -1 /* True */; if (source === undefinedType) return -1 /* True */; @@ -15593,7 +15622,7 @@ var ts; if (source.flags & 256 /* StringLiteral */ && target === stringType) return -1 /* True */; if (relation === assignableRelation) { - if (source.flags & 1 /* Any */) + if (isTypeAny(source)) return -1 /* True */; if (source === numberType && target.flags & 128 /* Enum */) return -1 /* True */; @@ -15836,12 +15865,13 @@ var ts; // Effectively, we will generate a false positive when two types are structurally equal to at least 10 levels, but unequal at // some level beyond that. function isDeeplyNestedGeneric(type, stack) { - if (type.flags & 4096 /* Reference */ && depth >= 10) { - var target_1 = type.target; + // We track type references (created by createTypeReference) and instantiated types (created by instantiateType) + if (type.flags & (4096 /* Reference */ | 65536 /* Instantiated */) && depth >= 10) { + var symbol = type.symbol; var count = 0; for (var i = 0; i < depth; i++) { var t = stack[i]; - if (t.flags & 4096 /* Reference */ && t.target === target_1) { + if (t.flags & (4096 /* Reference */ | 65536 /* Instantiated */) && t.symbol === symbol) { count++; if (count >= 10) return true; @@ -15856,7 +15886,7 @@ var ts; } var result = -1 /* True */; var properties = getPropertiesOfObjectType(target); - var requireOptionalProperties = relation === subtypeRelation && !(source.flags & 131072 /* ObjectLiteral */); + var requireOptionalProperties = relation === subtypeRelation && !(source.flags & 262144 /* ObjectLiteral */); for (var _i = 0; _i < properties.length; _i++) { var targetProp = properties[_i]; var sourceProp = getPropertyOfType(source, targetProp.name); @@ -15962,11 +15992,11 @@ var ts; var saveErrorInfo = errorInfo; outer: for (var _i = 0; _i < targetSignatures.length; _i++) { var t = targetSignatures[_i]; - if (!t.hasStringLiterals || target.flags & 65536 /* FromSignature */) { + if (!t.hasStringLiterals || target.flags & 131072 /* FromSignature */) { var localErrors = reportErrors; for (var _a = 0; _a < sourceSignatures.length; _a++) { var s = sourceSignatures[_a]; - if (!s.hasStringLiterals || source.flags & 65536 /* FromSignature */) { + if (!s.hasStringLiterals || source.flags & 131072 /* FromSignature */) { var related = signatureRelatedTo(s, t, localErrors); if (related) { result &= related; @@ -16278,11 +16308,11 @@ var ts; return createAnonymousType(type.symbol, members, emptyArray, emptyArray, stringIndexType, numberIndexType); } function getWidenedType(type) { - if (type.flags & 786432 /* RequiresWidening */) { + if (type.flags & 1572864 /* RequiresWidening */) { if (type.flags & (32 /* Undefined */ | 64 /* Null */)) { return anyType; } - if (type.flags & 131072 /* ObjectLiteral */) { + if (type.flags & 262144 /* ObjectLiteral */) { return getWidenedTypeOfObjectLiteral(type); } if (type.flags & 16384 /* Union */) { @@ -16307,11 +16337,11 @@ var ts; if (isArrayType(type)) { return reportWideningErrorsInType(type.typeArguments[0]); } - if (type.flags & 131072 /* ObjectLiteral */) { + if (type.flags & 262144 /* ObjectLiteral */) { var errorReported = false; ts.forEach(getPropertiesOfObjectType(type), function (p) { var t = getTypeOfSymbol(p); - if (t.flags & 262144 /* ContainsUndefinedOrNull */) { + if (t.flags & 524288 /* ContainsUndefinedOrNull */) { if (!reportWideningErrorsInType(t)) { error(p.valueDeclaration, ts.Diagnostics.Object_literal_s_property_0_implicitly_has_an_1_type, p.name, typeToString(getWidenedType(t))); } @@ -16354,7 +16384,7 @@ var ts; error(declaration, diagnostic, ts.declarationNameToString(declaration.name), typeAsString); } function reportErrorsFromWidening(declaration, type) { - if (produceDiagnostics && compilerOptions.noImplicitAny && type.flags & 262144 /* ContainsUndefinedOrNull */) { + if (produceDiagnostics && compilerOptions.noImplicitAny && type.flags & 524288 /* ContainsUndefinedOrNull */) { // Report implicit any error within type if possible, otherwise report error on declaration if (!reportWideningErrorsInType(type)) { reportImplicitAnyError(declaration, type); @@ -16416,11 +16446,11 @@ var ts; } function isWithinDepthLimit(type, stack) { if (depth >= 5) { - var target_2 = type.target; + var target_1 = type.target; var count = 0; for (var i = 0; i < depth; i++) { var t = stack[i]; - if (t.flags & 4096 /* Reference */ && t.target === target_2) { + if (t.flags & 4096 /* Reference */ && t.target === target_1) { count++; } } @@ -16763,52 +16793,54 @@ var ts; function getNarrowedTypeOfSymbol(symbol, node) { var type = getTypeOfSymbol(symbol); // Only narrow when symbol is variable of type any or an object, union, or type parameter type - if (node && symbol.flags & 3 /* Variable */ && type.flags & (1 /* Any */ | 48128 /* ObjectType */ | 16384 /* Union */ | 512 /* TypeParameter */)) { - loop: while (node.parent) { - var child = node; - node = node.parent; - var narrowedType = type; - switch (node.kind) { - case 184 /* IfStatement */: - // In a branch of an if statement, narrow based on controlling expression - if (child !== node.expression) { - narrowedType = narrowType(type, node.expression, child === node.thenStatement); - } - break; - case 171 /* ConditionalExpression */: - // In a branch of a conditional expression, narrow based on controlling condition - if (child !== node.condition) { - narrowedType = narrowType(type, node.condition, child === node.whenTrue); - } - break; - case 170 /* BinaryExpression */: - // In the right operand of an && or ||, narrow based on left operand - if (child === node.right) { - if (node.operatorToken.kind === 48 /* AmpersandAmpersandToken */) { - narrowedType = narrowType(type, node.left, true); + if (node && symbol.flags & 3 /* Variable */) { + if (isTypeAny(type) || type.flags & (48128 /* ObjectType */ | 16384 /* Union */ | 512 /* TypeParameter */)) { + loop: while (node.parent) { + var child = node; + node = node.parent; + var narrowedType = type; + switch (node.kind) { + case 184 /* IfStatement */: + // In a branch of an if statement, narrow based on controlling expression + if (child !== node.expression) { + narrowedType = narrowType(type, node.expression, child === node.thenStatement); } - else if (node.operatorToken.kind === 49 /* BarBarToken */) { - narrowedType = narrowType(type, node.left, false); + break; + case 171 /* ConditionalExpression */: + // In a branch of a conditional expression, narrow based on controlling condition + if (child !== node.condition) { + narrowedType = narrowType(type, node.condition, child === node.whenTrue); } - } - break; - case 228 /* SourceFile */: - case 206 /* ModuleDeclaration */: - case 201 /* FunctionDeclaration */: - case 135 /* MethodDeclaration */: - case 134 /* MethodSignature */: - case 137 /* GetAccessor */: - case 138 /* SetAccessor */: - case 136 /* Constructor */: - // Stop at the first containing function or module declaration - break loop; - } - // Use narrowed type if construct contains no assignments to variable - if (narrowedType !== type) { - if (isVariableAssignedWithin(symbol, node)) { - break; + break; + case 170 /* BinaryExpression */: + // In the right operand of an && or ||, narrow based on left operand + if (child === node.right) { + if (node.operatorToken.kind === 48 /* AmpersandAmpersandToken */) { + narrowedType = narrowType(type, node.left, true); + } + else if (node.operatorToken.kind === 49 /* BarBarToken */) { + narrowedType = narrowType(type, node.left, false); + } + } + break; + case 228 /* SourceFile */: + case 206 /* ModuleDeclaration */: + case 201 /* FunctionDeclaration */: + case 135 /* MethodDeclaration */: + case 134 /* MethodSignature */: + case 137 /* GetAccessor */: + case 138 /* SetAccessor */: + case 136 /* Constructor */: + // Stop at the first containing function or module declaration + break loop; + } + // Use narrowed type if construct contains no assignments to variable + if (narrowedType !== type) { + if (isVariableAssignedWithin(symbol, node)) { + break; + } + type = narrowedType; } - type = narrowedType; } } } @@ -16830,7 +16862,7 @@ var ts; if (assumeTrue) { // Assumed result is true. If check was not for a primitive type, remove all primitive types if (!typeInfo) { - return removeTypesFromUnionType(type, 258 /* StringLike */ | 132 /* NumberLike */ | 8 /* Boolean */ | 1048576 /* ESSymbol */, + return removeTypesFromUnionType(type, 258 /* StringLike */ | 132 /* NumberLike */ | 8 /* Boolean */ | 2097152 /* ESSymbol */, /*isOfTypeKind*/ true, false); } // Check was for a primitive type, return that primitive type if it is a subtype @@ -16880,7 +16912,7 @@ var ts; } function narrowTypeByInstanceof(type, expr, assumeTrue) { // Check that type is not any, assumed result is true, and we have variable symbol on the left - if (type.flags & 1 /* Any */ || !assumeTrue || expr.left.kind !== 65 /* Identifier */ || getResolvedSymbol(expr.left) !== symbol) { + if (isTypeAny(type) || !assumeTrue || expr.left.kind !== 65 /* Identifier */ || getResolvedSymbol(expr.left) !== symbol) { return type; } // Check that right operand is a function type with a prototype property @@ -16893,7 +16925,7 @@ var ts; if (prototypeProperty) { // Target type is type of the protoype property var prototypePropertyType = getTypeOfSymbol(prototypeProperty); - if (prototypePropertyType !== anyType) { + if (!isTypeAny(prototypePropertyType)) { targetType = prototypePropertyType; } } @@ -17576,7 +17608,10 @@ var ts; function isNumericComputedName(name) { // It seems odd to consider an expression of type Any to result in a numeric name, // but this behavior is consistent with checkIndexedAccess - return allConstituentTypesHaveKind(checkComputedPropertyName(name), 1 /* Any */ | 132 /* NumberLike */); + return isTypeAnyOrAllConstituentTypesHaveKind(checkComputedPropertyName(name), 132 /* NumberLike */); + } + function isTypeAnyOrAllConstituentTypesHaveKind(type, kind) { + return isTypeAny(type) || allConstituentTypesHaveKind(type, kind); } function isNumericLiteralName(name) { // The intent of numeric names is that @@ -17608,7 +17643,7 @@ var ts; links.resolvedType = checkExpression(node.expression); // This will allow types number, string, symbol or any. It will also allow enums, the unknown // type, and any union of these types (like string | number). - if (!allConstituentTypesHaveKind(links.resolvedType, 1 /* Any */ | 132 /* NumberLike */ | 258 /* StringLike */ | 1048576 /* ESSymbol */)) { + if (!isTypeAnyOrAllConstituentTypesHaveKind(links.resolvedType, 132 /* NumberLike */ | 258 /* StringLike */ | 2097152 /* ESSymbol */)) { error(node, ts.Diagnostics.A_computed_property_name_must_be_of_type_string_number_symbol_or_any); } else { @@ -17669,7 +17704,7 @@ var ts; var stringIndexType = getIndexType(0 /* String */); var numberIndexType = getIndexType(1 /* Number */); var result = createAnonymousType(node.symbol, propertiesTable, emptyArray, emptyArray, stringIndexType, numberIndexType); - result.flags |= 131072 /* ObjectLiteral */ | 524288 /* ContainsObjectLiteral */ | (typeFlags & 262144 /* ContainsUndefinedOrNull */); + result.flags |= 262144 /* ObjectLiteral */ | 1048576 /* ContainsObjectLiteral */ | (typeFlags & 524288 /* ContainsUndefinedOrNull */); return result; function getIndexType(kind) { if (contextualType && contextualTypeHasIndexSignature(contextualType, kind)) { @@ -17747,47 +17782,45 @@ var ts; } function checkPropertyAccessExpressionOrQualifiedName(node, left, right) { var type = checkExpressionOrQualifiedName(left); - if (type === unknownType) + if (isTypeAny(type)) { return type; - if (type !== anyType) { - var apparentType = getApparentType(getWidenedType(type)); - if (apparentType === unknownType) { - // handle cases when type is Type parameter with invalid constraint - return unknownType; - } - var prop = getPropertyOfType(apparentType, right.text); - if (!prop) { - if (right.text) { - error(right, ts.Diagnostics.Property_0_does_not_exist_on_type_1, ts.declarationNameToString(right), typeToString(type)); - } - return unknownType; - } - getNodeLinks(node).resolvedSymbol = prop; - if (prop.parent && prop.parent.flags & 32 /* Class */) { - // TS 1.0 spec (April 2014): 4.8.2 - // - In a constructor, instance member function, instance member accessor, or - // instance member variable initializer where this references a derived class instance, - // a super property access is permitted and must specify a public instance member function of the base class. - // - In a static member function or static member accessor - // where this references the constructor function object of a derived class, - // a super property access is permitted and must specify a public static member function of the base class. - if (left.kind === 91 /* SuperKeyword */ && getDeclarationKindFromSymbol(prop) !== 135 /* MethodDeclaration */) { - error(right, ts.Diagnostics.Only_public_and_protected_methods_of_the_base_class_are_accessible_via_the_super_keyword); - } - else { - checkClassPropertyAccess(node, left, type, prop); - } - } - return getTypeOfSymbol(prop); } - return anyType; + var apparentType = getApparentType(getWidenedType(type)); + if (apparentType === unknownType) { + // handle cases when type is Type parameter with invalid constraint + return unknownType; + } + var prop = getPropertyOfType(apparentType, right.text); + if (!prop) { + if (right.text) { + error(right, ts.Diagnostics.Property_0_does_not_exist_on_type_1, ts.declarationNameToString(right), typeToString(type)); + } + return unknownType; + } + getNodeLinks(node).resolvedSymbol = prop; + if (prop.parent && prop.parent.flags & 32 /* Class */) { + // TS 1.0 spec (April 2014): 4.8.2 + // - In a constructor, instance member function, instance member accessor, or + // instance member variable initializer where this references a derived class instance, + // a super property access is permitted and must specify a public instance member function of the base class. + // - In a static member function or static member accessor + // where this references the constructor function object of a derived class, + // a super property access is permitted and must specify a public static member function of the base class. + if (left.kind === 91 /* SuperKeyword */ && getDeclarationKindFromSymbol(prop) !== 135 /* MethodDeclaration */) { + error(right, ts.Diagnostics.Only_public_and_protected_methods_of_the_base_class_are_accessible_via_the_super_keyword); + } + else { + checkClassPropertyAccess(node, left, type, prop); + } + } + return getTypeOfSymbol(prop); } function isValidPropertyAccess(node, propertyName) { var left = node.kind === 156 /* PropertyAccessExpression */ ? node.expression : node.left; var type = checkExpressionOrQualifiedName(left); - if (type !== unknownType && type !== anyType) { + if (type !== unknownType && !isTypeAny(type)) { var prop = getPropertyOfType(getWidenedType(type), propertyName); if (prop && prop.parent && prop.parent.flags & 32 /* Class */) { if (left.kind === 91 /* SuperKeyword */ && getDeclarationKindFromSymbol(prop) !== 135 /* MethodDeclaration */) { @@ -17839,23 +17872,23 @@ var ts; // - Otherwise, if IndexExpr is of type Any, the String or Number primitive type, or an enum type, the property access is of type Any. // See if we can index as a property. if (node.argumentExpression) { - var name_9 = getPropertyNameForIndexedAccess(node.argumentExpression, indexType); - if (name_9 !== undefined) { - var prop = getPropertyOfType(objectType, name_9); + var name_10 = getPropertyNameForIndexedAccess(node.argumentExpression, indexType); + if (name_10 !== undefined) { + var prop = getPropertyOfType(objectType, name_10); if (prop) { getNodeLinks(node).resolvedSymbol = prop; return getTypeOfSymbol(prop); } else if (isConstEnum) { - error(node.argumentExpression, ts.Diagnostics.Property_0_does_not_exist_on_const_enum_1, name_9, symbolToString(objectType.symbol)); + error(node.argumentExpression, ts.Diagnostics.Property_0_does_not_exist_on_const_enum_1, name_10, symbolToString(objectType.symbol)); return unknownType; } } } // Check for compatible indexer types. - if (allConstituentTypesHaveKind(indexType, 1 /* Any */ | 258 /* StringLike */ | 132 /* NumberLike */ | 1048576 /* ESSymbol */)) { + if (isTypeAnyOrAllConstituentTypesHaveKind(indexType, 258 /* StringLike */ | 132 /* NumberLike */ | 2097152 /* ESSymbol */)) { // Try to use a number indexer. - if (allConstituentTypesHaveKind(indexType, 1 /* Any */ | 132 /* NumberLike */)) { + if (isTypeAnyOrAllConstituentTypesHaveKind(indexType, 132 /* NumberLike */)) { var numberIndexType = getIndexTypeOfType(objectType, 1 /* Number */); if (numberIndexType) { return numberIndexType; @@ -17867,7 +17900,7 @@ var ts; return stringIndexType; } // Fall back to any. - if (compilerOptions.noImplicitAny && !compilerOptions.suppressImplicitAnyIndexErrors && objectType !== anyType) { + if (compilerOptions.noImplicitAny && !compilerOptions.suppressImplicitAnyIndexErrors && !isTypeAny(objectType)) { error(node, ts.Diagnostics.Index_signature_of_object_type_implicitly_has_an_any_type); } return anyType; @@ -17908,7 +17941,7 @@ var ts; return false; } // Make sure the property type is the primitive symbol type - if ((expressionType.flags & 1048576 /* ESSymbol */) === 0) { + if ((expressionType.flags & 2097152 /* ESSymbol */) === 0) { if (reportError) { error(expression, ts.Diagnostics.A_computed_property_name_of_the_form_0_must_be_of_type_symbol, ts.getTextOfNode(expression)); } @@ -18446,8 +18479,10 @@ var ts; // types are provided for the argument expressions, and the result is always of type Any. // We exclude union types because we may have a union of function types that happen to have // no common signatures. - if (funcType === anyType || (!callSignatures.length && !constructSignatures.length && !(funcType.flags & 16384 /* Union */) && isTypeAssignableTo(funcType, globalFunctionType))) { - if (node.typeArguments) { + if (isTypeAny(funcType) || (!callSignatures.length && !constructSignatures.length && !(funcType.flags & 16384 /* Union */) && isTypeAssignableTo(funcType, globalFunctionType))) { + // The unknownType indicates that an error already occured (and was reported). No + // need to report another error in this case. + if (funcType !== unknownType && node.typeArguments) { error(node, ts.Diagnostics.Untyped_function_calls_may_not_accept_type_arguments); } return resolveUntypedCall(node); @@ -18474,15 +18509,6 @@ var ts; } } var expressionType = checkExpression(node.expression); - // TS 1.0 spec: 4.11 - // If ConstructExpr is of type Any, Args can be any argument - // list and the result of the operation is of type Any. - if (expressionType === anyType) { - if (node.typeArguments) { - error(node, ts.Diagnostics.Untyped_function_calls_may_not_accept_type_arguments); - } - return resolveUntypedCall(node); - } // If ConstructExpr's apparent type(section 3.8.1) is an object type with one or // more construct signatures, the expression is processed in the same manner as a // function call, but using the construct signatures as the initial set of candidate @@ -18493,6 +18519,15 @@ var ts; // Another error has already been reported return resolveErrorCall(node); } + // TS 1.0 spec: 4.11 + // If ConstructExpr is of type Any, Args can be any argument + // list and the result of the operation is of type Any. + if (isTypeAny(expressionType)) { + if (node.typeArguments) { + error(node, ts.Diagnostics.Untyped_function_calls_may_not_accept_type_arguments); + } + return resolveUntypedCall(node); + } // Technically, this signatures list may be incomplete. We are taking the apparent type, // but we are not including construct signatures that may have been added to the Object or // Function interface, since they have none by default. This is a bit of a leap of faith @@ -18524,7 +18559,7 @@ var ts; return resolveErrorCall(node); } var callSignatures = getSignaturesOfType(apparentType, 0 /* Call */); - if (tagType === anyType || (!callSignatures.length && !(tagType.flags & 16384 /* Union */) && isTypeAssignableTo(tagType, globalFunctionType))) { + if (isTypeAny(tagType) || (!callSignatures.length && !(tagType.flags & 16384 /* Union */) && isTypeAssignableTo(tagType, globalFunctionType))) { return resolveUntypedCall(node); } if (!callSignatures.length) { @@ -18709,7 +18744,7 @@ var ts; return; } // Functions that return 'void' or 'any' don't need any return expressions. - if (returnType === voidType || returnType === anyType) { + if (returnType === voidType || isTypeAny(returnType)) { return; } // If all we have is a function signature, or an arrow function with an expression body, then there is nothing to check. @@ -18778,6 +18813,14 @@ var ts; checkIfNonVoidFunctionHasReturnExpressionsOrSingleThrowStatment(node, getTypeFromTypeNode(node.type)); } if (node.body) { + if (!node.type) { + // There are some checks that are only performed in getReturnTypeFromBody, that may produce errors + // we need. An example is the noImplicitAny errors resulting from widening the return expression + // of a function. Because checking of function expression bodies is deferred, there was never an + // appropriate time to do this during the main walk of the file (see the comment at the top of + // checkFunctionExpressionBodies). So it must be done now. + getReturnTypeOfSignature(getSignatureFromDeclaration(node)); + } if (node.body.kind === 180 /* Block */) { checkSourceElement(node.body); } @@ -18791,7 +18834,7 @@ var ts; } } function checkArithmeticOperandType(operand, type, diagnostic) { - if (!allConstituentTypesHaveKind(type, 1 /* Any */ | 132 /* NumberLike */)) { + if (!isTypeAnyOrAllConstituentTypesHaveKind(type, 132 /* NumberLike */)) { error(operand, diagnostic); return false; } @@ -18847,8 +18890,8 @@ var ts; var index = n.argumentExpression; var symbol = findSymbol(n.expression); if (symbol && index && index.kind === 8 /* StringLiteral */) { - var name_10 = index.text; - var prop = getPropertyOfType(getTypeOfSymbol(symbol), name_10); + var name_11 = index.text; + var prop = getPropertyOfType(getTypeOfSymbol(symbol), name_11); return prop && (prop.flags & 3 /* Variable */) !== 0 && (getDeclarationFlagsFromSymbol(prop) & 8192 /* Const */) !== 0; } return false; @@ -18900,7 +18943,7 @@ var ts; case 33 /* PlusToken */: case 34 /* MinusToken */: case 47 /* TildeToken */: - if (someConstituentTypeHasKind(operandType, 1048576 /* ESSymbol */)) { + if (someConstituentTypeHasKind(operandType, 2097152 /* ESSymbol */)) { error(node.operand, ts.Diagnostics.The_0_operator_cannot_be_applied_to_type_symbol, ts.tokenToString(node.operator)); } return numberType; @@ -18978,11 +19021,11 @@ var ts; // and the right operand to be of type Any or a subtype of the 'Function' interface type. // The result is always of the Boolean primitive type. // NOTE: do not raise error if leftType is unknown as related error was already reported - if (allConstituentTypesHaveKind(leftType, 1049086 /* Primitive */)) { + if (allConstituentTypesHaveKind(leftType, 2097662 /* Primitive */)) { error(node.left, ts.Diagnostics.The_left_hand_side_of_an_instanceof_expression_must_be_of_type_any_an_object_type_or_a_type_parameter); } // NOTE: do not raise error if right is unknown as related error was already reported - if (!(rightType.flags & 1 /* Any */ || isTypeSubtypeOf(rightType, globalFunctionType))) { + if (!(isTypeAny(rightType) || isTypeSubtypeOf(rightType, globalFunctionType))) { error(node.right, ts.Diagnostics.The_right_hand_side_of_an_instanceof_expression_must_be_of_type_any_or_of_a_type_assignable_to_the_Function_interface_type); } return booleanType; @@ -18992,10 +19035,10 @@ var ts; // The in operator requires the left operand to be of type Any, the String primitive type, or the Number primitive type, // and the right operand to be of type Any, an object type, or a type parameter type. // The result is always of the Boolean primitive type. - if (!allConstituentTypesHaveKind(leftType, 1 /* Any */ | 258 /* StringLike */ | 132 /* NumberLike */ | 1048576 /* ESSymbol */)) { + if (!isTypeAnyOrAllConstituentTypesHaveKind(leftType, 258 /* StringLike */ | 132 /* NumberLike */ | 2097152 /* ESSymbol */)) { error(node.left, ts.Diagnostics.The_left_hand_side_of_an_in_expression_must_be_of_type_any_string_number_or_symbol); } - if (!allConstituentTypesHaveKind(rightType, 1 /* Any */ | 48128 /* ObjectType */ | 512 /* TypeParameter */)) { + if (!isTypeAnyOrAllConstituentTypesHaveKind(rightType, 48128 /* ObjectType */ | 512 /* TypeParameter */)) { error(node.right, ts.Diagnostics.The_right_hand_side_of_an_in_expression_must_be_of_type_any_an_object_type_or_a_type_parameter); } return booleanType; @@ -19006,16 +19049,17 @@ var ts; var p = properties[_i]; if (p.kind === 225 /* PropertyAssignment */ || p.kind === 226 /* ShorthandPropertyAssignment */) { // TODO(andersh): Computed property support - var name_11 = p.name; - var type = sourceType.flags & 1 /* Any */ ? sourceType : - getTypeOfPropertyOfType(sourceType, name_11.text) || - isNumericLiteralName(name_11.text) && getIndexTypeOfType(sourceType, 1 /* Number */) || + var name_12 = p.name; + var type = isTypeAny(sourceType) + ? sourceType + : getTypeOfPropertyOfType(sourceType, name_12.text) || + isNumericLiteralName(name_12.text) && getIndexTypeOfType(sourceType, 1 /* Number */) || getIndexTypeOfType(sourceType, 0 /* String */); if (type) { - checkDestructuringAssignment(p.initializer || name_11, type); + checkDestructuringAssignment(p.initializer || name_12, type); } else { - error(name_11, ts.Diagnostics.Type_0_has_no_property_1_and_no_string_index_signature, typeToString(sourceType), ts.declarationNameToString(name_11)); + error(name_12, ts.Diagnostics.Type_0_has_no_property_1_and_no_string_index_signature, typeToString(sourceType), ts.declarationNameToString(name_12)); } } else { @@ -19035,8 +19079,9 @@ var ts; if (e.kind !== 176 /* OmittedExpression */) { if (e.kind !== 174 /* SpreadElementExpression */) { var propName = "" + i; - var type = sourceType.flags & 1 /* Any */ ? sourceType : - isTupleLikeType(sourceType) + var type = isTypeAny(sourceType) + ? sourceType + : isTupleLikeType(sourceType) ? getTypeOfPropertyOfType(sourceType, propName) : elementType; if (type) { @@ -19171,10 +19216,10 @@ var ts; // If one or both operands are of the String primitive type, the result is of the String primitive type. resultType = stringType; } - else if (leftType.flags & 1 /* Any */ || rightType.flags & 1 /* Any */) { + else if (isTypeAny(leftType) || isTypeAny(rightType)) { // Otherwise, the result is of type Any. // NOTE: unknown type here denotes error type. Old compiler treated this case as any type so do we. - resultType = anyType; + resultType = leftType === unknownType || rightType === unknownType ? unknownType : anyType; } // Symbols are not allowed at all in arithmetic expressions if (resultType && !checkForDisallowedESSymbolOperand(operator)) { @@ -19221,8 +19266,8 @@ var ts; } // Return true if there was no error, false if there was an error. function checkForDisallowedESSymbolOperand(operator) { - var offendingSymbolOperand = someConstituentTypeHasKind(leftType, 1048576 /* ESSymbol */) ? node.left : - someConstituentTypeHasKind(rightType, 1048576 /* ESSymbol */) ? node.right : + var offendingSymbolOperand = someConstituentTypeHasKind(leftType, 2097152 /* ESSymbol */) ? node.left : + someConstituentTypeHasKind(rightType, 2097152 /* ESSymbol */) ? node.right : undefined; if (offendingSymbolOperand) { error(offendingSymbolOperand, ts.Diagnostics.The_0_operator_cannot_be_applied_to_type_symbol, ts.tokenToString(operator)); @@ -20138,7 +20183,7 @@ var ts; if (node && node.kind === 142 /* TypeReference */) { var type = getTypeFromTypeNode(node); var shouldCheckIfUnknownType = type === unknownType && compilerOptions.isolatedModules; - if (!type || (!shouldCheckIfUnknownType && type.flags & (1048703 /* Intrinsic */ | 132 /* NumberLike */ | 258 /* StringLike */))) { + if (!type || (!shouldCheckIfUnknownType && type.flags & (2097279 /* Intrinsic */ | 132 /* NumberLike */ | 258 /* StringLike */))) { return; } if (shouldCheckIfUnknownType || type.symbol.valueDeclaration) { @@ -20433,8 +20478,8 @@ var ts; // otherwise if variable has an initializer - show error that initialization will fail // since LHS will be block scoped name instead of function scoped if (!namesShareScope) { - var name_12 = symbolToString(localDeclarationSymbol); - error(node, ts.Diagnostics.Cannot_initialize_outer_scoped_variable_0_in_the_same_scope_as_block_scoped_declaration_1, name_12, name_12); + var name_13 = symbolToString(localDeclarationSymbol); + error(node, ts.Diagnostics.Cannot_initialize_outer_scoped_variable_0_in_the_same_scope_as_block_scoped_declaration_1, name_13, name_13); } } } @@ -20667,7 +20712,7 @@ var ts; if (varExpr.kind === 154 /* ArrayLiteralExpression */ || varExpr.kind === 155 /* ObjectLiteralExpression */) { error(varExpr, ts.Diagnostics.The_left_hand_side_of_a_for_in_statement_cannot_be_a_destructuring_pattern); } - else if (!allConstituentTypesHaveKind(leftType, 1 /* Any */ | 258 /* StringLike */)) { + else if (!isTypeAnyOrAllConstituentTypesHaveKind(leftType, 258 /* StringLike */)) { error(varExpr, ts.Diagnostics.The_left_hand_side_of_a_for_in_statement_must_be_of_type_string_or_any); } else { @@ -20678,7 +20723,7 @@ var ts; var rightType = checkExpression(node.expression); // unknownType is returned i.e. if node.expression is identifier whose name cannot be resolved // in this case error about missing name is already reported - do not report extra one - if (!allConstituentTypesHaveKind(rightType, 1 /* Any */ | 48128 /* ObjectType */ | 512 /* TypeParameter */)) { + if (!isTypeAnyOrAllConstituentTypesHaveKind(rightType, 48128 /* ObjectType */ | 512 /* TypeParameter */)) { error(node.expression, ts.Diagnostics.The_right_hand_side_of_a_for_in_statement_must_be_of_type_any_an_object_type_or_a_type_parameter); } checkSourceElement(node.statement); @@ -20696,7 +20741,7 @@ var ts; return checkIteratedTypeOrElementType(expressionType, rhsExpression, true); } function checkIteratedTypeOrElementType(inputType, errorNode, allowStringInput) { - if (inputType.flags & 1 /* Any */) { + if (isTypeAny(inputType)) { return inputType; } if (languageVersion >= 2 /* ES6 */) { @@ -20748,7 +20793,7 @@ var ts; * whole pattern and that T (above) is 'any'. */ function getElementTypeOfIterable(type, errorNode) { - if (type.flags & 1 /* Any */) { + if (isTypeAny(type)) { return undefined; } var typeAsIterable = type; @@ -20760,7 +20805,7 @@ var ts; } else { var iteratorFunction = getTypeOfPropertyOfType(type, ts.getPropertyNameForKnownSymbolName("iterator")); - if (iteratorFunction && iteratorFunction.flags & 1 /* Any */) { + if (isTypeAny(iteratorFunction)) { return undefined; } var iteratorFunctionSignatures = iteratorFunction ? getSignaturesOfType(iteratorFunction, 0 /* Call */) : emptyArray; @@ -20789,7 +20834,7 @@ var ts; * */ function getElementTypeOfIterator(type, errorNode) { - if (type.flags & 1 /* Any */) { + if (isTypeAny(type)) { return undefined; } var typeAsIterator = type; @@ -20801,7 +20846,7 @@ var ts; } else { var iteratorNextFunction = getTypeOfPropertyOfType(type, "next"); - if (iteratorNextFunction && iteratorNextFunction.flags & 1 /* Any */) { + if (isTypeAny(iteratorNextFunction)) { return undefined; } var iteratorNextFunctionSignatures = iteratorNextFunction ? getSignaturesOfType(iteratorNextFunction, 0 /* Call */) : emptyArray; @@ -20812,7 +20857,7 @@ var ts; return undefined; } var iteratorNextResult = getUnionType(ts.map(iteratorNextFunctionSignatures, getReturnTypeOfSignature)); - if (iteratorNextResult.flags & 1 /* Any */) { + if (isTypeAny(iteratorNextResult)) { return undefined; } var iteratorNextValue = getTypeOfPropertyOfType(iteratorNextResult, "value"); @@ -20828,7 +20873,7 @@ var ts; return typeAsIterator.iteratorElementType; } function getElementTypeOfIterableIterator(type) { - if (type.flags & 1 /* Any */) { + if (isTypeAny(type)) { return undefined; } // As an optimization, if the type is instantiated directly using the globalIterableIteratorType (IterableIterator), @@ -22457,9 +22502,9 @@ var ts; function getRootSymbols(symbol) { if (symbol.flags & 268435456 /* UnionProperty */) { var symbols = []; - var name_13 = symbol.name; + var name_14 = symbol.name; ts.forEach(getSymbolLinks(symbol).unionType.types, function (t) { - symbols.push(getPropertyOfType(t, name_13)); + symbols.push(getPropertyOfType(t, name_14)); }); return symbols; } @@ -22677,7 +22722,7 @@ var ts; else if (type.flags & 8192 /* Tuple */) { return "Array"; } - else if (type.flags & 1048576 /* ESSymbol */) { + else if (type.flags & 2097152 /* ESSymbol */) { return "Symbol"; } else if (type === unknownType) { @@ -22969,20 +23014,20 @@ var ts; if (impotClause.namedBindings) { var nameBindings = impotClause.namedBindings; if (nameBindings.kind === 212 /* NamespaceImport */) { - var name_14 = nameBindings.name; - if (isReservedWordInStrictMode(name_14)) { - var nameText = ts.declarationNameToString(name_14); - return grammarErrorOnNode(name_14, ts.Diagnostics.Identifier_expected_0_is_a_reserved_word_in_strict_mode, nameText); + var name_15 = nameBindings.name; + if (isReservedWordInStrictMode(name_15)) { + var nameText = ts.declarationNameToString(name_15); + return grammarErrorOnNode(name_15, ts.Diagnostics.Identifier_expected_0_is_a_reserved_word_in_strict_mode, nameText); } } else if (nameBindings.kind === 213 /* NamedImports */) { var reportError = false; for (var _i = 0, _a = nameBindings.elements; _i < _a.length; _i++) { var element = _a[_i]; - var name_15 = element.name; - if (isReservedWordInStrictMode(name_15)) { - var nameText = ts.declarationNameToString(name_15); - reportError = reportError || grammarErrorOnNode(name_15, ts.Diagnostics.Identifier_expected_0_is_a_reserved_word_in_strict_mode, nameText); + var name_16 = element.name; + if (isReservedWordInStrictMode(name_16)) { + var nameText = ts.declarationNameToString(name_16); + reportError = reportError || grammarErrorOnNode(name_16, ts.Diagnostics.Identifier_expected_0_is_a_reserved_word_in_strict_mode, nameText); } } return reportError; @@ -23475,11 +23520,11 @@ var ts; var inStrictMode = (node.parserContextFlags & 1 /* StrictMode */) !== 0; for (var _i = 0, _a = node.properties; _i < _a.length; _i++) { var prop = _a[_i]; - var name_16 = prop.name; + var name_17 = prop.name; if (prop.kind === 176 /* OmittedExpression */ || - name_16.kind === 128 /* ComputedPropertyName */) { + name_17.kind === 128 /* ComputedPropertyName */) { // If the name is not a ComputedPropertyName, the grammar checking will skip it - checkGrammarComputedPropertyName(name_16); + checkGrammarComputedPropertyName(name_17); continue; } // ECMA-262 11.1.5 Object Initialiser @@ -23494,8 +23539,8 @@ var ts; if (prop.kind === 225 /* PropertyAssignment */ || prop.kind === 226 /* ShorthandPropertyAssignment */) { // Grammar checking for computedPropertName and shorthandPropertyAssignment checkGrammarForInvalidQuestionMark(prop, prop.questionToken, ts.Diagnostics.An_object_member_cannot_be_declared_optional); - if (name_16.kind === 7 /* NumericLiteral */) { - checkGrammarNumericLiteral(name_16); + if (name_17.kind === 7 /* NumericLiteral */) { + checkGrammarNumericLiteral(name_17); } currentKind = Property; } @@ -23511,26 +23556,26 @@ var ts; else { ts.Debug.fail("Unexpected syntax kind:" + prop.kind); } - if (!ts.hasProperty(seen, name_16.text)) { - seen[name_16.text] = currentKind; + if (!ts.hasProperty(seen, name_17.text)) { + seen[name_17.text] = currentKind; } else { - var existingKind = seen[name_16.text]; + var existingKind = seen[name_17.text]; if (currentKind === Property && existingKind === Property) { if (inStrictMode) { - grammarErrorOnNode(name_16, ts.Diagnostics.An_object_literal_cannot_have_multiple_properties_with_the_same_name_in_strict_mode); + grammarErrorOnNode(name_17, ts.Diagnostics.An_object_literal_cannot_have_multiple_properties_with_the_same_name_in_strict_mode); } } else if ((currentKind & GetOrSetAccessor) && (existingKind & GetOrSetAccessor)) { if (existingKind !== GetOrSetAccessor && currentKind !== existingKind) { - seen[name_16.text] = currentKind | existingKind; + seen[name_17.text] = currentKind | existingKind; } else { - return grammarErrorOnNode(name_16, ts.Diagnostics.An_object_literal_cannot_have_multiple_get_Slashset_accessors_with_the_same_name); + return grammarErrorOnNode(name_17, ts.Diagnostics.An_object_literal_cannot_have_multiple_get_Slashset_accessors_with_the_same_name); } } else { - return grammarErrorOnNode(name_16, ts.Diagnostics.An_object_literal_cannot_have_property_and_accessor_with_the_same_name); + return grammarErrorOnNode(name_17, ts.Diagnostics.An_object_literal_cannot_have_property_and_accessor_with_the_same_name); } } } @@ -24391,9 +24436,9 @@ var ts; } var count = 0; while (true) { - var name_17 = baseName + "_" + (++count); - if (!ts.hasProperty(currentSourceFile.identifiers, name_17)) { - return name_17; + var name_18 = baseName + "_" + (++count); + if (!ts.hasProperty(currentSourceFile.identifiers, name_18)) { + return name_18; } } } @@ -25602,9 +25647,9 @@ var ts; tempFlags++; // Skip over 'i' and 'n' if (count !== 8 && count !== 13) { - var name_18 = count < 26 ? "_" + String.fromCharCode(97 /* a */ + count) : "_" + (count - 26); - if (isUniqueName(name_18)) { - return name_18; + var name_19 = count < 26 ? "_" + String.fromCharCode(97 /* a */ + count) : "_" + (count - 26); + if (isUniqueName(name_19)) { + return name_19; } } } @@ -25637,9 +25682,9 @@ var ts; } function generateNameForModuleOrEnum(node) { if (node.name.kind === 65 /* Identifier */) { - var name_19 = node.name.text; + var name_20 = node.name.text; // Use module/enum name itself if it is unique, otherwise make a unique variation - assignGeneratedName(node, isUniqueLocalName(name_19, node) ? name_19 : makeUniqueName(name_19)); + assignGeneratedName(node, isUniqueLocalName(name_20, node) ? name_20 : makeUniqueName(name_20)); } } function generateNameForImportOrExportDeclaration(node) { @@ -25858,8 +25903,8 @@ var ts; // Child scopes are always shown with a dot (even if they have no name), // unless it is a computed property. Then it is shown with brackets, // but the brackets are included in the name. - var name_20 = node.name; - if (!name_20 || name_20.kind !== 128 /* ComputedPropertyName */) { + var name_21 = node.name; + if (!name_21 || name_21.kind !== 128 /* ComputedPropertyName */) { scopeName = "." + scopeName; } scopeName = sourceMapData.sourceMapNames[parentIndex] + scopeName; @@ -25888,10 +25933,10 @@ var ts; node.kind === 205 /* EnumDeclaration */) { // Declaration and has associated name use it if (node.name) { - var name_21 = node.name; + var name_22 = node.name; // For computed property names, the text will include the brackets - scopeName = name_21.kind === 128 /* ComputedPropertyName */ - ? ts.getTextOfNode(name_21) + scopeName = name_22.kind === 128 /* ComputedPropertyName */ + ? ts.getTextOfNode(name_22) : node.name.text; } recordScopeNameStart(scopeName); @@ -26836,6 +26881,11 @@ var ts; return result; } function parenthesizeForAccess(expr) { + // When diagnosing whether the expression needs parentheses, the decision should be based + // on the innermost expression in a chain of nested type assertions. + while (expr.kind === 161 /* TypeAssertionExpression */) { + expr = expr.expression; + } // isLeftHandSideExpression is almost the correct criterion for when it is not necessary // to parenthesize the expression before a dot. The known exceptions are: // @@ -26844,7 +26894,9 @@ var ts; // NumberLiteral // 1.x -> not the same as (1).x // - if (ts.isLeftHandSideExpression(expr) && expr.kind !== 159 /* NewExpression */ && expr.kind !== 7 /* NumericLiteral */) { + if (ts.isLeftHandSideExpression(expr) && + expr.kind !== 159 /* NewExpression */ && + expr.kind !== 7 /* NumericLiteral */) { return expr; } var node = ts.createSynthesizedNode(162 /* ParenthesizedExpression */); @@ -27106,7 +27158,10 @@ var ts; } } function emitParenExpression(node) { - if (!node.parent || node.parent.kind !== 164 /* ArrowFunction */) { + // If the node is synthesized, it means the emitter put the parentheses there, + // not the user. If we didn't want them, the emitter would not have put them + // there. + if (!ts.nodeIsSynthesized(node) && node.parent.kind !== 164 /* ArrowFunction */) { if (node.expression.kind === 161 /* TypeAssertionExpression */) { var operand = node.expression.expression; // Make sure we consider all nested cast expressions, e.g.: @@ -28181,12 +28236,12 @@ var ts; function emitParameter(node) { if (languageVersion < 2 /* ES6 */) { if (ts.isBindingPattern(node.name)) { - var name_22 = createTempVariable(0 /* Auto */); + var name_23 = createTempVariable(0 /* Auto */); if (!tempParameters) { tempParameters = []; } - tempParameters.push(name_22); - emit(name_22); + tempParameters.push(name_23); + emit(name_23); } else { emit(node.name); @@ -29854,8 +29909,8 @@ var ts; // export { x, y } for (var _c = 0, _d = node.exportClause.elements; _c < _d.length; _c++) { var specifier = _d[_c]; - var name_23 = (specifier.propertyName || specifier.name).text; - (exportSpecifiers[name_23] || (exportSpecifiers[name_23] = [])).push(specifier); + var name_24 = (specifier.propertyName || specifier.name).text; + (exportSpecifiers[name_24] || (exportSpecifiers[name_24] = [])).push(specifier); } } break; @@ -30055,12 +30110,12 @@ var ts; var seen = {}; for (var i = 0; i < hoistedVars.length; ++i) { var local = hoistedVars[i]; - var name_24 = local.kind === 65 /* Identifier */ + var name_25 = local.kind === 65 /* Identifier */ ? local : local.name; - if (name_24) { + if (name_25) { // do not emit duplicate entries (in case of declaration merging) in the list of hoisted variables - var text = ts.unescapeIdentifier(name_24.text); + var text = ts.unescapeIdentifier(name_25.text); if (ts.hasProperty(seen, text)) { continue; } @@ -30139,15 +30194,15 @@ var ts; } if (node.kind === 199 /* VariableDeclaration */ || node.kind === 153 /* BindingElement */) { if (shouldHoistVariable(node, false)) { - var name_25 = node.name; - if (name_25.kind === 65 /* Identifier */) { + var name_26 = node.name; + if (name_26.kind === 65 /* Identifier */) { if (!hoistedVars) { hoistedVars = []; } - hoistedVars.push(name_25); + hoistedVars.push(name_26); } else { - ts.forEachChild(name_25, visit); + ts.forEachChild(name_26, visit); } } return; @@ -30945,8 +31000,6 @@ var ts; /* @internal */ ts.ioWriteTime = 0; /** The version of the TypeScript compiler release */ ts.version = "1.5.3"; - var carriageReturnLineFeed = "\r\n"; - var lineFeed = "\n"; function findConfigFile(searchPath) { var fileName = "tsconfig.json"; while (true) { @@ -31020,9 +31073,7 @@ var ts; } } } - var newLine = options.newLine === 0 /* CarriageReturnLineFeed */ ? carriageReturnLineFeed : - options.newLine === 1 /* LineFeed */ ? lineFeed : - ts.sys.newLine; + var newLine = ts.getNewLineCharacter(options); return { getSourceFile: getSourceFile, getDefaultLibFileName: function (options) { return ts.combinePaths(ts.getDirectoryPath(ts.normalizePath(ts.sys.getExecutingFilePath())), ts.getDefaultLibFileName(options)); }, @@ -31090,6 +31141,7 @@ var ts; getGlobalDiagnostics: getGlobalDiagnostics, getSemanticDiagnostics: getSemanticDiagnostics, getDeclarationDiagnostics: getDeclarationDiagnostics, + getCompilerOptionsDiagnostics: getCompilerOptionsDiagnostics, getTypeChecker: getTypeChecker, getDiagnosticsProducingTypeChecker: getDiagnosticsProducingTypeChecker, getCommonSourceDirectory: function () { return commonSourceDirectory; }, @@ -31181,6 +31233,11 @@ var ts; return ts.getDeclarationDiagnostics(getEmitHost(writeFile), resolver, sourceFile); } } + function getCompilerOptionsDiagnostics() { + var allDiagnostics = []; + ts.addRange(allDiagnostics, diagnostics.getGlobalDiagnostics()); + return ts.sortAndDeduplicateDiagnostics(allDiagnostics); + } function getGlobalDiagnostics() { var typeChecker = getDiagnosticsProducingTypeChecker(); var allDiagnostics = []; @@ -31838,7 +31895,7 @@ var ts; var errors = []; return { options: getCompilerOptions(), - fileNames: getFiles(), + fileNames: getFileNames(), errors: errors }; function getCompilerOptions() { @@ -31882,23 +31939,24 @@ var ts; } return options; } - function getFiles() { - var files = []; + function getFileNames() { + var fileNames = []; if (ts.hasProperty(json, "files")) { if (json["files"] instanceof Array) { - var files = ts.map(json["files"], function (s) { return ts.combinePaths(basePath, s); }); + fileNames = ts.map(json["files"], function (s) { return ts.combinePaths(basePath, s); }); } } else { - var sysFiles = host.readDirectory(basePath, ".ts"); + var exclude = json["exclude"] instanceof Array ? ts.map(json["exclude"], ts.normalizeSlashes) : undefined; + var sysFiles = host.readDirectory(basePath, ".ts", exclude); for (var i = 0; i < sysFiles.length; i++) { var name = sysFiles[i]; if (!ts.fileExtensionIs(name, ".d.ts") || !ts.contains(sysFiles, name.substr(0, name.length - 5) + ".ts")) { - files.push(name); + fileNames.push(name); } } } - return files; + return fileNames; } } ts.parseConfigFile = parseConfigFile; @@ -32077,12 +32135,12 @@ var ts; ts.forEach(program.getSourceFiles(), function (sourceFile) { cancellationToken.throwIfCancellationRequested(); var nameToDeclarations = sourceFile.getNamedDeclarations(); - for (var name_26 in nameToDeclarations) { - var declarations = ts.getProperty(nameToDeclarations, name_26); + for (var name_27 in nameToDeclarations) { + var declarations = ts.getProperty(nameToDeclarations, name_27); if (declarations) { // First do a quick check to see if the name of the declaration matches the // last portion of the (possibly) dotted name they're searching for. - var matches = patternMatcher.getMatchesForLastSegmentOfPattern(name_26); + var matches = patternMatcher.getMatchesForLastSegmentOfPattern(name_27); if (!matches) { continue; } @@ -32095,14 +32153,14 @@ var ts; if (!containers) { return undefined; } - matches = patternMatcher.getMatches(containers, name_26); + matches = patternMatcher.getMatches(containers, name_27); if (!matches) { continue; } } var fileName = sourceFile.fileName; var matchKind = bestMatchKind(matches); - rawItems.push({ name: name_26, fileName: fileName, matchKind: matchKind, isCaseSensitive: allMatchesAreCaseSensitive(matches), declaration: declaration }); + rawItems.push({ name: name_27, fileName: fileName, matchKind: matchKind, isCaseSensitive: allMatchesAreCaseSensitive(matches), declaration: declaration }); } } } @@ -32485,9 +32543,9 @@ var ts; case 199 /* VariableDeclaration */: case 153 /* BindingElement */: var variableDeclarationNode; - var name_27; + var name_28; if (node.kind === 153 /* BindingElement */) { - name_27 = node.name; + name_28 = node.name; variableDeclarationNode = node; // binding elements are added only for variable declarations // bubble up to the containing variable declaration @@ -32499,16 +32557,16 @@ var ts; else { ts.Debug.assert(!ts.isBindingPattern(node.name)); variableDeclarationNode = node; - name_27 = node.name; + name_28 = node.name; } if (ts.isConst(variableDeclarationNode)) { - return createItem(node, getTextOfNode(name_27), ts.ScriptElementKind.constElement); + return createItem(node, getTextOfNode(name_28), ts.ScriptElementKind.constElement); } else if (ts.isLet(variableDeclarationNode)) { - return createItem(node, getTextOfNode(name_27), ts.ScriptElementKind.letElement); + return createItem(node, getTextOfNode(name_28), ts.ScriptElementKind.letElement); } else { - return createItem(node, getTextOfNode(name_27), ts.ScriptElementKind.variableElement); + return createItem(node, getTextOfNode(name_28), ts.ScriptElementKind.variableElement); } case 136 /* Constructor */: return createItem(node, "constructor", ts.ScriptElementKind.constructorImplementationElement); @@ -35097,9 +35155,9 @@ var ts; } Rules.prototype.getRuleName = function (rule) { var o = this; - for (var name_28 in o) { - if (o[name_28] === rule) { - return name_28; + for (var name_29 in o) { + if (o[name_29] === rule) { + return name_29; } } throw new Error("Unknown rule"); @@ -38000,12 +38058,20 @@ var ts; * Extra compiler options that will unconditionally be used bu this function are: * - isolatedModules = true * - allowNonTsExtensions = true + * - noLib = true + * - noResolve = true */ function transpile(input, compilerOptions, fileName, diagnostics) { var options = compilerOptions ? ts.clone(compilerOptions) : getDefaultCompilerOptions(); options.isolatedModules = true; // Filename can be non-ts file. options.allowNonTsExtensions = true; + // We are not returning a sourceFile for lib file when asked by the program, + // so pass --noLib to avoid reporting a file not found error. + options.noLib = true; + // We are not doing a full typecheck, we are not resolving the whole context, + // so pass --noResolve to avoid reporting missing file errors. + options.noResolve = true; // Parse var inputFileName = fileName || "module.ts"; var sourceFile = ts.createSourceFile(inputFileName, input, options.target); @@ -38013,6 +38079,7 @@ var ts; if (diagnostics && sourceFile.parseDiagnostics) { diagnostics.push.apply(diagnostics, sourceFile.parseDiagnostics); } + var newLine = ts.getNewLineCharacter(options); // Output var outputText; // Create a compilerHost object to allow the compiler to read and write files @@ -38026,11 +38093,11 @@ var ts; useCaseSensitiveFileNames: function () { return false; }, getCanonicalFileName: function (fileName) { return fileName; }, getCurrentDirectory: function () { return ""; }, - getNewLine: function () { return (ts.sys && ts.sys.newLine) || "\r\n"; } + getNewLine: function () { return newLine; } }; var program = ts.createProgram([inputFileName], options, compilerHost); if (diagnostics) { - diagnostics.push.apply(diagnostics, program.getGlobalDiagnostics()); + diagnostics.push.apply(diagnostics, program.getCompilerOptionsDiagnostics()); } // Emit program.emit(); @@ -39424,10 +39491,10 @@ var ts; for (var _i = 0, _a = program.getSourceFiles(); _i < _a.length; _i++) { var sourceFile = _a[_i]; var nameTable = getNameTable(sourceFile); - for (var name_29 in nameTable) { - if (!allNames[name_29]) { - allNames[name_29] = name_29; - var displayName = getCompletionEntryDisplayName(name_29, target, true); + for (var name_30 in nameTable) { + if (!allNames[name_30]) { + allNames[name_30] = name_30; + var displayName = getCompletionEntryDisplayName(name_30, target, true); if (displayName) { var entry = { name: displayName, @@ -41309,19 +41376,19 @@ var ts; if (isNameOfPropertyAssignment(node)) { var objectLiteral = node.parent.parent; var contextualType = typeChecker.getContextualType(objectLiteral); - var name_30 = node.text; + var name_31 = node.text; if (contextualType) { if (contextualType.flags & 16384 /* Union */) { // This is a union type, first see if the property we are looking for is a union property (i.e. exists in all types) // if not, search the constituent types for the property - var unionProperty = contextualType.getProperty(name_30); + var unionProperty = contextualType.getProperty(name_31); if (unionProperty) { return [unionProperty]; } else { var result_4 = []; ts.forEach(contextualType.types, function (t) { - var symbol = t.getProperty(name_30); + var symbol = t.getProperty(name_31); if (symbol) { result_4.push(symbol); } @@ -41330,7 +41397,7 @@ var ts; } } else { - var symbol_1 = contextualType.getProperty(name_30); + var symbol_1 = contextualType.getProperty(name_31); if (symbol_1) { return [symbol_1]; } diff --git a/bin/typescriptServices.d.ts b/bin/typescriptServices.d.ts index ea7d2a352ec..9a153ade4b1 100644 --- a/bin/typescriptServices.d.ts +++ b/bin/typescriptServices.d.ts @@ -857,7 +857,7 @@ declare module ts { getCurrentDirectory(): string; } interface ParseConfigHost { - readDirectory(rootDir: string, extension: string): string[]; + readDirectory(rootDir: string, extension: string, exclude: string[]): string[]; } interface WriteFileCallback { (fileName: string, data: string, writeByteOrderMark: boolean, onError?: (message: string) => void): void; @@ -1091,8 +1091,9 @@ declare module ts { Tuple = 8192, Union = 16384, Anonymous = 32768, - ObjectLiteral = 131072, - ESSymbol = 1048576, + Instantiated = 65536, + ObjectLiteral = 262144, + ESSymbol = 2097152, StringLike = 258, NumberLike = 132, ObjectType = 48128, @@ -1281,7 +1282,7 @@ declare module ts { createDirectory(path: string): void; getExecutingFilePath(): string; getCurrentDirectory(): string; - readDirectory(path: string, extension?: string): string[]; + readDirectory(path: string, extension?: string, exclude?: string[]): string[]; getMemoryUsage?(): number; exit(exitCode?: number): void; } diff --git a/bin/typescriptServices.js b/bin/typescriptServices.js index 2b3f25998a5..3dd6dd919be 100644 --- a/bin/typescriptServices.js +++ b/bin/typescriptServices.js @@ -532,23 +532,24 @@ var ts; TypeFlags[TypeFlags["Tuple"] = 8192] = "Tuple"; TypeFlags[TypeFlags["Union"] = 16384] = "Union"; TypeFlags[TypeFlags["Anonymous"] = 32768] = "Anonymous"; + TypeFlags[TypeFlags["Instantiated"] = 65536] = "Instantiated"; /* @internal */ - TypeFlags[TypeFlags["FromSignature"] = 65536] = "FromSignature"; - TypeFlags[TypeFlags["ObjectLiteral"] = 131072] = "ObjectLiteral"; + TypeFlags[TypeFlags["FromSignature"] = 131072] = "FromSignature"; + TypeFlags[TypeFlags["ObjectLiteral"] = 262144] = "ObjectLiteral"; /* @internal */ - TypeFlags[TypeFlags["ContainsUndefinedOrNull"] = 262144] = "ContainsUndefinedOrNull"; + TypeFlags[TypeFlags["ContainsUndefinedOrNull"] = 524288] = "ContainsUndefinedOrNull"; /* @internal */ - TypeFlags[TypeFlags["ContainsObjectLiteral"] = 524288] = "ContainsObjectLiteral"; - TypeFlags[TypeFlags["ESSymbol"] = 1048576] = "ESSymbol"; + TypeFlags[TypeFlags["ContainsObjectLiteral"] = 1048576] = "ContainsObjectLiteral"; + TypeFlags[TypeFlags["ESSymbol"] = 2097152] = "ESSymbol"; /* @internal */ - TypeFlags[TypeFlags["Intrinsic"] = 1048703] = "Intrinsic"; + TypeFlags[TypeFlags["Intrinsic"] = 2097279] = "Intrinsic"; /* @internal */ - TypeFlags[TypeFlags["Primitive"] = 1049086] = "Primitive"; + TypeFlags[TypeFlags["Primitive"] = 2097662] = "Primitive"; TypeFlags[TypeFlags["StringLike"] = 258] = "StringLike"; TypeFlags[TypeFlags["NumberLike"] = 132] = "NumberLike"; TypeFlags[TypeFlags["ObjectType"] = 48128] = "ObjectType"; /* @internal */ - TypeFlags[TypeFlags["RequiresWidening"] = 786432] = "RequiresWidening"; + TypeFlags[TypeFlags["RequiresWidening"] = 1572864] = "RequiresWidening"; })(ts.TypeFlags || (ts.TypeFlags = {})); var TypeFlags = ts.TypeFlags; (function (SignatureKind) { @@ -1506,6 +1507,9 @@ var ts; fileStream.Close(); } } + function getCanonicalPath(path) { + return path.toLowerCase(); + } function getNames(collection) { var result = []; for (var e = new Enumerator(collection); !e.atEnd(); e.moveNext()) { @@ -1513,23 +1517,28 @@ var ts; } return result.sort(); } - function readDirectory(path, extension) { + function readDirectory(path, extension, exclude) { var result = []; + exclude = ts.map(exclude, function (s) { return getCanonicalPath(ts.combinePaths(path, s)); }); visitDirectory(path); return result; function visitDirectory(path) { var folder = fso.GetFolder(path || "."); var files = getNames(folder.files); for (var _i = 0; _i < files.length; _i++) { - var name_1 = files[_i]; - if (!extension || ts.fileExtensionIs(name_1, extension)) { - result.push(ts.combinePaths(path, name_1)); + var current = files[_i]; + var name_1 = ts.combinePaths(path, current); + if ((!extension || ts.fileExtensionIs(name_1, extension)) && !ts.contains(exclude, getCanonicalPath(name_1))) { + result.push(name_1); } } var subfolders = getNames(folder.subfolders); for (var _a = 0; _a < subfolders.length; _a++) { var current = subfolders[_a]; - visitDirectory(ts.combinePaths(path, current)); + var name_2 = ts.combinePaths(path, current); + if (!ts.contains(exclude, getCanonicalPath(name_2))) { + visitDirectory(name_2); + } } } } @@ -1614,8 +1623,12 @@ var ts; } _fs.writeFileSync(fileName, data, "utf8"); } - function readDirectory(path, extension) { + function getCanonicalPath(path) { + return useCaseSensitiveFileNames ? path.toLowerCase() : path; + } + function readDirectory(path, extension, exclude) { var result = []; + exclude = ts.map(exclude, function (s) { return getCanonicalPath(ts.combinePaths(path, s)); }); visitDirectory(path); return result; function visitDirectory(path) { @@ -1624,14 +1637,16 @@ var ts; for (var _i = 0; _i < files.length; _i++) { var current = files[_i]; var name = ts.combinePaths(path, current); - var stat = _fs.statSync(name); - if (stat.isFile()) { - if (!extension || ts.fileExtensionIs(name, extension)) { - result.push(name); + if (!ts.contains(exclude, getCanonicalPath(name))) { + var stat = _fs.statSync(name); + if (stat.isFile()) { + if (!extension || ts.fileExtensionIs(name, extension)) { + result.push(name); + } + } + else if (stat.isDirectory()) { + directories.push(name); } - } - else if (stat.isDirectory()) { - directories.push(name); } } for (var _a = 0; _a < directories.length; _a++) { @@ -2239,7 +2254,7 @@ var ts; Object_literal_s_property_0_implicitly_has_an_1_type: { code: 7018, category: ts.DiagnosticCategory.Error, key: "Object literal's property '{0}' implicitly has an '{1}' type." }, Rest_parameter_0_implicitly_has_an_any_type: { code: 7019, category: ts.DiagnosticCategory.Error, key: "Rest parameter '{0}' implicitly has an 'any[]' type." }, Call_signature_which_lacks_return_type_annotation_implicitly_has_an_any_return_type: { code: 7020, category: ts.DiagnosticCategory.Error, key: "Call signature, which lacks return-type annotation, implicitly has an 'any' return type." }, - _0_implicitly_has_type_any_because_it_is_does_not_have_a_type_annotation_and_is_referenced_directly_or_indirectly_in_its_own_initializer: { code: 7022, category: ts.DiagnosticCategory.Error, key: "'{0}' implicitly has type 'any' because it is does not have a type annotation and is referenced directly or indirectly in its own initializer." }, + _0_implicitly_has_type_any_because_it_does_not_have_a_type_annotation_and_is_referenced_directly_or_indirectly_in_its_own_initializer: { code: 7022, category: ts.DiagnosticCategory.Error, key: "'{0}' implicitly has type 'any' because it does not have a type annotation and is referenced directly or indirectly in its own initializer." }, _0_implicitly_has_return_type_any_because_it_does_not_have_a_return_type_annotation_and_is_referenced_directly_or_indirectly_in_one_of_its_return_expressions: { code: 7023, category: ts.DiagnosticCategory.Error, key: "'{0}' implicitly has return type 'any' because it does not have a return type annotation and is referenced directly or indirectly in one of its return expressions." }, Function_implicitly_has_return_type_any_because_it_does_not_have_a_return_type_annotation_and_is_referenced_directly_or_indirectly_in_one_of_its_return_expressions: { code: 7024, category: ts.DiagnosticCategory.Error, key: "Function implicitly has return type 'any' because it does not have a return type annotation and is referenced directly or indirectly in one of its return expressions." }, Generator_implicitly_has_type_0_because_it_does_not_yield_any_values_Consider_supplying_a_return_type: { code: 7025, category: ts.DiagnosticCategory.Error, key: "Generator implicitly has type '{0}' because it does not yield any values. Consider supplying a return type." }, @@ -2466,9 +2481,9 @@ var ts; } function makeReverseMap(source) { var result = []; - for (var name_2 in source) { - if (source.hasOwnProperty(name_2)) { - result[source[name_2]] = name_2; + for (var name_3 in source) { + if (source.hasOwnProperty(name_3)) { + result[source[name_3]] = name_3; } } return result; @@ -4815,11 +4830,11 @@ var ts; return; default: if (isFunctionLike(node)) { - var name_3 = node.name; - if (name_3 && name_3.kind === 128 /* ComputedPropertyName */) { + var name_4 = node.name; + if (name_4 && name_4.kind === 128 /* ComputedPropertyName */) { // Note that we will not include methods/accessors of a class because they would require // first descending into the class. This is by design. - traverse(name_3.expression); + traverse(name_4.expression); return; } } @@ -5268,8 +5283,8 @@ var ts; return ts.forEach(docComment.tags, function (t) { if (t.kind === 247 /* JSDocParameterTag */) { var parameterTag = t; - var name_4 = parameterTag.preParameterName || parameterTag.postParameterName; - if (name_4.text === parameterName) { + var name_5 = parameterTag.preParameterName || parameterTag.postParameterName; + if (name_5.text === parameterName) { return t; } } @@ -6159,6 +6174,21 @@ var ts; return result; } ts.convertToBase64 = convertToBase64; + var carriageReturnLineFeed = "\r\n"; + var lineFeed = "\n"; + function getNewLineCharacter(options) { + if (options.newLine === 0 /* CarriageReturnLineFeed */) { + return carriageReturnLineFeed; + } + else if (options.newLine === 1 /* LineFeed */) { + return lineFeed; + } + else if (ts.sys) { + return ts.sys.newLine; + } + return carriageReturnLineFeed; + } + ts.getNewLineCharacter = getNewLineCharacter; })(ts || (ts = {})); var ts; (function (ts) { @@ -10274,8 +10304,8 @@ var ts; } if (decorators) { // treat this as a property declaration with a missing name. - var name_5 = createMissingNode(65 /* Identifier */, true, ts.Diagnostics.Declaration_expected); - return parsePropertyDeclaration(fullStart, decorators, modifiers, name_5, undefined); + var name_6 = createMissingNode(65 /* Identifier */, true, ts.Diagnostics.Declaration_expected); + return parsePropertyDeclaration(fullStart, decorators, modifiers, name_6, undefined); } // 'isClassMemberStart' should have hinted not to attempt parsing. ts.Debug.fail("Should not have attempted to parse class member declaration."); @@ -11225,13 +11255,13 @@ var ts; while (true) { skipWhitespace(); var startPos = pos; - var name_6 = scanIdentifier(); - if (!name_6) { + var name_7 = scanIdentifier(); + if (!name_7) { parseErrorAtPosition(startPos, 0, ts.Diagnostics.Identifier_expected); return undefined; } - var typeParameter = createNode(129 /* TypeParameter */, name_6.pos); - typeParameter.name = name_6; + var typeParameter = createNode(129 /* TypeParameter */, name_7.pos); + typeParameter.name = name_7; finishNode(typeParameter, pos); typeParameters.push(typeParameter); skipWhitespace(); @@ -11816,10 +11846,10 @@ var ts; var stringType = createIntrinsicType(2 /* String */, "string"); var numberType = createIntrinsicType(4 /* Number */, "number"); var booleanType = createIntrinsicType(8 /* Boolean */, "boolean"); - var esSymbolType = createIntrinsicType(1048576 /* ESSymbol */, "symbol"); + var esSymbolType = createIntrinsicType(2097152 /* ESSymbol */, "symbol"); var voidType = createIntrinsicType(16 /* Void */, "void"); - var undefinedType = createIntrinsicType(32 /* Undefined */ | 262144 /* ContainsUndefinedOrNull */, "undefined"); - var nullType = createIntrinsicType(64 /* Null */ | 262144 /* ContainsUndefinedOrNull */, "null"); + var undefinedType = createIntrinsicType(32 /* Undefined */ | 524288 /* ContainsUndefinedOrNull */, "undefined"); + var nullType = createIntrinsicType(64 /* Null */ | 524288 /* ContainsUndefinedOrNull */, "null"); var unknownType = createIntrinsicType(1 /* Any */, "unknown"); var circularType = createIntrinsicType(1 /* Any */, "__circular__"); var emptyObjectType = createAnonymousType(undefined, emptySymbols, emptyArray, emptyArray, undefined, undefined); @@ -11876,7 +11906,7 @@ var ts; }, "symbol": { type: esSymbolType, - flags: 1048576 /* ESSymbol */ + flags: 2097152 /* ESSymbol */ } }; function getEmitResolver(sourceFile) { @@ -12383,15 +12413,15 @@ var ts; var moduleSymbol = resolveExternalModuleName(node, node.moduleSpecifier); var targetSymbol = resolveESModuleSymbol(moduleSymbol, node.moduleSpecifier); if (targetSymbol) { - var name_7 = specifier.propertyName || specifier.name; - if (name_7.text) { - var symbolFromModule = getExportOfModule(targetSymbol, name_7.text); - var symbolFromVariable = getPropertyOfVariable(targetSymbol, name_7.text); + var name_8 = specifier.propertyName || specifier.name; + if (name_8.text) { + var symbolFromModule = getExportOfModule(targetSymbol, name_8.text); + var symbolFromVariable = getPropertyOfVariable(targetSymbol, name_8.text); var symbol = symbolFromModule && symbolFromVariable ? combineValueAndTypeSymbols(symbolFromVariable, symbolFromModule) : symbolFromModule || symbolFromVariable; if (!symbol) { - error(name_7, ts.Diagnostics.Module_0_has_no_exported_member_1, getFullyQualifiedName(moduleSymbol), ts.declarationNameToString(name_7)); + error(name_8, ts.Diagnostics.Module_0_has_no_exported_member_1, getFullyQualifiedName(moduleSymbol), ts.declarationNameToString(name_8)); } return symbol; } @@ -13097,15 +13127,16 @@ var ts; } return appendParentTypeArgumentsAndSymbolName(symbol); } - function buildTypeDisplay(type, writer, enclosingDeclaration, globalFlags, typeStack) { + function buildTypeDisplay(type, writer, enclosingDeclaration, globalFlags, symbolStack) { var globalFlagsToPass = globalFlags & 16 /* WriteOwnNameForAnyLike */; return writeType(type, globalFlags); function writeType(type, flags) { // Write undefined/null type as any - if (type.flags & 1048703 /* Intrinsic */) { + if (type.flags & 2097279 /* Intrinsic */) { // Special handling for unknown / resolving types, they should show up as any and not unknown or __resolving - writer.writeKeyword(!(globalFlags & 16 /* WriteOwnNameForAnyLike */) && - (type.flags & 1 /* Any */) ? "any" : type.intrinsicName); + writer.writeKeyword(!(globalFlags & 16 /* WriteOwnNameForAnyLike */) && isTypeAny(type) + ? "any" + : type.intrinsicName); } else if (type.flags & 4096 /* Reference */) { writeTypeReference(type, flags); @@ -13213,47 +13244,54 @@ var ts; } } function writeAnonymousType(type, flags) { - // Always use 'typeof T' for type of class, enum, and module objects - if (type.symbol && type.symbol.flags & (32 /* Class */ | 384 /* Enum */ | 512 /* ValueModule */)) { - writeTypeofSymbol(type, flags); - } - else if (shouldWriteTypeOfFunctionSymbol()) { - writeTypeofSymbol(type, flags); - } - else if (typeStack && ts.contains(typeStack, type)) { - // If type is an anonymous type literal in a type alias declaration, use type alias name - var typeAlias = getTypeAliasForTypeLiteral(type); - if (typeAlias) { - // The specified symbol flags need to be reinterpreted as type flags - buildSymbolDisplay(typeAlias, writer, enclosingDeclaration, 793056 /* Type */, 0 /* None */, flags); + var symbol = type.symbol; + if (symbol) { + // Always use 'typeof T' for type of class, enum, and module objects + if (symbol.flags & (32 /* Class */ | 384 /* Enum */ | 512 /* ValueModule */)) { + writeTypeofSymbol(type, flags); + } + else if (shouldWriteTypeOfFunctionSymbol()) { + writeTypeofSymbol(type, flags); + } + else if (ts.contains(symbolStack, symbol)) { + // If type is an anonymous type literal in a type alias declaration, use type alias name + var typeAlias = getTypeAliasForTypeLiteral(type); + if (typeAlias) { + // The specified symbol flags need to be reinterpreted as type flags + buildSymbolDisplay(typeAlias, writer, enclosingDeclaration, 793056 /* Type */, 0 /* None */, flags); + } + else { + // Recursive usage, use any + writeKeyword(writer, 112 /* AnyKeyword */); + } } else { - // Recursive usage, use any - writeKeyword(writer, 112 /* AnyKeyword */); + // Since instantiations of the same anonymous type have the same symbol, tracking symbols instead + // of types allows us to catch circular references to instantiations of the same anonymous type + if (!symbolStack) { + symbolStack = []; + } + symbolStack.push(symbol); + writeLiteralType(type, flags); + symbolStack.pop(); } } else { - if (!typeStack) { - typeStack = []; - } - typeStack.push(type); + // Anonymous types with no symbol are never circular writeLiteralType(type, flags); - typeStack.pop(); } function shouldWriteTypeOfFunctionSymbol() { - if (type.symbol) { - var isStaticMethodSymbol = !!(type.symbol.flags & 8192 /* Method */ && - ts.forEach(type.symbol.declarations, function (declaration) { return declaration.flags & 128 /* Static */; })); - var isNonLocalFunctionSymbol = !!(type.symbol.flags & 16 /* Function */) && - (type.symbol.parent || - ts.forEach(type.symbol.declarations, function (declaration) { - return declaration.parent.kind === 228 /* SourceFile */ || declaration.parent.kind === 207 /* ModuleBlock */; - })); - if (isStaticMethodSymbol || isNonLocalFunctionSymbol) { - // typeof is allowed only for static/non local functions - return !!(flags & 2 /* UseTypeOfFunction */) || - (typeStack && ts.contains(typeStack, type)); // it is type of the symbol uses itself recursively - } + var isStaticMethodSymbol = !!(symbol.flags & 8192 /* Method */ && + ts.forEach(symbol.declarations, function (declaration) { return declaration.flags & 128 /* Static */; })); + var isNonLocalFunctionSymbol = !!(symbol.flags & 16 /* Function */) && + (symbol.parent || + ts.forEach(symbol.declarations, function (declaration) { + return declaration.parent.kind === 228 /* SourceFile */ || declaration.parent.kind === 207 /* ModuleBlock */; + })); + if (isStaticMethodSymbol || isNonLocalFunctionSymbol) { + // typeof is allowed only for static/non local functions + return !!(flags & 2 /* UseTypeOfFunction */) || + (ts.contains(symbolStack, symbol)); // it is type of the symbol uses itself recursively } } } @@ -13284,7 +13322,7 @@ var ts; if (flags & 64 /* InElementType */) { writePunctuation(writer, 16 /* OpenParenToken */); } - buildSignatureDisplay(resolved.callSignatures[0], writer, enclosingDeclaration, globalFlagsToPass | 8 /* WriteArrowStyleSignature */, typeStack); + buildSignatureDisplay(resolved.callSignatures[0], writer, enclosingDeclaration, globalFlagsToPass | 8 /* WriteArrowStyleSignature */, symbolStack); if (flags & 64 /* InElementType */) { writePunctuation(writer, 17 /* CloseParenToken */); } @@ -13296,7 +13334,7 @@ var ts; } writeKeyword(writer, 88 /* NewKeyword */); writeSpace(writer); - buildSignatureDisplay(resolved.constructSignatures[0], writer, enclosingDeclaration, globalFlagsToPass | 8 /* WriteArrowStyleSignature */, typeStack); + buildSignatureDisplay(resolved.constructSignatures[0], writer, enclosingDeclaration, globalFlagsToPass | 8 /* WriteArrowStyleSignature */, symbolStack); if (flags & 64 /* InElementType */) { writePunctuation(writer, 17 /* CloseParenToken */); } @@ -13308,7 +13346,7 @@ var ts; writer.increaseIndent(); for (var _i = 0, _a = resolved.callSignatures; _i < _a.length; _i++) { var signature = _a[_i]; - buildSignatureDisplay(signature, writer, enclosingDeclaration, globalFlagsToPass, typeStack); + buildSignatureDisplay(signature, writer, enclosingDeclaration, globalFlagsToPass, symbolStack); writePunctuation(writer, 22 /* SemicolonToken */); writer.writeLine(); } @@ -13316,7 +13354,7 @@ var ts; var signature = _c[_b]; writeKeyword(writer, 88 /* NewKeyword */); writeSpace(writer); - buildSignatureDisplay(signature, writer, enclosingDeclaration, globalFlagsToPass, typeStack); + buildSignatureDisplay(signature, writer, enclosingDeclaration, globalFlagsToPass, symbolStack); writePunctuation(writer, 22 /* SemicolonToken */); writer.writeLine(); } @@ -13359,7 +13397,7 @@ var ts; if (p.flags & 536870912 /* Optional */) { writePunctuation(writer, 50 /* QuestionToken */); } - buildSignatureDisplay(signature, writer, enclosingDeclaration, globalFlagsToPass, typeStack); + buildSignatureDisplay(signature, writer, enclosingDeclaration, globalFlagsToPass, symbolStack); writePunctuation(writer, 22 /* SemicolonToken */); writer.writeLine(); } @@ -13386,17 +13424,17 @@ var ts; buildDisplayForTypeParametersAndDelimiters(getLocalTypeParametersOfClassOrInterface(symbol), writer, enclosingDeclaraiton, flags); } } - function buildTypeParameterDisplay(tp, writer, enclosingDeclaration, flags, typeStack) { + function buildTypeParameterDisplay(tp, writer, enclosingDeclaration, flags, symbolStack) { appendSymbolNameOnly(tp.symbol, writer); var constraint = getConstraintOfTypeParameter(tp); if (constraint) { writeSpace(writer); writeKeyword(writer, 79 /* ExtendsKeyword */); writeSpace(writer); - buildTypeDisplay(constraint, writer, enclosingDeclaration, flags, typeStack); + buildTypeDisplay(constraint, writer, enclosingDeclaration, flags, symbolStack); } } - function buildParameterDisplay(p, writer, enclosingDeclaration, flags, typeStack) { + function buildParameterDisplay(p, writer, enclosingDeclaration, flags, symbolStack) { var parameterNode = p.valueDeclaration; if (ts.isRestParameter(parameterNode)) { writePunctuation(writer, 21 /* DotDotDotToken */); @@ -13407,9 +13445,9 @@ var ts; } writePunctuation(writer, 51 /* ColonToken */); writeSpace(writer); - buildTypeDisplay(getTypeOfSymbol(p), writer, enclosingDeclaration, flags, typeStack); + buildTypeDisplay(getTypeOfSymbol(p), writer, enclosingDeclaration, flags, symbolStack); } - function buildDisplayForTypeParametersAndDelimiters(typeParameters, writer, enclosingDeclaration, flags, typeStack) { + function buildDisplayForTypeParametersAndDelimiters(typeParameters, writer, enclosingDeclaration, flags, symbolStack) { if (typeParameters && typeParameters.length) { writePunctuation(writer, 24 /* LessThanToken */); for (var i = 0; i < typeParameters.length; i++) { @@ -13417,12 +13455,12 @@ var ts; writePunctuation(writer, 23 /* CommaToken */); writeSpace(writer); } - buildTypeParameterDisplay(typeParameters[i], writer, enclosingDeclaration, flags, typeStack); + buildTypeParameterDisplay(typeParameters[i], writer, enclosingDeclaration, flags, symbolStack); } writePunctuation(writer, 25 /* GreaterThanToken */); } } - function buildDisplayForTypeArgumentsAndDelimiters(typeParameters, mapper, writer, enclosingDeclaration, flags, typeStack) { + function buildDisplayForTypeArgumentsAndDelimiters(typeParameters, mapper, writer, enclosingDeclaration, flags, symbolStack) { if (typeParameters && typeParameters.length) { writePunctuation(writer, 24 /* LessThanToken */); for (var i = 0; i < typeParameters.length; i++) { @@ -13435,18 +13473,18 @@ var ts; writePunctuation(writer, 25 /* GreaterThanToken */); } } - function buildDisplayForParametersAndDelimiters(parameters, writer, enclosingDeclaration, flags, typeStack) { + function buildDisplayForParametersAndDelimiters(parameters, writer, enclosingDeclaration, flags, symbolStack) { writePunctuation(writer, 16 /* OpenParenToken */); for (var i = 0; i < parameters.length; i++) { if (i > 0) { writePunctuation(writer, 23 /* CommaToken */); writeSpace(writer); } - buildParameterDisplay(parameters[i], writer, enclosingDeclaration, flags, typeStack); + buildParameterDisplay(parameters[i], writer, enclosingDeclaration, flags, symbolStack); } writePunctuation(writer, 17 /* CloseParenToken */); } - function buildReturnTypeDisplay(signature, writer, enclosingDeclaration, flags, typeStack) { + function buildReturnTypeDisplay(signature, writer, enclosingDeclaration, flags, symbolStack) { if (flags & 8 /* WriteArrowStyleSignature */) { writeSpace(writer); writePunctuation(writer, 32 /* EqualsGreaterThanToken */); @@ -13455,19 +13493,19 @@ var ts; writePunctuation(writer, 51 /* ColonToken */); } writeSpace(writer); - buildTypeDisplay(getReturnTypeOfSignature(signature), writer, enclosingDeclaration, flags, typeStack); + buildTypeDisplay(getReturnTypeOfSignature(signature), writer, enclosingDeclaration, flags, symbolStack); } - function buildSignatureDisplay(signature, writer, enclosingDeclaration, flags, typeStack) { + function buildSignatureDisplay(signature, writer, enclosingDeclaration, flags, symbolStack) { if (signature.target && (flags & 32 /* WriteTypeArgumentsOfSignature */)) { // Instantiated signature, write type arguments instead // This is achieved by passing in the mapper separately buildDisplayForTypeArgumentsAndDelimiters(signature.target.typeParameters, signature.mapper, writer, enclosingDeclaration); } else { - buildDisplayForTypeParametersAndDelimiters(signature.typeParameters, writer, enclosingDeclaration, flags, typeStack); + buildDisplayForTypeParametersAndDelimiters(signature.typeParameters, writer, enclosingDeclaration, flags, symbolStack); } - buildDisplayForParametersAndDelimiters(signature.parameters, writer, enclosingDeclaration, flags, typeStack); - buildReturnTypeDisplay(signature, writer, enclosingDeclaration, flags, typeStack); + buildDisplayForParametersAndDelimiters(signature.parameters, writer, enclosingDeclaration, flags, symbolStack); + buildReturnTypeDisplay(signature, writer, enclosingDeclaration, flags, symbolStack); } return _displayBuilder || (_displayBuilder = { symbolToString: symbolToString, @@ -13695,6 +13733,9 @@ var ts; var prop = getPropertyOfType(type, name); return prop ? getTypeOfSymbol(prop) : undefined; } + function isTypeAny(type) { + return type && (type.flags & 1 /* Any */) !== 0; + } // Return the inferred type for a binding element function getTypeForBindingElement(declaration) { var pattern = declaration.parent; @@ -13706,7 +13747,7 @@ var ts; // If no type was specified or inferred for parent, or if the specified or inferred type is any, // infer from the initializer of the binding element if one is present. Otherwise, go with the // undefined or any type of the parent. - if (!parentType || parentType === anyType) { + if (!parentType || isTypeAny(parentType)) { if (declaration.initializer) { return checkExpressionCached(declaration.initializer); } @@ -13715,14 +13756,14 @@ var ts; var type; if (pattern.kind === 151 /* ObjectBindingPattern */) { // Use explicitly specified property name ({ p: xxx } form), or otherwise the implied name ({ p } form) - var name_8 = declaration.propertyName || declaration.name; + var name_9 = declaration.propertyName || declaration.name; // Use type of the specified property, or otherwise, for a numeric name, the type of the numeric index signature, // or otherwise the type of the string index signature. - type = getTypeOfPropertyOfType(parentType, name_8.text) || - isNumericLiteralName(name_8.text) && getIndexTypeOfType(parentType, 1 /* Number */) || + type = getTypeOfPropertyOfType(parentType, name_9.text) || + isNumericLiteralName(name_9.text) && getIndexTypeOfType(parentType, 1 /* Number */) || getIndexTypeOfType(parentType, 0 /* String */); if (!type) { - error(name_8, ts.Diagnostics.Type_0_has_no_property_1_and_no_string_index_signature, typeToString(parentType), ts.declarationNameToString(name_8)); + error(name_9, ts.Diagnostics.Type_0_has_no_property_1_and_no_string_index_signature, typeToString(parentType), ts.declarationNameToString(name_9)); return unknownType; } } @@ -13732,7 +13773,7 @@ var ts; // fact an iterable or array (depending on target language). var elementType = checkIteratedTypeOrElementType(parentType, pattern, false); if (!declaration.dotDotDotToken) { - if (elementType.flags & 1 /* Any */) { + if (isTypeAny(elementType)) { return elementType; } // Use specific property type when parent is a tuple or numeric index type when parent is an array @@ -13926,7 +13967,7 @@ var ts; // Variable has initializer that circularly references the variable itself type = anyType; if (compilerOptions.noImplicitAny) { - error(symbol.valueDeclaration, ts.Diagnostics._0_implicitly_has_type_any_because_it_is_does_not_have_a_type_annotation_and_is_referenced_directly_or_indirectly_in_its_own_initializer, symbolToString(symbol)); + error(symbol.valueDeclaration, ts.Diagnostics._0_implicitly_has_type_any_because_it_does_not_have_a_type_annotation_and_is_referenced_directly_or_indirectly_in_its_own_initializer, symbolToString(symbol)); } } } @@ -14569,7 +14610,7 @@ var ts; else if (type.flags & 8 /* Boolean */) { type = globalBooleanType; } - else if (type.flags & 1048576 /* ESSymbol */) { + else if (type.flags & 2097152 /* ESSymbol */) { type = globalESSymbolType; } return type; @@ -14844,7 +14885,7 @@ var ts; // will result in a different declaration kind. if (!signature.isolatedSignatureType) { var isConstructor = signature.declaration.kind === 136 /* Constructor */ || signature.declaration.kind === 140 /* ConstructSignature */; - var type = createObjectType(32768 /* Anonymous */ | 65536 /* FromSignature */); + var type = createObjectType(32768 /* Anonymous */ | 131072 /* FromSignature */); type.members = emptySymbols; type.properties = emptyArray; type.callSignatures = !isConstructor ? [signature] : emptyArray; @@ -14921,7 +14962,7 @@ var ts; var type = types[_i]; result |= type.flags; } - return result & 786432 /* RequiresWidening */; + return result & 1572864 /* RequiresWidening */; } function createTypeReference(target, typeArguments) { var id = getTypeListId(typeArguments); @@ -15165,10 +15206,10 @@ var ts; } } } - function containsAnyType(types) { + function containsTypeAny(types) { for (var _i = 0; _i < types.length; _i++) { var type = types[_i]; - if (type.flags & 1 /* Any */) { + if (isTypeAny(type)) { return true; } } @@ -15194,7 +15235,7 @@ var ts; var sortedTypes = []; addTypesToSortedSet(sortedTypes, types); if (noSubtypeReduction) { - if (containsAnyType(sortedTypes)) { + if (containsTypeAny(sortedTypes)) { return anyType; } removeAllButLast(sortedTypes, undefinedType); @@ -15420,19 +15461,8 @@ var ts; return result; } function instantiateAnonymousType(type, mapper) { - // If this type has already been instantiated using this mapper, returned the cached result. This guards against - // infinite instantiations of cyclic types, e.g. "var x: { a: T, b: typeof x };" - if (mapper.mappings) { - var cached = mapper.mappings[type.id]; - if (cached) { - return cached; - } - } - else { - mapper.mappings = {}; - } - // Instantiate the given type using the given mapper and cache the result - var result = createObjectType(32768 /* Anonymous */, type.symbol); + // Mark the anonymous type as instantiated such that our infinite instantiation detection logic can recognize it + var result = createObjectType(32768 /* Anonymous */ | 65536 /* Instantiated */, type.symbol); result.properties = instantiateList(getPropertiesOfObjectType(type), mapper, instantiateSymbol); result.members = createSymbolTable(result.properties); result.callSignatures = instantiateList(getSignaturesOfType(type, 0 /* Call */), mapper, instantiateSignature); @@ -15443,7 +15473,6 @@ var ts; result.stringIndexType = instantiateType(stringIndexType, mapper); if (numberIndexType) result.numberIndexType = instantiateType(numberIndexType, mapper); - mapper.mappings[type.id] = result; return result; } function instantiateType(type, mapper) { @@ -15582,7 +15611,7 @@ var ts; if (source === target) return -1 /* True */; if (relation !== identityRelation) { - if (target.flags & 1 /* Any */) + if (isTypeAny(target)) return -1 /* True */; if (source === undefinedType) return -1 /* True */; @@ -15593,7 +15622,7 @@ var ts; if (source.flags & 256 /* StringLiteral */ && target === stringType) return -1 /* True */; if (relation === assignableRelation) { - if (source.flags & 1 /* Any */) + if (isTypeAny(source)) return -1 /* True */; if (source === numberType && target.flags & 128 /* Enum */) return -1 /* True */; @@ -15836,12 +15865,13 @@ var ts; // Effectively, we will generate a false positive when two types are structurally equal to at least 10 levels, but unequal at // some level beyond that. function isDeeplyNestedGeneric(type, stack) { - if (type.flags & 4096 /* Reference */ && depth >= 10) { - var target_1 = type.target; + // We track type references (created by createTypeReference) and instantiated types (created by instantiateType) + if (type.flags & (4096 /* Reference */ | 65536 /* Instantiated */) && depth >= 10) { + var symbol = type.symbol; var count = 0; for (var i = 0; i < depth; i++) { var t = stack[i]; - if (t.flags & 4096 /* Reference */ && t.target === target_1) { + if (t.flags & (4096 /* Reference */ | 65536 /* Instantiated */) && t.symbol === symbol) { count++; if (count >= 10) return true; @@ -15856,7 +15886,7 @@ var ts; } var result = -1 /* True */; var properties = getPropertiesOfObjectType(target); - var requireOptionalProperties = relation === subtypeRelation && !(source.flags & 131072 /* ObjectLiteral */); + var requireOptionalProperties = relation === subtypeRelation && !(source.flags & 262144 /* ObjectLiteral */); for (var _i = 0; _i < properties.length; _i++) { var targetProp = properties[_i]; var sourceProp = getPropertyOfType(source, targetProp.name); @@ -15962,11 +15992,11 @@ var ts; var saveErrorInfo = errorInfo; outer: for (var _i = 0; _i < targetSignatures.length; _i++) { var t = targetSignatures[_i]; - if (!t.hasStringLiterals || target.flags & 65536 /* FromSignature */) { + if (!t.hasStringLiterals || target.flags & 131072 /* FromSignature */) { var localErrors = reportErrors; for (var _a = 0; _a < sourceSignatures.length; _a++) { var s = sourceSignatures[_a]; - if (!s.hasStringLiterals || source.flags & 65536 /* FromSignature */) { + if (!s.hasStringLiterals || source.flags & 131072 /* FromSignature */) { var related = signatureRelatedTo(s, t, localErrors); if (related) { result &= related; @@ -16278,11 +16308,11 @@ var ts; return createAnonymousType(type.symbol, members, emptyArray, emptyArray, stringIndexType, numberIndexType); } function getWidenedType(type) { - if (type.flags & 786432 /* RequiresWidening */) { + if (type.flags & 1572864 /* RequiresWidening */) { if (type.flags & (32 /* Undefined */ | 64 /* Null */)) { return anyType; } - if (type.flags & 131072 /* ObjectLiteral */) { + if (type.flags & 262144 /* ObjectLiteral */) { return getWidenedTypeOfObjectLiteral(type); } if (type.flags & 16384 /* Union */) { @@ -16307,11 +16337,11 @@ var ts; if (isArrayType(type)) { return reportWideningErrorsInType(type.typeArguments[0]); } - if (type.flags & 131072 /* ObjectLiteral */) { + if (type.flags & 262144 /* ObjectLiteral */) { var errorReported = false; ts.forEach(getPropertiesOfObjectType(type), function (p) { var t = getTypeOfSymbol(p); - if (t.flags & 262144 /* ContainsUndefinedOrNull */) { + if (t.flags & 524288 /* ContainsUndefinedOrNull */) { if (!reportWideningErrorsInType(t)) { error(p.valueDeclaration, ts.Diagnostics.Object_literal_s_property_0_implicitly_has_an_1_type, p.name, typeToString(getWidenedType(t))); } @@ -16354,7 +16384,7 @@ var ts; error(declaration, diagnostic, ts.declarationNameToString(declaration.name), typeAsString); } function reportErrorsFromWidening(declaration, type) { - if (produceDiagnostics && compilerOptions.noImplicitAny && type.flags & 262144 /* ContainsUndefinedOrNull */) { + if (produceDiagnostics && compilerOptions.noImplicitAny && type.flags & 524288 /* ContainsUndefinedOrNull */) { // Report implicit any error within type if possible, otherwise report error on declaration if (!reportWideningErrorsInType(type)) { reportImplicitAnyError(declaration, type); @@ -16416,11 +16446,11 @@ var ts; } function isWithinDepthLimit(type, stack) { if (depth >= 5) { - var target_2 = type.target; + var target_1 = type.target; var count = 0; for (var i = 0; i < depth; i++) { var t = stack[i]; - if (t.flags & 4096 /* Reference */ && t.target === target_2) { + if (t.flags & 4096 /* Reference */ && t.target === target_1) { count++; } } @@ -16763,52 +16793,54 @@ var ts; function getNarrowedTypeOfSymbol(symbol, node) { var type = getTypeOfSymbol(symbol); // Only narrow when symbol is variable of type any or an object, union, or type parameter type - if (node && symbol.flags & 3 /* Variable */ && type.flags & (1 /* Any */ | 48128 /* ObjectType */ | 16384 /* Union */ | 512 /* TypeParameter */)) { - loop: while (node.parent) { - var child = node; - node = node.parent; - var narrowedType = type; - switch (node.kind) { - case 184 /* IfStatement */: - // In a branch of an if statement, narrow based on controlling expression - if (child !== node.expression) { - narrowedType = narrowType(type, node.expression, child === node.thenStatement); - } - break; - case 171 /* ConditionalExpression */: - // In a branch of a conditional expression, narrow based on controlling condition - if (child !== node.condition) { - narrowedType = narrowType(type, node.condition, child === node.whenTrue); - } - break; - case 170 /* BinaryExpression */: - // In the right operand of an && or ||, narrow based on left operand - if (child === node.right) { - if (node.operatorToken.kind === 48 /* AmpersandAmpersandToken */) { - narrowedType = narrowType(type, node.left, true); + if (node && symbol.flags & 3 /* Variable */) { + if (isTypeAny(type) || type.flags & (48128 /* ObjectType */ | 16384 /* Union */ | 512 /* TypeParameter */)) { + loop: while (node.parent) { + var child = node; + node = node.parent; + var narrowedType = type; + switch (node.kind) { + case 184 /* IfStatement */: + // In a branch of an if statement, narrow based on controlling expression + if (child !== node.expression) { + narrowedType = narrowType(type, node.expression, child === node.thenStatement); } - else if (node.operatorToken.kind === 49 /* BarBarToken */) { - narrowedType = narrowType(type, node.left, false); + break; + case 171 /* ConditionalExpression */: + // In a branch of a conditional expression, narrow based on controlling condition + if (child !== node.condition) { + narrowedType = narrowType(type, node.condition, child === node.whenTrue); } - } - break; - case 228 /* SourceFile */: - case 206 /* ModuleDeclaration */: - case 201 /* FunctionDeclaration */: - case 135 /* MethodDeclaration */: - case 134 /* MethodSignature */: - case 137 /* GetAccessor */: - case 138 /* SetAccessor */: - case 136 /* Constructor */: - // Stop at the first containing function or module declaration - break loop; - } - // Use narrowed type if construct contains no assignments to variable - if (narrowedType !== type) { - if (isVariableAssignedWithin(symbol, node)) { - break; + break; + case 170 /* BinaryExpression */: + // In the right operand of an && or ||, narrow based on left operand + if (child === node.right) { + if (node.operatorToken.kind === 48 /* AmpersandAmpersandToken */) { + narrowedType = narrowType(type, node.left, true); + } + else if (node.operatorToken.kind === 49 /* BarBarToken */) { + narrowedType = narrowType(type, node.left, false); + } + } + break; + case 228 /* SourceFile */: + case 206 /* ModuleDeclaration */: + case 201 /* FunctionDeclaration */: + case 135 /* MethodDeclaration */: + case 134 /* MethodSignature */: + case 137 /* GetAccessor */: + case 138 /* SetAccessor */: + case 136 /* Constructor */: + // Stop at the first containing function or module declaration + break loop; + } + // Use narrowed type if construct contains no assignments to variable + if (narrowedType !== type) { + if (isVariableAssignedWithin(symbol, node)) { + break; + } + type = narrowedType; } - type = narrowedType; } } } @@ -16830,7 +16862,7 @@ var ts; if (assumeTrue) { // Assumed result is true. If check was not for a primitive type, remove all primitive types if (!typeInfo) { - return removeTypesFromUnionType(type, 258 /* StringLike */ | 132 /* NumberLike */ | 8 /* Boolean */ | 1048576 /* ESSymbol */, + return removeTypesFromUnionType(type, 258 /* StringLike */ | 132 /* NumberLike */ | 8 /* Boolean */ | 2097152 /* ESSymbol */, /*isOfTypeKind*/ true, false); } // Check was for a primitive type, return that primitive type if it is a subtype @@ -16880,7 +16912,7 @@ var ts; } function narrowTypeByInstanceof(type, expr, assumeTrue) { // Check that type is not any, assumed result is true, and we have variable symbol on the left - if (type.flags & 1 /* Any */ || !assumeTrue || expr.left.kind !== 65 /* Identifier */ || getResolvedSymbol(expr.left) !== symbol) { + if (isTypeAny(type) || !assumeTrue || expr.left.kind !== 65 /* Identifier */ || getResolvedSymbol(expr.left) !== symbol) { return type; } // Check that right operand is a function type with a prototype property @@ -16893,7 +16925,7 @@ var ts; if (prototypeProperty) { // Target type is type of the protoype property var prototypePropertyType = getTypeOfSymbol(prototypeProperty); - if (prototypePropertyType !== anyType) { + if (!isTypeAny(prototypePropertyType)) { targetType = prototypePropertyType; } } @@ -17576,7 +17608,10 @@ var ts; function isNumericComputedName(name) { // It seems odd to consider an expression of type Any to result in a numeric name, // but this behavior is consistent with checkIndexedAccess - return allConstituentTypesHaveKind(checkComputedPropertyName(name), 1 /* Any */ | 132 /* NumberLike */); + return isTypeAnyOrAllConstituentTypesHaveKind(checkComputedPropertyName(name), 132 /* NumberLike */); + } + function isTypeAnyOrAllConstituentTypesHaveKind(type, kind) { + return isTypeAny(type) || allConstituentTypesHaveKind(type, kind); } function isNumericLiteralName(name) { // The intent of numeric names is that @@ -17608,7 +17643,7 @@ var ts; links.resolvedType = checkExpression(node.expression); // This will allow types number, string, symbol or any. It will also allow enums, the unknown // type, and any union of these types (like string | number). - if (!allConstituentTypesHaveKind(links.resolvedType, 1 /* Any */ | 132 /* NumberLike */ | 258 /* StringLike */ | 1048576 /* ESSymbol */)) { + if (!isTypeAnyOrAllConstituentTypesHaveKind(links.resolvedType, 132 /* NumberLike */ | 258 /* StringLike */ | 2097152 /* ESSymbol */)) { error(node, ts.Diagnostics.A_computed_property_name_must_be_of_type_string_number_symbol_or_any); } else { @@ -17669,7 +17704,7 @@ var ts; var stringIndexType = getIndexType(0 /* String */); var numberIndexType = getIndexType(1 /* Number */); var result = createAnonymousType(node.symbol, propertiesTable, emptyArray, emptyArray, stringIndexType, numberIndexType); - result.flags |= 131072 /* ObjectLiteral */ | 524288 /* ContainsObjectLiteral */ | (typeFlags & 262144 /* ContainsUndefinedOrNull */); + result.flags |= 262144 /* ObjectLiteral */ | 1048576 /* ContainsObjectLiteral */ | (typeFlags & 524288 /* ContainsUndefinedOrNull */); return result; function getIndexType(kind) { if (contextualType && contextualTypeHasIndexSignature(contextualType, kind)) { @@ -17747,47 +17782,45 @@ var ts; } function checkPropertyAccessExpressionOrQualifiedName(node, left, right) { var type = checkExpressionOrQualifiedName(left); - if (type === unknownType) + if (isTypeAny(type)) { return type; - if (type !== anyType) { - var apparentType = getApparentType(getWidenedType(type)); - if (apparentType === unknownType) { - // handle cases when type is Type parameter with invalid constraint - return unknownType; - } - var prop = getPropertyOfType(apparentType, right.text); - if (!prop) { - if (right.text) { - error(right, ts.Diagnostics.Property_0_does_not_exist_on_type_1, ts.declarationNameToString(right), typeToString(type)); - } - return unknownType; - } - getNodeLinks(node).resolvedSymbol = prop; - if (prop.parent && prop.parent.flags & 32 /* Class */) { - // TS 1.0 spec (April 2014): 4.8.2 - // - In a constructor, instance member function, instance member accessor, or - // instance member variable initializer where this references a derived class instance, - // a super property access is permitted and must specify a public instance member function of the base class. - // - In a static member function or static member accessor - // where this references the constructor function object of a derived class, - // a super property access is permitted and must specify a public static member function of the base class. - if (left.kind === 91 /* SuperKeyword */ && getDeclarationKindFromSymbol(prop) !== 135 /* MethodDeclaration */) { - error(right, ts.Diagnostics.Only_public_and_protected_methods_of_the_base_class_are_accessible_via_the_super_keyword); - } - else { - checkClassPropertyAccess(node, left, type, prop); - } - } - return getTypeOfSymbol(prop); } - return anyType; + var apparentType = getApparentType(getWidenedType(type)); + if (apparentType === unknownType) { + // handle cases when type is Type parameter with invalid constraint + return unknownType; + } + var prop = getPropertyOfType(apparentType, right.text); + if (!prop) { + if (right.text) { + error(right, ts.Diagnostics.Property_0_does_not_exist_on_type_1, ts.declarationNameToString(right), typeToString(type)); + } + return unknownType; + } + getNodeLinks(node).resolvedSymbol = prop; + if (prop.parent && prop.parent.flags & 32 /* Class */) { + // TS 1.0 spec (April 2014): 4.8.2 + // - In a constructor, instance member function, instance member accessor, or + // instance member variable initializer where this references a derived class instance, + // a super property access is permitted and must specify a public instance member function of the base class. + // - In a static member function or static member accessor + // where this references the constructor function object of a derived class, + // a super property access is permitted and must specify a public static member function of the base class. + if (left.kind === 91 /* SuperKeyword */ && getDeclarationKindFromSymbol(prop) !== 135 /* MethodDeclaration */) { + error(right, ts.Diagnostics.Only_public_and_protected_methods_of_the_base_class_are_accessible_via_the_super_keyword); + } + else { + checkClassPropertyAccess(node, left, type, prop); + } + } + return getTypeOfSymbol(prop); } function isValidPropertyAccess(node, propertyName) { var left = node.kind === 156 /* PropertyAccessExpression */ ? node.expression : node.left; var type = checkExpressionOrQualifiedName(left); - if (type !== unknownType && type !== anyType) { + if (type !== unknownType && !isTypeAny(type)) { var prop = getPropertyOfType(getWidenedType(type), propertyName); if (prop && prop.parent && prop.parent.flags & 32 /* Class */) { if (left.kind === 91 /* SuperKeyword */ && getDeclarationKindFromSymbol(prop) !== 135 /* MethodDeclaration */) { @@ -17839,23 +17872,23 @@ var ts; // - Otherwise, if IndexExpr is of type Any, the String or Number primitive type, or an enum type, the property access is of type Any. // See if we can index as a property. if (node.argumentExpression) { - var name_9 = getPropertyNameForIndexedAccess(node.argumentExpression, indexType); - if (name_9 !== undefined) { - var prop = getPropertyOfType(objectType, name_9); + var name_10 = getPropertyNameForIndexedAccess(node.argumentExpression, indexType); + if (name_10 !== undefined) { + var prop = getPropertyOfType(objectType, name_10); if (prop) { getNodeLinks(node).resolvedSymbol = prop; return getTypeOfSymbol(prop); } else if (isConstEnum) { - error(node.argumentExpression, ts.Diagnostics.Property_0_does_not_exist_on_const_enum_1, name_9, symbolToString(objectType.symbol)); + error(node.argumentExpression, ts.Diagnostics.Property_0_does_not_exist_on_const_enum_1, name_10, symbolToString(objectType.symbol)); return unknownType; } } } // Check for compatible indexer types. - if (allConstituentTypesHaveKind(indexType, 1 /* Any */ | 258 /* StringLike */ | 132 /* NumberLike */ | 1048576 /* ESSymbol */)) { + if (isTypeAnyOrAllConstituentTypesHaveKind(indexType, 258 /* StringLike */ | 132 /* NumberLike */ | 2097152 /* ESSymbol */)) { // Try to use a number indexer. - if (allConstituentTypesHaveKind(indexType, 1 /* Any */ | 132 /* NumberLike */)) { + if (isTypeAnyOrAllConstituentTypesHaveKind(indexType, 132 /* NumberLike */)) { var numberIndexType = getIndexTypeOfType(objectType, 1 /* Number */); if (numberIndexType) { return numberIndexType; @@ -17867,7 +17900,7 @@ var ts; return stringIndexType; } // Fall back to any. - if (compilerOptions.noImplicitAny && !compilerOptions.suppressImplicitAnyIndexErrors && objectType !== anyType) { + if (compilerOptions.noImplicitAny && !compilerOptions.suppressImplicitAnyIndexErrors && !isTypeAny(objectType)) { error(node, ts.Diagnostics.Index_signature_of_object_type_implicitly_has_an_any_type); } return anyType; @@ -17908,7 +17941,7 @@ var ts; return false; } // Make sure the property type is the primitive symbol type - if ((expressionType.flags & 1048576 /* ESSymbol */) === 0) { + if ((expressionType.flags & 2097152 /* ESSymbol */) === 0) { if (reportError) { error(expression, ts.Diagnostics.A_computed_property_name_of_the_form_0_must_be_of_type_symbol, ts.getTextOfNode(expression)); } @@ -18446,8 +18479,10 @@ var ts; // types are provided for the argument expressions, and the result is always of type Any. // We exclude union types because we may have a union of function types that happen to have // no common signatures. - if (funcType === anyType || (!callSignatures.length && !constructSignatures.length && !(funcType.flags & 16384 /* Union */) && isTypeAssignableTo(funcType, globalFunctionType))) { - if (node.typeArguments) { + if (isTypeAny(funcType) || (!callSignatures.length && !constructSignatures.length && !(funcType.flags & 16384 /* Union */) && isTypeAssignableTo(funcType, globalFunctionType))) { + // The unknownType indicates that an error already occured (and was reported). No + // need to report another error in this case. + if (funcType !== unknownType && node.typeArguments) { error(node, ts.Diagnostics.Untyped_function_calls_may_not_accept_type_arguments); } return resolveUntypedCall(node); @@ -18474,15 +18509,6 @@ var ts; } } var expressionType = checkExpression(node.expression); - // TS 1.0 spec: 4.11 - // If ConstructExpr is of type Any, Args can be any argument - // list and the result of the operation is of type Any. - if (expressionType === anyType) { - if (node.typeArguments) { - error(node, ts.Diagnostics.Untyped_function_calls_may_not_accept_type_arguments); - } - return resolveUntypedCall(node); - } // If ConstructExpr's apparent type(section 3.8.1) is an object type with one or // more construct signatures, the expression is processed in the same manner as a // function call, but using the construct signatures as the initial set of candidate @@ -18493,6 +18519,15 @@ var ts; // Another error has already been reported return resolveErrorCall(node); } + // TS 1.0 spec: 4.11 + // If ConstructExpr is of type Any, Args can be any argument + // list and the result of the operation is of type Any. + if (isTypeAny(expressionType)) { + if (node.typeArguments) { + error(node, ts.Diagnostics.Untyped_function_calls_may_not_accept_type_arguments); + } + return resolveUntypedCall(node); + } // Technically, this signatures list may be incomplete. We are taking the apparent type, // but we are not including construct signatures that may have been added to the Object or // Function interface, since they have none by default. This is a bit of a leap of faith @@ -18524,7 +18559,7 @@ var ts; return resolveErrorCall(node); } var callSignatures = getSignaturesOfType(apparentType, 0 /* Call */); - if (tagType === anyType || (!callSignatures.length && !(tagType.flags & 16384 /* Union */) && isTypeAssignableTo(tagType, globalFunctionType))) { + if (isTypeAny(tagType) || (!callSignatures.length && !(tagType.flags & 16384 /* Union */) && isTypeAssignableTo(tagType, globalFunctionType))) { return resolveUntypedCall(node); } if (!callSignatures.length) { @@ -18709,7 +18744,7 @@ var ts; return; } // Functions that return 'void' or 'any' don't need any return expressions. - if (returnType === voidType || returnType === anyType) { + if (returnType === voidType || isTypeAny(returnType)) { return; } // If all we have is a function signature, or an arrow function with an expression body, then there is nothing to check. @@ -18778,6 +18813,14 @@ var ts; checkIfNonVoidFunctionHasReturnExpressionsOrSingleThrowStatment(node, getTypeFromTypeNode(node.type)); } if (node.body) { + if (!node.type) { + // There are some checks that are only performed in getReturnTypeFromBody, that may produce errors + // we need. An example is the noImplicitAny errors resulting from widening the return expression + // of a function. Because checking of function expression bodies is deferred, there was never an + // appropriate time to do this during the main walk of the file (see the comment at the top of + // checkFunctionExpressionBodies). So it must be done now. + getReturnTypeOfSignature(getSignatureFromDeclaration(node)); + } if (node.body.kind === 180 /* Block */) { checkSourceElement(node.body); } @@ -18791,7 +18834,7 @@ var ts; } } function checkArithmeticOperandType(operand, type, diagnostic) { - if (!allConstituentTypesHaveKind(type, 1 /* Any */ | 132 /* NumberLike */)) { + if (!isTypeAnyOrAllConstituentTypesHaveKind(type, 132 /* NumberLike */)) { error(operand, diagnostic); return false; } @@ -18847,8 +18890,8 @@ var ts; var index = n.argumentExpression; var symbol = findSymbol(n.expression); if (symbol && index && index.kind === 8 /* StringLiteral */) { - var name_10 = index.text; - var prop = getPropertyOfType(getTypeOfSymbol(symbol), name_10); + var name_11 = index.text; + var prop = getPropertyOfType(getTypeOfSymbol(symbol), name_11); return prop && (prop.flags & 3 /* Variable */) !== 0 && (getDeclarationFlagsFromSymbol(prop) & 8192 /* Const */) !== 0; } return false; @@ -18900,7 +18943,7 @@ var ts; case 33 /* PlusToken */: case 34 /* MinusToken */: case 47 /* TildeToken */: - if (someConstituentTypeHasKind(operandType, 1048576 /* ESSymbol */)) { + if (someConstituentTypeHasKind(operandType, 2097152 /* ESSymbol */)) { error(node.operand, ts.Diagnostics.The_0_operator_cannot_be_applied_to_type_symbol, ts.tokenToString(node.operator)); } return numberType; @@ -18978,11 +19021,11 @@ var ts; // and the right operand to be of type Any or a subtype of the 'Function' interface type. // The result is always of the Boolean primitive type. // NOTE: do not raise error if leftType is unknown as related error was already reported - if (allConstituentTypesHaveKind(leftType, 1049086 /* Primitive */)) { + if (allConstituentTypesHaveKind(leftType, 2097662 /* Primitive */)) { error(node.left, ts.Diagnostics.The_left_hand_side_of_an_instanceof_expression_must_be_of_type_any_an_object_type_or_a_type_parameter); } // NOTE: do not raise error if right is unknown as related error was already reported - if (!(rightType.flags & 1 /* Any */ || isTypeSubtypeOf(rightType, globalFunctionType))) { + if (!(isTypeAny(rightType) || isTypeSubtypeOf(rightType, globalFunctionType))) { error(node.right, ts.Diagnostics.The_right_hand_side_of_an_instanceof_expression_must_be_of_type_any_or_of_a_type_assignable_to_the_Function_interface_type); } return booleanType; @@ -18992,10 +19035,10 @@ var ts; // The in operator requires the left operand to be of type Any, the String primitive type, or the Number primitive type, // and the right operand to be of type Any, an object type, or a type parameter type. // The result is always of the Boolean primitive type. - if (!allConstituentTypesHaveKind(leftType, 1 /* Any */ | 258 /* StringLike */ | 132 /* NumberLike */ | 1048576 /* ESSymbol */)) { + if (!isTypeAnyOrAllConstituentTypesHaveKind(leftType, 258 /* StringLike */ | 132 /* NumberLike */ | 2097152 /* ESSymbol */)) { error(node.left, ts.Diagnostics.The_left_hand_side_of_an_in_expression_must_be_of_type_any_string_number_or_symbol); } - if (!allConstituentTypesHaveKind(rightType, 1 /* Any */ | 48128 /* ObjectType */ | 512 /* TypeParameter */)) { + if (!isTypeAnyOrAllConstituentTypesHaveKind(rightType, 48128 /* ObjectType */ | 512 /* TypeParameter */)) { error(node.right, ts.Diagnostics.The_right_hand_side_of_an_in_expression_must_be_of_type_any_an_object_type_or_a_type_parameter); } return booleanType; @@ -19006,16 +19049,17 @@ var ts; var p = properties[_i]; if (p.kind === 225 /* PropertyAssignment */ || p.kind === 226 /* ShorthandPropertyAssignment */) { // TODO(andersh): Computed property support - var name_11 = p.name; - var type = sourceType.flags & 1 /* Any */ ? sourceType : - getTypeOfPropertyOfType(sourceType, name_11.text) || - isNumericLiteralName(name_11.text) && getIndexTypeOfType(sourceType, 1 /* Number */) || + var name_12 = p.name; + var type = isTypeAny(sourceType) + ? sourceType + : getTypeOfPropertyOfType(sourceType, name_12.text) || + isNumericLiteralName(name_12.text) && getIndexTypeOfType(sourceType, 1 /* Number */) || getIndexTypeOfType(sourceType, 0 /* String */); if (type) { - checkDestructuringAssignment(p.initializer || name_11, type); + checkDestructuringAssignment(p.initializer || name_12, type); } else { - error(name_11, ts.Diagnostics.Type_0_has_no_property_1_and_no_string_index_signature, typeToString(sourceType), ts.declarationNameToString(name_11)); + error(name_12, ts.Diagnostics.Type_0_has_no_property_1_and_no_string_index_signature, typeToString(sourceType), ts.declarationNameToString(name_12)); } } else { @@ -19035,8 +19079,9 @@ var ts; if (e.kind !== 176 /* OmittedExpression */) { if (e.kind !== 174 /* SpreadElementExpression */) { var propName = "" + i; - var type = sourceType.flags & 1 /* Any */ ? sourceType : - isTupleLikeType(sourceType) + var type = isTypeAny(sourceType) + ? sourceType + : isTupleLikeType(sourceType) ? getTypeOfPropertyOfType(sourceType, propName) : elementType; if (type) { @@ -19171,10 +19216,10 @@ var ts; // If one or both operands are of the String primitive type, the result is of the String primitive type. resultType = stringType; } - else if (leftType.flags & 1 /* Any */ || rightType.flags & 1 /* Any */) { + else if (isTypeAny(leftType) || isTypeAny(rightType)) { // Otherwise, the result is of type Any. // NOTE: unknown type here denotes error type. Old compiler treated this case as any type so do we. - resultType = anyType; + resultType = leftType === unknownType || rightType === unknownType ? unknownType : anyType; } // Symbols are not allowed at all in arithmetic expressions if (resultType && !checkForDisallowedESSymbolOperand(operator)) { @@ -19221,8 +19266,8 @@ var ts; } // Return true if there was no error, false if there was an error. function checkForDisallowedESSymbolOperand(operator) { - var offendingSymbolOperand = someConstituentTypeHasKind(leftType, 1048576 /* ESSymbol */) ? node.left : - someConstituentTypeHasKind(rightType, 1048576 /* ESSymbol */) ? node.right : + var offendingSymbolOperand = someConstituentTypeHasKind(leftType, 2097152 /* ESSymbol */) ? node.left : + someConstituentTypeHasKind(rightType, 2097152 /* ESSymbol */) ? node.right : undefined; if (offendingSymbolOperand) { error(offendingSymbolOperand, ts.Diagnostics.The_0_operator_cannot_be_applied_to_type_symbol, ts.tokenToString(operator)); @@ -20138,7 +20183,7 @@ var ts; if (node && node.kind === 142 /* TypeReference */) { var type = getTypeFromTypeNode(node); var shouldCheckIfUnknownType = type === unknownType && compilerOptions.isolatedModules; - if (!type || (!shouldCheckIfUnknownType && type.flags & (1048703 /* Intrinsic */ | 132 /* NumberLike */ | 258 /* StringLike */))) { + if (!type || (!shouldCheckIfUnknownType && type.flags & (2097279 /* Intrinsic */ | 132 /* NumberLike */ | 258 /* StringLike */))) { return; } if (shouldCheckIfUnknownType || type.symbol.valueDeclaration) { @@ -20433,8 +20478,8 @@ var ts; // otherwise if variable has an initializer - show error that initialization will fail // since LHS will be block scoped name instead of function scoped if (!namesShareScope) { - var name_12 = symbolToString(localDeclarationSymbol); - error(node, ts.Diagnostics.Cannot_initialize_outer_scoped_variable_0_in_the_same_scope_as_block_scoped_declaration_1, name_12, name_12); + var name_13 = symbolToString(localDeclarationSymbol); + error(node, ts.Diagnostics.Cannot_initialize_outer_scoped_variable_0_in_the_same_scope_as_block_scoped_declaration_1, name_13, name_13); } } } @@ -20667,7 +20712,7 @@ var ts; if (varExpr.kind === 154 /* ArrayLiteralExpression */ || varExpr.kind === 155 /* ObjectLiteralExpression */) { error(varExpr, ts.Diagnostics.The_left_hand_side_of_a_for_in_statement_cannot_be_a_destructuring_pattern); } - else if (!allConstituentTypesHaveKind(leftType, 1 /* Any */ | 258 /* StringLike */)) { + else if (!isTypeAnyOrAllConstituentTypesHaveKind(leftType, 258 /* StringLike */)) { error(varExpr, ts.Diagnostics.The_left_hand_side_of_a_for_in_statement_must_be_of_type_string_or_any); } else { @@ -20678,7 +20723,7 @@ var ts; var rightType = checkExpression(node.expression); // unknownType is returned i.e. if node.expression is identifier whose name cannot be resolved // in this case error about missing name is already reported - do not report extra one - if (!allConstituentTypesHaveKind(rightType, 1 /* Any */ | 48128 /* ObjectType */ | 512 /* TypeParameter */)) { + if (!isTypeAnyOrAllConstituentTypesHaveKind(rightType, 48128 /* ObjectType */ | 512 /* TypeParameter */)) { error(node.expression, ts.Diagnostics.The_right_hand_side_of_a_for_in_statement_must_be_of_type_any_an_object_type_or_a_type_parameter); } checkSourceElement(node.statement); @@ -20696,7 +20741,7 @@ var ts; return checkIteratedTypeOrElementType(expressionType, rhsExpression, true); } function checkIteratedTypeOrElementType(inputType, errorNode, allowStringInput) { - if (inputType.flags & 1 /* Any */) { + if (isTypeAny(inputType)) { return inputType; } if (languageVersion >= 2 /* ES6 */) { @@ -20748,7 +20793,7 @@ var ts; * whole pattern and that T (above) is 'any'. */ function getElementTypeOfIterable(type, errorNode) { - if (type.flags & 1 /* Any */) { + if (isTypeAny(type)) { return undefined; } var typeAsIterable = type; @@ -20760,7 +20805,7 @@ var ts; } else { var iteratorFunction = getTypeOfPropertyOfType(type, ts.getPropertyNameForKnownSymbolName("iterator")); - if (iteratorFunction && iteratorFunction.flags & 1 /* Any */) { + if (isTypeAny(iteratorFunction)) { return undefined; } var iteratorFunctionSignatures = iteratorFunction ? getSignaturesOfType(iteratorFunction, 0 /* Call */) : emptyArray; @@ -20789,7 +20834,7 @@ var ts; * */ function getElementTypeOfIterator(type, errorNode) { - if (type.flags & 1 /* Any */) { + if (isTypeAny(type)) { return undefined; } var typeAsIterator = type; @@ -20801,7 +20846,7 @@ var ts; } else { var iteratorNextFunction = getTypeOfPropertyOfType(type, "next"); - if (iteratorNextFunction && iteratorNextFunction.flags & 1 /* Any */) { + if (isTypeAny(iteratorNextFunction)) { return undefined; } var iteratorNextFunctionSignatures = iteratorNextFunction ? getSignaturesOfType(iteratorNextFunction, 0 /* Call */) : emptyArray; @@ -20812,7 +20857,7 @@ var ts; return undefined; } var iteratorNextResult = getUnionType(ts.map(iteratorNextFunctionSignatures, getReturnTypeOfSignature)); - if (iteratorNextResult.flags & 1 /* Any */) { + if (isTypeAny(iteratorNextResult)) { return undefined; } var iteratorNextValue = getTypeOfPropertyOfType(iteratorNextResult, "value"); @@ -20828,7 +20873,7 @@ var ts; return typeAsIterator.iteratorElementType; } function getElementTypeOfIterableIterator(type) { - if (type.flags & 1 /* Any */) { + if (isTypeAny(type)) { return undefined; } // As an optimization, if the type is instantiated directly using the globalIterableIteratorType (IterableIterator), @@ -22457,9 +22502,9 @@ var ts; function getRootSymbols(symbol) { if (symbol.flags & 268435456 /* UnionProperty */) { var symbols = []; - var name_13 = symbol.name; + var name_14 = symbol.name; ts.forEach(getSymbolLinks(symbol).unionType.types, function (t) { - symbols.push(getPropertyOfType(t, name_13)); + symbols.push(getPropertyOfType(t, name_14)); }); return symbols; } @@ -22677,7 +22722,7 @@ var ts; else if (type.flags & 8192 /* Tuple */) { return "Array"; } - else if (type.flags & 1048576 /* ESSymbol */) { + else if (type.flags & 2097152 /* ESSymbol */) { return "Symbol"; } else if (type === unknownType) { @@ -22969,20 +23014,20 @@ var ts; if (impotClause.namedBindings) { var nameBindings = impotClause.namedBindings; if (nameBindings.kind === 212 /* NamespaceImport */) { - var name_14 = nameBindings.name; - if (isReservedWordInStrictMode(name_14)) { - var nameText = ts.declarationNameToString(name_14); - return grammarErrorOnNode(name_14, ts.Diagnostics.Identifier_expected_0_is_a_reserved_word_in_strict_mode, nameText); + var name_15 = nameBindings.name; + if (isReservedWordInStrictMode(name_15)) { + var nameText = ts.declarationNameToString(name_15); + return grammarErrorOnNode(name_15, ts.Diagnostics.Identifier_expected_0_is_a_reserved_word_in_strict_mode, nameText); } } else if (nameBindings.kind === 213 /* NamedImports */) { var reportError = false; for (var _i = 0, _a = nameBindings.elements; _i < _a.length; _i++) { var element = _a[_i]; - var name_15 = element.name; - if (isReservedWordInStrictMode(name_15)) { - var nameText = ts.declarationNameToString(name_15); - reportError = reportError || grammarErrorOnNode(name_15, ts.Diagnostics.Identifier_expected_0_is_a_reserved_word_in_strict_mode, nameText); + var name_16 = element.name; + if (isReservedWordInStrictMode(name_16)) { + var nameText = ts.declarationNameToString(name_16); + reportError = reportError || grammarErrorOnNode(name_16, ts.Diagnostics.Identifier_expected_0_is_a_reserved_word_in_strict_mode, nameText); } } return reportError; @@ -23475,11 +23520,11 @@ var ts; var inStrictMode = (node.parserContextFlags & 1 /* StrictMode */) !== 0; for (var _i = 0, _a = node.properties; _i < _a.length; _i++) { var prop = _a[_i]; - var name_16 = prop.name; + var name_17 = prop.name; if (prop.kind === 176 /* OmittedExpression */ || - name_16.kind === 128 /* ComputedPropertyName */) { + name_17.kind === 128 /* ComputedPropertyName */) { // If the name is not a ComputedPropertyName, the grammar checking will skip it - checkGrammarComputedPropertyName(name_16); + checkGrammarComputedPropertyName(name_17); continue; } // ECMA-262 11.1.5 Object Initialiser @@ -23494,8 +23539,8 @@ var ts; if (prop.kind === 225 /* PropertyAssignment */ || prop.kind === 226 /* ShorthandPropertyAssignment */) { // Grammar checking for computedPropertName and shorthandPropertyAssignment checkGrammarForInvalidQuestionMark(prop, prop.questionToken, ts.Diagnostics.An_object_member_cannot_be_declared_optional); - if (name_16.kind === 7 /* NumericLiteral */) { - checkGrammarNumericLiteral(name_16); + if (name_17.kind === 7 /* NumericLiteral */) { + checkGrammarNumericLiteral(name_17); } currentKind = Property; } @@ -23511,26 +23556,26 @@ var ts; else { ts.Debug.fail("Unexpected syntax kind:" + prop.kind); } - if (!ts.hasProperty(seen, name_16.text)) { - seen[name_16.text] = currentKind; + if (!ts.hasProperty(seen, name_17.text)) { + seen[name_17.text] = currentKind; } else { - var existingKind = seen[name_16.text]; + var existingKind = seen[name_17.text]; if (currentKind === Property && existingKind === Property) { if (inStrictMode) { - grammarErrorOnNode(name_16, ts.Diagnostics.An_object_literal_cannot_have_multiple_properties_with_the_same_name_in_strict_mode); + grammarErrorOnNode(name_17, ts.Diagnostics.An_object_literal_cannot_have_multiple_properties_with_the_same_name_in_strict_mode); } } else if ((currentKind & GetOrSetAccessor) && (existingKind & GetOrSetAccessor)) { if (existingKind !== GetOrSetAccessor && currentKind !== existingKind) { - seen[name_16.text] = currentKind | existingKind; + seen[name_17.text] = currentKind | existingKind; } else { - return grammarErrorOnNode(name_16, ts.Diagnostics.An_object_literal_cannot_have_multiple_get_Slashset_accessors_with_the_same_name); + return grammarErrorOnNode(name_17, ts.Diagnostics.An_object_literal_cannot_have_multiple_get_Slashset_accessors_with_the_same_name); } } else { - return grammarErrorOnNode(name_16, ts.Diagnostics.An_object_literal_cannot_have_property_and_accessor_with_the_same_name); + return grammarErrorOnNode(name_17, ts.Diagnostics.An_object_literal_cannot_have_property_and_accessor_with_the_same_name); } } } @@ -24391,9 +24436,9 @@ var ts; } var count = 0; while (true) { - var name_17 = baseName + "_" + (++count); - if (!ts.hasProperty(currentSourceFile.identifiers, name_17)) { - return name_17; + var name_18 = baseName + "_" + (++count); + if (!ts.hasProperty(currentSourceFile.identifiers, name_18)) { + return name_18; } } } @@ -25602,9 +25647,9 @@ var ts; tempFlags++; // Skip over 'i' and 'n' if (count !== 8 && count !== 13) { - var name_18 = count < 26 ? "_" + String.fromCharCode(97 /* a */ + count) : "_" + (count - 26); - if (isUniqueName(name_18)) { - return name_18; + var name_19 = count < 26 ? "_" + String.fromCharCode(97 /* a */ + count) : "_" + (count - 26); + if (isUniqueName(name_19)) { + return name_19; } } } @@ -25637,9 +25682,9 @@ var ts; } function generateNameForModuleOrEnum(node) { if (node.name.kind === 65 /* Identifier */) { - var name_19 = node.name.text; + var name_20 = node.name.text; // Use module/enum name itself if it is unique, otherwise make a unique variation - assignGeneratedName(node, isUniqueLocalName(name_19, node) ? name_19 : makeUniqueName(name_19)); + assignGeneratedName(node, isUniqueLocalName(name_20, node) ? name_20 : makeUniqueName(name_20)); } } function generateNameForImportOrExportDeclaration(node) { @@ -25858,8 +25903,8 @@ var ts; // Child scopes are always shown with a dot (even if they have no name), // unless it is a computed property. Then it is shown with brackets, // but the brackets are included in the name. - var name_20 = node.name; - if (!name_20 || name_20.kind !== 128 /* ComputedPropertyName */) { + var name_21 = node.name; + if (!name_21 || name_21.kind !== 128 /* ComputedPropertyName */) { scopeName = "." + scopeName; } scopeName = sourceMapData.sourceMapNames[parentIndex] + scopeName; @@ -25888,10 +25933,10 @@ var ts; node.kind === 205 /* EnumDeclaration */) { // Declaration and has associated name use it if (node.name) { - var name_21 = node.name; + var name_22 = node.name; // For computed property names, the text will include the brackets - scopeName = name_21.kind === 128 /* ComputedPropertyName */ - ? ts.getTextOfNode(name_21) + scopeName = name_22.kind === 128 /* ComputedPropertyName */ + ? ts.getTextOfNode(name_22) : node.name.text; } recordScopeNameStart(scopeName); @@ -26836,6 +26881,11 @@ var ts; return result; } function parenthesizeForAccess(expr) { + // When diagnosing whether the expression needs parentheses, the decision should be based + // on the innermost expression in a chain of nested type assertions. + while (expr.kind === 161 /* TypeAssertionExpression */) { + expr = expr.expression; + } // isLeftHandSideExpression is almost the correct criterion for when it is not necessary // to parenthesize the expression before a dot. The known exceptions are: // @@ -26844,7 +26894,9 @@ var ts; // NumberLiteral // 1.x -> not the same as (1).x // - if (ts.isLeftHandSideExpression(expr) && expr.kind !== 159 /* NewExpression */ && expr.kind !== 7 /* NumericLiteral */) { + if (ts.isLeftHandSideExpression(expr) && + expr.kind !== 159 /* NewExpression */ && + expr.kind !== 7 /* NumericLiteral */) { return expr; } var node = ts.createSynthesizedNode(162 /* ParenthesizedExpression */); @@ -27106,7 +27158,10 @@ var ts; } } function emitParenExpression(node) { - if (!node.parent || node.parent.kind !== 164 /* ArrowFunction */) { + // If the node is synthesized, it means the emitter put the parentheses there, + // not the user. If we didn't want them, the emitter would not have put them + // there. + if (!ts.nodeIsSynthesized(node) && node.parent.kind !== 164 /* ArrowFunction */) { if (node.expression.kind === 161 /* TypeAssertionExpression */) { var operand = node.expression.expression; // Make sure we consider all nested cast expressions, e.g.: @@ -28181,12 +28236,12 @@ var ts; function emitParameter(node) { if (languageVersion < 2 /* ES6 */) { if (ts.isBindingPattern(node.name)) { - var name_22 = createTempVariable(0 /* Auto */); + var name_23 = createTempVariable(0 /* Auto */); if (!tempParameters) { tempParameters = []; } - tempParameters.push(name_22); - emit(name_22); + tempParameters.push(name_23); + emit(name_23); } else { emit(node.name); @@ -29854,8 +29909,8 @@ var ts; // export { x, y } for (var _c = 0, _d = node.exportClause.elements; _c < _d.length; _c++) { var specifier = _d[_c]; - var name_23 = (specifier.propertyName || specifier.name).text; - (exportSpecifiers[name_23] || (exportSpecifiers[name_23] = [])).push(specifier); + var name_24 = (specifier.propertyName || specifier.name).text; + (exportSpecifiers[name_24] || (exportSpecifiers[name_24] = [])).push(specifier); } } break; @@ -30055,12 +30110,12 @@ var ts; var seen = {}; for (var i = 0; i < hoistedVars.length; ++i) { var local = hoistedVars[i]; - var name_24 = local.kind === 65 /* Identifier */ + var name_25 = local.kind === 65 /* Identifier */ ? local : local.name; - if (name_24) { + if (name_25) { // do not emit duplicate entries (in case of declaration merging) in the list of hoisted variables - var text = ts.unescapeIdentifier(name_24.text); + var text = ts.unescapeIdentifier(name_25.text); if (ts.hasProperty(seen, text)) { continue; } @@ -30139,15 +30194,15 @@ var ts; } if (node.kind === 199 /* VariableDeclaration */ || node.kind === 153 /* BindingElement */) { if (shouldHoistVariable(node, false)) { - var name_25 = node.name; - if (name_25.kind === 65 /* Identifier */) { + var name_26 = node.name; + if (name_26.kind === 65 /* Identifier */) { if (!hoistedVars) { hoistedVars = []; } - hoistedVars.push(name_25); + hoistedVars.push(name_26); } else { - ts.forEachChild(name_25, visit); + ts.forEachChild(name_26, visit); } } return; @@ -30945,8 +31000,6 @@ var ts; /* @internal */ ts.ioWriteTime = 0; /** The version of the TypeScript compiler release */ ts.version = "1.5.3"; - var carriageReturnLineFeed = "\r\n"; - var lineFeed = "\n"; function findConfigFile(searchPath) { var fileName = "tsconfig.json"; while (true) { @@ -31020,9 +31073,7 @@ var ts; } } } - var newLine = options.newLine === 0 /* CarriageReturnLineFeed */ ? carriageReturnLineFeed : - options.newLine === 1 /* LineFeed */ ? lineFeed : - ts.sys.newLine; + var newLine = ts.getNewLineCharacter(options); return { getSourceFile: getSourceFile, getDefaultLibFileName: function (options) { return ts.combinePaths(ts.getDirectoryPath(ts.normalizePath(ts.sys.getExecutingFilePath())), ts.getDefaultLibFileName(options)); }, @@ -31090,6 +31141,7 @@ var ts; getGlobalDiagnostics: getGlobalDiagnostics, getSemanticDiagnostics: getSemanticDiagnostics, getDeclarationDiagnostics: getDeclarationDiagnostics, + getCompilerOptionsDiagnostics: getCompilerOptionsDiagnostics, getTypeChecker: getTypeChecker, getDiagnosticsProducingTypeChecker: getDiagnosticsProducingTypeChecker, getCommonSourceDirectory: function () { return commonSourceDirectory; }, @@ -31181,6 +31233,11 @@ var ts; return ts.getDeclarationDiagnostics(getEmitHost(writeFile), resolver, sourceFile); } } + function getCompilerOptionsDiagnostics() { + var allDiagnostics = []; + ts.addRange(allDiagnostics, diagnostics.getGlobalDiagnostics()); + return ts.sortAndDeduplicateDiagnostics(allDiagnostics); + } function getGlobalDiagnostics() { var typeChecker = getDiagnosticsProducingTypeChecker(); var allDiagnostics = []; @@ -31838,7 +31895,7 @@ var ts; var errors = []; return { options: getCompilerOptions(), - fileNames: getFiles(), + fileNames: getFileNames(), errors: errors }; function getCompilerOptions() { @@ -31882,23 +31939,24 @@ var ts; } return options; } - function getFiles() { - var files = []; + function getFileNames() { + var fileNames = []; if (ts.hasProperty(json, "files")) { if (json["files"] instanceof Array) { - var files = ts.map(json["files"], function (s) { return ts.combinePaths(basePath, s); }); + fileNames = ts.map(json["files"], function (s) { return ts.combinePaths(basePath, s); }); } } else { - var sysFiles = host.readDirectory(basePath, ".ts"); + var exclude = json["exclude"] instanceof Array ? ts.map(json["exclude"], ts.normalizeSlashes) : undefined; + var sysFiles = host.readDirectory(basePath, ".ts", exclude); for (var i = 0; i < sysFiles.length; i++) { var name = sysFiles[i]; if (!ts.fileExtensionIs(name, ".d.ts") || !ts.contains(sysFiles, name.substr(0, name.length - 5) + ".ts")) { - files.push(name); + fileNames.push(name); } } } - return files; + return fileNames; } } ts.parseConfigFile = parseConfigFile; @@ -32077,12 +32135,12 @@ var ts; ts.forEach(program.getSourceFiles(), function (sourceFile) { cancellationToken.throwIfCancellationRequested(); var nameToDeclarations = sourceFile.getNamedDeclarations(); - for (var name_26 in nameToDeclarations) { - var declarations = ts.getProperty(nameToDeclarations, name_26); + for (var name_27 in nameToDeclarations) { + var declarations = ts.getProperty(nameToDeclarations, name_27); if (declarations) { // First do a quick check to see if the name of the declaration matches the // last portion of the (possibly) dotted name they're searching for. - var matches = patternMatcher.getMatchesForLastSegmentOfPattern(name_26); + var matches = patternMatcher.getMatchesForLastSegmentOfPattern(name_27); if (!matches) { continue; } @@ -32095,14 +32153,14 @@ var ts; if (!containers) { return undefined; } - matches = patternMatcher.getMatches(containers, name_26); + matches = patternMatcher.getMatches(containers, name_27); if (!matches) { continue; } } var fileName = sourceFile.fileName; var matchKind = bestMatchKind(matches); - rawItems.push({ name: name_26, fileName: fileName, matchKind: matchKind, isCaseSensitive: allMatchesAreCaseSensitive(matches), declaration: declaration }); + rawItems.push({ name: name_27, fileName: fileName, matchKind: matchKind, isCaseSensitive: allMatchesAreCaseSensitive(matches), declaration: declaration }); } } } @@ -32485,9 +32543,9 @@ var ts; case 199 /* VariableDeclaration */: case 153 /* BindingElement */: var variableDeclarationNode; - var name_27; + var name_28; if (node.kind === 153 /* BindingElement */) { - name_27 = node.name; + name_28 = node.name; variableDeclarationNode = node; // binding elements are added only for variable declarations // bubble up to the containing variable declaration @@ -32499,16 +32557,16 @@ var ts; else { ts.Debug.assert(!ts.isBindingPattern(node.name)); variableDeclarationNode = node; - name_27 = node.name; + name_28 = node.name; } if (ts.isConst(variableDeclarationNode)) { - return createItem(node, getTextOfNode(name_27), ts.ScriptElementKind.constElement); + return createItem(node, getTextOfNode(name_28), ts.ScriptElementKind.constElement); } else if (ts.isLet(variableDeclarationNode)) { - return createItem(node, getTextOfNode(name_27), ts.ScriptElementKind.letElement); + return createItem(node, getTextOfNode(name_28), ts.ScriptElementKind.letElement); } else { - return createItem(node, getTextOfNode(name_27), ts.ScriptElementKind.variableElement); + return createItem(node, getTextOfNode(name_28), ts.ScriptElementKind.variableElement); } case 136 /* Constructor */: return createItem(node, "constructor", ts.ScriptElementKind.constructorImplementationElement); @@ -35097,9 +35155,9 @@ var ts; } Rules.prototype.getRuleName = function (rule) { var o = this; - for (var name_28 in o) { - if (o[name_28] === rule) { - return name_28; + for (var name_29 in o) { + if (o[name_29] === rule) { + return name_29; } } throw new Error("Unknown rule"); @@ -38000,12 +38058,20 @@ var ts; * Extra compiler options that will unconditionally be used bu this function are: * - isolatedModules = true * - allowNonTsExtensions = true + * - noLib = true + * - noResolve = true */ function transpile(input, compilerOptions, fileName, diagnostics) { var options = compilerOptions ? ts.clone(compilerOptions) : getDefaultCompilerOptions(); options.isolatedModules = true; // Filename can be non-ts file. options.allowNonTsExtensions = true; + // We are not returning a sourceFile for lib file when asked by the program, + // so pass --noLib to avoid reporting a file not found error. + options.noLib = true; + // We are not doing a full typecheck, we are not resolving the whole context, + // so pass --noResolve to avoid reporting missing file errors. + options.noResolve = true; // Parse var inputFileName = fileName || "module.ts"; var sourceFile = ts.createSourceFile(inputFileName, input, options.target); @@ -38013,6 +38079,7 @@ var ts; if (diagnostics && sourceFile.parseDiagnostics) { diagnostics.push.apply(diagnostics, sourceFile.parseDiagnostics); } + var newLine = ts.getNewLineCharacter(options); // Output var outputText; // Create a compilerHost object to allow the compiler to read and write files @@ -38026,11 +38093,11 @@ var ts; useCaseSensitiveFileNames: function () { return false; }, getCanonicalFileName: function (fileName) { return fileName; }, getCurrentDirectory: function () { return ""; }, - getNewLine: function () { return (ts.sys && ts.sys.newLine) || "\r\n"; } + getNewLine: function () { return newLine; } }; var program = ts.createProgram([inputFileName], options, compilerHost); if (diagnostics) { - diagnostics.push.apply(diagnostics, program.getGlobalDiagnostics()); + diagnostics.push.apply(diagnostics, program.getCompilerOptionsDiagnostics()); } // Emit program.emit(); @@ -39424,10 +39491,10 @@ var ts; for (var _i = 0, _a = program.getSourceFiles(); _i < _a.length; _i++) { var sourceFile = _a[_i]; var nameTable = getNameTable(sourceFile); - for (var name_29 in nameTable) { - if (!allNames[name_29]) { - allNames[name_29] = name_29; - var displayName = getCompletionEntryDisplayName(name_29, target, true); + for (var name_30 in nameTable) { + if (!allNames[name_30]) { + allNames[name_30] = name_30; + var displayName = getCompletionEntryDisplayName(name_30, target, true); if (displayName) { var entry = { name: displayName, @@ -41309,19 +41376,19 @@ var ts; if (isNameOfPropertyAssignment(node)) { var objectLiteral = node.parent.parent; var contextualType = typeChecker.getContextualType(objectLiteral); - var name_30 = node.text; + var name_31 = node.text; if (contextualType) { if (contextualType.flags & 16384 /* Union */) { // This is a union type, first see if the property we are looking for is a union property (i.e. exists in all types) // if not, search the constituent types for the property - var unionProperty = contextualType.getProperty(name_30); + var unionProperty = contextualType.getProperty(name_31); if (unionProperty) { return [unionProperty]; } else { var result_4 = []; ts.forEach(contextualType.types, function (t) { - var symbol = t.getProperty(name_30); + var symbol = t.getProperty(name_31); if (symbol) { result_4.push(symbol); } @@ -41330,7 +41397,7 @@ var ts; } } else { - var symbol_1 = contextualType.getProperty(name_30); + var symbol_1 = contextualType.getProperty(name_31); if (symbol_1) { return [symbol_1]; } diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index af1e9349eee..7386acdc71d 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -1491,7 +1491,7 @@ module ts { return appendParentTypeArgumentsAndSymbolName(symbol); } - function buildTypeDisplay(type: Type, writer: SymbolWriter, enclosingDeclaration?: Node, globalFlags?: TypeFormatFlags, typeStack?: Type[]) { + function buildTypeDisplay(type: Type, writer: SymbolWriter, enclosingDeclaration?: Node, globalFlags?: TypeFormatFlags, symbolStack?: Symbol[]) { let globalFlagsToPass = globalFlags & TypeFormatFlags.WriteOwnNameForAnyLike; return writeType(type, globalFlags); @@ -1499,8 +1499,9 @@ module ts { // Write undefined/null type as any if (type.flags & TypeFlags.Intrinsic) { // Special handling for unknown / resolving types, they should show up as any and not unknown or __resolving - writer.writeKeyword(!(globalFlags & TypeFormatFlags.WriteOwnNameForAnyLike) && - (type.flags & TypeFlags.Any) ? "any" : (type).intrinsicName); + writer.writeKeyword(!(globalFlags & TypeFormatFlags.WriteOwnNameForAnyLike) && isTypeAny(type) + ? "any" + : (type).intrinsicName); } else if (type.flags & TypeFlags.Reference) { writeTypeReference(type, flags); @@ -1614,49 +1615,54 @@ module ts { } function writeAnonymousType(type: ObjectType, flags: TypeFormatFlags) { - // Always use 'typeof T' for type of class, enum, and module objects - if (type.symbol && type.symbol.flags & (SymbolFlags.Class | SymbolFlags.Enum | SymbolFlags.ValueModule)) { - writeTypeofSymbol(type, flags); - } - // Use 'typeof T' for types of functions and methods that circularly reference themselves - else if (shouldWriteTypeOfFunctionSymbol()) { - writeTypeofSymbol(type, flags); - } - else if (typeStack && contains(typeStack, type)) { - // If type is an anonymous type literal in a type alias declaration, use type alias name - let typeAlias = getTypeAliasForTypeLiteral(type); - if (typeAlias) { - // The specified symbol flags need to be reinterpreted as type flags - buildSymbolDisplay(typeAlias, writer, enclosingDeclaration, SymbolFlags.Type, SymbolFormatFlags.None, flags); + let symbol = type.symbol; + if (symbol) { + // Always use 'typeof T' for type of class, enum, and module objects + if (symbol.flags & (SymbolFlags.Class | SymbolFlags.Enum | SymbolFlags.ValueModule)) { + writeTypeofSymbol(type, flags); + } + else if (shouldWriteTypeOfFunctionSymbol()) { + writeTypeofSymbol(type, flags); + } + else if (contains(symbolStack, symbol)) { + // If type is an anonymous type literal in a type alias declaration, use type alias name + let typeAlias = getTypeAliasForTypeLiteral(type); + if (typeAlias) { + // The specified symbol flags need to be reinterpreted as type flags + buildSymbolDisplay(typeAlias, writer, enclosingDeclaration, SymbolFlags.Type, SymbolFormatFlags.None, flags); + } + else { + // Recursive usage, use any + writeKeyword(writer, SyntaxKind.AnyKeyword); + } } else { - // Recursive usage, use any - writeKeyword(writer, SyntaxKind.AnyKeyword); + // Since instantiations of the same anonymous type have the same symbol, tracking symbols instead + // of types allows us to catch circular references to instantiations of the same anonymous type + if (!symbolStack) { + symbolStack = []; + } + symbolStack.push(symbol); + writeLiteralType(type, flags); + symbolStack.pop(); } } else { - if (!typeStack) { - typeStack = []; - } - typeStack.push(type); + // Anonymous types with no symbol are never circular writeLiteralType(type, flags); - typeStack.pop(); } function shouldWriteTypeOfFunctionSymbol() { - if (type.symbol) { - let isStaticMethodSymbol = !!(type.symbol.flags & SymbolFlags.Method && // typeof static method - ts.forEach(type.symbol.declarations, declaration => declaration.flags & NodeFlags.Static)); - let isNonLocalFunctionSymbol = !!(type.symbol.flags & SymbolFlags.Function) && - (type.symbol.parent || // is exported function symbol - ts.forEach(type.symbol.declarations, declaration => - declaration.parent.kind === SyntaxKind.SourceFile || declaration.parent.kind === SyntaxKind.ModuleBlock)); - - if (isStaticMethodSymbol || isNonLocalFunctionSymbol) { - // typeof is allowed only for static/non local functions - return !!(flags & TypeFormatFlags.UseTypeOfFunction) || // use typeof if format flags specify it - (typeStack && contains(typeStack, type)); // it is type of the symbol uses itself recursively - } + let isStaticMethodSymbol = !!(symbol.flags & SymbolFlags.Method && // typeof static method + forEach(symbol.declarations, declaration => declaration.flags & NodeFlags.Static)); + let isNonLocalFunctionSymbol = !!(symbol.flags & SymbolFlags.Function) && + (symbol.parent || // is exported function symbol + forEach(symbol.declarations, declaration => + declaration.parent.kind === SyntaxKind.SourceFile || declaration.parent.kind === SyntaxKind.ModuleBlock)); + if (isStaticMethodSymbol || isNonLocalFunctionSymbol) { + // typeof is allowed only for static/non local functions + return !!(flags & TypeFormatFlags.UseTypeOfFunction) || // use typeof if format flags specify it + (contains(symbolStack, symbol)); // it is type of the symbol uses itself recursively } } } @@ -1691,7 +1697,7 @@ module ts { if (flags & TypeFormatFlags.InElementType) { writePunctuation(writer, SyntaxKind.OpenParenToken); } - buildSignatureDisplay(resolved.callSignatures[0], writer, enclosingDeclaration, globalFlagsToPass | TypeFormatFlags.WriteArrowStyleSignature, typeStack); + buildSignatureDisplay(resolved.callSignatures[0], writer, enclosingDeclaration, globalFlagsToPass | TypeFormatFlags.WriteArrowStyleSignature, symbolStack); if (flags & TypeFormatFlags.InElementType) { writePunctuation(writer, SyntaxKind.CloseParenToken); } @@ -1703,7 +1709,7 @@ module ts { } writeKeyword(writer, SyntaxKind.NewKeyword); writeSpace(writer); - buildSignatureDisplay(resolved.constructSignatures[0], writer, enclosingDeclaration, globalFlagsToPass | TypeFormatFlags.WriteArrowStyleSignature, typeStack); + buildSignatureDisplay(resolved.constructSignatures[0], writer, enclosingDeclaration, globalFlagsToPass | TypeFormatFlags.WriteArrowStyleSignature, symbolStack); if (flags & TypeFormatFlags.InElementType) { writePunctuation(writer, SyntaxKind.CloseParenToken); } @@ -1715,7 +1721,7 @@ module ts { writer.writeLine(); writer.increaseIndent(); for (let signature of resolved.callSignatures) { - buildSignatureDisplay(signature, writer, enclosingDeclaration, globalFlagsToPass, typeStack); + buildSignatureDisplay(signature, writer, enclosingDeclaration, globalFlagsToPass, symbolStack); writePunctuation(writer, SyntaxKind.SemicolonToken); writer.writeLine(); } @@ -1723,7 +1729,7 @@ module ts { writeKeyword(writer, SyntaxKind.NewKeyword); writeSpace(writer); - buildSignatureDisplay(signature, writer, enclosingDeclaration, globalFlagsToPass, typeStack); + buildSignatureDisplay(signature, writer, enclosingDeclaration, globalFlagsToPass, symbolStack); writePunctuation(writer, SyntaxKind.SemicolonToken); writer.writeLine(); } @@ -1764,7 +1770,7 @@ module ts { if (p.flags & SymbolFlags.Optional) { writePunctuation(writer, SyntaxKind.QuestionToken); } - buildSignatureDisplay(signature, writer, enclosingDeclaration, globalFlagsToPass, typeStack); + buildSignatureDisplay(signature, writer, enclosingDeclaration, globalFlagsToPass, symbolStack); writePunctuation(writer, SyntaxKind.SemicolonToken); writer.writeLine(); } @@ -1793,18 +1799,18 @@ module ts { } } - function buildTypeParameterDisplay(tp: TypeParameter, writer: SymbolWriter, enclosingDeclaration?: Node, flags?: TypeFormatFlags, typeStack?: Type[]) { + function buildTypeParameterDisplay(tp: TypeParameter, writer: SymbolWriter, enclosingDeclaration?: Node, flags?: TypeFormatFlags, symbolStack?: Symbol[]) { appendSymbolNameOnly(tp.symbol, writer); let constraint = getConstraintOfTypeParameter(tp); if (constraint) { writeSpace(writer); writeKeyword(writer, SyntaxKind.ExtendsKeyword); writeSpace(writer); - buildTypeDisplay(constraint, writer, enclosingDeclaration, flags, typeStack); + buildTypeDisplay(constraint, writer, enclosingDeclaration, flags, symbolStack); } } - function buildParameterDisplay(p: Symbol, writer: SymbolWriter, enclosingDeclaration?: Node, flags?: TypeFormatFlags, typeStack?: Type[]) { + function buildParameterDisplay(p: Symbol, writer: SymbolWriter, enclosingDeclaration?: Node, flags?: TypeFormatFlags, symbolStack?: Symbol[]) { let parameterNode = p.valueDeclaration; if (isRestParameter(parameterNode)) { writePunctuation(writer, SyntaxKind.DotDotDotToken); @@ -1816,10 +1822,10 @@ module ts { writePunctuation(writer, SyntaxKind.ColonToken); writeSpace(writer); - buildTypeDisplay(getTypeOfSymbol(p), writer, enclosingDeclaration, flags, typeStack); + buildTypeDisplay(getTypeOfSymbol(p), writer, enclosingDeclaration, flags, symbolStack); } - function buildDisplayForTypeParametersAndDelimiters(typeParameters: TypeParameter[], writer: SymbolWriter, enclosingDeclaration?: Node, flags?: TypeFormatFlags, typeStack?: Type[]) { + function buildDisplayForTypeParametersAndDelimiters(typeParameters: TypeParameter[], writer: SymbolWriter, enclosingDeclaration?: Node, flags?: TypeFormatFlags, symbolStack?: Symbol[]) { if (typeParameters && typeParameters.length) { writePunctuation(writer, SyntaxKind.LessThanToken); for (let i = 0; i < typeParameters.length; i++) { @@ -1827,13 +1833,13 @@ module ts { writePunctuation(writer, SyntaxKind.CommaToken); writeSpace(writer); } - buildTypeParameterDisplay(typeParameters[i], writer, enclosingDeclaration, flags, typeStack); + buildTypeParameterDisplay(typeParameters[i], writer, enclosingDeclaration, flags, symbolStack); } writePunctuation(writer, SyntaxKind.GreaterThanToken); } } - function buildDisplayForTypeArgumentsAndDelimiters(typeParameters: TypeParameter[], mapper: TypeMapper, writer: SymbolWriter, enclosingDeclaration?: Node, flags?: TypeFormatFlags, typeStack?: Type[]) { + function buildDisplayForTypeArgumentsAndDelimiters(typeParameters: TypeParameter[], mapper: TypeMapper, writer: SymbolWriter, enclosingDeclaration?: Node, flags?: TypeFormatFlags, symbolStack?: Symbol[]) { if (typeParameters && typeParameters.length) { writePunctuation(writer, SyntaxKind.LessThanToken); for (let i = 0; i < typeParameters.length; i++) { @@ -1847,19 +1853,19 @@ module ts { } } - function buildDisplayForParametersAndDelimiters(parameters: Symbol[], writer: SymbolWriter, enclosingDeclaration?: Node, flags?: TypeFormatFlags, typeStack?: Type[]) { + function buildDisplayForParametersAndDelimiters(parameters: Symbol[], writer: SymbolWriter, enclosingDeclaration?: Node, flags?: TypeFormatFlags, symbolStack?: Symbol[]) { writePunctuation(writer, SyntaxKind.OpenParenToken); for (let i = 0; i < parameters.length; i++) { if (i > 0) { writePunctuation(writer, SyntaxKind.CommaToken); writeSpace(writer); } - buildParameterDisplay(parameters[i], writer, enclosingDeclaration, flags, typeStack); + buildParameterDisplay(parameters[i], writer, enclosingDeclaration, flags, symbolStack); } writePunctuation(writer, SyntaxKind.CloseParenToken); } - function buildReturnTypeDisplay(signature: Signature, writer: SymbolWriter, enclosingDeclaration?: Node, flags?: TypeFormatFlags, typeStack?: Type[]) { + function buildReturnTypeDisplay(signature: Signature, writer: SymbolWriter, enclosingDeclaration?: Node, flags?: TypeFormatFlags, symbolStack?: Symbol[]) { if (flags & TypeFormatFlags.WriteArrowStyleSignature) { writeSpace(writer); writePunctuation(writer, SyntaxKind.EqualsGreaterThanToken); @@ -1868,21 +1874,21 @@ module ts { writePunctuation(writer, SyntaxKind.ColonToken); } writeSpace(writer); - buildTypeDisplay(getReturnTypeOfSignature(signature), writer, enclosingDeclaration, flags, typeStack); + buildTypeDisplay(getReturnTypeOfSignature(signature), writer, enclosingDeclaration, flags, symbolStack); } - function buildSignatureDisplay(signature: Signature, writer: SymbolWriter, enclosingDeclaration?: Node, flags?: TypeFormatFlags, typeStack?: Type[]) { + function buildSignatureDisplay(signature: Signature, writer: SymbolWriter, enclosingDeclaration?: Node, flags?: TypeFormatFlags, symbolStack?: Symbol[]) { if (signature.target && (flags & TypeFormatFlags.WriteTypeArgumentsOfSignature)) { // Instantiated signature, write type arguments instead // This is achieved by passing in the mapper separately buildDisplayForTypeArgumentsAndDelimiters(signature.target.typeParameters, signature.mapper, writer, enclosingDeclaration); } else { - buildDisplayForTypeParametersAndDelimiters(signature.typeParameters, writer, enclosingDeclaration, flags, typeStack); + buildDisplayForTypeParametersAndDelimiters(signature.typeParameters, writer, enclosingDeclaration, flags, symbolStack); } - buildDisplayForParametersAndDelimiters(signature.parameters, writer, enclosingDeclaration, flags, typeStack); - buildReturnTypeDisplay(signature, writer, enclosingDeclaration, flags, typeStack); + buildDisplayForParametersAndDelimiters(signature.parameters, writer, enclosingDeclaration, flags, symbolStack); + buildReturnTypeDisplay(signature, writer, enclosingDeclaration, flags, symbolStack); } return _displayBuilder || (_displayBuilder = { @@ -2137,6 +2143,10 @@ module ts { return prop ? getTypeOfSymbol(prop) : undefined; } + function isTypeAny(type: Type) { + return type && (type.flags & TypeFlags.Any) !== 0; + } + // Return the inferred type for a binding element function getTypeForBindingElement(declaration: BindingElement): Type { let pattern = declaration.parent; @@ -2148,7 +2158,7 @@ module ts { // If no type was specified or inferred for parent, or if the specified or inferred type is any, // infer from the initializer of the binding element if one is present. Otherwise, go with the // undefined or any type of the parent. - if (!parentType || parentType === anyType) { + if (!parentType || isTypeAny(parentType)) { if (declaration.initializer) { return checkExpressionCached(declaration.initializer); } @@ -2175,7 +2185,7 @@ module ts { // fact an iterable or array (depending on target language). let elementType = checkIteratedTypeOrElementType(parentType, pattern, /*allowStringInput*/ false); if (!declaration.dotDotDotToken) { - if (elementType.flags & TypeFlags.Any) { + if (isTypeAny(elementType)) { return elementType; } @@ -2379,7 +2389,7 @@ module ts { // Variable has initializer that circularly references the variable itself type = anyType; if (compilerOptions.noImplicitAny) { - error(symbol.valueDeclaration, Diagnostics._0_implicitly_has_type_any_because_it_is_does_not_have_a_type_annotation_and_is_referenced_directly_or_indirectly_in_its_own_initializer, + error(symbol.valueDeclaration, Diagnostics._0_implicitly_has_type_any_because_it_does_not_have_a_type_annotation_and_is_referenced_directly_or_indirectly_in_its_own_initializer, symbolToString(symbol)); } } @@ -3732,9 +3742,9 @@ module ts { } } - function containsAnyType(types: Type[]) { + function containsTypeAny(types: Type[]) { for (let type of types) { - if (type.flags & TypeFlags.Any) { + if (isTypeAny(type)) { return true; } } @@ -3762,7 +3772,7 @@ module ts { let sortedTypes: Type[] = []; addTypesToSortedSet(sortedTypes, types); if (noSubtypeReduction) { - if (containsAnyType(sortedTypes)) { + if (containsTypeAny(sortedTypes)) { return anyType; } removeAllButLast(sortedTypes, undefinedType); @@ -4023,19 +4033,8 @@ module ts { } function instantiateAnonymousType(type: ObjectType, mapper: TypeMapper): ObjectType { - // If this type has already been instantiated using this mapper, returned the cached result. This guards against - // infinite instantiations of cyclic types, e.g. "var x: { a: T, b: typeof x };" - if (mapper.mappings) { - let cached = mapper.mappings[type.id]; - if (cached) { - return cached; - } - } - else { - mapper.mappings = {}; - } - // Instantiate the given type using the given mapper and cache the result - let result = createObjectType(TypeFlags.Anonymous, type.symbol); + // Mark the anonymous type as instantiated such that our infinite instantiation detection logic can recognize it + let result = createObjectType(TypeFlags.Anonymous | TypeFlags.Instantiated, type.symbol); result.properties = instantiateList(getPropertiesOfObjectType(type), mapper, instantiateSymbol); result.members = createSymbolTable(result.properties); result.callSignatures = instantiateList(getSignaturesOfType(type, SignatureKind.Call), mapper, instantiateSignature); @@ -4044,7 +4043,6 @@ module ts { let numberIndexType = getIndexTypeOfType(type, IndexKind.Number); if (stringIndexType) result.stringIndexType = instantiateType(stringIndexType, mapper); if (numberIndexType) result.numberIndexType = instantiateType(numberIndexType, mapper); - mapper.mappings[type.id] = result; return result; } @@ -4209,13 +4207,13 @@ module ts { // both types are the same - covers 'they are the same primitive type or both are Any' or the same type parameter cases if (source === target) return Ternary.True; if (relation !== identityRelation) { - if (target.flags & TypeFlags.Any) return Ternary.True; + if (isTypeAny(target)) return Ternary.True; if (source === undefinedType) return Ternary.True; if (source === nullType && target !== undefinedType) return Ternary.True; if (source.flags & TypeFlags.Enum && target === numberType) return Ternary.True; if (source.flags & TypeFlags.StringLiteral && target === stringType) return Ternary.True; if (relation === assignableRelation) { - if (source.flags & TypeFlags.Any) return Ternary.True; + if (isTypeAny(source)) return Ternary.True; if (source === numberType && target.flags & TypeFlags.Enum) return Ternary.True; } } @@ -4459,12 +4457,13 @@ module ts { // Effectively, we will generate a false positive when two types are structurally equal to at least 10 levels, but unequal at // some level beyond that. function isDeeplyNestedGeneric(type: ObjectType, stack: ObjectType[]): boolean { - if (type.flags & TypeFlags.Reference && depth >= 10) { - let target = (type).target; + // We track type references (created by createTypeReference) and instantiated types (created by instantiateType) + if (type.flags & (TypeFlags.Reference | TypeFlags.Instantiated) && depth >= 10) { + let symbol = type.symbol; let count = 0; for (let i = 0; i < depth; i++) { let t = stack[i]; - if (t.flags & TypeFlags.Reference && (t).target === target) { + if (t.flags & (TypeFlags.Reference | TypeFlags.Instantiated) && t.symbol === symbol) { count++; if (count >= 10) return true; } @@ -5487,55 +5486,58 @@ module ts { function getNarrowedTypeOfSymbol(symbol: Symbol, node: Node) { let type = getTypeOfSymbol(symbol); // Only narrow when symbol is variable of type any or an object, union, or type parameter type - if (node && symbol.flags & SymbolFlags.Variable && type.flags & (TypeFlags.Any | TypeFlags.ObjectType | TypeFlags.Union | TypeFlags.TypeParameter)) { - loop: while (node.parent) { - let child = node; - node = node.parent; - let narrowedType = type; - switch (node.kind) { - case SyntaxKind.IfStatement: - // In a branch of an if statement, narrow based on controlling expression - if (child !== (node).expression) { - narrowedType = narrowType(type, (node).expression, /*assumeTrue*/ child === (node).thenStatement); - } - break; - case SyntaxKind.ConditionalExpression: - // In a branch of a conditional expression, narrow based on controlling condition - if (child !== (node).condition) { - narrowedType = narrowType(type, (node).condition, /*assumeTrue*/ child === (node).whenTrue); - } - break; - case SyntaxKind.BinaryExpression: - // In the right operand of an && or ||, narrow based on left operand - if (child === (node).right) { - if ((node).operatorToken.kind === SyntaxKind.AmpersandAmpersandToken) { - narrowedType = narrowType(type, (node).left, /*assumeTrue*/ true); + if (node && symbol.flags & SymbolFlags.Variable) { + if (isTypeAny(type) || type.flags & (TypeFlags.ObjectType | TypeFlags.Union | TypeFlags.TypeParameter)) { + loop: while (node.parent) { + let child = node; + node = node.parent; + let narrowedType = type; + switch (node.kind) { + case SyntaxKind.IfStatement: + // In a branch of an if statement, narrow based on controlling expression + if (child !== (node).expression) { + narrowedType = narrowType(type, (node).expression, /*assumeTrue*/ child === (node).thenStatement); } - else if ((node).operatorToken.kind === SyntaxKind.BarBarToken) { - narrowedType = narrowType(type, (node).left, /*assumeTrue*/ false); + break; + case SyntaxKind.ConditionalExpression: + // In a branch of a conditional expression, narrow based on controlling condition + if (child !== (node).condition) { + narrowedType = narrowType(type, (node).condition, /*assumeTrue*/ child === (node).whenTrue); } - } - break; - case SyntaxKind.SourceFile: - case SyntaxKind.ModuleDeclaration: - case SyntaxKind.FunctionDeclaration: - case SyntaxKind.MethodDeclaration: - case SyntaxKind.MethodSignature: - case SyntaxKind.GetAccessor: - case SyntaxKind.SetAccessor: - case SyntaxKind.Constructor: - // Stop at the first containing function or module declaration - break loop; - } - // Use narrowed type if construct contains no assignments to variable - if (narrowedType !== type) { - if (isVariableAssignedWithin(symbol, node)) { - break; + break; + case SyntaxKind.BinaryExpression: + // In the right operand of an && or ||, narrow based on left operand + if (child === (node).right) { + if ((node).operatorToken.kind === SyntaxKind.AmpersandAmpersandToken) { + narrowedType = narrowType(type, (node).left, /*assumeTrue*/ true); + } + else if ((node).operatorToken.kind === SyntaxKind.BarBarToken) { + narrowedType = narrowType(type, (node).left, /*assumeTrue*/ false); + } + } + break; + case SyntaxKind.SourceFile: + case SyntaxKind.ModuleDeclaration: + case SyntaxKind.FunctionDeclaration: + case SyntaxKind.MethodDeclaration: + case SyntaxKind.MethodSignature: + case SyntaxKind.GetAccessor: + case SyntaxKind.SetAccessor: + case SyntaxKind.Constructor: + // Stop at the first containing function or module declaration + break loop; + } + // Use narrowed type if construct contains no assignments to variable + if (narrowedType !== type) { + if (isVariableAssignedWithin(symbol, node)) { + break; + } + type = narrowedType; } - type = narrowedType; } } } + return type; function narrowTypeByEquality(type: Type, expr: BinaryExpression, assumeTrue: boolean): Type { @@ -5608,7 +5610,7 @@ module ts { function narrowTypeByInstanceof(type: Type, expr: BinaryExpression, assumeTrue: boolean): Type { // Check that type is not any, assumed result is true, and we have variable symbol on the left - if (type.flags & TypeFlags.Any || !assumeTrue || expr.left.kind !== SyntaxKind.Identifier || getResolvedSymbol(expr.left) !== symbol) { + if (isTypeAny(type) || !assumeTrue || expr.left.kind !== SyntaxKind.Identifier || getResolvedSymbol(expr.left) !== symbol) { return type; } // Check that right operand is a function type with a prototype property @@ -5622,7 +5624,7 @@ module ts { if (prototypeProperty) { // Target type is type of the prototype property let prototypePropertyType = getTypeOfSymbol(prototypeProperty); - if (prototypePropertyType !== anyType) { + if (!isTypeAny(prototypePropertyType)) { targetType = prototypePropertyType; } } @@ -6409,7 +6411,11 @@ module ts { function isNumericComputedName(name: ComputedPropertyName): boolean { // It seems odd to consider an expression of type Any to result in a numeric name, // but this behavior is consistent with checkIndexedAccess - return allConstituentTypesHaveKind(checkComputedPropertyName(name), TypeFlags.Any | TypeFlags.NumberLike); + return isTypeAnyOrAllConstituentTypesHaveKind(checkComputedPropertyName(name), TypeFlags.NumberLike); + } + + function isTypeAnyOrAllConstituentTypesHaveKind(type: Type, kind: TypeFlags): boolean { + return isTypeAny(type) || allConstituentTypesHaveKind(type, kind); } function isNumericLiteralName(name: string) { @@ -6444,7 +6450,7 @@ module ts { // This will allow types number, string, symbol or any. It will also allow enums, the unknown // type, and any union of these types (like string | number). - if (!allConstituentTypesHaveKind(links.resolvedType, TypeFlags.Any | TypeFlags.NumberLike | TypeFlags.StringLike | TypeFlags.ESSymbol)) { + if (!isTypeAnyOrAllConstituentTypesHaveKind(links.resolvedType, TypeFlags.NumberLike | TypeFlags.StringLike | TypeFlags.ESSymbol)) { error(node, Diagnostics.A_computed_property_name_must_be_of_type_string_number_symbol_or_any); } else { @@ -6596,39 +6602,39 @@ module ts { function checkPropertyAccessExpressionOrQualifiedName(node: PropertyAccessExpression | QualifiedName, left: Expression | QualifiedName, right: Identifier) { let type = checkExpressionOrQualifiedName(left); - if (type === unknownType) return type; - if (type !== anyType) { - let apparentType = getApparentType(getWidenedType(type)); - if (apparentType === unknownType) { - // handle cases when type is Type parameter with invalid constraint - return unknownType; - } - let prop = getPropertyOfType(apparentType, right.text); - if (!prop) { - if (right.text) { - error(right, Diagnostics.Property_0_does_not_exist_on_type_1, declarationNameToString(right), typeToString(type)); - } - return unknownType; - } - getNodeLinks(node).resolvedSymbol = prop; - if (prop.parent && prop.parent.flags & SymbolFlags.Class) { - // TS 1.0 spec (April 2014): 4.8.2 - // - In a constructor, instance member function, instance member accessor, or - // instance member variable initializer where this references a derived class instance, - // a super property access is permitted and must specify a public instance member function of the base class. - // - In a static member function or static member accessor - // where this references the constructor function object of a derived class, - // a super property access is permitted and must specify a public static member function of the base class. - if (left.kind === SyntaxKind.SuperKeyword && getDeclarationKindFromSymbol(prop) !== SyntaxKind.MethodDeclaration) { - error(right, Diagnostics.Only_public_and_protected_methods_of_the_base_class_are_accessible_via_the_super_keyword); - } - else { - checkClassPropertyAccess(node, left, type, prop); - } - } - return getTypeOfSymbol(prop); + if (isTypeAny(type)) { + return type; } - return anyType; + + let apparentType = getApparentType(getWidenedType(type)); + if (apparentType === unknownType) { + // handle cases when type is Type parameter with invalid constraint + return unknownType; + } + let prop = getPropertyOfType(apparentType, right.text); + if (!prop) { + if (right.text) { + error(right, Diagnostics.Property_0_does_not_exist_on_type_1, declarationNameToString(right), typeToString(type)); + } + return unknownType; + } + getNodeLinks(node).resolvedSymbol = prop; + if (prop.parent && prop.parent.flags & SymbolFlags.Class) { + // TS 1.0 spec (April 2014): 4.8.2 + // - In a constructor, instance member function, instance member accessor, or + // instance member variable initializer where this references a derived class instance, + // a super property access is permitted and must specify a public instance member function of the base class. + // - In a static member function or static member accessor + // where this references the constructor function object of a derived class, + // a super property access is permitted and must specify a public static member function of the base class. + if (left.kind === SyntaxKind.SuperKeyword && getDeclarationKindFromSymbol(prop) !== SyntaxKind.MethodDeclaration) { + error(right, Diagnostics.Only_public_and_protected_methods_of_the_base_class_are_accessible_via_the_super_keyword); + } + else { + checkClassPropertyAccess(node, left, type, prop); + } + } + return getTypeOfSymbol(prop); } function isValidPropertyAccess(node: PropertyAccessExpression | QualifiedName, propertyName: string): boolean { @@ -6637,7 +6643,7 @@ module ts { : (node).left; let type = checkExpressionOrQualifiedName(left); - if (type !== unknownType && type !== anyType) { + if (type !== unknownType && !isTypeAny(type)) { let prop = getPropertyOfType(getWidenedType(type), propertyName); if (prop && prop.parent && prop.parent.flags & SymbolFlags.Class) { if (left.kind === SyntaxKind.SuperKeyword && getDeclarationKindFromSymbol(prop) !== SyntaxKind.MethodDeclaration) { @@ -6710,10 +6716,10 @@ module ts { } // Check for compatible indexer types. - if (allConstituentTypesHaveKind(indexType, TypeFlags.Any | TypeFlags.StringLike | TypeFlags.NumberLike | TypeFlags.ESSymbol)) { + if (isTypeAnyOrAllConstituentTypesHaveKind(indexType, TypeFlags.StringLike | TypeFlags.NumberLike | TypeFlags.ESSymbol)) { // Try to use a number indexer. - if (allConstituentTypesHaveKind(indexType, TypeFlags.Any | TypeFlags.NumberLike)) { + if (isTypeAnyOrAllConstituentTypesHaveKind(indexType, TypeFlags.NumberLike)) { let numberIndexType = getIndexTypeOfType(objectType, IndexKind.Number); if (numberIndexType) { return numberIndexType; @@ -6727,7 +6733,7 @@ module ts { } // Fall back to any. - if (compilerOptions.noImplicitAny && !compilerOptions.suppressImplicitAnyIndexErrors && objectType !== anyType) { + if (compilerOptions.noImplicitAny && !compilerOptions.suppressImplicitAnyIndexErrors && !isTypeAny(objectType)) { error(node, Diagnostics.Index_signature_of_object_type_implicitly_has_an_any_type); } @@ -7377,8 +7383,10 @@ module ts { // types are provided for the argument expressions, and the result is always of type Any. // We exclude union types because we may have a union of function types that happen to have // no common signatures. - if (funcType === anyType || (!callSignatures.length && !constructSignatures.length && !(funcType.flags & TypeFlags.Union) && isTypeAssignableTo(funcType, globalFunctionType))) { - if (node.typeArguments) { + if (isTypeAny(funcType) || (!callSignatures.length && !constructSignatures.length && !(funcType.flags & TypeFlags.Union) && isTypeAssignableTo(funcType, globalFunctionType))) { + // The unknownType indicates that an error already occured (and was reported). No + // need to report another error in this case. + if (funcType !== unknownType && node.typeArguments) { error(node, Diagnostics.Untyped_function_calls_may_not_accept_type_arguments); } return resolveUntypedCall(node); @@ -7407,15 +7415,6 @@ module ts { } let expressionType = checkExpression(node.expression); - // TS 1.0 spec: 4.11 - // If ConstructExpr is of type Any, Args can be any argument - // list and the result of the operation is of type Any. - if (expressionType === anyType) { - if (node.typeArguments) { - error(node, Diagnostics.Untyped_function_calls_may_not_accept_type_arguments); - } - return resolveUntypedCall(node); - } // If ConstructExpr's apparent type(section 3.8.1) is an object type with one or // more construct signatures, the expression is processed in the same manner as a @@ -7428,6 +7427,16 @@ module ts { return resolveErrorCall(node); } + // TS 1.0 spec: 4.11 + // If ConstructExpr is of type Any, Args can be any argument + // list and the result of the operation is of type Any. + if (isTypeAny(expressionType)) { + if (node.typeArguments) { + error(node, Diagnostics.Untyped_function_calls_may_not_accept_type_arguments); + } + return resolveUntypedCall(node); + } + // Technically, this signatures list may be incomplete. We are taking the apparent type, // but we are not including construct signatures that may have been added to the Object or // Function interface, since they have none by default. This is a bit of a leap of faith @@ -7465,7 +7474,7 @@ module ts { let callSignatures = getSignaturesOfType(apparentType, SignatureKind.Call); - if (tagType === anyType || (!callSignatures.length && !(tagType.flags & TypeFlags.Union) && isTypeAssignableTo(tagType, globalFunctionType))) { + if (isTypeAny(tagType) || (!callSignatures.length && !(tagType.flags & TypeFlags.Union) && isTypeAssignableTo(tagType, globalFunctionType))) { return resolveUntypedCall(node); } @@ -7677,7 +7686,7 @@ module ts { } // Functions that return 'void' or 'any' don't need any return expressions. - if (returnType === voidType || returnType === anyType) { + if (returnType === voidType || isTypeAny(returnType)) { return; } @@ -7758,6 +7767,15 @@ module ts { } if (node.body) { + if (!node.type) { + // There are some checks that are only performed in getReturnTypeFromBody, that may produce errors + // we need. An example is the noImplicitAny errors resulting from widening the return expression + // of a function. Because checking of function expression bodies is deferred, there was never an + // appropriate time to do this during the main walk of the file (see the comment at the top of + // checkFunctionExpressionBodies). So it must be done now. + getReturnTypeOfSignature(getSignatureFromDeclaration(node)); + } + if (node.body.kind === SyntaxKind.Block) { checkSourceElement(node.body); } @@ -7772,7 +7790,7 @@ module ts { } function checkArithmeticOperandType(operand: Node, type: Type, diagnostic: DiagnosticMessage): boolean { - if (!allConstituentTypesHaveKind(type, TypeFlags.Any | TypeFlags.NumberLike)) { + if (!isTypeAnyOrAllConstituentTypesHaveKind(type, TypeFlags.NumberLike)) { error(operand, diagnostic); return false; } @@ -7984,7 +8002,7 @@ module ts { error(node.left, Diagnostics.The_left_hand_side_of_an_instanceof_expression_must_be_of_type_any_an_object_type_or_a_type_parameter); } // NOTE: do not raise error if right is unknown as related error was already reported - if (!(rightType.flags & TypeFlags.Any || isTypeSubtypeOf(rightType, globalFunctionType))) { + if (!(isTypeAny(rightType) || isTypeSubtypeOf(rightType, globalFunctionType))) { error(node.right, Diagnostics.The_right_hand_side_of_an_instanceof_expression_must_be_of_type_any_or_of_a_type_assignable_to_the_Function_interface_type); } return booleanType; @@ -7995,10 +8013,10 @@ module ts { // The in operator requires the left operand to be of type Any, the String primitive type, or the Number primitive type, // and the right operand to be of type Any, an object type, or a type parameter type. // The result is always of the Boolean primitive type. - if (!allConstituentTypesHaveKind(leftType, TypeFlags.Any | TypeFlags.StringLike | TypeFlags.NumberLike | TypeFlags.ESSymbol)) { + if (!isTypeAnyOrAllConstituentTypesHaveKind(leftType, TypeFlags.StringLike | TypeFlags.NumberLike | TypeFlags.ESSymbol)) { error(node.left, Diagnostics.The_left_hand_side_of_an_in_expression_must_be_of_type_any_string_number_or_symbol); } - if (!allConstituentTypesHaveKind(rightType, TypeFlags.Any | TypeFlags.ObjectType | TypeFlags.TypeParameter)) { + if (!isTypeAnyOrAllConstituentTypesHaveKind(rightType, TypeFlags.ObjectType | TypeFlags.TypeParameter)) { error(node.right, Diagnostics.The_right_hand_side_of_an_in_expression_must_be_of_type_any_an_object_type_or_a_type_parameter); } return booleanType; @@ -8010,10 +8028,11 @@ module ts { if (p.kind === SyntaxKind.PropertyAssignment || p.kind === SyntaxKind.ShorthandPropertyAssignment) { // TODO(andersh): Computed property support let name = (p).name; - let type = sourceType.flags & TypeFlags.Any ? sourceType : - getTypeOfPropertyOfType(sourceType, name.text) || - isNumericLiteralName(name.text) && getIndexTypeOfType(sourceType, IndexKind.Number) || - getIndexTypeOfType(sourceType, IndexKind.String); + let type = isTypeAny(sourceType) + ? sourceType + : getTypeOfPropertyOfType(sourceType, name.text) || + isNumericLiteralName(name.text) && getIndexTypeOfType(sourceType, IndexKind.Number) || + getIndexTypeOfType(sourceType, IndexKind.String); if (type) { checkDestructuringAssignment((p).initializer || name, type); } @@ -8039,8 +8058,9 @@ module ts { if (e.kind !== SyntaxKind.OmittedExpression) { if (e.kind !== SyntaxKind.SpreadElementExpression) { let propName = "" + i; - let type = sourceType.flags & TypeFlags.Any ? sourceType : - isTupleLikeType(sourceType) + let type = isTypeAny(sourceType) + ? sourceType + : isTupleLikeType(sourceType) ? getTypeOfPropertyOfType(sourceType, propName) : elementType; if (type) { @@ -8179,10 +8199,10 @@ module ts { // If one or both operands are of the String primitive type, the result is of the String primitive type. resultType = stringType; } - else if (leftType.flags & TypeFlags.Any || rightType.flags & TypeFlags.Any) { + else if (isTypeAny(leftType) || isTypeAny(rightType)) { // Otherwise, the result is of type Any. // NOTE: unknown type here denotes error type. Old compiler treated this case as any type so do we. - resultType = anyType; + resultType = leftType === unknownType || rightType === unknownType ? unknownType : anyType; } // Symbols are not allowed at all in arithmetic expressions @@ -9964,7 +9984,7 @@ module ts { if (varExpr.kind === SyntaxKind.ArrayLiteralExpression || varExpr.kind === SyntaxKind.ObjectLiteralExpression) { error(varExpr, Diagnostics.The_left_hand_side_of_a_for_in_statement_cannot_be_a_destructuring_pattern); } - else if (!allConstituentTypesHaveKind(leftType, TypeFlags.Any | TypeFlags.StringLike)) { + else if (!isTypeAnyOrAllConstituentTypesHaveKind(leftType, TypeFlags.StringLike)) { error(varExpr, Diagnostics.The_left_hand_side_of_a_for_in_statement_must_be_of_type_string_or_any); } else { @@ -9976,7 +9996,7 @@ module ts { let rightType = checkExpression(node.expression); // unknownType is returned i.e. if node.expression is identifier whose name cannot be resolved // in this case error about missing name is already reported - do not report extra one - if (!allConstituentTypesHaveKind(rightType, TypeFlags.Any | TypeFlags.ObjectType | TypeFlags.TypeParameter)) { + if (!isTypeAnyOrAllConstituentTypesHaveKind(rightType, TypeFlags.ObjectType | TypeFlags.TypeParameter)) { error(node.expression, Diagnostics.The_right_hand_side_of_a_for_in_statement_must_be_of_type_any_an_object_type_or_a_type_parameter); } @@ -9998,7 +10018,7 @@ module ts { } function checkIteratedTypeOrElementType(inputType: Type, errorNode: Node, allowStringInput: boolean): Type { - if (inputType.flags & TypeFlags.Any) { + if (isTypeAny(inputType)) { return inputType; } @@ -10057,7 +10077,7 @@ module ts { * whole pattern and that T (above) is 'any'. */ function getElementTypeOfIterable(type: Type, errorNode: Node): Type { - if (type.flags & TypeFlags.Any) { + if (isTypeAny(type)) { return undefined; } @@ -10070,7 +10090,7 @@ module ts { } else { let iteratorFunction = getTypeOfPropertyOfType(type, getPropertyNameForKnownSymbolName("iterator")); - if (iteratorFunction && iteratorFunction.flags & TypeFlags.Any) { + if (isTypeAny(iteratorFunction)) { return undefined; } @@ -10103,7 +10123,7 @@ module ts { * */ function getElementTypeOfIterator(type: Type, errorNode: Node): Type { - if (type.flags & TypeFlags.Any) { + if (isTypeAny(type)) { return undefined; } @@ -10116,7 +10136,7 @@ module ts { } else { let iteratorNextFunction = getTypeOfPropertyOfType(type, "next"); - if (iteratorNextFunction && iteratorNextFunction.flags & TypeFlags.Any) { + if (isTypeAny(iteratorNextFunction)) { return undefined; } @@ -10129,7 +10149,7 @@ module ts { } let iteratorNextResult = getUnionType(map(iteratorNextFunctionSignatures, getReturnTypeOfSignature)); - if (iteratorNextResult.flags & TypeFlags.Any) { + if (isTypeAny(iteratorNextResult)) { return undefined; } @@ -10149,7 +10169,7 @@ module ts { } function getElementTypeOfIterableIterator(type: Type): Type { - if (type.flags & TypeFlags.Any) { + if (isTypeAny(type)) { return undefined; } @@ -11544,6 +11564,10 @@ module ts { function checkSourceFileWorker(node: SourceFile) { let links = getNodeLinks(node); if (!(links.flags & NodeCheckFlags.TypeChecked)) { + if (node.isDefaultLib && compilerOptions.skipDefaultLibCheck) { + return; + } + // Grammar checking checkGrammarSourceFile(node); diff --git a/src/compiler/commandLineParser.ts b/src/compiler/commandLineParser.ts index be507f626d4..a3065bd7a4b 100644 --- a/src/compiler/commandLineParser.ts +++ b/src/compiler/commandLineParser.ts @@ -103,6 +103,10 @@ module ts { name: "noResolve", type: "boolean", }, + { + name: "skipDefaultLibCheck", + type: "boolean", + }, { name: "out", type: "string", @@ -349,7 +353,7 @@ module ts { return { options: getCompilerOptions(), - fileNames: getFiles(), + fileNames: getFileNames(), errors }; @@ -395,23 +399,24 @@ module ts { return options; } - function getFiles(): string[] { - var files: string[] = []; + function getFileNames(): string[] { + var fileNames: string[] = []; if (hasProperty(json, "files")) { if (json["files"] instanceof Array) { - var files = map(json["files"], s => combinePaths(basePath, s)); + fileNames = map(json["files"], s => combinePaths(basePath, s)); } } else { - var sysFiles = host.readDirectory(basePath, ".ts"); + var exclude = json["exclude"] instanceof Array ? map(json["exclude"], normalizeSlashes) : undefined; + var sysFiles = host.readDirectory(basePath, ".ts", exclude); for (var i = 0; i < sysFiles.length; i++) { var name = sysFiles[i]; if (!fileExtensionIs(name, ".d.ts") || !contains(sysFiles, name.substr(0, name.length - 5) + ".ts")) { - files.push(name); + fileNames.push(name); } } } - return files; + return fileNames; } } } diff --git a/src/compiler/core.ts b/src/compiler/core.ts index 281bfa36ece..dde1e3d6b57 100644 --- a/src/compiler/core.ts +++ b/src/compiler/core.ts @@ -15,6 +15,42 @@ module ts { True = -1 } + export function createFileMap(getCanonicalFileName: (fileName: string) => string): FileMap { + let files: Map = {}; + return { + get, + set, + contains, + remove, + forEachValue: forEachValueInMap + } + + function set(fileName: string, value: T) { + files[normalizeKey(fileName)] = value; + } + + function get(fileName: string) { + return files[normalizeKey(fileName)]; + } + + function contains(fileName: string) { + return hasProperty(files, normalizeKey(fileName)); + } + + function remove (fileName: string) { + let key = normalizeKey(fileName); + delete files[key]; + } + + function forEachValueInMap(f: (value: T) => void) { + forEachValue(files, f); + } + + function normalizeKey(key: string) { + return getCanonicalFileName(normalizeSlashes(key)); + } + } + export const enum Comparison { LessThan = -1, EqualTo = 0, diff --git a/src/compiler/diagnosticInformationMap.generated.ts b/src/compiler/diagnosticInformationMap.generated.ts index 51a955ea59c..0c8be2d3c54 100644 --- a/src/compiler/diagnosticInformationMap.generated.ts +++ b/src/compiler/diagnosticInformationMap.generated.ts @@ -536,7 +536,7 @@ module ts { Object_literal_s_property_0_implicitly_has_an_1_type: { code: 7018, category: DiagnosticCategory.Error, key: "Object literal's property '{0}' implicitly has an '{1}' type." }, Rest_parameter_0_implicitly_has_an_any_type: { code: 7019, category: DiagnosticCategory.Error, key: "Rest parameter '{0}' implicitly has an 'any[]' type." }, Call_signature_which_lacks_return_type_annotation_implicitly_has_an_any_return_type: { code: 7020, category: DiagnosticCategory.Error, key: "Call signature, which lacks return-type annotation, implicitly has an 'any' return type." }, - _0_implicitly_has_type_any_because_it_is_does_not_have_a_type_annotation_and_is_referenced_directly_or_indirectly_in_its_own_initializer: { code: 7022, category: DiagnosticCategory.Error, key: "'{0}' implicitly has type 'any' because it is does not have a type annotation and is referenced directly or indirectly in its own initializer." }, + _0_implicitly_has_type_any_because_it_does_not_have_a_type_annotation_and_is_referenced_directly_or_indirectly_in_its_own_initializer: { code: 7022, category: DiagnosticCategory.Error, key: "'{0}' implicitly has type 'any' because it does not have a type annotation and is referenced directly or indirectly in its own initializer." }, _0_implicitly_has_return_type_any_because_it_does_not_have_a_return_type_annotation_and_is_referenced_directly_or_indirectly_in_one_of_its_return_expressions: { code: 7023, category: DiagnosticCategory.Error, key: "'{0}' implicitly has return type 'any' because it does not have a return type annotation and is referenced directly or indirectly in one of its return expressions." }, Function_implicitly_has_return_type_any_because_it_does_not_have_a_return_type_annotation_and_is_referenced_directly_or_indirectly_in_one_of_its_return_expressions: { code: 7024, category: DiagnosticCategory.Error, key: "Function implicitly has return type 'any' because it does not have a return type annotation and is referenced directly or indirectly in one of its return expressions." }, Generator_implicitly_has_type_0_because_it_does_not_yield_any_values_Consider_supplying_a_return_type: { code: 7025, category: DiagnosticCategory.Error, key: "Generator implicitly has type '{0}' because it does not yield any values. Consider supplying a return type." }, diff --git a/src/compiler/diagnosticMessages.json b/src/compiler/diagnosticMessages.json index 567ccd86303..08273011745 100644 --- a/src/compiler/diagnosticMessages.json +++ b/src/compiler/diagnosticMessages.json @@ -2136,7 +2136,7 @@ "category": "Error", "code": 7020 }, - "'{0}' implicitly has type 'any' because it is does not have a type annotation and is referenced directly or indirectly in its own initializer.": { + "'{0}' implicitly has type 'any' because it does not have a type annotation and is referenced directly or indirectly in its own initializer.": { "category": "Error", "code": 7022 }, diff --git a/src/compiler/emitter.ts b/src/compiler/emitter.ts index d0d65aec2fb..ddccfad3108 100644 --- a/src/compiler/emitter.ts +++ b/src/compiler/emitter.ts @@ -1646,6 +1646,12 @@ var __param = (this && this.__param) || function (paramIndex, decorator) { } function parenthesizeForAccess(expr: Expression): LeftHandSideExpression { + // When diagnosing whether the expression needs parentheses, the decision should be based + // on the innermost expression in a chain of nested type assertions. + while (expr.kind === SyntaxKind.TypeAssertionExpression) { + expr = (expr).expression; + } + // isLeftHandSideExpression is almost the correct criterion for when it is not necessary // to parenthesize the expression before a dot. The known exceptions are: // @@ -1654,7 +1660,10 @@ var __param = (this && this.__param) || function (paramIndex, decorator) { // NumberLiteral // 1.x -> not the same as (1).x // - if (isLeftHandSideExpression(expr) && expr.kind !== SyntaxKind.NewExpression && expr.kind !== SyntaxKind.NumericLiteral) { + if (isLeftHandSideExpression(expr) && + expr.kind !== SyntaxKind.NewExpression && + expr.kind !== SyntaxKind.NumericLiteral) { + return expr; } let node = createSynthesizedNode(SyntaxKind.ParenthesizedExpression); @@ -1941,7 +1950,10 @@ var __param = (this && this.__param) || function (paramIndex, decorator) { } function emitParenExpression(node: ParenthesizedExpression) { - if (!node.parent || node.parent.kind !== SyntaxKind.ArrowFunction) { + // If the node is synthesized, it means the emitter put the parentheses there, + // not the user. If we didn't want them, the emitter would not have put them + // there. + if (!nodeIsSynthesized(node) && node.parent.kind !== SyntaxKind.ArrowFunction) { if (node.expression.kind === SyntaxKind.TypeAssertionExpression) { let operand = (node.expression).expression; @@ -4491,7 +4503,7 @@ var __param = (this && this.__param) || function (paramIndex, decorator) { emitDeclarationName(node); write(`", `); emitDeclarationName(node); - write(")"); + write(");"); } emitExportMemberAssignments(node.name); } @@ -4612,7 +4624,7 @@ var __param = (this && this.__param) || function (paramIndex, decorator) { emitDeclarationName(node); write(`", `); emitDeclarationName(node); - write(")"); + write(");"); } emitExportMemberAssignments(node.name); } @@ -5527,7 +5539,11 @@ var __param = (this && this.__param) || function (paramIndex, decorator) { Debug.assert(!exportFunctionForFile); // make sure that name of 'exports' function does not conflict with existing identifiers exportFunctionForFile = makeUniqueName("exports"); - write("System.register(["); + write("System.register("); + if (node.moduleName) { + write(`"${node.moduleName}", `); + } + write("[") for (let i = 0; i < externalImports.length; ++i) { let text = getExternalModuleNameText(externalImports[i]); if (i !== 0) { @@ -5613,8 +5629,8 @@ var __param = (this && this.__param) || function (paramIndex, decorator) { writeLine(); write("define("); - if (node.amdModuleName) { - write("\"" + node.amdModuleName + "\", "); + if (node.moduleName) { + write("\"" + node.moduleName + "\", "); } emitAMDDependencies(node, /*includeNonAmdDependencies*/ true); write(") {"); diff --git a/src/compiler/parser.ts b/src/compiler/parser.ts index 86c7ee98a06..a1347b0dcec 100644 --- a/src/compiler/parser.ts +++ b/src/compiler/parser.ts @@ -1819,7 +1819,7 @@ module ts { if (matchesPattern) { // Report that we need an identifier. However, report it right after the dot, // and not on the next token. This is because the next token might actually - // be an identifier and the error woudl be quite confusing. + // be an identifier and the error would be quite confusing. return createMissingNode(SyntaxKind.Identifier, /*reportAtCurrentToken*/ true, Diagnostics.Identifier_expected); } } @@ -2697,7 +2697,7 @@ module ts { function nextTokenIsIdentifierOnSameLine() { nextToken(); - return !scanner.hasPrecedingLineBreak() && isIdentifier() + return !scanner.hasPrecedingLineBreak() && isIdentifier(); } function parseYieldExpression(): YieldExpression { @@ -3820,14 +3820,42 @@ module ts { case SyntaxKind.ClassKeyword: case SyntaxKind.EnumKeyword: return StatementFlags.Statement; + + // 'declare', 'module', 'namespace', 'interface'* and 'type' are all legal JavaScript identifiers; + // however, an identifier cannot be followed by another identifier on the same line. This is what we + // count on to parse out the respective declarations. For instance, we exploit this to say that + // + // namespace n + // + // can be none other than the beginning of a namespace declaration, but need to respect that JavaScript sees + // + // namespace + // n + // + // as the identifier 'namespace' on one line followed by the identifier 'n' on another. + // We need to look one token ahead to see if it permissible to try parsing a declaration. + // + // *Note*: 'interface' is actually a strict mode reserved word. So while + // + // "use strict" + // interface + // I {} + // + // could be legal, it would add complexity for very little gain. case SyntaxKind.InterfaceKeyword: case SyntaxKind.TypeKeyword: - nextToken(); - return isIdentifierOrKeyword() ? StatementFlags.Statement : StatementFlags.None; + return nextTokenIsIdentifierOnSameLine() ? StatementFlags.Statement : StatementFlags.None; case SyntaxKind.ModuleKeyword: case SyntaxKind.NamespaceKeyword: + return nextTokenIsIdentifierOrStringLiteralOnSameLine() ? StatementFlags.ModuleElement : StatementFlags.None; + case SyntaxKind.DeclareKeyword: nextToken(); - return isIdentifierOrKeyword() || token === SyntaxKind.StringLiteral ? StatementFlags.ModuleElement : StatementFlags.None; + // ASI takes effect for this modifier. + if (scanner.hasPrecedingLineBreak()) { + return StatementFlags.None; + } + continue; + case SyntaxKind.ImportKeyword: nextToken(); return token === SyntaxKind.StringLiteral || token === SyntaxKind.AsteriskToken || @@ -3840,7 +3868,6 @@ module ts { return StatementFlags.ModuleElement; } continue; - case SyntaxKind.DeclareKeyword: case SyntaxKind.PublicKeyword: case SyntaxKind.PrivateKeyword: case SyntaxKind.ProtectedKeyword: @@ -3982,7 +4009,7 @@ module ts { case SyntaxKind.ThrowKeyword: return parseThrowStatement(); case SyntaxKind.TryKeyword: - // Include the next two for error recovery. + // Include 'catch' and 'finally' for error recovery. case SyntaxKind.CatchKeyword: case SyntaxKind.FinallyKeyword: return parseTryStatement(); @@ -3990,19 +4017,20 @@ module ts { return parseDebuggerStatement(); case SyntaxKind.AtToken: return parseDeclaration(); - case SyntaxKind.ConstKeyword: + + case SyntaxKind.InterfaceKeyword: + case SyntaxKind.TypeKeyword: + case SyntaxKind.ModuleKeyword: + case SyntaxKind.NamespaceKeyword: case SyntaxKind.DeclareKeyword: + case SyntaxKind.ConstKeyword: case SyntaxKind.EnumKeyword: case SyntaxKind.ExportKeyword: case SyntaxKind.ImportKeyword: - case SyntaxKind.InterfaceKeyword: - case SyntaxKind.ModuleKeyword: - case SyntaxKind.NamespaceKeyword: case SyntaxKind.PrivateKeyword: case SyntaxKind.ProtectedKeyword: case SyntaxKind.PublicKeyword: case SyntaxKind.StaticKeyword: - case SyntaxKind.TypeKeyword: if (getDeclarationFlags() & flags) { return parseDeclaration(); } @@ -4053,6 +4081,11 @@ module ts { } } + function nextTokenIsIdentifierOrStringLiteralOnSameLine() { + nextToken(); + return !scanner.hasPrecedingLineBreak() && (isIdentifier() || token === SyntaxKind.StringLiteral); + } + function parseFunctionBlockOrSemicolon(isGenerator: boolean, diagnosticMessage?: DiagnosticMessage): Block { if (token !== SyntaxKind.OpenBraceToken && canParseSemicolon()) { parseSemicolon(); @@ -4594,7 +4627,7 @@ module ts { function parseModuleBlock(): ModuleBlock { let node = createNode(SyntaxKind.ModuleBlock, scanner.getStartPos()); if (parseExpected(SyntaxKind.OpenBraceToken)) { - node.statements = parseList(ParsingContext.ModuleElements, /*checkForStrictMode*/false, parseModuleElement); + node.statements = parseList(ParsingContext.ModuleElements, /*checkForStrictMode*/ false, parseModuleElement); parseExpected(SyntaxKind.CloseBraceToken); } else { @@ -4906,7 +4939,7 @@ module ts { sourceFile.referencedFiles = referencedFiles; sourceFile.amdDependencies = amdDependencies; - sourceFile.amdModuleName = amdModuleName; + sourceFile.moduleName = amdModuleName; } function setExternalModuleIndicator(sourceFile: SourceFile) { diff --git a/src/compiler/program.ts b/src/compiler/program.ts index 955e24fd1de..c09b70a0c6d 100644 --- a/src/compiler/program.ts +++ b/src/compiler/program.ts @@ -10,9 +10,6 @@ module ts { /** The version of the TypeScript compiler release */ export const version = "1.5.3"; - const carriageReturnLineFeed = "\r\n"; - const lineFeed = "\n"; - export function findConfigFile(searchPath: string): string { var fileName = "tsconfig.json"; while (true) { @@ -94,10 +91,7 @@ module ts { } } - let newLine = - options.newLine === NewLineKind.CarriageReturnLineFeed ? carriageReturnLineFeed : - options.newLine === NewLineKind.LineFeed ? lineFeed : - sys.newLine; + const newLine = getNewLineCharacter(options); return { getSourceFile, @@ -149,9 +143,8 @@ module ts { export function createProgram(rootNames: string[], options: CompilerOptions, host?: CompilerHost): Program { let program: Program; let files: SourceFile[] = []; - let filesByName: Map = {}; let diagnostics = createDiagnosticCollection(); - let seenNoDefaultLib = options.noLib; + let skipDefaultLib = options.noLib; let commonSourceDirectory: string; let diagnosticsProducingTypeChecker: TypeChecker; let noDiagnosticsTypeChecker: TypeChecker; @@ -159,9 +152,11 @@ module ts { let start = new Date().getTime(); host = host || createCompilerHost(options); - forEach(rootNames, name => processRootFile(name, false)); - if (!seenNoDefaultLib) { - processRootFile(host.getDefaultLibFileName(options), true); + let filesByName = createFileMap(fileName => host.getCanonicalFileName(fileName)); + + forEach(rootNames, name => processRootFile(name, /*isDefaultLib:*/ false)); + if (!skipDefaultLib) { + processRootFile(host.getDefaultLibFileName(options), /*isDefaultLib:*/ true); } verifyCompilerOptions(); @@ -175,6 +170,7 @@ module ts { getGlobalDiagnostics, getSemanticDiagnostics, getDeclarationDiagnostics, + getCompilerOptionsDiagnostics, getTypeChecker, getDiagnosticsProducingTypeChecker, getCommonSourceDirectory: () => commonSourceDirectory, @@ -238,8 +234,7 @@ module ts { } function getSourceFile(fileName: string) { - fileName = host.getCanonicalFileName(normalizeSlashes(fileName)); - return hasProperty(filesByName, fileName) ? filesByName[fileName] : undefined; + return filesByName.get(fileName); } function getDiagnosticsHelper(sourceFile: SourceFile, getDiagnostics: (sourceFile: SourceFile) => Diagnostic[]): Diagnostic[] { @@ -291,6 +286,12 @@ module ts { } } + function getCompilerOptionsDiagnostics(): Diagnostic[] { + let allDiagnostics: Diagnostic[] = []; + addRange(allDiagnostics, diagnostics.getGlobalDiagnostics()); + return sortAndDeduplicateDiagnostics(allDiagnostics); + } + function getGlobalDiagnostics(): Diagnostic[] { let typeChecker = getDiagnosticsProducingTypeChecker(); @@ -358,19 +359,19 @@ module ts { // Get source file from normalized fileName function findSourceFile(fileName: string, isDefaultLib: boolean, refFile?: SourceFile, refStart?: number, refLength?: number): SourceFile { let canonicalName = host.getCanonicalFileName(normalizeSlashes(fileName)); - if (hasProperty(filesByName, canonicalName)) { + if (filesByName.contains(canonicalName)) { // We've already looked for this file, use cached result return getSourceFileFromCache(fileName, canonicalName, /*useAbsolutePath*/ false); } else { let normalizedAbsolutePath = getNormalizedAbsolutePath(fileName, host.getCurrentDirectory()); let canonicalAbsolutePath = host.getCanonicalFileName(normalizedAbsolutePath); - if (hasProperty(filesByName, canonicalAbsolutePath)) { + if (filesByName.contains(canonicalAbsolutePath)) { return getSourceFileFromCache(normalizedAbsolutePath, canonicalAbsolutePath, /*useAbsolutePath*/ true); } // We haven't looked for this file, do so now and cache result - let file = filesByName[canonicalName] = host.getSourceFile(fileName, options.target, hostErrorMessage => { + let file = host.getSourceFile(fileName, options.target, hostErrorMessage => { if (refFile) { diagnostics.add(createFileDiagnostic(refFile, refStart, refLength, Diagnostics.Cannot_read_file_0_Colon_1, fileName, hostErrorMessage)); @@ -379,11 +380,12 @@ module ts { diagnostics.add(createCompilerDiagnostic(Diagnostics.Cannot_read_file_0_Colon_1, fileName, hostErrorMessage)); } }); + filesByName.set(canonicalName, file); if (file) { - seenNoDefaultLib = seenNoDefaultLib || file.hasNoDefaultLib; + skipDefaultLib = skipDefaultLib || file.hasNoDefaultLib; // Set the source file for normalized absolute path - filesByName[canonicalAbsolutePath] = file; + filesByName.set(canonicalAbsolutePath, file); if (!options.noResolve) { let basePath = getDirectoryPath(fileName); @@ -391,6 +393,7 @@ module ts { processImportedModules(file, basePath); } if (isDefaultLib) { + file.isDefaultLib = true; files.unshift(file); } else { @@ -402,7 +405,7 @@ module ts { } function getSourceFileFromCache(fileName: string, canonicalName: string, useAbsolutePath: boolean): SourceFile { - let file = filesByName[canonicalName]; + let file = filesByName.get(canonicalName); if (file && host.useCaseSensitiveFileNames()) { let sourceFileName = useAbsolutePath ? getNormalizedAbsolutePath(file.fileName, host.getCurrentDirectory()) : file.fileName; if (canonicalName !== sourceFileName) { diff --git a/src/compiler/sys.ts b/src/compiler/sys.ts index 1a7d9de47a1..75e8af357bb 100644 --- a/src/compiler/sys.ts +++ b/src/compiler/sys.ts @@ -15,7 +15,7 @@ module ts { createDirectory(path: string): void; getExecutingFilePath(): string; getCurrentDirectory(): string; - readDirectory(path: string, extension?: string): string[]; + readDirectory(path: string, extension?: string, exclude?: string[]): string[]; getMemoryUsage?(): number; exit(exitCode?: number): void; } @@ -109,7 +109,11 @@ module ts { } } - function getNames(collection: any): string[] { + function getCanonicalPath(path: string): string { + return path.toLowerCase(); + } + + function getNames(collection: any): string[]{ var result: string[] = []; for (var e = new Enumerator(collection); !e.atEnd(); e.moveNext()) { result.push(e.item().Name); @@ -117,21 +121,26 @@ module ts { return result.sort(); } - function readDirectory(path: string, extension?: string): string[] { + function readDirectory(path: string, extension?: string, exclude?: string[]): string[] { var result: string[] = []; + exclude = map(exclude, s => getCanonicalPath(combinePaths(path, s))); visitDirectory(path); return result; function visitDirectory(path: string) { var folder = fso.GetFolder(path || "."); var files = getNames(folder.files); - for (let name of files) { - if (!extension || fileExtensionIs(name, extension)) { - result.push(combinePaths(path, name)); + for (let current of files) { + let name = combinePaths(path, current); + if ((!extension || fileExtensionIs(name, extension)) && !contains(exclude, getCanonicalPath(name))) { + result.push(name); } } var subfolders = getNames(folder.subfolders); for (let current of subfolders) { - visitDirectory(combinePaths(path, current)); + let name = combinePaths(path, current); + if (!contains(exclude, getCanonicalPath(name))) { + visitDirectory(name); + } } } } @@ -222,8 +231,13 @@ module ts { _fs.writeFileSync(fileName, data, "utf8"); } - function readDirectory(path: string, extension?: string): string[] { + function getCanonicalPath(path: string): string { + return useCaseSensitiveFileNames ? path.toLowerCase() : path; + } + + function readDirectory(path: string, extension?: string, exclude?: string[]): string[] { var result: string[] = []; + exclude = map(exclude, s => getCanonicalPath(combinePaths(path, s))); visitDirectory(path); return result; function visitDirectory(path: string) { @@ -231,14 +245,16 @@ module ts { var directories: string[] = []; for (let current of files) { var name = combinePaths(path, current); - var stat = _fs.statSync(name); - if (stat.isFile()) { - if (!extension || fileExtensionIs(name, extension)) { - result.push(name); + if (!contains(exclude, getCanonicalPath(name))) { + var stat = _fs.statSync(name); + if (stat.isFile()) { + if (!extension || fileExtensionIs(name, extension)) { + result.push(name); + } + } + else if (stat.isDirectory()) { + directories.push(name); } - } - else if (stat.isDirectory()) { - directories.push(name); } } for (let current of directories) { diff --git a/src/compiler/types.ts b/src/compiler/types.ts index cdcdd924b31..48bf19b93c2 100644 --- a/src/compiler/types.ts +++ b/src/compiler/types.ts @@ -3,6 +3,14 @@ module ts { [index: string]: T; } + export interface FileMap { + get(fileName: string): T; + set(fileName: string, value: T): void; + contains(fileName: string): boolean; + remove(fileName: string): void; + forEachValue(f: (v: T) => void): void; + } + export interface TextRange { pos: number; end: number; @@ -1141,7 +1149,7 @@ module ts { text: string; amdDependencies: {path: string; name: string}[]; - amdModuleName: string; + moduleName: string; referencedFiles: FileReference[]; hasNoDefaultLib: boolean; @@ -1150,7 +1158,8 @@ module ts { // The first node that causes this file to be an external module /* @internal */ externalModuleIndicator: Node; - + + /* @internal */ isDefaultLib: boolean; /* @internal */ identifiers: Map; /* @internal */ nodeCount: number; /* @internal */ identifierCount: number; @@ -1175,7 +1184,7 @@ module ts { } export interface ParseConfigHost { - readDirectory(rootDir: string, extension: string): string[]; + readDirectory(rootDir: string, extension: string, exclude: string[]): string[]; } export interface WriteFileCallback { @@ -1204,6 +1213,7 @@ module ts { getGlobalDiagnostics(): Diagnostic[]; getSemanticDiagnostics(sourceFile?: SourceFile): Diagnostic[]; getDeclarationDiagnostics(sourceFile?: SourceFile): Diagnostic[]; + /* @internal */ getCompilerOptionsDiagnostics(): Diagnostic[]; /** * Gets a type checker that can be used to semantically analyze source fils in the program. @@ -1595,14 +1605,15 @@ module ts { Tuple = 0x00002000, // Tuple Union = 0x00004000, // Union Anonymous = 0x00008000, // Anonymous - /* @internal */ - FromSignature = 0x00010000, // Created for signature assignment check - ObjectLiteral = 0x00020000, // Originates in an object literal - /* @internal */ - ContainsUndefinedOrNull = 0x00040000, // Type is or contains Undefined or Null type - /* @internal */ - ContainsObjectLiteral = 0x00080000, // Type is or contains object literal type - ESSymbol = 0x00100000, // Type of symbol primitive introduced in ES6 + Instantiated = 0x00010000, // Instantiated anonymous type + /* @internal */ + FromSignature = 0x00020000, // Created for signature assignment check + ObjectLiteral = 0x00040000, // Originates in an object literal + /* @internal */ + ContainsUndefinedOrNull = 0x00080000, // Type is or contains Undefined or Null type + /* @internal */ + ContainsObjectLiteral = 0x00100000, // Type is or contains object literal type + ESSymbol = 0x00200000, // Type of symbol primitive introduced in ES6 /* @internal */ Intrinsic = Any | String | Number | Boolean | ESSymbol | Void | Undefined | Null, @@ -1687,8 +1698,8 @@ module ts { properties: Symbol[]; // Properties callSignatures: Signature[]; // Call signatures of type constructSignatures: Signature[]; // Construct signatures of type - stringIndexType: Type; // String index type - numberIndexType: Type; // Numeric index type + stringIndexType?: Type; // String index type + numberIndexType?: Type; // Numeric index type } // Just a place to cache element types of iterables and iterators @@ -1745,7 +1756,6 @@ module ts { /* @internal */ export interface TypeMapper { (t: TypeParameter): Type; - mappings?: Map; // Type mapping cache } /* @internal */ @@ -1837,6 +1847,7 @@ module ts { experimentalDecorators?: boolean; emitDecoratorMetadata?: boolean; /* @internal */ stripInternal?: boolean; + /* @internal */ skipDefaultLibCheck?: boolean; [option: string]: string | number | boolean; } diff --git a/src/compiler/utilities.ts b/src/compiler/utilities.ts index 133be3d3d83..6c0943f22fd 100644 --- a/src/compiler/utilities.ts +++ b/src/compiler/utilities.ts @@ -1985,6 +1985,21 @@ module ts { return result; } + + const carriageReturnLineFeed = "\r\n"; + const lineFeed = "\n"; + export function getNewLineCharacter(options: CompilerOptions): string { + if (options.newLine === NewLineKind.CarriageReturnLineFeed) { + return carriageReturnLineFeed; + } + else if (options.newLine === NewLineKind.LineFeed) { + return lineFeed; + } + else if (sys) { + return sys.newLine + } + return carriageReturnLineFeed; + } } module ts { diff --git a/src/harness/harness.ts b/src/harness/harness.ts index b3791283a63..82afea4cf4d 100644 --- a/src/harness/harness.ts +++ b/src/harness/harness.ts @@ -808,9 +808,15 @@ module Harness { } } - export function createSourceFileAndAssertInvariants(fileName: string, sourceText: string, languageVersion: ts.ScriptTarget, assertInvariants = true) { + export function createSourceFileAndAssertInvariants( + fileName: string, + sourceText: string, + languageVersion: ts.ScriptTarget, + assertInvariants: boolean) { + // Only set the parent nodes if we're asserting invariants. We don't need them otherwise. var result = ts.createSourceFile(fileName, sourceText, languageVersion, /*setParentNodes:*/ assertInvariants); + if (assertInvariants) { Utils.assertInvariants(result, /*parent:*/ undefined); } @@ -821,8 +827,8 @@ module Harness { const lineFeed = "\n"; export var defaultLibFileName = 'lib.d.ts'; - export var defaultLibSourceFile = createSourceFileAndAssertInvariants(defaultLibFileName, IO.readFile(libFolder + 'lib.core.d.ts'), /*languageVersion*/ ts.ScriptTarget.Latest); - export var defaultES6LibSourceFile = createSourceFileAndAssertInvariants(defaultLibFileName, IO.readFile(libFolder + 'lib.core.es6.d.ts'), /*languageVersion*/ ts.ScriptTarget.Latest); + export var defaultLibSourceFile = createSourceFileAndAssertInvariants(defaultLibFileName, IO.readFile(libFolder + 'lib.core.d.ts'), /*languageVersion*/ ts.ScriptTarget.Latest, /*assertInvariants:*/ true); + export var defaultES6LibSourceFile = createSourceFileAndAssertInvariants(defaultLibFileName, IO.readFile(libFolder + 'lib.core.es6.d.ts'), /*languageVersion*/ ts.ScriptTarget.Latest, /*assertInvariants:*/ true); // Cache these between executions so we don't have to re-parse them for every test export var fourslashFileName = 'fourslash.ts'; @@ -832,13 +838,14 @@ module Harness { return ts.sys.useCaseSensitiveFileNames ? fileName : fileName.toLowerCase(); } - export function createCompilerHost(inputFiles: { unitName: string; content: string; }[], - writeFile: (fn: string, contents: string, writeByteOrderMark: boolean) => void, - scriptTarget: ts.ScriptTarget, - useCaseSensitiveFileNames: boolean, - // the currentDirectory is needed for rwcRunner to passed in specified current directory to compiler host - currentDirectory?: string, - newLineKind?: ts.NewLineKind): ts.CompilerHost { + export function createCompilerHost( + inputFiles: { unitName: string; content: string; }[], + writeFile: (fn: string, contents: string, writeByteOrderMark: boolean) => void, + scriptTarget: ts.ScriptTarget, + useCaseSensitiveFileNames: boolean, + // the currentDirectory is needed for rwcRunner to passed in specified current directory to compiler host + currentDirectory?: string, + newLineKind?: ts.NewLineKind): ts.CompilerHost { // Local get canonical file name function, that depends on passed in parameter for useCaseSensitiveFileNames function getCanonicalFileName(fileName: string): string { @@ -852,7 +859,7 @@ module Harness { function register(file: { unitName: string; content: string; }) { if (file.content !== undefined) { var fileName = ts.normalizePath(file.unitName); - filemap[getCanonicalFileName(fileName)] = createSourceFileAndAssertInvariants(fileName, file.content, scriptTarget); + filemap[getCanonicalFileName(fileName)] = createSourceFileAndAssertInvariants(fileName, file.content, scriptTarget, /*assertInvariants:*/ true); } }; inputFiles.forEach(register); @@ -875,7 +882,7 @@ module Harness { } else if (fn === fourslashFileName) { var tsFn = 'tests/cases/fourslash/' + fourslashFileName; - fourslashSourceFile = fourslashSourceFile || createSourceFileAndAssertInvariants(tsFn, Harness.IO.readFile(tsFn), scriptTarget); + fourslashSourceFile = fourslashSourceFile || createSourceFileAndAssertInvariants(tsFn, Harness.IO.readFile(tsFn), scriptTarget, /*assertInvariants:*/ true); return fourslashSourceFile; } else { @@ -899,7 +906,7 @@ module Harness { private compileOptions: ts.CompilerOptions; private settings: Harness.TestCaseParser.CompilerSetting[] = []; - private lastErrors: HarnessDiagnostic[]; + private lastErrors: ts.Diagnostic[]; public reset() { this.inputFiles = []; @@ -964,7 +971,8 @@ module Harness { settingsCallback(null); } - var newLine = '\r\n'; + let newLine = '\r\n'; + options.skipDefaultLibCheck = true; // Files from built\local that are requested by test "@includeBuiltFiles" to be in the context. // Treat them as library files, so include them in build, but not in baselines. @@ -1050,6 +1058,10 @@ module Harness { options.outDir = setting.value; break; + case 'skipdefaultlibcheck': + options.skipDefaultLibCheck = setting.value === "true"; + break; + case 'sourceroot': options.sourceRoot = setting.value; break; @@ -1078,10 +1090,6 @@ module Harness { } break; - case 'normalizenewline': - newLine = setting.value; - break; - case 'comments': options.removeComments = setting.value === 'false'; break; @@ -1138,17 +1146,15 @@ module Harness { var fileOutputs: GeneratedFile[] = []; var programFiles = inputFiles.concat(includeBuiltFiles).map(file => file.unitName); - var program = ts.createProgram(programFiles, options, createCompilerHost(inputFiles.concat(includeBuiltFiles).concat(otherFiles), + var compilerHost = createCompilerHost( + inputFiles.concat(includeBuiltFiles).concat(otherFiles), (fn, contents, writeByteOrderMark) => fileOutputs.push({ fileName: fn, code: contents, writeByteOrderMark: writeByteOrderMark }), - options.target, useCaseSensitiveFileNames, currentDirectory, options.newLine)); + options.target, useCaseSensitiveFileNames, currentDirectory, options.newLine); + var program = ts.createProgram(programFiles, options, compilerHost); var emitResult = program.emit(); - var errors: HarnessDiagnostic[] = []; - ts.getPreEmitDiagnostics(program).concat(emitResult.diagnostics).forEach(err => { - // TODO: new compiler formats errors after this point to add . and newlines so we'll just do it manually for now - errors.push(getMinimalDiagnostic(err)); - }); + var errors = ts.getPreEmitDiagnostics(program).concat(emitResult.diagnostics); this.lastErrors = errors; var result = new CompilerResult(fileOutputs, errors, program, ts.sys.getCurrentDirectory(), emitResult.sourceMaps); @@ -1235,70 +1241,50 @@ module Harness { return normalized; } - export function getMinimalDiagnostic(err: ts.Diagnostic): HarnessDiagnostic { - var errorLineInfo = err.file ? err.file.getLineAndCharacterOfPosition(err.start) : { line: -1, character: -1 }; - return { - fileName: err.file && err.file.fileName, - start: err.start, - end: err.start + err.length, - line: errorLineInfo.line + 1, - character: errorLineInfo.character + 1, - message: ts.flattenDiagnosticMessageText(err.messageText, ts.sys.newLine), - category: ts.DiagnosticCategory[err.category].toLowerCase(), - code: err.code - }; - } - - export function minimalDiagnosticsToString(diagnostics: HarnessDiagnostic[]) { + export function minimalDiagnosticsToString(diagnostics: ts.Diagnostic[]) { // This is basically copied from tsc.ts's reportError to replicate what tsc does var errorOutput = ""; - ts.forEach(diagnostics, diagnotic => { - if (diagnotic.fileName) { - errorOutput += diagnotic.fileName + "(" + diagnotic.line + "," + diagnotic.character + "): "; + ts.forEach(diagnostics, diagnostic => { + if (diagnostic.file) { + var lineAndCharacter = diagnostic.file.getLineAndCharacterOfPosition(diagnostic.start); + errorOutput += diagnostic.file.fileName + "(" + (lineAndCharacter.line + 1) + "," + (lineAndCharacter.character + 1) + "): "; } - errorOutput += diagnotic.category + " TS" + diagnotic.code + ": " + diagnotic.message + ts.sys.newLine; + errorOutput += ts.DiagnosticCategory[diagnostic.category].toLowerCase() + " TS" + diagnostic.code + ": " + ts.flattenDiagnosticMessageText(diagnostic.messageText, ts.sys.newLine) + ts.sys.newLine; }); return errorOutput; } - function compareDiagnostics(d1: HarnessDiagnostic, d2: HarnessDiagnostic) { - return ts.compareValues(d1.fileName, d2.fileName) || - ts.compareValues(d1.start, d2.start) || - ts.compareValues(d1.end, d2.end) || - ts.compareValues(d1.code, d2.code) || - ts.compareValues(d1.message, d2.message) || - 0; - } - - export function getErrorBaseline(inputFiles: { unitName: string; content: string }[], diagnostics: HarnessDiagnostic[]) { - diagnostics.sort(compareDiagnostics); + export function getErrorBaseline(inputFiles: { unitName: string; content: string }[], diagnostics: ts.Diagnostic[]) { + diagnostics.sort(ts.compareDiagnostics); var outputLines: string[] = []; // Count up all the errors we find so we don't miss any var totalErrorsReported = 0; - function outputErrorText(error: Harness.Compiler.HarnessDiagnostic) { - var errLines = RunnerBase.removeFullPaths(error.message) + function outputErrorText(error: ts.Diagnostic) { + var message = ts.flattenDiagnosticMessageText(error.messageText, ts.sys.newLine); + + var errLines = RunnerBase.removeFullPaths(message) .split('\n') .map(s => s.length > 0 && s.charAt(s.length - 1) === '\r' ? s.substr(0, s.length - 1) : s) .filter(s => s.length > 0) - .map(s => '!!! ' + error.category + " TS" + error.code + ": " + s); + .map(s => '!!! ' + ts.DiagnosticCategory[error.category].toLowerCase() + " TS" + error.code + ": " + s); errLines.forEach(e => outputLines.push(e)); totalErrorsReported++; } // Report global errors - var globalErrors = diagnostics.filter(err => !err.fileName); + var globalErrors = diagnostics.filter(err => !err.file); globalErrors.forEach(outputErrorText); // 'merge' the lines of each input file with any errors associated with it inputFiles.filter(f => f.content !== undefined).forEach(inputFile => { // Filter down to the errors in the file var fileErrors = diagnostics.filter(e => { - var errFn = e.fileName; - return errFn && errFn === inputFile.unitName; + var errFn = e.file; + return errFn && errFn.fileName === inputFile.unitName; }); @@ -1334,18 +1320,19 @@ module Harness { outputLines.push(' ' + line); fileErrors.forEach(err => { // Does any error start or continue on to this line? Emit squiggles - if ((err.end >= thisLineStart) && ((err.start < nextLineStart) || (lineIndex === lines.length - 1))) { + let end = ts.textSpanEnd(err); + if ((end >= thisLineStart) && ((err.start < nextLineStart) || (lineIndex === lines.length - 1))) { // How many characters from the start of this line the error starts at (could be positive or negative) var relativeOffset = err.start - thisLineStart; // How many characters of the error are on this line (might be longer than this line in reality) - var length = (err.end - err.start) - Math.max(0, thisLineStart - err.start); + var length = (end - err.start) - Math.max(0, thisLineStart - err.start); // Calculate the start of the squiggle var squiggleStart = Math.max(0, relativeOffset); // TODO/REVIEW: this doesn't work quite right in the browser if a multi file test has files whose names are just the right length relative to one another outputLines.push(' ' + line.substr(0, squiggleStart).replace(/[^\s]/g, ' ') + new Array(Math.min(length, line.length - squiggleStart) + 1).join('~')); // If the error ended here, or we're at the end of the file, emit its message - if ((lineIndex === lines.length - 1) || nextLineStart > err.end) { + if ((lineIndex === lines.length - 1) || nextLineStart > end) { // Just like above, we need to do a split on a string instead of on a regex // because the JS engine does regexes wrong @@ -1361,12 +1348,12 @@ module Harness { }); var numLibraryDiagnostics = ts.countWhere(diagnostics, diagnostic => { - return diagnostic.fileName && (isLibraryFile(diagnostic.fileName) || isBuiltFile(diagnostic.fileName)); + return diagnostic.file && (isLibraryFile(diagnostic.file.fileName) || isBuiltFile(diagnostic.file.fileName)); }); var numTest262HarnessDiagnostics = ts.countWhere(diagnostics, diagnostic => { // Count an error generated from tests262-harness folder.This should only apply for test262 - return diagnostic.fileName && diagnostic.fileName.indexOf("test262-harness") >= 0; + return diagnostic.file && diagnostic.file.fileName.indexOf("test262-harness") >= 0; }); // Verify we didn't miss any errors in total @@ -1419,17 +1406,6 @@ module Harness { //harnessCompiler.compileString(code, unitName, callback); } - export interface HarnessDiagnostic { - fileName: string; - start: number; - end: number; - line: number; - character: number; - message: string; - category: string; - code: number; - } - export interface GeneratedFile { fileName: string; code: string; @@ -1459,12 +1435,12 @@ module Harness { /** Contains the code and errors of a compilation and some helper methods to check its status. */ export class CompilerResult { public files: GeneratedFile[] = []; - public errors: HarnessDiagnostic[] = []; + public errors: ts.Diagnostic[] = []; public declFilesCode: GeneratedFile[] = []; public sourceMaps: GeneratedFile[] = []; /** @param fileResults an array of strings for the fileName and an ITextWriter with its code */ - constructor(fileResults: GeneratedFile[], errors: HarnessDiagnostic[], public program: ts.Program, + constructor(fileResults: GeneratedFile[], errors: ts.Diagnostic[], public program: ts.Program, public currentDirectoryForProgram: string, private sourceMapData: ts.SourceMapData[]) { fileResults.forEach(emittedFile => { @@ -1489,15 +1465,6 @@ module Harness { return Harness.SourceMapRecoder.getSourceMapRecord(this.sourceMapData, this.program, this.files); } } - - public isErrorAt(line: number, column: number, message: string) { - for (var i = 0; i < this.errors.length; i++) { - if ((this.errors[i].line + 1) === line && (this.errors[i].character + 1) === column && this.errors[i].message === message) - return true; - } - - return false; - } } } @@ -1527,7 +1494,8 @@ module Harness { "errortruncation", "usecasesensitivefilenames", "preserveconstenums", "includebuiltfile", "suppressimplicitanyindexerrors", "stripinternal", "isolatedmodules", "inlinesourcemap", "maproot", "sourceroot", - "inlinesources", "emitdecoratormetadata", "experimentaldecorators"]; + "inlinesources", "emitdecoratormetadata", "experimentaldecorators", + "skipdefaultlibcheck"]; function extractCompilerSettings(content: string): CompilerSetting[] { diff --git a/src/harness/projectsRunner.ts b/src/harness/projectsRunner.ts index 39221d55b29..cb454c00e6a 100644 --- a/src/harness/projectsRunner.ts +++ b/src/harness/projectsRunner.ts @@ -174,7 +174,7 @@ class ProjectRunner extends RunnerBase { else { var text = getSourceFileText(fileName); if (text !== undefined) { - sourceFile = Harness.Compiler.createSourceFileAndAssertInvariants(fileName, text, languageVersion); + sourceFile = Harness.Compiler.createSourceFileAndAssertInvariants(fileName, text, languageVersion, /*assertInvariants:*/ true); } } @@ -323,9 +323,8 @@ class ProjectRunner extends RunnerBase { sourceFile => { return { unitName: sourceFile.fileName, content: sourceFile.text }; }); - var diagnostics = ts.map(compilerResult.errors, error => Harness.Compiler.getMinimalDiagnostic(error)); - return Harness.Compiler.getErrorBaseline(inputFiles, diagnostics); + return Harness.Compiler.getErrorBaseline(inputFiles, compilerResult.errors); } var name = 'Compiling project for ' + testCase.scenario + ': testcase ' + testCaseFileName; diff --git a/src/harness/runner.ts b/src/harness/runner.ts index 37451639d75..eae4d77bb2c 100644 --- a/src/harness/runner.ts +++ b/src/harness/runner.ts @@ -38,41 +38,45 @@ var testConfigFile = (Harness.IO.fileExists(testconfig) ? Harness.IO.readFile(testconfig) : ''); if (testConfigFile !== '') { - // TODO: not sure why this is crashing mocha - //var testConfig = JSON.parse(testConfigRaw); - var testConfig = testConfigFile.match(/test:\s\['(.*)'\]/); - var options = testConfig ? [testConfig[1]] : []; - for (var i = 0; i < options.length; i++) { - switch (options[i]) { - case 'compiler': - runners.push(new CompilerBaselineRunner(CompilerTestType.Conformance)); - runners.push(new CompilerBaselineRunner(CompilerTestType.Regressions)); - runners.push(new ProjectRunner()); - break; - case 'conformance': - runners.push(new CompilerBaselineRunner(CompilerTestType.Conformance)); - break; - case 'project': - runners.push(new ProjectRunner()); - break; - case 'fourslash': - runners.push(new FourSlashRunner(FourSlashTestType.Native)); - break; - case 'fourslash-shims': - runners.push(new FourSlashRunner(FourSlashTestType.Shims)); - break; - case 'fourslash-server': - runners.push(new FourSlashRunner(FourSlashTestType.Server)); - break; - case 'fourslash-generated': - runners.push(new GeneratedFourslashRunner(FourSlashTestType.Native)); - break; - case 'rwc': - runners.push(new RWCRunner()); - break; - case 'test262': - runners.push(new Test262BaselineRunner()); - break; + var testConfig = JSON.parse(testConfigFile); + + if (testConfig.test && testConfig.test.length > 0) { + for (let option of testConfig.test) { + if (!option) { + continue; + } + ts.sys.write("Option: " + option + "\r\n"); + switch (option) { + case 'compiler': + runners.push(new CompilerBaselineRunner(CompilerTestType.Conformance)); + runners.push(new CompilerBaselineRunner(CompilerTestType.Regressions)); + runners.push(new ProjectRunner()); + break; + case 'conformance': + runners.push(new CompilerBaselineRunner(CompilerTestType.Conformance)); + break; + case 'project': + runners.push(new ProjectRunner()); + break; + case 'fourslash': + runners.push(new FourSlashRunner(FourSlashTestType.Native)); + break; + case 'fourslash-shims': + runners.push(new FourSlashRunner(FourSlashTestType.Shims)); + break; + case 'fourslash-server': + runners.push(new FourSlashRunner(FourSlashTestType.Server)); + break; + case 'fourslash-generated': + runners.push(new GeneratedFourslashRunner(FourSlashTestType.Native)); + break; + case 'rwc': + runners.push(new RWCRunner()); + break; + case 'test262': + runners.push(new Test262BaselineRunner()); + break; + } } } } diff --git a/src/lib/dom.generated.d.ts b/src/lib/dom.generated.d.ts index 5a4151c0c1c..e1f06f11009 100644 --- a/src/lib/dom.generated.d.ts +++ b/src/lib/dom.generated.d.ts @@ -7677,10 +7677,10 @@ declare var MediaQueryList: { interface MediaSource extends EventTarget { activeSourceBuffers: SourceBufferList; duration: number; - readyState: string; + readyState: number; sourceBuffers: SourceBufferList; addSourceBuffer(type: string): SourceBuffer; - endOfStream(error?: string): void; + endOfStream(error?: number): void; removeSourceBuffer(sourceBuffer: SourceBuffer): void; } @@ -8409,7 +8409,7 @@ declare var PopStateEvent: { interface Position { coords: Coordinates; - timestamp: Date; + timestamp: number; } declare var Position: { @@ -11090,9 +11090,17 @@ interface WebGLRenderingContext { stencilMaskSeparate(face: number, mask: number): void; stencilOp(fail: number, zfail: number, zpass: number): void; stencilOpSeparate(face: number, fail: number, zfail: number, zpass: number): void; + texImage2D(target: number, level: number, internalformat: number, width: number, height: number, border: number, format: number, type: number, pixels: ArrayBufferView): void; + texImage2D(target: number, level: number, internalformat: number, format: number, type: number, image: HTMLImageElement): void; + texImage2D(target: number, level: number, internalformat: number, format: number, type: number, canvas: HTMLCanvasElement): void; + texImage2D(target: number, level: number, internalformat: number, format: number, type: number, video: HTMLVideoElement): void; texImage2D(target: number, level: number, internalformat: number, format: number, type: number, pixels: ImageData): void; texParameterf(target: number, pname: number, param: number): void; texParameteri(target: number, pname: number, param: number): void; + texSubImage2D(target: number, level: number, xoffset: number, yoffset: number, width: number, height: number, format: number, type: number, pixels: ArrayBufferView): void; + texSubImage2D(target: number, level: number, xoffset: number, yoffset: number, format: number, type: number, image: HTMLImageElement): void; + texSubImage2D(target: number, level: number, xoffset: number, yoffset: number, format: number, type: number, canvas: HTMLCanvasElement): void; + texSubImage2D(target: number, level: number, xoffset: number, yoffset: number, format: number, type: number, video: HTMLVideoElement): void; texSubImage2D(target: number, level: number, xoffset: number, yoffset: number, format: number, type: number, pixels: ImageData): void; uniform1f(location: WebGLUniformLocation, x: number): void; uniform1fv(location: WebGLUniformLocation, v: any): void; @@ -12332,10 +12340,11 @@ interface DocumentEvent { createEvent(eventInterface:"AriaRequestEvent"): AriaRequestEvent; createEvent(eventInterface:"AudioProcessingEvent"): AudioProcessingEvent; createEvent(eventInterface:"BeforeUnloadEvent"): BeforeUnloadEvent; + createEvent(eventInterface:"ClipboardEvent"): ClipboardEvent; createEvent(eventInterface:"CloseEvent"): CloseEvent; createEvent(eventInterface:"CommandEvent"): CommandEvent; createEvent(eventInterface:"CompositionEvent"): CompositionEvent; - createEvent(eventInterface: "CustomEvent"): CustomEvent; + createEvent(eventInterface:"CustomEvent"): CustomEvent; createEvent(eventInterface:"DeviceMotionEvent"): DeviceMotionEvent; createEvent(eventInterface:"DeviceOrientationEvent"): DeviceOrientationEvent; createEvent(eventInterface:"DragEvent"): DragEvent; @@ -12358,8 +12367,6 @@ interface DocumentEvent { createEvent(eventInterface:"MouseEvent"): MouseEvent; createEvent(eventInterface:"MouseEvents"): MouseEvent; createEvent(eventInterface:"MouseWheelEvent"): MouseWheelEvent; - createEvent(eventInterface:"MSGestureEvent"): MSGestureEvent; - createEvent(eventInterface:"MSPointerEvent"): MSPointerEvent; createEvent(eventInterface:"MutationEvent"): MutationEvent; createEvent(eventInterface:"MutationEvents"): MutationEvent; createEvent(eventInterface:"NavigationCompletedEvent"): NavigationCompletedEvent; @@ -12971,4 +12978,4 @@ declare function addEventListener(type: "unload", listener: (ev: Event) => any, declare function addEventListener(type: "volumechange", listener: (ev: Event) => any, useCapture?: boolean): void; declare function addEventListener(type: "waiting", listener: (ev: Event) => any, useCapture?: boolean): void; declare function addEventListener(type: "wheel", listener: (ev: WheelEvent) => any, useCapture?: boolean): void; -declare function addEventListener(type: string, listener: EventListenerOrEventListenerObject, useCapture?: boolean): void; \ No newline at end of file +declare function addEventListener(type: string, listener: EventListenerOrEventListenerObject, useCapture?: boolean): void; diff --git a/src/services/services.ts b/src/services/services.ts index 400bf754a00..5f030bf320e 100644 --- a/src/services/services.ts +++ b/src/services/services.ts @@ -735,7 +735,7 @@ module ts { public endOfFileToken: Node; public amdDependencies: { name: string; path: string }[]; - public amdModuleName: string; + public moduleName: string; public referencedFiles: FileReference[]; public syntacticDiagnostics: Diagnostic[]; @@ -743,6 +743,7 @@ module ts { public parseDiagnostics: Diagnostic[]; public bindDiagnostics: Diagnostic[]; + public isDefaultLib: boolean; public hasNoDefaultLib: boolean; public externalModuleIndicator: Node; // The first node that causes this file to be an external module public nodeCount: number; @@ -960,6 +961,7 @@ module ts { log? (s: string): void; trace? (s: string): void; error? (s: string): void; + useCaseSensitiveFileNames? (): boolean; } // @@ -1632,12 +1634,12 @@ module ts { // at each language service public entry point, since we don't know when // set of scripts handled by the host changes. class HostCache { - private fileNameToEntry: Map; + private fileNameToEntry: FileMap; private _compilationSettings: CompilerOptions; - constructor(private host: LanguageServiceHost, private getCanonicalFileName: (fileName: string) => string) { + constructor(private host: LanguageServiceHost, getCanonicalFileName: (fileName: string) => string) { // script id => script index - this.fileNameToEntry = {}; + this.fileNameToEntry = createFileMap(getCanonicalFileName); // Initialize the list with the root file names let rootFileNames = host.getScriptFileNames(); @@ -1653,10 +1655,6 @@ module ts { return this._compilationSettings; } - private normalizeFileName(fileName: string): string { - return this.getCanonicalFileName(normalizeSlashes(fileName)); - } - private createEntry(fileName: string) { let entry: HostFileInformation; let scriptSnapshot = this.host.getScriptSnapshot(fileName); @@ -1668,15 +1666,16 @@ module ts { }; } - return this.fileNameToEntry[this.normalizeFileName(fileName)] = entry; + this.fileNameToEntry.set(fileName, entry); + return entry; } private getEntry(fileName: string): HostFileInformation { - return lookUp(this.fileNameToEntry, this.normalizeFileName(fileName)); + return this.fileNameToEntry.get(fileName); } private contains(fileName: string): boolean { - return hasProperty(this.fileNameToEntry, this.normalizeFileName(fileName)); + return this.fileNameToEntry.contains(fileName); } public getOrCreateEntry(fileName: string): HostFileInformation { @@ -1690,10 +1689,9 @@ module ts { public getRootFileNames(): string[] { let fileNames: string[] = []; - forEachKey(this.fileNameToEntry, key => { - let entry = this.getEntry(key); - if (entry) { - fileNames.push(entry.hostFileName); + this.fileNameToEntry.forEachValue(value => { + if (value) { + fileNames.push(value.hostFileName); } }); @@ -1765,8 +1763,10 @@ module ts { * Extra compiler options that will unconditionally be used bu this function are: * - isolatedModules = true * - allowNonTsExtensions = true + * - noLib = true + * - noResolve = true */ - export function transpile(input: string, compilerOptions?: CompilerOptions, fileName?: string, diagnostics?: Diagnostic[]): string { + export function transpile(input: string, compilerOptions?: CompilerOptions, fileName?: string, diagnostics?: Diagnostic[], moduleName?: string): string { let options = compilerOptions ? clone(compilerOptions) : getDefaultCompilerOptions(); options.isolatedModules = true; @@ -1774,15 +1774,28 @@ module ts { // Filename can be non-ts file. options.allowNonTsExtensions = true; + // We are not returning a sourceFile for lib file when asked by the program, + // so pass --noLib to avoid reporting a file not found error. + options.noLib = true; + + // We are not doing a full typecheck, we are not resolving the whole context, + // so pass --noResolve to avoid reporting missing file errors. + options.noResolve = true; + // Parse - var inputFileName = fileName || "module.ts"; - var sourceFile = createSourceFile(inputFileName, input, options.target); + let inputFileName = fileName || "module.ts"; + let sourceFile = createSourceFile(inputFileName, input, options.target); + if (moduleName) { + sourceFile.moduleName = moduleName; + } // Store syntactic diagnostics if (diagnostics && sourceFile.parseDiagnostics) { diagnostics.push(...sourceFile.parseDiagnostics); } + let newLine = getNewLineCharacter(options); + // Output let outputText: string; @@ -1797,13 +1810,13 @@ module ts { useCaseSensitiveFileNames: () => false, getCanonicalFileName: fileName => fileName, getCurrentDirectory: () => "", - getNewLine: () => (sys && sys.newLine) || "\r\n" + getNewLine: () => newLine }; var program = createProgram([inputFileName], options, compilerHost); if (diagnostics) { - diagnostics.push(...program.getGlobalDiagnostics()); + diagnostics.push(...program.getCompilerOptionsDiagnostics()); } // Emit @@ -1873,20 +1886,28 @@ module ts { return createLanguageServiceSourceFile(sourceFile.fileName, scriptSnapshot, sourceFile.languageVersion, version, /*setNodeParents:*/ true); } - export function createDocumentRegistry(): DocumentRegistry { + function createGetCanonicalFileName(useCaseSensitivefileNames: boolean): (fileName: string) => string { + return useCaseSensitivefileNames + ? ((fileName) => fileName) + : ((fileName) => fileName.toLowerCase()); + } + + + export function createDocumentRegistry(useCaseSensitiveFileNames?: boolean): DocumentRegistry { // Maps from compiler setting target (ES3, ES5, etc.) to all the cached documents we have // for those settings. - let buckets: Map> = {}; + let buckets: Map> = {}; + let getCanonicalFileName = createGetCanonicalFileName(!!useCaseSensitiveFileNames); function getKeyFromCompilationSettings(settings: CompilerOptions): string { return "_" + settings.target; // + "|" + settings.propagateEnumConstantoString() } - function getBucketForCompilationSettings(settings: CompilerOptions, createIfMissing: boolean): Map { + function getBucketForCompilationSettings(settings: CompilerOptions, createIfMissing: boolean): FileMap { let key = getKeyFromCompilationSettings(settings); let bucket = lookUp(buckets, key); if (!bucket && createIfMissing) { - buckets[key] = bucket = {}; + buckets[key] = bucket = createFileMap(getCanonicalFileName); } return bucket; } @@ -1896,7 +1917,7 @@ module ts { let entries = lookUp(buckets, name); let sourceFiles: { name: string; refCount: number; references: string[]; }[] = []; for (let i in entries) { - let entry = entries[i]; + let entry = entries.get(i); sourceFiles.push({ name: i, refCount: entry.languageServiceRefCount, @@ -1928,18 +1949,19 @@ module ts { acquiring: boolean): SourceFile { let bucket = getBucketForCompilationSettings(compilationSettings, /*createIfMissing*/ true); - let entry = lookUp(bucket, fileName); + let entry = bucket.get(fileName); if (!entry) { Debug.assert(acquiring, "How could we be trying to update a document that the registry doesn't have?"); // Have never seen this file with these settings. Create a new source file for it. let sourceFile = createLanguageServiceSourceFile(fileName, scriptSnapshot, compilationSettings.target, version, /*setNodeParents:*/ false); - bucket[fileName] = entry = { + entry = { sourceFile: sourceFile, languageServiceRefCount: 0, owners: [] }; + bucket.set(fileName, entry); } else { // We have an entry for this file. However, it may be for a different version of @@ -1967,12 +1989,12 @@ module ts { let bucket = getBucketForCompilationSettings(compilationSettings, false); Debug.assert(bucket !== undefined); - let entry = lookUp(bucket, fileName); + let entry = bucket.get(fileName); entry.languageServiceRefCount--; Debug.assert(entry.languageServiceRefCount >= 0); if (entry.languageServiceRefCount === 0) { - delete bucket[fileName]; + bucket.remove(fileName); } } @@ -2400,9 +2422,7 @@ module ts { } } - function getCanonicalFileName(fileName: string) { - return useCaseSensitivefileNames ? fileName : fileName.toLowerCase(); - } + let getCanonicalFileName = createGetCanonicalFileName(useCaseSensitivefileNames); function getValidSourceFile(fileName: string): SourceFile { fileName = normalizeSlashes(fileName); diff --git a/src/services/shims.ts b/src/services/shims.ts index d3f59737538..004393fb3b5 100644 --- a/src/services/shims.ts +++ b/src/services/shims.ts @@ -56,6 +56,7 @@ module ts { getDefaultLibFileName(options: string): string; getNewLine?(): string; getProjectVersion?(): string; + useCaseSensitiveFileNames?(): boolean; } /** Public interface of the the of a config service shim instance.*/ @@ -270,6 +271,10 @@ module ts { return this.shimHost.getProjectVersion(); } + public useCaseSensitiveFileNames(): boolean { + return this.shimHost.useCaseSensitiveFileNames ? this.shimHost.useCaseSensitiveFileNames() : false; + } + public getCompilationSettings(): CompilerOptions { var settingsJson = this.shimHost.getCompilationSettings(); if (settingsJson == null || settingsJson == "") { @@ -909,7 +914,7 @@ module ts { export class TypeScriptServicesFactory implements ShimFactory { private _shims: Shim[] = []; - private documentRegistry: DocumentRegistry = createDocumentRegistry(); + private documentRegistry: DocumentRegistry; /* * Returns script API version. @@ -920,6 +925,9 @@ module ts { public createLanguageServiceShim(host: LanguageServiceShimHost): LanguageServiceShim { try { + if (this.documentRegistry === undefined) { + this.documentRegistry = createDocumentRegistry(host.useCaseSensitiveFileNames && host.useCaseSensitiveFileNames()); + } var hostAdapter = new LanguageServiceShimHostAdapter(host); var languageService = createLanguageService(hostAdapter, this.documentRegistry); return new LanguageServiceShimObject(this, host, languageService); diff --git a/tests/baselines/reference/ArrowFunction3.errors.txt b/tests/baselines/reference/ArrowFunction3.errors.txt index b931fcb1cd8..aa5d1bfb725 100644 --- a/tests/baselines/reference/ArrowFunction3.errors.txt +++ b/tests/baselines/reference/ArrowFunction3.errors.txt @@ -1,11 +1,8 @@ -tests/cases/conformance/parser/ecmascript5/ErrorRecovery/ArrowFunctions/ArrowFunction3.ts(1,13): error TS2355: A function whose declared type is neither 'void' nor 'any' must return a value or consist of a single 'throw' statement. tests/cases/conformance/parser/ecmascript5/ErrorRecovery/ArrowFunctions/ArrowFunction3.ts(1,14): error TS1110: Type expected. -==== tests/cases/conformance/parser/ecmascript5/ErrorRecovery/ArrowFunctions/ArrowFunction3.ts (2 errors) ==== +==== tests/cases/conformance/parser/ecmascript5/ErrorRecovery/ArrowFunctions/ArrowFunction3.ts (1 errors) ==== var v = (a): => { - -!!! error TS2355: A function whose declared type is neither 'void' nor 'any' must return a value or consist of a single 'throw' statement. ~~ !!! error TS1110: Type expected. diff --git a/tests/baselines/reference/TypeGuardWithEnumUnion.types b/tests/baselines/reference/TypeGuardWithEnumUnion.types index 16d999e46f2..61cce562ba5 100644 --- a/tests/baselines/reference/TypeGuardWithEnumUnion.types +++ b/tests/baselines/reference/TypeGuardWithEnumUnion.types @@ -35,14 +35,14 @@ function f1(x: Color | string) { } function f2(x: Color | string | string[]) { ->f2 : (x: string | string[] | Color) => void ->x : string | string[] | Color +>f2 : (x: string | Color | string[]) => void +>x : string | Color | string[] >Color : Color if (typeof x === "object") { >typeof x === "object" : boolean >typeof x : string ->x : string | string[] | Color +>x : string | Color | string[] >"object" : string var y = x; @@ -55,7 +55,7 @@ function f2(x: Color | string | string[]) { if (typeof x === "number") { >typeof x === "number" : boolean >typeof x : string ->x : string | string[] | Color +>x : string | Color | string[] >"number" : string var z = x; @@ -77,7 +77,7 @@ function f2(x: Color | string | string[]) { if (typeof x === "string") { >typeof x === "string" : boolean >typeof x : string ->x : string | string[] | Color +>x : string | Color | string[] >"string" : string var a = x; @@ -89,11 +89,11 @@ function f2(x: Color | string | string[]) { } else { var b = x; ->b : string[] | Color ->x : string[] | Color +>b : Color | string[] +>x : Color | string[] var b: Color | string[]; ->b : string[] | Color +>b : Color | string[] >Color : Color } } diff --git a/tests/baselines/reference/arrayLiterals.types b/tests/baselines/reference/arrayLiterals.types index 841de336965..e103241dd0b 100644 --- a/tests/baselines/reference/arrayLiterals.types +++ b/tests/baselines/reference/arrayLiterals.types @@ -2,8 +2,8 @@ // Empty array literal with no contextual type has type Undefined[] var arr1= [[], [1], ['']]; ->arr1 : (string[] | number[])[] ->[[], [1], ['']] : (string[] | number[])[] +>arr1 : (number[] | string[])[] +>[[], [1], ['']] : (number[] | string[])[] >[] : undefined[] >[1] : number[] >1 : number @@ -11,8 +11,8 @@ var arr1= [[], [1], ['']]; >'' : string var arr2 = [[null], [1], ['']]; ->arr2 : (string[] | number[])[] ->[[null], [1], ['']] : (string[] | number[])[] +>arr2 : (number[] | string[])[] +>[[null], [1], ['']] : (number[] | string[])[] >[null] : null[] >null : null >[1] : number[] diff --git a/tests/baselines/reference/arrayLiterals3.errors.txt b/tests/baselines/reference/arrayLiterals3.errors.txt index 74cfdb165d7..36714162de0 100644 --- a/tests/baselines/reference/arrayLiterals3.errors.txt +++ b/tests/baselines/reference/arrayLiterals3.errors.txt @@ -8,8 +8,8 @@ tests/cases/conformance/expressions/arrayLiterals/arrayLiterals3.ts(17,5): error Type '() => string | number | boolean' is not assignable to type '() => number'. Type 'string | number | boolean' is not assignable to type 'number'. Type 'string' is not assignable to type 'number'. -tests/cases/conformance/expressions/arrayLiterals/arrayLiterals3.ts(32,5): error TS2322: Type '(string[] | number[])[]' is not assignable to type 'tup'. - Property '0' is missing in type '(string[] | number[])[]'. +tests/cases/conformance/expressions/arrayLiterals/arrayLiterals3.ts(32,5): error TS2322: Type '(number[] | string[])[]' is not assignable to type 'tup'. + Property '0' is missing in type '(number[] | string[])[]'. tests/cases/conformance/expressions/arrayLiterals/arrayLiterals3.ts(33,5): error TS2322: Type 'number[]' is not assignable to type '[number, number, number]'. Property '0' is missing in type 'number[]'. tests/cases/conformance/expressions/arrayLiterals/arrayLiterals3.ts(34,5): error TS2322: Type '(string | number)[]' is not assignable to type 'myArray'. @@ -68,8 +68,8 @@ tests/cases/conformance/expressions/arrayLiterals/arrayLiterals3.ts(34,5): error interface myArray2 extends Array { } var c0: tup = [...temp2]; // Error ~~ -!!! error TS2322: Type '(string[] | number[])[]' is not assignable to type 'tup'. -!!! error TS2322: Property '0' is missing in type '(string[] | number[])[]'. +!!! error TS2322: Type '(number[] | string[])[]' is not assignable to type 'tup'. +!!! error TS2322: Property '0' is missing in type '(number[] | string[])[]'. var c1: [number, number, number] = [...temp1]; // Error cannot assign number[] to [number, number, number] ~~ !!! error TS2322: Type 'number[]' is not assignable to type '[number, number, number]'. diff --git a/tests/baselines/reference/asiPreventsParsingAsAmbientExternalModule01.js b/tests/baselines/reference/asiPreventsParsingAsAmbientExternalModule01.js new file mode 100644 index 00000000000..caf90acae5f --- /dev/null +++ b/tests/baselines/reference/asiPreventsParsingAsAmbientExternalModule01.js @@ -0,0 +1,17 @@ +//// [asiPreventsParsingAsAmbientExternalModule01.ts] + +var declare: number; +var module: string; + +declare // this is the identifier 'declare' +module // this is the identifier 'module' +"my external module" // this is just a string +{ } // this is a block body + +//// [asiPreventsParsingAsAmbientExternalModule01.js] +var declare; +var module; +declare; // this is the identifier 'declare' +module; // this is the identifier 'module' +"my external module"; // this is just a string +{ } // this is a block body diff --git a/tests/baselines/reference/asiPreventsParsingAsAmbientExternalModule01.symbols b/tests/baselines/reference/asiPreventsParsingAsAmbientExternalModule01.symbols new file mode 100644 index 00000000000..c35432b7ece --- /dev/null +++ b/tests/baselines/reference/asiPreventsParsingAsAmbientExternalModule01.symbols @@ -0,0 +1,16 @@ +=== tests/cases/conformance/externalModules/asiPreventsParsingAsAmbientExternalModule01.ts === + +var declare: number; +>declare : Symbol(declare, Decl(asiPreventsParsingAsAmbientExternalModule01.ts, 1, 3)) + +var module: string; +>module : Symbol(module, Decl(asiPreventsParsingAsAmbientExternalModule01.ts, 2, 3)) + +declare // this is the identifier 'declare' +>declare : Symbol(declare, Decl(asiPreventsParsingAsAmbientExternalModule01.ts, 1, 3)) + +module // this is the identifier 'module' +>module : Symbol(module, Decl(asiPreventsParsingAsAmbientExternalModule01.ts, 2, 3)) + +"my external module" // this is just a string +{ } // this is a block body diff --git a/tests/baselines/reference/asiPreventsParsingAsAmbientExternalModule01.types b/tests/baselines/reference/asiPreventsParsingAsAmbientExternalModule01.types new file mode 100644 index 00000000000..3e6aade9a21 --- /dev/null +++ b/tests/baselines/reference/asiPreventsParsingAsAmbientExternalModule01.types @@ -0,0 +1,18 @@ +=== tests/cases/conformance/externalModules/asiPreventsParsingAsAmbientExternalModule01.ts === + +var declare: number; +>declare : number + +var module: string; +>module : string + +declare // this is the identifier 'declare' +>declare : number + +module // this is the identifier 'module' +>module : string + +"my external module" // this is just a string +>"my external module" : string + +{ } // this is a block body diff --git a/tests/baselines/reference/asiPreventsParsingAsAmbientExternalModule02.js b/tests/baselines/reference/asiPreventsParsingAsAmbientExternalModule02.js new file mode 100644 index 00000000000..20e2693ba7f --- /dev/null +++ b/tests/baselines/reference/asiPreventsParsingAsAmbientExternalModule02.js @@ -0,0 +1,22 @@ +//// [asiPreventsParsingAsAmbientExternalModule02.ts] + +var declare: number; +var module: string; + +module container { + declare // this is the identifier 'declare' + module // this is the identifier 'module' + "my external module" // this is just a string + { } // this is a block body +} + +//// [asiPreventsParsingAsAmbientExternalModule02.js] +var declare; +var module; +var container; +(function (container) { + declare; // this is the identifier 'declare' + module; // this is the identifier 'module' + "my external module"; // this is just a string + { } // this is a block body +})(container || (container = {})); diff --git a/tests/baselines/reference/asiPreventsParsingAsAmbientExternalModule02.symbols b/tests/baselines/reference/asiPreventsParsingAsAmbientExternalModule02.symbols new file mode 100644 index 00000000000..ed97f39fc11 --- /dev/null +++ b/tests/baselines/reference/asiPreventsParsingAsAmbientExternalModule02.symbols @@ -0,0 +1,20 @@ +=== tests/cases/conformance/externalModules/asiPreventsParsingAsAmbientExternalModule02.ts === + +var declare: number; +>declare : Symbol(declare, Decl(asiPreventsParsingAsAmbientExternalModule02.ts, 1, 3)) + +var module: string; +>module : Symbol(module, Decl(asiPreventsParsingAsAmbientExternalModule02.ts, 2, 3)) + +module container { +>container : Symbol(container, Decl(asiPreventsParsingAsAmbientExternalModule02.ts, 2, 19)) + + declare // this is the identifier 'declare' +>declare : Symbol(declare, Decl(asiPreventsParsingAsAmbientExternalModule02.ts, 1, 3)) + + module // this is the identifier 'module' +>module : Symbol(module, Decl(asiPreventsParsingAsAmbientExternalModule02.ts, 2, 3)) + + "my external module" // this is just a string + { } // this is a block body +} diff --git a/tests/baselines/reference/asiPreventsParsingAsAmbientExternalModule02.types b/tests/baselines/reference/asiPreventsParsingAsAmbientExternalModule02.types new file mode 100644 index 00000000000..67671853993 --- /dev/null +++ b/tests/baselines/reference/asiPreventsParsingAsAmbientExternalModule02.types @@ -0,0 +1,22 @@ +=== tests/cases/conformance/externalModules/asiPreventsParsingAsAmbientExternalModule02.ts === + +var declare: number; +>declare : number + +var module: string; +>module : string + +module container { +>container : typeof container + + declare // this is the identifier 'declare' +>declare : number + + module // this is the identifier 'module' +>module : string + + "my external module" // this is just a string +>"my external module" : string + + { } // this is a block body +} diff --git a/tests/baselines/reference/asiPreventsParsingAsInterface01.js b/tests/baselines/reference/asiPreventsParsingAsInterface01.js new file mode 100644 index 00000000000..024ad54371f --- /dev/null +++ b/tests/baselines/reference/asiPreventsParsingAsInterface01.js @@ -0,0 +1,13 @@ +//// [asiPreventsParsingAsInterface01.ts] + +var interface: number, I: string; + +interface // This should be the identifier 'interface' +I // This should be the identifier 'I' +{} // This should be a block body + +//// [asiPreventsParsingAsInterface01.js] +var interface, I; +interface; // This should be the identifier 'interface' +I; // This should be the identifier 'I' +{ } // This should be a block body diff --git a/tests/baselines/reference/asiPreventsParsingAsInterface01.symbols b/tests/baselines/reference/asiPreventsParsingAsInterface01.symbols new file mode 100644 index 00000000000..d92c13e8ceb --- /dev/null +++ b/tests/baselines/reference/asiPreventsParsingAsInterface01.symbols @@ -0,0 +1,13 @@ +=== tests/cases/conformance/interfaces/interfaceDeclarations/asiPreventsParsingAsInterface01.ts === + +var interface: number, I: string; +>interface : Symbol(interface, Decl(asiPreventsParsingAsInterface01.ts, 1, 3)) +>I : Symbol(I, Decl(asiPreventsParsingAsInterface01.ts, 1, 22)) + +interface // This should be the identifier 'interface' +>interface : Symbol(interface, Decl(asiPreventsParsingAsInterface01.ts, 1, 3)) + +I // This should be the identifier 'I' +>I : Symbol(I, Decl(asiPreventsParsingAsInterface01.ts, 1, 22)) + +{} // This should be a block body diff --git a/tests/baselines/reference/asiPreventsParsingAsInterface01.types b/tests/baselines/reference/asiPreventsParsingAsInterface01.types new file mode 100644 index 00000000000..03c1b9fc412 --- /dev/null +++ b/tests/baselines/reference/asiPreventsParsingAsInterface01.types @@ -0,0 +1,13 @@ +=== tests/cases/conformance/interfaces/interfaceDeclarations/asiPreventsParsingAsInterface01.ts === + +var interface: number, I: string; +>interface : number +>I : string + +interface // This should be the identifier 'interface' +>interface : number + +I // This should be the identifier 'I' +>I : string + +{} // This should be a block body diff --git a/tests/baselines/reference/asiPreventsParsingAsInterface02.js b/tests/baselines/reference/asiPreventsParsingAsInterface02.js new file mode 100644 index 00000000000..0ea0421550a --- /dev/null +++ b/tests/baselines/reference/asiPreventsParsingAsInterface02.js @@ -0,0 +1,14 @@ +//// [asiPreventsParsingAsInterface02.ts] + +function f(interface: number, I: string) { + interface // This should be the identifier 'interface' + I // This should be the identifier 'I' + {} // This should be a block body +} + +//// [asiPreventsParsingAsInterface02.js] +function f(interface, I) { + interface; // This should be the identifier 'interface' + I; // This should be the identifier 'I' + { } // This should be a block body +} diff --git a/tests/baselines/reference/asiPreventsParsingAsInterface02.symbols b/tests/baselines/reference/asiPreventsParsingAsInterface02.symbols new file mode 100644 index 00000000000..e1e4febe38c --- /dev/null +++ b/tests/baselines/reference/asiPreventsParsingAsInterface02.symbols @@ -0,0 +1,15 @@ +=== tests/cases/conformance/interfaces/interfaceDeclarations/asiPreventsParsingAsInterface02.ts === + +function f(interface: number, I: string) { +>f : Symbol(f, Decl(asiPreventsParsingAsInterface02.ts, 0, 0)) +>interface : Symbol(interface, Decl(asiPreventsParsingAsInterface02.ts, 1, 11)) +>I : Symbol(I, Decl(asiPreventsParsingAsInterface02.ts, 1, 29)) + + interface // This should be the identifier 'interface' +>interface : Symbol(interface, Decl(asiPreventsParsingAsInterface02.ts, 1, 11)) + + I // This should be the identifier 'I' +>I : Symbol(I, Decl(asiPreventsParsingAsInterface02.ts, 1, 29)) + + {} // This should be a block body +} diff --git a/tests/baselines/reference/asiPreventsParsingAsInterface02.types b/tests/baselines/reference/asiPreventsParsingAsInterface02.types new file mode 100644 index 00000000000..7989cc810a8 --- /dev/null +++ b/tests/baselines/reference/asiPreventsParsingAsInterface02.types @@ -0,0 +1,15 @@ +=== tests/cases/conformance/interfaces/interfaceDeclarations/asiPreventsParsingAsInterface02.ts === + +function f(interface: number, I: string) { +>f : (interface: number, I: string) => void +>interface : number +>I : string + + interface // This should be the identifier 'interface' +>interface : number + + I // This should be the identifier 'I' +>I : string + + {} // This should be a block body +} diff --git a/tests/baselines/reference/asiPreventsParsingAsInterface03.js b/tests/baselines/reference/asiPreventsParsingAsInterface03.js new file mode 100644 index 00000000000..3b3c836f7f4 --- /dev/null +++ b/tests/baselines/reference/asiPreventsParsingAsInterface03.js @@ -0,0 +1,18 @@ +//// [asiPreventsParsingAsInterface03.ts] + +var interface: number, I: string; + +namespace n { + interface // This should be the identifier 'interface' + I // This should be the identifier 'I' + {} // This should be a block body +} + +//// [asiPreventsParsingAsInterface03.js] +var interface, I; +var n; +(function (n) { + interface; // This should be the identifier 'interface' + I; // This should be the identifier 'I' + { } // This should be a block body +})(n || (n = {})); diff --git a/tests/baselines/reference/asiPreventsParsingAsInterface03.symbols b/tests/baselines/reference/asiPreventsParsingAsInterface03.symbols new file mode 100644 index 00000000000..e8c95cf1244 --- /dev/null +++ b/tests/baselines/reference/asiPreventsParsingAsInterface03.symbols @@ -0,0 +1,17 @@ +=== tests/cases/conformance/interfaces/interfaceDeclarations/asiPreventsParsingAsInterface03.ts === + +var interface: number, I: string; +>interface : Symbol(interface, Decl(asiPreventsParsingAsInterface03.ts, 1, 3)) +>I : Symbol(I, Decl(asiPreventsParsingAsInterface03.ts, 1, 22)) + +namespace n { +>n : Symbol(n, Decl(asiPreventsParsingAsInterface03.ts, 1, 33)) + + interface // This should be the identifier 'interface' +>interface : Symbol(interface, Decl(asiPreventsParsingAsInterface03.ts, 1, 3)) + + I // This should be the identifier 'I' +>I : Symbol(I, Decl(asiPreventsParsingAsInterface03.ts, 1, 22)) + + {} // This should be a block body +} diff --git a/tests/baselines/reference/asiPreventsParsingAsInterface03.types b/tests/baselines/reference/asiPreventsParsingAsInterface03.types new file mode 100644 index 00000000000..a58d502fc25 --- /dev/null +++ b/tests/baselines/reference/asiPreventsParsingAsInterface03.types @@ -0,0 +1,17 @@ +=== tests/cases/conformance/interfaces/interfaceDeclarations/asiPreventsParsingAsInterface03.ts === + +var interface: number, I: string; +>interface : number +>I : string + +namespace n { +>n : typeof n + + interface // This should be the identifier 'interface' +>interface : number + + I // This should be the identifier 'I' +>I : string + + {} // This should be a block body +} diff --git a/tests/baselines/reference/asiPreventsParsingAsInterface04.js b/tests/baselines/reference/asiPreventsParsingAsInterface04.js new file mode 100644 index 00000000000..1700636e522 --- /dev/null +++ b/tests/baselines/reference/asiPreventsParsingAsInterface04.js @@ -0,0 +1,15 @@ +//// [asiPreventsParsingAsInterface04.ts] + +var declare: boolean, interface: number, I: string; + +declare // This should be the identifier 'declare' +interface // This should be the identifier 'interface' +I // This should be the identifier 'I' +{} // This should be a block body + +//// [asiPreventsParsingAsInterface04.js] +var declare, interface, I; +declare; // This should be the identifier 'declare' +interface; // This should be the identifier 'interface' +I; // This should be the identifier 'I' +{ } // This should be a block body diff --git a/tests/baselines/reference/asiPreventsParsingAsInterface04.symbols b/tests/baselines/reference/asiPreventsParsingAsInterface04.symbols new file mode 100644 index 00000000000..094411ebed5 --- /dev/null +++ b/tests/baselines/reference/asiPreventsParsingAsInterface04.symbols @@ -0,0 +1,17 @@ +=== tests/cases/conformance/interfaces/interfaceDeclarations/asiPreventsParsingAsInterface04.ts === + +var declare: boolean, interface: number, I: string; +>declare : Symbol(declare, Decl(asiPreventsParsingAsInterface04.ts, 1, 3)) +>interface : Symbol(interface, Decl(asiPreventsParsingAsInterface04.ts, 1, 21)) +>I : Symbol(I, Decl(asiPreventsParsingAsInterface04.ts, 1, 40)) + +declare // This should be the identifier 'declare' +>declare : Symbol(declare, Decl(asiPreventsParsingAsInterface04.ts, 1, 3)) + +interface // This should be the identifier 'interface' +>interface : Symbol(interface, Decl(asiPreventsParsingAsInterface04.ts, 1, 21)) + +I // This should be the identifier 'I' +>I : Symbol(I, Decl(asiPreventsParsingAsInterface04.ts, 1, 40)) + +{} // This should be a block body diff --git a/tests/baselines/reference/asiPreventsParsingAsInterface04.types b/tests/baselines/reference/asiPreventsParsingAsInterface04.types new file mode 100644 index 00000000000..f6d29749ae1 --- /dev/null +++ b/tests/baselines/reference/asiPreventsParsingAsInterface04.types @@ -0,0 +1,17 @@ +=== tests/cases/conformance/interfaces/interfaceDeclarations/asiPreventsParsingAsInterface04.ts === + +var declare: boolean, interface: number, I: string; +>declare : boolean +>interface : number +>I : string + +declare // This should be the identifier 'declare' +>declare : boolean + +interface // This should be the identifier 'interface' +>interface : number + +I // This should be the identifier 'I' +>I : string + +{} // This should be a block body diff --git a/tests/baselines/reference/asiPreventsParsingAsInterface05.errors.txt b/tests/baselines/reference/asiPreventsParsingAsInterface05.errors.txt new file mode 100644 index 00000000000..e070305fdf8 --- /dev/null +++ b/tests/baselines/reference/asiPreventsParsingAsInterface05.errors.txt @@ -0,0 +1,24 @@ +tests/cases/conformance/interfaces/interfaceDeclarations/asiPreventsParsingAsInterface05.ts(3,5): error TS1212: Identifier expected. 'interface' is a reserved word in strict mode +tests/cases/conformance/interfaces/interfaceDeclarations/asiPreventsParsingAsInterface05.ts(10,1): error TS1212: Identifier expected. 'interface' is a reserved word in strict mode +tests/cases/conformance/interfaces/interfaceDeclarations/asiPreventsParsingAsInterface05.ts(11,1): error TS2304: Cannot find name 'I'. + + +==== tests/cases/conformance/interfaces/interfaceDeclarations/asiPreventsParsingAsInterface05.ts (3 errors) ==== + "use strict" + + var interface: number; + ~~~~~~~~~ +!!! error TS1212: Identifier expected. 'interface' is a reserved word in strict mode + + // 'interface' is a strict mode reserved word, and so it would be permissible + // to allow 'interface' and the name of the interface to be on separate lines; + // however, this complicates things, and so it is preferable to restrict interface + // declarations such that their identifier must follow 'interface' on the same line. + + interface // This should be the identifier 'interface' + ~~~~~~~~~ +!!! error TS1212: Identifier expected. 'interface' is a reserved word in strict mode + I // This should be the identifier 'I' + ~ +!!! error TS2304: Cannot find name 'I'. + { } // This should be a block body \ No newline at end of file diff --git a/tests/baselines/reference/asiPreventsParsingAsInterface05.js b/tests/baselines/reference/asiPreventsParsingAsInterface05.js new file mode 100644 index 00000000000..85c19be4473 --- /dev/null +++ b/tests/baselines/reference/asiPreventsParsingAsInterface05.js @@ -0,0 +1,24 @@ +//// [asiPreventsParsingAsInterface05.ts] +"use strict" + +var interface: number; + +// 'interface' is a strict mode reserved word, and so it would be permissible +// to allow 'interface' and the name of the interface to be on separate lines; +// however, this complicates things, and so it is preferable to restrict interface +// declarations such that their identifier must follow 'interface' on the same line. + +interface // This should be the identifier 'interface' +I // This should be the identifier 'I' +{ } // This should be a block body + +//// [asiPreventsParsingAsInterface05.js] +"use strict"; +var interface; +// 'interface' is a strict mode reserved word, and so it would be permissible +// to allow 'interface' and the name of the interface to be on separate lines; +// however, this complicates things, and so it is preferable to restrict interface +// declarations such that their identifier must follow 'interface' on the same line. +interface; // This should be the identifier 'interface' +I; // This should be the identifier 'I' +{ } // This should be a block body diff --git a/tests/baselines/reference/asiPreventsParsingAsNamespace01.js b/tests/baselines/reference/asiPreventsParsingAsNamespace01.js new file mode 100644 index 00000000000..282d9dd1c7c --- /dev/null +++ b/tests/baselines/reference/asiPreventsParsingAsNamespace01.js @@ -0,0 +1,15 @@ +//// [asiPreventsParsingAsNamespace01.ts] + +var namespace: number; +var n: string; + +namespace // this is the identifier 'namespace' +n // this is the identifier 'n' +{ } // this is a block body + +//// [asiPreventsParsingAsNamespace01.js] +var namespace; +var n; +namespace; // this is the identifier 'namespace' +n; // this is the identifier 'n' +{ } // this is a block body diff --git a/tests/baselines/reference/asiPreventsParsingAsNamespace01.symbols b/tests/baselines/reference/asiPreventsParsingAsNamespace01.symbols new file mode 100644 index 00000000000..b196d733352 --- /dev/null +++ b/tests/baselines/reference/asiPreventsParsingAsNamespace01.symbols @@ -0,0 +1,15 @@ +=== tests/cases/conformance/internalModules/moduleDeclarations/asiPreventsParsingAsNamespace01.ts === + +var namespace: number; +>namespace : Symbol(namespace, Decl(asiPreventsParsingAsNamespace01.ts, 1, 3)) + +var n: string; +>n : Symbol(n, Decl(asiPreventsParsingAsNamespace01.ts, 2, 3)) + +namespace // this is the identifier 'namespace' +>namespace : Symbol(namespace, Decl(asiPreventsParsingAsNamespace01.ts, 1, 3)) + +n // this is the identifier 'n' +>n : Symbol(n, Decl(asiPreventsParsingAsNamespace01.ts, 2, 3)) + +{ } // this is a block body diff --git a/tests/baselines/reference/asiPreventsParsingAsNamespace01.types b/tests/baselines/reference/asiPreventsParsingAsNamespace01.types new file mode 100644 index 00000000000..417a96dbed4 --- /dev/null +++ b/tests/baselines/reference/asiPreventsParsingAsNamespace01.types @@ -0,0 +1,15 @@ +=== tests/cases/conformance/internalModules/moduleDeclarations/asiPreventsParsingAsNamespace01.ts === + +var namespace: number; +>namespace : number + +var n: string; +>n : string + +namespace // this is the identifier 'namespace' +>namespace : number + +n // this is the identifier 'n' +>n : string + +{ } // this is a block body diff --git a/tests/baselines/reference/asiPreventsParsingAsNamespace02.js b/tests/baselines/reference/asiPreventsParsingAsNamespace02.js new file mode 100644 index 00000000000..514a026dc78 --- /dev/null +++ b/tests/baselines/reference/asiPreventsParsingAsNamespace02.js @@ -0,0 +1,15 @@ +//// [asiPreventsParsingAsNamespace02.ts] + +var module: number; +var m: string; + +module // this is the identifier 'namespace' +m // this is the identifier 'm' +{ } // this is a block body + +//// [asiPreventsParsingAsNamespace02.js] +var module; +var m; +module; // this is the identifier 'namespace' +m; // this is the identifier 'm' +{ } // this is a block body diff --git a/tests/baselines/reference/asiPreventsParsingAsNamespace02.symbols b/tests/baselines/reference/asiPreventsParsingAsNamespace02.symbols new file mode 100644 index 00000000000..a3bb37c73bc --- /dev/null +++ b/tests/baselines/reference/asiPreventsParsingAsNamespace02.symbols @@ -0,0 +1,15 @@ +=== tests/cases/conformance/internalModules/moduleDeclarations/asiPreventsParsingAsNamespace02.ts === + +var module: number; +>module : Symbol(module, Decl(asiPreventsParsingAsNamespace02.ts, 1, 3)) + +var m: string; +>m : Symbol(m, Decl(asiPreventsParsingAsNamespace02.ts, 2, 3)) + +module // this is the identifier 'namespace' +>module : Symbol(module, Decl(asiPreventsParsingAsNamespace02.ts, 1, 3)) + +m // this is the identifier 'm' +>m : Symbol(m, Decl(asiPreventsParsingAsNamespace02.ts, 2, 3)) + +{ } // this is a block body diff --git a/tests/baselines/reference/asiPreventsParsingAsNamespace02.types b/tests/baselines/reference/asiPreventsParsingAsNamespace02.types new file mode 100644 index 00000000000..e9e1433be7a --- /dev/null +++ b/tests/baselines/reference/asiPreventsParsingAsNamespace02.types @@ -0,0 +1,15 @@ +=== tests/cases/conformance/internalModules/moduleDeclarations/asiPreventsParsingAsNamespace02.ts === + +var module: number; +>module : number + +var m: string; +>m : string + +module // this is the identifier 'namespace' +>module : number + +m // this is the identifier 'm' +>m : string + +{ } // this is a block body diff --git a/tests/baselines/reference/asiPreventsParsingAsNamespace03.js b/tests/baselines/reference/asiPreventsParsingAsNamespace03.js new file mode 100644 index 00000000000..3c27694f5ce --- /dev/null +++ b/tests/baselines/reference/asiPreventsParsingAsNamespace03.js @@ -0,0 +1,20 @@ +//// [asiPreventsParsingAsNamespace03.ts] + +var namespace: number; +var n: string; + +namespace container { + namespace // this is the identifier 'namespace' + n // this is the identifier 'n' + { } // this is a block body +} + +//// [asiPreventsParsingAsNamespace03.js] +var namespace; +var n; +var container; +(function (container) { + namespace; // this is the identifier 'namespace' + n; // this is the identifier 'n' + { } // this is a block body +})(container || (container = {})); diff --git a/tests/baselines/reference/asiPreventsParsingAsNamespace03.symbols b/tests/baselines/reference/asiPreventsParsingAsNamespace03.symbols new file mode 100644 index 00000000000..e77d012a1bf --- /dev/null +++ b/tests/baselines/reference/asiPreventsParsingAsNamespace03.symbols @@ -0,0 +1,19 @@ +=== tests/cases/conformance/internalModules/moduleDeclarations/asiPreventsParsingAsNamespace03.ts === + +var namespace: number; +>namespace : Symbol(namespace, Decl(asiPreventsParsingAsNamespace03.ts, 1, 3)) + +var n: string; +>n : Symbol(n, Decl(asiPreventsParsingAsNamespace03.ts, 2, 3)) + +namespace container { +>container : Symbol(container, Decl(asiPreventsParsingAsNamespace03.ts, 2, 14)) + + namespace // this is the identifier 'namespace' +>namespace : Symbol(namespace, Decl(asiPreventsParsingAsNamespace03.ts, 1, 3)) + + n // this is the identifier 'n' +>n : Symbol(n, Decl(asiPreventsParsingAsNamespace03.ts, 2, 3)) + + { } // this is a block body +} diff --git a/tests/baselines/reference/asiPreventsParsingAsNamespace03.types b/tests/baselines/reference/asiPreventsParsingAsNamespace03.types new file mode 100644 index 00000000000..f119a789e11 --- /dev/null +++ b/tests/baselines/reference/asiPreventsParsingAsNamespace03.types @@ -0,0 +1,19 @@ +=== tests/cases/conformance/internalModules/moduleDeclarations/asiPreventsParsingAsNamespace03.ts === + +var namespace: number; +>namespace : number + +var n: string; +>n : string + +namespace container { +>container : typeof container + + namespace // this is the identifier 'namespace' +>namespace : number + + n // this is the identifier 'n' +>n : string + + { } // this is a block body +} diff --git a/tests/baselines/reference/asiPreventsParsingAsNamespace04.js b/tests/baselines/reference/asiPreventsParsingAsNamespace04.js new file mode 100644 index 00000000000..704c8893e76 --- /dev/null +++ b/tests/baselines/reference/asiPreventsParsingAsNamespace04.js @@ -0,0 +1,8 @@ +//// [asiPreventsParsingAsNamespace04.ts] + +let module = 10; +module in {} + +//// [asiPreventsParsingAsNamespace04.js] +var module = 10; +module in {}; diff --git a/tests/baselines/reference/asiPreventsParsingAsNamespace04.symbols b/tests/baselines/reference/asiPreventsParsingAsNamespace04.symbols new file mode 100644 index 00000000000..60d1f8fcc48 --- /dev/null +++ b/tests/baselines/reference/asiPreventsParsingAsNamespace04.symbols @@ -0,0 +1,8 @@ +=== tests/cases/conformance/internalModules/moduleDeclarations/asiPreventsParsingAsNamespace04.ts === + +let module = 10; +>module : Symbol(module, Decl(asiPreventsParsingAsNamespace04.ts, 1, 3)) + +module in {} +>module : Symbol(module, Decl(asiPreventsParsingAsNamespace04.ts, 1, 3)) + diff --git a/tests/baselines/reference/asiPreventsParsingAsNamespace04.types b/tests/baselines/reference/asiPreventsParsingAsNamespace04.types new file mode 100644 index 00000000000..3fa2a448cf9 --- /dev/null +++ b/tests/baselines/reference/asiPreventsParsingAsNamespace04.types @@ -0,0 +1,11 @@ +=== tests/cases/conformance/internalModules/moduleDeclarations/asiPreventsParsingAsNamespace04.ts === + +let module = 10; +>module : number +>10 : number + +module in {} +>module in {} : boolean +>module : number +>{} : {} + diff --git a/tests/baselines/reference/asiPreventsParsingAsNamespace05.js b/tests/baselines/reference/asiPreventsParsingAsNamespace05.js new file mode 100644 index 00000000000..35f557328c0 --- /dev/null +++ b/tests/baselines/reference/asiPreventsParsingAsNamespace05.js @@ -0,0 +1,25 @@ +//// [asiPreventsParsingAsNamespace05.ts] + +let namespace = 10; +namespace a.b { + export let c = 20; +} + +namespace +a.b.c +{ +} + +//// [asiPreventsParsingAsNamespace05.js] +var namespace = 10; +var a; +(function (a) { + var b; + (function (b) { + b.c = 20; + })(b = a.b || (a.b = {})); +})(a || (a = {})); +namespace; +a.b.c; +{ +} diff --git a/tests/baselines/reference/asiPreventsParsingAsNamespace05.symbols b/tests/baselines/reference/asiPreventsParsingAsNamespace05.symbols new file mode 100644 index 00000000000..47f05862b0a --- /dev/null +++ b/tests/baselines/reference/asiPreventsParsingAsNamespace05.symbols @@ -0,0 +1,24 @@ +=== tests/cases/conformance/internalModules/moduleDeclarations/asiPreventsParsingAsNamespace05.ts === + +let namespace = 10; +>namespace : Symbol(namespace, Decl(asiPreventsParsingAsNamespace05.ts, 1, 3)) + +namespace a.b { +>a : Symbol(a, Decl(asiPreventsParsingAsNamespace05.ts, 1, 19)) +>b : Symbol(b, Decl(asiPreventsParsingAsNamespace05.ts, 2, 12)) + + export let c = 20; +>c : Symbol(c, Decl(asiPreventsParsingAsNamespace05.ts, 3, 14)) +} + +namespace +>namespace : Symbol(namespace, Decl(asiPreventsParsingAsNamespace05.ts, 1, 3)) + +a.b.c +>a.b.c : Symbol(a.b.c, Decl(asiPreventsParsingAsNamespace05.ts, 3, 14)) +>a.b : Symbol(a.b, Decl(asiPreventsParsingAsNamespace05.ts, 2, 12)) +>a : Symbol(a, Decl(asiPreventsParsingAsNamespace05.ts, 1, 19)) +>b : Symbol(a.b, Decl(asiPreventsParsingAsNamespace05.ts, 2, 12)) +>c : Symbol(a.b.c, Decl(asiPreventsParsingAsNamespace05.ts, 3, 14)) +{ +} diff --git a/tests/baselines/reference/asiPreventsParsingAsNamespace05.types b/tests/baselines/reference/asiPreventsParsingAsNamespace05.types new file mode 100644 index 00000000000..515147c1096 --- /dev/null +++ b/tests/baselines/reference/asiPreventsParsingAsNamespace05.types @@ -0,0 +1,26 @@ +=== tests/cases/conformance/internalModules/moduleDeclarations/asiPreventsParsingAsNamespace05.ts === + +let namespace = 10; +>namespace : number +>10 : number + +namespace a.b { +>a : typeof a +>b : typeof b + + export let c = 20; +>c : number +>20 : number +} + +namespace +>namespace : number + +a.b.c +>a.b.c : number +>a.b : typeof a.b +>a : typeof a +>b : typeof a.b +>c : number +{ +} diff --git a/tests/baselines/reference/asiPreventsParsingAsTypeAlias01.js b/tests/baselines/reference/asiPreventsParsingAsTypeAlias01.js new file mode 100644 index 00000000000..b05988290cb --- /dev/null +++ b/tests/baselines/reference/asiPreventsParsingAsTypeAlias01.js @@ -0,0 +1,15 @@ +//// [asiPreventsParsingAsTypeAlias01.ts] + +var type; +var string; +var Foo; + +type +Foo = string; + +//// [asiPreventsParsingAsTypeAlias01.js] +var type; +var string; +var Foo; +type; +Foo = string; diff --git a/tests/baselines/reference/asiPreventsParsingAsTypeAlias01.symbols b/tests/baselines/reference/asiPreventsParsingAsTypeAlias01.symbols new file mode 100644 index 00000000000..fa82d53ac70 --- /dev/null +++ b/tests/baselines/reference/asiPreventsParsingAsTypeAlias01.symbols @@ -0,0 +1,18 @@ +=== tests/cases/conformance/types/typeAliases/asiPreventsParsingAsTypeAlias01.ts === + +var type; +>type : Symbol(type, Decl(asiPreventsParsingAsTypeAlias01.ts, 1, 3)) + +var string; +>string : Symbol(string, Decl(asiPreventsParsingAsTypeAlias01.ts, 2, 3)) + +var Foo; +>Foo : Symbol(Foo, Decl(asiPreventsParsingAsTypeAlias01.ts, 3, 3)) + +type +>type : Symbol(type, Decl(asiPreventsParsingAsTypeAlias01.ts, 1, 3)) + +Foo = string; +>Foo : Symbol(Foo, Decl(asiPreventsParsingAsTypeAlias01.ts, 3, 3)) +>string : Symbol(string, Decl(asiPreventsParsingAsTypeAlias01.ts, 2, 3)) + diff --git a/tests/baselines/reference/asiPreventsParsingAsTypeAlias01.types b/tests/baselines/reference/asiPreventsParsingAsTypeAlias01.types new file mode 100644 index 00000000000..7492a698e3a --- /dev/null +++ b/tests/baselines/reference/asiPreventsParsingAsTypeAlias01.types @@ -0,0 +1,19 @@ +=== tests/cases/conformance/types/typeAliases/asiPreventsParsingAsTypeAlias01.ts === + +var type; +>type : any + +var string; +>string : any + +var Foo; +>Foo : any + +type +>type : any + +Foo = string; +>Foo = string : any +>Foo : any +>string : any + diff --git a/tests/baselines/reference/asiPreventsParsingAsTypeAlias02.js b/tests/baselines/reference/asiPreventsParsingAsTypeAlias02.js new file mode 100644 index 00000000000..eae9898c8d4 --- /dev/null +++ b/tests/baselines/reference/asiPreventsParsingAsTypeAlias02.js @@ -0,0 +1,20 @@ +//// [asiPreventsParsingAsTypeAlias02.ts] + +var type; +var string; +var Foo; + +namespace container { + type + Foo = string; +} + +//// [asiPreventsParsingAsTypeAlias02.js] +var type; +var string; +var Foo; +var container; +(function (container) { + type; + Foo = string; +})(container || (container = {})); diff --git a/tests/baselines/reference/asiPreventsParsingAsTypeAlias02.symbols b/tests/baselines/reference/asiPreventsParsingAsTypeAlias02.symbols new file mode 100644 index 00000000000..4b83dba4c5d --- /dev/null +++ b/tests/baselines/reference/asiPreventsParsingAsTypeAlias02.symbols @@ -0,0 +1,21 @@ +=== tests/cases/conformance/types/typeAliases/asiPreventsParsingAsTypeAlias02.ts === + +var type; +>type : Symbol(type, Decl(asiPreventsParsingAsTypeAlias02.ts, 1, 3)) + +var string; +>string : Symbol(string, Decl(asiPreventsParsingAsTypeAlias02.ts, 2, 3)) + +var Foo; +>Foo : Symbol(Foo, Decl(asiPreventsParsingAsTypeAlias02.ts, 3, 3)) + +namespace container { +>container : Symbol(container, Decl(asiPreventsParsingAsTypeAlias02.ts, 3, 8)) + + type +>type : Symbol(type, Decl(asiPreventsParsingAsTypeAlias02.ts, 1, 3)) + + Foo = string; +>Foo : Symbol(Foo, Decl(asiPreventsParsingAsTypeAlias02.ts, 3, 3)) +>string : Symbol(string, Decl(asiPreventsParsingAsTypeAlias02.ts, 2, 3)) +} diff --git a/tests/baselines/reference/asiPreventsParsingAsTypeAlias02.types b/tests/baselines/reference/asiPreventsParsingAsTypeAlias02.types new file mode 100644 index 00000000000..1e6c7a8caf1 --- /dev/null +++ b/tests/baselines/reference/asiPreventsParsingAsTypeAlias02.types @@ -0,0 +1,22 @@ +=== tests/cases/conformance/types/typeAliases/asiPreventsParsingAsTypeAlias02.ts === + +var type; +>type : any + +var string; +>string : any + +var Foo; +>Foo : any + +namespace container { +>container : typeof container + + type +>type : any + + Foo = string; +>Foo = string : any +>Foo : any +>string : any +} diff --git a/tests/baselines/reference/computedPropertyNamesContextualType6_ES5.types b/tests/baselines/reference/computedPropertyNamesContextualType6_ES5.types index 52ff0c1001d..d6c97b5db81 100644 --- a/tests/baselines/reference/computedPropertyNamesContextualType6_ES5.types +++ b/tests/baselines/reference/computedPropertyNamesContextualType6_ES5.types @@ -17,9 +17,9 @@ declare function foo(obj: I): T >T : T foo({ ->foo({ p: "", 0: () => { }, ["hi" + "bye"]: true, [0 + 1]: 0, [+"hi"]: [0]}) : string | number | boolean | number[] | (() => void) +>foo({ p: "", 0: () => { }, ["hi" + "bye"]: true, [0 + 1]: 0, [+"hi"]: [0]}) : string | number | boolean | (() => void) | number[] >foo : (obj: I) => T ->{ p: "", 0: () => { }, ["hi" + "bye"]: true, [0 + 1]: 0, [+"hi"]: [0]} : { [x: string]: string | number | boolean | number[] | (() => void); 0: () => void; p: string; } +>{ p: "", 0: () => { }, ["hi" + "bye"]: true, [0 + 1]: 0, [+"hi"]: [0]} : { [x: string]: string | number | boolean | (() => void) | number[]; 0: () => void; p: string; } p: "", >p : string diff --git a/tests/baselines/reference/computedPropertyNamesContextualType6_ES6.types b/tests/baselines/reference/computedPropertyNamesContextualType6_ES6.types index 6998c9523cc..72a1d5ba04f 100644 --- a/tests/baselines/reference/computedPropertyNamesContextualType6_ES6.types +++ b/tests/baselines/reference/computedPropertyNamesContextualType6_ES6.types @@ -17,9 +17,9 @@ declare function foo(obj: I): T >T : T foo({ ->foo({ p: "", 0: () => { }, ["hi" + "bye"]: true, [0 + 1]: 0, [+"hi"]: [0]}) : string | number | boolean | number[] | (() => void) +>foo({ p: "", 0: () => { }, ["hi" + "bye"]: true, [0 + 1]: 0, [+"hi"]: [0]}) : string | number | boolean | (() => void) | number[] >foo : (obj: I) => T ->{ p: "", 0: () => { }, ["hi" + "bye"]: true, [0 + 1]: 0, [+"hi"]: [0]} : { [x: string]: string | number | boolean | number[] | (() => void); 0: () => void; p: string; } +>{ p: "", 0: () => { }, ["hi" + "bye"]: true, [0 + 1]: 0, [+"hi"]: [0]} : { [x: string]: string | number | boolean | (() => void) | number[]; 0: () => void; p: string; } p: "", >p : string diff --git a/tests/baselines/reference/computedPropertyNamesContextualType7_ES5.types b/tests/baselines/reference/computedPropertyNamesContextualType7_ES5.types index 1845d145966..5674f6aa393 100644 --- a/tests/baselines/reference/computedPropertyNamesContextualType7_ES5.types +++ b/tests/baselines/reference/computedPropertyNamesContextualType7_ES5.types @@ -17,9 +17,9 @@ declare function foo(obj: I): T >T : T foo({ ->foo({ p: "", 0: () => { }, ["hi" + "bye"]: true, [0 + 1]: 0, [+"hi"]: [0]}) : number | number[] | (() => void) +>foo({ p: "", 0: () => { }, ["hi" + "bye"]: true, [0 + 1]: 0, [+"hi"]: [0]}) : number | (() => void) | number[] >foo : (obj: I) => T ->{ p: "", 0: () => { }, ["hi" + "bye"]: true, [0 + 1]: 0, [+"hi"]: [0]} : { [x: number]: number | number[] | (() => void); 0: () => void; p: string; } +>{ p: "", 0: () => { }, ["hi" + "bye"]: true, [0 + 1]: 0, [+"hi"]: [0]} : { [x: number]: number | (() => void) | number[]; 0: () => void; p: string; } p: "", >p : string diff --git a/tests/baselines/reference/computedPropertyNamesContextualType7_ES6.types b/tests/baselines/reference/computedPropertyNamesContextualType7_ES6.types index 54d2afe4f61..93558c075e7 100644 --- a/tests/baselines/reference/computedPropertyNamesContextualType7_ES6.types +++ b/tests/baselines/reference/computedPropertyNamesContextualType7_ES6.types @@ -17,9 +17,9 @@ declare function foo(obj: I): T >T : T foo({ ->foo({ p: "", 0: () => { }, ["hi" + "bye"]: true, [0 + 1]: 0, [+"hi"]: [0]}) : number | number[] | (() => void) +>foo({ p: "", 0: () => { }, ["hi" + "bye"]: true, [0 + 1]: 0, [+"hi"]: [0]}) : number | (() => void) | number[] >foo : (obj: I) => T ->{ p: "", 0: () => { }, ["hi" + "bye"]: true, [0 + 1]: 0, [+"hi"]: [0]} : { [x: number]: number | number[] | (() => void); 0: () => void; p: string; } +>{ p: "", 0: () => { }, ["hi" + "bye"]: true, [0 + 1]: 0, [+"hi"]: [0]} : { [x: number]: number | (() => void) | number[]; 0: () => void; p: string; } p: "", >p : string diff --git a/tests/baselines/reference/contextualSignatureInstantiation.types b/tests/baselines/reference/contextualSignatureInstantiation.types index e7be6da51c5..49d6871804c 100644 --- a/tests/baselines/reference/contextualSignatureInstantiation.types +++ b/tests/baselines/reference/contextualSignatureInstantiation.types @@ -120,35 +120,35 @@ var b = baz(b, b, g); // Should be number | string >g : (x: T, y: T) => T var d: number[] | string[]; ->d : string[] | number[] +>d : number[] | string[] var d = foo(h); // Should be number[] | string[] ->d : string[] | number[] ->foo(h) : string[] | number[] +>d : number[] | string[] +>foo(h) : number[] | string[] >foo : (cb: (x: number, y: string) => T) => T >h : (x: T, y: U) => T[] | U[] var d = bar(1, "one", h); // Should be number[] | string[] ->d : string[] | number[] ->bar(1, "one", h) : string[] | number[] +>d : number[] | string[] +>bar(1, "one", h) : number[] | string[] >bar : (x: T, y: U, cb: (x: T, y: U) => V) => V >1 : number >"one" : string >h : (x: T, y: U) => T[] | U[] var d = bar("one", 1, h); // Should be number[] | string[] ->d : string[] | number[] ->bar("one", 1, h) : string[] | number[] +>d : number[] | string[] +>bar("one", 1, h) : number[] | string[] >bar : (x: T, y: U, cb: (x: T, y: U) => V) => V >"one" : string >1 : number >h : (x: T, y: U) => T[] | U[] var d = baz(d, d, g); // Should be number[] | string[] ->d : string[] | number[] ->baz(d, d, g) : string[] | number[] +>d : number[] | string[] +>baz(d, d, g) : number[] | string[] >baz : (x: T, y: T, cb: (x: T, y: T) => U) => U ->d : string[] | number[] ->d : string[] | number[] +>d : number[] | string[] +>d : number[] | string[] >g : (x: T, y: T) => T diff --git a/tests/baselines/reference/contextualTyping.errors.txt b/tests/baselines/reference/contextualTyping.errors.txt index f6941b7b92d..2e050777bfd 100644 --- a/tests/baselines/reference/contextualTyping.errors.txt +++ b/tests/baselines/reference/contextualTyping.errors.txt @@ -1,5 +1,11 @@ -tests/cases/compiler/contextualTyping.ts(189,18): error TS2384: Overload signatures must all be ambient or non-ambient.\ntests/cases/compiler/contextualTyping.ts(197,15): error TS2300: Duplicate identifier 'Point'.\ntests/cases/compiler/contextualTyping.ts(207,10): error TS2300: Duplicate identifier 'Point'.\ntests/cases/compiler/contextualTyping.ts(230,5): error TS2322: Type '{}' is not assignable to type 'B'. - Property 'x' is missing in type '{}'.\n\n\n==== tests/cases/compiler/contextualTyping.ts (4 errors) ==== +tests/cases/compiler/contextualTyping.ts(189,18): error TS2384: Overload signatures must all be ambient or non-ambient. +tests/cases/compiler/contextualTyping.ts(197,15): error TS2300: Duplicate identifier 'Point'. +tests/cases/compiler/contextualTyping.ts(207,10): error TS2300: Duplicate identifier 'Point'. +tests/cases/compiler/contextualTyping.ts(230,5): error TS2322: Type '{}' is not assignable to type 'B'. + Property 'x' is missing in type '{}'. + + +==== tests/cases/compiler/contextualTyping.ts (4 errors) ==== // DEFAULT INTERFACES interface IFoo { n: number; diff --git a/tests/baselines/reference/cyclicGenericTypeInstantiation.js b/tests/baselines/reference/cyclicGenericTypeInstantiation.js new file mode 100644 index 00000000000..10f52e10d89 --- /dev/null +++ b/tests/baselines/reference/cyclicGenericTypeInstantiation.js @@ -0,0 +1,37 @@ +//// [cyclicGenericTypeInstantiation.ts] +function foo() { + var z = foo(); + var y: { + y2: typeof z + }; + return y; +} + + +function bar() { + var z = bar(); + var y: { + y2: typeof z; + } + return y; +} + +var a = foo(); +var b = bar(); +a = b; + + +//// [cyclicGenericTypeInstantiation.js] +function foo() { + var z = foo(); + var y; + return y; +} +function bar() { + var z = bar(); + var y; + return y; +} +var a = foo(); +var b = bar(); +a = b; diff --git a/tests/baselines/reference/cyclicGenericTypeInstantiation.symbols b/tests/baselines/reference/cyclicGenericTypeInstantiation.symbols new file mode 100644 index 00000000000..a6566b86839 --- /dev/null +++ b/tests/baselines/reference/cyclicGenericTypeInstantiation.symbols @@ -0,0 +1,55 @@ +=== tests/cases/compiler/cyclicGenericTypeInstantiation.ts === +function foo() { +>foo : Symbol(foo, Decl(cyclicGenericTypeInstantiation.ts, 0, 0)) +>T : Symbol(T, Decl(cyclicGenericTypeInstantiation.ts, 0, 13)) + + var z = foo(); +>z : Symbol(z, Decl(cyclicGenericTypeInstantiation.ts, 1, 7)) +>foo : Symbol(foo, Decl(cyclicGenericTypeInstantiation.ts, 0, 0)) +>y : Symbol(y, Decl(cyclicGenericTypeInstantiation.ts, 2, 7)) + + var y: { +>y : Symbol(y, Decl(cyclicGenericTypeInstantiation.ts, 2, 7)) + + y2: typeof z +>y2 : Symbol(y2, Decl(cyclicGenericTypeInstantiation.ts, 2, 12)) +>z : Symbol(z, Decl(cyclicGenericTypeInstantiation.ts, 1, 7)) + + }; + return y; +>y : Symbol(y, Decl(cyclicGenericTypeInstantiation.ts, 2, 7)) +} + + +function bar() { +>bar : Symbol(bar, Decl(cyclicGenericTypeInstantiation.ts, 6, 1)) +>T : Symbol(T, Decl(cyclicGenericTypeInstantiation.ts, 9, 13)) + + var z = bar(); +>z : Symbol(z, Decl(cyclicGenericTypeInstantiation.ts, 10, 7)) +>bar : Symbol(bar, Decl(cyclicGenericTypeInstantiation.ts, 6, 1)) +>y : Symbol(y, Decl(cyclicGenericTypeInstantiation.ts, 11, 7)) + + var y: { +>y : Symbol(y, Decl(cyclicGenericTypeInstantiation.ts, 11, 7)) + + y2: typeof z; +>y2 : Symbol(y2, Decl(cyclicGenericTypeInstantiation.ts, 11, 12)) +>z : Symbol(z, Decl(cyclicGenericTypeInstantiation.ts, 10, 7)) + } + return y; +>y : Symbol(y, Decl(cyclicGenericTypeInstantiation.ts, 11, 7)) +} + +var a = foo(); +>a : Symbol(a, Decl(cyclicGenericTypeInstantiation.ts, 17, 3)) +>foo : Symbol(foo, Decl(cyclicGenericTypeInstantiation.ts, 0, 0)) + +var b = bar(); +>b : Symbol(b, Decl(cyclicGenericTypeInstantiation.ts, 18, 3)) +>bar : Symbol(bar, Decl(cyclicGenericTypeInstantiation.ts, 6, 1)) + +a = b; +>a : Symbol(a, Decl(cyclicGenericTypeInstantiation.ts, 17, 3)) +>b : Symbol(b, Decl(cyclicGenericTypeInstantiation.ts, 18, 3)) + diff --git a/tests/baselines/reference/cyclicGenericTypeInstantiation.types b/tests/baselines/reference/cyclicGenericTypeInstantiation.types new file mode 100644 index 00000000000..69b0955b22f --- /dev/null +++ b/tests/baselines/reference/cyclicGenericTypeInstantiation.types @@ -0,0 +1,60 @@ +=== tests/cases/compiler/cyclicGenericTypeInstantiation.ts === +function foo() { +>foo : () => { y2: any; } +>T : T + + var z = foo(); +>z : { y2: any; } +>foo() : { y2: any; } +>foo : () => { y2: any; } +>y : { y2: any; } + + var y: { +>y : { y2: any; } + + y2: typeof z +>y2 : { y2: any; } +>z : { y2: any; } + + }; + return y; +>y : { y2: any; } +} + + +function bar() { +>bar : () => { y2: any; } +>T : T + + var z = bar(); +>z : { y2: any; } +>bar() : { y2: any; } +>bar : () => { y2: any; } +>y : { y2: any; } + + var y: { +>y : { y2: any; } + + y2: typeof z; +>y2 : { y2: any; } +>z : { y2: any; } + } + return y; +>y : { y2: any; } +} + +var a = foo(); +>a : { y2: any; } +>foo() : { y2: any; } +>foo : () => { y2: any; } + +var b = bar(); +>b : { y2: any; } +>bar() : { y2: any; } +>bar : () => { y2: any; } + +a = b; +>a = b : { y2: any; } +>a : { y2: any; } +>b : { y2: any; } + diff --git a/tests/baselines/reference/declareIdentifierAsBeginningOfStatementExpression01.js b/tests/baselines/reference/declareIdentifierAsBeginningOfStatementExpression01.js new file mode 100644 index 00000000000..047b9b76719 --- /dev/null +++ b/tests/baselines/reference/declareIdentifierAsBeginningOfStatementExpression01.js @@ -0,0 +1,16 @@ +//// [declareIdentifierAsBeginningOfStatementExpression01.ts] +class C { +} + +var declare: any; + +declare instanceof C; + +//// [declareIdentifierAsBeginningOfStatementExpression01.js] +var C = (function () { + function C() { + } + return C; +})(); +var declare; +declare instanceof C; diff --git a/tests/baselines/reference/declareIdentifierAsBeginningOfStatementExpression01.symbols b/tests/baselines/reference/declareIdentifierAsBeginningOfStatementExpression01.symbols new file mode 100644 index 00000000000..d4ef7378b08 --- /dev/null +++ b/tests/baselines/reference/declareIdentifierAsBeginningOfStatementExpression01.symbols @@ -0,0 +1,12 @@ +=== tests/cases/compiler/declareIdentifierAsBeginningOfStatementExpression01.ts === +class C { +>C : Symbol(C, Decl(declareIdentifierAsBeginningOfStatementExpression01.ts, 0, 0)) +} + +var declare: any; +>declare : Symbol(declare, Decl(declareIdentifierAsBeginningOfStatementExpression01.ts, 3, 3)) + +declare instanceof C; +>declare : Symbol(declare, Decl(declareIdentifierAsBeginningOfStatementExpression01.ts, 3, 3)) +>C : Symbol(C, Decl(declareIdentifierAsBeginningOfStatementExpression01.ts, 0, 0)) + diff --git a/tests/baselines/reference/declareIdentifierAsBeginningOfStatementExpression01.types b/tests/baselines/reference/declareIdentifierAsBeginningOfStatementExpression01.types new file mode 100644 index 00000000000..2fad2eda164 --- /dev/null +++ b/tests/baselines/reference/declareIdentifierAsBeginningOfStatementExpression01.types @@ -0,0 +1,13 @@ +=== tests/cases/compiler/declareIdentifierAsBeginningOfStatementExpression01.ts === +class C { +>C : C +} + +var declare: any; +>declare : any + +declare instanceof C; +>declare instanceof C : boolean +>declare : any +>C : typeof C + diff --git a/tests/baselines/reference/destructuringParameterDeclaration3ES5.types b/tests/baselines/reference/destructuringParameterDeclaration3ES5.types index 64bede3e2de..d51a0e32dc8 100644 --- a/tests/baselines/reference/destructuringParameterDeclaration3ES5.types +++ b/tests/baselines/reference/destructuringParameterDeclaration3ES5.types @@ -12,7 +12,7 @@ type arrayString = Array >String : String type someArray = Array | number[]; ->someArray : number[] | String[] +>someArray : String[] | number[] >Array : T[] >String : String diff --git a/tests/baselines/reference/destructuringParameterDeclaration3ES6.types b/tests/baselines/reference/destructuringParameterDeclaration3ES6.types index aea7b2ae15a..63d5d074a8d 100644 --- a/tests/baselines/reference/destructuringParameterDeclaration3ES6.types +++ b/tests/baselines/reference/destructuringParameterDeclaration3ES6.types @@ -12,7 +12,7 @@ type arrayString = Array >String : String type someArray = Array | number[]; ->someArray : number[] | String[] +>someArray : String[] | number[] >Array : T[] >String : String diff --git a/tests/baselines/reference/destructuringTypeAssertionsES5_1.errors.txt b/tests/baselines/reference/destructuringTypeAssertionsES5_1.errors.txt new file mode 100644 index 00000000000..187c1d33f3d --- /dev/null +++ b/tests/baselines/reference/destructuringTypeAssertionsES5_1.errors.txt @@ -0,0 +1,7 @@ +tests/cases/conformance/es6/destructuring/destructuringTypeAssertionsES5_1.ts(1,18): error TS2304: Cannot find name 'foo'. + + +==== tests/cases/conformance/es6/destructuring/destructuringTypeAssertionsES5_1.ts (1 errors) ==== + var { x } = foo(); + ~~~ +!!! error TS2304: Cannot find name 'foo'. \ No newline at end of file diff --git a/tests/baselines/reference/destructuringTypeAssertionsES5_1.js b/tests/baselines/reference/destructuringTypeAssertionsES5_1.js new file mode 100644 index 00000000000..296cad051b1 --- /dev/null +++ b/tests/baselines/reference/destructuringTypeAssertionsES5_1.js @@ -0,0 +1,5 @@ +//// [destructuringTypeAssertionsES5_1.ts] +var { x } = foo(); + +//// [destructuringTypeAssertionsES5_1.js] +var x = foo().x; diff --git a/tests/baselines/reference/destructuringTypeAssertionsES5_2.errors.txt b/tests/baselines/reference/destructuringTypeAssertionsES5_2.errors.txt new file mode 100644 index 00000000000..2036653820b --- /dev/null +++ b/tests/baselines/reference/destructuringTypeAssertionsES5_2.errors.txt @@ -0,0 +1,7 @@ +tests/cases/conformance/es6/destructuring/destructuringTypeAssertionsES5_2.ts(1,19): error TS2304: Cannot find name 'foo'. + + +==== tests/cases/conformance/es6/destructuring/destructuringTypeAssertionsES5_2.ts (1 errors) ==== + var { x } = (foo()); + ~~~ +!!! error TS2304: Cannot find name 'foo'. \ No newline at end of file diff --git a/tests/baselines/reference/destructuringTypeAssertionsES5_2.js b/tests/baselines/reference/destructuringTypeAssertionsES5_2.js new file mode 100644 index 00000000000..1725b7042ec --- /dev/null +++ b/tests/baselines/reference/destructuringTypeAssertionsES5_2.js @@ -0,0 +1,5 @@ +//// [destructuringTypeAssertionsES5_2.ts] +var { x } = (foo()); + +//// [destructuringTypeAssertionsES5_2.js] +var x = foo().x; diff --git a/tests/baselines/reference/destructuringTypeAssertionsES5_3.errors.txt b/tests/baselines/reference/destructuringTypeAssertionsES5_3.errors.txt new file mode 100644 index 00000000000..a3aef8b91ea --- /dev/null +++ b/tests/baselines/reference/destructuringTypeAssertionsES5_3.errors.txt @@ -0,0 +1,7 @@ +tests/cases/conformance/es6/destructuring/destructuringTypeAssertionsES5_3.ts(1,19): error TS2304: Cannot find name 'foo'. + + +==== tests/cases/conformance/es6/destructuring/destructuringTypeAssertionsES5_3.ts (1 errors) ==== + var { x } = (foo()); + ~~~ +!!! error TS2304: Cannot find name 'foo'. \ No newline at end of file diff --git a/tests/baselines/reference/destructuringTypeAssertionsES5_3.js b/tests/baselines/reference/destructuringTypeAssertionsES5_3.js new file mode 100644 index 00000000000..1c8b8b1e5d8 --- /dev/null +++ b/tests/baselines/reference/destructuringTypeAssertionsES5_3.js @@ -0,0 +1,5 @@ +//// [destructuringTypeAssertionsES5_3.ts] +var { x } = (foo()); + +//// [destructuringTypeAssertionsES5_3.js] +var x = (foo()).x; diff --git a/tests/baselines/reference/destructuringTypeAssertionsES5_4.errors.txt b/tests/baselines/reference/destructuringTypeAssertionsES5_4.errors.txt new file mode 100644 index 00000000000..a27afe42f3c --- /dev/null +++ b/tests/baselines/reference/destructuringTypeAssertionsES5_4.errors.txt @@ -0,0 +1,7 @@ +tests/cases/conformance/es6/destructuring/destructuringTypeAssertionsES5_4.ts(1,23): error TS2304: Cannot find name 'foo'. + + +==== tests/cases/conformance/es6/destructuring/destructuringTypeAssertionsES5_4.ts (1 errors) ==== + var { x } = foo(); + ~~~ +!!! error TS2304: Cannot find name 'foo'. \ No newline at end of file diff --git a/tests/baselines/reference/destructuringTypeAssertionsES5_4.js b/tests/baselines/reference/destructuringTypeAssertionsES5_4.js new file mode 100644 index 00000000000..66a3e89c9b0 --- /dev/null +++ b/tests/baselines/reference/destructuringTypeAssertionsES5_4.js @@ -0,0 +1,5 @@ +//// [destructuringTypeAssertionsES5_4.ts] +var { x } = foo(); + +//// [destructuringTypeAssertionsES5_4.js] +var x = foo().x; diff --git a/tests/baselines/reference/destructuringTypeAssertionsES5_5.js b/tests/baselines/reference/destructuringTypeAssertionsES5_5.js new file mode 100644 index 00000000000..a51ac02af77 --- /dev/null +++ b/tests/baselines/reference/destructuringTypeAssertionsES5_5.js @@ -0,0 +1,5 @@ +//// [destructuringTypeAssertionsES5_5.ts] +var { x } = 0; + +//// [destructuringTypeAssertionsES5_5.js] +var x = (0).x; diff --git a/tests/baselines/reference/destructuringTypeAssertionsES5_5.symbols b/tests/baselines/reference/destructuringTypeAssertionsES5_5.symbols new file mode 100644 index 00000000000..d8e335f3e73 --- /dev/null +++ b/tests/baselines/reference/destructuringTypeAssertionsES5_5.symbols @@ -0,0 +1,4 @@ +=== tests/cases/conformance/es6/destructuring/destructuringTypeAssertionsES5_5.ts === +var { x } = 0; +>x : Symbol(x, Decl(destructuringTypeAssertionsES5_5.ts, 0, 5)) + diff --git a/tests/baselines/reference/destructuringTypeAssertionsES5_5.types b/tests/baselines/reference/destructuringTypeAssertionsES5_5.types new file mode 100644 index 00000000000..a7111cc4361 --- /dev/null +++ b/tests/baselines/reference/destructuringTypeAssertionsES5_5.types @@ -0,0 +1,6 @@ +=== tests/cases/conformance/es6/destructuring/destructuringTypeAssertionsES5_5.ts === +var { x } = 0; +>x : any +>0 : any +>0 : number + diff --git a/tests/baselines/reference/destructuringTypeAssertionsES5_6.errors.txt b/tests/baselines/reference/destructuringTypeAssertionsES5_6.errors.txt new file mode 100644 index 00000000000..9a27c4f47ab --- /dev/null +++ b/tests/baselines/reference/destructuringTypeAssertionsES5_6.errors.txt @@ -0,0 +1,7 @@ +tests/cases/conformance/es6/destructuring/destructuringTypeAssertionsES5_6.ts(1,22): error TS2304: Cannot find name 'Foo'. + + +==== tests/cases/conformance/es6/destructuring/destructuringTypeAssertionsES5_6.ts (1 errors) ==== + var { x } = new Foo; + ~~~ +!!! error TS2304: Cannot find name 'Foo'. \ No newline at end of file diff --git a/tests/baselines/reference/destructuringTypeAssertionsES5_6.js b/tests/baselines/reference/destructuringTypeAssertionsES5_6.js new file mode 100644 index 00000000000..01fd78f44e9 --- /dev/null +++ b/tests/baselines/reference/destructuringTypeAssertionsES5_6.js @@ -0,0 +1,5 @@ +//// [destructuringTypeAssertionsES5_6.ts] +var { x } = new Foo; + +//// [destructuringTypeAssertionsES5_6.js] +var x = (new Foo).x; diff --git a/tests/baselines/reference/destructuringTypeAssertionsES5_7.errors.txt b/tests/baselines/reference/destructuringTypeAssertionsES5_7.errors.txt new file mode 100644 index 00000000000..984f6a1dbb4 --- /dev/null +++ b/tests/baselines/reference/destructuringTypeAssertionsES5_7.errors.txt @@ -0,0 +1,7 @@ +tests/cases/conformance/es6/destructuring/destructuringTypeAssertionsES5_7.ts(1,27): error TS2304: Cannot find name 'Foo'. + + +==== tests/cases/conformance/es6/destructuring/destructuringTypeAssertionsES5_7.ts (1 errors) ==== + var { x } = new Foo; + ~~~ +!!! error TS2304: Cannot find name 'Foo'. \ No newline at end of file diff --git a/tests/baselines/reference/destructuringTypeAssertionsES5_7.js b/tests/baselines/reference/destructuringTypeAssertionsES5_7.js new file mode 100644 index 00000000000..78492eefc28 --- /dev/null +++ b/tests/baselines/reference/destructuringTypeAssertionsES5_7.js @@ -0,0 +1,5 @@ +//// [destructuringTypeAssertionsES5_7.ts] +var { x } = new Foo; + +//// [destructuringTypeAssertionsES5_7.js] +var x = (new Foo).x; diff --git a/tests/baselines/reference/for-of32.errors.txt b/tests/baselines/reference/for-of32.errors.txt index 4b139d386c0..f382ea40984 100644 --- a/tests/baselines/reference/for-of32.errors.txt +++ b/tests/baselines/reference/for-of32.errors.txt @@ -1,7 +1,7 @@ -tests/cases/conformance/es6/for-ofStatements/for-of32.ts(1,10): error TS7022: 'v' implicitly has type 'any' because it is does not have a type annotation and is referenced directly or indirectly in its own initializer. +tests/cases/conformance/es6/for-ofStatements/for-of32.ts(1,10): error TS7022: 'v' implicitly has type 'any' because it does not have a type annotation and is referenced directly or indirectly in its own initializer. ==== tests/cases/conformance/es6/for-ofStatements/for-of32.ts (1 errors) ==== for (var v of v) { } ~ -!!! error TS7022: 'v' implicitly has type 'any' because it is does not have a type annotation and is referenced directly or indirectly in its own initializer. \ No newline at end of file +!!! error TS7022: 'v' implicitly has type 'any' because it does not have a type annotation and is referenced directly or indirectly in its own initializer. \ No newline at end of file diff --git a/tests/baselines/reference/for-of33.errors.txt b/tests/baselines/reference/for-of33.errors.txt index cd2d48566ab..ff1feacd7b3 100644 --- a/tests/baselines/reference/for-of33.errors.txt +++ b/tests/baselines/reference/for-of33.errors.txt @@ -1,11 +1,11 @@ -tests/cases/conformance/es6/for-ofStatements/for-of33.ts(1,10): error TS7022: 'v' implicitly has type 'any' because it is does not have a type annotation and is referenced directly or indirectly in its own initializer. +tests/cases/conformance/es6/for-ofStatements/for-of33.ts(1,10): error TS7022: 'v' implicitly has type 'any' because it does not have a type annotation and is referenced directly or indirectly in its own initializer. tests/cases/conformance/es6/for-ofStatements/for-of33.ts(4,5): error TS7023: '[Symbol.iterator]' implicitly has return type 'any' because it does not have a return type annotation and is referenced directly or indirectly in one of its return expressions. ==== tests/cases/conformance/es6/for-ofStatements/for-of33.ts (2 errors) ==== for (var v of new StringIterator) { } ~ -!!! error TS7022: 'v' implicitly has type 'any' because it is does not have a type annotation and is referenced directly or indirectly in its own initializer. +!!! error TS7022: 'v' implicitly has type 'any' because it does not have a type annotation and is referenced directly or indirectly in its own initializer. class StringIterator { [Symbol.iterator]() { diff --git a/tests/baselines/reference/for-of34.errors.txt b/tests/baselines/reference/for-of34.errors.txt index a4f55ed29ba..c378a8f5bb8 100644 --- a/tests/baselines/reference/for-of34.errors.txt +++ b/tests/baselines/reference/for-of34.errors.txt @@ -1,11 +1,11 @@ -tests/cases/conformance/es6/for-ofStatements/for-of34.ts(1,10): error TS7022: 'v' implicitly has type 'any' because it is does not have a type annotation and is referenced directly or indirectly in its own initializer. +tests/cases/conformance/es6/for-ofStatements/for-of34.ts(1,10): error TS7022: 'v' implicitly has type 'any' because it does not have a type annotation and is referenced directly or indirectly in its own initializer. tests/cases/conformance/es6/for-ofStatements/for-of34.ts(4,5): error TS7023: 'next' implicitly has return type 'any' because it does not have a return type annotation and is referenced directly or indirectly in one of its return expressions. ==== tests/cases/conformance/es6/for-ofStatements/for-of34.ts (2 errors) ==== for (var v of new StringIterator) { } ~ -!!! error TS7022: 'v' implicitly has type 'any' because it is does not have a type annotation and is referenced directly or indirectly in its own initializer. +!!! error TS7022: 'v' implicitly has type 'any' because it does not have a type annotation and is referenced directly or indirectly in its own initializer. class StringIterator { next() { diff --git a/tests/baselines/reference/for-of35.errors.txt b/tests/baselines/reference/for-of35.errors.txt index 65529752b9b..58fb5056fd7 100644 --- a/tests/baselines/reference/for-of35.errors.txt +++ b/tests/baselines/reference/for-of35.errors.txt @@ -1,11 +1,11 @@ -tests/cases/conformance/es6/for-ofStatements/for-of35.ts(1,10): error TS7022: 'v' implicitly has type 'any' because it is does not have a type annotation and is referenced directly or indirectly in its own initializer. +tests/cases/conformance/es6/for-ofStatements/for-of35.ts(1,10): error TS7022: 'v' implicitly has type 'any' because it does not have a type annotation and is referenced directly or indirectly in its own initializer. tests/cases/conformance/es6/for-ofStatements/for-of35.ts(4,5): error TS7023: 'next' implicitly has return type 'any' because it does not have a return type annotation and is referenced directly or indirectly in one of its return expressions. ==== tests/cases/conformance/es6/for-ofStatements/for-of35.ts (2 errors) ==== for (var v of new StringIterator) { } ~ -!!! error TS7022: 'v' implicitly has type 'any' because it is does not have a type annotation and is referenced directly or indirectly in its own initializer. +!!! error TS7022: 'v' implicitly has type 'any' because it does not have a type annotation and is referenced directly or indirectly in its own initializer. class StringIterator { next() { diff --git a/tests/baselines/reference/genericRecursiveImplicitConstructorErrors3.errors.txt b/tests/baselines/reference/genericRecursiveImplicitConstructorErrors3.errors.txt index 760d1561113..1a04e356296 100644 --- a/tests/baselines/reference/genericRecursiveImplicitConstructorErrors3.errors.txt +++ b/tests/baselines/reference/genericRecursiveImplicitConstructorErrors3.errors.txt @@ -1,5 +1,4 @@ tests/cases/compiler/genericRecursiveImplicitConstructorErrors3.ts(3,66): error TS2314: Generic type 'MemberName' requires 3 type argument(s). -tests/cases/compiler/genericRecursiveImplicitConstructorErrors3.ts(3,66): error TS2355: A function whose declared type is neither 'void' nor 'any' must return a value or consist of a single 'throw' statement. tests/cases/compiler/genericRecursiveImplicitConstructorErrors3.ts(10,22): error TS2314: Generic type 'PullTypeSymbol' requires 3 type argument(s). tests/cases/compiler/genericRecursiveImplicitConstructorErrors3.ts(12,48): error TS2314: Generic type 'PullSymbol' requires 3 type argument(s). tests/cases/compiler/genericRecursiveImplicitConstructorErrors3.ts(13,31): error TS2314: Generic type 'PullTypeSymbol' requires 3 type argument(s). @@ -8,14 +7,12 @@ tests/cases/compiler/genericRecursiveImplicitConstructorErrors3.ts(18,53): error tests/cases/compiler/genericRecursiveImplicitConstructorErrors3.ts(19,22): error TS2339: Property 'isArray' does not exist on type 'PullTypeSymbol'. -==== tests/cases/compiler/genericRecursiveImplicitConstructorErrors3.ts (8 errors) ==== +==== tests/cases/compiler/genericRecursiveImplicitConstructorErrors3.ts (7 errors) ==== module TypeScript { export class MemberName { static create(arg1: any, arg2?: any, arg3?: any): MemberName { ~~~~~~~~~~ !!! error TS2314: Generic type 'MemberName' requires 3 type argument(s). - ~~~~~~~~~~ -!!! error TS2355: A function whose declared type is neither 'void' nor 'any' must return a value or consist of a single 'throw' statement. } } } diff --git a/tests/baselines/reference/heterogeneousArrayLiterals.types b/tests/baselines/reference/heterogeneousArrayLiterals.types index 81fa915ab03..ecfbf75e864 100644 --- a/tests/baselines/reference/heterogeneousArrayLiterals.types +++ b/tests/baselines/reference/heterogeneousArrayLiterals.types @@ -40,8 +40,8 @@ var f = [[], [1]]; // number[][] >1 : number var g = [[1], ['']]; // {}[] ->g : (string[] | number[])[] ->[[1], ['']] : (string[] | number[])[] +>g : (number[] | string[])[] +>[[1], ['']] : (number[] | string[])[] >[1] : number[] >1 : number >[''] : string[] diff --git a/tests/baselines/reference/implicitAnyFromCircularInference.errors.txt b/tests/baselines/reference/implicitAnyFromCircularInference.errors.txt index 8d0aaf04c03..36538aef4f3 100644 --- a/tests/baselines/reference/implicitAnyFromCircularInference.errors.txt +++ b/tests/baselines/reference/implicitAnyFromCircularInference.errors.txt @@ -7,7 +7,7 @@ tests/cases/compiler/implicitAnyFromCircularInference.ts(18,10): error TS7024: F tests/cases/compiler/implicitAnyFromCircularInference.ts(23,10): error TS7024: Function implicitly has return type 'any' because it does not have a return type annotation and is referenced directly or indirectly in one of its return expressions. tests/cases/compiler/implicitAnyFromCircularInference.ts(26,10): error TS7023: 'h' implicitly has return type 'any' because it does not have a return type annotation and is referenced directly or indirectly in one of its return expressions. tests/cases/compiler/implicitAnyFromCircularInference.ts(28,14): error TS7023: 'foo' implicitly has return type 'any' because it does not have a return type annotation and is referenced directly or indirectly in one of its return expressions. -tests/cases/compiler/implicitAnyFromCircularInference.ts(41,5): error TS7022: 's' implicitly has type 'any' because it is does not have a type annotation and is referenced directly or indirectly in its own initializer. +tests/cases/compiler/implicitAnyFromCircularInference.ts(41,5): error TS7022: 's' implicitly has type 'any' because it does not have a type annotation and is referenced directly or indirectly in its own initializer. tests/cases/compiler/implicitAnyFromCircularInference.ts(46,5): error TS7023: 'x' implicitly has return type 'any' because it does not have a return type annotation and is referenced directly or indirectly in one of its return expressions. @@ -72,7 +72,7 @@ tests/cases/compiler/implicitAnyFromCircularInference.ts(46,5): error TS7023: 'x // Error expected s = foo(this); ~~~~~~~~~~~~~~ -!!! error TS7022: 's' implicitly has type 'any' because it is does not have a type annotation and is referenced directly or indirectly in its own initializer. +!!! error TS7022: 's' implicitly has type 'any' because it does not have a type annotation and is referenced directly or indirectly in its own initializer. } class D { diff --git a/tests/baselines/reference/inlineSourceMap2.errors.txt b/tests/baselines/reference/inlineSourceMap2.errors.txt index 75db5689c66..2d8bc4be0c1 100644 --- a/tests/baselines/reference/inlineSourceMap2.errors.txt +++ b/tests/baselines/reference/inlineSourceMap2.errors.txt @@ -1,12 +1,12 @@ -error TS5050: Option 'mapRoot' cannot be specified with option 'inlineSourceMap'. -error TS5049: Option 'sourceRoot' cannot be specified with option 'inlineSourceMap'. error TS5048: Option 'sourceMap' cannot be specified with option 'inlineSourceMap'. +error TS5049: Option 'sourceRoot' cannot be specified with option 'inlineSourceMap'. +error TS5050: Option 'mapRoot' cannot be specified with option 'inlineSourceMap'. tests/cases/compiler/inlineSourceMap2.ts(5,1): error TS2304: Cannot find name 'console'. -!!! error TS5050: Option 'mapRoot' cannot be specified with option 'inlineSourceMap'. -!!! error TS5049: Option 'sourceRoot' cannot be specified with option 'inlineSourceMap'. !!! error TS5048: Option 'sourceMap' cannot be specified with option 'inlineSourceMap'. +!!! error TS5049: Option 'sourceRoot' cannot be specified with option 'inlineSourceMap'. +!!! error TS5050: Option 'mapRoot' cannot be specified with option 'inlineSourceMap'. ==== tests/cases/compiler/inlineSourceMap2.ts (1 errors) ==== // configuration errors diff --git a/tests/baselines/reference/interfacesWithPredefinedTypesAsNames.errors.txt b/tests/baselines/reference/interfacesWithPredefinedTypesAsNames.errors.txt index 91cd267b596..902e4b448b5 100644 --- a/tests/baselines/reference/interfacesWithPredefinedTypesAsNames.errors.txt +++ b/tests/baselines/reference/interfacesWithPredefinedTypesAsNames.errors.txt @@ -2,10 +2,11 @@ tests/cases/conformance/interfaces/interfaceDeclarations/interfacesWithPredefine tests/cases/conformance/interfaces/interfaceDeclarations/interfacesWithPredefinedTypesAsNames.ts(2,11): error TS2427: Interface name cannot be 'number' tests/cases/conformance/interfaces/interfaceDeclarations/interfacesWithPredefinedTypesAsNames.ts(3,11): error TS2427: Interface name cannot be 'string' tests/cases/conformance/interfaces/interfaceDeclarations/interfacesWithPredefinedTypesAsNames.ts(4,11): error TS2427: Interface name cannot be 'boolean' -tests/cases/conformance/interfaces/interfaceDeclarations/interfacesWithPredefinedTypesAsNames.ts(5,11): error TS1003: Identifier expected. +tests/cases/conformance/interfaces/interfaceDeclarations/interfacesWithPredefinedTypesAsNames.ts(5,1): error TS2304: Cannot find name 'interface'. +tests/cases/conformance/interfaces/interfaceDeclarations/interfacesWithPredefinedTypesAsNames.ts(5,11): error TS1005: ';' expected. -==== tests/cases/conformance/interfaces/interfaceDeclarations/interfacesWithPredefinedTypesAsNames.ts (5 errors) ==== +==== tests/cases/conformance/interfaces/interfaceDeclarations/interfacesWithPredefinedTypesAsNames.ts (6 errors) ==== interface any { } ~~~ !!! error TS2427: Interface name cannot be 'any' @@ -19,5 +20,7 @@ tests/cases/conformance/interfaces/interfaceDeclarations/interfacesWithPredefine ~~~~~~~ !!! error TS2427: Interface name cannot be 'boolean' interface void {} + ~~~~~~~~~ +!!! error TS2304: Cannot find name 'interface'. ~~~~ -!!! error TS1003: Identifier expected. \ No newline at end of file +!!! error TS1005: ';' expected. \ No newline at end of file diff --git a/tests/baselines/reference/interfacesWithPredefinedTypesAsNames.js b/tests/baselines/reference/interfacesWithPredefinedTypesAsNames.js index b79dfc12a04..ca186b1cef1 100644 --- a/tests/baselines/reference/interfacesWithPredefinedTypesAsNames.js +++ b/tests/baselines/reference/interfacesWithPredefinedTypesAsNames.js @@ -6,4 +6,5 @@ interface boolean { } interface void {} //// [interfacesWithPredefinedTypesAsNames.js] +interface; void {}; diff --git a/tests/baselines/reference/logicalOrOperatorWithEveryType.types b/tests/baselines/reference/logicalOrOperatorWithEveryType.types index c98966acb98..ecf6b23e729 100644 --- a/tests/baselines/reference/logicalOrOperatorWithEveryType.types +++ b/tests/baselines/reference/logicalOrOperatorWithEveryType.types @@ -379,8 +379,8 @@ var rg7 = a7 || a6; // object || enum is object | enum >a6 : E var rg8 = a8 || a6; // array || enum is array | enum ->rg8 : string[] | E ->a8 || a6 : string[] | E +>rg8 : E | string[] +>a8 || a6 : E | string[] >a8 : string[] >a6 : E @@ -439,8 +439,8 @@ var rh7 = a7 || a7; // object || object is object >a7 : { a: string; } var rh8 = a8 || a7; // array || object is array | object ->rh8 : string[] | { a: string; } ->a8 || a7 : string[] | { a: string; } +>rh8 : { a: string; } | string[] +>a8 || a7 : { a: string; } | string[] >a8 : string[] >a7 : { a: string; } @@ -487,14 +487,14 @@ var ri5 = a5 || a8; // void || array is void | array >a8 : string[] var ri6 = a6 || a8; // enum || array is enum | array ->ri6 : string[] | E ->a6 || a8 : string[] | E +>ri6 : E | string[] +>a6 || a8 : E | string[] >a6 : E >a8 : string[] var ri7 = a7 || a8; // object || array is object | array ->ri7 : string[] | { a: string; } ->a7 || a8 : string[] | { a: string; } +>ri7 : { a: string; } | string[] +>a7 || a8 : { a: string; } | string[] >a7 : { a: string; } >a8 : string[] diff --git a/tests/baselines/reference/multiLinePropertyAccessAndArrowFunctionIndent1.errors.txt b/tests/baselines/reference/multiLinePropertyAccessAndArrowFunctionIndent1.errors.txt index 14b7769d22f..abf11dc9dba 100644 --- a/tests/baselines/reference/multiLinePropertyAccessAndArrowFunctionIndent1.errors.txt +++ b/tests/baselines/reference/multiLinePropertyAccessAndArrowFunctionIndent1.errors.txt @@ -1,12 +1,15 @@ tests/cases/compiler/multiLinePropertyAccessAndArrowFunctionIndent1.ts(1,1): error TS1108: A 'return' statement can only be used within a function body. +tests/cases/compiler/multiLinePropertyAccessAndArrowFunctionIndent1.ts(1,18): error TS2304: Cannot find name 'role'. tests/cases/compiler/multiLinePropertyAccessAndArrowFunctionIndent1.ts(2,18): error TS2304: Cannot find name 'Role'. tests/cases/compiler/multiLinePropertyAccessAndArrowFunctionIndent1.ts(4,26): error TS2503: Cannot find namespace 'ng'. -==== tests/cases/compiler/multiLinePropertyAccessAndArrowFunctionIndent1.ts (3 errors) ==== +==== tests/cases/compiler/multiLinePropertyAccessAndArrowFunctionIndent1.ts (4 errors) ==== return this.edit(role) ~~~~~~ !!! error TS1108: A 'return' statement can only be used within a function body. + ~~~~ +!!! error TS2304: Cannot find name 'role'. .then((role: Role) => ~~~~ !!! error TS2304: Cannot find name 'Role'. diff --git a/tests/baselines/reference/noDefaultLib.errors.txt b/tests/baselines/reference/noDefaultLib.errors.txt index b8f42ba7c33..02098950055 100644 --- a/tests/baselines/reference/noDefaultLib.errors.txt +++ b/tests/baselines/reference/noDefaultLib.errors.txt @@ -1,10 +1,10 @@ -error TS2318: Cannot find global type 'IArguments'. error TS2318: Cannot find global type 'Boolean'. +error TS2318: Cannot find global type 'IArguments'. tests/cases/compiler/noDefaultLib.ts(4,11): error TS2317: Global type 'Array' must have 1 type parameter(s). -!!! error TS2318: Cannot find global type 'IArguments'. !!! error TS2318: Cannot find global type 'Boolean'. +!!! error TS2318: Cannot find global type 'IArguments'. ==== tests/cases/compiler/noDefaultLib.ts (1 errors) ==== /// var x; diff --git a/tests/baselines/reference/parser509698.errors.txt b/tests/baselines/reference/parser509698.errors.txt index 85485dd6501..2aaaec18dc2 100644 --- a/tests/baselines/reference/parser509698.errors.txt +++ b/tests/baselines/reference/parser509698.errors.txt @@ -1,21 +1,21 @@ -error TS2318: Cannot find global type 'String'. -error TS2318: Cannot find global type 'RegExp'. -error TS2318: Cannot find global type 'Object'. -error TS2318: Cannot find global type 'Number'. -error TS2318: Cannot find global type 'IArguments'. -error TS2318: Cannot find global type 'Function'. -error TS2318: Cannot find global type 'Boolean'. error TS2318: Cannot find global type 'Array'. +error TS2318: Cannot find global type 'Boolean'. +error TS2318: Cannot find global type 'Function'. +error TS2318: Cannot find global type 'IArguments'. +error TS2318: Cannot find global type 'Number'. +error TS2318: Cannot find global type 'Object'. +error TS2318: Cannot find global type 'RegExp'. +error TS2318: Cannot find global type 'String'. -!!! error TS2318: Cannot find global type 'String'. -!!! error TS2318: Cannot find global type 'RegExp'. -!!! error TS2318: Cannot find global type 'Object'. -!!! error TS2318: Cannot find global type 'Number'. -!!! error TS2318: Cannot find global type 'IArguments'. -!!! error TS2318: Cannot find global type 'Function'. -!!! error TS2318: Cannot find global type 'Boolean'. !!! error TS2318: Cannot find global type 'Array'. +!!! error TS2318: Cannot find global type 'Boolean'. +!!! error TS2318: Cannot find global type 'Function'. +!!! error TS2318: Cannot find global type 'IArguments'. +!!! error TS2318: Cannot find global type 'Number'. +!!! error TS2318: Cannot find global type 'Object'. +!!! error TS2318: Cannot find global type 'RegExp'. +!!! error TS2318: Cannot find global type 'String'. ==== tests/cases/conformance/parser/ecmascript5/RegressionTests/parser509698.ts (0 errors) ==== ///