From 6afb15c19e51d2bf9cf9c6b644234af532d2af42 Mon Sep 17 00:00:00 2001 From: Jason Ramsay Date: Wed, 17 Jun 2015 21:22:16 -0700 Subject: [PATCH 01/64] CoreServicesShimHost and CoreServicesShimHostAdapter changes to support TSConfig exclude from the language service --- src/services/shims.ts | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/src/services/shims.ts b/src/services/shims.ts index 2e8b3eb774d..611d1dc8d29 100644 --- a/src/services/shims.ts +++ b/src/services/shims.ts @@ -61,8 +61,12 @@ namespace ts { /** Public interface of the the of a config service shim instance.*/ export interface CoreServicesShimHost extends Logger { - /** Returns a JSON-encoded value of the type: string[] */ - readDirectory(rootDir: string, extension: string): string; + /** Returns a JSON-encoded value of the type: string[] + * + * @param exclude A JSON encoded string[] containing the paths to exclude + * when enumerating the directory. + */ + readDirectory(rootDir: string, extension: string, exclude?: string): string; } /// @@ -351,8 +355,18 @@ namespace ts { constructor(private shimHost: CoreServicesShimHost) { } - public readDirectory(rootDir: string, extension: string): string[] { - var encoded = this.shimHost.readDirectory(rootDir, extension); + public readDirectory(rootDir: string, extension: string, exclude: string[]): string[] { + // Wrap the API changes for 1.5 release. This try/catch + // should be removed once TypeScript 1.5 has shipped. + // Also consider removing the optional designation for + // the exclude param at this time. + var encoded: string; + try { + encoded = this.shimHost.readDirectory(rootDir, extension, JSON.stringify(exclude)); + } + catch (e) { + encoded = this.shimHost.readDirectory(rootDir, extension); + } return JSON.parse(encoded); } } From 54a4e9e57d74ed28c3d13e8adf32a1870d959bb8 Mon Sep 17 00:00:00 2001 From: vvakame Date: Sun, 21 Jun 2015 16:15:21 +0900 Subject: [PATCH 02/64] improve module loading interoperability for babel --- src/compiler/emitter.ts | 11 ++++++ tests/baselines/reference/es5-commonjs.js | 29 ++++++++++++++++ .../baselines/reference/es5-commonjs.symbols | 17 ++++++++++ tests/baselines/reference/es5-commonjs.types | 18 ++++++++++ tests/baselines/reference/es5-system.js | 34 +++++++++++++++++++ tests/baselines/reference/es5-system.symbols | 17 ++++++++++ tests/baselines/reference/es5-system.types | 18 ++++++++++ tests/baselines/reference/es5-umd3.js | 3 ++ .../es5ExportDefaultClassDeclaration.js | 3 ++ .../es5ExportDefaultClassDeclaration2.js | 3 ++ .../es5ExportDefaultClassDeclaration3.js | 3 ++ .../es5ExportDefaultFunctionDeclaration.js | 3 ++ .../es5ExportDefaultFunctionDeclaration2.js | 3 ++ .../es5ExportDefaultFunctionDeclaration3.js | 3 ++ .../reference/exportAndImport-es3-amd.js | 6 ++++ .../reference/exportAndImport-es3.js | 6 ++++ .../reference/exportAndImport-es5-amd.js | 6 ++++ .../reference/exportAndImport-es5.js | 6 ++++ tests/cases/compiler/es5-commonjs.ts | 17 ++++++++++ tests/cases/compiler/es5-system.ts | 17 ++++++++++ 20 files changed, 223 insertions(+) create mode 100644 tests/baselines/reference/es5-commonjs.js create mode 100644 tests/baselines/reference/es5-commonjs.symbols create mode 100644 tests/baselines/reference/es5-commonjs.types create mode 100644 tests/baselines/reference/es5-system.js create mode 100644 tests/baselines/reference/es5-system.symbols create mode 100644 tests/baselines/reference/es5-system.types create mode 100644 tests/cases/compiler/es5-commonjs.ts create mode 100644 tests/cases/compiler/es5-system.ts diff --git a/src/compiler/emitter.ts b/src/compiler/emitter.ts index 3fbe640254f..2d8377f74f8 100644 --- a/src/compiler/emitter.ts +++ b/src/compiler/emitter.ts @@ -2709,6 +2709,17 @@ var __param = (this && this.__param) || function (paramIndex, decorator) { } else { if (node.flags & NodeFlags.Default) { + if (compilerOptions.module === ModuleKind.CommonJS || compilerOptions.module === ModuleKind.AMD || compilerOptions.module === ModuleKind.UMD) { + write("Object.defineProperty(exports, \"__esModule\", {"); + writeLine(); + increaseIndent(); + // default value of configurable, enumerable, writable are `false`. + write("value: true"); + writeLine(); + decreaseIndent(); + write("};"); + writeLine(); + } if (languageVersion === ScriptTarget.ES3) { write("exports[\"default\"]"); } else { diff --git a/tests/baselines/reference/es5-commonjs.js b/tests/baselines/reference/es5-commonjs.js new file mode 100644 index 00000000000..e9f939dde31 --- /dev/null +++ b/tests/baselines/reference/es5-commonjs.js @@ -0,0 +1,29 @@ +//// [es5-commonjs.ts] + +export default class A +{ + constructor () + { + + } + + public B() + { + return 42; + } +} + + +//// [es5-commonjs.js] +var A = (function () { + function A() { + } + A.prototype.B = function () { + return 42; + }; + return A; +})(); +Object.defineProperty(exports, "__esModule", { + value: true +}; +exports.default = A; diff --git a/tests/baselines/reference/es5-commonjs.symbols b/tests/baselines/reference/es5-commonjs.symbols new file mode 100644 index 00000000000..41e4484afcd --- /dev/null +++ b/tests/baselines/reference/es5-commonjs.symbols @@ -0,0 +1,17 @@ +=== tests/cases/compiler/es5-commonjs.ts === + +export default class A +>A : Symbol(A, Decl(es5-commonjs.ts, 0, 0)) +{ + constructor () + { + + } + + public B() +>B : Symbol(B, Decl(es5-commonjs.ts, 6, 5)) + { + return 42; + } +} + diff --git a/tests/baselines/reference/es5-commonjs.types b/tests/baselines/reference/es5-commonjs.types new file mode 100644 index 00000000000..4c1bc922917 --- /dev/null +++ b/tests/baselines/reference/es5-commonjs.types @@ -0,0 +1,18 @@ +=== tests/cases/compiler/es5-commonjs.ts === + +export default class A +>A : A +{ + constructor () + { + + } + + public B() +>B : () => number + { + return 42; +>42 : number + } +} + diff --git a/tests/baselines/reference/es5-system.js b/tests/baselines/reference/es5-system.js new file mode 100644 index 00000000000..2674527722a --- /dev/null +++ b/tests/baselines/reference/es5-system.js @@ -0,0 +1,34 @@ +//// [es5-system.ts] + +export default class A +{ + constructor () + { + + } + + public B() + { + return 42; + } +} + + +//// [es5-system.js] +System.register([], function(exports_1) { + var A; + return { + setters:[], + execute: function() { + A = (function () { + function A() { + } + A.prototype.B = function () { + return 42; + }; + return A; + })(); + exports_1("default", A); + } + } +}); diff --git a/tests/baselines/reference/es5-system.symbols b/tests/baselines/reference/es5-system.symbols new file mode 100644 index 00000000000..5211e3c4259 --- /dev/null +++ b/tests/baselines/reference/es5-system.symbols @@ -0,0 +1,17 @@ +=== tests/cases/compiler/es5-system.ts === + +export default class A +>A : Symbol(A, Decl(es5-system.ts, 0, 0)) +{ + constructor () + { + + } + + public B() +>B : Symbol(B, Decl(es5-system.ts, 6, 5)) + { + return 42; + } +} + diff --git a/tests/baselines/reference/es5-system.types b/tests/baselines/reference/es5-system.types new file mode 100644 index 00000000000..eae884a78b4 --- /dev/null +++ b/tests/baselines/reference/es5-system.types @@ -0,0 +1,18 @@ +=== tests/cases/compiler/es5-system.ts === + +export default class A +>A : A +{ + constructor () + { + + } + + public B() +>B : () => number + { + return 42; +>42 : number + } +} + diff --git a/tests/baselines/reference/es5-umd3.js b/tests/baselines/reference/es5-umd3.js index 3abb92f816f..b823ab67f18 100644 --- a/tests/baselines/reference/es5-umd3.js +++ b/tests/baselines/reference/es5-umd3.js @@ -31,5 +31,8 @@ export default class A }; return A; })(); + Object.defineProperty(exports, "__esModule", { + value: true + }; exports.default = A; }); diff --git a/tests/baselines/reference/es5ExportDefaultClassDeclaration.js b/tests/baselines/reference/es5ExportDefaultClassDeclaration.js index b5cfdb02f78..b38a4ff1861 100644 --- a/tests/baselines/reference/es5ExportDefaultClassDeclaration.js +++ b/tests/baselines/reference/es5ExportDefaultClassDeclaration.js @@ -12,6 +12,9 @@ var C = (function () { C.prototype.method = function () { }; return C; })(); +Object.defineProperty(exports, "__esModule", { + value: true +}; exports.default = C; diff --git a/tests/baselines/reference/es5ExportDefaultClassDeclaration2.js b/tests/baselines/reference/es5ExportDefaultClassDeclaration2.js index de0d109dadf..4bddd5cd522 100644 --- a/tests/baselines/reference/es5ExportDefaultClassDeclaration2.js +++ b/tests/baselines/reference/es5ExportDefaultClassDeclaration2.js @@ -12,6 +12,9 @@ var default_1 = (function () { default_1.prototype.method = function () { }; return default_1; })(); +Object.defineProperty(exports, "__esModule", { + value: true +}; exports.default = default_1; diff --git a/tests/baselines/reference/es5ExportDefaultClassDeclaration3.js b/tests/baselines/reference/es5ExportDefaultClassDeclaration3.js index bff80940a02..be7b094852d 100644 --- a/tests/baselines/reference/es5ExportDefaultClassDeclaration3.js +++ b/tests/baselines/reference/es5ExportDefaultClassDeclaration3.js @@ -24,6 +24,9 @@ var C = (function () { }; return C; })(); +Object.defineProperty(exports, "__esModule", { + value: true +}; exports.default = C; var after = new C(); var t = C; diff --git a/tests/baselines/reference/es5ExportDefaultFunctionDeclaration.js b/tests/baselines/reference/es5ExportDefaultFunctionDeclaration.js index 673cc3cb453..24e514a13da 100644 --- a/tests/baselines/reference/es5ExportDefaultFunctionDeclaration.js +++ b/tests/baselines/reference/es5ExportDefaultFunctionDeclaration.js @@ -5,6 +5,9 @@ export default function f() { } //// [es5ExportDefaultFunctionDeclaration.js] function f() { } +Object.defineProperty(exports, "__esModule", { + value: true +}; exports.default = f; diff --git a/tests/baselines/reference/es5ExportDefaultFunctionDeclaration2.js b/tests/baselines/reference/es5ExportDefaultFunctionDeclaration2.js index ad1334e810b..637a780ddf6 100644 --- a/tests/baselines/reference/es5ExportDefaultFunctionDeclaration2.js +++ b/tests/baselines/reference/es5ExportDefaultFunctionDeclaration2.js @@ -5,6 +5,9 @@ export default function () { } //// [es5ExportDefaultFunctionDeclaration2.js] function default_1() { } +Object.defineProperty(exports, "__esModule", { + value: true +}; exports.default = default_1; diff --git a/tests/baselines/reference/es5ExportDefaultFunctionDeclaration3.js b/tests/baselines/reference/es5ExportDefaultFunctionDeclaration3.js index 1fc57976439..1340d239169 100644 --- a/tests/baselines/reference/es5ExportDefaultFunctionDeclaration3.js +++ b/tests/baselines/reference/es5ExportDefaultFunctionDeclaration3.js @@ -13,6 +13,9 @@ var before = func(); function func() { return func; } +Object.defineProperty(exports, "__esModule", { + value: true +}; exports.default = func; var after = func(); diff --git a/tests/baselines/reference/exportAndImport-es3-amd.js b/tests/baselines/reference/exportAndImport-es3-amd.js index a4552e70d68..33630da60d2 100644 --- a/tests/baselines/reference/exportAndImport-es3-amd.js +++ b/tests/baselines/reference/exportAndImport-es3-amd.js @@ -16,6 +16,9 @@ export default function f2() { define(["require", "exports"], function (require, exports) { function f1() { } + Object.defineProperty(exports, "__esModule", { + value: true + }; exports["default"] = f1; }); //// [m2.js] @@ -23,5 +26,8 @@ define(["require", "exports", "./m1"], function (require, exports, m1_1) { function f2() { m1_1["default"](); } + Object.defineProperty(exports, "__esModule", { + value: true + }; exports["default"] = f2; }); diff --git a/tests/baselines/reference/exportAndImport-es3.js b/tests/baselines/reference/exportAndImport-es3.js index 5f467509b68..60d2c39e203 100644 --- a/tests/baselines/reference/exportAndImport-es3.js +++ b/tests/baselines/reference/exportAndImport-es3.js @@ -15,10 +15,16 @@ export default function f2() { //// [m1.js] function f1() { } +Object.defineProperty(exports, "__esModule", { + value: true +}; exports["default"] = f1; //// [m2.js] var m1_1 = require("./m1"); function f2() { m1_1["default"](); } +Object.defineProperty(exports, "__esModule", { + value: true +}; exports["default"] = f2; diff --git a/tests/baselines/reference/exportAndImport-es5-amd.js b/tests/baselines/reference/exportAndImport-es5-amd.js index 4966af874f7..771405a3b4c 100644 --- a/tests/baselines/reference/exportAndImport-es5-amd.js +++ b/tests/baselines/reference/exportAndImport-es5-amd.js @@ -16,6 +16,9 @@ export default function f2() { define(["require", "exports"], function (require, exports) { function f1() { } + Object.defineProperty(exports, "__esModule", { + value: true + }; exports.default = f1; }); //// [m2.js] @@ -23,5 +26,8 @@ define(["require", "exports", "./m1"], function (require, exports, m1_1) { function f2() { m1_1.default(); } + Object.defineProperty(exports, "__esModule", { + value: true + }; exports.default = f2; }); diff --git a/tests/baselines/reference/exportAndImport-es5.js b/tests/baselines/reference/exportAndImport-es5.js index 02d0e43e5a9..9662e91be3b 100644 --- a/tests/baselines/reference/exportAndImport-es5.js +++ b/tests/baselines/reference/exportAndImport-es5.js @@ -15,10 +15,16 @@ export default function f2() { //// [m1.js] function f1() { } +Object.defineProperty(exports, "__esModule", { + value: true +}; exports.default = f1; //// [m2.js] var m1_1 = require("./m1"); function f2() { m1_1.default(); } +Object.defineProperty(exports, "__esModule", { + value: true +}; exports.default = f2; diff --git a/tests/cases/compiler/es5-commonjs.ts b/tests/cases/compiler/es5-commonjs.ts new file mode 100644 index 00000000000..21eb3732ada --- /dev/null +++ b/tests/cases/compiler/es5-commonjs.ts @@ -0,0 +1,17 @@ +// @target: ES5 +// @sourcemap: false +// @declaration: false +// @module: commonjs + +export default class A +{ + constructor () + { + + } + + public B() + { + return 42; + } +} diff --git a/tests/cases/compiler/es5-system.ts b/tests/cases/compiler/es5-system.ts new file mode 100644 index 00000000000..e615f7e5412 --- /dev/null +++ b/tests/cases/compiler/es5-system.ts @@ -0,0 +1,17 @@ +// @target: ES5 +// @sourcemap: false +// @declaration: false +// @module: system + +export default class A +{ + constructor () + { + + } + + public B() + { + return 42; + } +} From 3aba5aa9b50bf1623cb5c60fa008a26bc59a8737 Mon Sep 17 00:00:00 2001 From: vvakame Date: Mon, 22 Jun 2015 10:46:45 +0900 Subject: [PATCH 03/64] do not use `Object.defineProperty` in es3 target --- src/compiler/emitter.ts | 23 +++++++++++-------- .../reference/exportAndImport-es3-amd.js | 8 ++----- .../reference/exportAndImport-es3.js | 8 ++----- 3 files changed, 18 insertions(+), 21 deletions(-) diff --git a/src/compiler/emitter.ts b/src/compiler/emitter.ts index 2d8377f74f8..17c54c9eb0a 100644 --- a/src/compiler/emitter.ts +++ b/src/compiler/emitter.ts @@ -2710,15 +2710,20 @@ var __param = (this && this.__param) || function (paramIndex, decorator) { else { if (node.flags & NodeFlags.Default) { if (compilerOptions.module === ModuleKind.CommonJS || compilerOptions.module === ModuleKind.AMD || compilerOptions.module === ModuleKind.UMD) { - write("Object.defineProperty(exports, \"__esModule\", {"); - writeLine(); - increaseIndent(); - // default value of configurable, enumerable, writable are `false`. - write("value: true"); - writeLine(); - decreaseIndent(); - write("};"); - writeLine(); + if (languageVersion >= ScriptTarget.ES5) { + write("Object.defineProperty(exports, \"__esModule\", {"); + writeLine(); + increaseIndent(); + // default value of configurable, enumerable, writable are `false`. + write("value: true"); + writeLine(); + decreaseIndent(); + write("};"); + writeLine(); + } else { + write("exports.__esModule = true;"); + writeLine(); + } } if (languageVersion === ScriptTarget.ES3) { write("exports[\"default\"]"); diff --git a/tests/baselines/reference/exportAndImport-es3-amd.js b/tests/baselines/reference/exportAndImport-es3-amd.js index 33630da60d2..d2293a56e23 100644 --- a/tests/baselines/reference/exportAndImport-es3-amd.js +++ b/tests/baselines/reference/exportAndImport-es3-amd.js @@ -16,9 +16,7 @@ export default function f2() { define(["require", "exports"], function (require, exports) { function f1() { } - Object.defineProperty(exports, "__esModule", { - value: true - }; + exports.__esModule = true; exports["default"] = f1; }); //// [m2.js] @@ -26,8 +24,6 @@ define(["require", "exports", "./m1"], function (require, exports, m1_1) { function f2() { m1_1["default"](); } - Object.defineProperty(exports, "__esModule", { - value: true - }; + exports.__esModule = true; exports["default"] = f2; }); diff --git a/tests/baselines/reference/exportAndImport-es3.js b/tests/baselines/reference/exportAndImport-es3.js index 60d2c39e203..1be548bc930 100644 --- a/tests/baselines/reference/exportAndImport-es3.js +++ b/tests/baselines/reference/exportAndImport-es3.js @@ -15,16 +15,12 @@ export default function f2() { //// [m1.js] function f1() { } -Object.defineProperty(exports, "__esModule", { - value: true -}; +exports.__esModule = true; exports["default"] = f1; //// [m2.js] var m1_1 = require("./m1"); function f2() { m1_1["default"](); } -Object.defineProperty(exports, "__esModule", { - value: true -}; +exports.__esModule = true; exports["default"] = f2; From f848087db0082493458c9a1406d718cf802de7c5 Mon Sep 17 00:00:00 2001 From: Daniel Rosenwasser Date: Thu, 25 Jun 2015 11:59:45 -0400 Subject: [PATCH 04/64] Added failing tests. --- ...lRefsObjectBindingElementPropertyName01.ts | 19 +++++++++++++++++++ ...itionObjectBindingElementPropertyName01.ts | 14 ++++++++++++++ ...foForObjectBindingElementPropertyName01.ts | 12 ++++++++++++ ...enameObjectBindingElementPropertyName01.ts | 15 +++++++++++++++ 4 files changed, 60 insertions(+) create mode 100644 tests/cases/fourslash/findAllRefsObjectBindingElementPropertyName01.ts create mode 100644 tests/cases/fourslash/goToDefinitionObjectBindingElementPropertyName01.ts create mode 100644 tests/cases/fourslash/quickInfoForObjectBindingElementPropertyName01.ts create mode 100644 tests/cases/fourslash/renameObjectBindingElementPropertyName01.ts diff --git a/tests/cases/fourslash/findAllRefsObjectBindingElementPropertyName01.ts b/tests/cases/fourslash/findAllRefsObjectBindingElementPropertyName01.ts new file mode 100644 index 00000000000..0d03561515d --- /dev/null +++ b/tests/cases/fourslash/findAllRefsObjectBindingElementPropertyName01.ts @@ -0,0 +1,19 @@ +/// + +////interface I { +//// [|property1|]: number; +//// property2: string; +////} +//// +////var foo: I; +////var { [|property1|]: prop1 } = foo; + +let ranges = test.ranges(); +for (let range of ranges) { + goTo.position(range.start); + + verify.referencesCountIs(ranges.length); + for (let expectedRange of ranges) { + verify.referencesAtPositionContains(expectedRange); + } +} \ No newline at end of file diff --git a/tests/cases/fourslash/goToDefinitionObjectBindingElementPropertyName01.ts b/tests/cases/fourslash/goToDefinitionObjectBindingElementPropertyName01.ts new file mode 100644 index 00000000000..9348ba05678 --- /dev/null +++ b/tests/cases/fourslash/goToDefinitionObjectBindingElementPropertyName01.ts @@ -0,0 +1,14 @@ +/// + +////interface I { +//// /*def*/property1: number; +//// property2: string; +////} +//// +////var foo: I; +////var { /*use*/property1: prop1 } = foo; + +goTo.marker("use"); +verify.definitionLocationExists(); +goTo.definition(); +verify.caretAtMarker("def"); \ No newline at end of file diff --git a/tests/cases/fourslash/quickInfoForObjectBindingElementPropertyName01.ts b/tests/cases/fourslash/quickInfoForObjectBindingElementPropertyName01.ts new file mode 100644 index 00000000000..72e742ba7af --- /dev/null +++ b/tests/cases/fourslash/quickInfoForObjectBindingElementPropertyName01.ts @@ -0,0 +1,12 @@ +/// + +////interface I { +//// property1: number; +//// property2: string; +////} +//// +////var foo: I; +////var { /*use*/property1: prop1 } = foo; + +goTo.marker(); +verify.quickInfoIs("(property) I.property1: number"); \ No newline at end of file diff --git a/tests/cases/fourslash/renameObjectBindingElementPropertyName01.ts b/tests/cases/fourslash/renameObjectBindingElementPropertyName01.ts new file mode 100644 index 00000000000..34dcc1353d0 --- /dev/null +++ b/tests/cases/fourslash/renameObjectBindingElementPropertyName01.ts @@ -0,0 +1,15 @@ +/// + +////interface I { +//// /*1*/[|property1|]: number; +//// property2: string; +////} +//// +////var foo: I; +////var { /*2*/[|property1|]: prop1 } = foo; + +for (let m of test.markers()) { + goTo.position(m.position); + verify.renameInfoSucceeded("property1", "I.property1", "property"); + verify.renameLocations(/*findInStrings*/ false, /*findInComments*/ false); +} \ No newline at end of file From cb48c041874bebbfbf78a46ed5d2aa5e0979cdf9 Mon Sep 17 00:00:00 2001 From: Daniel Rosenwasser Date: Thu, 25 Jun 2015 12:18:06 -0400 Subject: [PATCH 05/64] Added failing tests for when RHS is a destructuring. --- ...lRefsObjectBindingElementPropertyName02.ts | 19 +++++++++++++++++++ ...foForObjectBindingElementPropertyName02.ts | 12 ++++++++++++ 2 files changed, 31 insertions(+) create mode 100644 tests/cases/fourslash/findAllRefsObjectBindingElementPropertyName02.ts create mode 100644 tests/cases/fourslash/quickInfoForObjectBindingElementPropertyName02.ts diff --git a/tests/cases/fourslash/findAllRefsObjectBindingElementPropertyName02.ts b/tests/cases/fourslash/findAllRefsObjectBindingElementPropertyName02.ts new file mode 100644 index 00000000000..86514051557 --- /dev/null +++ b/tests/cases/fourslash/findAllRefsObjectBindingElementPropertyName02.ts @@ -0,0 +1,19 @@ +/// + +////interface I { +//// [|property1|]: number; +//// property2: string; +////} +//// +////var foo: I; +////var { [|property1|]: {} } = foo; + +let ranges = test.ranges(); +for (let range of ranges) { + goTo.position(range.start); + + verify.referencesCountIs(ranges.length); + for (let expectedRange of ranges) { + verify.referencesAtPositionContains(expectedRange); + } +} \ No newline at end of file diff --git a/tests/cases/fourslash/quickInfoForObjectBindingElementPropertyName02.ts b/tests/cases/fourslash/quickInfoForObjectBindingElementPropertyName02.ts new file mode 100644 index 00000000000..5a166037f1c --- /dev/null +++ b/tests/cases/fourslash/quickInfoForObjectBindingElementPropertyName02.ts @@ -0,0 +1,12 @@ +/// + +////interface I { +//// property1: number; +//// property2: string; +////} +//// +////var foo: I; +////var { /**/property1: {} } = foo; + +goTo.marker(); +verify.quickInfoIs("(property) I.property1: number"); \ No newline at end of file From 70758e2920f6142d8dbcc02250129fa0f19a1d80 Mon Sep 17 00:00:00 2001 From: Daniel Rosenwasser Date: Thu, 25 Jun 2015 14:24:13 -0400 Subject: [PATCH 06/64] Add two new tests to test for regression. --- .../quickInfoForObjectBindingElementName01.ts | 12 ++++++++++++ .../quickInfoForObjectBindingElementName02.ts | 12 ++++++++++++ 2 files changed, 24 insertions(+) create mode 100644 tests/cases/fourslash/quickInfoForObjectBindingElementName01.ts create mode 100644 tests/cases/fourslash/quickInfoForObjectBindingElementName02.ts diff --git a/tests/cases/fourslash/quickInfoForObjectBindingElementName01.ts b/tests/cases/fourslash/quickInfoForObjectBindingElementName01.ts new file mode 100644 index 00000000000..5cba9554b80 --- /dev/null +++ b/tests/cases/fourslash/quickInfoForObjectBindingElementName01.ts @@ -0,0 +1,12 @@ +/// + +////interface I { +//// property1: number; +//// property2: string; +////} +//// +////var foo: I; +////var { /**/property1 } = foo; + +goTo.marker(); +verify.quickInfoIs("var property1: number"); \ No newline at end of file diff --git a/tests/cases/fourslash/quickInfoForObjectBindingElementName02.ts b/tests/cases/fourslash/quickInfoForObjectBindingElementName02.ts new file mode 100644 index 00000000000..e861d3db8fb --- /dev/null +++ b/tests/cases/fourslash/quickInfoForObjectBindingElementName02.ts @@ -0,0 +1,12 @@ +/// + +////interface I { +//// property1: number; +//// property2: string; +////} +//// +////var foo: I; +////var { property1: /**/prop1 } = foo; + +goTo.marker(); +verify.quickInfoIs("var prop1: number"); \ No newline at end of file From 341ba747d0d62bb9ca21830e1491d4e2790822c3 Mon Sep 17 00:00:00 2001 From: Daniel Rosenwasser Date: Thu, 25 Jun 2015 14:25:51 -0400 Subject: [PATCH 07/64] Fix marker name. --- .../fourslash/quickInfoForObjectBindingElementPropertyName01.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/cases/fourslash/quickInfoForObjectBindingElementPropertyName01.ts b/tests/cases/fourslash/quickInfoForObjectBindingElementPropertyName01.ts index 72e742ba7af..52a9af258b3 100644 --- a/tests/cases/fourslash/quickInfoForObjectBindingElementPropertyName01.ts +++ b/tests/cases/fourslash/quickInfoForObjectBindingElementPropertyName01.ts @@ -6,7 +6,7 @@ ////} //// ////var foo: I; -////var { /*use*/property1: prop1 } = foo; +////var { /**/property1: prop1 } = foo; goTo.marker(); verify.quickInfoIs("(property) I.property1: number"); \ No newline at end of file From 8ec4af546aad35e023a83e978ec5c833e74f2aa1 Mon Sep 17 00:00:00 2001 From: Daniel Rosenwasser Date: Thu, 25 Jun 2015 15:50:25 -0400 Subject: [PATCH 08/64] Just use ranges, don't bother iwth renameInfoSucceeded. --- .../renameObjectBindingElementPropertyName01.ts | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/tests/cases/fourslash/renameObjectBindingElementPropertyName01.ts b/tests/cases/fourslash/renameObjectBindingElementPropertyName01.ts index 34dcc1353d0..535dbd3d5a3 100644 --- a/tests/cases/fourslash/renameObjectBindingElementPropertyName01.ts +++ b/tests/cases/fourslash/renameObjectBindingElementPropertyName01.ts @@ -1,15 +1,14 @@ /// ////interface I { -//// /*1*/[|property1|]: number; +//// [|property1|]: number; //// property2: string; ////} //// ////var foo: I; -////var { /*2*/[|property1|]: prop1 } = foo; +////var { [|property1|]: prop1 } = foo; -for (let m of test.markers()) { - goTo.position(m.position); - verify.renameInfoSucceeded("property1", "I.property1", "property"); +for (let range of test.ranges()) { + goTo.position(range.start); verify.renameLocations(/*findInStrings*/ false, /*findInComments*/ false); } \ No newline at end of file From d7a4ac25f495d5ba78ff27b90fd4f23caf09abac Mon Sep 17 00:00:00 2001 From: Daniel Rosenwasser Date: Thu, 25 Jun 2015 15:52:10 -0400 Subject: [PATCH 09/64] Allow semantic operations to be performed on property names. Provide the property symbol of the type being destructured when referring to the property name. --- src/compiler/checker.ts | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index efee668a24b..763e4173287 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -12352,10 +12352,21 @@ namespace ts { return getSymbolOfNode(node.parent); } - if (node.kind === SyntaxKind.Identifier && isInRightSideOfImportOrExportAssignment(node)) { - return node.parent.kind === SyntaxKind.ExportAssignment - ? getSymbolOfEntityNameOrPropertyAccessExpression(node) - : getSymbolOfPartOfRightHandSideOfImportEquals(node); + if (node.kind === SyntaxKind.Identifier) { + if (isInRightSideOfImportOrExportAssignment(node)) { + return node.parent.kind === SyntaxKind.ExportAssignment + ? getSymbolOfEntityNameOrPropertyAccessExpression(node) + : getSymbolOfPartOfRightHandSideOfImportEquals(node); + } + else if (node.parent.kind === SyntaxKind.BindingElement && + node.parent.parent.kind === SyntaxKind.ObjectBindingPattern && + node === (node.parent).propertyName) { + let typeOfPattern = getTypeAtLocation(node.parent.parent); + let propertyDeclaration = getPropertyOfType(typeOfPattern, (node).text); + if (propertyDeclaration) { + return propertyDeclaration; + } + } } switch (node.kind) { From a769e6747a0ead53cc8ca77c446de6cea5bc7c92 Mon Sep 17 00:00:00 2001 From: Daniel Rosenwasser Date: Thu, 25 Jun 2015 15:57:30 -0400 Subject: [PATCH 10/64] Added one more test. --- ...lRefsObjectBindingElementPropertyName03.ts | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 tests/cases/fourslash/findAllRefsObjectBindingElementPropertyName03.ts diff --git a/tests/cases/fourslash/findAllRefsObjectBindingElementPropertyName03.ts b/tests/cases/fourslash/findAllRefsObjectBindingElementPropertyName03.ts new file mode 100644 index 00000000000..304fa9e42e9 --- /dev/null +++ b/tests/cases/fourslash/findAllRefsObjectBindingElementPropertyName03.ts @@ -0,0 +1,19 @@ +/// + +////interface I { +//// [|property1|]: number; +//// property2: string; +////} +//// +////var foo: I; +////var [{ [|property1|]: prop1 }, { property1, property2 } ] = [foo, foo]; + +let ranges = test.ranges(); +for (let range of ranges) { + goTo.position(range.start); + + verify.referencesCountIs(ranges.length); + for (let expectedRange of ranges) { + verify.referencesAtPositionContains(expectedRange); + } +} \ No newline at end of file From 5ee5ae11f99a8830af6fb4a94aca7f8ef2f68b94 Mon Sep 17 00:00:00 2001 From: Daniel Rosenwasser Date: Thu, 25 Jun 2015 16:09:59 -0400 Subject: [PATCH 11/64] Check for definedness on the pattern's type. --- src/compiler/checker.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 763e4173287..64155fe7737 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -12362,7 +12362,8 @@ namespace ts { node.parent.parent.kind === SyntaxKind.ObjectBindingPattern && node === (node.parent).propertyName) { let typeOfPattern = getTypeAtLocation(node.parent.parent); - let propertyDeclaration = getPropertyOfType(typeOfPattern, (node).text); + let propertyDeclaration = typeOfPattern && getPropertyOfType(typeOfPattern, (node).text); + if (propertyDeclaration) { return propertyDeclaration; } From 475819e27cb84e007fae02e82a4dbaa7d6fa6e05 Mon Sep 17 00:00:00 2001 From: Daniel Rosenwasser Date: Thu, 25 Jun 2015 16:18:51 -0400 Subject: [PATCH 12/64] Accepted new baselines. --- .../reference/declarationEmitDestructuring1.symbols | 1 + .../declarationEmitDestructuringArrayPattern2.symbols | 1 + ...larationEmitDestructuringObjectLiteralPattern.symbols | 9 +++++++++ ...arationEmitDestructuringObjectLiteralPattern1.symbols | 4 ++++ ...arationEmitDestructuringObjectLiteralPattern2.symbols | 5 +++++ ...ucturingObjectBindingPatternAndAssignment1ES5.symbols | 2 ++ ...ucturingObjectBindingPatternAndAssignment1ES6.symbols | 2 ++ .../destructuringVariableDeclaration1ES5.symbols | 6 ++++++ .../destructuringVariableDeclaration1ES6.symbols | 6 ++++++ tests/baselines/reference/downlevelLetConst12.symbols | 2 ++ tests/baselines/reference/downlevelLetConst13.symbols | 4 ++++ tests/baselines/reference/downlevelLetConst14.symbols | 4 ++++ tests/baselines/reference/downlevelLetConst15.symbols | 6 ++++++ .../emitArrowFunctionWhenUsingArguments18_ES6.symbols | 1 + tests/baselines/reference/for-of41.symbols | 2 ++ tests/baselines/reference/for-of42.symbols | 2 ++ .../reference/initializePropertiesWithRenamedLet.symbols | 1 + tests/baselines/reference/letInNonStrictMode.symbols | 1 + .../objectBindingPatternKeywordIdentifiers06.symbols | 1 + tests/baselines/reference/systemModule13.symbols | 3 +++ tests/baselines/reference/systemModule8.symbols | 3 +++ 21 files changed, 66 insertions(+) diff --git a/tests/baselines/reference/declarationEmitDestructuring1.symbols b/tests/baselines/reference/declarationEmitDestructuring1.symbols index 10920128eee..32755fdef35 100644 --- a/tests/baselines/reference/declarationEmitDestructuring1.symbols +++ b/tests/baselines/reference/declarationEmitDestructuring1.symbols @@ -23,6 +23,7 @@ function bar({a1, b1, c1}: { a1: number, b1: boolean, c1: string }): void { } function baz({a2, b2: {b1, c1}}: { a2: number, b2: { b1: boolean, c1: string } }): void { } >baz : Symbol(baz, Decl(declarationEmitDestructuring1.ts, 2, 77)) >a2 : Symbol(a2, Decl(declarationEmitDestructuring1.ts, 3, 14)) +>b2 : Symbol(b2, Decl(declarationEmitDestructuring1.ts, 3, 46)) >b1 : Symbol(b1, Decl(declarationEmitDestructuring1.ts, 3, 23)) >c1 : Symbol(c1, Decl(declarationEmitDestructuring1.ts, 3, 26)) >a2 : Symbol(a2, Decl(declarationEmitDestructuring1.ts, 3, 34)) diff --git a/tests/baselines/reference/declarationEmitDestructuringArrayPattern2.symbols b/tests/baselines/reference/declarationEmitDestructuringArrayPattern2.symbols index 9e0e48f89e8..0a3c6f4044d 100644 --- a/tests/baselines/reference/declarationEmitDestructuringArrayPattern2.symbols +++ b/tests/baselines/reference/declarationEmitDestructuringArrayPattern2.symbols @@ -17,6 +17,7 @@ var [a2, [b2, { x12, y12: c2 }]=["abc", { x12: 10, y12: false }]] = [1, ["hello" >a2 : Symbol(a2, Decl(declarationEmitDestructuringArrayPattern2.ts, 5, 5)) >b2 : Symbol(b2, Decl(declarationEmitDestructuringArrayPattern2.ts, 5, 10)) >x12 : Symbol(x12, Decl(declarationEmitDestructuringArrayPattern2.ts, 5, 15)) +>y12 : Symbol(y12, Decl(declarationEmitDestructuringArrayPattern2.ts, 5, 91)) >c2 : Symbol(c2, Decl(declarationEmitDestructuringArrayPattern2.ts, 5, 20)) >x12 : Symbol(x12, Decl(declarationEmitDestructuringArrayPattern2.ts, 5, 41)) >y12 : Symbol(y12, Decl(declarationEmitDestructuringArrayPattern2.ts, 5, 50)) diff --git a/tests/baselines/reference/declarationEmitDestructuringObjectLiteralPattern.symbols b/tests/baselines/reference/declarationEmitDestructuringObjectLiteralPattern.symbols index 3cb4ef28c2b..0a57a93f3d0 100644 --- a/tests/baselines/reference/declarationEmitDestructuringObjectLiteralPattern.symbols +++ b/tests/baselines/reference/declarationEmitDestructuringObjectLiteralPattern.symbols @@ -21,24 +21,33 @@ var { x6, y6 } = { x6: 5, y6: "hello" }; >y6 : Symbol(y6, Decl(declarationEmitDestructuringObjectLiteralPattern.ts, 4, 25)) var { x7: a1 } = { x7: 5, y7: "hello" }; +>x7 : Symbol(x7, Decl(declarationEmitDestructuringObjectLiteralPattern.ts, 5, 18)) >a1 : Symbol(a1, Decl(declarationEmitDestructuringObjectLiteralPattern.ts, 5, 5)) >x7 : Symbol(x7, Decl(declarationEmitDestructuringObjectLiteralPattern.ts, 5, 18)) >y7 : Symbol(y7, Decl(declarationEmitDestructuringObjectLiteralPattern.ts, 5, 25)) var { y8: b1 } = { x8: 5, y8: "hello" }; +>y8 : Symbol(y8, Decl(declarationEmitDestructuringObjectLiteralPattern.ts, 6, 25)) >b1 : Symbol(b1, Decl(declarationEmitDestructuringObjectLiteralPattern.ts, 6, 5)) >x8 : Symbol(x8, Decl(declarationEmitDestructuringObjectLiteralPattern.ts, 6, 18)) >y8 : Symbol(y8, Decl(declarationEmitDestructuringObjectLiteralPattern.ts, 6, 25)) var { x9: a2, y9: b2 } = { x9: 5, y9: "hello" }; +>x9 : Symbol(x9, Decl(declarationEmitDestructuringObjectLiteralPattern.ts, 7, 26)) >a2 : Symbol(a2, Decl(declarationEmitDestructuringObjectLiteralPattern.ts, 7, 5)) +>y9 : Symbol(y9, Decl(declarationEmitDestructuringObjectLiteralPattern.ts, 7, 33)) >b2 : Symbol(b2, Decl(declarationEmitDestructuringObjectLiteralPattern.ts, 7, 13)) >x9 : Symbol(x9, Decl(declarationEmitDestructuringObjectLiteralPattern.ts, 7, 26)) >y9 : Symbol(y9, Decl(declarationEmitDestructuringObjectLiteralPattern.ts, 7, 33)) var { a: x11, b: { a: y11, b: { a: z11 }}} = { a: 1, b: { a: "hello", b: { a: true } } }; +>a : Symbol(a, Decl(declarationEmitDestructuringObjectLiteralPattern.ts, 9, 46)) >x11 : Symbol(x11, Decl(declarationEmitDestructuringObjectLiteralPattern.ts, 9, 5)) +>b : Symbol(b, Decl(declarationEmitDestructuringObjectLiteralPattern.ts, 9, 52)) +>a : Symbol(a, Decl(declarationEmitDestructuringObjectLiteralPattern.ts, 9, 57)) >y11 : Symbol(y11, Decl(declarationEmitDestructuringObjectLiteralPattern.ts, 9, 18)) +>b : Symbol(b, Decl(declarationEmitDestructuringObjectLiteralPattern.ts, 9, 69)) +>a : Symbol(a, Decl(declarationEmitDestructuringObjectLiteralPattern.ts, 9, 74)) >z11 : Symbol(z11, Decl(declarationEmitDestructuringObjectLiteralPattern.ts, 9, 31)) >a : Symbol(a, Decl(declarationEmitDestructuringObjectLiteralPattern.ts, 9, 46)) >b : Symbol(b, Decl(declarationEmitDestructuringObjectLiteralPattern.ts, 9, 52)) diff --git a/tests/baselines/reference/declarationEmitDestructuringObjectLiteralPattern1.symbols b/tests/baselines/reference/declarationEmitDestructuringObjectLiteralPattern1.symbols index a4c43a07bc8..cac2431411e 100644 --- a/tests/baselines/reference/declarationEmitDestructuringObjectLiteralPattern1.symbols +++ b/tests/baselines/reference/declarationEmitDestructuringObjectLiteralPattern1.symbols @@ -21,17 +21,21 @@ var { x6, y6 } = { x6: 5, y6: "hello" }; >y6 : Symbol(y6, Decl(declarationEmitDestructuringObjectLiteralPattern1.ts, 4, 25)) var { x7: a1 } = { x7: 5, y7: "hello" }; +>x7 : Symbol(x7, Decl(declarationEmitDestructuringObjectLiteralPattern1.ts, 5, 18)) >a1 : Symbol(a1, Decl(declarationEmitDestructuringObjectLiteralPattern1.ts, 5, 5)) >x7 : Symbol(x7, Decl(declarationEmitDestructuringObjectLiteralPattern1.ts, 5, 18)) >y7 : Symbol(y7, Decl(declarationEmitDestructuringObjectLiteralPattern1.ts, 5, 25)) var { y8: b1 } = { x8: 5, y8: "hello" }; +>y8 : Symbol(y8, Decl(declarationEmitDestructuringObjectLiteralPattern1.ts, 6, 25)) >b1 : Symbol(b1, Decl(declarationEmitDestructuringObjectLiteralPattern1.ts, 6, 5)) >x8 : Symbol(x8, Decl(declarationEmitDestructuringObjectLiteralPattern1.ts, 6, 18)) >y8 : Symbol(y8, Decl(declarationEmitDestructuringObjectLiteralPattern1.ts, 6, 25)) var { x9: a2, y9: b2 } = { x9: 5, y9: "hello" }; +>x9 : Symbol(x9, Decl(declarationEmitDestructuringObjectLiteralPattern1.ts, 7, 26)) >a2 : Symbol(a2, Decl(declarationEmitDestructuringObjectLiteralPattern1.ts, 7, 5)) +>y9 : Symbol(y9, Decl(declarationEmitDestructuringObjectLiteralPattern1.ts, 7, 33)) >b2 : Symbol(b2, Decl(declarationEmitDestructuringObjectLiteralPattern1.ts, 7, 13)) >x9 : Symbol(x9, Decl(declarationEmitDestructuringObjectLiteralPattern1.ts, 7, 26)) >y9 : Symbol(y9, Decl(declarationEmitDestructuringObjectLiteralPattern1.ts, 7, 33)) diff --git a/tests/baselines/reference/declarationEmitDestructuringObjectLiteralPattern2.symbols b/tests/baselines/reference/declarationEmitDestructuringObjectLiteralPattern2.symbols index 76440b60038..77e26e2c9b7 100644 --- a/tests/baselines/reference/declarationEmitDestructuringObjectLiteralPattern2.symbols +++ b/tests/baselines/reference/declarationEmitDestructuringObjectLiteralPattern2.symbols @@ -1,8 +1,13 @@ === tests/cases/compiler/declarationEmitDestructuringObjectLiteralPattern2.ts === var { a: x11, b: { a: y11, b: { a: z11 }}} = { a: 1, b: { a: "hello", b: { a: true } } }; +>a : Symbol(a, Decl(declarationEmitDestructuringObjectLiteralPattern2.ts, 1, 46)) >x11 : Symbol(x11, Decl(declarationEmitDestructuringObjectLiteralPattern2.ts, 1, 5)) +>b : Symbol(b, Decl(declarationEmitDestructuringObjectLiteralPattern2.ts, 1, 52)) +>a : Symbol(a, Decl(declarationEmitDestructuringObjectLiteralPattern2.ts, 1, 57)) >y11 : Symbol(y11, Decl(declarationEmitDestructuringObjectLiteralPattern2.ts, 1, 18)) +>b : Symbol(b, Decl(declarationEmitDestructuringObjectLiteralPattern2.ts, 1, 69)) +>a : Symbol(a, Decl(declarationEmitDestructuringObjectLiteralPattern2.ts, 1, 74)) >z11 : Symbol(z11, Decl(declarationEmitDestructuringObjectLiteralPattern2.ts, 1, 31)) >a : Symbol(a, Decl(declarationEmitDestructuringObjectLiteralPattern2.ts, 1, 46)) >b : Symbol(b, Decl(declarationEmitDestructuringObjectLiteralPattern2.ts, 1, 52)) diff --git a/tests/baselines/reference/destructuringObjectBindingPatternAndAssignment1ES5.symbols b/tests/baselines/reference/destructuringObjectBindingPatternAndAssignment1ES5.symbols index 017a7f71e61..718af66047d 100644 --- a/tests/baselines/reference/destructuringObjectBindingPatternAndAssignment1ES5.symbols +++ b/tests/baselines/reference/destructuringObjectBindingPatternAndAssignment1ES5.symbols @@ -19,6 +19,7 @@ var { b1, } = { b1:1, }; >b1 : Symbol(b1, Decl(destructuringObjectBindingPatternAndAssignment1ES5.ts, 11, 15)) var { b2: { b21 } = { b21: "string" } } = { b2: { b21: "world" } }; +>b2 : Symbol(b2, Decl(destructuringObjectBindingPatternAndAssignment1ES5.ts, 12, 44)) >b21 : Symbol(b21, Decl(destructuringObjectBindingPatternAndAssignment1ES5.ts, 12, 11)) >b21 : Symbol(b21, Decl(destructuringObjectBindingPatternAndAssignment1ES5.ts, 12, 21)) >b2 : Symbol(b2, Decl(destructuringObjectBindingPatternAndAssignment1ES5.ts, 12, 44)) @@ -32,6 +33,7 @@ var {b4 = 1}: any = { b4: 100000 }; >b4 : Symbol(b4, Decl(destructuringObjectBindingPatternAndAssignment1ES5.ts, 14, 21)) var {b5: { b52 } } = { b5: { b52 } }; +>b5 : Symbol(b5, Decl(destructuringObjectBindingPatternAndAssignment1ES5.ts, 15, 23)) >b52 : Symbol(b52, Decl(destructuringObjectBindingPatternAndAssignment1ES5.ts, 15, 10)) >b5 : Symbol(b5, Decl(destructuringObjectBindingPatternAndAssignment1ES5.ts, 15, 23)) >b52 : Symbol(b52, Decl(destructuringObjectBindingPatternAndAssignment1ES5.ts, 15, 29)) diff --git a/tests/baselines/reference/destructuringObjectBindingPatternAndAssignment1ES6.symbols b/tests/baselines/reference/destructuringObjectBindingPatternAndAssignment1ES6.symbols index 11289210ee4..57d739cbbfc 100644 --- a/tests/baselines/reference/destructuringObjectBindingPatternAndAssignment1ES6.symbols +++ b/tests/baselines/reference/destructuringObjectBindingPatternAndAssignment1ES6.symbols @@ -19,6 +19,7 @@ var { b1, } = { b1:1, }; >b1 : Symbol(b1, Decl(destructuringObjectBindingPatternAndAssignment1ES6.ts, 11, 15)) var { b2: { b21 } = { b21: "string" } } = { b2: { b21: "world" } }; +>b2 : Symbol(b2, Decl(destructuringObjectBindingPatternAndAssignment1ES6.ts, 12, 44)) >b21 : Symbol(b21, Decl(destructuringObjectBindingPatternAndAssignment1ES6.ts, 12, 11)) >b21 : Symbol(b21, Decl(destructuringObjectBindingPatternAndAssignment1ES6.ts, 12, 21)) >b2 : Symbol(b2, Decl(destructuringObjectBindingPatternAndAssignment1ES6.ts, 12, 44)) @@ -32,6 +33,7 @@ var {b4 = 1}: any = { b4: 100000 }; >b4 : Symbol(b4, Decl(destructuringObjectBindingPatternAndAssignment1ES6.ts, 14, 21)) var {b5: { b52 } } = { b5: { b52 } }; +>b5 : Symbol(b5, Decl(destructuringObjectBindingPatternAndAssignment1ES6.ts, 15, 23)) >b52 : Symbol(b52, Decl(destructuringObjectBindingPatternAndAssignment1ES6.ts, 15, 10)) >b5 : Symbol(b5, Decl(destructuringObjectBindingPatternAndAssignment1ES6.ts, 15, 23)) >b52 : Symbol(b52, Decl(destructuringObjectBindingPatternAndAssignment1ES6.ts, 15, 29)) diff --git a/tests/baselines/reference/destructuringVariableDeclaration1ES5.symbols b/tests/baselines/reference/destructuringVariableDeclaration1ES5.symbols index 2a2f2a358ca..924527bf1b4 100644 --- a/tests/baselines/reference/destructuringVariableDeclaration1ES5.symbols +++ b/tests/baselines/reference/destructuringVariableDeclaration1ES5.symbols @@ -17,6 +17,7 @@ var [a3, [[a4]], a5]: [number, [[string]], boolean] = [1, [["hello"]], true]; // The type T associated with a destructuring variable declaration is determined as follows: // Otherwise, if the declaration includes an initializer expression, T is the type of that initializer expression. var { b1: { b11 } = { b11: "string" } } = { b1: { b11: "world" } }; +>b1 : Symbol(b1, Decl(destructuringVariableDeclaration1ES5.ts, 7, 44)) >b11 : Symbol(b11, Decl(destructuringVariableDeclaration1ES5.ts, 7, 11)) >b11 : Symbol(b11, Decl(destructuringVariableDeclaration1ES5.ts, 7, 21)) >b1 : Symbol(b1, Decl(destructuringVariableDeclaration1ES5.ts, 7, 44)) @@ -74,6 +75,7 @@ var [d3, d4] = [1, "string", ...temp1]; // Combining both forms of destructuring, var {e: [e1, e2, e3 = { b1: 1000, b4: 200 }]} = { e: [1, 2, { b1: 4, b4: 0 }] }; +>e : Symbol(e, Decl(destructuringVariableDeclaration1ES5.ts, 31, 49)) >e1 : Symbol(e1, Decl(destructuringVariableDeclaration1ES5.ts, 31, 9)) >e2 : Symbol(e2, Decl(destructuringVariableDeclaration1ES5.ts, 31, 12)) >e3 : Symbol(e3, Decl(destructuringVariableDeclaration1ES5.ts, 31, 16)) @@ -84,8 +86,10 @@ var {e: [e1, e2, e3 = { b1: 1000, b4: 200 }]} = { e: [1, 2, { b1: 4, b4: 0 }] }; >b4 : Symbol(b4, Decl(destructuringVariableDeclaration1ES5.ts, 31, 68)) var {f: [f1, f2, { f3: f4, f5 }, , ]} = { f: [1, 2, { f3: 4, f5: 0 }] }; +>f : Symbol(f, Decl(destructuringVariableDeclaration1ES5.ts, 32, 41)) >f1 : Symbol(f1, Decl(destructuringVariableDeclaration1ES5.ts, 32, 9)) >f2 : Symbol(f2, Decl(destructuringVariableDeclaration1ES5.ts, 32, 12)) +>f3 : Symbol(f3, Decl(destructuringVariableDeclaration1ES5.ts, 32, 53)) >f4 : Symbol(f4, Decl(destructuringVariableDeclaration1ES5.ts, 32, 18)) >f5 : Symbol(f5, Decl(destructuringVariableDeclaration1ES5.ts, 32, 26)) >f : Symbol(f, Decl(destructuringVariableDeclaration1ES5.ts, 32, 41)) @@ -96,6 +100,7 @@ var {f: [f1, f2, { f3: f4, f5 }, , ]} = { f: [1, 2, { f3: 4, f5: 0 }] }; // an initializer expression, the type of the initializer expression is required to be assignable // to the widened form of the type associated with the destructuring variable declaration, binding property, or binding element. var {g: {g1 = [undefined, null]}}: { g: { g1: any[] } } = { g: { g1: [1, 2] } }; +>g : Symbol(g, Decl(destructuringVariableDeclaration1ES5.ts, 37, 36)) >g1 : Symbol(g1, Decl(destructuringVariableDeclaration1ES5.ts, 37, 9)) >undefined : Symbol(undefined) >g : Symbol(g, Decl(destructuringVariableDeclaration1ES5.ts, 37, 36)) @@ -104,6 +109,7 @@ var {g: {g1 = [undefined, null]}}: { g: { g1: any[] } } = { g: { g1: [1, 2] } }; >g1 : Symbol(g1, Decl(destructuringVariableDeclaration1ES5.ts, 37, 64)) var {h: {h1 = [undefined, null]}}: { h: { h1: number[] } } = { h: { h1: [1, 2] } }; +>h : Symbol(h, Decl(destructuringVariableDeclaration1ES5.ts, 38, 36)) >h1 : Symbol(h1, Decl(destructuringVariableDeclaration1ES5.ts, 38, 9)) >undefined : Symbol(undefined) >h : Symbol(h, Decl(destructuringVariableDeclaration1ES5.ts, 38, 36)) diff --git a/tests/baselines/reference/destructuringVariableDeclaration1ES6.symbols b/tests/baselines/reference/destructuringVariableDeclaration1ES6.symbols index 0350ff35251..ee4f391eb7a 100644 --- a/tests/baselines/reference/destructuringVariableDeclaration1ES6.symbols +++ b/tests/baselines/reference/destructuringVariableDeclaration1ES6.symbols @@ -17,6 +17,7 @@ var [a3, [[a4]], a5]: [number, [[string]], boolean] = [1, [["hello"]], true]; // The type T associated with a destructuring variable declaration is determined as follows: // Otherwise, if the declaration includes an initializer expression, T is the type of that initializer expression. var { b1: { b11 } = { b11: "string" } } = { b1: { b11: "world" } }; +>b1 : Symbol(b1, Decl(destructuringVariableDeclaration1ES6.ts, 7, 44)) >b11 : Symbol(b11, Decl(destructuringVariableDeclaration1ES6.ts, 7, 11)) >b11 : Symbol(b11, Decl(destructuringVariableDeclaration1ES6.ts, 7, 21)) >b1 : Symbol(b1, Decl(destructuringVariableDeclaration1ES6.ts, 7, 44)) @@ -74,6 +75,7 @@ var [d3, d4] = [1, "string", ...temp1]; // Combining both forms of destructuring, var {e: [e1, e2, e3 = { b1: 1000, b4: 200 }]} = { e: [1, 2, { b1: 4, b4: 0 }] }; +>e : Symbol(e, Decl(destructuringVariableDeclaration1ES6.ts, 31, 49)) >e1 : Symbol(e1, Decl(destructuringVariableDeclaration1ES6.ts, 31, 9)) >e2 : Symbol(e2, Decl(destructuringVariableDeclaration1ES6.ts, 31, 12)) >e3 : Symbol(e3, Decl(destructuringVariableDeclaration1ES6.ts, 31, 16)) @@ -84,8 +86,10 @@ var {e: [e1, e2, e3 = { b1: 1000, b4: 200 }]} = { e: [1, 2, { b1: 4, b4: 0 }] }; >b4 : Symbol(b4, Decl(destructuringVariableDeclaration1ES6.ts, 31, 68)) var {f: [f1, f2, { f3: f4, f5 }, , ]} = { f: [1, 2, { f3: 4, f5: 0 }] }; +>f : Symbol(f, Decl(destructuringVariableDeclaration1ES6.ts, 32, 41)) >f1 : Symbol(f1, Decl(destructuringVariableDeclaration1ES6.ts, 32, 9)) >f2 : Symbol(f2, Decl(destructuringVariableDeclaration1ES6.ts, 32, 12)) +>f3 : Symbol(f3, Decl(destructuringVariableDeclaration1ES6.ts, 32, 53)) >f4 : Symbol(f4, Decl(destructuringVariableDeclaration1ES6.ts, 32, 18)) >f5 : Symbol(f5, Decl(destructuringVariableDeclaration1ES6.ts, 32, 26)) >f : Symbol(f, Decl(destructuringVariableDeclaration1ES6.ts, 32, 41)) @@ -96,6 +100,7 @@ var {f: [f1, f2, { f3: f4, f5 }, , ]} = { f: [1, 2, { f3: 4, f5: 0 }] }; // an initializer expression, the type of the initializer expression is required to be assignable // to the widened form of the type associated with the destructuring variable declaration, binding property, or binding element. var {g: {g1 = [undefined, null]}}: { g: { g1: any[] } } = { g: { g1: [1, 2] } }; +>g : Symbol(g, Decl(destructuringVariableDeclaration1ES6.ts, 37, 36)) >g1 : Symbol(g1, Decl(destructuringVariableDeclaration1ES6.ts, 37, 9)) >undefined : Symbol(undefined) >g : Symbol(g, Decl(destructuringVariableDeclaration1ES6.ts, 37, 36)) @@ -104,6 +109,7 @@ var {g: {g1 = [undefined, null]}}: { g: { g1: any[] } } = { g: { g1: [1, 2] } }; >g1 : Symbol(g1, Decl(destructuringVariableDeclaration1ES6.ts, 37, 64)) var {h: {h1 = [undefined, null]}}: { h: { h1: number[] } } = { h: { h1: [1, 2] } }; +>h : Symbol(h, Decl(destructuringVariableDeclaration1ES6.ts, 38, 36)) >h1 : Symbol(h1, Decl(destructuringVariableDeclaration1ES6.ts, 38, 9)) >undefined : Symbol(undefined) >h : Symbol(h, Decl(destructuringVariableDeclaration1ES6.ts, 38, 36)) diff --git a/tests/baselines/reference/downlevelLetConst12.symbols b/tests/baselines/reference/downlevelLetConst12.symbols index d1c7fe3ea5b..97d6d5eebf8 100644 --- a/tests/baselines/reference/downlevelLetConst12.symbols +++ b/tests/baselines/reference/downlevelLetConst12.symbols @@ -12,6 +12,7 @@ let [baz] = []; >baz : Symbol(baz, Decl(downlevelLetConst12.ts, 6, 5)) let {a: baz2} = { a: 1 }; +>a : Symbol(a, Decl(downlevelLetConst12.ts, 7, 17)) >baz2 : Symbol(baz2, Decl(downlevelLetConst12.ts, 7, 5)) >a : Symbol(a, Decl(downlevelLetConst12.ts, 7, 17)) @@ -19,6 +20,7 @@ const [baz3] = [] >baz3 : Symbol(baz3, Decl(downlevelLetConst12.ts, 9, 7)) const {a: baz4} = { a: 1 }; +>a : Symbol(a, Decl(downlevelLetConst12.ts, 10, 19)) >baz4 : Symbol(baz4, Decl(downlevelLetConst12.ts, 10, 7)) >a : Symbol(a, Decl(downlevelLetConst12.ts, 10, 19)) diff --git a/tests/baselines/reference/downlevelLetConst13.symbols b/tests/baselines/reference/downlevelLetConst13.symbols index 1b06184f2b3..f8cd2e548a9 100644 --- a/tests/baselines/reference/downlevelLetConst13.symbols +++ b/tests/baselines/reference/downlevelLetConst13.symbols @@ -16,10 +16,12 @@ export const [bar2] = [2]; >bar2 : Symbol(bar2, Decl(downlevelLetConst13.ts, 7, 14)) export let {a: bar3} = { a: 1 }; +>a : Symbol(a, Decl(downlevelLetConst13.ts, 8, 24)) >bar3 : Symbol(bar3, Decl(downlevelLetConst13.ts, 8, 12)) >a : Symbol(a, Decl(downlevelLetConst13.ts, 8, 24)) export const {a: bar4} = { a: 1 }; +>a : Symbol(a, Decl(downlevelLetConst13.ts, 9, 26)) >bar4 : Symbol(bar4, Decl(downlevelLetConst13.ts, 9, 14)) >a : Symbol(a, Decl(downlevelLetConst13.ts, 9, 26)) @@ -39,10 +41,12 @@ export module M { >bar6 : Symbol(bar6, Decl(downlevelLetConst13.ts, 15, 18)) export let {a: bar7} = { a: 1 }; +>a : Symbol(a, Decl(downlevelLetConst13.ts, 16, 28)) >bar7 : Symbol(bar7, Decl(downlevelLetConst13.ts, 16, 16)) >a : Symbol(a, Decl(downlevelLetConst13.ts, 16, 28)) export const {a: bar8} = { a: 1 }; +>a : Symbol(a, Decl(downlevelLetConst13.ts, 17, 30)) >bar8 : Symbol(bar8, Decl(downlevelLetConst13.ts, 17, 18)) >a : Symbol(a, Decl(downlevelLetConst13.ts, 17, 30)) } diff --git a/tests/baselines/reference/downlevelLetConst14.symbols b/tests/baselines/reference/downlevelLetConst14.symbols index bf3450af71c..135f3c1417d 100644 --- a/tests/baselines/reference/downlevelLetConst14.symbols +++ b/tests/baselines/reference/downlevelLetConst14.symbols @@ -35,6 +35,7 @@ var z0, z1, z2, z3; >z1 : Symbol(z1, Decl(downlevelLetConst14.ts, 11, 9)) let {a: z2} = { a: 1 }; +>a : Symbol(a, Decl(downlevelLetConst14.ts, 13, 19)) >z2 : Symbol(z2, Decl(downlevelLetConst14.ts, 13, 9)) >a : Symbol(a, Decl(downlevelLetConst14.ts, 13, 19)) @@ -43,6 +44,7 @@ var z0, z1, z2, z3; >z2 : Symbol(z2, Decl(downlevelLetConst14.ts, 13, 9)) let {a: z3} = { a: 1 }; +>a : Symbol(a, Decl(downlevelLetConst14.ts, 15, 19)) >z3 : Symbol(z3, Decl(downlevelLetConst14.ts, 15, 9)) >a : Symbol(a, Decl(downlevelLetConst14.ts, 15, 19)) @@ -86,6 +88,7 @@ var y = true; >y : Symbol(y, Decl(downlevelLetConst14.ts, 29, 11)) let {a: z6} = {a: 1} +>a : Symbol(a, Decl(downlevelLetConst14.ts, 30, 23)) >z6 : Symbol(z6, Decl(downlevelLetConst14.ts, 30, 13)) >a : Symbol(a, Decl(downlevelLetConst14.ts, 30, 23)) @@ -129,6 +132,7 @@ var z5 = 1; >_z : Symbol(_z, Decl(downlevelLetConst14.ts, 46, 11)) let {a: _z5} = { a: 1 }; +>a : Symbol(a, Decl(downlevelLetConst14.ts, 47, 24)) >_z5 : Symbol(_z5, Decl(downlevelLetConst14.ts, 47, 13)) >a : Symbol(a, Decl(downlevelLetConst14.ts, 47, 24)) diff --git a/tests/baselines/reference/downlevelLetConst15.symbols b/tests/baselines/reference/downlevelLetConst15.symbols index 159e5a6d676..00c7e122eb2 100644 --- a/tests/baselines/reference/downlevelLetConst15.symbols +++ b/tests/baselines/reference/downlevelLetConst15.symbols @@ -28,6 +28,7 @@ var z0, z1, z2, z3; >z0 : Symbol(z0, Decl(downlevelLetConst15.ts, 9, 11)) const [{a: z1}] = [{a: 1}] +>a : Symbol(a, Decl(downlevelLetConst15.ts, 11, 24)) >z1 : Symbol(z1, Decl(downlevelLetConst15.ts, 11, 12)) >a : Symbol(a, Decl(downlevelLetConst15.ts, 11, 24)) @@ -36,6 +37,7 @@ var z0, z1, z2, z3; >z1 : Symbol(z1, Decl(downlevelLetConst15.ts, 11, 12)) const {a: z2} = { a: 1 }; +>a : Symbol(a, Decl(downlevelLetConst15.ts, 13, 21)) >z2 : Symbol(z2, Decl(downlevelLetConst15.ts, 13, 11)) >a : Symbol(a, Decl(downlevelLetConst15.ts, 13, 21)) @@ -44,6 +46,8 @@ var z0, z1, z2, z3; >z2 : Symbol(z2, Decl(downlevelLetConst15.ts, 13, 11)) const {a: {b: z3}} = { a: {b: 1} }; +>a : Symbol(a, Decl(downlevelLetConst15.ts, 15, 26)) +>b : Symbol(b, Decl(downlevelLetConst15.ts, 15, 31)) >z3 : Symbol(z3, Decl(downlevelLetConst15.ts, 15, 15)) >a : Symbol(a, Decl(downlevelLetConst15.ts, 15, 26)) >b : Symbol(b, Decl(downlevelLetConst15.ts, 15, 31)) @@ -88,6 +92,7 @@ var y = true; >y : Symbol(y, Decl(downlevelLetConst15.ts, 29, 13)) const {a: z6} = { a: 1 } +>a : Symbol(a, Decl(downlevelLetConst15.ts, 30, 25)) >z6 : Symbol(z6, Decl(downlevelLetConst15.ts, 30, 15)) >a : Symbol(a, Decl(downlevelLetConst15.ts, 30, 25)) @@ -131,6 +136,7 @@ var z5 = 1; >_z : Symbol(_z, Decl(downlevelLetConst15.ts, 46, 13)) const {a: _z5} = { a: 1 }; +>a : Symbol(a, Decl(downlevelLetConst15.ts, 47, 26)) >_z5 : Symbol(_z5, Decl(downlevelLetConst15.ts, 47, 15)) >a : Symbol(a, Decl(downlevelLetConst15.ts, 47, 26)) diff --git a/tests/baselines/reference/emitArrowFunctionWhenUsingArguments18_ES6.symbols b/tests/baselines/reference/emitArrowFunctionWhenUsingArguments18_ES6.symbols index 4d0887c1ff8..eb24f638884 100644 --- a/tests/baselines/reference/emitArrowFunctionWhenUsingArguments18_ES6.symbols +++ b/tests/baselines/reference/emitArrowFunctionWhenUsingArguments18_ES6.symbols @@ -4,6 +4,7 @@ function f() { >f : Symbol(f, Decl(emitArrowFunctionWhenUsingArguments18_ES6.ts, 0, 0)) var { arguments: args } = { arguments }; +>arguments : Symbol(arguments, Decl(emitArrowFunctionWhenUsingArguments18_ES6.ts, 2, 31)) >args : Symbol(args, Decl(emitArrowFunctionWhenUsingArguments18_ES6.ts, 2, 9)) >arguments : Symbol(arguments, Decl(emitArrowFunctionWhenUsingArguments18_ES6.ts, 2, 31)) diff --git a/tests/baselines/reference/for-of41.symbols b/tests/baselines/reference/for-of41.symbols index cf8db913919..046361653bb 100644 --- a/tests/baselines/reference/for-of41.symbols +++ b/tests/baselines/reference/for-of41.symbols @@ -6,7 +6,9 @@ var array = [{x: [0], y: {p: ""}}] >p : Symbol(p, Decl(for-of41.ts, 0, 26)) for (var {x: [a], y: {p}} of array) { +>x : Symbol(x, Decl(for-of41.ts, 0, 14)) >a : Symbol(a, Decl(for-of41.ts, 1, 14)) +>y : Symbol(y, Decl(for-of41.ts, 0, 21)) >p : Symbol(p, Decl(for-of41.ts, 1, 22)) >array : Symbol(array, Decl(for-of41.ts, 0, 3)) diff --git a/tests/baselines/reference/for-of42.symbols b/tests/baselines/reference/for-of42.symbols index b310fb1044f..5310f4970b9 100644 --- a/tests/baselines/reference/for-of42.symbols +++ b/tests/baselines/reference/for-of42.symbols @@ -5,7 +5,9 @@ var array = [{ x: "", y: 0 }] >y : Symbol(y, Decl(for-of42.ts, 0, 21)) for (var {x: a, y: b} of array) { +>x : Symbol(x, Decl(for-of42.ts, 0, 14)) >a : Symbol(a, Decl(for-of42.ts, 1, 10)) +>y : Symbol(y, Decl(for-of42.ts, 0, 21)) >b : Symbol(b, Decl(for-of42.ts, 1, 15)) >array : Symbol(array, Decl(for-of42.ts, 0, 3)) diff --git a/tests/baselines/reference/initializePropertiesWithRenamedLet.symbols b/tests/baselines/reference/initializePropertiesWithRenamedLet.symbols index 203508ddf98..f16d8cfc9e0 100644 --- a/tests/baselines/reference/initializePropertiesWithRenamedLet.symbols +++ b/tests/baselines/reference/initializePropertiesWithRenamedLet.symbols @@ -24,6 +24,7 @@ var x, y, z; if (true) { let { x: x } = { x: 0 }; +>x : Symbol(x, Decl(initializePropertiesWithRenamedLet.ts, 10, 20)) >x : Symbol(x, Decl(initializePropertiesWithRenamedLet.ts, 10, 9)) >x : Symbol(x, Decl(initializePropertiesWithRenamedLet.ts, 10, 20)) diff --git a/tests/baselines/reference/letInNonStrictMode.symbols b/tests/baselines/reference/letInNonStrictMode.symbols index 2b854a8c03f..47ba4465d1b 100644 --- a/tests/baselines/reference/letInNonStrictMode.symbols +++ b/tests/baselines/reference/letInNonStrictMode.symbols @@ -3,6 +3,7 @@ let [x] = [1]; >x : Symbol(x, Decl(letInNonStrictMode.ts, 0, 5)) let {a: y} = {a: 1}; +>a : Symbol(a, Decl(letInNonStrictMode.ts, 1, 14)) >y : Symbol(y, Decl(letInNonStrictMode.ts, 1, 5)) >a : Symbol(a, Decl(letInNonStrictMode.ts, 1, 14)) diff --git a/tests/baselines/reference/objectBindingPatternKeywordIdentifiers06.symbols b/tests/baselines/reference/objectBindingPatternKeywordIdentifiers06.symbols index 7cee5f3009b..f0546012498 100644 --- a/tests/baselines/reference/objectBindingPatternKeywordIdentifiers06.symbols +++ b/tests/baselines/reference/objectBindingPatternKeywordIdentifiers06.symbols @@ -1,6 +1,7 @@ === tests/cases/conformance/es6/destructuring/objectBindingPatternKeywordIdentifiers06.ts === var { as: as } = { as: 1 } +>as : Symbol(as, Decl(objectBindingPatternKeywordIdentifiers06.ts, 1, 18)) >as : Symbol(as, Decl(objectBindingPatternKeywordIdentifiers06.ts, 1, 5)) >as : Symbol(as, Decl(objectBindingPatternKeywordIdentifiers06.ts, 1, 18)) diff --git a/tests/baselines/reference/systemModule13.symbols b/tests/baselines/reference/systemModule13.symbols index d9e64335c2b..8245029e006 100644 --- a/tests/baselines/reference/systemModule13.symbols +++ b/tests/baselines/reference/systemModule13.symbols @@ -6,7 +6,10 @@ export let [x,y,z] = [1, 2, 3]; >z : Symbol(z, Decl(systemModule13.ts, 1, 16)) export const {a: z0, b: {c: z1}} = {a: true, b: {c: "123"}}; +>a : Symbol(a, Decl(systemModule13.ts, 2, 36)) >z0 : Symbol(z0, Decl(systemModule13.ts, 2, 14)) +>b : Symbol(b, Decl(systemModule13.ts, 2, 44)) +>c : Symbol(c, Decl(systemModule13.ts, 2, 49)) >z1 : Symbol(z1, Decl(systemModule13.ts, 2, 25)) >a : Symbol(a, Decl(systemModule13.ts, 2, 36)) >b : Symbol(b, Decl(systemModule13.ts, 2, 44)) diff --git a/tests/baselines/reference/systemModule8.symbols b/tests/baselines/reference/systemModule8.symbols index 3365ce7e37d..719d48e4592 100644 --- a/tests/baselines/reference/systemModule8.symbols +++ b/tests/baselines/reference/systemModule8.symbols @@ -78,7 +78,10 @@ export let [y] = [1]; >y : Symbol(y, Decl(systemModule8.ts, 27, 12)) export const {a: z0, b: {c: z1}} = {a: true, b: {c: "123"}}; +>a : Symbol(a, Decl(systemModule8.ts, 28, 36)) >z0 : Symbol(z0, Decl(systemModule8.ts, 28, 14)) +>b : Symbol(b, Decl(systemModule8.ts, 28, 44)) +>c : Symbol(c, Decl(systemModule8.ts, 28, 49)) >z1 : Symbol(z1, Decl(systemModule8.ts, 28, 25)) >a : Symbol(a, Decl(systemModule8.ts, 28, 36)) >b : Symbol(b, Decl(systemModule8.ts, 28, 44)) From e9d590f634b4d35061af87a282f6016007b57c8f Mon Sep 17 00:00:00 2001 From: vvakame Date: Thu, 25 Jun 2015 02:45:46 +0900 Subject: [PATCH 13/64] PR feedback --- src/compiler/emitter.ts | 37 ++++++++++--------- tests/baselines/reference/es5-commonjs.js | 4 +- tests/baselines/reference/es5-commonjs2.js | 8 ++++ .../baselines/reference/es5-commonjs2.symbols | 5 +++ tests/baselines/reference/es5-commonjs2.types | 5 +++ tests/baselines/reference/es5-commonjs3.js | 9 +++++ .../baselines/reference/es5-commonjs3.symbols | 6 +++ tests/baselines/reference/es5-commonjs3.types | 7 ++++ tests/baselines/reference/es5-commonjs4.js | 28 ++++++++++++++ .../baselines/reference/es5-commonjs4.symbols | 19 ++++++++++ tests/baselines/reference/es5-commonjs4.types | 21 +++++++++++ tests/baselines/reference/es5-commonjs5.js | 13 +++++++ .../baselines/reference/es5-commonjs5.symbols | 7 ++++ tests/baselines/reference/es5-commonjs5.types | 7 ++++ tests/baselines/reference/es5-umd3.js | 4 +- .../es5ExportDefaultClassDeclaration.js | 4 +- .../es5ExportDefaultClassDeclaration2.js | 4 +- .../es5ExportDefaultClassDeclaration3.js | 4 +- .../reference/es5ExportDefaultExpression.js | 1 + .../es5ExportDefaultFunctionDeclaration.js | 4 +- .../es5ExportDefaultFunctionDeclaration2.js | 4 +- .../es5ExportDefaultFunctionDeclaration3.js | 4 +- .../reference/es5ExportDefaultIdentifier.js | 1 + .../reference/es6ImportDefaultBindingAmd.js | 1 + .../reference/es6ImportDefaultBindingDts.js | 1 + ...ultBindingFollowedWithNamedImport1InEs5.js | 1 + ...ndingFollowedWithNamedImport1WithExport.js | 1 + ...faultBindingFollowedWithNamedImportDts1.js | 1 + ...indingFollowedWithNamedImportWithExport.js | 1 + ...ndingFollowedWithNamespaceBinding1InEs5.js | 1 + ...FollowedWithNamespaceBinding1WithExport.js | 1 + ...BindingFollowedWithNamespaceBindingDts1.js | 1 + .../es6ImportDefaultBindingMergeErrors.js | 1 + .../es6ImportDefaultBindingWithExport.js | 1 + .../reference/exportAndImport-es5-amd.js | 8 +--- .../reference/exportAndImport-es5.js | 8 +--- tests/baselines/reference/exportStar-amd.js | 1 + tests/baselines/reference/exportStar.js | 1 + .../reference/exportsAndImports4-amd.js | 1 + .../baselines/reference/exportsAndImports4.js | 1 + tests/cases/compiler/es5-commonjs2.ts | 6 +++ tests/cases/compiler/es5-commonjs3.ts | 7 ++++ tests/cases/compiler/es5-commonjs4.ts | 18 +++++++++ tests/cases/compiler/es5-commonjs5.ts | 8 ++++ 44 files changed, 223 insertions(+), 53 deletions(-) create mode 100644 tests/baselines/reference/es5-commonjs2.js create mode 100644 tests/baselines/reference/es5-commonjs2.symbols create mode 100644 tests/baselines/reference/es5-commonjs2.types create mode 100644 tests/baselines/reference/es5-commonjs3.js create mode 100644 tests/baselines/reference/es5-commonjs3.symbols create mode 100644 tests/baselines/reference/es5-commonjs3.types create mode 100644 tests/baselines/reference/es5-commonjs4.js create mode 100644 tests/baselines/reference/es5-commonjs4.symbols create mode 100644 tests/baselines/reference/es5-commonjs4.types create mode 100644 tests/baselines/reference/es5-commonjs5.js create mode 100644 tests/baselines/reference/es5-commonjs5.symbols create mode 100644 tests/baselines/reference/es5-commonjs5.types create mode 100644 tests/cases/compiler/es5-commonjs2.ts create mode 100644 tests/cases/compiler/es5-commonjs3.ts create mode 100644 tests/cases/compiler/es5-commonjs4.ts create mode 100644 tests/cases/compiler/es5-commonjs5.ts diff --git a/src/compiler/emitter.ts b/src/compiler/emitter.ts index 17c54c9eb0a..e57ff159f18 100644 --- a/src/compiler/emitter.ts +++ b/src/compiler/emitter.ts @@ -2687,6 +2687,22 @@ var __param = (this && this.__param) || function (paramIndex, decorator) { return result; } + function emitEs6ExportDefaultCompat() { + if (compilerOptions.module === ModuleKind.CommonJS || compilerOptions.module === ModuleKind.AMD || compilerOptions.module === ModuleKind.UMD) { + if (!hasProperty(currentSourceFile.identifiers, "___esModule")) { + if (languageVersion >= ScriptTarget.ES5) { + // default value of configurable, enumerable, writable are `false`. + write("Object.defineProperty(exports, \"__esModule\", { value: true });"); + writeLine(); + } + else { + write("exports.__esModule = true;"); + writeLine(); + } + } + } + } + function emitExportMemberAssignment(node: FunctionLikeDeclaration | ClassDeclaration) { if (node.flags & NodeFlags.Export) { writeLine(); @@ -2709,25 +2725,11 @@ var __param = (this && this.__param) || function (paramIndex, decorator) { } else { if (node.flags & NodeFlags.Default) { - if (compilerOptions.module === ModuleKind.CommonJS || compilerOptions.module === ModuleKind.AMD || compilerOptions.module === ModuleKind.UMD) { - if (languageVersion >= ScriptTarget.ES5) { - write("Object.defineProperty(exports, \"__esModule\", {"); - writeLine(); - increaseIndent(); - // default value of configurable, enumerable, writable are `false`. - write("value: true"); - writeLine(); - decreaseIndent(); - write("};"); - writeLine(); - } else { - write("exports.__esModule = true;"); - writeLine(); - } - } + emitEs6ExportDefaultCompat(); if (languageVersion === ScriptTarget.ES3) { write("exports[\"default\"]"); - } else { + } + else { write("exports.default"); } } @@ -4883,6 +4885,7 @@ var __param = (this && this.__param) || function (paramIndex, decorator) { write(")"); } else { + emitEs6ExportDefaultCompat(); emitContainingModuleName(node); if (languageVersion === ScriptTarget.ES3) { write("[\"default\"] = "); diff --git a/tests/baselines/reference/es5-commonjs.js b/tests/baselines/reference/es5-commonjs.js index e9f939dde31..2a0c6d924ca 100644 --- a/tests/baselines/reference/es5-commonjs.js +++ b/tests/baselines/reference/es5-commonjs.js @@ -23,7 +23,5 @@ var A = (function () { }; return A; })(); -Object.defineProperty(exports, "__esModule", { - value: true -}; +Object.defineProperty(exports, "__esModule", { value: true }); exports.default = A; diff --git a/tests/baselines/reference/es5-commonjs2.js b/tests/baselines/reference/es5-commonjs2.js new file mode 100644 index 00000000000..174665b4125 --- /dev/null +++ b/tests/baselines/reference/es5-commonjs2.js @@ -0,0 +1,8 @@ +//// [es5-commonjs2.ts] + +export default 1; + + +//// [es5-commonjs2.js] +Object.defineProperty(exports, "__esModule", { value: true }); +exports.default = 1; diff --git a/tests/baselines/reference/es5-commonjs2.symbols b/tests/baselines/reference/es5-commonjs2.symbols new file mode 100644 index 00000000000..ee57f9ad5cd --- /dev/null +++ b/tests/baselines/reference/es5-commonjs2.symbols @@ -0,0 +1,5 @@ +=== tests/cases/compiler/es5-commonjs2.ts === + +No type information for this code.export default 1; +No type information for this code. +No type information for this code. \ No newline at end of file diff --git a/tests/baselines/reference/es5-commonjs2.types b/tests/baselines/reference/es5-commonjs2.types new file mode 100644 index 00000000000..ee57f9ad5cd --- /dev/null +++ b/tests/baselines/reference/es5-commonjs2.types @@ -0,0 +1,5 @@ +=== tests/cases/compiler/es5-commonjs2.ts === + +No type information for this code.export default 1; +No type information for this code. +No type information for this code. \ No newline at end of file diff --git a/tests/baselines/reference/es5-commonjs3.js b/tests/baselines/reference/es5-commonjs3.js new file mode 100644 index 00000000000..cc3d0b1527a --- /dev/null +++ b/tests/baselines/reference/es5-commonjs3.js @@ -0,0 +1,9 @@ +//// [es5-commonjs3.ts] + +export default "test"; +export var __esModule = 1; + + +//// [es5-commonjs3.js] +exports.default = "test"; +exports.__esModule = 1; diff --git a/tests/baselines/reference/es5-commonjs3.symbols b/tests/baselines/reference/es5-commonjs3.symbols new file mode 100644 index 00000000000..9d5bc830099 --- /dev/null +++ b/tests/baselines/reference/es5-commonjs3.symbols @@ -0,0 +1,6 @@ +=== tests/cases/compiler/es5-commonjs3.ts === + +export default "test"; +export var __esModule = 1; +>__esModule : Symbol(__esModule, Decl(es5-commonjs3.ts, 2, 10)) + diff --git a/tests/baselines/reference/es5-commonjs3.types b/tests/baselines/reference/es5-commonjs3.types new file mode 100644 index 00000000000..facdfae00ce --- /dev/null +++ b/tests/baselines/reference/es5-commonjs3.types @@ -0,0 +1,7 @@ +=== tests/cases/compiler/es5-commonjs3.ts === + +export default "test"; +export var __esModule = 1; +>__esModule : number +>1 : number + diff --git a/tests/baselines/reference/es5-commonjs4.js b/tests/baselines/reference/es5-commonjs4.js new file mode 100644 index 00000000000..50a4c49e464 --- /dev/null +++ b/tests/baselines/reference/es5-commonjs4.js @@ -0,0 +1,28 @@ +//// [es5-commonjs4.ts] + +export default class A +{ + constructor () + { + + } + + public B() + { + return 42; + } +} +export var __esModule = 1; + + +//// [es5-commonjs4.js] +var A = (function () { + function A() { + } + A.prototype.B = function () { + return 42; + }; + return A; +})(); +exports.default = A; +exports.__esModule = 1; diff --git a/tests/baselines/reference/es5-commonjs4.symbols b/tests/baselines/reference/es5-commonjs4.symbols new file mode 100644 index 00000000000..22d41128d74 --- /dev/null +++ b/tests/baselines/reference/es5-commonjs4.symbols @@ -0,0 +1,19 @@ +=== tests/cases/compiler/es5-commonjs4.ts === + +export default class A +>A : Symbol(A, Decl(es5-commonjs4.ts, 0, 0)) +{ + constructor () + { + + } + + public B() +>B : Symbol(B, Decl(es5-commonjs4.ts, 6, 5)) + { + return 42; + } +} +export var __esModule = 1; +>__esModule : Symbol(__esModule, Decl(es5-commonjs4.ts, 13, 10)) + diff --git a/tests/baselines/reference/es5-commonjs4.types b/tests/baselines/reference/es5-commonjs4.types new file mode 100644 index 00000000000..d3471afbfeb --- /dev/null +++ b/tests/baselines/reference/es5-commonjs4.types @@ -0,0 +1,21 @@ +=== tests/cases/compiler/es5-commonjs4.ts === + +export default class A +>A : A +{ + constructor () + { + + } + + public B() +>B : () => number + { + return 42; +>42 : number + } +} +export var __esModule = 1; +>__esModule : number +>1 : number + diff --git a/tests/baselines/reference/es5-commonjs5.js b/tests/baselines/reference/es5-commonjs5.js new file mode 100644 index 00000000000..ead6079eff1 --- /dev/null +++ b/tests/baselines/reference/es5-commonjs5.js @@ -0,0 +1,13 @@ +//// [es5-commonjs5.ts] + +export default function () { + return "test"; +} + + +//// [es5-commonjs5.js] +function default_1() { + return "test"; +} +Object.defineProperty(exports, "__esModule", { value: true }); +exports.default = default_1; diff --git a/tests/baselines/reference/es5-commonjs5.symbols b/tests/baselines/reference/es5-commonjs5.symbols new file mode 100644 index 00000000000..b134e216668 --- /dev/null +++ b/tests/baselines/reference/es5-commonjs5.symbols @@ -0,0 +1,7 @@ +=== tests/cases/compiler/es5-commonjs5.ts === + +No type information for this code.export default function () { +No type information for this code. return "test"; +No type information for this code.} +No type information for this code. +No type information for this code. \ No newline at end of file diff --git a/tests/baselines/reference/es5-commonjs5.types b/tests/baselines/reference/es5-commonjs5.types new file mode 100644 index 00000000000..d8094e1e0ea --- /dev/null +++ b/tests/baselines/reference/es5-commonjs5.types @@ -0,0 +1,7 @@ +=== tests/cases/compiler/es5-commonjs5.ts === + +export default function () { + return "test"; +>"test" : string +} + diff --git a/tests/baselines/reference/es5-umd3.js b/tests/baselines/reference/es5-umd3.js index b823ab67f18..92ac306698a 100644 --- a/tests/baselines/reference/es5-umd3.js +++ b/tests/baselines/reference/es5-umd3.js @@ -31,8 +31,6 @@ export default class A }; return A; })(); - Object.defineProperty(exports, "__esModule", { - value: true - }; + Object.defineProperty(exports, "__esModule", { value: true }); exports.default = A; }); diff --git a/tests/baselines/reference/es5ExportDefaultClassDeclaration.js b/tests/baselines/reference/es5ExportDefaultClassDeclaration.js index b38a4ff1861..0d4076e39a1 100644 --- a/tests/baselines/reference/es5ExportDefaultClassDeclaration.js +++ b/tests/baselines/reference/es5ExportDefaultClassDeclaration.js @@ -12,9 +12,7 @@ var C = (function () { C.prototype.method = function () { }; return C; })(); -Object.defineProperty(exports, "__esModule", { - value: true -}; +Object.defineProperty(exports, "__esModule", { value: true }); exports.default = C; diff --git a/tests/baselines/reference/es5ExportDefaultClassDeclaration2.js b/tests/baselines/reference/es5ExportDefaultClassDeclaration2.js index 4bddd5cd522..5e5eeae1f0f 100644 --- a/tests/baselines/reference/es5ExportDefaultClassDeclaration2.js +++ b/tests/baselines/reference/es5ExportDefaultClassDeclaration2.js @@ -12,9 +12,7 @@ var default_1 = (function () { default_1.prototype.method = function () { }; return default_1; })(); -Object.defineProperty(exports, "__esModule", { - value: true -}; +Object.defineProperty(exports, "__esModule", { value: true }); exports.default = default_1; diff --git a/tests/baselines/reference/es5ExportDefaultClassDeclaration3.js b/tests/baselines/reference/es5ExportDefaultClassDeclaration3.js index be7b094852d..a977447f9ad 100644 --- a/tests/baselines/reference/es5ExportDefaultClassDeclaration3.js +++ b/tests/baselines/reference/es5ExportDefaultClassDeclaration3.js @@ -24,9 +24,7 @@ var C = (function () { }; return C; })(); -Object.defineProperty(exports, "__esModule", { - value: true -}; +Object.defineProperty(exports, "__esModule", { value: true }); exports.default = C; var after = new C(); var t = C; diff --git a/tests/baselines/reference/es5ExportDefaultExpression.js b/tests/baselines/reference/es5ExportDefaultExpression.js index 944b6fc71a5..a825e45971b 100644 --- a/tests/baselines/reference/es5ExportDefaultExpression.js +++ b/tests/baselines/reference/es5ExportDefaultExpression.js @@ -4,6 +4,7 @@ export default (1 + 2); //// [es5ExportDefaultExpression.js] +Object.defineProperty(exports, "__esModule", { value: true }); exports.default = (1 + 2); diff --git a/tests/baselines/reference/es5ExportDefaultFunctionDeclaration.js b/tests/baselines/reference/es5ExportDefaultFunctionDeclaration.js index 24e514a13da..afc44ac53f5 100644 --- a/tests/baselines/reference/es5ExportDefaultFunctionDeclaration.js +++ b/tests/baselines/reference/es5ExportDefaultFunctionDeclaration.js @@ -5,9 +5,7 @@ export default function f() { } //// [es5ExportDefaultFunctionDeclaration.js] function f() { } -Object.defineProperty(exports, "__esModule", { - value: true -}; +Object.defineProperty(exports, "__esModule", { value: true }); exports.default = f; diff --git a/tests/baselines/reference/es5ExportDefaultFunctionDeclaration2.js b/tests/baselines/reference/es5ExportDefaultFunctionDeclaration2.js index 637a780ddf6..10f1db6a0eb 100644 --- a/tests/baselines/reference/es5ExportDefaultFunctionDeclaration2.js +++ b/tests/baselines/reference/es5ExportDefaultFunctionDeclaration2.js @@ -5,9 +5,7 @@ export default function () { } //// [es5ExportDefaultFunctionDeclaration2.js] function default_1() { } -Object.defineProperty(exports, "__esModule", { - value: true -}; +Object.defineProperty(exports, "__esModule", { value: true }); exports.default = default_1; diff --git a/tests/baselines/reference/es5ExportDefaultFunctionDeclaration3.js b/tests/baselines/reference/es5ExportDefaultFunctionDeclaration3.js index 1340d239169..af437c08766 100644 --- a/tests/baselines/reference/es5ExportDefaultFunctionDeclaration3.js +++ b/tests/baselines/reference/es5ExportDefaultFunctionDeclaration3.js @@ -13,9 +13,7 @@ var before = func(); function func() { return func; } -Object.defineProperty(exports, "__esModule", { - value: true -}; +Object.defineProperty(exports, "__esModule", { value: true }); exports.default = func; var after = func(); diff --git a/tests/baselines/reference/es5ExportDefaultIdentifier.js b/tests/baselines/reference/es5ExportDefaultIdentifier.js index 739f3d6c109..c8fb6b3be27 100644 --- a/tests/baselines/reference/es5ExportDefaultIdentifier.js +++ b/tests/baselines/reference/es5ExportDefaultIdentifier.js @@ -8,6 +8,7 @@ export default f; //// [es5ExportDefaultIdentifier.js] function f() { } exports.f = f; +Object.defineProperty(exports, "__esModule", { value: true }); exports.default = f; diff --git a/tests/baselines/reference/es6ImportDefaultBindingAmd.js b/tests/baselines/reference/es6ImportDefaultBindingAmd.js index 70e4f7e2f57..9c8cbec9db5 100644 --- a/tests/baselines/reference/es6ImportDefaultBindingAmd.js +++ b/tests/baselines/reference/es6ImportDefaultBindingAmd.js @@ -14,6 +14,7 @@ import defaultBinding2 from "es6ImportDefaultBindingAmd_0"; // elide this import //// [es6ImportDefaultBindingAmd_0.js] define(["require", "exports"], function (require, exports) { var a = 10; + Object.defineProperty(exports, "__esModule", { value: true }); exports.default = a; }); //// [es6ImportDefaultBindingAmd_1.js] diff --git a/tests/baselines/reference/es6ImportDefaultBindingDts.js b/tests/baselines/reference/es6ImportDefaultBindingDts.js index caa46ed30ef..a5e8d509da1 100644 --- a/tests/baselines/reference/es6ImportDefaultBindingDts.js +++ b/tests/baselines/reference/es6ImportDefaultBindingDts.js @@ -17,6 +17,7 @@ var c = (function () { } return c; })(); +Object.defineProperty(exports, "__esModule", { value: true }); exports.default = c; //// [client.js] var server_1 = require("server"); diff --git a/tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamedImport1InEs5.js b/tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamedImport1InEs5.js index 15ca1284a1e..7090b7a0663 100644 --- a/tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamedImport1InEs5.js +++ b/tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamedImport1InEs5.js @@ -22,6 +22,7 @@ var x: number = defaultBinding6; //// [es6ImportDefaultBindingFollowedWithNamedImport1InEs5_0.js] var a = 10; +Object.defineProperty(exports, "__esModule", { value: true }); exports.default = a; //// [es6ImportDefaultBindingFollowedWithNamedImport1InEs5_1.js] var es6ImportDefaultBindingFollowedWithNamedImport1InEs5_0_1 = require("es6ImportDefaultBindingFollowedWithNamedImport1InEs5_0"); diff --git a/tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamedImport1WithExport.js b/tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamedImport1WithExport.js index b6b03176df1..2b0e3ebbeb5 100644 --- a/tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamedImport1WithExport.js +++ b/tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamedImport1WithExport.js @@ -22,6 +22,7 @@ export var x1: number = defaultBinding6; //// [server.js] var a = 10; +Object.defineProperty(exports, "__esModule", { value: true }); exports.default = a; //// [client.js] var server_1 = require("server"); diff --git a/tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamedImportDts1.js b/tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamedImportDts1.js index e6211ac1ebe..dad034c618c 100644 --- a/tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamedImportDts1.js +++ b/tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamedImportDts1.js @@ -25,6 +25,7 @@ var a = (function () { } return a; })(); +Object.defineProperty(exports, "__esModule", { value: true }); exports.default = a; //// [client.js] var server_1 = require("server"); diff --git a/tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamedImportWithExport.js b/tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamedImportWithExport.js index 90521007735..b7da05d7dbb 100644 --- a/tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamedImportWithExport.js +++ b/tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamedImportWithExport.js @@ -27,6 +27,7 @@ define(["require", "exports"], function (require, exports) { exports.a = 10; exports.x = exports.a; exports.m = exports.a; + Object.defineProperty(exports, "__esModule", { value: true }); exports.default = {}; }); //// [client.js] diff --git a/tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamespaceBinding1InEs5.js b/tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamespaceBinding1InEs5.js index c2bd5476a7c..4a987110224 100644 --- a/tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamespaceBinding1InEs5.js +++ b/tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamespaceBinding1InEs5.js @@ -11,6 +11,7 @@ var x: number = defaultBinding; //// [es6ImportDefaultBindingFollowedWithNamespaceBindingInEs5_0.js] var a = 10; +Object.defineProperty(exports, "__esModule", { value: true }); exports.default = a; //// [es6ImportDefaultBindingFollowedWithNamespaceBindingInEs5_1.js] var es6ImportDefaultBindingFollowedWithNamespaceBindingInEs5_0_1 = require("es6ImportDefaultBindingFollowedWithNamespaceBindingInEs5_0"), nameSpaceBinding = es6ImportDefaultBindingFollowedWithNamespaceBindingInEs5_0_1; diff --git a/tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamespaceBinding1WithExport.js b/tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamespaceBinding1WithExport.js index ed40582e923..a032325fbb4 100644 --- a/tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamespaceBinding1WithExport.js +++ b/tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamespaceBinding1WithExport.js @@ -12,6 +12,7 @@ export var x: number = defaultBinding; //// [server.js] define(["require", "exports"], function (require, exports) { var a = 10; + Object.defineProperty(exports, "__esModule", { value: true }); exports.default = a; }); //// [client.js] diff --git a/tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamespaceBindingDts1.js b/tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamespaceBindingDts1.js index e03ded5fd5a..639ffce59fd 100644 --- a/tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamespaceBindingDts1.js +++ b/tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamespaceBindingDts1.js @@ -16,6 +16,7 @@ define(["require", "exports"], function (require, exports) { } return a; })(); + Object.defineProperty(exports, "__esModule", { value: true }); exports.default = a; }); //// [client.js] diff --git a/tests/baselines/reference/es6ImportDefaultBindingMergeErrors.js b/tests/baselines/reference/es6ImportDefaultBindingMergeErrors.js index 1208ace5dde..10b8bec03c7 100644 --- a/tests/baselines/reference/es6ImportDefaultBindingMergeErrors.js +++ b/tests/baselines/reference/es6ImportDefaultBindingMergeErrors.js @@ -18,6 +18,7 @@ import defaultBinding3 from "es6ImportDefaultBindingMergeErrors_0"; // SHould be //// [es6ImportDefaultBindingMergeErrors_0.js] var a = 10; +Object.defineProperty(exports, "__esModule", { value: true }); exports.default = a; //// [es6ImportDefaultBindingMergeErrors_1.js] var es6ImportDefaultBindingMergeErrors_0_1 = require("es6ImportDefaultBindingMergeErrors_0"); diff --git a/tests/baselines/reference/es6ImportDefaultBindingWithExport.js b/tests/baselines/reference/es6ImportDefaultBindingWithExport.js index e2c5fab4c94..2fb7f0644b9 100644 --- a/tests/baselines/reference/es6ImportDefaultBindingWithExport.js +++ b/tests/baselines/reference/es6ImportDefaultBindingWithExport.js @@ -13,6 +13,7 @@ export import defaultBinding2 from "server"; // non referenced //// [server.js] define(["require", "exports"], function (require, exports) { var a = 10; + Object.defineProperty(exports, "__esModule", { value: true }); exports.default = a; }); //// [client.js] diff --git a/tests/baselines/reference/exportAndImport-es5-amd.js b/tests/baselines/reference/exportAndImport-es5-amd.js index 771405a3b4c..447356b1230 100644 --- a/tests/baselines/reference/exportAndImport-es5-amd.js +++ b/tests/baselines/reference/exportAndImport-es5-amd.js @@ -16,9 +16,7 @@ export default function f2() { define(["require", "exports"], function (require, exports) { function f1() { } - Object.defineProperty(exports, "__esModule", { - value: true - }; + Object.defineProperty(exports, "__esModule", { value: true }); exports.default = f1; }); //// [m2.js] @@ -26,8 +24,6 @@ define(["require", "exports", "./m1"], function (require, exports, m1_1) { function f2() { m1_1.default(); } - Object.defineProperty(exports, "__esModule", { - value: true - }; + Object.defineProperty(exports, "__esModule", { value: true }); exports.default = f2; }); diff --git a/tests/baselines/reference/exportAndImport-es5.js b/tests/baselines/reference/exportAndImport-es5.js index 9662e91be3b..c0bacb94aee 100644 --- a/tests/baselines/reference/exportAndImport-es5.js +++ b/tests/baselines/reference/exportAndImport-es5.js @@ -15,16 +15,12 @@ export default function f2() { //// [m1.js] function f1() { } -Object.defineProperty(exports, "__esModule", { - value: true -}; +Object.defineProperty(exports, "__esModule", { value: true }); exports.default = f1; //// [m2.js] var m1_1 = require("./m1"); function f2() { m1_1.default(); } -Object.defineProperty(exports, "__esModule", { - value: true -}; +Object.defineProperty(exports, "__esModule", { value: true }); exports.default = f2; diff --git a/tests/baselines/reference/exportStar-amd.js b/tests/baselines/reference/exportStar-amd.js index dcd2d126a35..534a23b4d5b 100644 --- a/tests/baselines/reference/exportStar-amd.js +++ b/tests/baselines/reference/exportStar-amd.js @@ -36,6 +36,7 @@ define(["require", "exports"], function (require, exports) { }); //// [t2.js] define(["require", "exports"], function (require, exports) { + Object.defineProperty(exports, "__esModule", { value: true }); exports.default = "hello"; function foo() { } exports.foo = foo; diff --git a/tests/baselines/reference/exportStar.js b/tests/baselines/reference/exportStar.js index d219a3650e7..74cf24a0f97 100644 --- a/tests/baselines/reference/exportStar.js +++ b/tests/baselines/reference/exportStar.js @@ -33,6 +33,7 @@ foo; exports.x = 1; exports.y = 2; //// [t2.js] +Object.defineProperty(exports, "__esModule", { value: true }); exports.default = "hello"; function foo() { } exports.foo = foo; diff --git a/tests/baselines/reference/exportsAndImports4-amd.js b/tests/baselines/reference/exportsAndImports4-amd.js index db28ed5b350..e6a431854b2 100644 --- a/tests/baselines/reference/exportsAndImports4-amd.js +++ b/tests/baselines/reference/exportsAndImports4-amd.js @@ -41,6 +41,7 @@ export { a, b, c, d, e1, e2, f1, f2 }; //// [t1.js] define(["require", "exports"], function (require, exports) { + Object.defineProperty(exports, "__esModule", { value: true }); exports.default = "hello"; }); //// [t3.js] diff --git a/tests/baselines/reference/exportsAndImports4.js b/tests/baselines/reference/exportsAndImports4.js index ea5f34b882b..7358b31eace 100644 --- a/tests/baselines/reference/exportsAndImports4.js +++ b/tests/baselines/reference/exportsAndImports4.js @@ -40,6 +40,7 @@ export { a, b, c, d, e1, e2, f1, f2 }; //// [t1.js] +Object.defineProperty(exports, "__esModule", { value: true }); exports.default = "hello"; //// [t3.js] var a = require("./t1"); diff --git a/tests/cases/compiler/es5-commonjs2.ts b/tests/cases/compiler/es5-commonjs2.ts new file mode 100644 index 00000000000..c6b404c7ef5 --- /dev/null +++ b/tests/cases/compiler/es5-commonjs2.ts @@ -0,0 +1,6 @@ +// @target: ES5 +// @sourcemap: false +// @declaration: false +// @module: commonjs + +export default 1; diff --git a/tests/cases/compiler/es5-commonjs3.ts b/tests/cases/compiler/es5-commonjs3.ts new file mode 100644 index 00000000000..54f2c9ac6fe --- /dev/null +++ b/tests/cases/compiler/es5-commonjs3.ts @@ -0,0 +1,7 @@ +// @target: ES5 +// @sourcemap: false +// @declaration: false +// @module: commonjs + +export default "test"; +export var __esModule = 1; diff --git a/tests/cases/compiler/es5-commonjs4.ts b/tests/cases/compiler/es5-commonjs4.ts new file mode 100644 index 00000000000..ce4f8ef6883 --- /dev/null +++ b/tests/cases/compiler/es5-commonjs4.ts @@ -0,0 +1,18 @@ +// @target: ES5 +// @sourcemap: false +// @declaration: false +// @module: commonjs + +export default class A +{ + constructor () + { + + } + + public B() + { + return 42; + } +} +export var __esModule = 1; diff --git a/tests/cases/compiler/es5-commonjs5.ts b/tests/cases/compiler/es5-commonjs5.ts new file mode 100644 index 00000000000..631dd11a39a --- /dev/null +++ b/tests/cases/compiler/es5-commonjs5.ts @@ -0,0 +1,8 @@ +// @target: ES5 +// @sourcemap: false +// @declaration: false +// @module: commonjs + +export default function () { + return "test"; +} From c0faaeecbe045dd070f17d41fe314f6561f67ccc Mon Sep 17 00:00:00 2001 From: Daniel Rosenwasser Date: Wed, 1 Jul 2015 14:26:05 -0700 Subject: [PATCH 14/64] Added more test cases for object binding patterns. --- ...lRefsObjectBindingElementPropertyName04.ts | 21 +++++++++++++++++ ...lRefsObjectBindingElementPropertyName05.ts | 21 +++++++++++++++++ ...lRefsObjectBindingElementPropertyName06.ts | 23 +++++++++++++++++++ ...lRefsObjectBindingElementPropertyName07.ts | 15 ++++++++++++ 4 files changed, 80 insertions(+) create mode 100644 tests/cases/fourslash/findAllRefsObjectBindingElementPropertyName04.ts create mode 100644 tests/cases/fourslash/findAllRefsObjectBindingElementPropertyName05.ts create mode 100644 tests/cases/fourslash/findAllRefsObjectBindingElementPropertyName06.ts create mode 100644 tests/cases/fourslash/findAllRefsObjectBindingElementPropertyName07.ts diff --git a/tests/cases/fourslash/findAllRefsObjectBindingElementPropertyName04.ts b/tests/cases/fourslash/findAllRefsObjectBindingElementPropertyName04.ts new file mode 100644 index 00000000000..ad72bd99bb8 --- /dev/null +++ b/tests/cases/fourslash/findAllRefsObjectBindingElementPropertyName04.ts @@ -0,0 +1,21 @@ +/// + +////interface I { +//// [|property1|]: number; +//// property2: string; +////} +//// +////function f({ [|property1|]: p1 }: I, +//// { [|property1|] }: I, +//// { property1: p2 }) { +////} + +let ranges = test.ranges(); +for (let range of ranges) { + goTo.position(range.start); + + verify.referencesCountIs(ranges.length); + for (let expectedRange of ranges) { + verify.referencesAtPositionContains(expectedRange); + } +} \ No newline at end of file diff --git a/tests/cases/fourslash/findAllRefsObjectBindingElementPropertyName05.ts b/tests/cases/fourslash/findAllRefsObjectBindingElementPropertyName05.ts new file mode 100644 index 00000000000..aa6432fa62e --- /dev/null +++ b/tests/cases/fourslash/findAllRefsObjectBindingElementPropertyName05.ts @@ -0,0 +1,21 @@ +/// + +////interface I { +//// property1: number; +//// property2: string; +////} +//// +////function f({ [|property1|]: p }, { property1 }) { +//// let x = property1; +////} + +// Notice only one range. +let ranges = test.ranges(); +for (let range of ranges) { + goTo.position(range.start); + + verify.referencesCountIs(ranges.length); + for (let expectedRange of ranges) { + verify.referencesAtPositionContains(expectedRange); + } +} \ No newline at end of file diff --git a/tests/cases/fourslash/findAllRefsObjectBindingElementPropertyName06.ts b/tests/cases/fourslash/findAllRefsObjectBindingElementPropertyName06.ts new file mode 100644 index 00000000000..4ce33f2b6ad --- /dev/null +++ b/tests/cases/fourslash/findAllRefsObjectBindingElementPropertyName06.ts @@ -0,0 +1,23 @@ +/// + +////interface I { +//// [|property1|]: number; +//// property2: string; +////} +//// +////for (let { [|property1|]: p } of []) { +////} +////for (let { [|property1|] } of []) { +////} +////for (var { [|property1|]: p } of []) { +////} + +let ranges = test.ranges(); +for (let range of ranges) { + goTo.position(range.start); + + verify.referencesCountIs(ranges.length); + for (let expectedRange of ranges) { + verify.referencesAtPositionContains(expectedRange); + } +} \ No newline at end of file diff --git a/tests/cases/fourslash/findAllRefsObjectBindingElementPropertyName07.ts b/tests/cases/fourslash/findAllRefsObjectBindingElementPropertyName07.ts new file mode 100644 index 00000000000..6448d2396b3 --- /dev/null +++ b/tests/cases/fourslash/findAllRefsObjectBindingElementPropertyName07.ts @@ -0,0 +1,15 @@ +/// + +////let p, b; +//// +////p, [{ [|a|]: p, b }] = [{ [|a|]: 10, b: true }]; + +let ranges = test.ranges(); +for (let range of ranges) { + goTo.position(range.start); + + verify.referencesCountIs(ranges.length); + for (let expectedRange of ranges) { + verify.referencesAtPositionContains(expectedRange); + } +} \ No newline at end of file From 544b1772c3e85992b96fda4cc42f36c883983828 Mon Sep 17 00:00:00 2001 From: Jason Freeman Date: Wed, 8 Jul 2015 14:49:41 -0700 Subject: [PATCH 15/64] Fix type parameters every time a parameter is assigned a contextual type --- src/compiler/checker.ts | 71 +++++++++++++++++++++++++++++++---------- src/compiler/types.ts | 3 ++ 2 files changed, 57 insertions(+), 17 deletions(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 1b34952f3ae..05174a43155 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -4225,7 +4225,7 @@ namespace ts { } function createInferenceMapper(context: InferenceContext): TypeMapper { - return t => { + let mapper: TypeMapper = t => { for (let i = 0; i < context.typeParameters.length; i++) { if (t === context.typeParameters[i]) { context.inferences[i].isFixed = true; @@ -4234,6 +4234,20 @@ namespace ts { } return t; } + + mapper.context = context; + return mapper; + } + + function fixTypeParametersAfterInferringFromContextualParameterTypes(context: InferenceContext): void { + for (let i = 0; i < context.typeParameters.length; i++) { + let typeParameterInfo = context.inferences[i]; + if (typeParameterInfo.fixAfterInferringFromContextualParameterType) { + typeParameterInfo.fixAfterInferringFromContextualParameterType = false; + typeParameterInfo.isFixed = true; + getInferredType(context, i); + } + } } function identityMapper(type: Type): Type { @@ -5397,7 +5411,10 @@ namespace ts { function createInferenceContext(typeParameters: TypeParameter[], inferUnionTypes: boolean): InferenceContext { let inferences: TypeInferences[] = []; for (let unused of typeParameters) { - inferences.push({ primary: undefined, secondary: undefined, isFixed: false }); + inferences.push({ + primary: undefined, secondary: undefined, + isFixed: false, fixAfterInferringFromContextualParameterType: false + }); } return { typeParameters, @@ -5407,7 +5424,7 @@ namespace ts { }; } - function inferTypes(context: InferenceContext, source: Type, target: Type) { + function inferTypes(context: InferenceContext, source: Type, target: Type, inferringFromContextuallyTypedParameter: boolean) { let sourceStack: Type[]; let targetStack: Type[]; let depth = 0; @@ -5446,6 +5463,9 @@ namespace ts { if (!contains(candidates, source)) { candidates.push(source); } + if (inferringFromContextuallyTypedParameter) { + inferences.fixAfterInferringFromContextualParameterType = true; + } } return; } @@ -6698,7 +6718,7 @@ namespace ts { // Presence of a contextual type mapper indicates inferential typing, except the identityMapper object is // used as a special marker for other purposes. function isInferentialContext(mapper: TypeMapper) { - return mapper && mapper !== identityMapper; + return mapper && mapper.context; } // A node is an assignment target if it is on the left hand side of an '=' token, if it is parented by a property @@ -7834,7 +7854,7 @@ namespace ts { let context = createInferenceContext(signature.typeParameters, /*inferUnionTypes*/ true); forEachMatchingParameterType(contextualSignature, signature, (source, target) => { // Type parameters from outer context referenced by source type are fixed by instantiation of the source type - inferTypes(context, instantiateType(source, contextualMapper), target); + inferTypes(context, instantiateType(source, contextualMapper), target, false); }); return getSignatureInstantiation(signature, getInferredTypes(context)); } @@ -7884,7 +7904,7 @@ namespace ts { argType = checkExpressionWithContextualType(arg, paramType, mapper); } - inferTypes(context, argType, paramType); + inferTypes(context, argType, paramType, false); } } @@ -7899,7 +7919,7 @@ namespace ts { if (excludeArgument[i] === false) { let arg = args[i]; let paramType = getTypeAtPosition(signature, i); - inferTypes(context, checkExpressionWithContextualType(arg, paramType, inferenceMapper), paramType); + inferTypes(context, checkExpressionWithContextualType(arg, paramType, inferenceMapper), paramType, false); } } } @@ -8788,13 +8808,23 @@ namespace ts { let len = signature.parameters.length - (signature.hasRestParameter ? 1 : 0); for (let i = 0; i < len; i++) { let parameter = signature.parameters[i]; - let links = getSymbolLinks(parameter); - links.type = instantiateType(getTypeAtPosition(context, i), mapper); + let contextualParameterType = getTypeAtPosition(context, i); + assignTypeToParameterAndFixTypeParameters(getSymbolLinks(parameter), contextualParameterType, mapper); } if (signature.hasRestParameter && context.hasRestParameter && signature.parameters.length >= context.parameters.length) { let parameter = lastOrUndefined(signature.parameters); - let links = getSymbolLinks(parameter); - links.type = instantiateType(getTypeOfSymbol(lastOrUndefined(context.parameters)), mapper); + let contextualParameterType = getTypeOfSymbol(lastOrUndefined(context.parameters)); + assignTypeToParameterAndFixTypeParameters(getSymbolLinks(parameter), contextualParameterType, mapper); + } + } + + function assignTypeToParameterAndFixTypeParameters(parameterLinks: SymbolLinks, contextualType: Type, mapper: TypeMapper) { + if (!parameterLinks.type) { + parameterLinks.type = instantiateType(contextualType, mapper); + } + else if (isInferentialContext(mapper)) { + inferTypes(mapper.context, parameterLinks.type, contextualType, true); + fixTypeParametersAfterInferringFromContextualParameterTypes(mapper.context); } } @@ -9014,27 +9044,34 @@ namespace ts { let links = getNodeLinks(node); let type = getTypeOfSymbol(node.symbol); + let contextSensitive = isContextSensitive(node); + let mightFixTypeParameters = contextSensitive && isInferentialContext(contextualMapper); + // Check if function expression is contextually typed and assign parameter types if so - if (!(links.flags & NodeCheckFlags.ContextChecked)) { + if (mightFixTypeParameters || !(links.flags & NodeCheckFlags.ContextChecked)) { let contextualSignature = getContextualSignature(node); // If a type check is started at a function expression that is an argument of a function call, obtaining the // contextual type may recursively get back to here during overload resolution of the call. If so, we will have // already assigned contextual types. - if (!(links.flags & NodeCheckFlags.ContextChecked)) { + let contextChecked = !!(links.flags & NodeCheckFlags.ContextChecked); + if (mightFixTypeParameters || !contextChecked) { links.flags |= NodeCheckFlags.ContextChecked; if (contextualSignature) { let signature = getSignaturesOfType(type, SignatureKind.Call)[0]; - if (isContextSensitive(node)) { + if (contextSensitive) { assignContextualParameterTypes(signature, contextualSignature, contextualMapper || identityMapper); } - if (!node.type && !signature.resolvedReturnType) { + if (mightFixTypeParameters || !node.type && !signature.resolvedReturnType) { let returnType = getReturnTypeFromBody(node, contextualMapper); if (!signature.resolvedReturnType) { signature.resolvedReturnType = returnType; } } } - checkSignatureDeclaration(node); + + if (!contextChecked) { + checkSignatureDeclaration(node); + } } } @@ -9724,7 +9761,7 @@ namespace ts { } function instantiateTypeWithSingleGenericCallSignature(node: Expression | MethodDeclaration, type: Type, contextualMapper?: TypeMapper) { - if (contextualMapper && contextualMapper !== identityMapper) { + if (isInferentialContext(contextualMapper)) { let signature = getSingleCallSignature(type); if (signature && signature.typeParameters) { let contextualType = getContextualType(node); diff --git a/src/compiler/types.ts b/src/compiler/types.ts index 6c2f72a1ab7..22dcc89b5e3 100644 --- a/src/compiler/types.ts +++ b/src/compiler/types.ts @@ -1893,6 +1893,7 @@ namespace ts { /* @internal */ export interface TypeMapper { (t: TypeParameter): Type; + context?: InferenceContext; } /* @internal */ @@ -1901,6 +1902,8 @@ namespace ts { secondary: Type[]; // Inferences made to a type parameter in a union type isFixed: boolean; // Whether the type parameter is fixed, as defined in section 4.12.2 of the TypeScript spec // If a type parameter is fixed, no more inferences can be made for the type parameter + + fixAfterInferringFromContextualParameterType: boolean; } /* @internal */ From f5ca4563252664ce0aedced5fd422f95f8e7173d Mon Sep 17 00:00:00 2001 From: Jason Freeman Date: Wed, 8 Jul 2015 14:49:54 -0700 Subject: [PATCH 16/64] Accept baselines --- .../parenthesizedContexualTyping1.types | 32 +++++++++---------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/tests/baselines/reference/parenthesizedContexualTyping1.types b/tests/baselines/reference/parenthesizedContexualTyping1.types index b7307eaf3e7..61ec1a24ec5 100644 --- a/tests/baselines/reference/parenthesizedContexualTyping1.types +++ b/tests/baselines/reference/parenthesizedContexualTyping1.types @@ -146,8 +146,8 @@ var h = fun((((x => x))), ((x => x)), 10); // Ternaries in parens var i = fun((Math.random() < 0.5 ? x => x : x => undefined), 10); ->i : any ->fun((Math.random() < 0.5 ? x => x : x => undefined), 10) : any +>i : number +>fun((Math.random() < 0.5 ? x => x : x => undefined), 10) : number >fun : { (g: (x: T) => T, x: T): T; (g: (x: T) => T, h: (y: T) => T, x: T): T; } >(Math.random() < 0.5 ? x => x : x => undefined) : (x: number) => any >Math.random() < 0.5 ? x => x : x => undefined : (x: number) => any @@ -166,8 +166,8 @@ var i = fun((Math.random() < 0.5 ? x => x : x => undefined), 10); >10 : number var j = fun((Math.random() < 0.5 ? (x => x) : (x => undefined)), 10); ->j : any ->fun((Math.random() < 0.5 ? (x => x) : (x => undefined)), 10) : any +>j : number +>fun((Math.random() < 0.5 ? (x => x) : (x => undefined)), 10) : number >fun : { (g: (x: T) => T, x: T): T; (g: (x: T) => T, h: (y: T) => T, x: T): T; } >(Math.random() < 0.5 ? (x => x) : (x => undefined)) : (x: number) => any >Math.random() < 0.5 ? (x => x) : (x => undefined) : (x: number) => any @@ -188,8 +188,8 @@ var j = fun((Math.random() < 0.5 ? (x => x) : (x => undefined)), 10); >10 : number var k = fun((Math.random() < 0.5 ? (x => x) : (x => undefined)), x => x, 10); ->k : any ->fun((Math.random() < 0.5 ? (x => x) : (x => undefined)), x => x, 10) : any +>k : number +>fun((Math.random() < 0.5 ? (x => x) : (x => undefined)), x => x, 10) : number >fun : { (g: (x: T) => T, x: T): T; (g: (x: T) => T, h: (y: T) => T, x: T): T; } >(Math.random() < 0.5 ? (x => x) : (x => undefined)) : (x: number) => any >Math.random() < 0.5 ? (x => x) : (x => undefined) : (x: number) => any @@ -207,14 +207,14 @@ var k = fun((Math.random() < 0.5 ? (x => x) : (x => undefined)), x => x, 10); >x => undefined : (x: number) => any >x : number >undefined : undefined ->x => x : (x: any) => any ->x : any ->x : any +>x => x : (x: number) => number +>x : number +>x : number >10 : number var l = fun(((Math.random() < 0.5 ? ((x => x)) : ((x => undefined)))), ((x => x)), 10); ->l : any ->fun(((Math.random() < 0.5 ? ((x => x)) : ((x => undefined)))), ((x => x)), 10) : any +>l : number +>fun(((Math.random() < 0.5 ? ((x => x)) : ((x => undefined)))), ((x => x)), 10) : number >fun : { (g: (x: T) => T, x: T): T; (g: (x: T) => T, h: (y: T) => T, x: T): T; } >((Math.random() < 0.5 ? ((x => x)) : ((x => undefined)))) : (x: number) => any >(Math.random() < 0.5 ? ((x => x)) : ((x => undefined))) : (x: number) => any @@ -235,11 +235,11 @@ var l = fun(((Math.random() < 0.5 ? ((x => x)) : ((x => undefined)))), ((x => x) >x => undefined : (x: number) => any >x : number >undefined : undefined ->((x => x)) : (x: any) => any ->(x => x) : (x: any) => any ->x => x : (x: any) => any ->x : any ->x : any +>((x => x)) : (x: number) => number +>(x => x) : (x: number) => number +>x => x : (x: number) => number +>x : number +>x : number >10 : number var lambda1: (x: number) => number = x => x; From 263c54edd4713565c31f157cdc42b401f3abb2ca Mon Sep 17 00:00:00 2001 From: Jason Freeman Date: Wed, 8 Jul 2015 16:17:03 -0700 Subject: [PATCH 17/64] Add tests for type parameter fixing --- .../fixingTypeParametersRepeatedly1.js | 12 +++ .../fixingTypeParametersRepeatedly1.symbols | 51 ++++++++++++ .../fixingTypeParametersRepeatedly1.types | 63 +++++++++++++++ ...fixingTypeParametersRepeatedly2.errors.txt | 32 ++++++++ .../fixingTypeParametersRepeatedly2.js | 23 ++++++ .../fixingTypeParametersRepeatedly3.js | 23 ++++++ .../fixingTypeParametersRepeatedly3.symbols | 73 +++++++++++++++++ .../fixingTypeParametersRepeatedly3.types | 79 +++++++++++++++++++ .../fixingTypeParametersRepeatedly1.ts | 7 ++ .../fixingTypeParametersRepeatedly2.ts | 17 ++++ .../fixingTypeParametersRepeatedly3.ts | 17 ++++ .../fixingTypeParametersQuickInfo.ts | 13 +++ 12 files changed, 410 insertions(+) create mode 100644 tests/baselines/reference/fixingTypeParametersRepeatedly1.js create mode 100644 tests/baselines/reference/fixingTypeParametersRepeatedly1.symbols create mode 100644 tests/baselines/reference/fixingTypeParametersRepeatedly1.types create mode 100644 tests/baselines/reference/fixingTypeParametersRepeatedly2.errors.txt create mode 100644 tests/baselines/reference/fixingTypeParametersRepeatedly2.js create mode 100644 tests/baselines/reference/fixingTypeParametersRepeatedly3.js create mode 100644 tests/baselines/reference/fixingTypeParametersRepeatedly3.symbols create mode 100644 tests/baselines/reference/fixingTypeParametersRepeatedly3.types create mode 100644 tests/cases/compiler/fixingTypeParametersRepeatedly1.ts create mode 100644 tests/cases/compiler/fixingTypeParametersRepeatedly2.ts create mode 100644 tests/cases/compiler/fixingTypeParametersRepeatedly3.ts create mode 100644 tests/cases/fourslash/fixingTypeParametersQuickInfo.ts diff --git a/tests/baselines/reference/fixingTypeParametersRepeatedly1.js b/tests/baselines/reference/fixingTypeParametersRepeatedly1.js new file mode 100644 index 00000000000..93ab8ba9888 --- /dev/null +++ b/tests/baselines/reference/fixingTypeParametersRepeatedly1.js @@ -0,0 +1,12 @@ +//// [fixingTypeParametersRepeatedly1.ts] +declare function f(x: T, y: (p: T) => T, z: (p: T) => T): T; +f("", x => null, x => x.toLowerCase()); + +// First overload of g should type check just like f +declare function g(x: T, y: (p: T) => T, z: (p: T) => T): T; +declare function g(); +g("", x => null, x => x.toLowerCase()); + +//// [fixingTypeParametersRepeatedly1.js] +f("", function (x) { return null; }, function (x) { return x.toLowerCase(); }); +g("", function (x) { return null; }, function (x) { return x.toLowerCase(); }); diff --git a/tests/baselines/reference/fixingTypeParametersRepeatedly1.symbols b/tests/baselines/reference/fixingTypeParametersRepeatedly1.symbols new file mode 100644 index 00000000000..998e59c0b8f --- /dev/null +++ b/tests/baselines/reference/fixingTypeParametersRepeatedly1.symbols @@ -0,0 +1,51 @@ +=== tests/cases/compiler/fixingTypeParametersRepeatedly1.ts === +declare function f(x: T, y: (p: T) => T, z: (p: T) => T): T; +>f : Symbol(f, Decl(fixingTypeParametersRepeatedly1.ts, 0, 0)) +>T : Symbol(T, Decl(fixingTypeParametersRepeatedly1.ts, 0, 19)) +>x : Symbol(x, Decl(fixingTypeParametersRepeatedly1.ts, 0, 22)) +>T : Symbol(T, Decl(fixingTypeParametersRepeatedly1.ts, 0, 19)) +>y : Symbol(y, Decl(fixingTypeParametersRepeatedly1.ts, 0, 27)) +>p : Symbol(p, Decl(fixingTypeParametersRepeatedly1.ts, 0, 32)) +>T : Symbol(T, Decl(fixingTypeParametersRepeatedly1.ts, 0, 19)) +>T : Symbol(T, Decl(fixingTypeParametersRepeatedly1.ts, 0, 19)) +>z : Symbol(z, Decl(fixingTypeParametersRepeatedly1.ts, 0, 43)) +>p : Symbol(p, Decl(fixingTypeParametersRepeatedly1.ts, 0, 48)) +>T : Symbol(T, Decl(fixingTypeParametersRepeatedly1.ts, 0, 19)) +>T : Symbol(T, Decl(fixingTypeParametersRepeatedly1.ts, 0, 19)) +>T : Symbol(T, Decl(fixingTypeParametersRepeatedly1.ts, 0, 19)) + +f("", x => null, x => x.toLowerCase()); +>f : Symbol(f, Decl(fixingTypeParametersRepeatedly1.ts, 0, 0)) +>x : Symbol(x, Decl(fixingTypeParametersRepeatedly1.ts, 1, 5)) +>x : Symbol(x, Decl(fixingTypeParametersRepeatedly1.ts, 1, 16)) +>x.toLowerCase : Symbol(String.toLowerCase, Decl(lib.d.ts, 399, 51)) +>x : Symbol(x, Decl(fixingTypeParametersRepeatedly1.ts, 1, 16)) +>toLowerCase : Symbol(String.toLowerCase, Decl(lib.d.ts, 399, 51)) + +// First overload of g should type check just like f +declare function g(x: T, y: (p: T) => T, z: (p: T) => T): T; +>g : Symbol(g, Decl(fixingTypeParametersRepeatedly1.ts, 1, 39), Decl(fixingTypeParametersRepeatedly1.ts, 4, 63)) +>T : Symbol(T, Decl(fixingTypeParametersRepeatedly1.ts, 4, 19)) +>x : Symbol(x, Decl(fixingTypeParametersRepeatedly1.ts, 4, 22)) +>T : Symbol(T, Decl(fixingTypeParametersRepeatedly1.ts, 4, 19)) +>y : Symbol(y, Decl(fixingTypeParametersRepeatedly1.ts, 4, 27)) +>p : Symbol(p, Decl(fixingTypeParametersRepeatedly1.ts, 4, 32)) +>T : Symbol(T, Decl(fixingTypeParametersRepeatedly1.ts, 4, 19)) +>T : Symbol(T, Decl(fixingTypeParametersRepeatedly1.ts, 4, 19)) +>z : Symbol(z, Decl(fixingTypeParametersRepeatedly1.ts, 4, 43)) +>p : Symbol(p, Decl(fixingTypeParametersRepeatedly1.ts, 4, 48)) +>T : Symbol(T, Decl(fixingTypeParametersRepeatedly1.ts, 4, 19)) +>T : Symbol(T, Decl(fixingTypeParametersRepeatedly1.ts, 4, 19)) +>T : Symbol(T, Decl(fixingTypeParametersRepeatedly1.ts, 4, 19)) + +declare function g(); +>g : Symbol(g, Decl(fixingTypeParametersRepeatedly1.ts, 1, 39), Decl(fixingTypeParametersRepeatedly1.ts, 4, 63)) + +g("", x => null, x => x.toLowerCase()); +>g : Symbol(g, Decl(fixingTypeParametersRepeatedly1.ts, 1, 39), Decl(fixingTypeParametersRepeatedly1.ts, 4, 63)) +>x : Symbol(x, Decl(fixingTypeParametersRepeatedly1.ts, 6, 5)) +>x : Symbol(x, Decl(fixingTypeParametersRepeatedly1.ts, 6, 16)) +>x.toLowerCase : Symbol(String.toLowerCase, Decl(lib.d.ts, 399, 51)) +>x : Symbol(x, Decl(fixingTypeParametersRepeatedly1.ts, 6, 16)) +>toLowerCase : Symbol(String.toLowerCase, Decl(lib.d.ts, 399, 51)) + diff --git a/tests/baselines/reference/fixingTypeParametersRepeatedly1.types b/tests/baselines/reference/fixingTypeParametersRepeatedly1.types new file mode 100644 index 00000000000..273c66b342d --- /dev/null +++ b/tests/baselines/reference/fixingTypeParametersRepeatedly1.types @@ -0,0 +1,63 @@ +=== tests/cases/compiler/fixingTypeParametersRepeatedly1.ts === +declare function f(x: T, y: (p: T) => T, z: (p: T) => T): T; +>f : (x: T, y: (p: T) => T, z: (p: T) => T) => T +>T : T +>x : T +>T : T +>y : (p: T) => T +>p : T +>T : T +>T : T +>z : (p: T) => T +>p : T +>T : T +>T : T +>T : T + +f("", x => null, x => x.toLowerCase()); +>f("", x => null, x => x.toLowerCase()) : string +>f : (x: T, y: (p: T) => T, z: (p: T) => T) => T +>"" : string +>x => null : (x: string) => any +>x : string +>null : null +>x => x.toLowerCase() : (x: string) => string +>x : string +>x.toLowerCase() : string +>x.toLowerCase : () => string +>x : string +>toLowerCase : () => string + +// First overload of g should type check just like f +declare function g(x: T, y: (p: T) => T, z: (p: T) => T): T; +>g : { (x: T, y: (p: T) => T, z: (p: T) => T): T; (): any; } +>T : T +>x : T +>T : T +>y : (p: T) => T +>p : T +>T : T +>T : T +>z : (p: T) => T +>p : T +>T : T +>T : T +>T : T + +declare function g(); +>g : { (x: T, y: (p: T) => T, z: (p: T) => T): T; (): any; } + +g("", x => null, x => x.toLowerCase()); +>g("", x => null, x => x.toLowerCase()) : string +>g : { (x: T, y: (p: T) => T, z: (p: T) => T): T; (): any; } +>"" : string +>x => null : (x: string) => any +>x : string +>null : null +>x => x.toLowerCase() : (x: string) => string +>x : string +>x.toLowerCase() : string +>x.toLowerCase : () => string +>x : string +>toLowerCase : () => string + diff --git a/tests/baselines/reference/fixingTypeParametersRepeatedly2.errors.txt b/tests/baselines/reference/fixingTypeParametersRepeatedly2.errors.txt new file mode 100644 index 00000000000..e56b58a268d --- /dev/null +++ b/tests/baselines/reference/fixingTypeParametersRepeatedly2.errors.txt @@ -0,0 +1,32 @@ +tests/cases/compiler/fixingTypeParametersRepeatedly2.ts(11,27): error TS2345: Argument of type '(d: Derived) => Base' is not assignable to parameter of type '(p: Derived) => Derived'. + Type 'Base' is not assignable to type 'Derived'. + Property 'toBase' is missing in type 'Base'. +tests/cases/compiler/fixingTypeParametersRepeatedly2.ts(17,27): error TS2345: Argument of type '(d: Derived) => Base' is not assignable to parameter of type '(p: Derived) => Derived'. + Type 'Base' is not assignable to type 'Derived'. + + +==== tests/cases/compiler/fixingTypeParametersRepeatedly2.ts (2 errors) ==== + interface Base { + baseProp; + } + interface Derived extends Base { + toBase(): Base; + } + + var derived: Derived; + + declare function foo(x: T, func: (p: T) => T): T; + var result = foo(derived, d => d.toBase()); + ~~~~~~~~~~~~~~~ +!!! error TS2345: Argument of type '(d: Derived) => Base' is not assignable to parameter of type '(p: Derived) => Derived'. +!!! error TS2345: Type 'Base' is not assignable to type 'Derived'. +!!! error TS2345: Property 'toBase' is missing in type 'Base'. + + // bar should type check just like foo. + // The same error should be observed in both cases. + declare function bar(x: T, func: (p: T) => T): T; + declare function bar(x: T, func: (p: T) => T): T; + var result = bar(derived, d => d.toBase()); + ~~~~~~~~~~~~~~~ +!!! error TS2345: Argument of type '(d: Derived) => Base' is not assignable to parameter of type '(p: Derived) => Derived'. +!!! error TS2345: Type 'Base' is not assignable to type 'Derived'. \ No newline at end of file diff --git a/tests/baselines/reference/fixingTypeParametersRepeatedly2.js b/tests/baselines/reference/fixingTypeParametersRepeatedly2.js new file mode 100644 index 00000000000..9ebf426bbd2 --- /dev/null +++ b/tests/baselines/reference/fixingTypeParametersRepeatedly2.js @@ -0,0 +1,23 @@ +//// [fixingTypeParametersRepeatedly2.ts] +interface Base { + baseProp; +} +interface Derived extends Base { + toBase(): Base; +} + +var derived: Derived; + +declare function foo(x: T, func: (p: T) => T): T; +var result = foo(derived, d => d.toBase()); + +// bar should type check just like foo. +// The same error should be observed in both cases. +declare function bar(x: T, func: (p: T) => T): T; +declare function bar(x: T, func: (p: T) => T): T; +var result = bar(derived, d => d.toBase()); + +//// [fixingTypeParametersRepeatedly2.js] +var derived; +var result = foo(derived, function (d) { return d.toBase(); }); +var result = bar(derived, function (d) { return d.toBase(); }); diff --git a/tests/baselines/reference/fixingTypeParametersRepeatedly3.js b/tests/baselines/reference/fixingTypeParametersRepeatedly3.js new file mode 100644 index 00000000000..83a47c92c34 --- /dev/null +++ b/tests/baselines/reference/fixingTypeParametersRepeatedly3.js @@ -0,0 +1,23 @@ +//// [fixingTypeParametersRepeatedly3.ts] +interface Base { + baseProp; +} +interface Derived extends Base { + toBase?(): Base; +} + +var derived: Derived; + +declare function foo(x: T, func: (p: T) => T): T; +var result = foo(derived, d => d.toBase()); + +// bar should type check just like foo. +// result2 should have the same type as result +declare function bar(x: T, func: (p: T) => T): T; +declare function bar(x: T, func: (p: T) => T): T; +var result2 = bar(derived, d => d.toBase()); + +//// [fixingTypeParametersRepeatedly3.js] +var derived; +var result = foo(derived, function (d) { return d.toBase(); }); +var result2 = bar(derived, function (d) { return d.toBase(); }); diff --git a/tests/baselines/reference/fixingTypeParametersRepeatedly3.symbols b/tests/baselines/reference/fixingTypeParametersRepeatedly3.symbols new file mode 100644 index 00000000000..a849adb6235 --- /dev/null +++ b/tests/baselines/reference/fixingTypeParametersRepeatedly3.symbols @@ -0,0 +1,73 @@ +=== tests/cases/compiler/fixingTypeParametersRepeatedly3.ts === +interface Base { +>Base : Symbol(Base, Decl(fixingTypeParametersRepeatedly3.ts, 0, 0)) + + baseProp; +>baseProp : Symbol(baseProp, Decl(fixingTypeParametersRepeatedly3.ts, 0, 16)) +} +interface Derived extends Base { +>Derived : Symbol(Derived, Decl(fixingTypeParametersRepeatedly3.ts, 2, 1)) +>Base : Symbol(Base, Decl(fixingTypeParametersRepeatedly3.ts, 0, 0)) + + toBase?(): Base; +>toBase : Symbol(toBase, Decl(fixingTypeParametersRepeatedly3.ts, 3, 32)) +>Base : Symbol(Base, Decl(fixingTypeParametersRepeatedly3.ts, 0, 0)) +} + +var derived: Derived; +>derived : Symbol(derived, Decl(fixingTypeParametersRepeatedly3.ts, 7, 3)) +>Derived : Symbol(Derived, Decl(fixingTypeParametersRepeatedly3.ts, 2, 1)) + +declare function foo(x: T, func: (p: T) => T): T; +>foo : Symbol(foo, Decl(fixingTypeParametersRepeatedly3.ts, 7, 21)) +>T : Symbol(T, Decl(fixingTypeParametersRepeatedly3.ts, 9, 21)) +>x : Symbol(x, Decl(fixingTypeParametersRepeatedly3.ts, 9, 24)) +>T : Symbol(T, Decl(fixingTypeParametersRepeatedly3.ts, 9, 21)) +>func : Symbol(func, Decl(fixingTypeParametersRepeatedly3.ts, 9, 29)) +>p : Symbol(p, Decl(fixingTypeParametersRepeatedly3.ts, 9, 37)) +>T : Symbol(T, Decl(fixingTypeParametersRepeatedly3.ts, 9, 21)) +>T : Symbol(T, Decl(fixingTypeParametersRepeatedly3.ts, 9, 21)) +>T : Symbol(T, Decl(fixingTypeParametersRepeatedly3.ts, 9, 21)) + +var result = foo(derived, d => d.toBase()); +>result : Symbol(result, Decl(fixingTypeParametersRepeatedly3.ts, 10, 3)) +>foo : Symbol(foo, Decl(fixingTypeParametersRepeatedly3.ts, 7, 21)) +>derived : Symbol(derived, Decl(fixingTypeParametersRepeatedly3.ts, 7, 3)) +>d : Symbol(d, Decl(fixingTypeParametersRepeatedly3.ts, 10, 25)) +>d.toBase : Symbol(Derived.toBase, Decl(fixingTypeParametersRepeatedly3.ts, 3, 32)) +>d : Symbol(d, Decl(fixingTypeParametersRepeatedly3.ts, 10, 25)) +>toBase : Symbol(Derived.toBase, Decl(fixingTypeParametersRepeatedly3.ts, 3, 32)) + +// bar should type check just like foo. +// result2 should have the same type as result +declare function bar(x: T, func: (p: T) => T): T; +>bar : Symbol(bar, Decl(fixingTypeParametersRepeatedly3.ts, 10, 43), Decl(fixingTypeParametersRepeatedly3.ts, 14, 52)) +>T : Symbol(T, Decl(fixingTypeParametersRepeatedly3.ts, 14, 21)) +>x : Symbol(x, Decl(fixingTypeParametersRepeatedly3.ts, 14, 24)) +>T : Symbol(T, Decl(fixingTypeParametersRepeatedly3.ts, 14, 21)) +>func : Symbol(func, Decl(fixingTypeParametersRepeatedly3.ts, 14, 29)) +>p : Symbol(p, Decl(fixingTypeParametersRepeatedly3.ts, 14, 37)) +>T : Symbol(T, Decl(fixingTypeParametersRepeatedly3.ts, 14, 21)) +>T : Symbol(T, Decl(fixingTypeParametersRepeatedly3.ts, 14, 21)) +>T : Symbol(T, Decl(fixingTypeParametersRepeatedly3.ts, 14, 21)) + +declare function bar(x: T, func: (p: T) => T): T; +>bar : Symbol(bar, Decl(fixingTypeParametersRepeatedly3.ts, 10, 43), Decl(fixingTypeParametersRepeatedly3.ts, 14, 52)) +>T : Symbol(T, Decl(fixingTypeParametersRepeatedly3.ts, 15, 21)) +>x : Symbol(x, Decl(fixingTypeParametersRepeatedly3.ts, 15, 24)) +>T : Symbol(T, Decl(fixingTypeParametersRepeatedly3.ts, 15, 21)) +>func : Symbol(func, Decl(fixingTypeParametersRepeatedly3.ts, 15, 29)) +>p : Symbol(p, Decl(fixingTypeParametersRepeatedly3.ts, 15, 37)) +>T : Symbol(T, Decl(fixingTypeParametersRepeatedly3.ts, 15, 21)) +>T : Symbol(T, Decl(fixingTypeParametersRepeatedly3.ts, 15, 21)) +>T : Symbol(T, Decl(fixingTypeParametersRepeatedly3.ts, 15, 21)) + +var result2 = bar(derived, d => d.toBase()); +>result2 : Symbol(result2, Decl(fixingTypeParametersRepeatedly3.ts, 16, 3)) +>bar : Symbol(bar, Decl(fixingTypeParametersRepeatedly3.ts, 10, 43), Decl(fixingTypeParametersRepeatedly3.ts, 14, 52)) +>derived : Symbol(derived, Decl(fixingTypeParametersRepeatedly3.ts, 7, 3)) +>d : Symbol(d, Decl(fixingTypeParametersRepeatedly3.ts, 16, 26)) +>d.toBase : Symbol(Derived.toBase, Decl(fixingTypeParametersRepeatedly3.ts, 3, 32)) +>d : Symbol(d, Decl(fixingTypeParametersRepeatedly3.ts, 16, 26)) +>toBase : Symbol(Derived.toBase, Decl(fixingTypeParametersRepeatedly3.ts, 3, 32)) + diff --git a/tests/baselines/reference/fixingTypeParametersRepeatedly3.types b/tests/baselines/reference/fixingTypeParametersRepeatedly3.types new file mode 100644 index 00000000000..3bf926276d2 --- /dev/null +++ b/tests/baselines/reference/fixingTypeParametersRepeatedly3.types @@ -0,0 +1,79 @@ +=== tests/cases/compiler/fixingTypeParametersRepeatedly3.ts === +interface Base { +>Base : Base + + baseProp; +>baseProp : any +} +interface Derived extends Base { +>Derived : Derived +>Base : Base + + toBase?(): Base; +>toBase : () => Base +>Base : Base +} + +var derived: Derived; +>derived : Derived +>Derived : Derived + +declare function foo(x: T, func: (p: T) => T): T; +>foo : (x: T, func: (p: T) => T) => T +>T : T +>x : T +>T : T +>func : (p: T) => T +>p : T +>T : T +>T : T +>T : T + +var result = foo(derived, d => d.toBase()); +>result : Derived +>foo(derived, d => d.toBase()) : Derived +>foo : (x: T, func: (p: T) => T) => T +>derived : Derived +>d => d.toBase() : (d: Derived) => Base +>d : Derived +>d.toBase() : Base +>d.toBase : () => Base +>d : Derived +>toBase : () => Base + +// bar should type check just like foo. +// result2 should have the same type as result +declare function bar(x: T, func: (p: T) => T): T; +>bar : { (x: T, func: (p: T) => T): T; (x: T, func: (p: T) => T): T; } +>T : T +>x : T +>T : T +>func : (p: T) => T +>p : T +>T : T +>T : T +>T : T + +declare function bar(x: T, func: (p: T) => T): T; +>bar : { (x: T, func: (p: T) => T): T; (x: T, func: (p: T) => T): T; } +>T : T +>x : T +>T : T +>func : (p: T) => T +>p : T +>T : T +>T : T +>T : T + +var result2 = bar(derived, d => d.toBase()); +>result2 : Derived +>bar(derived, d => d.toBase()) : Derived +>bar : { (x: T, func: (p: T) => T): T; (x: T, func: (p: T) => T): T; } +>derived : Derived +>d => d.toBase() : (d: Derived) => Base +>d : Derived +>d.toBase() : Base +>d.toBase : () => Base +>d : Derived +>toBase : () => Base + diff --git a/tests/cases/compiler/fixingTypeParametersRepeatedly1.ts b/tests/cases/compiler/fixingTypeParametersRepeatedly1.ts new file mode 100644 index 00000000000..d02e434c61c --- /dev/null +++ b/tests/cases/compiler/fixingTypeParametersRepeatedly1.ts @@ -0,0 +1,7 @@ +declare function f(x: T, y: (p: T) => T, z: (p: T) => T): T; +f("", x => null, x => x.toLowerCase()); + +// First overload of g should type check just like f +declare function g(x: T, y: (p: T) => T, z: (p: T) => T): T; +declare function g(); +g("", x => null, x => x.toLowerCase()); \ No newline at end of file diff --git a/tests/cases/compiler/fixingTypeParametersRepeatedly2.ts b/tests/cases/compiler/fixingTypeParametersRepeatedly2.ts new file mode 100644 index 00000000000..b439838862f --- /dev/null +++ b/tests/cases/compiler/fixingTypeParametersRepeatedly2.ts @@ -0,0 +1,17 @@ +interface Base { + baseProp; +} +interface Derived extends Base { + toBase(): Base; +} + +var derived: Derived; + +declare function foo(x: T, func: (p: T) => T): T; +var result = foo(derived, d => d.toBase()); + +// bar should type check just like foo. +// The same error should be observed in both cases. +declare function bar(x: T, func: (p: T) => T): T; +declare function bar(x: T, func: (p: T) => T): T; +var result = bar(derived, d => d.toBase()); \ No newline at end of file diff --git a/tests/cases/compiler/fixingTypeParametersRepeatedly3.ts b/tests/cases/compiler/fixingTypeParametersRepeatedly3.ts new file mode 100644 index 00000000000..1ffba2e50c6 --- /dev/null +++ b/tests/cases/compiler/fixingTypeParametersRepeatedly3.ts @@ -0,0 +1,17 @@ +interface Base { + baseProp; +} +interface Derived extends Base { + toBase?(): Base; +} + +var derived: Derived; + +declare function foo(x: T, func: (p: T) => T): T; +var result = foo(derived, d => d.toBase()); + +// bar should type check just like foo. +// result2 should have the same type as result +declare function bar(x: T, func: (p: T) => T): T; +declare function bar(x: T, func: (p: T) => T): T; +var result2 = bar(derived, d => d.toBase()); \ No newline at end of file diff --git a/tests/cases/fourslash/fixingTypeParametersQuickInfo.ts b/tests/cases/fourslash/fixingTypeParametersQuickInfo.ts new file mode 100644 index 00000000000..033663052be --- /dev/null +++ b/tests/cases/fourslash/fixingTypeParametersQuickInfo.ts @@ -0,0 +1,13 @@ +/// + +////declare function f(x: T, y: (p: T) => T, z: (p: T) => T): T; +////var /*1*/result = /*2*/f(0, /*3*/x => null, /*4*/x => x.blahblah); + +goTo.marker('1'); +verify.quickInfoIs('var result: number'); +goTo.marker('2'); +verify.quickInfoIs('function f(x: number, y: (p: number) => number, z: (p: number) => number): number'); +goTo.marker('3'); +verify.quickInfoIs('(parameter) x: number'); +goTo.marker('4'); +verify.quickInfoIs('(parameter) x: number'); \ No newline at end of file From d25bceaf8705d9ffc527332191c80d08d174500b Mon Sep 17 00:00:00 2001 From: Jason Freeman Date: Wed, 8 Jul 2015 16:37:18 -0700 Subject: [PATCH 18/64] Don't bother doing inference from the function parameter if you are about to fix the type parameter --- src/compiler/checker.ts | 28 ++++++---------------------- src/compiler/types.ts | 2 -- 2 files changed, 6 insertions(+), 24 deletions(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 05174a43155..35d9abe2fb2 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -4239,17 +4239,6 @@ namespace ts { return mapper; } - function fixTypeParametersAfterInferringFromContextualParameterTypes(context: InferenceContext): void { - for (let i = 0; i < context.typeParameters.length; i++) { - let typeParameterInfo = context.inferences[i]; - if (typeParameterInfo.fixAfterInferringFromContextualParameterType) { - typeParameterInfo.fixAfterInferringFromContextualParameterType = false; - typeParameterInfo.isFixed = true; - getInferredType(context, i); - } - } - } - function identityMapper(type: Type): Type { return type; } @@ -5412,8 +5401,7 @@ namespace ts { let inferences: TypeInferences[] = []; for (let unused of typeParameters) { inferences.push({ - primary: undefined, secondary: undefined, - isFixed: false, fixAfterInferringFromContextualParameterType: false + primary: undefined, secondary: undefined, isFixed: false }); } return { @@ -5424,7 +5412,7 @@ namespace ts { }; } - function inferTypes(context: InferenceContext, source: Type, target: Type, inferringFromContextuallyTypedParameter: boolean) { + function inferTypes(context: InferenceContext, source: Type, target: Type) { let sourceStack: Type[]; let targetStack: Type[]; let depth = 0; @@ -5463,9 +5451,6 @@ namespace ts { if (!contains(candidates, source)) { candidates.push(source); } - if (inferringFromContextuallyTypedParameter) { - inferences.fixAfterInferringFromContextualParameterType = true; - } } return; } @@ -7854,7 +7839,7 @@ namespace ts { let context = createInferenceContext(signature.typeParameters, /*inferUnionTypes*/ true); forEachMatchingParameterType(contextualSignature, signature, (source, target) => { // Type parameters from outer context referenced by source type are fixed by instantiation of the source type - inferTypes(context, instantiateType(source, contextualMapper), target, false); + inferTypes(context, instantiateType(source, contextualMapper), target); }); return getSignatureInstantiation(signature, getInferredTypes(context)); } @@ -7904,7 +7889,7 @@ namespace ts { argType = checkExpressionWithContextualType(arg, paramType, mapper); } - inferTypes(context, argType, paramType, false); + inferTypes(context, argType, paramType); } } @@ -7919,7 +7904,7 @@ namespace ts { if (excludeArgument[i] === false) { let arg = args[i]; let paramType = getTypeAtPosition(signature, i); - inferTypes(context, checkExpressionWithContextualType(arg, paramType, inferenceMapper), paramType, false); + inferTypes(context, checkExpressionWithContextualType(arg, paramType, inferenceMapper), paramType); } } } @@ -8823,8 +8808,7 @@ namespace ts { parameterLinks.type = instantiateType(contextualType, mapper); } else if (isInferentialContext(mapper)) { - inferTypes(mapper.context, parameterLinks.type, contextualType, true); - fixTypeParametersAfterInferringFromContextualParameterTypes(mapper.context); + inferTypes(mapper.context, parameterLinks.type, instantiateType(contextualType, mapper)); } } diff --git a/src/compiler/types.ts b/src/compiler/types.ts index 22dcc89b5e3..7c893da9a6f 100644 --- a/src/compiler/types.ts +++ b/src/compiler/types.ts @@ -1902,8 +1902,6 @@ namespace ts { secondary: Type[]; // Inferences made to a type parameter in a union type isFixed: boolean; // Whether the type parameter is fixed, as defined in section 4.12.2 of the TypeScript spec // If a type parameter is fixed, no more inferences can be made for the type parameter - - fixAfterInferringFromContextualParameterType: boolean; } /* @internal */ From a660d7bbea42d51a263058c2f5f5ef83dd3696ea Mon Sep 17 00:00:00 2001 From: Jason Freeman Date: Wed, 8 Jul 2015 17:15:05 -0700 Subject: [PATCH 19/64] Add hopefully helpful comments --- src/compiler/checker.ts | 46 ++++++++++++++++++++++++++++++++++------- src/compiler/types.ts | 4 +++- 2 files changed, 42 insertions(+), 8 deletions(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 35d9abe2fb2..534deb5fde6 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -8794,21 +8794,51 @@ namespace ts { for (let i = 0; i < len; i++) { let parameter = signature.parameters[i]; let contextualParameterType = getTypeAtPosition(context, i); - assignTypeToParameterAndFixTypeParameters(getSymbolLinks(parameter), contextualParameterType, mapper); + assignTypeToParameterAndFixTypeParameters(parameter, contextualParameterType, mapper); } if (signature.hasRestParameter && context.hasRestParameter && signature.parameters.length >= context.parameters.length) { let parameter = lastOrUndefined(signature.parameters); let contextualParameterType = getTypeOfSymbol(lastOrUndefined(context.parameters)); - assignTypeToParameterAndFixTypeParameters(getSymbolLinks(parameter), contextualParameterType, mapper); + assignTypeToParameterAndFixTypeParameters(parameter, contextualParameterType, mapper); } } - function assignTypeToParameterAndFixTypeParameters(parameterLinks: SymbolLinks, contextualType: Type, mapper: TypeMapper) { - if (!parameterLinks.type) { - parameterLinks.type = instantiateType(contextualType, mapper); + function assignTypeToParameterAndFixTypeParameters(parameter: Symbol, contextualType: Type, mapper: TypeMapper) { + let links = getSymbolLinks(parameter); + if (!links.type) { + links.type = instantiateType(contextualType, mapper); } else if (isInferentialContext(mapper)) { - inferTypes(mapper.context, parameterLinks.type, instantiateType(contextualType, mapper)); + // Even if the parameter already has a type, it might be because it was given a type while + // processing the function as an argument to a prior signature during overload resolution. + // If this was the case, it may have caused some type parameters to be fixed. So here, + // we need to ensure that type parameters at the same positions get fixed again. This is + // done by calling instantiateType to attach the mapper to the contextualType, and then + // calling inferTypes to force a walk of contextualType so that all the correct fixing + // happens. The choice to pass in links.type may seem kind of arbitrary, but it serves + // to make sure that all the correct positions in contextualType are reached by the walk. + // Here is an example: + // + // interface Base { + // baseProp; + // } + // interface Derived extends Base { + // toBase(): Base; + // } + // + // var derived: Derived; + // + // declare function foo(x: T, func: (p: T) => T): T; + // declare function foo(x: T, func: (p: T) => T): T; + // + // var result = foo(derived, d => d.toBase()); + // + // We are typing d while checking the second overload. But we've already given d + // a type (Derived) from the first overload. However, we still want to fix the + // T in the second overload so that we do not infer Base as a candidate for T + // (inferring Base would make type argument inference inconsistent between the two + // overloads). + inferTypes(mapper.context, links.type, instantiateType(contextualType, mapper)); } } @@ -9031,7 +9061,9 @@ namespace ts { let contextSensitive = isContextSensitive(node); let mightFixTypeParameters = contextSensitive && isInferentialContext(contextualMapper); - // Check if function expression is contextually typed and assign parameter types if so + // Check if function expression is contextually typed and assign parameter types if so. + // See the comment in assignTypeToParameterAndFixTypeParameters to understand why we need to + // check mightFixTypeParameters. if (mightFixTypeParameters || !(links.flags & NodeCheckFlags.ContextChecked)) { let contextualSignature = getContextualSignature(node); // If a type check is started at a function expression that is an argument of a function call, obtaining the diff --git a/src/compiler/types.ts b/src/compiler/types.ts index 7c893da9a6f..4b19ece77c1 100644 --- a/src/compiler/types.ts +++ b/src/compiler/types.ts @@ -1893,7 +1893,9 @@ namespace ts { /* @internal */ export interface TypeMapper { (t: TypeParameter): Type; - context?: InferenceContext; + context?: InferenceContext; // The inference context this mapper was created from. + // Only inference mappers have this set (in createInferenceMapper). + // The identity mapper and regular instantiation mappers do not need it. } /* @internal */ From 726eea2896e4c8054f0e162c10399e4b930c1845 Mon Sep 17 00:00:00 2001 From: Vladimir Matveev Date: Tue, 30 Jun 2015 16:11:09 -0700 Subject: [PATCH 20/64] dispose script snapshots from the old source file --- src/services/services.ts | 13 +++++++++++++ src/services/shims.ts | 9 +++++++++ 2 files changed, 22 insertions(+) diff --git a/src/services/services.ts b/src/services/services.ts index 521c6db155a..41996349fba 100644 --- a/src/services/services.ts +++ b/src/services/services.ts @@ -91,6 +91,9 @@ module ts { * not happen and the entire document will be re - parsed. */ getChangeRange(oldSnapshot: IScriptSnapshot): TextChangeRange; + + /** Releases all resources held by this script snapshot */ + dispose?(): void; } export module ScriptSnapshot { @@ -1873,6 +1876,16 @@ module ts { // after incremental parsing nameTable might not be up-to-date // drop it so it can be lazily recreated later newSourceFile.nameTable = undefined; + + // dispose all resources held by old script snapshot + if (sourceFile.scriptSnapshot) { + if (sourceFile.scriptSnapshot.dispose) { + sourceFile.scriptSnapshot.dispose(); + } + + sourceFile.scriptSnapshot = undefined; + } + return newSourceFile; } } diff --git a/src/services/shims.ts b/src/services/shims.ts index d6f9f7a968a..6743f48df1d 100644 --- a/src/services/shims.ts +++ b/src/services/shims.ts @@ -34,6 +34,9 @@ module ts { * Or undefined value if there was no change. */ getChangeRange(oldSnapshot: ScriptSnapshotShim): string; + + /** Releases all resources held by this script snapshot */ + dispose?(): void; } export interface Logger { @@ -242,6 +245,12 @@ module ts { return createTextChangeRange( createTextSpan(decoded.span.start, decoded.span.length), decoded.newLength); } + + public dispose(): void { + if ("dispose" in this.scriptSnapshotShim) { + this.scriptSnapshotShim.dispose(); + } + } } export class LanguageServiceShimHostAdapter implements LanguageServiceHost { From ee1350b40e6cdd4a49eb298f591ad62afb4f3993 Mon Sep 17 00:00:00 2001 From: Vladimir Matveev Date: Wed, 1 Jul 2015 23:14:40 -0700 Subject: [PATCH 21/64] dispose snapshot only if new file differs from the old file --- src/services/services.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/services/services.ts b/src/services/services.ts index 41996349fba..a446c45aa8f 100644 --- a/src/services/services.ts +++ b/src/services/services.ts @@ -1878,7 +1878,7 @@ module ts { newSourceFile.nameTable = undefined; // dispose all resources held by old script snapshot - if (sourceFile.scriptSnapshot) { + if (sourceFile !== newSourceFile && sourceFile.scriptSnapshot) { if (sourceFile.scriptSnapshot.dispose) { sourceFile.scriptSnapshot.dispose(); } From e190761d96beaa0aa39e84de010695c63b05e64d Mon Sep 17 00:00:00 2001 From: Vladimir Matveev Date: Thu, 9 Jul 2015 13:13:49 -0700 Subject: [PATCH 22/64] addressed PR feedback: added comments --- src/services/shims.ts | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/services/shims.ts b/src/services/shims.ts index 6743f48df1d..e583a0d3d18 100644 --- a/src/services/shims.ts +++ b/src/services/shims.ts @@ -247,6 +247,8 @@ module ts { } public dispose(): void { + // if scriptSnapshotShim is a COM object then property check becomes method call with no arguments + // 'in' does not have this effect if ("dispose" in this.scriptSnapshotShim) { this.scriptSnapshotShim.dispose(); } From dcbb2e5f0f728b5788a255a7ba56b45816c0a75f Mon Sep 17 00:00:00 2001 From: Jason Freeman Date: Fri, 10 Jul 2015 11:35:03 -0700 Subject: [PATCH 23/64] Add a comment for isInferentialContext --- src/compiler/checker.ts | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 534deb5fde6..19c7c094c22 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -6700,8 +6700,21 @@ namespace ts { return result; } - // Presence of a contextual type mapper indicates inferential typing, except the identityMapper object is - // used as a special marker for other purposes. + /** + * Detect if the mapper implies an inference context. Specifically, there are 4 possible values + * for a mapper. Let's go through each one of them: + * + * 1. undefined - this means we are not doing inferential typing, but we may do contextual typing, + * which could cause us to assign a parameter type + * 2. identityMapper - means we want to avoid assigning a parameter type, whether or not we are in + * inferential typing (context is undefined for the identityMapper) + * 3. a mapper created by createInferenceMapper - we are doing inferential typing, we want to assign + * parameter types and fix type parameters (context is defined) + * 4. an instantiation mapper created by createTypeMapper or createTypeEraser - this should never be + * passed as the contextual mapper when checking an expression (context is undefined for these) + * + * isInferentialContext is detecting if we are in case 3 + */ function isInferentialContext(mapper: TypeMapper) { return mapper && mapper.context; } From 86d106aff0fb160e39804b81779f4ee4d01daed4 Mon Sep 17 00:00:00 2001 From: vvakame Date: Sat, 11 Jul 2015 20:55:27 +0900 Subject: [PATCH 24/64] PR feedback --- src/compiler/emitter.ts | 29 ++++++----- tests/baselines/reference/es5-commonjs6.js | 10 ++++ .../baselines/reference/es5-commonjs6.symbols | 6 +++ tests/baselines/reference/es5-commonjs6.types | 7 +++ .../reference/tsxAttributeResolution9.symbols | 47 ------------------ .../reference/tsxAttributeResolution9.types | 49 ------------------- tests/cases/compiler/es5-commonjs6.ts | 7 +++ 7 files changed, 46 insertions(+), 109 deletions(-) create mode 100644 tests/baselines/reference/es5-commonjs6.js create mode 100644 tests/baselines/reference/es5-commonjs6.symbols create mode 100644 tests/baselines/reference/es5-commonjs6.types delete mode 100644 tests/baselines/reference/tsxAttributeResolution9.symbols delete mode 100644 tests/baselines/reference/tsxAttributeResolution9.types create mode 100644 tests/cases/compiler/es5-commonjs6.ts diff --git a/src/compiler/emitter.ts b/src/compiler/emitter.ts index 4fd5462d9f8..6cee68f7e12 100644 --- a/src/compiler/emitter.ts +++ b/src/compiler/emitter.ts @@ -3012,17 +3012,20 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, Promi return result; } - function emitEs6ExportDefaultCompat() { - if (compilerOptions.module === ModuleKind.CommonJS || compilerOptions.module === ModuleKind.AMD || compilerOptions.module === ModuleKind.UMD) { - if (!hasProperty(currentSourceFile.identifiers, "___esModule")) { - if (languageVersion >= ScriptTarget.ES5) { - // default value of configurable, enumerable, writable are `false`. - write("Object.defineProperty(exports, \"__esModule\", { value: true });"); - writeLine(); - } - else { - write("exports.__esModule = true;"); - writeLine(); + function emitEs6ExportDefaultCompat(node: Node) { + if (node.parent.kind === SyntaxKind.SourceFile && (!!(node.flags & NodeFlags.Default) || node.kind === SyntaxKind.ExportAssignment)) { + // only allow export default at a source file level + if (compilerOptions.module === ModuleKind.CommonJS || compilerOptions.module === ModuleKind.AMD || compilerOptions.module === ModuleKind.UMD) { + if (!currentSourceFile.symbol.exports["___esModule"]) { + if (languageVersion === ScriptTarget.ES5) { + // default value of configurable, enumerable, writable are `false`. + write("Object.defineProperty(exports, \"__esModule\", { value: true });"); + writeLine(); + } + else if (languageVersion === ScriptTarget.ES3) { + write("exports.__esModule = true;"); + writeLine(); + } } } } @@ -3050,7 +3053,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, Promi } else { if (node.flags & NodeFlags.Default) { - emitEs6ExportDefaultCompat(); + emitEs6ExportDefaultCompat(node); if (languageVersion === ScriptTarget.ES3) { write("exports[\"default\"]"); } @@ -5547,7 +5550,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, Promi write(")"); } else { - emitEs6ExportDefaultCompat(); + emitEs6ExportDefaultCompat(node); emitContainingModuleName(node); if (languageVersion === ScriptTarget.ES3) { write("[\"default\"] = "); diff --git a/tests/baselines/reference/es5-commonjs6.js b/tests/baselines/reference/es5-commonjs6.js new file mode 100644 index 00000000000..7c2c8b21779 --- /dev/null +++ b/tests/baselines/reference/es5-commonjs6.js @@ -0,0 +1,10 @@ +//// [es5-commonjs6.ts] + +export default "test"; +var __esModule = 1; + + +//// [es5-commonjs6.js] +Object.defineProperty(exports, "__esModule", { value: true }); +exports.default = "test"; +var __esModule = 1; diff --git a/tests/baselines/reference/es5-commonjs6.symbols b/tests/baselines/reference/es5-commonjs6.symbols new file mode 100644 index 00000000000..7a2847e0f25 --- /dev/null +++ b/tests/baselines/reference/es5-commonjs6.symbols @@ -0,0 +1,6 @@ +=== tests/cases/compiler/es5-commonjs6.ts === + +export default "test"; +var __esModule = 1; +>__esModule : Symbol(__esModule, Decl(es5-commonjs6.ts, 2, 3)) + diff --git a/tests/baselines/reference/es5-commonjs6.types b/tests/baselines/reference/es5-commonjs6.types new file mode 100644 index 00000000000..904b69dec22 --- /dev/null +++ b/tests/baselines/reference/es5-commonjs6.types @@ -0,0 +1,7 @@ +=== tests/cases/compiler/es5-commonjs6.ts === + +export default "test"; +var __esModule = 1; +>__esModule : number +>1 : number + diff --git a/tests/baselines/reference/tsxAttributeResolution9.symbols b/tests/baselines/reference/tsxAttributeResolution9.symbols deleted file mode 100644 index 081482d5d47..00000000000 --- a/tests/baselines/reference/tsxAttributeResolution9.symbols +++ /dev/null @@ -1,47 +0,0 @@ -=== tests/cases/conformance/jsx/react.d.ts === - -declare module JSX { ->JSX : Symbol(JSX, Decl(react.d.ts, 0, 0)) - - interface Element { } ->Element : Symbol(Element, Decl(react.d.ts, 1, 20)) - - interface IntrinsicElements { ->IntrinsicElements : Symbol(IntrinsicElements, Decl(react.d.ts, 2, 22)) - } - interface ElementAttributesProperty { ->ElementAttributesProperty : Symbol(ElementAttributesProperty, Decl(react.d.ts, 4, 2)) - - props; ->props : Symbol(props, Decl(react.d.ts, 5, 38)) - } -} - -interface Props { ->Props : Symbol(Props, Decl(react.d.ts, 8, 1)) - - foo: string; ->foo : Symbol(foo, Decl(react.d.ts, 10, 17)) -} - -=== tests/cases/conformance/jsx/file.tsx === -export class MyComponent { ->MyComponent : Symbol(MyComponent, Decl(file.tsx, 0, 0)) - - render() { ->render : Symbol(render, Decl(file.tsx, 0, 26)) - } - - props: { foo: string; } ->props : Symbol(props, Decl(file.tsx, 2, 3)) ->foo : Symbol(foo, Decl(file.tsx, 4, 10)) -} - -; // ok ->MyComponent : Symbol(MyComponent, Decl(file.tsx, 0, 0)) ->foo : Symbol(unknown) - -; // should be an error ->MyComponent : Symbol(MyComponent, Decl(file.tsx, 0, 0)) ->foo : Symbol(unknown) - diff --git a/tests/baselines/reference/tsxAttributeResolution9.types b/tests/baselines/reference/tsxAttributeResolution9.types deleted file mode 100644 index 1b2c6d42389..00000000000 --- a/tests/baselines/reference/tsxAttributeResolution9.types +++ /dev/null @@ -1,49 +0,0 @@ -=== tests/cases/conformance/jsx/react.d.ts === - -declare module JSX { ->JSX : any - - interface Element { } ->Element : Element - - interface IntrinsicElements { ->IntrinsicElements : IntrinsicElements - } - interface ElementAttributesProperty { ->ElementAttributesProperty : ElementAttributesProperty - - props; ->props : any - } -} - -interface Props { ->Props : Props - - foo: string; ->foo : string -} - -=== tests/cases/conformance/jsx/file.tsx === -export class MyComponent { ->MyComponent : MyComponent - - render() { ->render : () => void - } - - props: { foo: string; } ->props : { foo: string; } ->foo : string -} - -; // ok -> : JSX.Element ->MyComponent : typeof MyComponent ->foo : any - -; // should be an error -> : JSX.Element ->MyComponent : typeof MyComponent ->foo : any - diff --git a/tests/cases/compiler/es5-commonjs6.ts b/tests/cases/compiler/es5-commonjs6.ts new file mode 100644 index 00000000000..676e5bddb48 --- /dev/null +++ b/tests/cases/compiler/es5-commonjs6.ts @@ -0,0 +1,7 @@ +// @target: ES5 +// @sourcemap: false +// @declaration: false +// @module: commonjs + +export default "test"; +var __esModule = 1; From 1066f0e3cca7b1ddcf219490487edb7b13631ab5 Mon Sep 17 00:00:00 2001 From: "shyyko.serhiy@gmail.com" Date: Tue, 14 Jul 2015 15:28:05 +0300 Subject: [PATCH 25/64] fixed issue #3454 --- src/compiler/emitter.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/compiler/emitter.ts b/src/compiler/emitter.ts index fd0d4ad796e..1c032c0aa25 100644 --- a/src/compiler/emitter.ts +++ b/src/compiler/emitter.ts @@ -4219,6 +4219,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, Promi scopeEmitStart(node, "constructor"); increaseIndent(); if (ctor) { + var startIndex = emitDirectivePrologues(ctor.body.statements, /*startWithNewLine*/ true); emitDetachedComments(ctor.body.statements); } emitCaptureThisForNodeIfNecessary(node); @@ -4253,7 +4254,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, Promi if (superCall) { statements = statements.slice(1); } - emitLines(statements); + emitLinesStartingAt(statements, startIndex); } emitTempDeclarations(/*newLine*/ true); writeLine(); From aec0fb4818b7031fc1474b5497f084287e303133 Mon Sep 17 00:00:00 2001 From: "shyyko.serhiy@gmail.com" Date: Tue, 14 Jul 2015 17:02:18 +0300 Subject: [PATCH 26/64] fixed strictModeInConstructor baseline reference --- tests/baselines/reference/strictModeInConstructor.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/baselines/reference/strictModeInConstructor.js b/tests/baselines/reference/strictModeInConstructor.js index 7fd74aa108f..7d1adc48fa0 100644 --- a/tests/baselines/reference/strictModeInConstructor.js +++ b/tests/baselines/reference/strictModeInConstructor.js @@ -74,8 +74,8 @@ var A = (function () { var B = (function (_super) { __extends(B, _super); function B() { - this.s = 9; "use strict"; // No error + this.s = 9; _super.call(this); } return B; From 12809125f8eb406e7743b75425595c065e8e05af Mon Sep 17 00:00:00 2001 From: "shyyko.serhiy@gmail.com" Date: Tue, 14 Jul 2015 17:21:47 +0300 Subject: [PATCH 27/64] added comment --- src/compiler/emitter.ts | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/compiler/emitter.ts b/src/compiler/emitter.ts index 1c032c0aa25..7b083ba7363 100644 --- a/src/compiler/emitter.ts +++ b/src/compiler/emitter.ts @@ -4219,6 +4219,8 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, Promi scopeEmitStart(node, "constructor"); increaseIndent(); if (ctor) { + // Emit all the directive prologues (like "use strict"). These have to come before + // any other preamble code we write (like parameter initializers). var startIndex = emitDirectivePrologues(ctor.body.statements, /*startWithNewLine*/ true); emitDetachedComments(ctor.body.statements); } From a24aa6f57d281bafd3535f0f4c3f492364a8b4d6 Mon Sep 17 00:00:00 2001 From: Mohamed Hegazy Date: Tue, 14 Jul 2015 23:40:06 -0700 Subject: [PATCH 28/64] Update LKG --- bin/tsserver.js | 6 ++++++ bin/typescript.d.ts | 2 ++ bin/typescript.js | 14 ++++++++++++++ bin/typescriptServices.d.ts | 2 ++ bin/typescriptServices.js | 14 ++++++++++++++ 5 files changed, 38 insertions(+) diff --git a/bin/tsserver.js b/bin/tsserver.js index 040eac2ef75..d4ff3ea8a2b 100644 --- a/bin/tsserver.js +++ b/bin/tsserver.js @@ -31502,6 +31502,12 @@ var ts; var newSourceFile = ts.updateSourceFile(sourceFile, newText, textChangeRange, aggressiveChecks); setSourceFileFields(newSourceFile, scriptSnapshot, version); newSourceFile.nameTable = undefined; + if (sourceFile !== newSourceFile && sourceFile.scriptSnapshot) { + if (sourceFile.scriptSnapshot.dispose) { + sourceFile.scriptSnapshot.dispose(); + } + sourceFile.scriptSnapshot = undefined; + } return newSourceFile; } } diff --git a/bin/typescript.d.ts b/bin/typescript.d.ts index 11169b6fa28..f560e5958cf 100644 --- a/bin/typescript.d.ts +++ b/bin/typescript.d.ts @@ -1375,6 +1375,8 @@ declare module "typescript" { * not happen and the entire document will be re - parsed. */ getChangeRange(oldSnapshot: IScriptSnapshot): TextChangeRange; + /** Releases all resources held by this script snapshot */ + dispose?(): void; } module ScriptSnapshot { function fromString(text: string): IScriptSnapshot; diff --git a/bin/typescript.js b/bin/typescript.js index c2f23126ea8..a3b921d2341 100644 --- a/bin/typescript.js +++ b/bin/typescript.js @@ -36867,6 +36867,13 @@ var ts; // after incremental parsing nameTable might not be up-to-date // drop it so it can be lazily recreated later newSourceFile.nameTable = undefined; + // dispose all resources held by old script snapshot + if (sourceFile !== newSourceFile && sourceFile.scriptSnapshot) { + if (sourceFile.scriptSnapshot.dispose) { + sourceFile.scriptSnapshot.dispose(); + } + sourceFile.scriptSnapshot = undefined; + } return newSourceFile; } } @@ -41947,6 +41954,13 @@ var ts; var decoded = JSON.parse(encoded); return ts.createTextChangeRange(ts.createTextSpan(decoded.span.start, decoded.span.length), decoded.newLength); }; + ScriptSnapshotShimAdapter.prototype.dispose = function () { + // if scriptSnapshotShim is a COM object then property check becomes method call with no arguments + // 'in' does not have this effect + if ("dispose" in this.scriptSnapshotShim) { + this.scriptSnapshotShim.dispose(); + } + }; return ScriptSnapshotShimAdapter; })(); var LanguageServiceShimHostAdapter = (function () { diff --git a/bin/typescriptServices.d.ts b/bin/typescriptServices.d.ts index ae49ab102ad..e29f03ee3d8 100644 --- a/bin/typescriptServices.d.ts +++ b/bin/typescriptServices.d.ts @@ -1375,6 +1375,8 @@ declare module ts { * not happen and the entire document will be re - parsed. */ getChangeRange(oldSnapshot: IScriptSnapshot): TextChangeRange; + /** Releases all resources held by this script snapshot */ + dispose?(): void; } module ScriptSnapshot { function fromString(text: string): IScriptSnapshot; diff --git a/bin/typescriptServices.js b/bin/typescriptServices.js index c2f23126ea8..a3b921d2341 100644 --- a/bin/typescriptServices.js +++ b/bin/typescriptServices.js @@ -36867,6 +36867,13 @@ var ts; // after incremental parsing nameTable might not be up-to-date // drop it so it can be lazily recreated later newSourceFile.nameTable = undefined; + // dispose all resources held by old script snapshot + if (sourceFile !== newSourceFile && sourceFile.scriptSnapshot) { + if (sourceFile.scriptSnapshot.dispose) { + sourceFile.scriptSnapshot.dispose(); + } + sourceFile.scriptSnapshot = undefined; + } return newSourceFile; } } @@ -41947,6 +41954,13 @@ var ts; var decoded = JSON.parse(encoded); return ts.createTextChangeRange(ts.createTextSpan(decoded.span.start, decoded.span.length), decoded.newLength); }; + ScriptSnapshotShimAdapter.prototype.dispose = function () { + // if scriptSnapshotShim is a COM object then property check becomes method call with no arguments + // 'in' does not have this effect + if ("dispose" in this.scriptSnapshotShim) { + this.scriptSnapshotShim.dispose(); + } + }; return ScriptSnapshotShimAdapter; })(); var LanguageServiceShimHostAdapter = (function () { From a512e9eeae8e5b9f49357f69e298db98d2296582 Mon Sep 17 00:00:00 2001 From: vvakame Date: Thu, 16 Jul 2015 03:05:10 +0900 Subject: [PATCH 29/64] PR feedback --- src/compiler/emitter.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/compiler/emitter.ts b/src/compiler/emitter.ts index 6cee68f7e12..cd827a54c51 100644 --- a/src/compiler/emitter.ts +++ b/src/compiler/emitter.ts @@ -3013,7 +3013,8 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, Promi } function emitEs6ExportDefaultCompat(node: Node) { - if (node.parent.kind === SyntaxKind.SourceFile && (!!(node.flags & NodeFlags.Default) || node.kind === SyntaxKind.ExportAssignment)) { + if (node.parent.kind === SyntaxKind.SourceFile) { + Debug.assert(!!(node.flags & NodeFlags.Default) || node.kind === SyntaxKind.ExportAssignment); // only allow export default at a source file level if (compilerOptions.module === ModuleKind.CommonJS || compilerOptions.module === ModuleKind.AMD || compilerOptions.module === ModuleKind.UMD) { if (!currentSourceFile.symbol.exports["___esModule"]) { From 79dcc43b5081eda64bdfc9701071994a3a526234 Mon Sep 17 00:00:00 2001 From: Daniel Rosenwasser Date: Wed, 15 Jul 2015 13:53:54 -0700 Subject: [PATCH 30/64] Make JSON.stringify's 'space' parameter have type 'string | number'. --- src/lib/core.d.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/lib/core.d.ts b/src/lib/core.d.ts index f177c421f4f..442921ca5a4 100644 --- a/src/lib/core.d.ts +++ b/src/lib/core.d.ts @@ -971,14 +971,14 @@ interface JSON { * @param replacer A function that transforms the results. * @param space Adds indentation, white space, and line break characters to the return-value JSON text to make it easier to read. */ - stringify(value: any, replacer: (key: string, value: any) => any, space: any): string; + stringify(value: any, replacer: (key: string, value: any) => any, space: string | number): string; /** * Converts a JavaScript value to a JavaScript Object Notation (JSON) string. * @param value A JavaScript value, usually an object or array, to be converted. * @param replacer Array that transforms the results. * @param space Adds indentation, white space, and line break characters to the return-value JSON text to make it easier to read. */ - stringify(value: any, replacer: any[], space: any): string; + stringify(value: any, replacer: any[], space: string | number): string; } /** * An intrinsic object that provides functions to convert JavaScript values to and from the JavaScript Object Notation (JSON) format. @@ -1181,4 +1181,4 @@ interface PromiseLike { */ then(onfulfilled?: (value: T) => TResult | PromiseLike, onrejected?: (reason: any) => TResult | PromiseLike): PromiseLike; then(onfulfilled?: (value: T) => TResult | PromiseLike, onrejected?: (reason: any) => void): PromiseLike; -} +} From 52423f0e6e98079e7d5629a30a44e5b63dccfcdb Mon Sep 17 00:00:00 2001 From: Jason Ramsay Date: Wed, 17 Jun 2015 21:22:16 -0700 Subject: [PATCH 31/64] CoreServicesShimHost and CoreServicesShimHostAdapter changes to support TSConfig exclude from the language service --- src/services/shims.ts | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/src/services/shims.ts b/src/services/shims.ts index 84580470b27..362293c0c79 100644 --- a/src/services/shims.ts +++ b/src/services/shims.ts @@ -64,8 +64,12 @@ namespace ts { /** Public interface of the the of a config service shim instance.*/ export interface CoreServicesShimHost extends Logger { - /** Returns a JSON-encoded value of the type: string[] */ - readDirectory(rootDir: string, extension: string): string; + /** Returns a JSON-encoded value of the type: string[] + * + * @param exclude A JSON encoded string[] containing the paths to exclude + * when enumerating the directory. + */ + readDirectory(rootDir: string, extension: string, exclude?: string): string; } /// @@ -386,8 +390,18 @@ namespace ts { constructor(private shimHost: CoreServicesShimHost) { } - public readDirectory(rootDir: string, extension: string): string[] { - var encoded = this.shimHost.readDirectory(rootDir, extension); + public readDirectory(rootDir: string, extension: string, exclude: string[]): string[] { + // Wrap the API changes for 1.5 release. This try/catch + // should be removed once TypeScript 1.5 has shipped. + // Also consider removing the optional designation for + // the exclude param at this time. + var encoded: string; + try { + encoded = this.shimHost.readDirectory(rootDir, extension, JSON.stringify(exclude)); + } + catch (e) { + encoded = this.shimHost.readDirectory(rootDir, extension); + } return JSON.parse(encoded); } } From dea66a66dc93118abdde6eec558d12d33c267829 Mon Sep 17 00:00:00 2001 From: Jason Ramsay Date: Wed, 15 Jul 2015 14:19:54 -0700 Subject: [PATCH 32/64] Fix comment spacing for readDirectory in shims.ts --- src/services/shims.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/services/shims.ts b/src/services/shims.ts index 362293c0c79..e2055b3de77 100644 --- a/src/services/shims.ts +++ b/src/services/shims.ts @@ -64,7 +64,8 @@ namespace ts { /** Public interface of the the of a config service shim instance.*/ export interface CoreServicesShimHost extends Logger { - /** Returns a JSON-encoded value of the type: string[] + /** + * Returns a JSON-encoded value of the type: string[] * * @param exclude A JSON encoded string[] containing the paths to exclude * when enumerating the directory. From 95cd3c3d0ffa19a3bc987367115070f0858f2645 Mon Sep 17 00:00:00 2001 From: Jason Freeman Date: Wed, 15 Jul 2015 14:41:24 -0700 Subject: [PATCH 33/64] Allow super element access --- src/compiler/parser.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/compiler/parser.ts b/src/compiler/parser.ts index 8c220604e89..127d1b58ee4 100644 --- a/src/compiler/parser.ts +++ b/src/compiler/parser.ts @@ -3295,7 +3295,7 @@ namespace ts { function parseSuperExpression(): MemberExpression { let expression = parseTokenNode(); - if (token === SyntaxKind.OpenParenToken || token === SyntaxKind.DotToken) { + if (token === SyntaxKind.OpenParenToken || token === SyntaxKind.DotToken || token === SyntaxKind.OpenBracketToken) { return expression; } From 75f97f302ac96c45d0c0fd2289d96e9fa9d4d1f9 Mon Sep 17 00:00:00 2001 From: Jason Freeman Date: Wed, 15 Jul 2015 14:41:36 -0700 Subject: [PATCH 34/64] Add tests --- .../reference/superSymbolIndexedAccess1.js | 27 +++++++++++++++ .../superSymbolIndexedAccess1.symbols | 29 ++++++++++++++++ .../reference/superSymbolIndexedAccess1.types | 34 +++++++++++++++++++ .../reference/superSymbolIndexedAccess2.js | 25 ++++++++++++++ .../superSymbolIndexedAccess2.symbols | 30 ++++++++++++++++ .../reference/superSymbolIndexedAccess2.types | 33 ++++++++++++++++++ .../superSymbolIndexedAccess3.errors.txt | 19 +++++++++++ .../reference/superSymbolIndexedAccess3.js | 27 +++++++++++++++ .../superSymbolIndexedAccess4.errors.txt | 13 +++++++ .../reference/superSymbolIndexedAccess4.js | 16 +++++++++ .../superSymbolIndexedAccess1.ts | 14 ++++++++ .../superSymbolIndexedAccess2.ts | 13 +++++++ .../superSymbolIndexedAccess3.ts | 14 ++++++++ .../superSymbolIndexedAccess4.ts | 8 +++++ 14 files changed, 302 insertions(+) create mode 100644 tests/baselines/reference/superSymbolIndexedAccess1.js create mode 100644 tests/baselines/reference/superSymbolIndexedAccess1.symbols create mode 100644 tests/baselines/reference/superSymbolIndexedAccess1.types create mode 100644 tests/baselines/reference/superSymbolIndexedAccess2.js create mode 100644 tests/baselines/reference/superSymbolIndexedAccess2.symbols create mode 100644 tests/baselines/reference/superSymbolIndexedAccess2.types create mode 100644 tests/baselines/reference/superSymbolIndexedAccess3.errors.txt create mode 100644 tests/baselines/reference/superSymbolIndexedAccess3.js create mode 100644 tests/baselines/reference/superSymbolIndexedAccess4.errors.txt create mode 100644 tests/baselines/reference/superSymbolIndexedAccess4.js create mode 100644 tests/cases/conformance/expressions/superPropertyAccess/superSymbolIndexedAccess1.ts create mode 100644 tests/cases/conformance/expressions/superPropertyAccess/superSymbolIndexedAccess2.ts create mode 100644 tests/cases/conformance/expressions/superPropertyAccess/superSymbolIndexedAccess3.ts create mode 100644 tests/cases/conformance/expressions/superPropertyAccess/superSymbolIndexedAccess4.ts diff --git a/tests/baselines/reference/superSymbolIndexedAccess1.js b/tests/baselines/reference/superSymbolIndexedAccess1.js new file mode 100644 index 00000000000..411158bcc7d --- /dev/null +++ b/tests/baselines/reference/superSymbolIndexedAccess1.js @@ -0,0 +1,27 @@ +//// [superSymbolIndexedAccess1.ts] +var symbol = Symbol.for('myThing'); + +class Foo { + [symbol]() { + return 0; + } +} + +class Bar extends Foo { + [symbol]() { + return super[symbol](); + } +} + +//// [superSymbolIndexedAccess1.js] +var symbol = Symbol.for('myThing'); +class Foo { + [symbol]() { + return 0; + } +} +class Bar extends Foo { + [symbol]() { + return super[symbol](); + } +} diff --git a/tests/baselines/reference/superSymbolIndexedAccess1.symbols b/tests/baselines/reference/superSymbolIndexedAccess1.symbols new file mode 100644 index 00000000000..818d0ac52af --- /dev/null +++ b/tests/baselines/reference/superSymbolIndexedAccess1.symbols @@ -0,0 +1,29 @@ +=== tests/cases/conformance/expressions/superPropertyAccess/superSymbolIndexedAccess1.ts === +var symbol = Symbol.for('myThing'); +>symbol : Symbol(symbol, Decl(superSymbolIndexedAccess1.ts, 0, 3)) +>Symbol.for : Symbol(SymbolConstructor.for, Decl(lib.d.ts, 1221, 42)) +>Symbol : Symbol(Symbol, Decl(lib.d.ts, 1199, 52), Decl(lib.d.ts, 1305, 11)) +>for : Symbol(SymbolConstructor.for, Decl(lib.d.ts, 1221, 42)) + +class Foo { +>Foo : Symbol(Foo, Decl(superSymbolIndexedAccess1.ts, 0, 35)) + + [symbol]() { +>symbol : Symbol(symbol, Decl(superSymbolIndexedAccess1.ts, 0, 3)) + + return 0; + } +} + +class Bar extends Foo { +>Bar : Symbol(Bar, Decl(superSymbolIndexedAccess1.ts, 6, 1)) +>Foo : Symbol(Foo, Decl(superSymbolIndexedAccess1.ts, 0, 35)) + + [symbol]() { +>symbol : Symbol(symbol, Decl(superSymbolIndexedAccess1.ts, 0, 3)) + + return super[symbol](); +>super : Symbol(Foo, Decl(superSymbolIndexedAccess1.ts, 0, 35)) +>symbol : Symbol(symbol, Decl(superSymbolIndexedAccess1.ts, 0, 3)) + } +} diff --git a/tests/baselines/reference/superSymbolIndexedAccess1.types b/tests/baselines/reference/superSymbolIndexedAccess1.types new file mode 100644 index 00000000000..af2c6cab156 --- /dev/null +++ b/tests/baselines/reference/superSymbolIndexedAccess1.types @@ -0,0 +1,34 @@ +=== tests/cases/conformance/expressions/superPropertyAccess/superSymbolIndexedAccess1.ts === +var symbol = Symbol.for('myThing'); +>symbol : symbol +>Symbol.for('myThing') : symbol +>Symbol.for : (key: string) => symbol +>Symbol : SymbolConstructor +>for : (key: string) => symbol +>'myThing' : string + +class Foo { +>Foo : Foo + + [symbol]() { +>symbol : symbol + + return 0; +>0 : number + } +} + +class Bar extends Foo { +>Bar : Bar +>Foo : Foo + + [symbol]() { +>symbol : symbol + + return super[symbol](); +>super[symbol]() : any +>super[symbol] : any +>super : Foo +>symbol : symbol + } +} diff --git a/tests/baselines/reference/superSymbolIndexedAccess2.js b/tests/baselines/reference/superSymbolIndexedAccess2.js new file mode 100644 index 00000000000..bc42addc41f --- /dev/null +++ b/tests/baselines/reference/superSymbolIndexedAccess2.js @@ -0,0 +1,25 @@ +//// [superSymbolIndexedAccess2.ts] + +class Foo { + [Symbol.isConcatSpreadable]() { + return 0; + } +} + +class Bar extends Foo { + [Symbol.isConcatSpreadable]() { + return super[Symbol.isConcatSpreadable](); + } +} + +//// [superSymbolIndexedAccess2.js] +class Foo { + [Symbol.isConcatSpreadable]() { + return 0; + } +} +class Bar extends Foo { + [Symbol.isConcatSpreadable]() { + return super[Symbol.isConcatSpreadable](); + } +} diff --git a/tests/baselines/reference/superSymbolIndexedAccess2.symbols b/tests/baselines/reference/superSymbolIndexedAccess2.symbols new file mode 100644 index 00000000000..3865b920647 --- /dev/null +++ b/tests/baselines/reference/superSymbolIndexedAccess2.symbols @@ -0,0 +1,30 @@ +=== tests/cases/conformance/expressions/superPropertyAccess/superSymbolIndexedAccess2.ts === + +class Foo { +>Foo : Symbol(Foo, Decl(superSymbolIndexedAccess2.ts, 0, 0)) + + [Symbol.isConcatSpreadable]() { +>Symbol.isConcatSpreadable : Symbol(SymbolConstructor.isConcatSpreadable, Decl(lib.d.ts, 1243, 24)) +>Symbol : Symbol(Symbol, Decl(lib.d.ts, 1199, 52), Decl(lib.d.ts, 1305, 11)) +>isConcatSpreadable : Symbol(SymbolConstructor.isConcatSpreadable, Decl(lib.d.ts, 1243, 24)) + + return 0; + } +} + +class Bar extends Foo { +>Bar : Symbol(Bar, Decl(superSymbolIndexedAccess2.ts, 5, 1)) +>Foo : Symbol(Foo, Decl(superSymbolIndexedAccess2.ts, 0, 0)) + + [Symbol.isConcatSpreadable]() { +>Symbol.isConcatSpreadable : Symbol(SymbolConstructor.isConcatSpreadable, Decl(lib.d.ts, 1243, 24)) +>Symbol : Symbol(Symbol, Decl(lib.d.ts, 1199, 52), Decl(lib.d.ts, 1305, 11)) +>isConcatSpreadable : Symbol(SymbolConstructor.isConcatSpreadable, Decl(lib.d.ts, 1243, 24)) + + return super[Symbol.isConcatSpreadable](); +>super : Symbol(Foo, Decl(superSymbolIndexedAccess2.ts, 0, 0)) +>Symbol.isConcatSpreadable : Symbol(SymbolConstructor.isConcatSpreadable, Decl(lib.d.ts, 1243, 24)) +>Symbol : Symbol(Symbol, Decl(lib.d.ts, 1199, 52), Decl(lib.d.ts, 1305, 11)) +>isConcatSpreadable : Symbol(SymbolConstructor.isConcatSpreadable, Decl(lib.d.ts, 1243, 24)) + } +} diff --git a/tests/baselines/reference/superSymbolIndexedAccess2.types b/tests/baselines/reference/superSymbolIndexedAccess2.types new file mode 100644 index 00000000000..72bb6914d3e --- /dev/null +++ b/tests/baselines/reference/superSymbolIndexedAccess2.types @@ -0,0 +1,33 @@ +=== tests/cases/conformance/expressions/superPropertyAccess/superSymbolIndexedAccess2.ts === + +class Foo { +>Foo : Foo + + [Symbol.isConcatSpreadable]() { +>Symbol.isConcatSpreadable : symbol +>Symbol : SymbolConstructor +>isConcatSpreadable : symbol + + return 0; +>0 : number + } +} + +class Bar extends Foo { +>Bar : Bar +>Foo : Foo + + [Symbol.isConcatSpreadable]() { +>Symbol.isConcatSpreadable : symbol +>Symbol : SymbolConstructor +>isConcatSpreadable : symbol + + return super[Symbol.isConcatSpreadable](); +>super[Symbol.isConcatSpreadable]() : number +>super[Symbol.isConcatSpreadable] : () => number +>super : Foo +>Symbol.isConcatSpreadable : symbol +>Symbol : SymbolConstructor +>isConcatSpreadable : symbol + } +} diff --git a/tests/baselines/reference/superSymbolIndexedAccess3.errors.txt b/tests/baselines/reference/superSymbolIndexedAccess3.errors.txt new file mode 100644 index 00000000000..7f25510e00b --- /dev/null +++ b/tests/baselines/reference/superSymbolIndexedAccess3.errors.txt @@ -0,0 +1,19 @@ +tests/cases/conformance/expressions/superPropertyAccess/superSymbolIndexedAccess3.ts(11,16): error TS2342: An index expression argument must be of type 'string', 'number', 'symbol, or 'any'. + + +==== tests/cases/conformance/expressions/superPropertyAccess/superSymbolIndexedAccess3.ts (1 errors) ==== + var symbol = Symbol.for('myThing'); + + class Foo { + [symbol]() { + return 0; + } + } + + class Bar extends Foo { + [symbol]() { + return super[Bar](); + ~~~~~~~~~~ +!!! error TS2342: An index expression argument must be of type 'string', 'number', 'symbol, or 'any'. + } + } \ No newline at end of file diff --git a/tests/baselines/reference/superSymbolIndexedAccess3.js b/tests/baselines/reference/superSymbolIndexedAccess3.js new file mode 100644 index 00000000000..439a13c6e6e --- /dev/null +++ b/tests/baselines/reference/superSymbolIndexedAccess3.js @@ -0,0 +1,27 @@ +//// [superSymbolIndexedAccess3.ts] +var symbol = Symbol.for('myThing'); + +class Foo { + [symbol]() { + return 0; + } +} + +class Bar extends Foo { + [symbol]() { + return super[Bar](); + } +} + +//// [superSymbolIndexedAccess3.js] +var symbol = Symbol.for('myThing'); +class Foo { + [symbol]() { + return 0; + } +} +class Bar extends Foo { + [symbol]() { + return super[Bar](); + } +} diff --git a/tests/baselines/reference/superSymbolIndexedAccess4.errors.txt b/tests/baselines/reference/superSymbolIndexedAccess4.errors.txt new file mode 100644 index 00000000000..dbf18c3d00d --- /dev/null +++ b/tests/baselines/reference/superSymbolIndexedAccess4.errors.txt @@ -0,0 +1,13 @@ +tests/cases/conformance/expressions/superPropertyAccess/superSymbolIndexedAccess4.ts(5,16): error TS2335: 'super' can only be referenced in a derived class. + + +==== tests/cases/conformance/expressions/superPropertyAccess/superSymbolIndexedAccess4.ts (1 errors) ==== + var symbol = Symbol.for('myThing'); + + class Bar { + [symbol]() { + return super[symbol](); + ~~~~~ +!!! error TS2335: 'super' can only be referenced in a derived class. + } + } \ No newline at end of file diff --git a/tests/baselines/reference/superSymbolIndexedAccess4.js b/tests/baselines/reference/superSymbolIndexedAccess4.js new file mode 100644 index 00000000000..8d966511fc6 --- /dev/null +++ b/tests/baselines/reference/superSymbolIndexedAccess4.js @@ -0,0 +1,16 @@ +//// [superSymbolIndexedAccess4.ts] +var symbol = Symbol.for('myThing'); + +class Bar { + [symbol]() { + return super[symbol](); + } +} + +//// [superSymbolIndexedAccess4.js] +var symbol = Symbol.for('myThing'); +class Bar { + [symbol]() { + return super[symbol](); + } +} diff --git a/tests/cases/conformance/expressions/superPropertyAccess/superSymbolIndexedAccess1.ts b/tests/cases/conformance/expressions/superPropertyAccess/superSymbolIndexedAccess1.ts new file mode 100644 index 00000000000..160a76f5c61 --- /dev/null +++ b/tests/cases/conformance/expressions/superPropertyAccess/superSymbolIndexedAccess1.ts @@ -0,0 +1,14 @@ +//@target: ES6 +var symbol = Symbol.for('myThing'); + +class Foo { + [symbol]() { + return 0; + } +} + +class Bar extends Foo { + [symbol]() { + return super[symbol](); + } +} \ No newline at end of file diff --git a/tests/cases/conformance/expressions/superPropertyAccess/superSymbolIndexedAccess2.ts b/tests/cases/conformance/expressions/superPropertyAccess/superSymbolIndexedAccess2.ts new file mode 100644 index 00000000000..3f399d41629 --- /dev/null +++ b/tests/cases/conformance/expressions/superPropertyAccess/superSymbolIndexedAccess2.ts @@ -0,0 +1,13 @@ +//@target: ES6 + +class Foo { + [Symbol.isConcatSpreadable]() { + return 0; + } +} + +class Bar extends Foo { + [Symbol.isConcatSpreadable]() { + return super[Symbol.isConcatSpreadable](); + } +} \ No newline at end of file diff --git a/tests/cases/conformance/expressions/superPropertyAccess/superSymbolIndexedAccess3.ts b/tests/cases/conformance/expressions/superPropertyAccess/superSymbolIndexedAccess3.ts new file mode 100644 index 00000000000..2fbbbdc63e6 --- /dev/null +++ b/tests/cases/conformance/expressions/superPropertyAccess/superSymbolIndexedAccess3.ts @@ -0,0 +1,14 @@ +//@target: ES6 +var symbol = Symbol.for('myThing'); + +class Foo { + [symbol]() { + return 0; + } +} + +class Bar extends Foo { + [symbol]() { + return super[Bar](); + } +} \ No newline at end of file diff --git a/tests/cases/conformance/expressions/superPropertyAccess/superSymbolIndexedAccess4.ts b/tests/cases/conformance/expressions/superPropertyAccess/superSymbolIndexedAccess4.ts new file mode 100644 index 00000000000..095fcc1dbb7 --- /dev/null +++ b/tests/cases/conformance/expressions/superPropertyAccess/superSymbolIndexedAccess4.ts @@ -0,0 +1,8 @@ +//@target: ES6 +var symbol = Symbol.for('myThing'); + +class Bar { + [symbol]() { + return super[symbol](); + } +} \ No newline at end of file From 8e5f34fb4b0dd515c77ab957b2ddaa7e0e40f17a Mon Sep 17 00:00:00 2001 From: Jason Freeman Date: Wed, 15 Jul 2015 15:04:24 -0700 Subject: [PATCH 35/64] Add downlevel emit tests --- .../reference/superSymbolIndexedAccess5.js | 40 +++++++++++++++++++ .../superSymbolIndexedAccess5.symbols | 26 ++++++++++++ .../reference/superSymbolIndexedAccess5.types | 29 ++++++++++++++ .../reference/superSymbolIndexedAccess6.js | 40 +++++++++++++++++++ .../superSymbolIndexedAccess6.symbols | 26 ++++++++++++ .../reference/superSymbolIndexedAccess6.types | 29 ++++++++++++++ .../superSymbolIndexedAccess5.ts | 14 +++++++ .../superSymbolIndexedAccess6.ts | 14 +++++++ 8 files changed, 218 insertions(+) create mode 100644 tests/baselines/reference/superSymbolIndexedAccess5.js create mode 100644 tests/baselines/reference/superSymbolIndexedAccess5.symbols create mode 100644 tests/baselines/reference/superSymbolIndexedAccess5.types create mode 100644 tests/baselines/reference/superSymbolIndexedAccess6.js create mode 100644 tests/baselines/reference/superSymbolIndexedAccess6.symbols create mode 100644 tests/baselines/reference/superSymbolIndexedAccess6.types create mode 100644 tests/cases/conformance/expressions/superPropertyAccess/superSymbolIndexedAccess5.ts create mode 100644 tests/cases/conformance/expressions/superPropertyAccess/superSymbolIndexedAccess6.ts diff --git a/tests/baselines/reference/superSymbolIndexedAccess5.js b/tests/baselines/reference/superSymbolIndexedAccess5.js new file mode 100644 index 00000000000..64a8ac5094c --- /dev/null +++ b/tests/baselines/reference/superSymbolIndexedAccess5.js @@ -0,0 +1,40 @@ +//// [superSymbolIndexedAccess5.ts] +var symbol: any; + +class Foo { + [symbol]() { + return 0; + } +} + +class Bar extends Foo { + [symbol]() { + return super[symbol](); + } +} + +//// [superSymbolIndexedAccess5.js] +var __extends = (this && this.__extends) || function (d, b) { + for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; + function __() { this.constructor = d; } + d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); +}; +var symbol; +var Foo = (function () { + function Foo() { + } + Foo.prototype[symbol] = function () { + return 0; + }; + return Foo; +})(); +var Bar = (function (_super) { + __extends(Bar, _super); + function Bar() { + _super.apply(this, arguments); + } + Bar.prototype[symbol] = function () { + return _super.prototype[symbol](); + }; + return Bar; +})(Foo); diff --git a/tests/baselines/reference/superSymbolIndexedAccess5.symbols b/tests/baselines/reference/superSymbolIndexedAccess5.symbols new file mode 100644 index 00000000000..98ff04a25cd --- /dev/null +++ b/tests/baselines/reference/superSymbolIndexedAccess5.symbols @@ -0,0 +1,26 @@ +=== tests/cases/conformance/expressions/superPropertyAccess/superSymbolIndexedAccess5.ts === +var symbol: any; +>symbol : Symbol(symbol, Decl(superSymbolIndexedAccess5.ts, 0, 3)) + +class Foo { +>Foo : Symbol(Foo, Decl(superSymbolIndexedAccess5.ts, 0, 16)) + + [symbol]() { +>symbol : Symbol(symbol, Decl(superSymbolIndexedAccess5.ts, 0, 3)) + + return 0; + } +} + +class Bar extends Foo { +>Bar : Symbol(Bar, Decl(superSymbolIndexedAccess5.ts, 6, 1)) +>Foo : Symbol(Foo, Decl(superSymbolIndexedAccess5.ts, 0, 16)) + + [symbol]() { +>symbol : Symbol(symbol, Decl(superSymbolIndexedAccess5.ts, 0, 3)) + + return super[symbol](); +>super : Symbol(Foo, Decl(superSymbolIndexedAccess5.ts, 0, 16)) +>symbol : Symbol(symbol, Decl(superSymbolIndexedAccess5.ts, 0, 3)) + } +} diff --git a/tests/baselines/reference/superSymbolIndexedAccess5.types b/tests/baselines/reference/superSymbolIndexedAccess5.types new file mode 100644 index 00000000000..abc3ba364b0 --- /dev/null +++ b/tests/baselines/reference/superSymbolIndexedAccess5.types @@ -0,0 +1,29 @@ +=== tests/cases/conformance/expressions/superPropertyAccess/superSymbolIndexedAccess5.ts === +var symbol: any; +>symbol : any + +class Foo { +>Foo : Foo + + [symbol]() { +>symbol : any + + return 0; +>0 : number + } +} + +class Bar extends Foo { +>Bar : Bar +>Foo : Foo + + [symbol]() { +>symbol : any + + return super[symbol](); +>super[symbol]() : any +>super[symbol] : any +>super : Foo +>symbol : any + } +} diff --git a/tests/baselines/reference/superSymbolIndexedAccess6.js b/tests/baselines/reference/superSymbolIndexedAccess6.js new file mode 100644 index 00000000000..e014cf47c1a --- /dev/null +++ b/tests/baselines/reference/superSymbolIndexedAccess6.js @@ -0,0 +1,40 @@ +//// [superSymbolIndexedAccess6.ts] +var symbol: any; + +class Foo { + static [symbol]() { + return 0; + } +} + +class Bar extends Foo { + static [symbol]() { + return super[symbol](); + } +} + +//// [superSymbolIndexedAccess6.js] +var __extends = (this && this.__extends) || function (d, b) { + for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; + function __() { this.constructor = d; } + d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); +}; +var symbol; +var Foo = (function () { + function Foo() { + } + Foo[symbol] = function () { + return 0; + }; + return Foo; +})(); +var Bar = (function (_super) { + __extends(Bar, _super); + function Bar() { + _super.apply(this, arguments); + } + Bar[symbol] = function () { + return _super[symbol](); + }; + return Bar; +})(Foo); diff --git a/tests/baselines/reference/superSymbolIndexedAccess6.symbols b/tests/baselines/reference/superSymbolIndexedAccess6.symbols new file mode 100644 index 00000000000..a79a6552674 --- /dev/null +++ b/tests/baselines/reference/superSymbolIndexedAccess6.symbols @@ -0,0 +1,26 @@ +=== tests/cases/conformance/expressions/superPropertyAccess/superSymbolIndexedAccess6.ts === +var symbol: any; +>symbol : Symbol(symbol, Decl(superSymbolIndexedAccess6.ts, 0, 3)) + +class Foo { +>Foo : Symbol(Foo, Decl(superSymbolIndexedAccess6.ts, 0, 16)) + + static [symbol]() { +>symbol : Symbol(symbol, Decl(superSymbolIndexedAccess6.ts, 0, 3)) + + return 0; + } +} + +class Bar extends Foo { +>Bar : Symbol(Bar, Decl(superSymbolIndexedAccess6.ts, 6, 1)) +>Foo : Symbol(Foo, Decl(superSymbolIndexedAccess6.ts, 0, 16)) + + static [symbol]() { +>symbol : Symbol(symbol, Decl(superSymbolIndexedAccess6.ts, 0, 3)) + + return super[symbol](); +>super : Symbol(Foo, Decl(superSymbolIndexedAccess6.ts, 0, 16)) +>symbol : Symbol(symbol, Decl(superSymbolIndexedAccess6.ts, 0, 3)) + } +} diff --git a/tests/baselines/reference/superSymbolIndexedAccess6.types b/tests/baselines/reference/superSymbolIndexedAccess6.types new file mode 100644 index 00000000000..830ade0c685 --- /dev/null +++ b/tests/baselines/reference/superSymbolIndexedAccess6.types @@ -0,0 +1,29 @@ +=== tests/cases/conformance/expressions/superPropertyAccess/superSymbolIndexedAccess6.ts === +var symbol: any; +>symbol : any + +class Foo { +>Foo : Foo + + static [symbol]() { +>symbol : any + + return 0; +>0 : number + } +} + +class Bar extends Foo { +>Bar : Bar +>Foo : Foo + + static [symbol]() { +>symbol : any + + return super[symbol](); +>super[symbol]() : any +>super[symbol] : any +>super : typeof Foo +>symbol : any + } +} diff --git a/tests/cases/conformance/expressions/superPropertyAccess/superSymbolIndexedAccess5.ts b/tests/cases/conformance/expressions/superPropertyAccess/superSymbolIndexedAccess5.ts new file mode 100644 index 00000000000..3c1a376eab6 --- /dev/null +++ b/tests/cases/conformance/expressions/superPropertyAccess/superSymbolIndexedAccess5.ts @@ -0,0 +1,14 @@ +//@target: ES5 +var symbol: any; + +class Foo { + [symbol]() { + return 0; + } +} + +class Bar extends Foo { + [symbol]() { + return super[symbol](); + } +} \ No newline at end of file diff --git a/tests/cases/conformance/expressions/superPropertyAccess/superSymbolIndexedAccess6.ts b/tests/cases/conformance/expressions/superPropertyAccess/superSymbolIndexedAccess6.ts new file mode 100644 index 00000000000..3850821e9f3 --- /dev/null +++ b/tests/cases/conformance/expressions/superPropertyAccess/superSymbolIndexedAccess6.ts @@ -0,0 +1,14 @@ +//@target: ES5 +var symbol: any; + +class Foo { + static [symbol]() { + return 0; + } +} + +class Bar extends Foo { + static [symbol]() { + return super[symbol](); + } +} \ No newline at end of file From 873835b9e50354dc26f67e0f0ddbc336349fbf93 Mon Sep 17 00:00:00 2001 From: Daniel Rosenwasser Date: Wed, 15 Jul 2015 15:07:04 -0700 Subject: [PATCH 36/64] Add tests. --- ...tifierDefinitionLocations_destructuring.ts | 2 +- ...lRefsObjectBindingElementPropertyName04.ts | 16 +++++++------- ...lRefsObjectBindingElementPropertyName05.ts | 14 +++---------- ...lRefsObjectBindingElementPropertyName06.ts | 13 +++++++++--- ...lRefsObjectBindingElementPropertyName09.ts | 21 +++++++++++++++++++ ...lRefsObjectBindingElementPropertyName10.ts | 21 +++++++++++++++++++ ...foForObjectBindingElementPropertyName03.ts | 14 +++++++++++++ ...foForObjectBindingElementPropertyName04.ts | 14 +++++++++++++ 8 files changed, 92 insertions(+), 23 deletions(-) create mode 100644 tests/cases/fourslash/findAllRefsObjectBindingElementPropertyName09.ts create mode 100644 tests/cases/fourslash/findAllRefsObjectBindingElementPropertyName10.ts create mode 100644 tests/cases/fourslash/quickInfoForObjectBindingElementPropertyName03.ts create mode 100644 tests/cases/fourslash/quickInfoForObjectBindingElementPropertyName04.ts diff --git a/tests/cases/fourslash/completionListAtIdentifierDefinitionLocations_destructuring.ts b/tests/cases/fourslash/completionListAtIdentifierDefinitionLocations_destructuring.ts index 0812cb138d2..7f8ef32e1ad 100644 --- a/tests/cases/fourslash/completionListAtIdentifierDefinitionLocations_destructuring.ts +++ b/tests/cases/fourslash/completionListAtIdentifierDefinitionLocations_destructuring.ts @@ -16,7 +16,7 @@ //// function func2({ a, b/*parameter2*/ -test.markers().forEach((m) => { +test.markers().forEach(m => { goTo.position(m.position, m.fileName); verify.completionListIsEmpty(); }); diff --git a/tests/cases/fourslash/findAllRefsObjectBindingElementPropertyName04.ts b/tests/cases/fourslash/findAllRefsObjectBindingElementPropertyName04.ts index ad72bd99bb8..a72023a1028 100644 --- a/tests/cases/fourslash/findAllRefsObjectBindingElementPropertyName04.ts +++ b/tests/cases/fourslash/findAllRefsObjectBindingElementPropertyName04.ts @@ -5,17 +5,17 @@ //// property2: string; ////} //// -////function f({ [|property1|]: p1 }: I, +////function f({ /**/[|property1|]: p1 }: I, //// { [|property1|] }: I, //// { property1: p2 }) { +//// +//// return property1 + 1; ////} -let ranges = test.ranges(); -for (let range of ranges) { - goTo.position(range.start); +goTo.marker(); - verify.referencesCountIs(ranges.length); - for (let expectedRange of ranges) { - verify.referencesAtPositionContains(expectedRange); - } +let ranges = test.ranges(); +verify.referencesCountIs(ranges.length); +for (let expectedRange of ranges) { + verify.referencesAtPositionContains(expectedRange); } \ No newline at end of file diff --git a/tests/cases/fourslash/findAllRefsObjectBindingElementPropertyName05.ts b/tests/cases/fourslash/findAllRefsObjectBindingElementPropertyName05.ts index aa6432fa62e..f7e3b80fe45 100644 --- a/tests/cases/fourslash/findAllRefsObjectBindingElementPropertyName05.ts +++ b/tests/cases/fourslash/findAllRefsObjectBindingElementPropertyName05.ts @@ -5,17 +5,9 @@ //// property2: string; ////} //// -////function f({ [|property1|]: p }, { property1 }) { +////function f({ /**/property1: p }, { property1 }) { //// let x = property1; ////} -// Notice only one range. -let ranges = test.ranges(); -for (let range of ranges) { - goTo.position(range.start); - - verify.referencesCountIs(ranges.length); - for (let expectedRange of ranges) { - verify.referencesAtPositionContains(expectedRange); - } -} \ No newline at end of file +goTo.marker(); +verify.referencesCountIs(0); \ No newline at end of file diff --git a/tests/cases/fourslash/findAllRefsObjectBindingElementPropertyName06.ts b/tests/cases/fourslash/findAllRefsObjectBindingElementPropertyName06.ts index 4ce33f2b6ad..67c7029861e 100644 --- a/tests/cases/fourslash/findAllRefsObjectBindingElementPropertyName06.ts +++ b/tests/cases/fourslash/findAllRefsObjectBindingElementPropertyName06.ts @@ -5,12 +5,19 @@ //// property2: string; ////} //// -////for (let { [|property1|]: p } of []) { +////var elems: I[]; +////for (let { [|property1|]: p } of elems) { ////} -////for (let { [|property1|] } of []) { +////for (let { property1 } of elems) { ////} -////for (var { [|property1|]: p } of []) { +////for (var { [|property1|]: p1 } of elems) { ////} +////var p2; +////for ({ property1 : p2 } of elems) { +////} + +// Note: if this test ever changes, consider updating +// 'quickInfoForObjectBindingElementPropertyName05.ts' let ranges = test.ranges(); for (let range of ranges) { diff --git a/tests/cases/fourslash/findAllRefsObjectBindingElementPropertyName09.ts b/tests/cases/fourslash/findAllRefsObjectBindingElementPropertyName09.ts new file mode 100644 index 00000000000..0b82c73e31d --- /dev/null +++ b/tests/cases/fourslash/findAllRefsObjectBindingElementPropertyName09.ts @@ -0,0 +1,21 @@ +/// + +////interface I { +//// [|property1|]: number; +//// property2: string; +////} +//// +////function f({ [|property1|]: p1 }: I, +//// { /**/[|property1|] }: I, +//// { property1: p2 }) { +//// +//// return [|property1|] + 1; +////} + +goTo.marker(); + +let ranges = test.ranges(); +verify.referencesCountIs(ranges.length); +for (let expectedRange of ranges) { + verify.referencesAtPositionContains(expectedRange); +} \ No newline at end of file diff --git a/tests/cases/fourslash/findAllRefsObjectBindingElementPropertyName10.ts b/tests/cases/fourslash/findAllRefsObjectBindingElementPropertyName10.ts new file mode 100644 index 00000000000..ea38f35d103 --- /dev/null +++ b/tests/cases/fourslash/findAllRefsObjectBindingElementPropertyName10.ts @@ -0,0 +1,21 @@ +/// + +////interface Recursive { +//// [|next|]?: Recursive; +//// value: any; +////} +//// +////function f ({ [|next|]: { [|next|]: x} }: Recursive) { +////} + +goTo.marker(); + +let ranges = test.ranges(); +for (let range of ranges) { + goTo.position(range.start); + + verify.referencesCountIs(ranges.length); + for (let expectedRange of ranges) { + verify.referencesAtPositionContains(expectedRange); + } +} \ No newline at end of file diff --git a/tests/cases/fourslash/quickInfoForObjectBindingElementPropertyName03.ts b/tests/cases/fourslash/quickInfoForObjectBindingElementPropertyName03.ts new file mode 100644 index 00000000000..cfdeef111dc --- /dev/null +++ b/tests/cases/fourslash/quickInfoForObjectBindingElementPropertyName03.ts @@ -0,0 +1,14 @@ +/// + +////interface Recursive { +//// next?: Recursive; +//// value: any; +////} +//// +////function f ({ /*1*/next: { /*2*/next: x} }: Recursive) { +////} + +for (let { position } of test.markers()) { + goTo.position(position) + verify.quickInfoIs("(property) Recursive.next: Recursive"); +} \ No newline at end of file diff --git a/tests/cases/fourslash/quickInfoForObjectBindingElementPropertyName04.ts b/tests/cases/fourslash/quickInfoForObjectBindingElementPropertyName04.ts new file mode 100644 index 00000000000..6a0a6cb792a --- /dev/null +++ b/tests/cases/fourslash/quickInfoForObjectBindingElementPropertyName04.ts @@ -0,0 +1,14 @@ +/// + +////interface Recursive { +//// next?: Recursive; +//// value: any; +////} +//// +////function f ({ /*1*/next: { /*2*/next: x} }) { +////} + +for (let { position } of test.markers()) { + goTo.position(position) + verify.quickInfoIs("(property) next: any"); +} \ No newline at end of file From 1f6e2ddeacbcd18763ee2c1ea9527dd240740cca Mon Sep 17 00:00:00 2001 From: Daniel Rosenwasser Date: Wed, 15 Jul 2015 15:53:11 -0700 Subject: [PATCH 37/64] Fixed reporting of problems with tests. --- src/harness/fourslash.ts | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/harness/fourslash.ts b/src/harness/fourslash.ts index 208237b8b64..c90494ce8ed 100644 --- a/src/harness/fourslash.ts +++ b/src/harness/fourslash.ts @@ -670,20 +670,20 @@ module FourSlash { var completions = this.getCompletionListAtCaret(); if ((!completions || completions.entries.length === 0) && negative) { - this.raiseError("Completion list is empty at Caret"); - } else if ((completions && completions.entries.length !== 0) && !negative) { - - var errorMsg = "\n" + "Completion List contains: [" + completions.entries[0].name; + this.raiseError("Completion list is empty at caret at position " + this.activeFile.fileName + " " + this.currentCaretPosition); + } + else if (completions && completions.entries.length !== 0 && !negative) { + let errorMsg = "\n" + "Completion List contains: [" + completions.entries[0].name; for (var i = 1; i < completions.entries.length; i++) { errorMsg += ", " + completions.entries[i].name; } errorMsg += "]\n"; - Harness.IO.log(errorMsg); - this.raiseError("Completion list is not empty at Caret"); + this.raiseError("Completion list is not empty at caret at position " + this.activeFile.fileName + " " + this.currentCaretPosition + errorMsg); } } + public verifyCompletionListAllowsNewIdentifier(negative: boolean) { var completions = this.getCompletionListAtCaret(); From 5c6a3d73b9e9eb3ac44590b30573e05394fa1cbc Mon Sep 17 00:00:00 2001 From: Daniel Rosenwasser Date: Wed, 15 Jul 2015 15:53:42 -0700 Subject: [PATCH 38/64] Use type predicate for 'isVariableLike'. --- src/compiler/utilities.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/compiler/utilities.ts b/src/compiler/utilities.ts index e66e1925519..37a7552a3e7 100644 --- a/src/compiler/utilities.ts +++ b/src/compiler/utilities.ts @@ -566,7 +566,7 @@ namespace ts { } } - export function isVariableLike(node: Node): boolean { + export function isVariableLike(node: Node): node is VariableLikeDeclaration { if (node) { switch (node.kind) { case SyntaxKind.BindingElement: From fdd1f30a955ea2aa99dea761754bb12ee52cc32b Mon Sep 17 00:00:00 2001 From: Daniel Rosenwasser Date: Wed, 15 Jul 2015 15:56:13 -0700 Subject: [PATCH 39/64] Enable retrieving the type of a binding property name when an initializer/type annotation is present. --- src/compiler/checker.ts | 19 ++++++++++++++----- src/services/services.ts | 15 +++++++++++++-- 2 files changed, 27 insertions(+), 7 deletions(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 8122ab3c983..38554f63b2a 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -2293,6 +2293,7 @@ namespace ts { if (declaration.parent.parent.kind === SyntaxKind.ForInStatement) { return anyType; } + if (declaration.parent.parent.kind === SyntaxKind.ForOfStatement) { // checkRightHandSideOfForOf will return undefined if the for-of expression type was // missing properties/signatures required to get its iteratedType (like @@ -2300,13 +2301,16 @@ namespace ts { // or it may have led to an error inside getElementTypeOfIterable. return checkRightHandSideOfForOf((declaration.parent.parent).expression) || anyType; } + if (isBindingPattern(declaration.parent)) { return getTypeForBindingElement(declaration); } + // Use type from type annotation if one is present if (declaration.type) { return getTypeFromTypeNode(declaration.type); } + if (declaration.kind === SyntaxKind.Parameter) { let func = declaration.parent; // For a parameter of a set accessor, use the type of the get accessor if one is present @@ -2322,14 +2326,22 @@ namespace ts { return type; } } + // Use the type of the initializer expression if one is present if (declaration.initializer) { return checkExpressionCached(declaration.initializer); } + // If it is a short-hand property assignment, use the type of the identifier if (declaration.kind === SyntaxKind.ShorthandPropertyAssignment) { return checkIdentifier(declaration.name); } + + // If the declaration specifies a binding pattern, use the type implied by the binding pattern + if (isBindingPattern(declaration.name)) { + return getTypeFromBindingPattern(declaration.name); + } + // No type specified and nothing can be inferred return undefined; } @@ -2415,13 +2427,10 @@ namespace ts { // tools see the actual type. return declaration.kind !== SyntaxKind.PropertyAssignment ? getWidenedType(type) : type; } - // If no type was specified and nothing could be inferred, and if the declaration specifies a binding pattern, use - // the type implied by the binding pattern - if (isBindingPattern(declaration.name)) { - return getTypeFromBindingPattern(declaration.name); - } + // Rest parameters default to type any[], other parameters default to type any type = declaration.dotDotDotToken ? anyArrayType : anyType; + // Report implicit any errors unless this is a private property within an ambient declaration if (reportErrors && compilerOptions.noImplicitAny) { let root = getRootDeclaration(declaration); diff --git a/src/services/services.ts b/src/services/services.ts index d79436bb478..0a34ed0e1c0 100644 --- a/src/services/services.ts +++ b/src/services/services.ts @@ -3232,8 +3232,19 @@ namespace ts { // We are *only* completing on properties from the type being destructured. isNewIdentifierLocation = false; - typeForObject = typeChecker.getTypeAtLocation(objectLikeContainer); - existingMembers = (objectLikeContainer).elements; + let rootDeclaration = getRootDeclaration(objectLikeContainer.parent); + if (isVariableLike(rootDeclaration)) { + // We don't want to complete using the type acquired by the shape + // of the binding pattern; we are only interested in types acquired + // through type declaration or inference. + if (rootDeclaration.initializer || rootDeclaration.type) { + typeForObject = typeChecker.getTypeAtLocation(objectLikeContainer); + existingMembers = (objectLikeContainer).elements; + } + } + else { + Debug.fail("Root declaration is not variable-like.") + } } else { Debug.fail("Expected object literal or binding pattern, got " + objectLikeContainer.kind); From 5cd77167ec212f94ea2cc8783678440b8ffafd0b Mon Sep 17 00:00:00 2001 From: Daniel Rosenwasser Date: Wed, 15 Jul 2015 15:57:01 -0700 Subject: [PATCH 40/64] Updated baselines. --- tests/baselines/reference/arrowFunctionExpressions.symbols | 2 ++ tests/baselines/reference/emitArrowFunctionES6.symbols | 2 ++ 2 files changed, 4 insertions(+) diff --git a/tests/baselines/reference/arrowFunctionExpressions.symbols b/tests/baselines/reference/arrowFunctionExpressions.symbols index 28945e1179f..61c575933da 100644 --- a/tests/baselines/reference/arrowFunctionExpressions.symbols +++ b/tests/baselines/reference/arrowFunctionExpressions.symbols @@ -70,6 +70,7 @@ var p6 = ({ a }) => { }; var p7 = ({ a: { b } }) => { }; >p7 : Symbol(p7, Decl(arrowFunctionExpressions.ts, 21, 3)) +>a : Symbol(a) >b : Symbol(b, Decl(arrowFunctionExpressions.ts, 21, 16)) var p8 = ({ a = 1 }) => { }; @@ -78,6 +79,7 @@ var p8 = ({ a = 1 }) => { }; var p9 = ({ a: { b = 1 } = { b: 1 } }) => { }; >p9 : Symbol(p9, Decl(arrowFunctionExpressions.ts, 23, 3)) +>a : Symbol(a) >b : Symbol(b, Decl(arrowFunctionExpressions.ts, 23, 16)) >b : Symbol(b, Decl(arrowFunctionExpressions.ts, 23, 28)) diff --git a/tests/baselines/reference/emitArrowFunctionES6.symbols b/tests/baselines/reference/emitArrowFunctionES6.symbols index 06f83f7f6f0..8d1603cfd82 100644 --- a/tests/baselines/reference/emitArrowFunctionES6.symbols +++ b/tests/baselines/reference/emitArrowFunctionES6.symbols @@ -56,6 +56,7 @@ var p6 = ({ a }) => { }; var p7 = ({ a: { b } }) => { }; >p7 : Symbol(p7, Decl(emitArrowFunctionES6.ts, 15, 3)) +>a : Symbol(a) >b : Symbol(b, Decl(emitArrowFunctionES6.ts, 15, 16)) var p8 = ({ a = 1 }) => { }; @@ -64,6 +65,7 @@ var p8 = ({ a = 1 }) => { }; var p9 = ({ a: { b = 1 } = { b: 1 } }) => { }; >p9 : Symbol(p9, Decl(emitArrowFunctionES6.ts, 17, 3)) +>a : Symbol(a) >b : Symbol(b, Decl(emitArrowFunctionES6.ts, 17, 16)) >b : Symbol(b, Decl(emitArrowFunctionES6.ts, 17, 28)) From 9233073d235b745b599a4b71dfebbb70749e1c0a Mon Sep 17 00:00:00 2001 From: Daniel Rosenwasser Date: Wed, 15 Jul 2015 16:05:49 -0700 Subject: [PATCH 41/64] Fixed tests. --- .../findAllRefsObjectBindingElementPropertyName10.ts | 2 -- .../quickInfoForObjectBindingElementPropertyName04.ts | 11 +++++++---- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/tests/cases/fourslash/findAllRefsObjectBindingElementPropertyName10.ts b/tests/cases/fourslash/findAllRefsObjectBindingElementPropertyName10.ts index ea38f35d103..7b8be1aa91c 100644 --- a/tests/cases/fourslash/findAllRefsObjectBindingElementPropertyName10.ts +++ b/tests/cases/fourslash/findAllRefsObjectBindingElementPropertyName10.ts @@ -8,8 +8,6 @@ ////function f ({ [|next|]: { [|next|]: x} }: Recursive) { ////} -goTo.marker(); - let ranges = test.ranges(); for (let range of ranges) { goTo.position(range.start); diff --git a/tests/cases/fourslash/quickInfoForObjectBindingElementPropertyName04.ts b/tests/cases/fourslash/quickInfoForObjectBindingElementPropertyName04.ts index 6a0a6cb792a..8b152740861 100644 --- a/tests/cases/fourslash/quickInfoForObjectBindingElementPropertyName04.ts +++ b/tests/cases/fourslash/quickInfoForObjectBindingElementPropertyName04.ts @@ -8,7 +8,10 @@ ////function f ({ /*1*/next: { /*2*/next: x} }) { ////} -for (let { position } of test.markers()) { - goTo.position(position) - verify.quickInfoIs("(property) next: any"); -} \ No newline at end of file +goTo.marker("1"); +verify.quickInfoIs(`(property) next: { + next: any; +}`); + +goTo.marker("2"); +verify.quickInfoIs("(property) next: any"); \ No newline at end of file From c17934ed3d3d929ec6bf6daa0412bfbb6fa140e4 Mon Sep 17 00:00:00 2001 From: Jason Freeman Date: Wed, 15 Jul 2015 16:21:31 -0700 Subject: [PATCH 42/64] Update LKG --- bin/tsc.js | 126 ++++++--- bin/tsserver.js | 552 ++++++++++++++++++++------------------ bin/typescript.js | 358 +++++++++++++++--------- bin/typescriptServices.js | 358 +++++++++++++++--------- 4 files changed, 839 insertions(+), 555 deletions(-) diff --git a/bin/tsc.js b/bin/tsc.js index f5a780a390d..185aca1ef44 100644 --- a/bin/tsc.js +++ b/bin/tsc.js @@ -933,7 +933,14 @@ var ts; newLine: _os.EOL, useCaseSensitiveFileNames: useCaseSensitiveFileNames, write: function (s) { - _fs.writeSync(1, s); + var buffer = new Buffer(s, 'utf8'); + var offset = 0; + var toWrite = buffer.length; + var written = 0; + while ((written = _fs.writeSync(1, buffer, offset, toWrite)) < toWrite) { + offset += written; + toWrite -= written; + } }, readFile: readFile, writeFile: writeFile, @@ -1401,7 +1408,7 @@ var ts; Classes_containing_abstract_methods_must_be_marked_abstract: { code: 2514, category: ts.DiagnosticCategory.Error, key: "Classes containing abstract methods must be marked abstract." }, Non_abstract_class_0_does_not_implement_inherited_abstract_member_1_from_class_2: { code: 2515, category: ts.DiagnosticCategory.Error, key: "Non-abstract class '{0}' does not implement inherited abstract member '{1}' from class '{2}'." }, All_declarations_of_an_abstract_method_must_be_consecutive: { code: 2516, category: ts.DiagnosticCategory.Error, key: "All declarations of an abstract method must be consecutive." }, - Constructor_objects_of_abstract_type_cannot_be_assigned_to_constructor_objects_of_non_abstract_type: { code: 2517, category: ts.DiagnosticCategory.Error, key: "Constructor objects of abstract type cannot be assigned to constructor objects of non-abstract type" }, + Cannot_assign_an_abstract_constructor_type_to_a_non_abstract_constructor_type: { code: 2517, category: ts.DiagnosticCategory.Error, key: "Cannot assign an abstract constructor type to a non-abstract constructor type." }, Only_an_ambient_class_can_be_merged_with_an_interface: { code: 2518, category: ts.DiagnosticCategory.Error, key: "Only an ambient class can be merged with an interface." }, Duplicate_identifier_0_Compiler_uses_declaration_1_to_support_async_functions: { code: 2520, category: ts.DiagnosticCategory.Error, key: "Duplicate identifier '{0}'. Compiler uses declaration '{1}' to support async functions." }, Expression_resolves_to_variable_declaration_0_that_compiler_uses_to_support_async_functions: { code: 2521, category: ts.DiagnosticCategory.Error, key: "Expression resolves to variable declaration '{0}' that compiler uses to support async functions." }, @@ -9187,7 +9194,8 @@ var ts; } else { node.exportClause = parseNamedImportsOrExports(226); - if (parseOptional(130)) { + if (token === 130 || (token === 8 && !scanner.hasPrecedingLineBreak())) { + parseExpected(130); node.moduleSpecifier = parseModuleSpecifier(); } } @@ -13263,7 +13271,7 @@ var ts; var id = getTypeListId(elementTypes); var type = tupleTypes[id]; if (!type) { - type = tupleTypes[id] = createObjectType(8192); + type = tupleTypes[id] = createObjectType(8192 | getWideningFlagsOfTypes(elementTypes)); type.elementTypes = elementTypes; } return type; @@ -14084,10 +14092,29 @@ var ts; var targetSignatures = getSignaturesOfType(target, kind); var result = -1; var saveErrorInfo = errorInfo; + var sourceSig = sourceSignatures[0]; + var targetSig = targetSignatures[0]; + if (sourceSig && targetSig) { + var sourceErasedSignature = getErasedSignature(sourceSig); + var targetErasedSignature = getErasedSignature(targetSig); + var sourceReturnType = sourceErasedSignature && getReturnTypeOfSignature(sourceErasedSignature); + var targetReturnType = targetErasedSignature && getReturnTypeOfSignature(targetErasedSignature); + var sourceReturnDecl = sourceReturnType && sourceReturnType.symbol && ts.getDeclarationOfKind(sourceReturnType.symbol, 211); + var targetReturnDecl = targetReturnType && targetReturnType.symbol && ts.getDeclarationOfKind(targetReturnType.symbol, 211); + var sourceIsAbstract = sourceReturnDecl && sourceReturnDecl.flags & 256; + var targetIsAbstract = targetReturnDecl && targetReturnDecl.flags & 256; + if (sourceIsAbstract && !targetIsAbstract) { + if (reportErrors) { + reportError(ts.Diagnostics.Cannot_assign_an_abstract_constructor_type_to_a_non_abstract_constructor_type); + } + return 0; + } + } outer: for (var _i = 0; _i < targetSignatures.length; _i++) { var t = targetSignatures[_i]; if (!t.hasStringLiterals || target.flags & 262144) { var localErrors = reportErrors; + var checkedAbstractAssignability = false; for (var _a = 0; _a < sourceSignatures.length; _a++) { var s = sourceSignatures[_a]; if (!s.hasStringLiterals || source.flags & 262144) { @@ -14135,12 +14162,12 @@ var ts; target = getErasedSignature(target); var result = -1; for (var i = 0; i < checkCount; i++) { - var s_1 = i < sourceMax ? getTypeOfSymbol(source.parameters[i]) : getRestTypeOfSignature(source); - var t_1 = i < targetMax ? getTypeOfSymbol(target.parameters[i]) : getRestTypeOfSignature(target); + var s = i < sourceMax ? getTypeOfSymbol(source.parameters[i]) : getRestTypeOfSignature(source); + var t = i < targetMax ? getTypeOfSymbol(target.parameters[i]) : getRestTypeOfSignature(target); var saveErrorInfo = errorInfo; - var related = isRelatedTo(s_1, t_1, reportErrors); + var related = isRelatedTo(s, t, reportErrors); if (!related) { - related = isRelatedTo(t_1, s_1, false); + related = isRelatedTo(t, s, false); if (!related) { if (reportErrors) { reportError(ts.Diagnostics.Types_of_parameters_0_and_1_are_incompatible, source.parameters[i < sourceMax ? i : sourceMax].name, target.parameters[i < targetMax ? i : targetMax].name); @@ -14178,11 +14205,11 @@ var ts; } return 0; } - var t = getReturnTypeOfSignature(target); - if (t === voidType) + var targetReturnType = getReturnTypeOfSignature(target); + if (targetReturnType === voidType) return result; - var s = getReturnTypeOfSignature(source); - return result & isRelatedTo(s, t, reportErrors); + var sourceReturnType = getReturnTypeOfSignature(source); + return result & isRelatedTo(sourceReturnType, targetReturnType, reportErrors); } function signaturesIdenticalTo(source, target, kind) { var sourceSignatures = getSignaturesOfType(source, kind); @@ -14395,7 +14422,7 @@ var ts; return !!getPropertyOfType(type, "0"); } function isTupleType(type) { - return (type.flags & 8192) && !!type.elementTypes; + return !!(type.flags & 8192); } function getWidenedTypeOfObjectLiteral(type) { var properties = getPropertiesOfObjectType(type); @@ -14437,25 +14464,36 @@ var ts; if (isArrayType(type)) { return createArrayType(getWidenedType(type.typeArguments[0])); } + if (isTupleType(type)) { + return createTupleType(ts.map(type.elementTypes, getWidenedType)); + } } return type; } function reportWideningErrorsInType(type) { + var errorReported = false; if (type.flags & 16384) { - var errorReported = false; - ts.forEach(type.types, function (t) { + for (var _i = 0, _a = type.types; _i < _a.length; _i++) { + var t = _a[_i]; if (reportWideningErrorsInType(t)) { errorReported = true; } - }); - return errorReported; + } } if (isArrayType(type)) { return reportWideningErrorsInType(type.typeArguments[0]); } + if (isTupleType(type)) { + for (var _b = 0, _c = type.elementTypes; _b < _c.length; _b++) { + var t = _c[_b]; + if (reportWideningErrorsInType(t)) { + errorReported = true; + } + } + } if (type.flags & 524288) { - var errorReported = false; - ts.forEach(getPropertiesOfObjectType(type), function (p) { + for (var _d = 0, _e = getPropertiesOfObjectType(type); _d < _e.length; _d++) { + var p = _e[_d]; var t = getTypeOfSymbol(p); if (t.flags & 1048576) { if (!reportWideningErrorsInType(t)) { @@ -14463,10 +14501,9 @@ var ts; } errorReported = true; } - }); - return errorReported; + } } - return false; + return errorReported; } function reportImplicitAnyError(declaration, type) { var typeAsString = typeToString(getWidenedType(type)); @@ -14614,28 +14651,31 @@ var ts; inferFromTypes(sourceType, target); } } - else if (source.flags & 80896 && (target.flags & (4096 | 8192) || - (target.flags & 65536) && target.symbol && target.symbol.flags & (8192 | 2048 | 32))) { - if (isInProcess(source, target)) { - return; + else { + source = getApparentType(source); + if (source.flags & 80896 && (target.flags & (4096 | 8192) || + (target.flags & 65536) && target.symbol && target.symbol.flags & (8192 | 2048 | 32))) { + if (isInProcess(source, target)) { + return; + } + if (isDeeplyNestedGeneric(source, sourceStack, depth) && isDeeplyNestedGeneric(target, targetStack, depth)) { + return; + } + if (depth === 0) { + sourceStack = []; + targetStack = []; + } + sourceStack[depth] = source; + targetStack[depth] = target; + depth++; + inferFromProperties(source, target); + inferFromSignatures(source, target, 0); + inferFromSignatures(source, target, 1); + inferFromIndexTypes(source, target, 0, 0); + inferFromIndexTypes(source, target, 1, 1); + inferFromIndexTypes(source, target, 0, 1); + depth--; } - if (isDeeplyNestedGeneric(source, sourceStack, depth) && isDeeplyNestedGeneric(target, targetStack, depth)) { - return; - } - if (depth === 0) { - sourceStack = []; - targetStack = []; - } - sourceStack[depth] = source; - targetStack[depth] = target; - depth++; - inferFromProperties(source, target); - inferFromSignatures(source, target, 0); - inferFromSignatures(source, target, 1); - inferFromIndexTypes(source, target, 0, 0); - inferFromIndexTypes(source, target, 1, 1); - inferFromIndexTypes(source, target, 0, 1); - depth--; } } function inferFromProperties(source, target) { diff --git a/bin/tsserver.js b/bin/tsserver.js index bb420529a8c..9d582485e2f 100644 --- a/bin/tsserver.js +++ b/bin/tsserver.js @@ -933,7 +933,14 @@ var ts; newLine: _os.EOL, useCaseSensitiveFileNames: useCaseSensitiveFileNames, write: function (s) { - _fs.writeSync(1, s); + var buffer = new Buffer(s, 'utf8'); + var offset = 0; + var toWrite = buffer.length; + var written = 0; + while ((written = _fs.writeSync(1, buffer, offset, toWrite)) < toWrite) { + offset += written; + toWrite -= written; + } }, readFile: readFile, writeFile: writeFile, @@ -1401,7 +1408,7 @@ var ts; Classes_containing_abstract_methods_must_be_marked_abstract: { code: 2514, category: ts.DiagnosticCategory.Error, key: "Classes containing abstract methods must be marked abstract." }, Non_abstract_class_0_does_not_implement_inherited_abstract_member_1_from_class_2: { code: 2515, category: ts.DiagnosticCategory.Error, key: "Non-abstract class '{0}' does not implement inherited abstract member '{1}' from class '{2}'." }, All_declarations_of_an_abstract_method_must_be_consecutive: { code: 2516, category: ts.DiagnosticCategory.Error, key: "All declarations of an abstract method must be consecutive." }, - Constructor_objects_of_abstract_type_cannot_be_assigned_to_constructor_objects_of_non_abstract_type: { code: 2517, category: ts.DiagnosticCategory.Error, key: "Constructor objects of abstract type cannot be assigned to constructor objects of non-abstract type" }, + Cannot_assign_an_abstract_constructor_type_to_a_non_abstract_constructor_type: { code: 2517, category: ts.DiagnosticCategory.Error, key: "Cannot assign an abstract constructor type to a non-abstract constructor type." }, Only_an_ambient_class_can_be_merged_with_an_interface: { code: 2518, category: ts.DiagnosticCategory.Error, key: "Only an ambient class can be merged with an interface." }, Duplicate_identifier_0_Compiler_uses_declaration_1_to_support_async_functions: { code: 2520, category: ts.DiagnosticCategory.Error, key: "Duplicate identifier '{0}'. Compiler uses declaration '{1}' to support async functions." }, Expression_resolves_to_variable_declaration_0_that_compiler_uses_to_support_async_functions: { code: 2521, category: ts.DiagnosticCategory.Error, key: "Expression resolves to variable declaration '{0}' that compiler uses to support async functions." }, @@ -8904,7 +8911,8 @@ var ts; } else { node.exportClause = parseNamedImportsOrExports(226); - if (parseOptional(130)) { + if (token === 130 || (token === 8 && !scanner.hasPrecedingLineBreak())) { + parseExpected(130); node.moduleSpecifier = parseModuleSpecifier(); } } @@ -13686,7 +13694,7 @@ var ts; var id = getTypeListId(elementTypes); var type = tupleTypes[id]; if (!type) { - type = tupleTypes[id] = createObjectType(8192); + type = tupleTypes[id] = createObjectType(8192 | getWideningFlagsOfTypes(elementTypes)); type.elementTypes = elementTypes; } return type; @@ -14507,10 +14515,29 @@ var ts; var targetSignatures = getSignaturesOfType(target, kind); var result = -1; var saveErrorInfo = errorInfo; + var sourceSig = sourceSignatures[0]; + var targetSig = targetSignatures[0]; + if (sourceSig && targetSig) { + var sourceErasedSignature = getErasedSignature(sourceSig); + var targetErasedSignature = getErasedSignature(targetSig); + var sourceReturnType = sourceErasedSignature && getReturnTypeOfSignature(sourceErasedSignature); + var targetReturnType = targetErasedSignature && getReturnTypeOfSignature(targetErasedSignature); + var sourceReturnDecl = sourceReturnType && sourceReturnType.symbol && ts.getDeclarationOfKind(sourceReturnType.symbol, 211); + var targetReturnDecl = targetReturnType && targetReturnType.symbol && ts.getDeclarationOfKind(targetReturnType.symbol, 211); + var sourceIsAbstract = sourceReturnDecl && sourceReturnDecl.flags & 256; + var targetIsAbstract = targetReturnDecl && targetReturnDecl.flags & 256; + if (sourceIsAbstract && !targetIsAbstract) { + if (reportErrors) { + reportError(ts.Diagnostics.Cannot_assign_an_abstract_constructor_type_to_a_non_abstract_constructor_type); + } + return 0; + } + } outer: for (var _i = 0; _i < targetSignatures.length; _i++) { var t = targetSignatures[_i]; if (!t.hasStringLiterals || target.flags & 262144) { var localErrors = reportErrors; + var checkedAbstractAssignability = false; for (var _a = 0; _a < sourceSignatures.length; _a++) { var s = sourceSignatures[_a]; if (!s.hasStringLiterals || source.flags & 262144) { @@ -14558,12 +14585,12 @@ var ts; target = getErasedSignature(target); var result = -1; for (var i = 0; i < checkCount; i++) { - var s_1 = i < sourceMax ? getTypeOfSymbol(source.parameters[i]) : getRestTypeOfSignature(source); - var t_1 = i < targetMax ? getTypeOfSymbol(target.parameters[i]) : getRestTypeOfSignature(target); + var s = i < sourceMax ? getTypeOfSymbol(source.parameters[i]) : getRestTypeOfSignature(source); + var t = i < targetMax ? getTypeOfSymbol(target.parameters[i]) : getRestTypeOfSignature(target); var saveErrorInfo = errorInfo; - var related = isRelatedTo(s_1, t_1, reportErrors); + var related = isRelatedTo(s, t, reportErrors); if (!related) { - related = isRelatedTo(t_1, s_1, false); + related = isRelatedTo(t, s, false); if (!related) { if (reportErrors) { reportError(ts.Diagnostics.Types_of_parameters_0_and_1_are_incompatible, source.parameters[i < sourceMax ? i : sourceMax].name, target.parameters[i < targetMax ? i : targetMax].name); @@ -14601,11 +14628,11 @@ var ts; } return 0; } - var t = getReturnTypeOfSignature(target); - if (t === voidType) + var targetReturnType = getReturnTypeOfSignature(target); + if (targetReturnType === voidType) return result; - var s = getReturnTypeOfSignature(source); - return result & isRelatedTo(s, t, reportErrors); + var sourceReturnType = getReturnTypeOfSignature(source); + return result & isRelatedTo(sourceReturnType, targetReturnType, reportErrors); } function signaturesIdenticalTo(source, target, kind) { var sourceSignatures = getSignaturesOfType(source, kind); @@ -14818,7 +14845,7 @@ var ts; return !!getPropertyOfType(type, "0"); } function isTupleType(type) { - return (type.flags & 8192) && !!type.elementTypes; + return !!(type.flags & 8192); } function getWidenedTypeOfObjectLiteral(type) { var properties = getPropertiesOfObjectType(type); @@ -14860,25 +14887,36 @@ var ts; if (isArrayType(type)) { return createArrayType(getWidenedType(type.typeArguments[0])); } + if (isTupleType(type)) { + return createTupleType(ts.map(type.elementTypes, getWidenedType)); + } } return type; } function reportWideningErrorsInType(type) { + var errorReported = false; if (type.flags & 16384) { - var errorReported = false; - ts.forEach(type.types, function (t) { + for (var _i = 0, _a = type.types; _i < _a.length; _i++) { + var t = _a[_i]; if (reportWideningErrorsInType(t)) { errorReported = true; } - }); - return errorReported; + } } if (isArrayType(type)) { return reportWideningErrorsInType(type.typeArguments[0]); } + if (isTupleType(type)) { + for (var _b = 0, _c = type.elementTypes; _b < _c.length; _b++) { + var t = _c[_b]; + if (reportWideningErrorsInType(t)) { + errorReported = true; + } + } + } if (type.flags & 524288) { - var errorReported = false; - ts.forEach(getPropertiesOfObjectType(type), function (p) { + for (var _d = 0, _e = getPropertiesOfObjectType(type); _d < _e.length; _d++) { + var p = _e[_d]; var t = getTypeOfSymbol(p); if (t.flags & 1048576) { if (!reportWideningErrorsInType(t)) { @@ -14886,10 +14924,9 @@ var ts; } errorReported = true; } - }); - return errorReported; + } } - return false; + return errorReported; } function reportImplicitAnyError(declaration, type) { var typeAsString = typeToString(getWidenedType(type)); @@ -15037,28 +15074,31 @@ var ts; inferFromTypes(sourceType, target); } } - else if (source.flags & 80896 && (target.flags & (4096 | 8192) || - (target.flags & 65536) && target.symbol && target.symbol.flags & (8192 | 2048 | 32))) { - if (isInProcess(source, target)) { - return; + else { + source = getApparentType(source); + if (source.flags & 80896 && (target.flags & (4096 | 8192) || + (target.flags & 65536) && target.symbol && target.symbol.flags & (8192 | 2048 | 32))) { + if (isInProcess(source, target)) { + return; + } + if (isDeeplyNestedGeneric(source, sourceStack, depth) && isDeeplyNestedGeneric(target, targetStack, depth)) { + return; + } + if (depth === 0) { + sourceStack = []; + targetStack = []; + } + sourceStack[depth] = source; + targetStack[depth] = target; + depth++; + inferFromProperties(source, target); + inferFromSignatures(source, target, 0); + inferFromSignatures(source, target, 1); + inferFromIndexTypes(source, target, 0, 0); + inferFromIndexTypes(source, target, 1, 1); + inferFromIndexTypes(source, target, 0, 1); + depth--; } - if (isDeeplyNestedGeneric(source, sourceStack, depth) && isDeeplyNestedGeneric(target, targetStack, depth)) { - return; - } - if (depth === 0) { - sourceStack = []; - targetStack = []; - } - sourceStack[depth] = source; - targetStack[depth] = target; - depth++; - inferFromProperties(source, target); - inferFromSignatures(source, target, 0); - inferFromSignatures(source, target, 1); - inferFromIndexTypes(source, target, 0, 0); - inferFromIndexTypes(source, target, 1, 1); - inferFromIndexTypes(source, target, 0, 1); - depth--; } } function inferFromProperties(source, target) { @@ -31937,15 +31977,15 @@ var ts; var t; var pos = scanner.getStartPos(); while (pos < endPos) { - var t_2 = scanner.getToken(); - if (!ts.isTrivia(t_2)) { + var t_1 = scanner.getToken(); + if (!ts.isTrivia(t_1)) { break; } scanner.scan(); var item = { pos: pos, end: scanner.getStartPos(), - kind: t_2 + kind: t_1 }; pos = scanner.getStartPos(); if (!leadingTrivia) { @@ -33289,6 +33329,8 @@ var ts; case 15: case 18: case 19: + case 16: + case 17: case 77: case 101: case 53: @@ -33390,7 +33432,7 @@ var ts; } else if (tokenInfo.token.kind === listStartToken) { startLine = sourceFile.getLineAndCharacterOfPosition(tokenInfo.token.pos).line; - var indentation_1 = computeIndentation(tokenInfo.token, startLine, -1, parent, parentDynamicIndentation, startLine); + var indentation_1 = computeIndentation(tokenInfo.token, startLine, -1, parent, parentDynamicIndentation, parentStartLine); listDynamicIndentation = getDynamicIndentation(parent, parentStartLine, indentation_1.indentation, indentation_1.delta); consumeTokenAndAdvanceScanner(tokenInfo, parent, listDynamicIndentation); } @@ -35914,20 +35956,20 @@ var ts; } function tryGetGlobalSymbols() { var objectLikeContainer; - var importClause; + var namedImportsOrExports; var jsxContainer; if (objectLikeContainer = tryGetObjectLikeCompletionContainer(contextToken)) { return tryGetObjectLikeCompletionSymbols(objectLikeContainer); } - if (importClause = ts.getAncestor(contextToken, 220)) { - return tryGetImportClauseCompletionSymbols(importClause); + if (namedImportsOrExports = tryGetNamedImportsOrExportsForCompletion(contextToken)) { + return tryGetImportOrExportClauseCompletionSymbols(namedImportsOrExports); } if (jsxContainer = tryGetContainingJsxElement(contextToken)) { var attrsType; if ((jsxContainer.kind === 231) || (jsxContainer.kind === 232)) { attrsType = typeChecker.getJsxElementAttributesType(jsxContainer); if (attrsType) { - symbols = filterJsxAttributes(jsxContainer.attributes, typeChecker.getPropertiesOfType(attrsType)); + symbols = filterJsxAttributes(typeChecker.getPropertiesOfType(attrsType), jsxContainer.attributes); isMemberCompletion = true; isNewIdentifierLocation = false; return true; @@ -35957,19 +35999,11 @@ var ts; function isCompletionListBlocker(contextToken) { var start = new Date().getTime(); var result = isInStringOrRegularExpressionOrTemplateLiteral(contextToken) || - isIdentifierDefinitionLocation(contextToken) || + isSolelyIdentifierDefinitionLocation(contextToken) || isDotOfNumericLiteral(contextToken); log("getCompletionsAtPosition: isCompletionListBlocker: " + (new Date().getTime() - start)); return result; } - function shouldShowCompletionsInImportsClause(node) { - if (node) { - if (node.kind === 14 || node.kind === 23) { - return node.parent.kind === 222; - } - } - return false; - } function isNewIdentifierDefinitionLocation(previousToken) { if (previousToken) { var containingNodeKind = previousToken.parent.kind; @@ -36061,23 +36095,23 @@ var ts; } return true; } - function tryGetImportClauseCompletionSymbols(importClause) { - if (shouldShowCompletionsInImportsClause(contextToken)) { - isMemberCompletion = true; - isNewIdentifierLocation = false; - var importDeclaration = importClause.parent; - ts.Debug.assert(importDeclaration !== undefined && importDeclaration.kind === 219); - var exports_2; - var moduleSpecifierSymbol = typeChecker.getSymbolAtLocation(importDeclaration.moduleSpecifier); - if (moduleSpecifierSymbol) { - exports_2 = typeChecker.getExportsOfModule(moduleSpecifierSymbol); - } - symbols = exports_2 ? filterModuleExports(exports_2, importDeclaration) : emptyArray; + function tryGetImportOrExportClauseCompletionSymbols(namedImportsOrExports) { + var declarationKind = namedImportsOrExports.kind === 222 ? + 219 : + 225; + var importOrExportDeclaration = ts.getAncestor(namedImportsOrExports, declarationKind); + var moduleSpecifier = importOrExportDeclaration.moduleSpecifier; + if (!moduleSpecifier) { + return false; } - else { - isMemberCompletion = false; - isNewIdentifierLocation = true; + isMemberCompletion = true; + isNewIdentifierLocation = false; + var exports; + var moduleSpecifierSymbol = typeChecker.getSymbolAtLocation(importOrExportDeclaration.moduleSpecifier); + if (moduleSpecifierSymbol) { + exports = typeChecker.getExportsOfModule(moduleSpecifierSymbol); } + symbols = exports ? filterNamedImportOrExportCompletionItems(exports, namedImportsOrExports.elements) : emptyArray; return true; } function tryGetObjectLikeCompletionContainer(contextToken) { @@ -36094,6 +36128,20 @@ var ts; } return undefined; } + function tryGetNamedImportsOrExportsForCompletion(contextToken) { + if (contextToken) { + switch (contextToken.kind) { + case 14: + case 23: + switch (contextToken.parent.kind) { + case 222: + case 226: + return contextToken.parent; + } + } + } + return undefined; + } function tryGetContainingJsxElement(contextToken) { if (contextToken) { var parent_12 = contextToken.parent; @@ -36133,7 +36181,7 @@ var ts; } return false; } - function isIdentifierDefinitionLocation(contextToken) { + function isSolelyIdentifierDefinitionLocation(contextToken) { var containingNodeKind = contextToken.parent.kind; switch (contextToken.kind) { case 23: @@ -36179,6 +36227,10 @@ var ts; case 107: case 108: return containingNodeKind === 135; + case 113: + containingNodeKind === 223 || + containingNodeKind === 227 || + containingNodeKind === 221; case 70: case 78: case 104: @@ -36214,25 +36266,20 @@ var ts; } return false; } - function filterModuleExports(exports, importDeclaration) { - var exisingImports = {}; - if (!importDeclaration.importClause) { - return exports; + function filterNamedImportOrExportCompletionItems(exportsOfModule, namedImportsOrExports) { + var exisingImportsOrExports = {}; + for (var _i = 0; _i < namedImportsOrExports.length; _i++) { + var element = namedImportsOrExports[_i]; + if (element.getStart() <= position && position <= element.getEnd()) { + continue; + } + var name_31 = element.propertyName || element.name; + exisingImportsOrExports[name_31.text] = true; } - if (importDeclaration.importClause.namedBindings && - importDeclaration.importClause.namedBindings.kind === 222) { - ts.forEach(importDeclaration.importClause.namedBindings.elements, function (el) { - if (el.getStart() <= position && position <= el.getEnd()) { - return; - } - var name = el.propertyName || el.name; - exisingImports[name.text] = true; - }); + if (ts.isEmpty(exisingImportsOrExports)) { + return exportsOfModule; } - if (ts.isEmpty(exisingImports)) { - return exports; - } - return ts.filter(exports, function (e) { return !ts.lookUp(exisingImports, e.name); }); + return ts.filter(exportsOfModule, function (e) { return !ts.lookUp(exisingImportsOrExports, e.name); }); } function filterObjectMembersList(contextualMemberSymbols, existingMembers) { if (!existingMembers || existingMembers.length === 0) { @@ -36258,15 +36305,9 @@ var ts; } existingMemberNames[existingName] = true; } - var filteredMembers = []; - ts.forEach(contextualMemberSymbols, function (s) { - if (!existingMemberNames[s.name]) { - filteredMembers.push(s); - } - }); - return filteredMembers; + return ts.filter(contextualMemberSymbols, function (m) { return !ts.lookUp(existingMemberNames, m.name); }); } - function filterJsxAttributes(attributes, symbols) { + function filterJsxAttributes(symbols, attributes) { var seenNames = {}; for (var _i = 0; _i < attributes.length; _i++) { var attr = attributes[_i]; @@ -36277,14 +36318,7 @@ var ts; seenNames[attr.name.text] = true; } } - var result = []; - for (var _a = 0; _a < symbols.length; _a++) { - var sym = symbols[_a]; - if (!seenNames[sym.name]) { - result.push(sym); - } - } - return result; + return ts.filter(symbols, function (a) { return !ts.lookUp(seenNames, a.name); }); } } function getCompletionsAtPosition(fileName, position) { @@ -36316,10 +36350,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_31 in nameTable) { - if (!allNames[name_31]) { - allNames[name_31] = name_31; - var displayName = getCompletionEntryDisplayName(name_31, target, true); + for (var name_32 in nameTable) { + if (!allNames[name_32]) { + allNames[name_32] = name_32; + var displayName = getCompletionEntryDisplayName(name_32, target, true); if (displayName) { var entry = { name: displayName, @@ -37123,6 +37157,7 @@ var ts; if (hasKind(node.parent, 142) || hasKind(node.parent, 143)) { return getGetAndSetOccurrences(node.parent); } + break; default: if (ts.isModifier(node.kind) && node.parent && (ts.isDeclaration(node.parent) || node.parent.kind === 190)) { @@ -37222,12 +37257,13 @@ var ts; var container = declaration.parent; if (ts.isAccessibilityModifier(modifier)) { if (!(container.kind === 211 || + container.kind === 183 || (declaration.kind === 135 && hasKind(container, 141)))) { return undefined; } } else if (modifier === 110) { - if (container.kind !== 211) { + if (!(container.kind === 211 || container.kind === 183)) { return undefined; } } @@ -37236,6 +37272,11 @@ var ts; return undefined; } } + else if (modifier === 112) { + if (!(container.kind === 211 || declaration.kind === 211)) { + return undefined; + } + } else { return undefined; } @@ -37245,12 +37286,18 @@ var ts; switch (container.kind) { case 216: case 245: - nodes = container.statements; + if (modifierFlag & 256) { + nodes = declaration.members.concat(declaration); + } + else { + nodes = container.statements; + } break; case 141: nodes = container.parameters.concat(container.parent.members); break; case 211: + case 183: nodes = container.members; if (modifierFlag & 112) { var constructor = ts.forEach(container.members, function (member) { @@ -37260,6 +37307,9 @@ var ts; nodes = nodes.concat(constructor.parameters); } } + else if (modifierFlag & 256) { + nodes = nodes.concat(container); + } break; default: ts.Debug.fail("Invalid container kind."); @@ -37284,6 +37334,8 @@ var ts; return 1; case 119: return 2; + case 112: + return 256; default: ts.Debug.fail(); } @@ -37981,17 +38033,17 @@ var ts; if (isNameOfPropertyAssignment(node)) { var objectLiteral = node.parent.parent; var contextualType = typeChecker.getContextualType(objectLiteral); - var name_32 = node.text; + var name_33 = node.text; if (contextualType) { if (contextualType.flags & 16384) { - var unionProperty = contextualType.getProperty(name_32); + var unionProperty = contextualType.getProperty(name_33); if (unionProperty) { return [unionProperty]; } else { var result_4 = []; ts.forEach(contextualType.types, function (t) { - var symbol = t.getProperty(name_32); + var symbol = t.getProperty(name_33); if (symbol) { result_4.push(symbol); } @@ -38000,7 +38052,7 @@ var ts; } } else { - var symbol_1 = contextualType.getProperty(name_32); + var symbol_1 = contextualType.getProperty(name_33); if (symbol_1) { return [symbol_1]; } @@ -38599,7 +38651,7 @@ var ts; return; } } - return 9; + return 2; } } function processElement(element) { @@ -39343,10 +39395,113 @@ var ts; this.fileHash = {}; this.nextFileId = 1; this.changeSeq = 0; + this.handlers = (_a = {}, + _a[CommandNames.Exit] = function () { + _this.exit(); + return {}; + }, + _a[CommandNames.Definition] = function (request) { + var defArgs = request.arguments; + return { response: _this.getDefinition(defArgs.line, defArgs.offset, defArgs.file) }; + }, + _a[CommandNames.TypeDefinition] = function (request) { + var defArgs = request.arguments; + return { response: _this.getTypeDefinition(defArgs.line, defArgs.offset, defArgs.file) }; + }, + _a[CommandNames.References] = function (request) { + var defArgs = request.arguments; + return { response: _this.getReferences(defArgs.line, defArgs.offset, defArgs.file) }; + }, + _a[CommandNames.Rename] = function (request) { + var renameArgs = request.arguments; + return { response: _this.getRenameLocations(renameArgs.line, renameArgs.offset, renameArgs.file, renameArgs.findInComments, renameArgs.findInStrings) }; + }, + _a[CommandNames.Open] = function (request) { + var openArgs = request.arguments; + _this.openClientFile(openArgs.file); + return {}; + }, + _a[CommandNames.Quickinfo] = function (request) { + var quickinfoArgs = request.arguments; + return { response: _this.getQuickInfo(quickinfoArgs.line, quickinfoArgs.offset, quickinfoArgs.file) }; + }, + _a[CommandNames.Format] = function (request) { + var formatArgs = request.arguments; + return { response: _this.getFormattingEditsForRange(formatArgs.line, formatArgs.offset, formatArgs.endLine, formatArgs.endOffset, formatArgs.file) }; + }, + _a[CommandNames.Formatonkey] = function (request) { + var formatOnKeyArgs = request.arguments; + return { response: _this.getFormattingEditsAfterKeystroke(formatOnKeyArgs.line, formatOnKeyArgs.offset, formatOnKeyArgs.key, formatOnKeyArgs.file) }; + }, + _a[CommandNames.Completions] = function (request) { + var completionsArgs = request.arguments; + return { response: _this.getCompletions(completionsArgs.line, completionsArgs.offset, completionsArgs.prefix, completionsArgs.file) }; + }, + _a[CommandNames.CompletionDetails] = function (request) { + var completionDetailsArgs = request.arguments; + return { response: _this.getCompletionEntryDetails(completionDetailsArgs.line, completionDetailsArgs.offset, completionDetailsArgs.entryNames, completionDetailsArgs.file) }; + }, + _a[CommandNames.SignatureHelp] = function (request) { + var signatureHelpArgs = request.arguments; + return { response: _this.getSignatureHelpItems(signatureHelpArgs.line, signatureHelpArgs.offset, signatureHelpArgs.file) }; + }, + _a[CommandNames.Geterr] = function (request) { + var geterrArgs = request.arguments; + return { response: _this.getDiagnostics(geterrArgs.delay, geterrArgs.files), responseRequired: false }; + }, + _a[CommandNames.Change] = function (request) { + var changeArgs = request.arguments; + _this.change(changeArgs.line, changeArgs.offset, changeArgs.endLine, changeArgs.endOffset, changeArgs.insertString, changeArgs.file); + return { responseRequired: false }; + }, + _a[CommandNames.Configure] = function (request) { + var configureArgs = request.arguments; + _this.projectService.setHostConfiguration(configureArgs); + _this.output(undefined, CommandNames.Configure, request.seq); + return { responseRequired: false }; + }, + _a[CommandNames.Reload] = function (request) { + var reloadArgs = request.arguments; + _this.reload(reloadArgs.file, reloadArgs.tmpfile, request.seq); + return { responseRequired: false }; + }, + _a[CommandNames.Saveto] = function (request) { + var savetoArgs = request.arguments; + _this.saveToTmp(savetoArgs.file, savetoArgs.tmpfile); + return { responseRequired: false }; + }, + _a[CommandNames.Close] = function (request) { + var closeArgs = request.arguments; + _this.closeClientFile(closeArgs.file); + return { responseRequired: false }; + }, + _a[CommandNames.Navto] = function (request) { + var navtoArgs = request.arguments; + return { response: _this.getNavigateToItems(navtoArgs.searchValue, navtoArgs.file, navtoArgs.maxResultCount) }; + }, + _a[CommandNames.Brace] = function (request) { + var braceArguments = request.arguments; + return { response: _this.getBraceMatching(braceArguments.line, braceArguments.offset, braceArguments.file) }; + }, + _a[CommandNames.NavBar] = function (request) { + var navBarArgs = request.arguments; + return { response: _this.getNavigationBarItems(navBarArgs.file) }; + }, + _a[CommandNames.Occurrences] = function (request) { + var _a = request.arguments, line = _a.line, offset = _a.offset, fileName = _a.file; + return { response: _this.getOccurrences(line, offset, fileName) }; + }, + _a[CommandNames.ProjectInfo] = function (request) { + var _a = request.arguments, file = _a.file, needFileNameList = _a.needFileNameList; + return { response: _this.getProjectInfo(file, needFileNameList) }; + }, + _a + ); this.projectService = new server.ProjectService(host, logger, function (eventName, project, fileName) { _this.handleEvent(eventName, project, fileName); }); + var _a; } Session.prototype.handleEvent = function (eventName, project, fileName) { var _this = this; @@ -39963,6 +40118,23 @@ var ts; }; Session.prototype.exit = function () { }; + Session.prototype.addProtocolHandler = function (command, handler) { + if (this.handlers[command]) { + throw new Error("Protocol handler already exists for command \"" + command + "\""); + } + this.handlers[command] = handler; + }; + Session.prototype.executeCommand = function (request) { + var handler = this.handlers[request.command]; + if (handler) { + return handler(request); + } + else { + this.projectService.log("Unrecognized JSON command: " + JSON.stringify(request)); + this.output(undefined, CommandNames.Unknown, request.seq, "Unrecognized JSON command: " + request.command); + return { responseRequired: false }; + } + }; Session.prototype.onMessage = function (message) { if (this.logger.isVerbose()) { this.logger.info("request: " + message); @@ -39970,140 +40142,7 @@ var ts; } try { var request = JSON.parse(message); - var response; - var errorMessage; - var responseRequired = true; - switch (request.command) { - case CommandNames.Exit: { - this.exit(); - responseRequired = false; - break; - } - case CommandNames.Definition: { - var defArgs = request.arguments; - response = this.getDefinition(defArgs.line, defArgs.offset, defArgs.file); - break; - } - case CommandNames.TypeDefinition: { - var defArgs = request.arguments; - response = this.getTypeDefinition(defArgs.line, defArgs.offset, defArgs.file); - break; - } - case CommandNames.References: { - var refArgs = request.arguments; - response = this.getReferences(refArgs.line, refArgs.offset, refArgs.file); - break; - } - case CommandNames.Rename: { - var renameArgs = request.arguments; - response = this.getRenameLocations(renameArgs.line, renameArgs.offset, renameArgs.file, renameArgs.findInComments, renameArgs.findInStrings); - break; - } - case CommandNames.Open: { - var openArgs = request.arguments; - this.openClientFile(openArgs.file); - responseRequired = false; - break; - } - case CommandNames.Quickinfo: { - var quickinfoArgs = request.arguments; - response = this.getQuickInfo(quickinfoArgs.line, quickinfoArgs.offset, quickinfoArgs.file); - break; - } - case CommandNames.Format: { - var formatArgs = request.arguments; - response = this.getFormattingEditsForRange(formatArgs.line, formatArgs.offset, formatArgs.endLine, formatArgs.endOffset, formatArgs.file); - break; - } - case CommandNames.Formatonkey: { - var formatOnKeyArgs = request.arguments; - response = this.getFormattingEditsAfterKeystroke(formatOnKeyArgs.line, formatOnKeyArgs.offset, formatOnKeyArgs.key, formatOnKeyArgs.file); - break; - } - case CommandNames.Completions: { - var completionsArgs = request.arguments; - response = this.getCompletions(completionsArgs.line, completionsArgs.offset, completionsArgs.prefix, completionsArgs.file); - break; - } - case CommandNames.CompletionDetails: { - var completionDetailsArgs = request.arguments; - response = - this.getCompletionEntryDetails(completionDetailsArgs.line, completionDetailsArgs.offset, completionDetailsArgs.entryNames, completionDetailsArgs.file); - break; - } - case CommandNames.SignatureHelp: { - var signatureHelpArgs = request.arguments; - response = this.getSignatureHelpItems(signatureHelpArgs.line, signatureHelpArgs.offset, signatureHelpArgs.file); - break; - } - case CommandNames.Geterr: { - var geterrArgs = request.arguments; - response = this.getDiagnostics(geterrArgs.delay, geterrArgs.files); - responseRequired = false; - break; - } - case CommandNames.Change: { - var changeArgs = request.arguments; - this.change(changeArgs.line, changeArgs.offset, changeArgs.endLine, changeArgs.endOffset, changeArgs.insertString, changeArgs.file); - responseRequired = false; - break; - } - case CommandNames.Configure: { - var configureArgs = request.arguments; - this.projectService.setHostConfiguration(configureArgs); - this.output(undefined, CommandNames.Configure, request.seq); - responseRequired = false; - break; - } - case CommandNames.Reload: { - var reloadArgs = request.arguments; - this.reload(reloadArgs.file, reloadArgs.tmpfile, request.seq); - responseRequired = false; - break; - } - case CommandNames.Saveto: { - var savetoArgs = request.arguments; - this.saveToTmp(savetoArgs.file, savetoArgs.tmpfile); - responseRequired = false; - break; - } - case CommandNames.Close: { - var closeArgs = request.arguments; - this.closeClientFile(closeArgs.file); - responseRequired = false; - break; - } - case CommandNames.Navto: { - var navtoArgs = request.arguments; - response = this.getNavigateToItems(navtoArgs.searchValue, navtoArgs.file, navtoArgs.maxResultCount); - break; - } - case CommandNames.Brace: { - var braceArguments = request.arguments; - response = this.getBraceMatching(braceArguments.line, braceArguments.offset, braceArguments.file); - break; - } - case CommandNames.NavBar: { - var navBarArgs = request.arguments; - response = this.getNavigationBarItems(navBarArgs.file); - break; - } - case CommandNames.Occurrences: { - var _a = request.arguments, line = _a.line, offset = _a.offset, fileName = _a.file; - response = this.getOccurrences(line, offset, fileName); - break; - } - case CommandNames.ProjectInfo: { - var _b = request.arguments, file = _b.file, needFileNameList = _b.needFileNameList; - response = this.getProjectInfo(file, needFileNameList); - break; - } - default: { - this.projectService.log("Unrecognized JSON command: " + message); - this.output(undefined, CommandNames.Unknown, request.seq, "Unrecognized JSON command: " + request.command); - break; - } - } + var _a = this.executeCommand(request), response = _a.response, responseRequired = _a.responseRequired; if (this.logger.isVerbose()) { var elapsed = this.hrtime(start); var seconds = elapsed[0]; @@ -42033,6 +42072,11 @@ var ts; var decoded = JSON.parse(encoded); return ts.createTextChangeRange(ts.createTextSpan(decoded.span.start, decoded.span.length), decoded.newLength); }; + ScriptSnapshotShimAdapter.prototype.dispose = function () { + if ("dispose" in this.scriptSnapshotShim) { + this.scriptSnapshotShim.dispose(); + } + }; return ScriptSnapshotShimAdapter; })(); var LanguageServiceShimHostAdapter = (function () { diff --git a/bin/typescript.js b/bin/typescript.js index e3573e840e8..6035d71fa2b 100644 --- a/bin/typescript.js +++ b/bin/typescript.js @@ -1775,8 +1775,15 @@ var ts; newLine: _os.EOL, useCaseSensitiveFileNames: useCaseSensitiveFileNames, write: function (s) { + var buffer = new Buffer(s, 'utf8'); + var offset = 0; + var toWrite = buffer.length; + var written = 0; // 1 is a standard descriptor for stdout - _fs.writeSync(1, s); + while ((written = _fs.writeSync(1, buffer, offset, toWrite)) < toWrite) { + offset += written; + toWrite -= written; + } }, readFile: readFile, writeFile: writeFile, @@ -2247,7 +2254,7 @@ var ts; Classes_containing_abstract_methods_must_be_marked_abstract: { code: 2514, category: ts.DiagnosticCategory.Error, key: "Classes containing abstract methods must be marked abstract." }, Non_abstract_class_0_does_not_implement_inherited_abstract_member_1_from_class_2: { code: 2515, category: ts.DiagnosticCategory.Error, key: "Non-abstract class '{0}' does not implement inherited abstract member '{1}' from class '{2}'." }, All_declarations_of_an_abstract_method_must_be_consecutive: { code: 2516, category: ts.DiagnosticCategory.Error, key: "All declarations of an abstract method must be consecutive." }, - Constructor_objects_of_abstract_type_cannot_be_assigned_to_constructor_objects_of_non_abstract_type: { code: 2517, category: ts.DiagnosticCategory.Error, key: "Constructor objects of abstract type cannot be assigned to constructor objects of non-abstract type" }, + Cannot_assign_an_abstract_constructor_type_to_a_non_abstract_constructor_type: { code: 2517, category: ts.DiagnosticCategory.Error, key: "Cannot assign an abstract constructor type to a non-abstract constructor type." }, Only_an_ambient_class_can_be_merged_with_an_interface: { code: 2518, category: ts.DiagnosticCategory.Error, key: "Only an ambient class can be merged with an interface." }, Duplicate_identifier_0_Compiler_uses_declaration_1_to_support_async_functions: { code: 2520, category: ts.DiagnosticCategory.Error, key: "Duplicate identifier '{0}'. Compiler uses declaration '{1}' to support async functions." }, Expression_resolves_to_variable_declaration_0_that_compiler_uses_to_support_async_functions: { code: 2521, category: ts.DiagnosticCategory.Error, key: "Expression resolves to variable declaration '{0}' that compiler uses to support async functions." }, @@ -11517,7 +11524,11 @@ var ts; } else { node.exportClause = parseNamedImportsOrExports(226 /* NamedExports */); - if (parseOptional(130 /* FromKeyword */)) { + // It is not uncommon to accidentally omit the 'from' keyword. Additionally, in editing scenarios, + // the 'from' keyword can be parsed as a named export when the export clause is unterminated (i.e. `export { from "moduleName";`) + // If we don't have a 'from' keyword, see if we have a string literal such that ASI won't take effect. + if (token === 130 /* FromKeyword */ || (token === 8 /* StringLiteral */ && !scanner.hasPrecedingLineBreak())) { + parseExpected(130 /* FromKeyword */); node.moduleSpecifier = parseModuleSpecifier(); } } @@ -16299,7 +16310,7 @@ var ts; var id = getTypeListId(elementTypes); var type = tupleTypes[id]; if (!type) { - type = tupleTypes[id] = createObjectType(8192 /* Tuple */); + type = tupleTypes[id] = createObjectType(8192 /* Tuple */ | getWideningFlagsOfTypes(elementTypes)); type.elementTypes = elementTypes; } return type; @@ -17200,10 +17211,33 @@ var ts; var targetSignatures = getSignaturesOfType(target, kind); var result = -1 /* True */; var saveErrorInfo = errorInfo; + // Because the "abstractness" of a class is the same across all construct signatures + // (internally we are checking the corresponding declaration), it is enough to perform + // the check and report an error once over all pairs of source and target construct signatures. + var sourceSig = sourceSignatures[0]; + // Note that in an extends-clause, targetSignatures is stripped, so the check never proceeds. + var targetSig = targetSignatures[0]; + if (sourceSig && targetSig) { + var sourceErasedSignature = getErasedSignature(sourceSig); + var targetErasedSignature = getErasedSignature(targetSig); + var sourceReturnType = sourceErasedSignature && getReturnTypeOfSignature(sourceErasedSignature); + var targetReturnType = targetErasedSignature && getReturnTypeOfSignature(targetErasedSignature); + var sourceReturnDecl = sourceReturnType && sourceReturnType.symbol && ts.getDeclarationOfKind(sourceReturnType.symbol, 211 /* ClassDeclaration */); + var targetReturnDecl = targetReturnType && targetReturnType.symbol && ts.getDeclarationOfKind(targetReturnType.symbol, 211 /* ClassDeclaration */); + var sourceIsAbstract = sourceReturnDecl && sourceReturnDecl.flags & 256 /* Abstract */; + var targetIsAbstract = targetReturnDecl && targetReturnDecl.flags & 256 /* Abstract */; + if (sourceIsAbstract && !targetIsAbstract) { + if (reportErrors) { + reportError(ts.Diagnostics.Cannot_assign_an_abstract_constructor_type_to_a_non_abstract_constructor_type); + } + return 0 /* False */; + } + } outer: for (var _i = 0; _i < targetSignatures.length; _i++) { var t = targetSignatures[_i]; if (!t.hasStringLiterals || target.flags & 262144 /* FromSignature */) { var localErrors = reportErrors; + var checkedAbstractAssignability = false; for (var _a = 0; _a < sourceSignatures.length; _a++) { var s = sourceSignatures[_a]; if (!s.hasStringLiterals || source.flags & 262144 /* FromSignature */) { @@ -17254,12 +17288,12 @@ var ts; target = getErasedSignature(target); var result = -1 /* True */; for (var i = 0; i < checkCount; i++) { - var s_1 = i < sourceMax ? getTypeOfSymbol(source.parameters[i]) : getRestTypeOfSignature(source); - var t_1 = i < targetMax ? getTypeOfSymbol(target.parameters[i]) : getRestTypeOfSignature(target); + var s = i < sourceMax ? getTypeOfSymbol(source.parameters[i]) : getRestTypeOfSignature(source); + var t = i < targetMax ? getTypeOfSymbol(target.parameters[i]) : getRestTypeOfSignature(target); var saveErrorInfo = errorInfo; - var related = isRelatedTo(s_1, t_1, reportErrors); + var related = isRelatedTo(s, t, reportErrors); if (!related) { - related = isRelatedTo(t_1, s_1, false); + related = isRelatedTo(t, s, false); if (!related) { if (reportErrors) { reportError(ts.Diagnostics.Types_of_parameters_0_and_1_are_incompatible, source.parameters[i < sourceMax ? i : sourceMax].name, target.parameters[i < targetMax ? i : targetMax].name); @@ -17297,11 +17331,11 @@ var ts; } return 0 /* False */; } - var t = getReturnTypeOfSignature(target); - if (t === voidType) + var targetReturnType = getReturnTypeOfSignature(target); + if (targetReturnType === voidType) return result; - var s = getReturnTypeOfSignature(source); - return result & isRelatedTo(s, t, reportErrors); + var sourceReturnType = getReturnTypeOfSignature(source); + return result & isRelatedTo(sourceReturnType, targetReturnType, reportErrors); } function signaturesIdenticalTo(source, target, kind) { var sourceSignatures = getSignaturesOfType(source, kind); @@ -17537,7 +17571,7 @@ var ts; * Prefer using isTupleLikeType() unless the use of `elementTypes` is required. */ function isTupleType(type) { - return (type.flags & 8192 /* Tuple */) && !!type.elementTypes; + return !!(type.flags & 8192 /* Tuple */); } function getWidenedTypeOfObjectLiteral(type) { var properties = getPropertiesOfObjectType(type); @@ -17579,25 +17613,47 @@ var ts; if (isArrayType(type)) { return createArrayType(getWidenedType(type.typeArguments[0])); } + if (isTupleType(type)) { + return createTupleType(ts.map(type.elementTypes, getWidenedType)); + } } return type; } + /** + * Reports implicit any errors that occur as a result of widening 'null' and 'undefined' + * to 'any'. A call to reportWideningErrorsInType is normally accompanied by a call to + * getWidenedType. But in some cases getWidenedType is called without reporting errors + * (type argument inference is an example). + * + * The return value indicates whether an error was in fact reported. The particular circumstances + * are on a best effort basis. Currently, if the null or undefined that causes widening is inside + * an object literal property (arbitrarily deeply), this function reports an error. If no error is + * reported, reportImplicitAnyError is a suitable fallback to report a general error. + */ function reportWideningErrorsInType(type) { + var errorReported = false; if (type.flags & 16384 /* Union */) { - var errorReported = false; - ts.forEach(type.types, function (t) { + for (var _i = 0, _a = type.types; _i < _a.length; _i++) { + var t = _a[_i]; if (reportWideningErrorsInType(t)) { errorReported = true; } - }); - return errorReported; + } } if (isArrayType(type)) { return reportWideningErrorsInType(type.typeArguments[0]); } + if (isTupleType(type)) { + for (var _b = 0, _c = type.elementTypes; _b < _c.length; _b++) { + var t = _c[_b]; + if (reportWideningErrorsInType(t)) { + errorReported = true; + } + } + } if (type.flags & 524288 /* ObjectLiteral */) { - var errorReported = false; - ts.forEach(getPropertiesOfObjectType(type), function (p) { + for (var _d = 0, _e = getPropertiesOfObjectType(type); _d < _e.length; _d++) { + var p = _e[_d]; var t = getTypeOfSymbol(p); if (t.flags & 1048576 /* ContainsUndefinedOrNull */) { if (!reportWideningErrorsInType(t)) { @@ -17605,10 +17661,9 @@ var ts; } errorReported = true; } - }); - return errorReported; + } } - return false; + return errorReported; } function reportImplicitAnyError(declaration, type) { var typeAsString = typeToString(getWidenedType(type)); @@ -17771,29 +17826,32 @@ var ts; inferFromTypes(sourceType, target); } } - else if (source.flags & 80896 /* ObjectType */ && (target.flags & (4096 /* Reference */ | 8192 /* Tuple */) || - (target.flags & 65536 /* Anonymous */) && target.symbol && target.symbol.flags & (8192 /* Method */ | 2048 /* TypeLiteral */ | 32 /* Class */))) { - // If source is an object type, and target is a type reference, a tuple type, the type of a method, or a type literal, infer from members - if (isInProcess(source, target)) { - return; + else { + source = getApparentType(source); + if (source.flags & 80896 /* ObjectType */ && (target.flags & (4096 /* Reference */ | 8192 /* Tuple */) || + (target.flags & 65536 /* Anonymous */) && target.symbol && target.symbol.flags & (8192 /* Method */ | 2048 /* TypeLiteral */ | 32 /* Class */))) { + // If source is an object type, and target is a type reference, a tuple type, the type of a method, or a type literal, infer from members + if (isInProcess(source, target)) { + return; + } + if (isDeeplyNestedGeneric(source, sourceStack, depth) && isDeeplyNestedGeneric(target, targetStack, depth)) { + return; + } + if (depth === 0) { + sourceStack = []; + targetStack = []; + } + sourceStack[depth] = source; + targetStack[depth] = target; + depth++; + inferFromProperties(source, target); + inferFromSignatures(source, target, 0 /* Call */); + inferFromSignatures(source, target, 1 /* Construct */); + inferFromIndexTypes(source, target, 0 /* String */, 0 /* String */); + inferFromIndexTypes(source, target, 1 /* Number */, 1 /* Number */); + inferFromIndexTypes(source, target, 0 /* String */, 1 /* Number */); + depth--; } - if (isDeeplyNestedGeneric(source, sourceStack, depth) && isDeeplyNestedGeneric(target, targetStack, depth)) { - return; - } - if (depth === 0) { - sourceStack = []; - targetStack = []; - } - sourceStack[depth] = source; - targetStack[depth] = target; - depth++; - inferFromProperties(source, target); - inferFromSignatures(source, target, 0 /* Call */); - inferFromSignatures(source, target, 1 /* Construct */); - inferFromIndexTypes(source, target, 0 /* String */, 0 /* String */); - inferFromIndexTypes(source, target, 1 /* Number */, 1 /* Number */); - inferFromIndexTypes(source, target, 0 /* String */, 1 /* Number */); - depth--; } } function inferFromProperties(source, target) { @@ -37768,8 +37826,8 @@ var ts; var pos = scanner.getStartPos(); // Read leading trivia and token while (pos < endPos) { - var t_2 = scanner.getToken(); - if (!ts.isTrivia(t_2)) { + var t_1 = scanner.getToken(); + if (!ts.isTrivia(t_1)) { break; } // consume leading trivia @@ -37777,7 +37835,7 @@ var ts; var item = { pos: pos, end: scanner.getStartPos(), - kind: t_2 + kind: t_1 }; pos = scanner.getStartPos(); if (!leadingTrivia) { @@ -39359,6 +39417,8 @@ var ts; case 15 /* CloseBraceToken */: case 18 /* OpenBracketToken */: case 19 /* CloseBracketToken */: + case 16 /* OpenParenToken */: + case 17 /* CloseParenToken */: case 77 /* ElseKeyword */: case 101 /* WhileKeyword */: case 53 /* AtToken */: @@ -39483,7 +39543,7 @@ var ts; else if (tokenInfo.token.kind === listStartToken) { // consume list start token startLine = sourceFile.getLineAndCharacterOfPosition(tokenInfo.token.pos).line; - var indentation_1 = computeIndentation(tokenInfo.token, startLine, -1 /* Unknown */, parent, parentDynamicIndentation, startLine); + var indentation_1 = computeIndentation(tokenInfo.token, startLine, -1 /* Unknown */, parent, parentDynamicIndentation, parentStartLine); listDynamicIndentation = getDynamicIndentation(parent, parentStartLine, indentation_1.indentation, indentation_1.delta); consumeTokenAndAdvanceScanner(tokenInfo, parent, listDynamicIndentation); } @@ -42417,15 +42477,15 @@ var ts; } function tryGetGlobalSymbols() { var objectLikeContainer; - var importClause; + var namedImportsOrExports; var jsxContainer; if (objectLikeContainer = tryGetObjectLikeCompletionContainer(contextToken)) { return tryGetObjectLikeCompletionSymbols(objectLikeContainer); } - if (importClause = ts.getAncestor(contextToken, 220 /* ImportClause */)) { + if (namedImportsOrExports = tryGetNamedImportsOrExportsForCompletion(contextToken)) { // cursor is in an import clause // try to show exported member for imported module - return tryGetImportClauseCompletionSymbols(importClause); + return tryGetImportOrExportClauseCompletionSymbols(namedImportsOrExports); } if (jsxContainer = tryGetContainingJsxElement(contextToken)) { var attrsType; @@ -42433,7 +42493,7 @@ var ts; // Cursor is inside a JSX self-closing element or opening element attrsType = typeChecker.getJsxElementAttributesType(jsxContainer); if (attrsType) { - symbols = filterJsxAttributes(jsxContainer.attributes, typeChecker.getPropertiesOfType(attrsType)); + symbols = filterJsxAttributes(typeChecker.getPropertiesOfType(attrsType), jsxContainer.attributes); isMemberCompletion = true; isNewIdentifierLocation = false; return true; @@ -42494,21 +42554,11 @@ var ts; function isCompletionListBlocker(contextToken) { var start = new Date().getTime(); var result = isInStringOrRegularExpressionOrTemplateLiteral(contextToken) || - isIdentifierDefinitionLocation(contextToken) || + isSolelyIdentifierDefinitionLocation(contextToken) || isDotOfNumericLiteral(contextToken); log("getCompletionsAtPosition: isCompletionListBlocker: " + (new Date().getTime() - start)); return result; } - function shouldShowCompletionsInImportsClause(node) { - if (node) { - // import {| - // import {a,| - if (node.kind === 14 /* OpenBraceToken */ || node.kind === 23 /* CommaToken */) { - return node.parent.kind === 222 /* NamedImports */; - } - } - return false; - } function isNewIdentifierDefinitionLocation(previousToken) { if (previousToken) { var containingNodeKind = previousToken.parent.kind; @@ -42617,34 +42667,37 @@ var ts; return true; } /** - * Aggregates relevant symbols for completion in import clauses; for instance, + * Aggregates relevant symbols for completion in import clauses and export clauses + * whose declarations have a module specifier; for instance, symbols will be aggregated for * - * import { $ } from "moduleName"; + * import { | } from "moduleName"; + * export { a as foo, | } from "moduleName"; + * + * but not for + * + * export { | }; * * Relevant symbols are stored in the captured 'symbols' variable. * * @returns true if 'symbols' was successfully populated; false otherwise. */ - function tryGetImportClauseCompletionSymbols(importClause) { - // cursor is in import clause - // try to show exported member for imported module - if (shouldShowCompletionsInImportsClause(contextToken)) { - isMemberCompletion = true; - isNewIdentifierLocation = false; - var importDeclaration = importClause.parent; - ts.Debug.assert(importDeclaration !== undefined && importDeclaration.kind === 219 /* ImportDeclaration */); - var exports; - var moduleSpecifierSymbol = typeChecker.getSymbolAtLocation(importDeclaration.moduleSpecifier); - if (moduleSpecifierSymbol) { - exports = typeChecker.getExportsOfModule(moduleSpecifierSymbol); - } - //let exports = typeInfoResolver.getExportsOfImportDeclaration(importDeclaration); - symbols = exports ? filterModuleExports(exports, importDeclaration) : emptyArray; + function tryGetImportOrExportClauseCompletionSymbols(namedImportsOrExports) { + var declarationKind = namedImportsOrExports.kind === 222 /* NamedImports */ ? + 219 /* ImportDeclaration */ : + 225 /* ExportDeclaration */; + var importOrExportDeclaration = ts.getAncestor(namedImportsOrExports, declarationKind); + var moduleSpecifier = importOrExportDeclaration.moduleSpecifier; + if (!moduleSpecifier) { + return false; } - else { - isMemberCompletion = false; - isNewIdentifierLocation = true; + isMemberCompletion = true; + isNewIdentifierLocation = false; + var exports; + var moduleSpecifierSymbol = typeChecker.getSymbolAtLocation(importOrExportDeclaration.moduleSpecifier); + if (moduleSpecifierSymbol) { + exports = typeChecker.getExportsOfModule(moduleSpecifierSymbol); } + symbols = exports ? filterNamedImportOrExportCompletionItems(exports, namedImportsOrExports.elements) : emptyArray; return true; } /** @@ -42665,6 +42718,24 @@ var ts; } return undefined; } + /** + * Returns the containing list of named imports or exports of a context token, + * on the condition that one exists and that the context implies completion should be given. + */ + function tryGetNamedImportsOrExportsForCompletion(contextToken) { + if (contextToken) { + switch (contextToken.kind) { + case 14 /* OpenBraceToken */: // import { | + case 23 /* CommaToken */: + switch (contextToken.parent.kind) { + case 222 /* NamedImports */: + case 226 /* NamedExports */: + return contextToken.parent; + } + } + } + return undefined; + } function tryGetContainingJsxElement(contextToken) { if (contextToken) { var parent_12 = contextToken.parent; @@ -42707,7 +42778,10 @@ var ts; } return false; } - function isIdentifierDefinitionLocation(contextToken) { + /** + * @returns true if we are certain that the currently edited location must define a new location; false otherwise. + */ + function isSolelyIdentifierDefinitionLocation(contextToken) { var containingNodeKind = contextToken.parent.kind; switch (contextToken.kind) { case 23 /* CommaToken */: @@ -42753,6 +42827,10 @@ var ts; case 107 /* PrivateKeyword */: case 108 /* ProtectedKeyword */: return containingNodeKind === 135 /* Parameter */; + case 113 /* AsKeyword */: + containingNodeKind === 223 /* ImportSpecifier */ || + containingNodeKind === 227 /* ExportSpecifier */ || + containingNodeKind === 221 /* NamespaceImport */; case 70 /* ClassKeyword */: case 78 /* EnumKeyword */: case 104 /* InterfaceKeyword */: @@ -42789,27 +42867,37 @@ var ts; } return false; } - function filterModuleExports(exports, importDeclaration) { - var exisingImports = {}; - if (!importDeclaration.importClause) { - return exports; + /** + * Filters out completion suggestions for named imports or exports. + * + * @param exportsOfModule The list of symbols which a module exposes. + * @param namedImportsOrExports The list of existing import/export specifiers in the import/export clause. + * + * @returns Symbols to be suggested at an import/export clause, barring those whose named imports/exports + * do not occur at the current position and have not otherwise been typed. + */ + function filterNamedImportOrExportCompletionItems(exportsOfModule, namedImportsOrExports) { + var exisingImportsOrExports = {}; + for (var _i = 0; _i < namedImportsOrExports.length; _i++) { + var element = namedImportsOrExports[_i]; + // If this is the current item we are editing right now, do not filter it out + if (element.getStart() <= position && position <= element.getEnd()) { + continue; + } + var name_31 = element.propertyName || element.name; + exisingImportsOrExports[name_31.text] = true; } - if (importDeclaration.importClause.namedBindings && - importDeclaration.importClause.namedBindings.kind === 222 /* NamedImports */) { - ts.forEach(importDeclaration.importClause.namedBindings.elements, function (el) { - // If this is the current item we are editing right now, do not filter it out - if (el.getStart() <= position && position <= el.getEnd()) { - return; - } - var name = el.propertyName || el.name; - exisingImports[name.text] = true; - }); + if (ts.isEmpty(exisingImportsOrExports)) { + return exportsOfModule; } - if (ts.isEmpty(exisingImports)) { - return exports; - } - return ts.filter(exports, function (e) { return !ts.lookUp(exisingImports, e.name); }); + return ts.filter(exportsOfModule, function (e) { return !ts.lookUp(exisingImportsOrExports, e.name); }); } + /** + * Filters out completion suggestions for named imports or exports. + * + * @returns Symbols to be suggested in an object binding pattern or object literal expression, barring those whose declarations + * do not occur at the current position and have not otherwise been typed. + */ function filterObjectMembersList(contextualMemberSymbols, existingMembers) { if (!existingMembers || existingMembers.length === 0) { return contextualMemberSymbols; @@ -42839,15 +42927,15 @@ var ts; } existingMemberNames[existingName] = true; } - var filteredMembers = []; - ts.forEach(contextualMemberSymbols, function (s) { - if (!existingMemberNames[s.name]) { - filteredMembers.push(s); - } - }); - return filteredMembers; + return ts.filter(contextualMemberSymbols, function (m) { return !ts.lookUp(existingMemberNames, m.name); }); } - function filterJsxAttributes(attributes, symbols) { + /** + * Filters out completion suggestions from 'symbols' according to existing JSX attributes. + * + * @returns Symbols to be suggested in a JSX element, barring those whose attributes + * do not occur at the current position and have not otherwise been typed. + */ + function filterJsxAttributes(symbols, attributes) { var seenNames = {}; for (var _i = 0; _i < attributes.length; _i++) { var attr = attributes[_i]; @@ -42859,14 +42947,7 @@ var ts; seenNames[attr.name.text] = true; } } - var result = []; - for (var _a = 0; _a < symbols.length; _a++) { - var sym = symbols[_a]; - if (!seenNames[sym.name]) { - result.push(sym); - } - } - return result; + return ts.filter(symbols, function (a) { return !ts.lookUp(seenNames, a.name); }); } } function getCompletionsAtPosition(fileName, position) { @@ -42899,10 +42980,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_31 in nameTable) { - if (!allNames[name_31]) { - allNames[name_31] = name_31; - var displayName = getCompletionEntryDisplayName(name_31, target, true); + for (var name_32 in nameTable) { + if (!allNames[name_32]) { + allNames[name_32] = name_32; + var displayName = getCompletionEntryDisplayName(name_32, target, true); if (displayName) { var entry = { name: displayName, @@ -43771,6 +43852,7 @@ var ts; if (hasKind(node.parent, 142 /* GetAccessor */) || hasKind(node.parent, 143 /* SetAccessor */)) { return getGetAndSetOccurrences(node.parent); } + break; default: if (ts.isModifier(node.kind) && node.parent && (ts.isDeclaration(node.parent) || node.parent.kind === 190 /* VariableStatement */)) { @@ -43886,12 +43968,13 @@ var ts; // Make sure we only highlight the keyword when it makes sense to do so. if (ts.isAccessibilityModifier(modifier)) { if (!(container.kind === 211 /* ClassDeclaration */ || + container.kind === 183 /* ClassExpression */ || (declaration.kind === 135 /* Parameter */ && hasKind(container, 141 /* Constructor */)))) { return undefined; } } else if (modifier === 110 /* StaticKeyword */) { - if (container.kind !== 211 /* ClassDeclaration */) { + if (!(container.kind === 211 /* ClassDeclaration */ || container.kind === 183 /* ClassExpression */)) { return undefined; } } @@ -43900,6 +43983,11 @@ var ts; return undefined; } } + else if (modifier === 112 /* AbstractKeyword */) { + if (!(container.kind === 211 /* ClassDeclaration */ || declaration.kind === 211 /* ClassDeclaration */)) { + return undefined; + } + } else { // unsupported modifier return undefined; @@ -43910,12 +43998,19 @@ var ts; switch (container.kind) { case 216 /* ModuleBlock */: case 245 /* SourceFile */: - nodes = container.statements; + // Container is either a class declaration or the declaration is a classDeclaration + if (modifierFlag & 256 /* Abstract */) { + nodes = declaration.members.concat(declaration); + } + else { + nodes = container.statements; + } break; case 141 /* Constructor */: nodes = container.parameters.concat(container.parent.members); break; case 211 /* ClassDeclaration */: + case 183 /* ClassExpression */: nodes = container.members; // If we're an accessibility modifier, we're in an instance member and should search // the constructor's parameter list for instance members as well. @@ -43927,6 +44022,9 @@ var ts; nodes = nodes.concat(constructor.parameters); } } + else if (modifierFlag & 256 /* Abstract */) { + nodes = nodes.concat(container); + } break; default: ts.Debug.fail("Invalid container kind."); @@ -43951,6 +44049,8 @@ var ts; return 1 /* Export */; case 119 /* DeclareKeyword */: return 2 /* Ambient */; + case 112 /* AbstractKeyword */: + return 256 /* Abstract */; default: ts.Debug.fail(); } @@ -44768,19 +44868,19 @@ var ts; if (isNameOfPropertyAssignment(node)) { var objectLiteral = node.parent.parent; var contextualType = typeChecker.getContextualType(objectLiteral); - var name_32 = node.text; + var name_33 = 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_32); + var unionProperty = contextualType.getProperty(name_33); if (unionProperty) { return [unionProperty]; } else { var result_4 = []; ts.forEach(contextualType.types, function (t) { - var symbol = t.getProperty(name_32); + var symbol = t.getProperty(name_33); if (symbol) { result_4.push(symbol); } @@ -44789,7 +44889,7 @@ var ts; } } else { - var symbol_1 = contextualType.getProperty(name_32); + var symbol_1 = contextualType.getProperty(name_33); if (symbol_1) { return [symbol_1]; } @@ -45471,7 +45571,7 @@ var ts; return; } } - return 9 /* text */; + return 2 /* identifier */; } } function processElement(element) { diff --git a/bin/typescriptServices.js b/bin/typescriptServices.js index e3573e840e8..6035d71fa2b 100644 --- a/bin/typescriptServices.js +++ b/bin/typescriptServices.js @@ -1775,8 +1775,15 @@ var ts; newLine: _os.EOL, useCaseSensitiveFileNames: useCaseSensitiveFileNames, write: function (s) { + var buffer = new Buffer(s, 'utf8'); + var offset = 0; + var toWrite = buffer.length; + var written = 0; // 1 is a standard descriptor for stdout - _fs.writeSync(1, s); + while ((written = _fs.writeSync(1, buffer, offset, toWrite)) < toWrite) { + offset += written; + toWrite -= written; + } }, readFile: readFile, writeFile: writeFile, @@ -2247,7 +2254,7 @@ var ts; Classes_containing_abstract_methods_must_be_marked_abstract: { code: 2514, category: ts.DiagnosticCategory.Error, key: "Classes containing abstract methods must be marked abstract." }, Non_abstract_class_0_does_not_implement_inherited_abstract_member_1_from_class_2: { code: 2515, category: ts.DiagnosticCategory.Error, key: "Non-abstract class '{0}' does not implement inherited abstract member '{1}' from class '{2}'." }, All_declarations_of_an_abstract_method_must_be_consecutive: { code: 2516, category: ts.DiagnosticCategory.Error, key: "All declarations of an abstract method must be consecutive." }, - Constructor_objects_of_abstract_type_cannot_be_assigned_to_constructor_objects_of_non_abstract_type: { code: 2517, category: ts.DiagnosticCategory.Error, key: "Constructor objects of abstract type cannot be assigned to constructor objects of non-abstract type" }, + Cannot_assign_an_abstract_constructor_type_to_a_non_abstract_constructor_type: { code: 2517, category: ts.DiagnosticCategory.Error, key: "Cannot assign an abstract constructor type to a non-abstract constructor type." }, Only_an_ambient_class_can_be_merged_with_an_interface: { code: 2518, category: ts.DiagnosticCategory.Error, key: "Only an ambient class can be merged with an interface." }, Duplicate_identifier_0_Compiler_uses_declaration_1_to_support_async_functions: { code: 2520, category: ts.DiagnosticCategory.Error, key: "Duplicate identifier '{0}'. Compiler uses declaration '{1}' to support async functions." }, Expression_resolves_to_variable_declaration_0_that_compiler_uses_to_support_async_functions: { code: 2521, category: ts.DiagnosticCategory.Error, key: "Expression resolves to variable declaration '{0}' that compiler uses to support async functions." }, @@ -11517,7 +11524,11 @@ var ts; } else { node.exportClause = parseNamedImportsOrExports(226 /* NamedExports */); - if (parseOptional(130 /* FromKeyword */)) { + // It is not uncommon to accidentally omit the 'from' keyword. Additionally, in editing scenarios, + // the 'from' keyword can be parsed as a named export when the export clause is unterminated (i.e. `export { from "moduleName";`) + // If we don't have a 'from' keyword, see if we have a string literal such that ASI won't take effect. + if (token === 130 /* FromKeyword */ || (token === 8 /* StringLiteral */ && !scanner.hasPrecedingLineBreak())) { + parseExpected(130 /* FromKeyword */); node.moduleSpecifier = parseModuleSpecifier(); } } @@ -16299,7 +16310,7 @@ var ts; var id = getTypeListId(elementTypes); var type = tupleTypes[id]; if (!type) { - type = tupleTypes[id] = createObjectType(8192 /* Tuple */); + type = tupleTypes[id] = createObjectType(8192 /* Tuple */ | getWideningFlagsOfTypes(elementTypes)); type.elementTypes = elementTypes; } return type; @@ -17200,10 +17211,33 @@ var ts; var targetSignatures = getSignaturesOfType(target, kind); var result = -1 /* True */; var saveErrorInfo = errorInfo; + // Because the "abstractness" of a class is the same across all construct signatures + // (internally we are checking the corresponding declaration), it is enough to perform + // the check and report an error once over all pairs of source and target construct signatures. + var sourceSig = sourceSignatures[0]; + // Note that in an extends-clause, targetSignatures is stripped, so the check never proceeds. + var targetSig = targetSignatures[0]; + if (sourceSig && targetSig) { + var sourceErasedSignature = getErasedSignature(sourceSig); + var targetErasedSignature = getErasedSignature(targetSig); + var sourceReturnType = sourceErasedSignature && getReturnTypeOfSignature(sourceErasedSignature); + var targetReturnType = targetErasedSignature && getReturnTypeOfSignature(targetErasedSignature); + var sourceReturnDecl = sourceReturnType && sourceReturnType.symbol && ts.getDeclarationOfKind(sourceReturnType.symbol, 211 /* ClassDeclaration */); + var targetReturnDecl = targetReturnType && targetReturnType.symbol && ts.getDeclarationOfKind(targetReturnType.symbol, 211 /* ClassDeclaration */); + var sourceIsAbstract = sourceReturnDecl && sourceReturnDecl.flags & 256 /* Abstract */; + var targetIsAbstract = targetReturnDecl && targetReturnDecl.flags & 256 /* Abstract */; + if (sourceIsAbstract && !targetIsAbstract) { + if (reportErrors) { + reportError(ts.Diagnostics.Cannot_assign_an_abstract_constructor_type_to_a_non_abstract_constructor_type); + } + return 0 /* False */; + } + } outer: for (var _i = 0; _i < targetSignatures.length; _i++) { var t = targetSignatures[_i]; if (!t.hasStringLiterals || target.flags & 262144 /* FromSignature */) { var localErrors = reportErrors; + var checkedAbstractAssignability = false; for (var _a = 0; _a < sourceSignatures.length; _a++) { var s = sourceSignatures[_a]; if (!s.hasStringLiterals || source.flags & 262144 /* FromSignature */) { @@ -17254,12 +17288,12 @@ var ts; target = getErasedSignature(target); var result = -1 /* True */; for (var i = 0; i < checkCount; i++) { - var s_1 = i < sourceMax ? getTypeOfSymbol(source.parameters[i]) : getRestTypeOfSignature(source); - var t_1 = i < targetMax ? getTypeOfSymbol(target.parameters[i]) : getRestTypeOfSignature(target); + var s = i < sourceMax ? getTypeOfSymbol(source.parameters[i]) : getRestTypeOfSignature(source); + var t = i < targetMax ? getTypeOfSymbol(target.parameters[i]) : getRestTypeOfSignature(target); var saveErrorInfo = errorInfo; - var related = isRelatedTo(s_1, t_1, reportErrors); + var related = isRelatedTo(s, t, reportErrors); if (!related) { - related = isRelatedTo(t_1, s_1, false); + related = isRelatedTo(t, s, false); if (!related) { if (reportErrors) { reportError(ts.Diagnostics.Types_of_parameters_0_and_1_are_incompatible, source.parameters[i < sourceMax ? i : sourceMax].name, target.parameters[i < targetMax ? i : targetMax].name); @@ -17297,11 +17331,11 @@ var ts; } return 0 /* False */; } - var t = getReturnTypeOfSignature(target); - if (t === voidType) + var targetReturnType = getReturnTypeOfSignature(target); + if (targetReturnType === voidType) return result; - var s = getReturnTypeOfSignature(source); - return result & isRelatedTo(s, t, reportErrors); + var sourceReturnType = getReturnTypeOfSignature(source); + return result & isRelatedTo(sourceReturnType, targetReturnType, reportErrors); } function signaturesIdenticalTo(source, target, kind) { var sourceSignatures = getSignaturesOfType(source, kind); @@ -17537,7 +17571,7 @@ var ts; * Prefer using isTupleLikeType() unless the use of `elementTypes` is required. */ function isTupleType(type) { - return (type.flags & 8192 /* Tuple */) && !!type.elementTypes; + return !!(type.flags & 8192 /* Tuple */); } function getWidenedTypeOfObjectLiteral(type) { var properties = getPropertiesOfObjectType(type); @@ -17579,25 +17613,47 @@ var ts; if (isArrayType(type)) { return createArrayType(getWidenedType(type.typeArguments[0])); } + if (isTupleType(type)) { + return createTupleType(ts.map(type.elementTypes, getWidenedType)); + } } return type; } + /** + * Reports implicit any errors that occur as a result of widening 'null' and 'undefined' + * to 'any'. A call to reportWideningErrorsInType is normally accompanied by a call to + * getWidenedType. But in some cases getWidenedType is called without reporting errors + * (type argument inference is an example). + * + * The return value indicates whether an error was in fact reported. The particular circumstances + * are on a best effort basis. Currently, if the null or undefined that causes widening is inside + * an object literal property (arbitrarily deeply), this function reports an error. If no error is + * reported, reportImplicitAnyError is a suitable fallback to report a general error. + */ function reportWideningErrorsInType(type) { + var errorReported = false; if (type.flags & 16384 /* Union */) { - var errorReported = false; - ts.forEach(type.types, function (t) { + for (var _i = 0, _a = type.types; _i < _a.length; _i++) { + var t = _a[_i]; if (reportWideningErrorsInType(t)) { errorReported = true; } - }); - return errorReported; + } } if (isArrayType(type)) { return reportWideningErrorsInType(type.typeArguments[0]); } + if (isTupleType(type)) { + for (var _b = 0, _c = type.elementTypes; _b < _c.length; _b++) { + var t = _c[_b]; + if (reportWideningErrorsInType(t)) { + errorReported = true; + } + } + } if (type.flags & 524288 /* ObjectLiteral */) { - var errorReported = false; - ts.forEach(getPropertiesOfObjectType(type), function (p) { + for (var _d = 0, _e = getPropertiesOfObjectType(type); _d < _e.length; _d++) { + var p = _e[_d]; var t = getTypeOfSymbol(p); if (t.flags & 1048576 /* ContainsUndefinedOrNull */) { if (!reportWideningErrorsInType(t)) { @@ -17605,10 +17661,9 @@ var ts; } errorReported = true; } - }); - return errorReported; + } } - return false; + return errorReported; } function reportImplicitAnyError(declaration, type) { var typeAsString = typeToString(getWidenedType(type)); @@ -17771,29 +17826,32 @@ var ts; inferFromTypes(sourceType, target); } } - else if (source.flags & 80896 /* ObjectType */ && (target.flags & (4096 /* Reference */ | 8192 /* Tuple */) || - (target.flags & 65536 /* Anonymous */) && target.symbol && target.symbol.flags & (8192 /* Method */ | 2048 /* TypeLiteral */ | 32 /* Class */))) { - // If source is an object type, and target is a type reference, a tuple type, the type of a method, or a type literal, infer from members - if (isInProcess(source, target)) { - return; + else { + source = getApparentType(source); + if (source.flags & 80896 /* ObjectType */ && (target.flags & (4096 /* Reference */ | 8192 /* Tuple */) || + (target.flags & 65536 /* Anonymous */) && target.symbol && target.symbol.flags & (8192 /* Method */ | 2048 /* TypeLiteral */ | 32 /* Class */))) { + // If source is an object type, and target is a type reference, a tuple type, the type of a method, or a type literal, infer from members + if (isInProcess(source, target)) { + return; + } + if (isDeeplyNestedGeneric(source, sourceStack, depth) && isDeeplyNestedGeneric(target, targetStack, depth)) { + return; + } + if (depth === 0) { + sourceStack = []; + targetStack = []; + } + sourceStack[depth] = source; + targetStack[depth] = target; + depth++; + inferFromProperties(source, target); + inferFromSignatures(source, target, 0 /* Call */); + inferFromSignatures(source, target, 1 /* Construct */); + inferFromIndexTypes(source, target, 0 /* String */, 0 /* String */); + inferFromIndexTypes(source, target, 1 /* Number */, 1 /* Number */); + inferFromIndexTypes(source, target, 0 /* String */, 1 /* Number */); + depth--; } - if (isDeeplyNestedGeneric(source, sourceStack, depth) && isDeeplyNestedGeneric(target, targetStack, depth)) { - return; - } - if (depth === 0) { - sourceStack = []; - targetStack = []; - } - sourceStack[depth] = source; - targetStack[depth] = target; - depth++; - inferFromProperties(source, target); - inferFromSignatures(source, target, 0 /* Call */); - inferFromSignatures(source, target, 1 /* Construct */); - inferFromIndexTypes(source, target, 0 /* String */, 0 /* String */); - inferFromIndexTypes(source, target, 1 /* Number */, 1 /* Number */); - inferFromIndexTypes(source, target, 0 /* String */, 1 /* Number */); - depth--; } } function inferFromProperties(source, target) { @@ -37768,8 +37826,8 @@ var ts; var pos = scanner.getStartPos(); // Read leading trivia and token while (pos < endPos) { - var t_2 = scanner.getToken(); - if (!ts.isTrivia(t_2)) { + var t_1 = scanner.getToken(); + if (!ts.isTrivia(t_1)) { break; } // consume leading trivia @@ -37777,7 +37835,7 @@ var ts; var item = { pos: pos, end: scanner.getStartPos(), - kind: t_2 + kind: t_1 }; pos = scanner.getStartPos(); if (!leadingTrivia) { @@ -39359,6 +39417,8 @@ var ts; case 15 /* CloseBraceToken */: case 18 /* OpenBracketToken */: case 19 /* CloseBracketToken */: + case 16 /* OpenParenToken */: + case 17 /* CloseParenToken */: case 77 /* ElseKeyword */: case 101 /* WhileKeyword */: case 53 /* AtToken */: @@ -39483,7 +39543,7 @@ var ts; else if (tokenInfo.token.kind === listStartToken) { // consume list start token startLine = sourceFile.getLineAndCharacterOfPosition(tokenInfo.token.pos).line; - var indentation_1 = computeIndentation(tokenInfo.token, startLine, -1 /* Unknown */, parent, parentDynamicIndentation, startLine); + var indentation_1 = computeIndentation(tokenInfo.token, startLine, -1 /* Unknown */, parent, parentDynamicIndentation, parentStartLine); listDynamicIndentation = getDynamicIndentation(parent, parentStartLine, indentation_1.indentation, indentation_1.delta); consumeTokenAndAdvanceScanner(tokenInfo, parent, listDynamicIndentation); } @@ -42417,15 +42477,15 @@ var ts; } function tryGetGlobalSymbols() { var objectLikeContainer; - var importClause; + var namedImportsOrExports; var jsxContainer; if (objectLikeContainer = tryGetObjectLikeCompletionContainer(contextToken)) { return tryGetObjectLikeCompletionSymbols(objectLikeContainer); } - if (importClause = ts.getAncestor(contextToken, 220 /* ImportClause */)) { + if (namedImportsOrExports = tryGetNamedImportsOrExportsForCompletion(contextToken)) { // cursor is in an import clause // try to show exported member for imported module - return tryGetImportClauseCompletionSymbols(importClause); + return tryGetImportOrExportClauseCompletionSymbols(namedImportsOrExports); } if (jsxContainer = tryGetContainingJsxElement(contextToken)) { var attrsType; @@ -42433,7 +42493,7 @@ var ts; // Cursor is inside a JSX self-closing element or opening element attrsType = typeChecker.getJsxElementAttributesType(jsxContainer); if (attrsType) { - symbols = filterJsxAttributes(jsxContainer.attributes, typeChecker.getPropertiesOfType(attrsType)); + symbols = filterJsxAttributes(typeChecker.getPropertiesOfType(attrsType), jsxContainer.attributes); isMemberCompletion = true; isNewIdentifierLocation = false; return true; @@ -42494,21 +42554,11 @@ var ts; function isCompletionListBlocker(contextToken) { var start = new Date().getTime(); var result = isInStringOrRegularExpressionOrTemplateLiteral(contextToken) || - isIdentifierDefinitionLocation(contextToken) || + isSolelyIdentifierDefinitionLocation(contextToken) || isDotOfNumericLiteral(contextToken); log("getCompletionsAtPosition: isCompletionListBlocker: " + (new Date().getTime() - start)); return result; } - function shouldShowCompletionsInImportsClause(node) { - if (node) { - // import {| - // import {a,| - if (node.kind === 14 /* OpenBraceToken */ || node.kind === 23 /* CommaToken */) { - return node.parent.kind === 222 /* NamedImports */; - } - } - return false; - } function isNewIdentifierDefinitionLocation(previousToken) { if (previousToken) { var containingNodeKind = previousToken.parent.kind; @@ -42617,34 +42667,37 @@ var ts; return true; } /** - * Aggregates relevant symbols for completion in import clauses; for instance, + * Aggregates relevant symbols for completion in import clauses and export clauses + * whose declarations have a module specifier; for instance, symbols will be aggregated for * - * import { $ } from "moduleName"; + * import { | } from "moduleName"; + * export { a as foo, | } from "moduleName"; + * + * but not for + * + * export { | }; * * Relevant symbols are stored in the captured 'symbols' variable. * * @returns true if 'symbols' was successfully populated; false otherwise. */ - function tryGetImportClauseCompletionSymbols(importClause) { - // cursor is in import clause - // try to show exported member for imported module - if (shouldShowCompletionsInImportsClause(contextToken)) { - isMemberCompletion = true; - isNewIdentifierLocation = false; - var importDeclaration = importClause.parent; - ts.Debug.assert(importDeclaration !== undefined && importDeclaration.kind === 219 /* ImportDeclaration */); - var exports; - var moduleSpecifierSymbol = typeChecker.getSymbolAtLocation(importDeclaration.moduleSpecifier); - if (moduleSpecifierSymbol) { - exports = typeChecker.getExportsOfModule(moduleSpecifierSymbol); - } - //let exports = typeInfoResolver.getExportsOfImportDeclaration(importDeclaration); - symbols = exports ? filterModuleExports(exports, importDeclaration) : emptyArray; + function tryGetImportOrExportClauseCompletionSymbols(namedImportsOrExports) { + var declarationKind = namedImportsOrExports.kind === 222 /* NamedImports */ ? + 219 /* ImportDeclaration */ : + 225 /* ExportDeclaration */; + var importOrExportDeclaration = ts.getAncestor(namedImportsOrExports, declarationKind); + var moduleSpecifier = importOrExportDeclaration.moduleSpecifier; + if (!moduleSpecifier) { + return false; } - else { - isMemberCompletion = false; - isNewIdentifierLocation = true; + isMemberCompletion = true; + isNewIdentifierLocation = false; + var exports; + var moduleSpecifierSymbol = typeChecker.getSymbolAtLocation(importOrExportDeclaration.moduleSpecifier); + if (moduleSpecifierSymbol) { + exports = typeChecker.getExportsOfModule(moduleSpecifierSymbol); } + symbols = exports ? filterNamedImportOrExportCompletionItems(exports, namedImportsOrExports.elements) : emptyArray; return true; } /** @@ -42665,6 +42718,24 @@ var ts; } return undefined; } + /** + * Returns the containing list of named imports or exports of a context token, + * on the condition that one exists and that the context implies completion should be given. + */ + function tryGetNamedImportsOrExportsForCompletion(contextToken) { + if (contextToken) { + switch (contextToken.kind) { + case 14 /* OpenBraceToken */: // import { | + case 23 /* CommaToken */: + switch (contextToken.parent.kind) { + case 222 /* NamedImports */: + case 226 /* NamedExports */: + return contextToken.parent; + } + } + } + return undefined; + } function tryGetContainingJsxElement(contextToken) { if (contextToken) { var parent_12 = contextToken.parent; @@ -42707,7 +42778,10 @@ var ts; } return false; } - function isIdentifierDefinitionLocation(contextToken) { + /** + * @returns true if we are certain that the currently edited location must define a new location; false otherwise. + */ + function isSolelyIdentifierDefinitionLocation(contextToken) { var containingNodeKind = contextToken.parent.kind; switch (contextToken.kind) { case 23 /* CommaToken */: @@ -42753,6 +42827,10 @@ var ts; case 107 /* PrivateKeyword */: case 108 /* ProtectedKeyword */: return containingNodeKind === 135 /* Parameter */; + case 113 /* AsKeyword */: + containingNodeKind === 223 /* ImportSpecifier */ || + containingNodeKind === 227 /* ExportSpecifier */ || + containingNodeKind === 221 /* NamespaceImport */; case 70 /* ClassKeyword */: case 78 /* EnumKeyword */: case 104 /* InterfaceKeyword */: @@ -42789,27 +42867,37 @@ var ts; } return false; } - function filterModuleExports(exports, importDeclaration) { - var exisingImports = {}; - if (!importDeclaration.importClause) { - return exports; + /** + * Filters out completion suggestions for named imports or exports. + * + * @param exportsOfModule The list of symbols which a module exposes. + * @param namedImportsOrExports The list of existing import/export specifiers in the import/export clause. + * + * @returns Symbols to be suggested at an import/export clause, barring those whose named imports/exports + * do not occur at the current position and have not otherwise been typed. + */ + function filterNamedImportOrExportCompletionItems(exportsOfModule, namedImportsOrExports) { + var exisingImportsOrExports = {}; + for (var _i = 0; _i < namedImportsOrExports.length; _i++) { + var element = namedImportsOrExports[_i]; + // If this is the current item we are editing right now, do not filter it out + if (element.getStart() <= position && position <= element.getEnd()) { + continue; + } + var name_31 = element.propertyName || element.name; + exisingImportsOrExports[name_31.text] = true; } - if (importDeclaration.importClause.namedBindings && - importDeclaration.importClause.namedBindings.kind === 222 /* NamedImports */) { - ts.forEach(importDeclaration.importClause.namedBindings.elements, function (el) { - // If this is the current item we are editing right now, do not filter it out - if (el.getStart() <= position && position <= el.getEnd()) { - return; - } - var name = el.propertyName || el.name; - exisingImports[name.text] = true; - }); + if (ts.isEmpty(exisingImportsOrExports)) { + return exportsOfModule; } - if (ts.isEmpty(exisingImports)) { - return exports; - } - return ts.filter(exports, function (e) { return !ts.lookUp(exisingImports, e.name); }); + return ts.filter(exportsOfModule, function (e) { return !ts.lookUp(exisingImportsOrExports, e.name); }); } + /** + * Filters out completion suggestions for named imports or exports. + * + * @returns Symbols to be suggested in an object binding pattern or object literal expression, barring those whose declarations + * do not occur at the current position and have not otherwise been typed. + */ function filterObjectMembersList(contextualMemberSymbols, existingMembers) { if (!existingMembers || existingMembers.length === 0) { return contextualMemberSymbols; @@ -42839,15 +42927,15 @@ var ts; } existingMemberNames[existingName] = true; } - var filteredMembers = []; - ts.forEach(contextualMemberSymbols, function (s) { - if (!existingMemberNames[s.name]) { - filteredMembers.push(s); - } - }); - return filteredMembers; + return ts.filter(contextualMemberSymbols, function (m) { return !ts.lookUp(existingMemberNames, m.name); }); } - function filterJsxAttributes(attributes, symbols) { + /** + * Filters out completion suggestions from 'symbols' according to existing JSX attributes. + * + * @returns Symbols to be suggested in a JSX element, barring those whose attributes + * do not occur at the current position and have not otherwise been typed. + */ + function filterJsxAttributes(symbols, attributes) { var seenNames = {}; for (var _i = 0; _i < attributes.length; _i++) { var attr = attributes[_i]; @@ -42859,14 +42947,7 @@ var ts; seenNames[attr.name.text] = true; } } - var result = []; - for (var _a = 0; _a < symbols.length; _a++) { - var sym = symbols[_a]; - if (!seenNames[sym.name]) { - result.push(sym); - } - } - return result; + return ts.filter(symbols, function (a) { return !ts.lookUp(seenNames, a.name); }); } } function getCompletionsAtPosition(fileName, position) { @@ -42899,10 +42980,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_31 in nameTable) { - if (!allNames[name_31]) { - allNames[name_31] = name_31; - var displayName = getCompletionEntryDisplayName(name_31, target, true); + for (var name_32 in nameTable) { + if (!allNames[name_32]) { + allNames[name_32] = name_32; + var displayName = getCompletionEntryDisplayName(name_32, target, true); if (displayName) { var entry = { name: displayName, @@ -43771,6 +43852,7 @@ var ts; if (hasKind(node.parent, 142 /* GetAccessor */) || hasKind(node.parent, 143 /* SetAccessor */)) { return getGetAndSetOccurrences(node.parent); } + break; default: if (ts.isModifier(node.kind) && node.parent && (ts.isDeclaration(node.parent) || node.parent.kind === 190 /* VariableStatement */)) { @@ -43886,12 +43968,13 @@ var ts; // Make sure we only highlight the keyword when it makes sense to do so. if (ts.isAccessibilityModifier(modifier)) { if (!(container.kind === 211 /* ClassDeclaration */ || + container.kind === 183 /* ClassExpression */ || (declaration.kind === 135 /* Parameter */ && hasKind(container, 141 /* Constructor */)))) { return undefined; } } else if (modifier === 110 /* StaticKeyword */) { - if (container.kind !== 211 /* ClassDeclaration */) { + if (!(container.kind === 211 /* ClassDeclaration */ || container.kind === 183 /* ClassExpression */)) { return undefined; } } @@ -43900,6 +43983,11 @@ var ts; return undefined; } } + else if (modifier === 112 /* AbstractKeyword */) { + if (!(container.kind === 211 /* ClassDeclaration */ || declaration.kind === 211 /* ClassDeclaration */)) { + return undefined; + } + } else { // unsupported modifier return undefined; @@ -43910,12 +43998,19 @@ var ts; switch (container.kind) { case 216 /* ModuleBlock */: case 245 /* SourceFile */: - nodes = container.statements; + // Container is either a class declaration or the declaration is a classDeclaration + if (modifierFlag & 256 /* Abstract */) { + nodes = declaration.members.concat(declaration); + } + else { + nodes = container.statements; + } break; case 141 /* Constructor */: nodes = container.parameters.concat(container.parent.members); break; case 211 /* ClassDeclaration */: + case 183 /* ClassExpression */: nodes = container.members; // If we're an accessibility modifier, we're in an instance member and should search // the constructor's parameter list for instance members as well. @@ -43927,6 +44022,9 @@ var ts; nodes = nodes.concat(constructor.parameters); } } + else if (modifierFlag & 256 /* Abstract */) { + nodes = nodes.concat(container); + } break; default: ts.Debug.fail("Invalid container kind."); @@ -43951,6 +44049,8 @@ var ts; return 1 /* Export */; case 119 /* DeclareKeyword */: return 2 /* Ambient */; + case 112 /* AbstractKeyword */: + return 256 /* Abstract */; default: ts.Debug.fail(); } @@ -44768,19 +44868,19 @@ var ts; if (isNameOfPropertyAssignment(node)) { var objectLiteral = node.parent.parent; var contextualType = typeChecker.getContextualType(objectLiteral); - var name_32 = node.text; + var name_33 = 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_32); + var unionProperty = contextualType.getProperty(name_33); if (unionProperty) { return [unionProperty]; } else { var result_4 = []; ts.forEach(contextualType.types, function (t) { - var symbol = t.getProperty(name_32); + var symbol = t.getProperty(name_33); if (symbol) { result_4.push(symbol); } @@ -44789,7 +44889,7 @@ var ts; } } else { - var symbol_1 = contextualType.getProperty(name_32); + var symbol_1 = contextualType.getProperty(name_33); if (symbol_1) { return [symbol_1]; } @@ -45471,7 +45571,7 @@ var ts; return; } } - return 9 /* text */; + return 2 /* identifier */; } } function processElement(element) { From 4c483e5517bc4ef57e46cbf9e204b1623c14d106 Mon Sep 17 00:00:00 2001 From: Daniel Rosenwasser Date: Wed, 15 Jul 2015 16:32:02 -0700 Subject: [PATCH 43/64] Make tests intentionally expect wrong results until we do "smarter" things for object binding elements. --- .../findAllRefsObjectBindingElementPropertyName04.ts | 4 +++- .../findAllRefsObjectBindingElementPropertyName09.ts | 6 ++++-- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/tests/cases/fourslash/findAllRefsObjectBindingElementPropertyName04.ts b/tests/cases/fourslash/findAllRefsObjectBindingElementPropertyName04.ts index a72023a1028..bdb37525f71 100644 --- a/tests/cases/fourslash/findAllRefsObjectBindingElementPropertyName04.ts +++ b/tests/cases/fourslash/findAllRefsObjectBindingElementPropertyName04.ts @@ -6,12 +6,14 @@ ////} //// ////function f({ /**/[|property1|]: p1 }: I, -//// { [|property1|] }: I, +//// { /*SHOULD_BE_A_REFERENCE*/property1 }: I, //// { property1: p2 }) { //// //// return property1 + 1; ////} +// NOTE: In the future, the identifier at +// SHOULD_BE_A_REFERENCE should be in the set of ranges. goTo.marker(); let ranges = test.ranges(); diff --git a/tests/cases/fourslash/findAllRefsObjectBindingElementPropertyName09.ts b/tests/cases/fourslash/findAllRefsObjectBindingElementPropertyName09.ts index 0b82c73e31d..e45359bcf1c 100644 --- a/tests/cases/fourslash/findAllRefsObjectBindingElementPropertyName09.ts +++ b/tests/cases/fourslash/findAllRefsObjectBindingElementPropertyName09.ts @@ -1,17 +1,19 @@ /// ////interface I { -//// [|property1|]: number; +//// /*SHOULD_BE_A_REFERENCE1*/property1: number; //// property2: string; ////} //// -////function f({ [|property1|]: p1 }: I, +////function f({ /*SHOULD_BE_A_REFERENCE2*/property1: p1 }: I, //// { /**/[|property1|] }: I, //// { property1: p2 }) { //// //// return [|property1|] + 1; ////} +// NOTE: In the future, the identifiers at +// SHOULD_BE_A_REFERENCE[1/2] should be in the set of ranges. goTo.marker(); let ranges = test.ranges(); From 4cd7f079e3f1e1aac59c424d8090baefdfe2f1cb Mon Sep 17 00:00:00 2001 From: Mohamed Hegazy Date: Wed, 15 Jul 2015 16:43:13 -0700 Subject: [PATCH 44/64] Move startIndex declaration to the top --- src/compiler/emitter.ts | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/compiler/emitter.ts b/src/compiler/emitter.ts index 7b083ba7363..9c8438565e7 100644 --- a/src/compiler/emitter.ts +++ b/src/compiler/emitter.ts @@ -4215,13 +4215,15 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, Promi } } + let startIndex = 0; + write(" {"); scopeEmitStart(node, "constructor"); increaseIndent(); if (ctor) { // Emit all the directive prologues (like "use strict"). These have to come before // any other preamble code we write (like parameter initializers). - var startIndex = emitDirectivePrologues(ctor.body.statements, /*startWithNewLine*/ true); + startIndex = emitDirectivePrologues(ctor.body.statements, /*startWithNewLine*/ true); emitDetachedComments(ctor.body.statements); } emitCaptureThisForNodeIfNecessary(node); From 61ca65f22fe4045536f35499e461f5c53582c39a Mon Sep 17 00:00:00 2001 From: Dirk Baeumer Date: Thu, 16 Jul 2015 10:40:06 +0200 Subject: [PATCH 45/64] Fixed #3887 tsserver drops responses --- src/server/session.ts | 34 +++++++++++++++++----------------- 1 file changed, 17 insertions(+), 17 deletions(-) diff --git a/src/server/session.ts b/src/server/session.ts index e0c540db18b..d2ac429aa3c 100644 --- a/src/server/session.ts +++ b/src/server/session.ts @@ -842,53 +842,53 @@ namespace ts.server { private handlers : Map<(request: protocol.Request) => {response?: any, responseRequired?: boolean}> = { [CommandNames.Exit]: () => { this.exit(); - return {}; + return { responseRequired: false}; }, [CommandNames.Definition]: (request: protocol.Request) => { var defArgs = request.arguments; - return {response: this.getDefinition(defArgs.line, defArgs.offset, defArgs.file)}; + return {response: this.getDefinition(defArgs.line, defArgs.offset, defArgs.file), responseRequired: true}; }, [CommandNames.TypeDefinition]: (request: protocol.Request) => { var defArgs = request.arguments; - return {response: this.getTypeDefinition(defArgs.line, defArgs.offset, defArgs.file)}; + return {response: this.getTypeDefinition(defArgs.line, defArgs.offset, defArgs.file), responseRequired: true}; }, [CommandNames.References]: (request: protocol.Request) => { var defArgs = request.arguments; - return {response: this.getReferences(defArgs.line, defArgs.offset, defArgs.file)}; + return {response: this.getReferences(defArgs.line, defArgs.offset, defArgs.file), responseRequired: true}; }, [CommandNames.Rename]: (request: protocol.Request) => { var renameArgs = request.arguments; - return {response: this.getRenameLocations(renameArgs.line, renameArgs.offset, renameArgs.file, renameArgs.findInComments, renameArgs.findInStrings)} + return {response: this.getRenameLocations(renameArgs.line, renameArgs.offset, renameArgs.file, renameArgs.findInComments, renameArgs.findInStrings), responseRequired: true} }, [CommandNames.Open]: (request: protocol.Request) => { var openArgs = request.arguments; this.openClientFile(openArgs.file); - return {} + return {responseRequired: false} }, [CommandNames.Quickinfo]: (request: protocol.Request) => { var quickinfoArgs = request.arguments; - return {response: this.getQuickInfo(quickinfoArgs.line, quickinfoArgs.offset, quickinfoArgs.file)}; + return {response: this.getQuickInfo(quickinfoArgs.line, quickinfoArgs.offset, quickinfoArgs.file), responseRequired: true}; }, [CommandNames.Format]: (request: protocol.Request) => { var formatArgs = request.arguments; - return {response: this.getFormattingEditsForRange(formatArgs.line, formatArgs.offset, formatArgs.endLine, formatArgs.endOffset, formatArgs.file)}; + return {response: this.getFormattingEditsForRange(formatArgs.line, formatArgs.offset, formatArgs.endLine, formatArgs.endOffset, formatArgs.file), responseRequired: true}; }, [CommandNames.Formatonkey]: (request: protocol.Request) => { var formatOnKeyArgs = request.arguments; - return {response: this.getFormattingEditsAfterKeystroke(formatOnKeyArgs.line, formatOnKeyArgs.offset, formatOnKeyArgs.key, formatOnKeyArgs.file)}; + return {response: this.getFormattingEditsAfterKeystroke(formatOnKeyArgs.line, formatOnKeyArgs.offset, formatOnKeyArgs.key, formatOnKeyArgs.file), responseRequired: true}; }, [CommandNames.Completions]: (request: protocol.Request) => { var completionsArgs = request.arguments; - return {response: this.getCompletions(completionsArgs.line, completionsArgs.offset, completionsArgs.prefix, completionsArgs.file)} + return {response: this.getCompletions(completionsArgs.line, completionsArgs.offset, completionsArgs.prefix, completionsArgs.file), responseRequired: true} }, [CommandNames.CompletionDetails]: (request: protocol.Request) => { var completionDetailsArgs = request.arguments; return {response: this.getCompletionEntryDetails(completionDetailsArgs.line,completionDetailsArgs.offset, - completionDetailsArgs.entryNames,completionDetailsArgs.file)} + completionDetailsArgs.entryNames,completionDetailsArgs.file), responseRequired: true} }, [CommandNames.SignatureHelp]: (request: protocol.Request) => { var signatureHelpArgs = request.arguments; - return {response: this.getSignatureHelpItems(signatureHelpArgs.line, signatureHelpArgs.offset, signatureHelpArgs.file)} + return {response: this.getSignatureHelpItems(signatureHelpArgs.line, signatureHelpArgs.offset, signatureHelpArgs.file), responseRequired: true} }, [CommandNames.Geterr]: (request: protocol.Request) => { var geterrArgs = request.arguments; @@ -923,23 +923,23 @@ namespace ts.server { }, [CommandNames.Navto]: (request: protocol.Request) => { var navtoArgs = request.arguments; - return {response: this.getNavigateToItems(navtoArgs.searchValue, navtoArgs.file, navtoArgs.maxResultCount)}; + return {response: this.getNavigateToItems(navtoArgs.searchValue, navtoArgs.file, navtoArgs.maxResultCount), responseRequired: true}; }, [CommandNames.Brace]: (request: protocol.Request) => { var braceArguments = request.arguments; - return {response: this.getBraceMatching(braceArguments.line, braceArguments.offset, braceArguments.file)}; + return {response: this.getBraceMatching(braceArguments.line, braceArguments.offset, braceArguments.file), responseRequired: true}; }, [CommandNames.NavBar]: (request: protocol.Request) => { var navBarArgs = request.arguments; - return {response: this.getNavigationBarItems(navBarArgs.file)}; + return {response: this.getNavigationBarItems(navBarArgs.file), responseRequired: true}; }, [CommandNames.Occurrences]: (request: protocol.Request) => { var { line, offset, file: fileName } = request.arguments; - return {response: this.getOccurrences(line, offset, fileName)}; + return {response: this.getOccurrences(line, offset, fileName), responseRequired: true}; }, [CommandNames.ProjectInfo]: (request: protocol.Request) => { var { file, needFileNameList } = request.arguments; - return {response: this.getProjectInfo(file, needFileNameList)}; + return {response: this.getProjectInfo(file, needFileNameList), responseRequired: true}; }, }; addProtocolHandler(command: string, handler: (request: protocol.Request) => {response?: any, responseRequired: boolean}) { From 9a9e00487f27834579b6276e53ce5eda760986ad Mon Sep 17 00:00:00 2001 From: Daniel Rosenwasser Date: Thu, 16 Jul 2015 16:34:07 -0700 Subject: [PATCH 46/64] Added tests. --- .../es6/destructuring/emptyAssignmentPatterns01_ES5.ts | 6 ++++++ .../es6/destructuring/emptyAssignmentPatterns01_ES6.ts | 6 ++++++ 2 files changed, 12 insertions(+) create mode 100644 tests/cases/conformance/es6/destructuring/emptyAssignmentPatterns01_ES5.ts create mode 100644 tests/cases/conformance/es6/destructuring/emptyAssignmentPatterns01_ES6.ts diff --git a/tests/cases/conformance/es6/destructuring/emptyAssignmentPatterns01_ES5.ts b/tests/cases/conformance/es6/destructuring/emptyAssignmentPatterns01_ES5.ts new file mode 100644 index 00000000000..dd10e552615 --- /dev/null +++ b/tests/cases/conformance/es6/destructuring/emptyAssignmentPatterns01_ES5.ts @@ -0,0 +1,6 @@ +// @target: es5 + +var a: any; + +({} = a); +([] = a); \ No newline at end of file diff --git a/tests/cases/conformance/es6/destructuring/emptyAssignmentPatterns01_ES6.ts b/tests/cases/conformance/es6/destructuring/emptyAssignmentPatterns01_ES6.ts new file mode 100644 index 00000000000..043f0cf1108 --- /dev/null +++ b/tests/cases/conformance/es6/destructuring/emptyAssignmentPatterns01_ES6.ts @@ -0,0 +1,6 @@ +// @target: es6 + +var a: any; + +({} = a); +([] = a); \ No newline at end of file From 255fc65410128cb2f0fc8c21daa44e271ff5e6f4 Mon Sep 17 00:00:00 2001 From: Daniel Rosenwasser Date: Thu, 16 Jul 2015 16:34:47 -0700 Subject: [PATCH 47/64] Tabs to spaces. --- .../es6/destructuring/emptyArrayBindingPatternParameter01.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/cases/conformance/es6/destructuring/emptyArrayBindingPatternParameter01.ts b/tests/cases/conformance/es6/destructuring/emptyArrayBindingPatternParameter01.ts index 0dea1fe795c..64b198b0916 100644 --- a/tests/cases/conformance/es6/destructuring/emptyArrayBindingPatternParameter01.ts +++ b/tests/cases/conformance/es6/destructuring/emptyArrayBindingPatternParameter01.ts @@ -1,5 +1,5 @@ function f([]) { - var x, y, z; + var x, y, z; } \ No newline at end of file From 895535bd2232b25b0389854c2eee7eb058e9b294 Mon Sep 17 00:00:00 2001 From: Daniel Rosenwasser Date: Thu, 16 Jul 2015 16:50:09 -0700 Subject: [PATCH 48/64] Accepted baselines. --- .../emptyArrayBindingPatternParameter01.js | 2 +- .../emptyArrayBindingPatternParameter01.symbols | 8 ++++---- .../emptyArrayBindingPatternParameter01.types | 2 +- .../reference/emptyAssignmentPatterns01_ES5.js | 11 +++++++++++ .../emptyAssignmentPatterns01_ES5.symbols | 11 +++++++++++ .../emptyAssignmentPatterns01_ES5.types | 17 +++++++++++++++++ .../reference/emptyAssignmentPatterns01_ES6.js | 11 +++++++++++ .../emptyAssignmentPatterns01_ES6.symbols | 11 +++++++++++ .../emptyAssignmentPatterns01_ES6.types | 17 +++++++++++++++++ 9 files changed, 84 insertions(+), 6 deletions(-) create mode 100644 tests/baselines/reference/emptyAssignmentPatterns01_ES5.js create mode 100644 tests/baselines/reference/emptyAssignmentPatterns01_ES5.symbols create mode 100644 tests/baselines/reference/emptyAssignmentPatterns01_ES5.types create mode 100644 tests/baselines/reference/emptyAssignmentPatterns01_ES6.js create mode 100644 tests/baselines/reference/emptyAssignmentPatterns01_ES6.symbols create mode 100644 tests/baselines/reference/emptyAssignmentPatterns01_ES6.types diff --git a/tests/baselines/reference/emptyArrayBindingPatternParameter01.js b/tests/baselines/reference/emptyArrayBindingPatternParameter01.js index 05b59b7d5f2..5723c74f117 100644 --- a/tests/baselines/reference/emptyArrayBindingPatternParameter01.js +++ b/tests/baselines/reference/emptyArrayBindingPatternParameter01.js @@ -2,7 +2,7 @@ function f([]) { - var x, y, z; + var x, y, z; } //// [emptyArrayBindingPatternParameter01.js] diff --git a/tests/baselines/reference/emptyArrayBindingPatternParameter01.symbols b/tests/baselines/reference/emptyArrayBindingPatternParameter01.symbols index 3207ca97dec..f5089ce5850 100644 --- a/tests/baselines/reference/emptyArrayBindingPatternParameter01.symbols +++ b/tests/baselines/reference/emptyArrayBindingPatternParameter01.symbols @@ -4,8 +4,8 @@ function f([]) { >f : Symbol(f, Decl(emptyArrayBindingPatternParameter01.ts, 0, 0)) - var x, y, z; ->x : Symbol(x, Decl(emptyArrayBindingPatternParameter01.ts, 3, 4)) ->y : Symbol(y, Decl(emptyArrayBindingPatternParameter01.ts, 3, 7)) ->z : Symbol(z, Decl(emptyArrayBindingPatternParameter01.ts, 3, 10)) + var x, y, z; +>x : Symbol(x, Decl(emptyArrayBindingPatternParameter01.ts, 3, 7)) +>y : Symbol(y, Decl(emptyArrayBindingPatternParameter01.ts, 3, 10)) +>z : Symbol(z, Decl(emptyArrayBindingPatternParameter01.ts, 3, 13)) } diff --git a/tests/baselines/reference/emptyArrayBindingPatternParameter01.types b/tests/baselines/reference/emptyArrayBindingPatternParameter01.types index e93394b7371..7ef40d52d59 100644 --- a/tests/baselines/reference/emptyArrayBindingPatternParameter01.types +++ b/tests/baselines/reference/emptyArrayBindingPatternParameter01.types @@ -4,7 +4,7 @@ function f([]) { >f : ([]: any[]) => void - var x, y, z; + var x, y, z; >x : any >y : any >z : any diff --git a/tests/baselines/reference/emptyAssignmentPatterns01_ES5.js b/tests/baselines/reference/emptyAssignmentPatterns01_ES5.js new file mode 100644 index 00000000000..97f050ac2c6 --- /dev/null +++ b/tests/baselines/reference/emptyAssignmentPatterns01_ES5.js @@ -0,0 +1,11 @@ +//// [emptyAssignmentPatterns01_ES5.ts] + +var a: any; + +({} = a); +([] = a); + +//// [emptyAssignmentPatterns01_ES5.js] +var a; +(, a); +(, a); diff --git a/tests/baselines/reference/emptyAssignmentPatterns01_ES5.symbols b/tests/baselines/reference/emptyAssignmentPatterns01_ES5.symbols new file mode 100644 index 00000000000..97752a1358d --- /dev/null +++ b/tests/baselines/reference/emptyAssignmentPatterns01_ES5.symbols @@ -0,0 +1,11 @@ +=== tests/cases/conformance/es6/destructuring/emptyAssignmentPatterns01_ES5.ts === + +var a: any; +>a : Symbol(a, Decl(emptyAssignmentPatterns01_ES5.ts, 1, 3)) + +({} = a); +>a : Symbol(a, Decl(emptyAssignmentPatterns01_ES5.ts, 1, 3)) + +([] = a); +>a : Symbol(a, Decl(emptyAssignmentPatterns01_ES5.ts, 1, 3)) + diff --git a/tests/baselines/reference/emptyAssignmentPatterns01_ES5.types b/tests/baselines/reference/emptyAssignmentPatterns01_ES5.types new file mode 100644 index 00000000000..cbc0a25b074 --- /dev/null +++ b/tests/baselines/reference/emptyAssignmentPatterns01_ES5.types @@ -0,0 +1,17 @@ +=== tests/cases/conformance/es6/destructuring/emptyAssignmentPatterns01_ES5.ts === + +var a: any; +>a : any + +({} = a); +>({} = a) : any +>{} = a : any +>{} : {} +>a : any + +([] = a); +>([] = a) : any +>[] = a : any +>[] : undefined[] +>a : any + diff --git a/tests/baselines/reference/emptyAssignmentPatterns01_ES6.js b/tests/baselines/reference/emptyAssignmentPatterns01_ES6.js new file mode 100644 index 00000000000..fe311ac9061 --- /dev/null +++ b/tests/baselines/reference/emptyAssignmentPatterns01_ES6.js @@ -0,0 +1,11 @@ +//// [emptyAssignmentPatterns01_ES6.ts] + +var a: any; + +({} = a); +([] = a); + +//// [emptyAssignmentPatterns01_ES6.js] +var a; +({} = a); +([] = a); diff --git a/tests/baselines/reference/emptyAssignmentPatterns01_ES6.symbols b/tests/baselines/reference/emptyAssignmentPatterns01_ES6.symbols new file mode 100644 index 00000000000..345bdd52265 --- /dev/null +++ b/tests/baselines/reference/emptyAssignmentPatterns01_ES6.symbols @@ -0,0 +1,11 @@ +=== tests/cases/conformance/es6/destructuring/emptyAssignmentPatterns01_ES6.ts === + +var a: any; +>a : Symbol(a, Decl(emptyAssignmentPatterns01_ES6.ts, 1, 3)) + +({} = a); +>a : Symbol(a, Decl(emptyAssignmentPatterns01_ES6.ts, 1, 3)) + +([] = a); +>a : Symbol(a, Decl(emptyAssignmentPatterns01_ES6.ts, 1, 3)) + diff --git a/tests/baselines/reference/emptyAssignmentPatterns01_ES6.types b/tests/baselines/reference/emptyAssignmentPatterns01_ES6.types new file mode 100644 index 00000000000..c22c0e72854 --- /dev/null +++ b/tests/baselines/reference/emptyAssignmentPatterns01_ES6.types @@ -0,0 +1,17 @@ +=== tests/cases/conformance/es6/destructuring/emptyAssignmentPatterns01_ES6.ts === + +var a: any; +>a : any + +({} = a); +>({} = a) : any +>{} = a : any +>{} : {} +>a : any + +([] = a); +>([] = a) : any +>[] = a : any +>[] : undefined[] +>a : any + From 987dc1f5d0fc23440bd27ace0c5d87175e5eb637 Mon Sep 17 00:00:00 2001 From: Daniel Rosenwasser Date: Thu, 16 Jul 2015 17:23:43 -0700 Subject: [PATCH 49/64] Added tests. --- .../es6/destructuring/emptyAssignmentPatterns02_ES5.ts | 7 +++++++ .../es6/destructuring/emptyAssignmentPatterns02_ES6.ts | 7 +++++++ .../es6/destructuring/emptyAssignmentPatterns03_ES5.ts | 6 ++++++ .../es6/destructuring/emptyAssignmentPatterns03_ES6.ts | 6 ++++++ .../es6/destructuring/emptyAssignmentPatterns04_ES5.ts | 7 +++++++ .../es6/destructuring/emptyAssignmentPatterns04_ES6.ts | 7 +++++++ 6 files changed, 40 insertions(+) create mode 100644 tests/cases/conformance/es6/destructuring/emptyAssignmentPatterns02_ES5.ts create mode 100644 tests/cases/conformance/es6/destructuring/emptyAssignmentPatterns02_ES6.ts create mode 100644 tests/cases/conformance/es6/destructuring/emptyAssignmentPatterns03_ES5.ts create mode 100644 tests/cases/conformance/es6/destructuring/emptyAssignmentPatterns03_ES6.ts create mode 100644 tests/cases/conformance/es6/destructuring/emptyAssignmentPatterns04_ES5.ts create mode 100644 tests/cases/conformance/es6/destructuring/emptyAssignmentPatterns04_ES6.ts diff --git a/tests/cases/conformance/es6/destructuring/emptyAssignmentPatterns02_ES5.ts b/tests/cases/conformance/es6/destructuring/emptyAssignmentPatterns02_ES5.ts new file mode 100644 index 00000000000..60fe89758d6 --- /dev/null +++ b/tests/cases/conformance/es6/destructuring/emptyAssignmentPatterns02_ES5.ts @@ -0,0 +1,7 @@ +// @target: es5 + +var a: any; +let x, y, z, a1, a2, a3; + +({} = { x, y, z } = a); +([] = [ a1, a2, a3] = a); \ No newline at end of file diff --git a/tests/cases/conformance/es6/destructuring/emptyAssignmentPatterns02_ES6.ts b/tests/cases/conformance/es6/destructuring/emptyAssignmentPatterns02_ES6.ts new file mode 100644 index 00000000000..295401545d4 --- /dev/null +++ b/tests/cases/conformance/es6/destructuring/emptyAssignmentPatterns02_ES6.ts @@ -0,0 +1,7 @@ +// @target: es6 + +var a: any; +let x, y, z, a1, a2, a3; + +({} = { x, y, z } = a); +([] = [ a1, a2, a3] = a); \ No newline at end of file diff --git a/tests/cases/conformance/es6/destructuring/emptyAssignmentPatterns03_ES5.ts b/tests/cases/conformance/es6/destructuring/emptyAssignmentPatterns03_ES5.ts new file mode 100644 index 00000000000..080c828ad62 --- /dev/null +++ b/tests/cases/conformance/es6/destructuring/emptyAssignmentPatterns03_ES5.ts @@ -0,0 +1,6 @@ +// @target: es5 + +var a: any; + +({} = {} = a); +([] = [] = a); \ No newline at end of file diff --git a/tests/cases/conformance/es6/destructuring/emptyAssignmentPatterns03_ES6.ts b/tests/cases/conformance/es6/destructuring/emptyAssignmentPatterns03_ES6.ts new file mode 100644 index 00000000000..10d67254cd8 --- /dev/null +++ b/tests/cases/conformance/es6/destructuring/emptyAssignmentPatterns03_ES6.ts @@ -0,0 +1,6 @@ +// @target: es6 + +var a: any; + +({} = {} = a); +([] = [] = a); \ No newline at end of file diff --git a/tests/cases/conformance/es6/destructuring/emptyAssignmentPatterns04_ES5.ts b/tests/cases/conformance/es6/destructuring/emptyAssignmentPatterns04_ES5.ts new file mode 100644 index 00000000000..0233ddcda70 --- /dev/null +++ b/tests/cases/conformance/es6/destructuring/emptyAssignmentPatterns04_ES5.ts @@ -0,0 +1,7 @@ +// @target: es5 + +var a: any; +let x, y, z, a1, a2, a3; + +({ x, y, z } = {} = a); +([ a1, a2, a3] = [] = a); \ No newline at end of file diff --git a/tests/cases/conformance/es6/destructuring/emptyAssignmentPatterns04_ES6.ts b/tests/cases/conformance/es6/destructuring/emptyAssignmentPatterns04_ES6.ts new file mode 100644 index 00000000000..3380a56aaa7 --- /dev/null +++ b/tests/cases/conformance/es6/destructuring/emptyAssignmentPatterns04_ES6.ts @@ -0,0 +1,7 @@ +// @target: es6 + +var a: any; +let x, y, z, a1, a2, a3; + +({ x, y, z } = {} = a); +([ a1, a2, a3] = [] = a); \ No newline at end of file From 0ec38b759004d6040cd0695f4148840832c71e21 Mon Sep 17 00:00:00 2001 From: Daniel Rosenwasser Date: Thu, 16 Jul 2015 17:25:00 -0700 Subject: [PATCH 50/64] Accepted baselines. --- .../emptyAssignmentPatterns02_ES5.js | 14 ++++++++ .../emptyAssignmentPatterns02_ES5.symbols | 25 +++++++++++++ .../emptyAssignmentPatterns02_ES5.types | 35 +++++++++++++++++++ .../emptyAssignmentPatterns02_ES6.js | 13 +++++++ .../emptyAssignmentPatterns02_ES6.symbols | 25 +++++++++++++ .../emptyAssignmentPatterns02_ES6.types | 35 +++++++++++++++++++ .../emptyAssignmentPatterns03_ES5.js | 12 +++++++ .../emptyAssignmentPatterns03_ES5.symbols | 11 ++++++ .../emptyAssignmentPatterns03_ES5.types | 21 +++++++++++ .../emptyAssignmentPatterns03_ES6.js | 11 ++++++ .../emptyAssignmentPatterns03_ES6.symbols | 11 ++++++ .../emptyAssignmentPatterns03_ES6.types | 21 +++++++++++ .../emptyAssignmentPatterns04_ES5.js | 14 ++++++++ .../emptyAssignmentPatterns04_ES5.symbols | 25 +++++++++++++ .../emptyAssignmentPatterns04_ES5.types | 35 +++++++++++++++++++ .../emptyAssignmentPatterns04_ES6.js | 13 +++++++ .../emptyAssignmentPatterns04_ES6.symbols | 25 +++++++++++++ .../emptyAssignmentPatterns04_ES6.types | 35 +++++++++++++++++++ 18 files changed, 381 insertions(+) create mode 100644 tests/baselines/reference/emptyAssignmentPatterns02_ES5.js create mode 100644 tests/baselines/reference/emptyAssignmentPatterns02_ES5.symbols create mode 100644 tests/baselines/reference/emptyAssignmentPatterns02_ES5.types create mode 100644 tests/baselines/reference/emptyAssignmentPatterns02_ES6.js create mode 100644 tests/baselines/reference/emptyAssignmentPatterns02_ES6.symbols create mode 100644 tests/baselines/reference/emptyAssignmentPatterns02_ES6.types create mode 100644 tests/baselines/reference/emptyAssignmentPatterns03_ES5.js create mode 100644 tests/baselines/reference/emptyAssignmentPatterns03_ES5.symbols create mode 100644 tests/baselines/reference/emptyAssignmentPatterns03_ES5.types create mode 100644 tests/baselines/reference/emptyAssignmentPatterns03_ES6.js create mode 100644 tests/baselines/reference/emptyAssignmentPatterns03_ES6.symbols create mode 100644 tests/baselines/reference/emptyAssignmentPatterns03_ES6.types create mode 100644 tests/baselines/reference/emptyAssignmentPatterns04_ES5.js create mode 100644 tests/baselines/reference/emptyAssignmentPatterns04_ES5.symbols create mode 100644 tests/baselines/reference/emptyAssignmentPatterns04_ES5.types create mode 100644 tests/baselines/reference/emptyAssignmentPatterns04_ES6.js create mode 100644 tests/baselines/reference/emptyAssignmentPatterns04_ES6.symbols create mode 100644 tests/baselines/reference/emptyAssignmentPatterns04_ES6.types diff --git a/tests/baselines/reference/emptyAssignmentPatterns02_ES5.js b/tests/baselines/reference/emptyAssignmentPatterns02_ES5.js new file mode 100644 index 00000000000..253d68c8779 --- /dev/null +++ b/tests/baselines/reference/emptyAssignmentPatterns02_ES5.js @@ -0,0 +1,14 @@ +//// [emptyAssignmentPatterns02_ES5.ts] + +var a: any; +let x, y, z, a1, a2, a3; + +({} = { x, y, z } = a); +([] = [ a1, a2, a3] = a); + +//// [emptyAssignmentPatterns02_ES5.js] +var a; +var x, y, z, a1, a2, a3; +(_a = (x = a.x, y = a.y, z = a.z, a), _a); +(_b = (a1 = a[0], a2 = a[1], a3 = a[2], a), _b); +var _a, _b; diff --git a/tests/baselines/reference/emptyAssignmentPatterns02_ES5.symbols b/tests/baselines/reference/emptyAssignmentPatterns02_ES5.symbols new file mode 100644 index 00000000000..a575ea35f24 --- /dev/null +++ b/tests/baselines/reference/emptyAssignmentPatterns02_ES5.symbols @@ -0,0 +1,25 @@ +=== tests/cases/conformance/es6/destructuring/emptyAssignmentPatterns02_ES5.ts === + +var a: any; +>a : Symbol(a, Decl(emptyAssignmentPatterns02_ES5.ts, 1, 3)) + +let x, y, z, a1, a2, a3; +>x : Symbol(x, Decl(emptyAssignmentPatterns02_ES5.ts, 2, 3)) +>y : Symbol(y, Decl(emptyAssignmentPatterns02_ES5.ts, 2, 6)) +>z : Symbol(z, Decl(emptyAssignmentPatterns02_ES5.ts, 2, 9)) +>a1 : Symbol(a1, Decl(emptyAssignmentPatterns02_ES5.ts, 2, 12)) +>a2 : Symbol(a2, Decl(emptyAssignmentPatterns02_ES5.ts, 2, 16)) +>a3 : Symbol(a3, Decl(emptyAssignmentPatterns02_ES5.ts, 2, 20)) + +({} = { x, y, z } = a); +>x : Symbol(x, Decl(emptyAssignmentPatterns02_ES5.ts, 4, 7)) +>y : Symbol(y, Decl(emptyAssignmentPatterns02_ES5.ts, 4, 10)) +>z : Symbol(z, Decl(emptyAssignmentPatterns02_ES5.ts, 4, 13)) +>a : Symbol(a, Decl(emptyAssignmentPatterns02_ES5.ts, 1, 3)) + +([] = [ a1, a2, a3] = a); +>a1 : Symbol(a1, Decl(emptyAssignmentPatterns02_ES5.ts, 2, 12)) +>a2 : Symbol(a2, Decl(emptyAssignmentPatterns02_ES5.ts, 2, 16)) +>a3 : Symbol(a3, Decl(emptyAssignmentPatterns02_ES5.ts, 2, 20)) +>a : Symbol(a, Decl(emptyAssignmentPatterns02_ES5.ts, 1, 3)) + diff --git a/tests/baselines/reference/emptyAssignmentPatterns02_ES5.types b/tests/baselines/reference/emptyAssignmentPatterns02_ES5.types new file mode 100644 index 00000000000..76897f8516e --- /dev/null +++ b/tests/baselines/reference/emptyAssignmentPatterns02_ES5.types @@ -0,0 +1,35 @@ +=== tests/cases/conformance/es6/destructuring/emptyAssignmentPatterns02_ES5.ts === + +var a: any; +>a : any + +let x, y, z, a1, a2, a3; +>x : any +>y : any +>z : any +>a1 : any +>a2 : any +>a3 : any + +({} = { x, y, z } = a); +>({} = { x, y, z } = a) : any +>{} = { x, y, z } = a : any +>{} : {} +>{ x, y, z } = a : any +>{ x, y, z } : { x: any; y: any; z: any; } +>x : any +>y : any +>z : any +>a : any + +([] = [ a1, a2, a3] = a); +>([] = [ a1, a2, a3] = a) : any +>[] = [ a1, a2, a3] = a : any +>[] : undefined[] +>[ a1, a2, a3] = a : any +>[ a1, a2, a3] : [any, any, any] +>a1 : any +>a2 : any +>a3 : any +>a : any + diff --git a/tests/baselines/reference/emptyAssignmentPatterns02_ES6.js b/tests/baselines/reference/emptyAssignmentPatterns02_ES6.js new file mode 100644 index 00000000000..e9783c7e57d --- /dev/null +++ b/tests/baselines/reference/emptyAssignmentPatterns02_ES6.js @@ -0,0 +1,13 @@ +//// [emptyAssignmentPatterns02_ES6.ts] + +var a: any; +let x, y, z, a1, a2, a3; + +({} = { x, y, z } = a); +([] = [ a1, a2, a3] = a); + +//// [emptyAssignmentPatterns02_ES6.js] +var a; +let x, y, z, a1, a2, a3; +({} = { x, y, z } = a); +([] = [a1, a2, a3] = a); diff --git a/tests/baselines/reference/emptyAssignmentPatterns02_ES6.symbols b/tests/baselines/reference/emptyAssignmentPatterns02_ES6.symbols new file mode 100644 index 00000000000..e55339cb658 --- /dev/null +++ b/tests/baselines/reference/emptyAssignmentPatterns02_ES6.symbols @@ -0,0 +1,25 @@ +=== tests/cases/conformance/es6/destructuring/emptyAssignmentPatterns02_ES6.ts === + +var a: any; +>a : Symbol(a, Decl(emptyAssignmentPatterns02_ES6.ts, 1, 3)) + +let x, y, z, a1, a2, a3; +>x : Symbol(x, Decl(emptyAssignmentPatterns02_ES6.ts, 2, 3)) +>y : Symbol(y, Decl(emptyAssignmentPatterns02_ES6.ts, 2, 6)) +>z : Symbol(z, Decl(emptyAssignmentPatterns02_ES6.ts, 2, 9)) +>a1 : Symbol(a1, Decl(emptyAssignmentPatterns02_ES6.ts, 2, 12)) +>a2 : Symbol(a2, Decl(emptyAssignmentPatterns02_ES6.ts, 2, 16)) +>a3 : Symbol(a3, Decl(emptyAssignmentPatterns02_ES6.ts, 2, 20)) + +({} = { x, y, z } = a); +>x : Symbol(x, Decl(emptyAssignmentPatterns02_ES6.ts, 4, 7)) +>y : Symbol(y, Decl(emptyAssignmentPatterns02_ES6.ts, 4, 10)) +>z : Symbol(z, Decl(emptyAssignmentPatterns02_ES6.ts, 4, 13)) +>a : Symbol(a, Decl(emptyAssignmentPatterns02_ES6.ts, 1, 3)) + +([] = [ a1, a2, a3] = a); +>a1 : Symbol(a1, Decl(emptyAssignmentPatterns02_ES6.ts, 2, 12)) +>a2 : Symbol(a2, Decl(emptyAssignmentPatterns02_ES6.ts, 2, 16)) +>a3 : Symbol(a3, Decl(emptyAssignmentPatterns02_ES6.ts, 2, 20)) +>a : Symbol(a, Decl(emptyAssignmentPatterns02_ES6.ts, 1, 3)) + diff --git a/tests/baselines/reference/emptyAssignmentPatterns02_ES6.types b/tests/baselines/reference/emptyAssignmentPatterns02_ES6.types new file mode 100644 index 00000000000..48c9146e154 --- /dev/null +++ b/tests/baselines/reference/emptyAssignmentPatterns02_ES6.types @@ -0,0 +1,35 @@ +=== tests/cases/conformance/es6/destructuring/emptyAssignmentPatterns02_ES6.ts === + +var a: any; +>a : any + +let x, y, z, a1, a2, a3; +>x : any +>y : any +>z : any +>a1 : any +>a2 : any +>a3 : any + +({} = { x, y, z } = a); +>({} = { x, y, z } = a) : any +>{} = { x, y, z } = a : any +>{} : {} +>{ x, y, z } = a : any +>{ x, y, z } : { x: any; y: any; z: any; } +>x : any +>y : any +>z : any +>a : any + +([] = [ a1, a2, a3] = a); +>([] = [ a1, a2, a3] = a) : any +>[] = [ a1, a2, a3] = a : any +>[] : undefined[] +>[ a1, a2, a3] = a : any +>[ a1, a2, a3] : [any, any, any] +>a1 : any +>a2 : any +>a3 : any +>a : any + diff --git a/tests/baselines/reference/emptyAssignmentPatterns03_ES5.js b/tests/baselines/reference/emptyAssignmentPatterns03_ES5.js new file mode 100644 index 00000000000..7c6d39eb0a2 --- /dev/null +++ b/tests/baselines/reference/emptyAssignmentPatterns03_ES5.js @@ -0,0 +1,12 @@ +//// [emptyAssignmentPatterns03_ES5.ts] + +var a: any; + +({} = {} = a); +([] = [] = a); + +//// [emptyAssignmentPatterns03_ES5.js] +var a; +(_a = (, a), _a); +(_b = (, a), _b); +var _a, _b; diff --git a/tests/baselines/reference/emptyAssignmentPatterns03_ES5.symbols b/tests/baselines/reference/emptyAssignmentPatterns03_ES5.symbols new file mode 100644 index 00000000000..c57365bc7d0 --- /dev/null +++ b/tests/baselines/reference/emptyAssignmentPatterns03_ES5.symbols @@ -0,0 +1,11 @@ +=== tests/cases/conformance/es6/destructuring/emptyAssignmentPatterns03_ES5.ts === + +var a: any; +>a : Symbol(a, Decl(emptyAssignmentPatterns03_ES5.ts, 1, 3)) + +({} = {} = a); +>a : Symbol(a, Decl(emptyAssignmentPatterns03_ES5.ts, 1, 3)) + +([] = [] = a); +>a : Symbol(a, Decl(emptyAssignmentPatterns03_ES5.ts, 1, 3)) + diff --git a/tests/baselines/reference/emptyAssignmentPatterns03_ES5.types b/tests/baselines/reference/emptyAssignmentPatterns03_ES5.types new file mode 100644 index 00000000000..4f32b0555ef --- /dev/null +++ b/tests/baselines/reference/emptyAssignmentPatterns03_ES5.types @@ -0,0 +1,21 @@ +=== tests/cases/conformance/es6/destructuring/emptyAssignmentPatterns03_ES5.ts === + +var a: any; +>a : any + +({} = {} = a); +>({} = {} = a) : any +>{} = {} = a : any +>{} : {} +>{} = a : any +>{} : {} +>a : any + +([] = [] = a); +>([] = [] = a) : any +>[] = [] = a : any +>[] : undefined[] +>[] = a : any +>[] : undefined[] +>a : any + diff --git a/tests/baselines/reference/emptyAssignmentPatterns03_ES6.js b/tests/baselines/reference/emptyAssignmentPatterns03_ES6.js new file mode 100644 index 00000000000..95bfdfefa52 --- /dev/null +++ b/tests/baselines/reference/emptyAssignmentPatterns03_ES6.js @@ -0,0 +1,11 @@ +//// [emptyAssignmentPatterns03_ES6.ts] + +var a: any; + +({} = {} = a); +([] = [] = a); + +//// [emptyAssignmentPatterns03_ES6.js] +var a; +({} = {} = a); +([] = [] = a); diff --git a/tests/baselines/reference/emptyAssignmentPatterns03_ES6.symbols b/tests/baselines/reference/emptyAssignmentPatterns03_ES6.symbols new file mode 100644 index 00000000000..3e32848207a --- /dev/null +++ b/tests/baselines/reference/emptyAssignmentPatterns03_ES6.symbols @@ -0,0 +1,11 @@ +=== tests/cases/conformance/es6/destructuring/emptyAssignmentPatterns03_ES6.ts === + +var a: any; +>a : Symbol(a, Decl(emptyAssignmentPatterns03_ES6.ts, 1, 3)) + +({} = {} = a); +>a : Symbol(a, Decl(emptyAssignmentPatterns03_ES6.ts, 1, 3)) + +([] = [] = a); +>a : Symbol(a, Decl(emptyAssignmentPatterns03_ES6.ts, 1, 3)) + diff --git a/tests/baselines/reference/emptyAssignmentPatterns03_ES6.types b/tests/baselines/reference/emptyAssignmentPatterns03_ES6.types new file mode 100644 index 00000000000..1f1d005aac5 --- /dev/null +++ b/tests/baselines/reference/emptyAssignmentPatterns03_ES6.types @@ -0,0 +1,21 @@ +=== tests/cases/conformance/es6/destructuring/emptyAssignmentPatterns03_ES6.ts === + +var a: any; +>a : any + +({} = {} = a); +>({} = {} = a) : any +>{} = {} = a : any +>{} : {} +>{} = a : any +>{} : {} +>a : any + +([] = [] = a); +>([] = [] = a) : any +>[] = [] = a : any +>[] : undefined[] +>[] = a : any +>[] : undefined[] +>a : any + diff --git a/tests/baselines/reference/emptyAssignmentPatterns04_ES5.js b/tests/baselines/reference/emptyAssignmentPatterns04_ES5.js new file mode 100644 index 00000000000..10b024352f4 --- /dev/null +++ b/tests/baselines/reference/emptyAssignmentPatterns04_ES5.js @@ -0,0 +1,14 @@ +//// [emptyAssignmentPatterns04_ES5.ts] + +var a: any; +let x, y, z, a1, a2, a3; + +({ x, y, z } = {} = a); +([ a1, a2, a3] = [] = a); + +//// [emptyAssignmentPatterns04_ES5.js] +var a; +var x, y, z, a1, a2, a3; +(_a = (, a), x = _a.x, y = _a.y, z = _a.z, _a); +(_b = (, a), a1 = _b[0], a2 = _b[1], a3 = _b[2], _b); +var _a, _b; diff --git a/tests/baselines/reference/emptyAssignmentPatterns04_ES5.symbols b/tests/baselines/reference/emptyAssignmentPatterns04_ES5.symbols new file mode 100644 index 00000000000..20ea8c037c3 --- /dev/null +++ b/tests/baselines/reference/emptyAssignmentPatterns04_ES5.symbols @@ -0,0 +1,25 @@ +=== tests/cases/conformance/es6/destructuring/emptyAssignmentPatterns04_ES5.ts === + +var a: any; +>a : Symbol(a, Decl(emptyAssignmentPatterns04_ES5.ts, 1, 3)) + +let x, y, z, a1, a2, a3; +>x : Symbol(x, Decl(emptyAssignmentPatterns04_ES5.ts, 2, 3)) +>y : Symbol(y, Decl(emptyAssignmentPatterns04_ES5.ts, 2, 6)) +>z : Symbol(z, Decl(emptyAssignmentPatterns04_ES5.ts, 2, 9)) +>a1 : Symbol(a1, Decl(emptyAssignmentPatterns04_ES5.ts, 2, 12)) +>a2 : Symbol(a2, Decl(emptyAssignmentPatterns04_ES5.ts, 2, 16)) +>a3 : Symbol(a3, Decl(emptyAssignmentPatterns04_ES5.ts, 2, 20)) + +({ x, y, z } = {} = a); +>x : Symbol(x, Decl(emptyAssignmentPatterns04_ES5.ts, 4, 2)) +>y : Symbol(y, Decl(emptyAssignmentPatterns04_ES5.ts, 4, 5)) +>z : Symbol(z, Decl(emptyAssignmentPatterns04_ES5.ts, 4, 8)) +>a : Symbol(a, Decl(emptyAssignmentPatterns04_ES5.ts, 1, 3)) + +([ a1, a2, a3] = [] = a); +>a1 : Symbol(a1, Decl(emptyAssignmentPatterns04_ES5.ts, 2, 12)) +>a2 : Symbol(a2, Decl(emptyAssignmentPatterns04_ES5.ts, 2, 16)) +>a3 : Symbol(a3, Decl(emptyAssignmentPatterns04_ES5.ts, 2, 20)) +>a : Symbol(a, Decl(emptyAssignmentPatterns04_ES5.ts, 1, 3)) + diff --git a/tests/baselines/reference/emptyAssignmentPatterns04_ES5.types b/tests/baselines/reference/emptyAssignmentPatterns04_ES5.types new file mode 100644 index 00000000000..5ae2f0674fa --- /dev/null +++ b/tests/baselines/reference/emptyAssignmentPatterns04_ES5.types @@ -0,0 +1,35 @@ +=== tests/cases/conformance/es6/destructuring/emptyAssignmentPatterns04_ES5.ts === + +var a: any; +>a : any + +let x, y, z, a1, a2, a3; +>x : any +>y : any +>z : any +>a1 : any +>a2 : any +>a3 : any + +({ x, y, z } = {} = a); +>({ x, y, z } = {} = a) : any +>{ x, y, z } = {} = a : any +>{ x, y, z } : { x: any; y: any; z: any; } +>x : any +>y : any +>z : any +>{} = a : any +>{} : {} +>a : any + +([ a1, a2, a3] = [] = a); +>([ a1, a2, a3] = [] = a) : any +>[ a1, a2, a3] = [] = a : any +>[ a1, a2, a3] : [any, any, any] +>a1 : any +>a2 : any +>a3 : any +>[] = a : any +>[] : undefined[] +>a : any + diff --git a/tests/baselines/reference/emptyAssignmentPatterns04_ES6.js b/tests/baselines/reference/emptyAssignmentPatterns04_ES6.js new file mode 100644 index 00000000000..eabc2678c05 --- /dev/null +++ b/tests/baselines/reference/emptyAssignmentPatterns04_ES6.js @@ -0,0 +1,13 @@ +//// [emptyAssignmentPatterns04_ES6.ts] + +var a: any; +let x, y, z, a1, a2, a3; + +({ x, y, z } = {} = a); +([ a1, a2, a3] = [] = a); + +//// [emptyAssignmentPatterns04_ES6.js] +var a; +let x, y, z, a1, a2, a3; +({ x, y, z } = {} = a); +([a1, a2, a3] = [] = a); diff --git a/tests/baselines/reference/emptyAssignmentPatterns04_ES6.symbols b/tests/baselines/reference/emptyAssignmentPatterns04_ES6.symbols new file mode 100644 index 00000000000..ee793cd3187 --- /dev/null +++ b/tests/baselines/reference/emptyAssignmentPatterns04_ES6.symbols @@ -0,0 +1,25 @@ +=== tests/cases/conformance/es6/destructuring/emptyAssignmentPatterns04_ES6.ts === + +var a: any; +>a : Symbol(a, Decl(emptyAssignmentPatterns04_ES6.ts, 1, 3)) + +let x, y, z, a1, a2, a3; +>x : Symbol(x, Decl(emptyAssignmentPatterns04_ES6.ts, 2, 3)) +>y : Symbol(y, Decl(emptyAssignmentPatterns04_ES6.ts, 2, 6)) +>z : Symbol(z, Decl(emptyAssignmentPatterns04_ES6.ts, 2, 9)) +>a1 : Symbol(a1, Decl(emptyAssignmentPatterns04_ES6.ts, 2, 12)) +>a2 : Symbol(a2, Decl(emptyAssignmentPatterns04_ES6.ts, 2, 16)) +>a3 : Symbol(a3, Decl(emptyAssignmentPatterns04_ES6.ts, 2, 20)) + +({ x, y, z } = {} = a); +>x : Symbol(x, Decl(emptyAssignmentPatterns04_ES6.ts, 4, 2)) +>y : Symbol(y, Decl(emptyAssignmentPatterns04_ES6.ts, 4, 5)) +>z : Symbol(z, Decl(emptyAssignmentPatterns04_ES6.ts, 4, 8)) +>a : Symbol(a, Decl(emptyAssignmentPatterns04_ES6.ts, 1, 3)) + +([ a1, a2, a3] = [] = a); +>a1 : Symbol(a1, Decl(emptyAssignmentPatterns04_ES6.ts, 2, 12)) +>a2 : Symbol(a2, Decl(emptyAssignmentPatterns04_ES6.ts, 2, 16)) +>a3 : Symbol(a3, Decl(emptyAssignmentPatterns04_ES6.ts, 2, 20)) +>a : Symbol(a, Decl(emptyAssignmentPatterns04_ES6.ts, 1, 3)) + diff --git a/tests/baselines/reference/emptyAssignmentPatterns04_ES6.types b/tests/baselines/reference/emptyAssignmentPatterns04_ES6.types new file mode 100644 index 00000000000..6bd85593748 --- /dev/null +++ b/tests/baselines/reference/emptyAssignmentPatterns04_ES6.types @@ -0,0 +1,35 @@ +=== tests/cases/conformance/es6/destructuring/emptyAssignmentPatterns04_ES6.ts === + +var a: any; +>a : any + +let x, y, z, a1, a2, a3; +>x : any +>y : any +>z : any +>a1 : any +>a2 : any +>a3 : any + +({ x, y, z } = {} = a); +>({ x, y, z } = {} = a) : any +>{ x, y, z } = {} = a : any +>{ x, y, z } : { x: any; y: any; z: any; } +>x : any +>y : any +>z : any +>{} = a : any +>{} : {} +>a : any + +([ a1, a2, a3] = [] = a); +>([ a1, a2, a3] = [] = a) : any +>[ a1, a2, a3] = [] = a : any +>[ a1, a2, a3] : [any, any, any] +>a1 : any +>a2 : any +>a3 : any +>[] = a : any +>[] : undefined[] +>a : any + From 0bdc79fbb8dc6eced088b795ca4fb16c93ac2c15 Mon Sep 17 00:00:00 2001 From: Daniel Rosenwasser Date: Thu, 16 Jul 2015 17:40:07 -0700 Subject: [PATCH 51/64] Only emit the RHS in an empty assignment pattern. --- src/compiler/emitter.ts | 6 +++++- src/compiler/utilities.ts | 11 +++++++++++ 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/src/compiler/emitter.ts b/src/compiler/emitter.ts index 9c8438565e7..2c235f9fdca 100644 --- a/src/compiler/emitter.ts +++ b/src/compiler/emitter.ts @@ -3249,7 +3249,11 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, Promi function emitAssignmentExpression(root: BinaryExpression) { let target = root.left; let value = root.right; - if (isAssignmentExpressionStatement) { + + if (isEmptyObjectLiteralOrArrayLiteral(target)) { + emit(value); + } + else if (isAssignmentExpressionStatement) { emitDestructuringAssignment(target, value); } else { diff --git a/src/compiler/utilities.ts b/src/compiler/utilities.ts index df3f1c9f174..9d7877ca6e3 100644 --- a/src/compiler/utilities.ts +++ b/src/compiler/utilities.ts @@ -1981,6 +1981,17 @@ namespace ts { (node.parent.kind === SyntaxKind.PropertyAccessExpression && (node.parent).name === node); } + export function isEmptyObjectLiteralOrArrayLiteral(expression: Node): boolean { + let kind = expression.kind; + if (kind === SyntaxKind.ObjectLiteralExpression) { + return (expression).properties.length === 0; + } + if (kind === SyntaxKind.ArrayLiteralExpression) { + return (expression).elements.length === 0; + } + return false; + } + export function getLocalSymbolForExportDefault(symbol: Symbol) { return symbol && symbol.valueDeclaration && (symbol.valueDeclaration.flags & NodeFlags.Default) ? symbol.valueDeclaration.localSymbol : undefined; } From 521d83a934f09af859d1942366ff849311287438 Mon Sep 17 00:00:00 2001 From: Daniel Rosenwasser Date: Thu, 16 Jul 2015 17:40:53 -0700 Subject: [PATCH 52/64] Accepted baselines. --- tests/baselines/reference/emptyAssignmentPatterns01_ES5.js | 4 ++-- tests/baselines/reference/emptyAssignmentPatterns02_ES5.js | 5 ++--- tests/baselines/reference/emptyAssignmentPatterns03_ES5.js | 5 ++--- tests/baselines/reference/emptyAssignmentPatterns04_ES5.js | 4 ++-- 4 files changed, 8 insertions(+), 10 deletions(-) diff --git a/tests/baselines/reference/emptyAssignmentPatterns01_ES5.js b/tests/baselines/reference/emptyAssignmentPatterns01_ES5.js index 97f050ac2c6..b89db88e5e5 100644 --- a/tests/baselines/reference/emptyAssignmentPatterns01_ES5.js +++ b/tests/baselines/reference/emptyAssignmentPatterns01_ES5.js @@ -7,5 +7,5 @@ var a: any; //// [emptyAssignmentPatterns01_ES5.js] var a; -(, a); -(, a); +(a); +(a); diff --git a/tests/baselines/reference/emptyAssignmentPatterns02_ES5.js b/tests/baselines/reference/emptyAssignmentPatterns02_ES5.js index 253d68c8779..7b9f1f402f9 100644 --- a/tests/baselines/reference/emptyAssignmentPatterns02_ES5.js +++ b/tests/baselines/reference/emptyAssignmentPatterns02_ES5.js @@ -9,6 +9,5 @@ let x, y, z, a1, a2, a3; //// [emptyAssignmentPatterns02_ES5.js] var a; var x, y, z, a1, a2, a3; -(_a = (x = a.x, y = a.y, z = a.z, a), _a); -(_b = (a1 = a[0], a2 = a[1], a3 = a[2], a), _b); -var _a, _b; +((x = a.x, y = a.y, z = a.z, a)); +((a1 = a[0], a2 = a[1], a3 = a[2], a)); diff --git a/tests/baselines/reference/emptyAssignmentPatterns03_ES5.js b/tests/baselines/reference/emptyAssignmentPatterns03_ES5.js index 7c6d39eb0a2..d9ff8ba9ede 100644 --- a/tests/baselines/reference/emptyAssignmentPatterns03_ES5.js +++ b/tests/baselines/reference/emptyAssignmentPatterns03_ES5.js @@ -7,6 +7,5 @@ var a: any; //// [emptyAssignmentPatterns03_ES5.js] var a; -(_a = (, a), _a); -(_b = (, a), _b); -var _a, _b; +(a); +(a); diff --git a/tests/baselines/reference/emptyAssignmentPatterns04_ES5.js b/tests/baselines/reference/emptyAssignmentPatterns04_ES5.js index 10b024352f4..7e342d08e39 100644 --- a/tests/baselines/reference/emptyAssignmentPatterns04_ES5.js +++ b/tests/baselines/reference/emptyAssignmentPatterns04_ES5.js @@ -9,6 +9,6 @@ let x, y, z, a1, a2, a3; //// [emptyAssignmentPatterns04_ES5.js] var a; var x, y, z, a1, a2, a3; -(_a = (, a), x = _a.x, y = _a.y, z = _a.z, _a); -(_b = (, a), a1 = _b[0], a2 = _b[1], a3 = _b[2], _b); +(_a = a, x = _a.x, y = _a.y, z = _a.z, _a); +(_b = a, a1 = _b[0], a2 = _b[1], a3 = _b[2], _b); var _a, _b; From 65a9713d800f1e9e5651a492e8465eef91838fa4 Mon Sep 17 00:00:00 2001 From: Yui T Date: Thu, 16 Jul 2015 18:26:46 -0700 Subject: [PATCH 53/64] Fix reading rwc file --- src/harness/rwcRunner.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/harness/rwcRunner.ts b/src/harness/rwcRunner.ts index bbe80abc887..54aeff18efd 100644 --- a/src/harness/rwcRunner.ts +++ b/src/harness/rwcRunner.ts @@ -123,7 +123,7 @@ module RWC { content = ts.sys.readFile(unitName); } catch (e) { - // Leave content undefined. + content = ts.sys.readFile(fileName); } return { unitName, content }; } From ad67cd31991853aa26068427d6c2c42f033e81e3 Mon Sep 17 00:00:00 2001 From: Jason Freeman Date: Thu, 16 Jul 2015 19:02:32 -0700 Subject: [PATCH 54/64] Don't fall back to any when typing tuples --- src/compiler/checker.ts | 4 ---- 1 file changed, 4 deletions(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 7d022825ea7..2a5a3578221 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -2274,10 +2274,6 @@ namespace ts { // fact an iterable or array (depending on target language). let elementType = checkIteratedTypeOrElementType(parentType, pattern, /*allowStringInput*/ false); if (!declaration.dotDotDotToken) { - if (isTypeAny(elementType)) { - return elementType; - } - // Use specific property type when parent is a tuple or numeric index type when parent is an array let propName = "" + indexOf(pattern.elements, declaration); type = isTupleLikeType(parentType) From 4ab9c0213626498ad62338476c94ec2f55491152 Mon Sep 17 00:00:00 2001 From: Jason Freeman Date: Thu, 16 Jul 2015 19:03:06 -0700 Subject: [PATCH 55/64] Accept baselines --- .../reference/arityAndOrderCompatibility01.errors.txt | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/tests/baselines/reference/arityAndOrderCompatibility01.errors.txt b/tests/baselines/reference/arityAndOrderCompatibility01.errors.txt index 391fbf42384..d13e0a265f7 100644 --- a/tests/baselines/reference/arityAndOrderCompatibility01.errors.txt +++ b/tests/baselines/reference/arityAndOrderCompatibility01.errors.txt @@ -1,6 +1,7 @@ tests/cases/conformance/types/tuple/arityAndOrderCompatibility01.ts(13,12): error TS2493: Tuple type '[string, number]' with length '2' cannot be assigned to tuple with length '3'. tests/cases/conformance/types/tuple/arityAndOrderCompatibility01.ts(14,12): error TS2460: Type 'StrNum' has no property '2'. tests/cases/conformance/types/tuple/arityAndOrderCompatibility01.ts(15,5): error TS2461: Type '{ 0: string; 1: number; }' is not an array type. +tests/cases/conformance/types/tuple/arityAndOrderCompatibility01.ts(15,12): error TS2460: Type '{ 0: string; 1: number; }' has no property '2'. tests/cases/conformance/types/tuple/arityAndOrderCompatibility01.ts(16,5): error TS2322: Type '[string, number]' is not assignable to type '[number, number, number]'. Types of property '0' are incompatible. Type 'string' is not assignable to type 'number'. @@ -46,7 +47,7 @@ tests/cases/conformance/types/tuple/arityAndOrderCompatibility01.ts(30,5): error Type 'string' is not assignable to type 'number'. -==== tests/cases/conformance/types/tuple/arityAndOrderCompatibility01.ts (18 errors) ==== +==== tests/cases/conformance/types/tuple/arityAndOrderCompatibility01.ts (19 errors) ==== interface StrNum extends Array { 0: string; 1: number; @@ -68,6 +69,8 @@ tests/cases/conformance/types/tuple/arityAndOrderCompatibility01.ts(30,5): error var [g, h, i] = z; ~~~~~~~~~ !!! error TS2461: Type '{ 0: string; 1: number; }' is not an array type. + ~ +!!! error TS2460: Type '{ 0: string; 1: number; }' has no property '2'. var j1: [number, number, number] = x; ~~ !!! error TS2322: Type '[string, number]' is not assignable to type '[number, number, number]'. From a74d64baa6e7bddefafdfe495ec0b12250248afa Mon Sep 17 00:00:00 2001 From: Jason Freeman Date: Thu, 16 Jul 2015 19:03:15 -0700 Subject: [PATCH 56/64] Add tests --- tests/baselines/reference/tupleElementTypes1.js | 5 +++++ tests/baselines/reference/tupleElementTypes1.symbols | 7 +++++++ tests/baselines/reference/tupleElementTypes1.types | 8 ++++++++ tests/baselines/reference/tupleElementTypes2.js | 7 +++++++ tests/baselines/reference/tupleElementTypes2.symbols | 6 ++++++ tests/baselines/reference/tupleElementTypes2.types | 6 ++++++ tests/baselines/reference/tupleElementTypes3.js | 5 +++++ tests/baselines/reference/tupleElementTypes3.symbols | 6 ++++++ tests/baselines/reference/tupleElementTypes3.types | 8 ++++++++ tests/baselines/reference/tupleElementTypes4.js | 7 +++++++ tests/baselines/reference/tupleElementTypes4.symbols | 7 +++++++ tests/baselines/reference/tupleElementTypes4.types | 9 +++++++++ .../cases/conformance/types/tuple/tupleElementTypes1.ts | 1 + .../cases/conformance/types/tuple/tupleElementTypes2.ts | 1 + .../cases/conformance/types/tuple/tupleElementTypes3.ts | 1 + .../cases/conformance/types/tuple/tupleElementTypes4.ts | 1 + 16 files changed, 85 insertions(+) create mode 100644 tests/baselines/reference/tupleElementTypes1.js create mode 100644 tests/baselines/reference/tupleElementTypes1.symbols create mode 100644 tests/baselines/reference/tupleElementTypes1.types create mode 100644 tests/baselines/reference/tupleElementTypes2.js create mode 100644 tests/baselines/reference/tupleElementTypes2.symbols create mode 100644 tests/baselines/reference/tupleElementTypes2.types create mode 100644 tests/baselines/reference/tupleElementTypes3.js create mode 100644 tests/baselines/reference/tupleElementTypes3.symbols create mode 100644 tests/baselines/reference/tupleElementTypes3.types create mode 100644 tests/baselines/reference/tupleElementTypes4.js create mode 100644 tests/baselines/reference/tupleElementTypes4.symbols create mode 100644 tests/baselines/reference/tupleElementTypes4.types create mode 100644 tests/cases/conformance/types/tuple/tupleElementTypes1.ts create mode 100644 tests/cases/conformance/types/tuple/tupleElementTypes2.ts create mode 100644 tests/cases/conformance/types/tuple/tupleElementTypes3.ts create mode 100644 tests/cases/conformance/types/tuple/tupleElementTypes4.ts diff --git a/tests/baselines/reference/tupleElementTypes1.js b/tests/baselines/reference/tupleElementTypes1.js new file mode 100644 index 00000000000..be220d5021c --- /dev/null +++ b/tests/baselines/reference/tupleElementTypes1.js @@ -0,0 +1,5 @@ +//// [tupleElementTypes1.ts] +var [a, b]: [number, any] = [undefined, undefined]; + +//// [tupleElementTypes1.js] +var _a = [undefined, undefined], a = _a[0], b = _a[1]; diff --git a/tests/baselines/reference/tupleElementTypes1.symbols b/tests/baselines/reference/tupleElementTypes1.symbols new file mode 100644 index 00000000000..1d27232a2a5 --- /dev/null +++ b/tests/baselines/reference/tupleElementTypes1.symbols @@ -0,0 +1,7 @@ +=== tests/cases/conformance/types/tuple/tupleElementTypes1.ts === +var [a, b]: [number, any] = [undefined, undefined]; +>a : Symbol(a, Decl(tupleElementTypes1.ts, 0, 5)) +>b : Symbol(b, Decl(tupleElementTypes1.ts, 0, 7)) +>undefined : Symbol(undefined) +>undefined : Symbol(undefined) + diff --git a/tests/baselines/reference/tupleElementTypes1.types b/tests/baselines/reference/tupleElementTypes1.types new file mode 100644 index 00000000000..3b0b8b6e854 --- /dev/null +++ b/tests/baselines/reference/tupleElementTypes1.types @@ -0,0 +1,8 @@ +=== tests/cases/conformance/types/tuple/tupleElementTypes1.ts === +var [a, b]: [number, any] = [undefined, undefined]; +>a : number +>b : any +>[undefined, undefined] : [undefined, undefined] +>undefined : undefined +>undefined : undefined + diff --git a/tests/baselines/reference/tupleElementTypes2.js b/tests/baselines/reference/tupleElementTypes2.js new file mode 100644 index 00000000000..56a7b1c889e --- /dev/null +++ b/tests/baselines/reference/tupleElementTypes2.js @@ -0,0 +1,7 @@ +//// [tupleElementTypes2.ts] +function f([a, b]: [number, any]) { } + +//// [tupleElementTypes2.js] +function f(_a) { + var a = _a[0], b = _a[1]; +} diff --git a/tests/baselines/reference/tupleElementTypes2.symbols b/tests/baselines/reference/tupleElementTypes2.symbols new file mode 100644 index 00000000000..0eae02320d4 --- /dev/null +++ b/tests/baselines/reference/tupleElementTypes2.symbols @@ -0,0 +1,6 @@ +=== tests/cases/conformance/types/tuple/tupleElementTypes2.ts === +function f([a, b]: [number, any]) { } +>f : Symbol(f, Decl(tupleElementTypes2.ts, 0, 0)) +>a : Symbol(a, Decl(tupleElementTypes2.ts, 0, 12)) +>b : Symbol(b, Decl(tupleElementTypes2.ts, 0, 14)) + diff --git a/tests/baselines/reference/tupleElementTypes2.types b/tests/baselines/reference/tupleElementTypes2.types new file mode 100644 index 00000000000..978df27d6b6 --- /dev/null +++ b/tests/baselines/reference/tupleElementTypes2.types @@ -0,0 +1,6 @@ +=== tests/cases/conformance/types/tuple/tupleElementTypes2.ts === +function f([a, b]: [number, any]) { } +>f : ([a, b]: [number, any]) => void +>a : number +>b : any + diff --git a/tests/baselines/reference/tupleElementTypes3.js b/tests/baselines/reference/tupleElementTypes3.js new file mode 100644 index 00000000000..a8db914137b --- /dev/null +++ b/tests/baselines/reference/tupleElementTypes3.js @@ -0,0 +1,5 @@ +//// [tupleElementTypes3.ts] +var [a, b] = [0, undefined]; + +//// [tupleElementTypes3.js] +var _a = [0, undefined], a = _a[0], b = _a[1]; diff --git a/tests/baselines/reference/tupleElementTypes3.symbols b/tests/baselines/reference/tupleElementTypes3.symbols new file mode 100644 index 00000000000..bf4eb78a219 --- /dev/null +++ b/tests/baselines/reference/tupleElementTypes3.symbols @@ -0,0 +1,6 @@ +=== tests/cases/conformance/types/tuple/tupleElementTypes3.ts === +var [a, b] = [0, undefined]; +>a : Symbol(a, Decl(tupleElementTypes3.ts, 0, 5)) +>b : Symbol(b, Decl(tupleElementTypes3.ts, 0, 7)) +>undefined : Symbol(undefined) + diff --git a/tests/baselines/reference/tupleElementTypes3.types b/tests/baselines/reference/tupleElementTypes3.types new file mode 100644 index 00000000000..6f29ba1371a --- /dev/null +++ b/tests/baselines/reference/tupleElementTypes3.types @@ -0,0 +1,8 @@ +=== tests/cases/conformance/types/tuple/tupleElementTypes3.ts === +var [a, b] = [0, undefined]; +>a : number +>b : any +>[0, undefined] : [number, undefined] +>0 : number +>undefined : undefined + diff --git a/tests/baselines/reference/tupleElementTypes4.js b/tests/baselines/reference/tupleElementTypes4.js new file mode 100644 index 00000000000..58c5b3f31ae --- /dev/null +++ b/tests/baselines/reference/tupleElementTypes4.js @@ -0,0 +1,7 @@ +//// [tupleElementTypes4.ts] +function f([a, b] = [0, undefined]) { } + +//// [tupleElementTypes4.js] +function f(_a) { + var _b = _a === void 0 ? [0, undefined] : _a, a = _b[0], b = _b[1]; +} diff --git a/tests/baselines/reference/tupleElementTypes4.symbols b/tests/baselines/reference/tupleElementTypes4.symbols new file mode 100644 index 00000000000..86b901e4d04 --- /dev/null +++ b/tests/baselines/reference/tupleElementTypes4.symbols @@ -0,0 +1,7 @@ +=== tests/cases/conformance/types/tuple/tupleElementTypes4.ts === +function f([a, b] = [0, undefined]) { } +>f : Symbol(f, Decl(tupleElementTypes4.ts, 0, 0)) +>a : Symbol(a, Decl(tupleElementTypes4.ts, 0, 12)) +>b : Symbol(b, Decl(tupleElementTypes4.ts, 0, 14)) +>undefined : Symbol(undefined) + diff --git a/tests/baselines/reference/tupleElementTypes4.types b/tests/baselines/reference/tupleElementTypes4.types new file mode 100644 index 00000000000..06e19ef72bb --- /dev/null +++ b/tests/baselines/reference/tupleElementTypes4.types @@ -0,0 +1,9 @@ +=== tests/cases/conformance/types/tuple/tupleElementTypes4.ts === +function f([a, b] = [0, undefined]) { } +>f : ([a, b]?: [number, any]) => void +>a : number +>b : any +>[0, undefined] : [number, undefined] +>0 : number +>undefined : undefined + diff --git a/tests/cases/conformance/types/tuple/tupleElementTypes1.ts b/tests/cases/conformance/types/tuple/tupleElementTypes1.ts new file mode 100644 index 00000000000..60772a30f66 --- /dev/null +++ b/tests/cases/conformance/types/tuple/tupleElementTypes1.ts @@ -0,0 +1 @@ +var [a, b]: [number, any] = [undefined, undefined]; \ No newline at end of file diff --git a/tests/cases/conformance/types/tuple/tupleElementTypes2.ts b/tests/cases/conformance/types/tuple/tupleElementTypes2.ts new file mode 100644 index 00000000000..aff6b569a88 --- /dev/null +++ b/tests/cases/conformance/types/tuple/tupleElementTypes2.ts @@ -0,0 +1 @@ +function f([a, b]: [number, any]) { } \ No newline at end of file diff --git a/tests/cases/conformance/types/tuple/tupleElementTypes3.ts b/tests/cases/conformance/types/tuple/tupleElementTypes3.ts new file mode 100644 index 00000000000..7ff2fd47f65 --- /dev/null +++ b/tests/cases/conformance/types/tuple/tupleElementTypes3.ts @@ -0,0 +1 @@ +var [a, b] = [0, undefined]; \ No newline at end of file diff --git a/tests/cases/conformance/types/tuple/tupleElementTypes4.ts b/tests/cases/conformance/types/tuple/tupleElementTypes4.ts new file mode 100644 index 00000000000..9d5d0277b44 --- /dev/null +++ b/tests/cases/conformance/types/tuple/tupleElementTypes4.ts @@ -0,0 +1 @@ +function f([a, b] = [0, undefined]) { } \ No newline at end of file From 6df0f3d4aa5fe90aee4a6fe64b2a55d814083dba Mon Sep 17 00:00:00 2001 From: Jason Freeman Date: Fri, 17 Jul 2015 14:52:24 -0700 Subject: [PATCH 57/64] Fix comment --- src/compiler/checker.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 0fcc1a0adaa..86f46297293 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -6783,11 +6783,11 @@ namespace ts { * for a mapper. Let's go through each one of them: * * 1. undefined - this means we are not doing inferential typing, but we may do contextual typing, - * which could cause us to assign a parameter type - * 2. identityMapper - means we want to avoid assigning a parameter type, whether or not we are in + * which could cause us to assign a parameter a type + * 2. identityMapper - means we want to avoid assigning a parameter a type, whether or not we are in * inferential typing (context is undefined for the identityMapper) * 3. a mapper created by createInferenceMapper - we are doing inferential typing, we want to assign - * parameter types and fix type parameters (context is defined) + * types to parameters and fix type parameters (context is defined) * 4. an instantiation mapper created by createTypeMapper or createTypeEraser - this should never be * passed as the contextual mapper when checking an expression (context is undefined for these) * From fbe4246d39d2f001160948855b61a492094d44fd Mon Sep 17 00:00:00 2001 From: Jason Freeman Date: Wed, 15 Jul 2015 16:36:54 -0700 Subject: [PATCH 58/64] Remove resolveLocation --- src/compiler/checker.ts | 17 ----------------- 1 file changed, 17 deletions(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 007edacadc9..d0c5667a340 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -5841,32 +5841,15 @@ namespace ts { } } - function resolveLocation(node: Node) { - // Resolve location from top down towards node if it is a context sensitive expression - // That helps in making sure not assigning types as any when resolved out of order - let containerNodes: Node[] = []; - for (let parent = node.parent; parent; parent = parent.parent) { - if ((isExpression(parent) || isObjectLiteralMethod(node)) && - isContextSensitive(parent)) { - containerNodes.unshift(parent); - } - } - - ts.forEach(containerNodes, node => { getTypeOfNode(node); }); - } - function getSymbolAtLocation(node: Node): Symbol { - resolveLocation(node); return getSymbolInfo(node); } function getTypeAtLocation(node: Node): Type { - resolveLocation(node); return getTypeOfNode(node); } function getTypeOfSymbolAtLocation(symbol: Symbol, node: Node): Type { - resolveLocation(node); // Get the narrowed type of symbol at given location instead of just getting // the type of the symbol. // eg. From 48588b622e50d2e90ea8aae1f856e9483f2c476b Mon Sep 17 00:00:00 2001 From: Jason Freeman Date: Thu, 16 Jul 2015 18:17:28 -0700 Subject: [PATCH 59/64] Only consider a type resolution sequence a cycle if none of the items in the sequence have types --- src/compiler/checker.ts | 49 ++++++++++++++++++++++++++++++++--------- 1 file changed, 39 insertions(+), 10 deletions(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index d0c5667a340..9211437b42f 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -161,6 +161,7 @@ namespace ts { let resolutionTargets: Object[] = []; let resolutionResults: boolean[] = []; + let resolutionKinds: TypeSystemObjectKind[] = []; let mergedSymbols: Symbol[] = []; let symbolLinks: SymbolLinks[] = []; @@ -201,6 +202,13 @@ namespace ts { let assignableRelation: Map = {}; let identityRelation: Map = {}; + enum TypeSystemObjectKind { + Symbol, + Type, + SymbolLinks, + Signature + } + initializeTypeChecker(); return checker; @@ -2184,13 +2192,14 @@ namespace ts { // a unique identity for a particular type resolution result: Symbol instances are used to track resolution of // SymbolLinks.type, SymbolLinks instances are used to track resolution of SymbolLinks.declaredType, and // Signature instances are used to track resolution of Signature.resolvedReturnType. - function pushTypeResolution(target: Object): boolean { - let i = 0; + function pushTypeResolution(target: Object, flags: TypeSystemObjectKind): boolean { let count = resolutionTargets.length; - while (i < count && resolutionTargets[i] !== target) { - i++; + let i = count - 1; + let foundGoodType = false; + while (i >= 0 && !(foundGoodType = !!hasType(resolutionTargets[i], resolutionKinds[i])) && resolutionTargets[i] !== target) { + i--; } - if (i < count) { + if (i >= 0 && !foundGoodType) { do { resolutionResults[i++] = false; } @@ -2199,13 +2208,33 @@ namespace ts { } resolutionTargets.push(target); resolutionResults.push(true); + resolutionKinds.push(flags); return true; } + function hasType(target: Object, flags: TypeSystemObjectKind): Type { + if (flags === TypeSystemObjectKind.Symbol) { + return getSymbolLinks(target).type; + } + else if (flags === TypeSystemObjectKind.Type) { + Debug.assert(!!((target).flags & TypeFlags.Class)); + return (target).resolvedBaseConstructorType; + } + else if (flags === TypeSystemObjectKind.SymbolLinks) { + return (target).declaredType; + } + else if (flags === TypeSystemObjectKind.Signature) { + return (target).resolvedReturnType; + } + + Debug.fail("Unhandled TypeSystemObjectKind"); + } + // Pop an entry from the type resolution stack and return its associated result value. The result value will // be true if no circularities were detected, or false if a circularity was found. function popTypeResolution(): boolean { resolutionTargets.pop(); + resolutionKinds.pop(); return resolutionResults.pop(); } @@ -2468,7 +2497,7 @@ namespace ts { return links.type = checkExpression((declaration).expression); } // Handle variable, parameter or property - if (!pushTypeResolution(symbol)) { + if (!pushTypeResolution(symbol, TypeSystemObjectKind.Symbol)) { return unknownType; } let type = getWidenedTypeForVariableLikeDeclaration(declaration, /*reportErrors*/ true); @@ -2509,7 +2538,7 @@ namespace ts { function getTypeOfAccessors(symbol: Symbol): Type { let links = getSymbolLinks(symbol); if (!links.type) { - if (!pushTypeResolution(symbol)) { + if (!pushTypeResolution(symbol, TypeSystemObjectKind.Symbol)) { return unknownType; } let getter = getDeclarationOfKind(symbol, SyntaxKind.GetAccessor); @@ -2725,7 +2754,7 @@ namespace ts { if (!baseTypeNode) { return type.resolvedBaseConstructorType = undefinedType; } - if (!pushTypeResolution(type)) { + if (!pushTypeResolution(type, TypeSystemObjectKind.Type)) { return unknownType; } let baseConstructorType = checkExpression(baseTypeNode.expression); @@ -2852,7 +2881,7 @@ namespace ts { if (!links.declaredType) { // Note that we use the links object as the target here because the symbol object is used as the unique // identity for resolution of the 'type' property in SymbolLinks. - if (!pushTypeResolution(links)) { + if (!pushTypeResolution(links, TypeSystemObjectKind.SymbolLinks)) { return unknownType; } let declaration = getDeclarationOfKind(symbol, SyntaxKind.TypeAliasDeclaration); @@ -3539,7 +3568,7 @@ namespace ts { function getReturnTypeOfSignature(signature: Signature): Type { if (!signature.resolvedReturnType) { - if (!pushTypeResolution(signature)) { + if (!pushTypeResolution(signature, TypeSystemObjectKind.Signature)) { return unknownType; } let type: Type; From c0b3835b19685ed9b71ad1686b5e6308f3c03e87 Mon Sep 17 00:00:00 2001 From: Jason Freeman Date: Fri, 17 Jul 2015 16:32:40 -0700 Subject: [PATCH 60/64] Instantiate signatures if there is an overload resolution error but type arguments present --- src/compiler/checker.ts | 3 +++ tests/cases/fourslash/genericCombinators2.ts | 6 +++--- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 9211437b42f..bf4f6e07b73 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -8522,6 +8522,9 @@ namespace ts { if (!produceDiagnostics) { for (let candidate of candidates) { if (hasCorrectArity(node, args, candidate)) { + if (candidate.typeParameters && typeArguments) { + candidate = getSignatureInstantiation(candidate, map(typeArguments, getTypeFromTypeNode)); + } return candidate; } } diff --git a/tests/cases/fourslash/genericCombinators2.ts b/tests/cases/fourslash/genericCombinators2.ts index 4d38ffd0796..bcd96dcd1c6 100644 --- a/tests/cases/fourslash/genericCombinators2.ts +++ b/tests/cases/fourslash/genericCombinators2.ts @@ -110,7 +110,7 @@ goTo.marker('15'); verify.quickInfoIs('var r4a: Collection'); goTo.marker('17'); -verify.quickInfoIs('var r5a: Collection'); // This is actually due to an error because toFixed does not return a Date +verify.quickInfoIs('var r5a: Collection'); goTo.marker('18'); verify.quickInfoIs('var r5b: Collection'); @@ -122,10 +122,10 @@ goTo.marker('20'); verify.quickInfoIs('var r6b: Collection, Date>'); goTo.marker('21'); -verify.quickInfoIs('var r7a: Collection'); // This call is an error because y.foo() does not return a string +verify.quickInfoIs('var r7a: Collection'); goTo.marker('22'); -verify.quickInfoIs('var r7b: Collection'); // This call is an error because y.foo() does not return a string +verify.quickInfoIs('var r7b: Collection'); goTo.marker('23'); verify.quickInfoIs('var r8a: Collection'); From 3b78377cf0de87c3d17b6fd27b0627001a82b901 Mon Sep 17 00:00:00 2001 From: Jason Freeman Date: Fri, 17 Jul 2015 17:01:37 -0700 Subject: [PATCH 61/64] Clean up pushTypeResolution --- src/compiler/checker.ts | 89 +++++++++++++++++++++++------------------ src/compiler/types.ts | 2 + 2 files changed, 53 insertions(+), 38 deletions(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index bf4f6e07b73..927e20b5d27 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -159,9 +159,9 @@ namespace ts { let emitAwaiter = false; let emitGenerator = false; - let resolutionTargets: Object[] = []; + let resolutionTargets: TypeSystemEntity[] = []; let resolutionResults: boolean[] = []; - let resolutionKinds: TypeSystemObjectKind[] = []; + let resolutionPropertyNames: TypeSystemPropertyName[] = []; let mergedSymbols: Symbol[] = []; let symbolLinks: SymbolLinks[] = []; @@ -202,11 +202,11 @@ namespace ts { let assignableRelation: Map = {}; let identityRelation: Map = {}; - enum TypeSystemObjectKind { - Symbol, + enum TypeSystemPropertyName { Type, - SymbolLinks, - Signature + ResolvedBaseConstructorType, + DeclaredType, + ResolvedReturnType } initializeTypeChecker(); @@ -2185,45 +2185,58 @@ namespace ts { } } - // Push an entry on the type resolution stack. If an entry with the given target is not already on the stack, - // a new entry with that target and an associated result value of true is pushed on the stack, and the value - // true is returned. Otherwise, a circularity has occurred and the result values of the existing entry and - // all entries pushed after it are changed to false, and the value false is returned. The target object provides - // a unique identity for a particular type resolution result: Symbol instances are used to track resolution of - // SymbolLinks.type, SymbolLinks instances are used to track resolution of SymbolLinks.declaredType, and - // Signature instances are used to track resolution of Signature.resolvedReturnType. - function pushTypeResolution(target: Object, flags: TypeSystemObjectKind): boolean { - let count = resolutionTargets.length; - let i = count - 1; - let foundGoodType = false; - while (i >= 0 && !(foundGoodType = !!hasType(resolutionTargets[i], resolutionKinds[i])) && resolutionTargets[i] !== target) { - i--; - } - if (i >= 0 && !foundGoodType) { - do { - resolutionResults[i++] = false; + /** + * Push an entry on the type resolution stack. If an entry with the given target and the given property name + * is already on the stack, and no entries in between already have a type, then a circularity has occurred. + * In this case, the result values of the existing entry and all entries pushed after it are changed to false, + * and the value false is returned. Otherwise, the new entry is just pushed onto the stack, and true is returned. + * In order to see if the same query has already been done before, the target object and the propertyName both + * must match the one passed in. + * + * @param target The symbol, type, or signature whose type is being queried + * @param propertyName The property name that should be used to query the target for its type + */ + function pushTypeResolution(target: TypeSystemEntity, propertyName: TypeSystemPropertyName): boolean { + let resolutionCycleStartIndex = findResolutionCycleStartIndex(target, propertyName); + if (resolutionCycleStartIndex >= 0) { + // A cycle was found + let { length } = resolutionTargets; + for (let i = resolutionCycleStartIndex; i < length; i++) { + resolutionResults[i] = false; } - while (i < count); return false; } resolutionTargets.push(target); resolutionResults.push(true); - resolutionKinds.push(flags); + resolutionPropertyNames.push(propertyName); return true; } - function hasType(target: Object, flags: TypeSystemObjectKind): Type { - if (flags === TypeSystemObjectKind.Symbol) { + function findResolutionCycleStartIndex(target: TypeSystemEntity, propertyName: TypeSystemPropertyName): number { + for (let i = resolutionTargets.length - 1; i >= 0; i--) { + if (hasType(resolutionTargets[i], resolutionPropertyNames[i])) { + return -1; + } + if (resolutionTargets[i] === target && resolutionPropertyNames[i] === propertyName) { + return i; + } + } + + return -1; + } + + function hasType(target: TypeSystemEntity, propertyName: TypeSystemPropertyName): Type { + if (propertyName === TypeSystemPropertyName.Type) { return getSymbolLinks(target).type; } - else if (flags === TypeSystemObjectKind.Type) { + else if (propertyName === TypeSystemPropertyName.DeclaredType) { + return getSymbolLinks(target).declaredType; + } + else if (propertyName === TypeSystemPropertyName.ResolvedBaseConstructorType) { Debug.assert(!!((target).flags & TypeFlags.Class)); return (target).resolvedBaseConstructorType; } - else if (flags === TypeSystemObjectKind.SymbolLinks) { - return (target).declaredType; - } - else if (flags === TypeSystemObjectKind.Signature) { + else if (propertyName === TypeSystemPropertyName.ResolvedReturnType) { return (target).resolvedReturnType; } @@ -2234,7 +2247,7 @@ namespace ts { // be true if no circularities were detected, or false if a circularity was found. function popTypeResolution(): boolean { resolutionTargets.pop(); - resolutionKinds.pop(); + resolutionPropertyNames.pop(); return resolutionResults.pop(); } @@ -2497,7 +2510,7 @@ namespace ts { return links.type = checkExpression((declaration).expression); } // Handle variable, parameter or property - if (!pushTypeResolution(symbol, TypeSystemObjectKind.Symbol)) { + if (!pushTypeResolution(symbol, TypeSystemPropertyName.Type)) { return unknownType; } let type = getWidenedTypeForVariableLikeDeclaration(declaration, /*reportErrors*/ true); @@ -2538,7 +2551,7 @@ namespace ts { function getTypeOfAccessors(symbol: Symbol): Type { let links = getSymbolLinks(symbol); if (!links.type) { - if (!pushTypeResolution(symbol, TypeSystemObjectKind.Symbol)) { + if (!pushTypeResolution(symbol, TypeSystemPropertyName.Type)) { return unknownType; } let getter = getDeclarationOfKind(symbol, SyntaxKind.GetAccessor); @@ -2754,7 +2767,7 @@ namespace ts { if (!baseTypeNode) { return type.resolvedBaseConstructorType = undefinedType; } - if (!pushTypeResolution(type, TypeSystemObjectKind.Type)) { + if (!pushTypeResolution(type, TypeSystemPropertyName.ResolvedBaseConstructorType)) { return unknownType; } let baseConstructorType = checkExpression(baseTypeNode.expression); @@ -2881,7 +2894,7 @@ namespace ts { if (!links.declaredType) { // Note that we use the links object as the target here because the symbol object is used as the unique // identity for resolution of the 'type' property in SymbolLinks. - if (!pushTypeResolution(links, TypeSystemObjectKind.SymbolLinks)) { + if (!pushTypeResolution(symbol, TypeSystemPropertyName.DeclaredType)) { return unknownType; } let declaration = getDeclarationOfKind(symbol, SyntaxKind.TypeAliasDeclaration); @@ -3568,7 +3581,7 @@ namespace ts { function getReturnTypeOfSignature(signature: Signature): Type { if (!signature.resolvedReturnType) { - if (!pushTypeResolution(signature, TypeSystemObjectKind.Signature)) { + if (!pushTypeResolution(signature, TypeSystemPropertyName.ResolvedReturnType)) { return unknownType; } let type: Type; diff --git a/src/compiler/types.ts b/src/compiler/types.ts index f1b476d11b4..edaf940e2fc 100644 --- a/src/compiler/types.ts +++ b/src/compiler/types.ts @@ -1904,6 +1904,8 @@ namespace ts { isolatedSignatureType?: ObjectType; // A manufactured type that just contains the signature for purposes of signature comparison } + export type TypeSystemEntity = Symbol | Type | Signature; + export const enum IndexKind { String, Number, From e2303b1ae865f150c3102fe5b370d51b4aa7d88d Mon Sep 17 00:00:00 2001 From: Jason Freeman Date: Fri, 17 Jul 2015 17:22:17 -0700 Subject: [PATCH 62/64] Clean up the language service aliases to check functions --- src/compiler/checker.ts | 59 +++++++++++++++++------------------------ 1 file changed, 24 insertions(+), 35 deletions(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 927e20b5d27..7281d0d6059 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -59,7 +59,20 @@ namespace ts { isArgumentsSymbol: symbol => symbol === argumentsSymbol, getDiagnostics, getGlobalDiagnostics, - getTypeOfSymbolAtLocation, + + // Get the narrowed type of symbol at given location instead of just getting + // the type of the symbol. + // eg. + // function foo(a: string | number) { + // if (typeof a === "string") { + // a/**/ + // } + // } + // getTypeOfSymbol for a would return type of parameter symbol string | number + // Unless we provide location /**/, checker wouldn't know how to narrow the type + // By using getNarrowedTypeOfSymbol would return string since it would be able to narrow + // it by typeguard in the if true condition + getTypeOfSymbolAtLocation: getNarrowedTypeOfSymbol, getDeclaredTypeOfSymbol, getPropertiesOfType, getPropertyOfType, @@ -69,7 +82,7 @@ namespace ts { getSymbolsInScope, getSymbolAtLocation, getShorthandAssignmentValueSymbol, - getTypeAtLocation, + getTypeAtLocation: getTypeOfNode, typeToString, getSymbolDisplayBuilder, symbolToString, @@ -4226,7 +4239,7 @@ namespace ts { // Callers should first ensure this by calling isTypeNode case SyntaxKind.Identifier: case SyntaxKind.QualifiedName: - let symbol = getSymbolInfo(node); + let symbol = getSymbolAtLocation(node); return symbol && getDeclaredTypeOfSymbol(symbol); default: return unknownType; @@ -5883,30 +5896,6 @@ namespace ts { } } - function getSymbolAtLocation(node: Node): Symbol { - return getSymbolInfo(node); - } - - function getTypeAtLocation(node: Node): Type { - return getTypeOfNode(node); - } - - function getTypeOfSymbolAtLocation(symbol: Symbol, node: Node): Type { - // Get the narrowed type of symbol at given location instead of just getting - // the type of the symbol. - // eg. - // function foo(a: string | number) { - // if (typeof a === "string") { - // a/**/ - // } - // } - // getTypeOfSymbol for a would return type of parameter symbol string | number - // Unless we provide location /**/, checker wouldn't know how to narrow the type - // By using getNarrowedTypeOfSymbol would return string since it would be able to narrow - // it by typeguard in the if true condition - return getNarrowedTypeOfSymbol(symbol, node); - } - // Get the narrowed type of a given symbol at a given location function getNarrowedTypeOfSymbol(symbol: Symbol, node: Node) { let type = getTypeOfSymbol(symbol); @@ -10136,7 +10125,7 @@ namespace ts { } else { checkTypeAssignableTo(typePredicate.type, - getTypeAtLocation(node.parameters[typePredicate.parameterIndex]), + getTypeOfNode(node.parameters[typePredicate.parameterIndex]), typePredicateNode.type); } } @@ -13758,7 +13747,7 @@ namespace ts { return undefined; } - function getSymbolInfo(node: Node) { + function getSymbolAtLocation(node: Node) { if (isInsideWithStatementBody(node)) { // We cannot answer semantic questions within a with block, do not proceed any further return undefined; @@ -13778,7 +13767,7 @@ namespace ts { else if (node.parent.kind === SyntaxKind.BindingElement && node.parent.parent.kind === SyntaxKind.ObjectBindingPattern && node === (node.parent).propertyName) { - let typeOfPattern = getTypeAtLocation(node.parent.parent); + let typeOfPattern = getTypeOfNode(node.parent.parent); let propertyDeclaration = typeOfPattern && getPropertyOfType(typeOfPattern, (node).text); if (propertyDeclaration) { @@ -13861,24 +13850,24 @@ namespace ts { } if (isTypeDeclaration(node)) { - // In this case, we call getSymbolOfNode instead of getSymbolInfo because it is a declaration + // In this case, we call getSymbolOfNode instead of getSymbolAtLocation because it is a declaration let symbol = getSymbolOfNode(node); return getDeclaredTypeOfSymbol(symbol); } if (isTypeDeclarationName(node)) { - let symbol = getSymbolInfo(node); + let symbol = getSymbolAtLocation(node); return symbol && getDeclaredTypeOfSymbol(symbol); } if (isDeclaration(node)) { - // In this case, we call getSymbolOfNode instead of getSymbolInfo because it is a declaration + // In this case, we call getSymbolOfNode instead of getSymbolAtLocation because it is a declaration let symbol = getSymbolOfNode(node); return getTypeOfSymbol(symbol); } if (isDeclarationName(node)) { - let symbol = getSymbolInfo(node); + let symbol = getSymbolAtLocation(node); return symbol && getTypeOfSymbol(symbol); } @@ -13887,7 +13876,7 @@ namespace ts { } if (isInRightSideOfImportOrExportAssignment(node)) { - let symbol = getSymbolInfo(node); + let symbol = getSymbolAtLocation(node); let declaredType = symbol && getDeclaredTypeOfSymbol(symbol); return declaredType !== unknownType ? declaredType : getTypeOfSymbol(symbol); } From 9c9e39e7a3f875a4865518f76ee91c0fe42f8b78 Mon Sep 17 00:00:00 2001 From: kimamula Date: Sat, 18 Jul 2015 18:46:40 +0900 Subject: [PATCH 63/64] Add includes method to String interface, and remove contains --- src/lib/es6.d.ts | 2 +- tests/baselines/reference/stringIncludes.js | 10 ++++++++ .../reference/stringIncludes.symbols | 15 ++++++++++++ .../baselines/reference/stringIncludes.types | 24 +++++++++++++++++++ tests/cases/compiler/stringIncludes.ts | 5 ++++ 5 files changed, 55 insertions(+), 1 deletion(-) create mode 100644 tests/baselines/reference/stringIncludes.js create mode 100644 tests/baselines/reference/stringIncludes.symbols create mode 100644 tests/baselines/reference/stringIncludes.types create mode 100644 tests/cases/compiler/stringIncludes.ts diff --git a/src/lib/es6.d.ts b/src/lib/es6.d.ts index f3c0a1418fe..97291f742bd 100644 --- a/src/lib/es6.d.ts +++ b/src/lib/es6.d.ts @@ -377,7 +377,7 @@ interface String { * @param searchString search string * @param position If position is undefined, 0 is assumed, so as to search all of the String. */ - contains(searchString: string, position?: number): boolean; + includes(searchString: string, position?: number): boolean; /** * Returns true if the sequence of elements of searchString converted to a String is the diff --git a/tests/baselines/reference/stringIncludes.js b/tests/baselines/reference/stringIncludes.js new file mode 100644 index 00000000000..055d7d8beeb --- /dev/null +++ b/tests/baselines/reference/stringIncludes.js @@ -0,0 +1,10 @@ +//// [stringIncludes.ts] + +var includes: boolean; +includes = "abcde".includes("cd"); +includes = "abcde".includes("cd", 2); + +//// [stringIncludes.js] +var includes; +includes = "abcde".includes("cd"); +includes = "abcde".includes("cd", 2); diff --git a/tests/baselines/reference/stringIncludes.symbols b/tests/baselines/reference/stringIncludes.symbols new file mode 100644 index 00000000000..d0fa641c857 --- /dev/null +++ b/tests/baselines/reference/stringIncludes.symbols @@ -0,0 +1,15 @@ +=== tests/cases/compiler/stringIncludes.ts === + +var includes: boolean; +>includes : Symbol(includes, Decl(stringIncludes.ts, 1, 3)) + +includes = "abcde".includes("cd"); +>includes : Symbol(includes, Decl(stringIncludes.ts, 1, 3)) +>"abcde".includes : Symbol(String.includes, Decl(lib.d.ts, 1569, 37)) +>includes : Symbol(String.includes, Decl(lib.d.ts, 1569, 37)) + +includes = "abcde".includes("cd", 2); +>includes : Symbol(includes, Decl(stringIncludes.ts, 1, 3)) +>"abcde".includes : Symbol(String.includes, Decl(lib.d.ts, 1569, 37)) +>includes : Symbol(String.includes, Decl(lib.d.ts, 1569, 37)) + diff --git a/tests/baselines/reference/stringIncludes.types b/tests/baselines/reference/stringIncludes.types new file mode 100644 index 00000000000..0d1e5ffea4d --- /dev/null +++ b/tests/baselines/reference/stringIncludes.types @@ -0,0 +1,24 @@ +=== tests/cases/compiler/stringIncludes.ts === + +var includes: boolean; +>includes : boolean + +includes = "abcde".includes("cd"); +>includes = "abcde".includes("cd") : boolean +>includes : boolean +>"abcde".includes("cd") : boolean +>"abcde".includes : (searchString: string, position?: number) => boolean +>"abcde" : string +>includes : (searchString: string, position?: number) => boolean +>"cd" : string + +includes = "abcde".includes("cd", 2); +>includes = "abcde".includes("cd", 2) : boolean +>includes : boolean +>"abcde".includes("cd", 2) : boolean +>"abcde".includes : (searchString: string, position?: number) => boolean +>"abcde" : string +>includes : (searchString: string, position?: number) => boolean +>"cd" : string +>2 : number + diff --git a/tests/cases/compiler/stringIncludes.ts b/tests/cases/compiler/stringIncludes.ts new file mode 100644 index 00000000000..8196cafa3ed --- /dev/null +++ b/tests/cases/compiler/stringIncludes.ts @@ -0,0 +1,5 @@ +//@target: ES6 + +var includes: boolean; +includes = "abcde".includes("cd"); +includes = "abcde".includes("cd", 2); \ No newline at end of file From 05bc4fecb1778c79262505be54a0b095a66b33b2 Mon Sep 17 00:00:00 2001 From: Jason Freeman Date: Mon, 20 Jul 2015 13:40:03 -0700 Subject: [PATCH 64/64] Address PR feedback --- src/compiler/checker.ts | 26 +++++++++----------------- src/compiler/types.ts | 2 -- 2 files changed, 9 insertions(+), 19 deletions(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 7281d0d6059..c8b558e91d4 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -60,18 +60,8 @@ namespace ts { getDiagnostics, getGlobalDiagnostics, - // Get the narrowed type of symbol at given location instead of just getting - // the type of the symbol. - // eg. - // function foo(a: string | number) { - // if (typeof a === "string") { - // a/**/ - // } - // } - // getTypeOfSymbol for a would return type of parameter symbol string | number - // Unless we provide location /**/, checker wouldn't know how to narrow the type - // By using getNarrowedTypeOfSymbol would return string since it would be able to narrow - // it by typeguard in the if true condition + // The language service will always care about the narrowed type of a symbol, because that is + // the type the language says the symbol should have. getTypeOfSymbolAtLocation: getNarrowedTypeOfSymbol, getDeclaredTypeOfSymbol, getPropertiesOfType, @@ -215,7 +205,9 @@ namespace ts { let assignableRelation: Map = {}; let identityRelation: Map = {}; - enum TypeSystemPropertyName { + type TypeSystemEntity = Symbol | Type | Signature; + + const enum TypeSystemPropertyName { Type, ResolvedBaseConstructorType, DeclaredType, @@ -2242,18 +2234,18 @@ namespace ts { if (propertyName === TypeSystemPropertyName.Type) { return getSymbolLinks(target).type; } - else if (propertyName === TypeSystemPropertyName.DeclaredType) { + if (propertyName === TypeSystemPropertyName.DeclaredType) { return getSymbolLinks(target).declaredType; } - else if (propertyName === TypeSystemPropertyName.ResolvedBaseConstructorType) { + if (propertyName === TypeSystemPropertyName.ResolvedBaseConstructorType) { Debug.assert(!!((target).flags & TypeFlags.Class)); return (target).resolvedBaseConstructorType; } - else if (propertyName === TypeSystemPropertyName.ResolvedReturnType) { + if (propertyName === TypeSystemPropertyName.ResolvedReturnType) { return (target).resolvedReturnType; } - Debug.fail("Unhandled TypeSystemObjectKind"); + Debug.fail("Unhandled TypeSystemPropertyName " + propertyName); } // Pop an entry from the type resolution stack and return its associated result value. The result value will diff --git a/src/compiler/types.ts b/src/compiler/types.ts index edaf940e2fc..f1b476d11b4 100644 --- a/src/compiler/types.ts +++ b/src/compiler/types.ts @@ -1904,8 +1904,6 @@ namespace ts { isolatedSignatureType?: ObjectType; // A manufactured type that just contains the signature for purposes of signature comparison } - export type TypeSystemEntity = Symbol | Type | Signature; - export const enum IndexKind { String, Number,