From 9d3907ffbe9f35f17616850188f3d167f01c7a14 Mon Sep 17 00:00:00 2001 From: Daniel Rosenwasser Date: Tue, 1 Sep 2015 16:09:44 -0700 Subject: [PATCH 01/28] Added declaration option to empty destructuring tests. --- .../es6/destructuring/emptyArrayBindingPatternParameter01.ts | 2 +- .../es6/destructuring/emptyArrayBindingPatternParameter02.ts | 2 +- .../es6/destructuring/emptyArrayBindingPatternParameter03.ts | 2 +- .../es6/destructuring/emptyArrayBindingPatternParameter04.ts | 2 +- .../es6/destructuring/emptyAssignmentPatterns01_ES5.ts | 1 + .../es6/destructuring/emptyAssignmentPatterns01_ES6.ts | 1 + .../es6/destructuring/emptyAssignmentPatterns02_ES5.ts | 1 + .../es6/destructuring/emptyAssignmentPatterns02_ES6.ts | 1 + .../es6/destructuring/emptyAssignmentPatterns03_ES5.ts | 1 + .../es6/destructuring/emptyAssignmentPatterns03_ES6.ts | 1 + .../es6/destructuring/emptyAssignmentPatterns04_ES5.ts | 1 + .../es6/destructuring/emptyAssignmentPatterns04_ES6.ts | 1 + .../es6/destructuring/emptyObjectBindingPatternParameter01.ts | 2 +- .../es6/destructuring/emptyObjectBindingPatternParameter02.ts | 2 +- .../es6/destructuring/emptyObjectBindingPatternParameter03.ts | 2 +- .../es6/destructuring/emptyObjectBindingPatternParameter04.ts | 2 +- 16 files changed, 16 insertions(+), 8 deletions(-) diff --git a/tests/cases/conformance/es6/destructuring/emptyArrayBindingPatternParameter01.ts b/tests/cases/conformance/es6/destructuring/emptyArrayBindingPatternParameter01.ts index 64b198b0916..90e25765847 100644 --- a/tests/cases/conformance/es6/destructuring/emptyArrayBindingPatternParameter01.ts +++ b/tests/cases/conformance/es6/destructuring/emptyArrayBindingPatternParameter01.ts @@ -1,4 +1,4 @@ - +// @declaration: true function f([]) { var x, y, z; diff --git a/tests/cases/conformance/es6/destructuring/emptyArrayBindingPatternParameter02.ts b/tests/cases/conformance/es6/destructuring/emptyArrayBindingPatternParameter02.ts index 39663a4bed7..e9e99c6d0eb 100644 --- a/tests/cases/conformance/es6/destructuring/emptyArrayBindingPatternParameter02.ts +++ b/tests/cases/conformance/es6/destructuring/emptyArrayBindingPatternParameter02.ts @@ -1,4 +1,4 @@ - +// @declaration: true function f(a, []) { var x, y, z; diff --git a/tests/cases/conformance/es6/destructuring/emptyArrayBindingPatternParameter03.ts b/tests/cases/conformance/es6/destructuring/emptyArrayBindingPatternParameter03.ts index 39663a4bed7..e9e99c6d0eb 100644 --- a/tests/cases/conformance/es6/destructuring/emptyArrayBindingPatternParameter03.ts +++ b/tests/cases/conformance/es6/destructuring/emptyArrayBindingPatternParameter03.ts @@ -1,4 +1,4 @@ - +// @declaration: true function f(a, []) { var x, y, z; diff --git a/tests/cases/conformance/es6/destructuring/emptyArrayBindingPatternParameter04.ts b/tests/cases/conformance/es6/destructuring/emptyArrayBindingPatternParameter04.ts index 313d4fe6708..7f57c6a6acf 100644 --- a/tests/cases/conformance/es6/destructuring/emptyArrayBindingPatternParameter04.ts +++ b/tests/cases/conformance/es6/destructuring/emptyArrayBindingPatternParameter04.ts @@ -1,4 +1,4 @@ - +// @declaration: true function f([] = [1,2,3,4]) { var x, y, z; diff --git a/tests/cases/conformance/es6/destructuring/emptyAssignmentPatterns01_ES5.ts b/tests/cases/conformance/es6/destructuring/emptyAssignmentPatterns01_ES5.ts index dd10e552615..44175dbb63a 100644 --- a/tests/cases/conformance/es6/destructuring/emptyAssignmentPatterns01_ES5.ts +++ b/tests/cases/conformance/es6/destructuring/emptyAssignmentPatterns01_ES5.ts @@ -1,4 +1,5 @@ // @target: es5 +// @declaration: true var a: any; diff --git a/tests/cases/conformance/es6/destructuring/emptyAssignmentPatterns01_ES6.ts b/tests/cases/conformance/es6/destructuring/emptyAssignmentPatterns01_ES6.ts index 043f0cf1108..4f367ee8853 100644 --- a/tests/cases/conformance/es6/destructuring/emptyAssignmentPatterns01_ES6.ts +++ b/tests/cases/conformance/es6/destructuring/emptyAssignmentPatterns01_ES6.ts @@ -1,4 +1,5 @@ // @target: es6 +// @declaration: true var a: any; diff --git a/tests/cases/conformance/es6/destructuring/emptyAssignmentPatterns02_ES5.ts b/tests/cases/conformance/es6/destructuring/emptyAssignmentPatterns02_ES5.ts index 60fe89758d6..1d291425e67 100644 --- a/tests/cases/conformance/es6/destructuring/emptyAssignmentPatterns02_ES5.ts +++ b/tests/cases/conformance/es6/destructuring/emptyAssignmentPatterns02_ES5.ts @@ -1,4 +1,5 @@ // @target: es5 +// @declaration: true var a: any; let x, y, z, a1, a2, a3; diff --git a/tests/cases/conformance/es6/destructuring/emptyAssignmentPatterns02_ES6.ts b/tests/cases/conformance/es6/destructuring/emptyAssignmentPatterns02_ES6.ts index 295401545d4..b156883f7d2 100644 --- a/tests/cases/conformance/es6/destructuring/emptyAssignmentPatterns02_ES6.ts +++ b/tests/cases/conformance/es6/destructuring/emptyAssignmentPatterns02_ES6.ts @@ -1,4 +1,5 @@ // @target: es6 +// @declaration: true var a: any; let x, y, z, a1, a2, a3; diff --git a/tests/cases/conformance/es6/destructuring/emptyAssignmentPatterns03_ES5.ts b/tests/cases/conformance/es6/destructuring/emptyAssignmentPatterns03_ES5.ts index 080c828ad62..dbe79355cd8 100644 --- a/tests/cases/conformance/es6/destructuring/emptyAssignmentPatterns03_ES5.ts +++ b/tests/cases/conformance/es6/destructuring/emptyAssignmentPatterns03_ES5.ts @@ -1,4 +1,5 @@ // @target: es5 +// @declaration: true var a: any; diff --git a/tests/cases/conformance/es6/destructuring/emptyAssignmentPatterns03_ES6.ts b/tests/cases/conformance/es6/destructuring/emptyAssignmentPatterns03_ES6.ts index 10d67254cd8..d86f01f5c79 100644 --- a/tests/cases/conformance/es6/destructuring/emptyAssignmentPatterns03_ES6.ts +++ b/tests/cases/conformance/es6/destructuring/emptyAssignmentPatterns03_ES6.ts @@ -1,4 +1,5 @@ // @target: es6 +// @declaration: true var a: any; diff --git a/tests/cases/conformance/es6/destructuring/emptyAssignmentPatterns04_ES5.ts b/tests/cases/conformance/es6/destructuring/emptyAssignmentPatterns04_ES5.ts index 0233ddcda70..ac79e87a11c 100644 --- a/tests/cases/conformance/es6/destructuring/emptyAssignmentPatterns04_ES5.ts +++ b/tests/cases/conformance/es6/destructuring/emptyAssignmentPatterns04_ES5.ts @@ -1,4 +1,5 @@ // @target: es5 +// @declaration: true var a: any; let x, y, z, a1, a2, a3; diff --git a/tests/cases/conformance/es6/destructuring/emptyAssignmentPatterns04_ES6.ts b/tests/cases/conformance/es6/destructuring/emptyAssignmentPatterns04_ES6.ts index 3380a56aaa7..25e56c353b9 100644 --- a/tests/cases/conformance/es6/destructuring/emptyAssignmentPatterns04_ES6.ts +++ b/tests/cases/conformance/es6/destructuring/emptyAssignmentPatterns04_ES6.ts @@ -1,4 +1,5 @@ // @target: es6 +// @declaration: true var a: any; let x, y, z, a1, a2, a3; diff --git a/tests/cases/conformance/es6/destructuring/emptyObjectBindingPatternParameter01.ts b/tests/cases/conformance/es6/destructuring/emptyObjectBindingPatternParameter01.ts index 01aa5b54230..270d7f10227 100644 --- a/tests/cases/conformance/es6/destructuring/emptyObjectBindingPatternParameter01.ts +++ b/tests/cases/conformance/es6/destructuring/emptyObjectBindingPatternParameter01.ts @@ -1,4 +1,4 @@ - +// @declaration: true function f({}) { var x, y, z; diff --git a/tests/cases/conformance/es6/destructuring/emptyObjectBindingPatternParameter02.ts b/tests/cases/conformance/es6/destructuring/emptyObjectBindingPatternParameter02.ts index f34503c1152..79d026eac9e 100644 --- a/tests/cases/conformance/es6/destructuring/emptyObjectBindingPatternParameter02.ts +++ b/tests/cases/conformance/es6/destructuring/emptyObjectBindingPatternParameter02.ts @@ -1,4 +1,4 @@ - +// @declaration: true function f(a, {}) { var x, y, z; diff --git a/tests/cases/conformance/es6/destructuring/emptyObjectBindingPatternParameter03.ts b/tests/cases/conformance/es6/destructuring/emptyObjectBindingPatternParameter03.ts index a940c659703..c5d51b20cfa 100644 --- a/tests/cases/conformance/es6/destructuring/emptyObjectBindingPatternParameter03.ts +++ b/tests/cases/conformance/es6/destructuring/emptyObjectBindingPatternParameter03.ts @@ -1,4 +1,4 @@ - +// @declaration: true function f({}, a) { var x, y, z; diff --git a/tests/cases/conformance/es6/destructuring/emptyObjectBindingPatternParameter04.ts b/tests/cases/conformance/es6/destructuring/emptyObjectBindingPatternParameter04.ts index da05e5cb428..0273e174de0 100644 --- a/tests/cases/conformance/es6/destructuring/emptyObjectBindingPatternParameter04.ts +++ b/tests/cases/conformance/es6/destructuring/emptyObjectBindingPatternParameter04.ts @@ -1,4 +1,4 @@ - +// @declaration: true function f({} = {a: 1, b: "2", c: true}) { var x, y, z; From 232e33e8547324dda065402ec9bd94a6ded7a115 Mon Sep 17 00:00:00 2001 From: Daniel Rosenwasser Date: Tue, 1 Sep 2015 17:22:13 -0700 Subject: [PATCH 02/28] Accepted baselines. --- .../emptyArrayBindingPatternParameter01.js | 5 ++++- .../emptyArrayBindingPatternParameter01.symbols | 7 +++---- .../emptyArrayBindingPatternParameter01.types | 1 - .../emptyArrayBindingPatternParameter02.js | 5 ++++- .../emptyArrayBindingPatternParameter02.symbols | 9 ++++----- .../emptyArrayBindingPatternParameter02.types | 1 - .../emptyArrayBindingPatternParameter03.js | 5 ++++- .../emptyArrayBindingPatternParameter03.symbols | 9 ++++----- .../emptyArrayBindingPatternParameter03.types | 1 - .../emptyArrayBindingPatternParameter04.js | 5 ++++- .../emptyArrayBindingPatternParameter04.symbols | 7 +++---- .../emptyArrayBindingPatternParameter04.types | 1 - .../reference/emptyAssignmentPatterns01_ES5.js | 4 ++++ .../reference/emptyAssignmentPatterns01_ES6.js | 4 ++++ .../reference/emptyAssignmentPatterns02_ES5.js | 5 +++++ .../reference/emptyAssignmentPatterns02_ES6.js | 5 +++++ .../reference/emptyAssignmentPatterns03_ES5.js | 4 ++++ .../reference/emptyAssignmentPatterns03_ES6.js | 4 ++++ .../reference/emptyAssignmentPatterns04_ES5.js | 5 +++++ .../reference/emptyAssignmentPatterns04_ES6.js | 5 +++++ .../emptyObjectBindingPatternParameter01.js | 5 ++++- .../emptyObjectBindingPatternParameter01.symbols | 7 +++---- .../emptyObjectBindingPatternParameter01.types | 1 - .../emptyObjectBindingPatternParameter02.js | 5 ++++- .../emptyObjectBindingPatternParameter02.symbols | 9 ++++----- .../emptyObjectBindingPatternParameter02.types | 1 - .../emptyObjectBindingPatternParameter03.js | 5 ++++- .../emptyObjectBindingPatternParameter03.symbols | 9 ++++----- .../emptyObjectBindingPatternParameter03.types | 1 - .../emptyObjectBindingPatternParameter04.js | 9 ++++++++- .../emptyObjectBindingPatternParameter04.symbols | 13 ++++++------- .../emptyObjectBindingPatternParameter04.types | 1 - 32 files changed, 103 insertions(+), 55 deletions(-) diff --git a/tests/baselines/reference/emptyArrayBindingPatternParameter01.js b/tests/baselines/reference/emptyArrayBindingPatternParameter01.js index 5723c74f117..1eb76741e84 100644 --- a/tests/baselines/reference/emptyArrayBindingPatternParameter01.js +++ b/tests/baselines/reference/emptyArrayBindingPatternParameter01.js @@ -1,6 +1,5 @@ //// [emptyArrayBindingPatternParameter01.ts] - function f([]) { var x, y, z; } @@ -9,3 +8,7 @@ function f([]) { function f(_a) { var x, y, z; } + + +//// [emptyArrayBindingPatternParameter01.d.ts] +declare function f([]: any[]): void; diff --git a/tests/baselines/reference/emptyArrayBindingPatternParameter01.symbols b/tests/baselines/reference/emptyArrayBindingPatternParameter01.symbols index f5089ce5850..e1630be639b 100644 --- a/tests/baselines/reference/emptyArrayBindingPatternParameter01.symbols +++ b/tests/baselines/reference/emptyArrayBindingPatternParameter01.symbols @@ -1,11 +1,10 @@ === tests/cases/conformance/es6/destructuring/emptyArrayBindingPatternParameter01.ts === - function f([]) { >f : Symbol(f, Decl(emptyArrayBindingPatternParameter01.ts, 0, 0)) 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)) +>x : Symbol(x, Decl(emptyArrayBindingPatternParameter01.ts, 2, 7)) +>y : Symbol(y, Decl(emptyArrayBindingPatternParameter01.ts, 2, 10)) +>z : Symbol(z, Decl(emptyArrayBindingPatternParameter01.ts, 2, 13)) } diff --git a/tests/baselines/reference/emptyArrayBindingPatternParameter01.types b/tests/baselines/reference/emptyArrayBindingPatternParameter01.types index 7ef40d52d59..4ca0b892ecf 100644 --- a/tests/baselines/reference/emptyArrayBindingPatternParameter01.types +++ b/tests/baselines/reference/emptyArrayBindingPatternParameter01.types @@ -1,6 +1,5 @@ === tests/cases/conformance/es6/destructuring/emptyArrayBindingPatternParameter01.ts === - function f([]) { >f : ([]: any[]) => void diff --git a/tests/baselines/reference/emptyArrayBindingPatternParameter02.js b/tests/baselines/reference/emptyArrayBindingPatternParameter02.js index dbd86e843a8..d6dda16e12f 100644 --- a/tests/baselines/reference/emptyArrayBindingPatternParameter02.js +++ b/tests/baselines/reference/emptyArrayBindingPatternParameter02.js @@ -1,6 +1,5 @@ //// [emptyArrayBindingPatternParameter02.ts] - function f(a, []) { var x, y, z; } @@ -9,3 +8,7 @@ function f(a, []) { function f(a, _a) { var x, y, z; } + + +//// [emptyArrayBindingPatternParameter02.d.ts] +declare function f(a: any, []: any[]): void; diff --git a/tests/baselines/reference/emptyArrayBindingPatternParameter02.symbols b/tests/baselines/reference/emptyArrayBindingPatternParameter02.symbols index 48cdcfaf93d..3289c06f962 100644 --- a/tests/baselines/reference/emptyArrayBindingPatternParameter02.symbols +++ b/tests/baselines/reference/emptyArrayBindingPatternParameter02.symbols @@ -1,12 +1,11 @@ === tests/cases/conformance/es6/destructuring/emptyArrayBindingPatternParameter02.ts === - function f(a, []) { >f : Symbol(f, Decl(emptyArrayBindingPatternParameter02.ts, 0, 0)) ->a : Symbol(a, Decl(emptyArrayBindingPatternParameter02.ts, 2, 11)) +>a : Symbol(a, Decl(emptyArrayBindingPatternParameter02.ts, 1, 11)) var x, y, z; ->x : Symbol(x, Decl(emptyArrayBindingPatternParameter02.ts, 3, 7)) ->y : Symbol(y, Decl(emptyArrayBindingPatternParameter02.ts, 3, 10)) ->z : Symbol(z, Decl(emptyArrayBindingPatternParameter02.ts, 3, 13)) +>x : Symbol(x, Decl(emptyArrayBindingPatternParameter02.ts, 2, 7)) +>y : Symbol(y, Decl(emptyArrayBindingPatternParameter02.ts, 2, 10)) +>z : Symbol(z, Decl(emptyArrayBindingPatternParameter02.ts, 2, 13)) } diff --git a/tests/baselines/reference/emptyArrayBindingPatternParameter02.types b/tests/baselines/reference/emptyArrayBindingPatternParameter02.types index a58fe6b91d3..34d9e7dde6b 100644 --- a/tests/baselines/reference/emptyArrayBindingPatternParameter02.types +++ b/tests/baselines/reference/emptyArrayBindingPatternParameter02.types @@ -1,6 +1,5 @@ === tests/cases/conformance/es6/destructuring/emptyArrayBindingPatternParameter02.ts === - function f(a, []) { >f : (a: any, []: any[]) => void >a : any diff --git a/tests/baselines/reference/emptyArrayBindingPatternParameter03.js b/tests/baselines/reference/emptyArrayBindingPatternParameter03.js index e2c3f7196e6..4867b39ac2f 100644 --- a/tests/baselines/reference/emptyArrayBindingPatternParameter03.js +++ b/tests/baselines/reference/emptyArrayBindingPatternParameter03.js @@ -1,6 +1,5 @@ //// [emptyArrayBindingPatternParameter03.ts] - function f(a, []) { var x, y, z; } @@ -9,3 +8,7 @@ function f(a, []) { function f(a, _a) { var x, y, z; } + + +//// [emptyArrayBindingPatternParameter03.d.ts] +declare function f(a: any, []: any[]): void; diff --git a/tests/baselines/reference/emptyArrayBindingPatternParameter03.symbols b/tests/baselines/reference/emptyArrayBindingPatternParameter03.symbols index d3ec078df78..86a95687310 100644 --- a/tests/baselines/reference/emptyArrayBindingPatternParameter03.symbols +++ b/tests/baselines/reference/emptyArrayBindingPatternParameter03.symbols @@ -1,12 +1,11 @@ === tests/cases/conformance/es6/destructuring/emptyArrayBindingPatternParameter03.ts === - function f(a, []) { >f : Symbol(f, Decl(emptyArrayBindingPatternParameter03.ts, 0, 0)) ->a : Symbol(a, Decl(emptyArrayBindingPatternParameter03.ts, 2, 11)) +>a : Symbol(a, Decl(emptyArrayBindingPatternParameter03.ts, 1, 11)) var x, y, z; ->x : Symbol(x, Decl(emptyArrayBindingPatternParameter03.ts, 3, 7)) ->y : Symbol(y, Decl(emptyArrayBindingPatternParameter03.ts, 3, 10)) ->z : Symbol(z, Decl(emptyArrayBindingPatternParameter03.ts, 3, 13)) +>x : Symbol(x, Decl(emptyArrayBindingPatternParameter03.ts, 2, 7)) +>y : Symbol(y, Decl(emptyArrayBindingPatternParameter03.ts, 2, 10)) +>z : Symbol(z, Decl(emptyArrayBindingPatternParameter03.ts, 2, 13)) } diff --git a/tests/baselines/reference/emptyArrayBindingPatternParameter03.types b/tests/baselines/reference/emptyArrayBindingPatternParameter03.types index 43f0af63ace..1c5579ebe36 100644 --- a/tests/baselines/reference/emptyArrayBindingPatternParameter03.types +++ b/tests/baselines/reference/emptyArrayBindingPatternParameter03.types @@ -1,6 +1,5 @@ === tests/cases/conformance/es6/destructuring/emptyArrayBindingPatternParameter03.ts === - function f(a, []) { >f : (a: any, []: any[]) => void >a : any diff --git a/tests/baselines/reference/emptyArrayBindingPatternParameter04.js b/tests/baselines/reference/emptyArrayBindingPatternParameter04.js index e0715499ffe..c9819c88f40 100644 --- a/tests/baselines/reference/emptyArrayBindingPatternParameter04.js +++ b/tests/baselines/reference/emptyArrayBindingPatternParameter04.js @@ -1,6 +1,5 @@ //// [emptyArrayBindingPatternParameter04.ts] - function f([] = [1,2,3,4]) { var x, y, z; } @@ -10,3 +9,7 @@ function f(_a) { var _a = [1, 2, 3, 4]; var x, y, z; } + + +//// [emptyArrayBindingPatternParameter04.d.ts] +declare function f([]?: number[]): void; diff --git a/tests/baselines/reference/emptyArrayBindingPatternParameter04.symbols b/tests/baselines/reference/emptyArrayBindingPatternParameter04.symbols index bb76a2c5925..9f4c9bae0c6 100644 --- a/tests/baselines/reference/emptyArrayBindingPatternParameter04.symbols +++ b/tests/baselines/reference/emptyArrayBindingPatternParameter04.symbols @@ -1,11 +1,10 @@ === tests/cases/conformance/es6/destructuring/emptyArrayBindingPatternParameter04.ts === - function f([] = [1,2,3,4]) { >f : Symbol(f, Decl(emptyArrayBindingPatternParameter04.ts, 0, 0)) var x, y, z; ->x : Symbol(x, Decl(emptyArrayBindingPatternParameter04.ts, 3, 7)) ->y : Symbol(y, Decl(emptyArrayBindingPatternParameter04.ts, 3, 10)) ->z : Symbol(z, Decl(emptyArrayBindingPatternParameter04.ts, 3, 13)) +>x : Symbol(x, Decl(emptyArrayBindingPatternParameter04.ts, 2, 7)) +>y : Symbol(y, Decl(emptyArrayBindingPatternParameter04.ts, 2, 10)) +>z : Symbol(z, Decl(emptyArrayBindingPatternParameter04.ts, 2, 13)) } diff --git a/tests/baselines/reference/emptyArrayBindingPatternParameter04.types b/tests/baselines/reference/emptyArrayBindingPatternParameter04.types index 6f00a994f7b..834eb41b34d 100644 --- a/tests/baselines/reference/emptyArrayBindingPatternParameter04.types +++ b/tests/baselines/reference/emptyArrayBindingPatternParameter04.types @@ -1,6 +1,5 @@ === tests/cases/conformance/es6/destructuring/emptyArrayBindingPatternParameter04.ts === - function f([] = [1,2,3,4]) { >f : ([]?: number[]) => void >[1,2,3,4] : number[] diff --git a/tests/baselines/reference/emptyAssignmentPatterns01_ES5.js b/tests/baselines/reference/emptyAssignmentPatterns01_ES5.js index b89db88e5e5..fe0a642c51e 100644 --- a/tests/baselines/reference/emptyAssignmentPatterns01_ES5.js +++ b/tests/baselines/reference/emptyAssignmentPatterns01_ES5.js @@ -9,3 +9,7 @@ var a: any; var a; (a); (a); + + +//// [emptyAssignmentPatterns01_ES5.d.ts] +declare var a: any; diff --git a/tests/baselines/reference/emptyAssignmentPatterns01_ES6.js b/tests/baselines/reference/emptyAssignmentPatterns01_ES6.js index fe311ac9061..4cf33452d98 100644 --- a/tests/baselines/reference/emptyAssignmentPatterns01_ES6.js +++ b/tests/baselines/reference/emptyAssignmentPatterns01_ES6.js @@ -9,3 +9,7 @@ var a: any; var a; ({} = a); ([] = a); + + +//// [emptyAssignmentPatterns01_ES6.d.ts] +declare var a: any; diff --git a/tests/baselines/reference/emptyAssignmentPatterns02_ES5.js b/tests/baselines/reference/emptyAssignmentPatterns02_ES5.js index 7b9f1f402f9..27a0b5f9b61 100644 --- a/tests/baselines/reference/emptyAssignmentPatterns02_ES5.js +++ b/tests/baselines/reference/emptyAssignmentPatterns02_ES5.js @@ -11,3 +11,8 @@ var a; var x, y, z, a1, a2, a3; ((x = a.x, y = a.y, z = a.z, a)); ((a1 = a[0], a2 = a[1], a3 = a[2], a)); + + +//// [emptyAssignmentPatterns02_ES5.d.ts] +declare var a: any; +declare let x: any, y: any, z: any, a1: any, a2: any, a3: any; diff --git a/tests/baselines/reference/emptyAssignmentPatterns02_ES6.js b/tests/baselines/reference/emptyAssignmentPatterns02_ES6.js index e9783c7e57d..493246c9473 100644 --- a/tests/baselines/reference/emptyAssignmentPatterns02_ES6.js +++ b/tests/baselines/reference/emptyAssignmentPatterns02_ES6.js @@ -11,3 +11,8 @@ var a; let x, y, z, a1, a2, a3; ({} = { x, y, z } = a); ([] = [a1, a2, a3] = a); + + +//// [emptyAssignmentPatterns02_ES6.d.ts] +declare var a: any; +declare let x: any, y: any, z: any, a1: any, a2: any, a3: any; diff --git a/tests/baselines/reference/emptyAssignmentPatterns03_ES5.js b/tests/baselines/reference/emptyAssignmentPatterns03_ES5.js index d9ff8ba9ede..adaad2e3b63 100644 --- a/tests/baselines/reference/emptyAssignmentPatterns03_ES5.js +++ b/tests/baselines/reference/emptyAssignmentPatterns03_ES5.js @@ -9,3 +9,7 @@ var a: any; var a; (a); (a); + + +//// [emptyAssignmentPatterns03_ES5.d.ts] +declare var a: any; diff --git a/tests/baselines/reference/emptyAssignmentPatterns03_ES6.js b/tests/baselines/reference/emptyAssignmentPatterns03_ES6.js index 95bfdfefa52..8050cc1e47a 100644 --- a/tests/baselines/reference/emptyAssignmentPatterns03_ES6.js +++ b/tests/baselines/reference/emptyAssignmentPatterns03_ES6.js @@ -9,3 +9,7 @@ var a: any; var a; ({} = {} = a); ([] = [] = a); + + +//// [emptyAssignmentPatterns03_ES6.d.ts] +declare var a: any; diff --git a/tests/baselines/reference/emptyAssignmentPatterns04_ES5.js b/tests/baselines/reference/emptyAssignmentPatterns04_ES5.js index 7e342d08e39..e6b3cc7e3f2 100644 --- a/tests/baselines/reference/emptyAssignmentPatterns04_ES5.js +++ b/tests/baselines/reference/emptyAssignmentPatterns04_ES5.js @@ -12,3 +12,8 @@ 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; + + +//// [emptyAssignmentPatterns04_ES5.d.ts] +declare var a: any; +declare let x: any, y: any, z: any, a1: any, a2: any, a3: any; diff --git a/tests/baselines/reference/emptyAssignmentPatterns04_ES6.js b/tests/baselines/reference/emptyAssignmentPatterns04_ES6.js index eabc2678c05..fb52975d6d1 100644 --- a/tests/baselines/reference/emptyAssignmentPatterns04_ES6.js +++ b/tests/baselines/reference/emptyAssignmentPatterns04_ES6.js @@ -11,3 +11,8 @@ var a; let x, y, z, a1, a2, a3; ({ x, y, z } = {} = a); ([a1, a2, a3] = [] = a); + + +//// [emptyAssignmentPatterns04_ES6.d.ts] +declare var a: any; +declare let x: any, y: any, z: any, a1: any, a2: any, a3: any; diff --git a/tests/baselines/reference/emptyObjectBindingPatternParameter01.js b/tests/baselines/reference/emptyObjectBindingPatternParameter01.js index 28cc30d2a0b..6a8ec808cd0 100644 --- a/tests/baselines/reference/emptyObjectBindingPatternParameter01.js +++ b/tests/baselines/reference/emptyObjectBindingPatternParameter01.js @@ -1,6 +1,5 @@ //// [emptyObjectBindingPatternParameter01.ts] - function f({}) { var x, y, z; } @@ -9,3 +8,7 @@ function f({}) { function f(_a) { var x, y, z; } + + +//// [emptyObjectBindingPatternParameter01.d.ts] +declare function f({}: {}): void; diff --git a/tests/baselines/reference/emptyObjectBindingPatternParameter01.symbols b/tests/baselines/reference/emptyObjectBindingPatternParameter01.symbols index 98829df994f..3ef5898c29a 100644 --- a/tests/baselines/reference/emptyObjectBindingPatternParameter01.symbols +++ b/tests/baselines/reference/emptyObjectBindingPatternParameter01.symbols @@ -1,11 +1,10 @@ === tests/cases/conformance/es6/destructuring/emptyObjectBindingPatternParameter01.ts === - function f({}) { >f : Symbol(f, Decl(emptyObjectBindingPatternParameter01.ts, 0, 0)) var x, y, z; ->x : Symbol(x, Decl(emptyObjectBindingPatternParameter01.ts, 3, 7)) ->y : Symbol(y, Decl(emptyObjectBindingPatternParameter01.ts, 3, 10)) ->z : Symbol(z, Decl(emptyObjectBindingPatternParameter01.ts, 3, 13)) +>x : Symbol(x, Decl(emptyObjectBindingPatternParameter01.ts, 2, 7)) +>y : Symbol(y, Decl(emptyObjectBindingPatternParameter01.ts, 2, 10)) +>z : Symbol(z, Decl(emptyObjectBindingPatternParameter01.ts, 2, 13)) } diff --git a/tests/baselines/reference/emptyObjectBindingPatternParameter01.types b/tests/baselines/reference/emptyObjectBindingPatternParameter01.types index c46569ea770..05ddc54719c 100644 --- a/tests/baselines/reference/emptyObjectBindingPatternParameter01.types +++ b/tests/baselines/reference/emptyObjectBindingPatternParameter01.types @@ -1,6 +1,5 @@ === tests/cases/conformance/es6/destructuring/emptyObjectBindingPatternParameter01.ts === - function f({}) { >f : ({}: {}) => void diff --git a/tests/baselines/reference/emptyObjectBindingPatternParameter02.js b/tests/baselines/reference/emptyObjectBindingPatternParameter02.js index 8488428ea51..be2bdcab298 100644 --- a/tests/baselines/reference/emptyObjectBindingPatternParameter02.js +++ b/tests/baselines/reference/emptyObjectBindingPatternParameter02.js @@ -1,6 +1,5 @@ //// [emptyObjectBindingPatternParameter02.ts] - function f(a, {}) { var x, y, z; } @@ -9,3 +8,7 @@ function f(a, {}) { function f(a, _a) { var x, y, z; } + + +//// [emptyObjectBindingPatternParameter02.d.ts] +declare function f(a: any, {}: {}): void; diff --git a/tests/baselines/reference/emptyObjectBindingPatternParameter02.symbols b/tests/baselines/reference/emptyObjectBindingPatternParameter02.symbols index fb0fa946b6f..d5bb4f292aa 100644 --- a/tests/baselines/reference/emptyObjectBindingPatternParameter02.symbols +++ b/tests/baselines/reference/emptyObjectBindingPatternParameter02.symbols @@ -1,12 +1,11 @@ === tests/cases/conformance/es6/destructuring/emptyObjectBindingPatternParameter02.ts === - function f(a, {}) { >f : Symbol(f, Decl(emptyObjectBindingPatternParameter02.ts, 0, 0)) ->a : Symbol(a, Decl(emptyObjectBindingPatternParameter02.ts, 2, 11)) +>a : Symbol(a, Decl(emptyObjectBindingPatternParameter02.ts, 1, 11)) var x, y, z; ->x : Symbol(x, Decl(emptyObjectBindingPatternParameter02.ts, 3, 7)) ->y : Symbol(y, Decl(emptyObjectBindingPatternParameter02.ts, 3, 10)) ->z : Symbol(z, Decl(emptyObjectBindingPatternParameter02.ts, 3, 13)) +>x : Symbol(x, Decl(emptyObjectBindingPatternParameter02.ts, 2, 7)) +>y : Symbol(y, Decl(emptyObjectBindingPatternParameter02.ts, 2, 10)) +>z : Symbol(z, Decl(emptyObjectBindingPatternParameter02.ts, 2, 13)) } diff --git a/tests/baselines/reference/emptyObjectBindingPatternParameter02.types b/tests/baselines/reference/emptyObjectBindingPatternParameter02.types index 0a77fac8588..e2b485538e6 100644 --- a/tests/baselines/reference/emptyObjectBindingPatternParameter02.types +++ b/tests/baselines/reference/emptyObjectBindingPatternParameter02.types @@ -1,6 +1,5 @@ === tests/cases/conformance/es6/destructuring/emptyObjectBindingPatternParameter02.ts === - function f(a, {}) { >f : (a: any, {}: {}) => void >a : any diff --git a/tests/baselines/reference/emptyObjectBindingPatternParameter03.js b/tests/baselines/reference/emptyObjectBindingPatternParameter03.js index 0279744e386..320bfe2d0df 100644 --- a/tests/baselines/reference/emptyObjectBindingPatternParameter03.js +++ b/tests/baselines/reference/emptyObjectBindingPatternParameter03.js @@ -1,6 +1,5 @@ //// [emptyObjectBindingPatternParameter03.ts] - function f({}, a) { var x, y, z; } @@ -9,3 +8,7 @@ function f({}, a) { function f(_a, a) { var x, y, z; } + + +//// [emptyObjectBindingPatternParameter03.d.ts] +declare function f({}: {}, a: any): void; diff --git a/tests/baselines/reference/emptyObjectBindingPatternParameter03.symbols b/tests/baselines/reference/emptyObjectBindingPatternParameter03.symbols index 4e658e21ccf..82a1bcee75b 100644 --- a/tests/baselines/reference/emptyObjectBindingPatternParameter03.symbols +++ b/tests/baselines/reference/emptyObjectBindingPatternParameter03.symbols @@ -1,12 +1,11 @@ === tests/cases/conformance/es6/destructuring/emptyObjectBindingPatternParameter03.ts === - function f({}, a) { >f : Symbol(f, Decl(emptyObjectBindingPatternParameter03.ts, 0, 0)) ->a : Symbol(a, Decl(emptyObjectBindingPatternParameter03.ts, 2, 14)) +>a : Symbol(a, Decl(emptyObjectBindingPatternParameter03.ts, 1, 14)) var x, y, z; ->x : Symbol(x, Decl(emptyObjectBindingPatternParameter03.ts, 3, 7)) ->y : Symbol(y, Decl(emptyObjectBindingPatternParameter03.ts, 3, 10)) ->z : Symbol(z, Decl(emptyObjectBindingPatternParameter03.ts, 3, 13)) +>x : Symbol(x, Decl(emptyObjectBindingPatternParameter03.ts, 2, 7)) +>y : Symbol(y, Decl(emptyObjectBindingPatternParameter03.ts, 2, 10)) +>z : Symbol(z, Decl(emptyObjectBindingPatternParameter03.ts, 2, 13)) } diff --git a/tests/baselines/reference/emptyObjectBindingPatternParameter03.types b/tests/baselines/reference/emptyObjectBindingPatternParameter03.types index 873c748dd9b..0f89702402a 100644 --- a/tests/baselines/reference/emptyObjectBindingPatternParameter03.types +++ b/tests/baselines/reference/emptyObjectBindingPatternParameter03.types @@ -1,6 +1,5 @@ === tests/cases/conformance/es6/destructuring/emptyObjectBindingPatternParameter03.ts === - function f({}, a) { >f : ({}: {}, a: any) => void >a : any diff --git a/tests/baselines/reference/emptyObjectBindingPatternParameter04.js b/tests/baselines/reference/emptyObjectBindingPatternParameter04.js index fc3e41d0709..8c128bb806e 100644 --- a/tests/baselines/reference/emptyObjectBindingPatternParameter04.js +++ b/tests/baselines/reference/emptyObjectBindingPatternParameter04.js @@ -1,6 +1,5 @@ //// [emptyObjectBindingPatternParameter04.ts] - function f({} = {a: 1, b: "2", c: true}) { var x, y, z; } @@ -10,3 +9,11 @@ function f(_a) { var _a = { a: 1, b: "2", c: true }; var x, y, z; } + + +//// [emptyObjectBindingPatternParameter04.d.ts] +declare function f({}?: { + a: number; + b: string; + c: boolean; +}): void; diff --git a/tests/baselines/reference/emptyObjectBindingPatternParameter04.symbols b/tests/baselines/reference/emptyObjectBindingPatternParameter04.symbols index 9922d4cd074..1b594d9e38a 100644 --- a/tests/baselines/reference/emptyObjectBindingPatternParameter04.symbols +++ b/tests/baselines/reference/emptyObjectBindingPatternParameter04.symbols @@ -1,14 +1,13 @@ === tests/cases/conformance/es6/destructuring/emptyObjectBindingPatternParameter04.ts === - function f({} = {a: 1, b: "2", c: true}) { >f : Symbol(f, Decl(emptyObjectBindingPatternParameter04.ts, 0, 0)) ->a : Symbol(a, Decl(emptyObjectBindingPatternParameter04.ts, 2, 17)) ->b : Symbol(b, Decl(emptyObjectBindingPatternParameter04.ts, 2, 22)) ->c : Symbol(c, Decl(emptyObjectBindingPatternParameter04.ts, 2, 30)) +>a : Symbol(a, Decl(emptyObjectBindingPatternParameter04.ts, 1, 17)) +>b : Symbol(b, Decl(emptyObjectBindingPatternParameter04.ts, 1, 22)) +>c : Symbol(c, Decl(emptyObjectBindingPatternParameter04.ts, 1, 30)) var x, y, z; ->x : Symbol(x, Decl(emptyObjectBindingPatternParameter04.ts, 3, 7)) ->y : Symbol(y, Decl(emptyObjectBindingPatternParameter04.ts, 3, 10)) ->z : Symbol(z, Decl(emptyObjectBindingPatternParameter04.ts, 3, 13)) +>x : Symbol(x, Decl(emptyObjectBindingPatternParameter04.ts, 2, 7)) +>y : Symbol(y, Decl(emptyObjectBindingPatternParameter04.ts, 2, 10)) +>z : Symbol(z, Decl(emptyObjectBindingPatternParameter04.ts, 2, 13)) } diff --git a/tests/baselines/reference/emptyObjectBindingPatternParameter04.types b/tests/baselines/reference/emptyObjectBindingPatternParameter04.types index 5ee32d422a9..fddc23e854a 100644 --- a/tests/baselines/reference/emptyObjectBindingPatternParameter04.types +++ b/tests/baselines/reference/emptyObjectBindingPatternParameter04.types @@ -1,6 +1,5 @@ === tests/cases/conformance/es6/destructuring/emptyObjectBindingPatternParameter04.ts === - function f({} = {a: 1, b: "2", c: true}) { >f : ({}?: { a: number; b: string; c: boolean; }) => void >{a: 1, b: "2", c: true} : { a: number; b: string; c: boolean; } From e3657bccff7726777fc230f0a58116fe65bab465 Mon Sep 17 00:00:00 2001 From: Daniel Rosenwasser Date: Tue, 1 Sep 2015 17:36:20 -0700 Subject: [PATCH 03/28] Added tests. --- ...mptyVariableDeclarationBindingPatterns01_ES5.ts | 14 ++++++++++++++ ...mptyVariableDeclarationBindingPatterns01_ES6.ts | 14 ++++++++++++++ ...mptyVariableDeclarationBindingPatterns02_ES5.ts | 12 ++++++++++++ ...mptyVariableDeclarationBindingPatterns02_ES6.ts | 12 ++++++++++++ 4 files changed, 52 insertions(+) create mode 100644 tests/cases/conformance/es6/destructuring/emptyVariableDeclarationBindingPatterns01_ES5.ts create mode 100644 tests/cases/conformance/es6/destructuring/emptyVariableDeclarationBindingPatterns01_ES6.ts create mode 100644 tests/cases/conformance/es6/destructuring/emptyVariableDeclarationBindingPatterns02_ES5.ts create mode 100644 tests/cases/conformance/es6/destructuring/emptyVariableDeclarationBindingPatterns02_ES6.ts diff --git a/tests/cases/conformance/es6/destructuring/emptyVariableDeclarationBindingPatterns01_ES5.ts b/tests/cases/conformance/es6/destructuring/emptyVariableDeclarationBindingPatterns01_ES5.ts new file mode 100644 index 00000000000..50beb289f60 --- /dev/null +++ b/tests/cases/conformance/es6/destructuring/emptyVariableDeclarationBindingPatterns01_ES5.ts @@ -0,0 +1,14 @@ +// @target: es5 +// @declaration: true + +(function () { + var a: any; + + var {} = a; + let {} = a; + const {} = a; + + var [] = a; + let [] = a; + const [] = a; +})(); \ No newline at end of file diff --git a/tests/cases/conformance/es6/destructuring/emptyVariableDeclarationBindingPatterns01_ES6.ts b/tests/cases/conformance/es6/destructuring/emptyVariableDeclarationBindingPatterns01_ES6.ts new file mode 100644 index 00000000000..8fd5beef63b --- /dev/null +++ b/tests/cases/conformance/es6/destructuring/emptyVariableDeclarationBindingPatterns01_ES6.ts @@ -0,0 +1,14 @@ +// @target: es6 +// @declaration: true + +(function () { + var a: any; + + var {} = a; + let {} = a; + const {} = a; + + var [] = a; + let [] = a; + const [] = a; +})(); \ No newline at end of file diff --git a/tests/cases/conformance/es6/destructuring/emptyVariableDeclarationBindingPatterns02_ES5.ts b/tests/cases/conformance/es6/destructuring/emptyVariableDeclarationBindingPatterns02_ES5.ts new file mode 100644 index 00000000000..34c05e1838f --- /dev/null +++ b/tests/cases/conformance/es6/destructuring/emptyVariableDeclarationBindingPatterns02_ES5.ts @@ -0,0 +1,12 @@ +// @target: es5 +// @declaration: true + +(function () { + var {}; + let {}; + const {}; + + var []; + let []; + const []; +})(); \ No newline at end of file diff --git a/tests/cases/conformance/es6/destructuring/emptyVariableDeclarationBindingPatterns02_ES6.ts b/tests/cases/conformance/es6/destructuring/emptyVariableDeclarationBindingPatterns02_ES6.ts new file mode 100644 index 00000000000..3146fec4cb7 --- /dev/null +++ b/tests/cases/conformance/es6/destructuring/emptyVariableDeclarationBindingPatterns02_ES6.ts @@ -0,0 +1,12 @@ +// @target: es6 +// @declaration: true + +(function () { + var {}; + let {}; + const {}; + + var []; + let []; + const []; +})(); \ No newline at end of file From 906634f0a48e5842d633a9e07178269e47a91bbc Mon Sep 17 00:00:00 2001 From: Daniel Rosenwasser Date: Tue, 1 Sep 2015 17:45:47 -0700 Subject: [PATCH 04/28] Accepted baselines. --- ...ariableDeclarationBindingPatterns01_ES5.js | 27 ++++++++++++++++ ...leDeclarationBindingPatterns01_ES5.symbols | 25 +++++++++++++++ ...ableDeclarationBindingPatterns01_ES5.types | 29 +++++++++++++++++ ...ariableDeclarationBindingPatterns01_ES6.js | 27 ++++++++++++++++ ...leDeclarationBindingPatterns01_ES6.symbols | 25 +++++++++++++++ ...ableDeclarationBindingPatterns01_ES6.types | 29 +++++++++++++++++ ...eclarationBindingPatterns02_ES5.errors.txt | 31 +++++++++++++++++++ ...ariableDeclarationBindingPatterns02_ES5.js | 24 ++++++++++++++ ...eclarationBindingPatterns02_ES6.errors.txt | 31 +++++++++++++++++++ ...ariableDeclarationBindingPatterns02_ES6.js | 24 ++++++++++++++ 10 files changed, 272 insertions(+) create mode 100644 tests/baselines/reference/emptyVariableDeclarationBindingPatterns01_ES5.js create mode 100644 tests/baselines/reference/emptyVariableDeclarationBindingPatterns01_ES5.symbols create mode 100644 tests/baselines/reference/emptyVariableDeclarationBindingPatterns01_ES5.types create mode 100644 tests/baselines/reference/emptyVariableDeclarationBindingPatterns01_ES6.js create mode 100644 tests/baselines/reference/emptyVariableDeclarationBindingPatterns01_ES6.symbols create mode 100644 tests/baselines/reference/emptyVariableDeclarationBindingPatterns01_ES6.types create mode 100644 tests/baselines/reference/emptyVariableDeclarationBindingPatterns02_ES5.errors.txt create mode 100644 tests/baselines/reference/emptyVariableDeclarationBindingPatterns02_ES5.js create mode 100644 tests/baselines/reference/emptyVariableDeclarationBindingPatterns02_ES6.errors.txt create mode 100644 tests/baselines/reference/emptyVariableDeclarationBindingPatterns02_ES6.js diff --git a/tests/baselines/reference/emptyVariableDeclarationBindingPatterns01_ES5.js b/tests/baselines/reference/emptyVariableDeclarationBindingPatterns01_ES5.js new file mode 100644 index 00000000000..2b50bc58dd7 --- /dev/null +++ b/tests/baselines/reference/emptyVariableDeclarationBindingPatterns01_ES5.js @@ -0,0 +1,27 @@ +//// [emptyVariableDeclarationBindingPatterns01_ES5.ts] + +(function () { + var a: any; + + var {} = a; + let {} = a; + const {} = a; + + var [] = a; + let [] = a; + const [] = a; +})(); + +//// [emptyVariableDeclarationBindingPatterns01_ES5.js] +(function () { + var a; + var ; + var ; + var ; + var ; + var ; + var ; +})(); + + +//// [emptyVariableDeclarationBindingPatterns01_ES5.d.ts] diff --git a/tests/baselines/reference/emptyVariableDeclarationBindingPatterns01_ES5.symbols b/tests/baselines/reference/emptyVariableDeclarationBindingPatterns01_ES5.symbols new file mode 100644 index 00000000000..eac59730e49 --- /dev/null +++ b/tests/baselines/reference/emptyVariableDeclarationBindingPatterns01_ES5.symbols @@ -0,0 +1,25 @@ +=== tests/cases/conformance/es6/destructuring/emptyVariableDeclarationBindingPatterns01_ES5.ts === + +(function () { + var a: any; +>a : Symbol(a, Decl(emptyVariableDeclarationBindingPatterns01_ES5.ts, 2, 7)) + + var {} = a; +>a : Symbol(a, Decl(emptyVariableDeclarationBindingPatterns01_ES5.ts, 2, 7)) + + let {} = a; +>a : Symbol(a, Decl(emptyVariableDeclarationBindingPatterns01_ES5.ts, 2, 7)) + + const {} = a; +>a : Symbol(a, Decl(emptyVariableDeclarationBindingPatterns01_ES5.ts, 2, 7)) + + var [] = a; +>a : Symbol(a, Decl(emptyVariableDeclarationBindingPatterns01_ES5.ts, 2, 7)) + + let [] = a; +>a : Symbol(a, Decl(emptyVariableDeclarationBindingPatterns01_ES5.ts, 2, 7)) + + const [] = a; +>a : Symbol(a, Decl(emptyVariableDeclarationBindingPatterns01_ES5.ts, 2, 7)) + +})(); diff --git a/tests/baselines/reference/emptyVariableDeclarationBindingPatterns01_ES5.types b/tests/baselines/reference/emptyVariableDeclarationBindingPatterns01_ES5.types new file mode 100644 index 00000000000..9508ef00a54 --- /dev/null +++ b/tests/baselines/reference/emptyVariableDeclarationBindingPatterns01_ES5.types @@ -0,0 +1,29 @@ +=== tests/cases/conformance/es6/destructuring/emptyVariableDeclarationBindingPatterns01_ES5.ts === + +(function () { +>(function () { var a: any; var {} = a; let {} = a; const {} = a; var [] = a; let [] = a; const [] = a;})() : void +>(function () { var a: any; var {} = a; let {} = a; const {} = a; var [] = a; let [] = a; const [] = a;}) : () => void +>function () { var a: any; var {} = a; let {} = a; const {} = a; var [] = a; let [] = a; const [] = a;} : () => void + + var a: any; +>a : any + + var {} = a; +>a : any + + let {} = a; +>a : any + + const {} = a; +>a : any + + var [] = a; +>a : any + + let [] = a; +>a : any + + const [] = a; +>a : any + +})(); diff --git a/tests/baselines/reference/emptyVariableDeclarationBindingPatterns01_ES6.js b/tests/baselines/reference/emptyVariableDeclarationBindingPatterns01_ES6.js new file mode 100644 index 00000000000..ba08ad93c3c --- /dev/null +++ b/tests/baselines/reference/emptyVariableDeclarationBindingPatterns01_ES6.js @@ -0,0 +1,27 @@ +//// [emptyVariableDeclarationBindingPatterns01_ES6.ts] + +(function () { + var a: any; + + var {} = a; + let {} = a; + const {} = a; + + var [] = a; + let [] = a; + const [] = a; +})(); + +//// [emptyVariableDeclarationBindingPatterns01_ES6.js] +(function () { + var a; + var { } = a; + let { } = a; + const { } = a; + var [] = a; + let [] = a; + const [] = a; +})(); + + +//// [emptyVariableDeclarationBindingPatterns01_ES6.d.ts] diff --git a/tests/baselines/reference/emptyVariableDeclarationBindingPatterns01_ES6.symbols b/tests/baselines/reference/emptyVariableDeclarationBindingPatterns01_ES6.symbols new file mode 100644 index 00000000000..9a8130c87ca --- /dev/null +++ b/tests/baselines/reference/emptyVariableDeclarationBindingPatterns01_ES6.symbols @@ -0,0 +1,25 @@ +=== tests/cases/conformance/es6/destructuring/emptyVariableDeclarationBindingPatterns01_ES6.ts === + +(function () { + var a: any; +>a : Symbol(a, Decl(emptyVariableDeclarationBindingPatterns01_ES6.ts, 2, 7)) + + var {} = a; +>a : Symbol(a, Decl(emptyVariableDeclarationBindingPatterns01_ES6.ts, 2, 7)) + + let {} = a; +>a : Symbol(a, Decl(emptyVariableDeclarationBindingPatterns01_ES6.ts, 2, 7)) + + const {} = a; +>a : Symbol(a, Decl(emptyVariableDeclarationBindingPatterns01_ES6.ts, 2, 7)) + + var [] = a; +>a : Symbol(a, Decl(emptyVariableDeclarationBindingPatterns01_ES6.ts, 2, 7)) + + let [] = a; +>a : Symbol(a, Decl(emptyVariableDeclarationBindingPatterns01_ES6.ts, 2, 7)) + + const [] = a; +>a : Symbol(a, Decl(emptyVariableDeclarationBindingPatterns01_ES6.ts, 2, 7)) + +})(); diff --git a/tests/baselines/reference/emptyVariableDeclarationBindingPatterns01_ES6.types b/tests/baselines/reference/emptyVariableDeclarationBindingPatterns01_ES6.types new file mode 100644 index 00000000000..09c04100695 --- /dev/null +++ b/tests/baselines/reference/emptyVariableDeclarationBindingPatterns01_ES6.types @@ -0,0 +1,29 @@ +=== tests/cases/conformance/es6/destructuring/emptyVariableDeclarationBindingPatterns01_ES6.ts === + +(function () { +>(function () { var a: any; var {} = a; let {} = a; const {} = a; var [] = a; let [] = a; const [] = a;})() : void +>(function () { var a: any; var {} = a; let {} = a; const {} = a; var [] = a; let [] = a; const [] = a;}) : () => void +>function () { var a: any; var {} = a; let {} = a; const {} = a; var [] = a; let [] = a; const [] = a;} : () => void + + var a: any; +>a : any + + var {} = a; +>a : any + + let {} = a; +>a : any + + const {} = a; +>a : any + + var [] = a; +>a : any + + let [] = a; +>a : any + + const [] = a; +>a : any + +})(); diff --git a/tests/baselines/reference/emptyVariableDeclarationBindingPatterns02_ES5.errors.txt b/tests/baselines/reference/emptyVariableDeclarationBindingPatterns02_ES5.errors.txt new file mode 100644 index 00000000000..b589b075ecb --- /dev/null +++ b/tests/baselines/reference/emptyVariableDeclarationBindingPatterns02_ES5.errors.txt @@ -0,0 +1,31 @@ +tests/cases/conformance/es6/destructuring/emptyVariableDeclarationBindingPatterns02_ES5.ts(3,9): error TS1182: A destructuring declaration must have an initializer. +tests/cases/conformance/es6/destructuring/emptyVariableDeclarationBindingPatterns02_ES5.ts(4,9): error TS1182: A destructuring declaration must have an initializer. +tests/cases/conformance/es6/destructuring/emptyVariableDeclarationBindingPatterns02_ES5.ts(5,11): error TS1182: A destructuring declaration must have an initializer. +tests/cases/conformance/es6/destructuring/emptyVariableDeclarationBindingPatterns02_ES5.ts(7,9): error TS1182: A destructuring declaration must have an initializer. +tests/cases/conformance/es6/destructuring/emptyVariableDeclarationBindingPatterns02_ES5.ts(8,9): error TS1182: A destructuring declaration must have an initializer. +tests/cases/conformance/es6/destructuring/emptyVariableDeclarationBindingPatterns02_ES5.ts(9,11): error TS1182: A destructuring declaration must have an initializer. + + +==== tests/cases/conformance/es6/destructuring/emptyVariableDeclarationBindingPatterns02_ES5.ts (6 errors) ==== + + (function () { + var {}; + ~~ +!!! error TS1182: A destructuring declaration must have an initializer. + let {}; + ~~ +!!! error TS1182: A destructuring declaration must have an initializer. + const {}; + ~~ +!!! error TS1182: A destructuring declaration must have an initializer. + + var []; + ~~ +!!! error TS1182: A destructuring declaration must have an initializer. + let []; + ~~ +!!! error TS1182: A destructuring declaration must have an initializer. + const []; + ~~ +!!! error TS1182: A destructuring declaration must have an initializer. + })(); \ No newline at end of file diff --git a/tests/baselines/reference/emptyVariableDeclarationBindingPatterns02_ES5.js b/tests/baselines/reference/emptyVariableDeclarationBindingPatterns02_ES5.js new file mode 100644 index 00000000000..7710b5e26c1 --- /dev/null +++ b/tests/baselines/reference/emptyVariableDeclarationBindingPatterns02_ES5.js @@ -0,0 +1,24 @@ +//// [emptyVariableDeclarationBindingPatterns02_ES5.ts] + +(function () { + var {}; + let {}; + const {}; + + var []; + let []; + const []; +})(); + +//// [emptyVariableDeclarationBindingPatterns02_ES5.js] +(function () { + var _a = void 0; + var _b = void 0; + var _c = void 0; + var _d = void 0; + var _e = void 0; + var _f = void 0; +})(); + + +//// [emptyVariableDeclarationBindingPatterns02_ES5.d.ts] diff --git a/tests/baselines/reference/emptyVariableDeclarationBindingPatterns02_ES6.errors.txt b/tests/baselines/reference/emptyVariableDeclarationBindingPatterns02_ES6.errors.txt new file mode 100644 index 00000000000..81349584f47 --- /dev/null +++ b/tests/baselines/reference/emptyVariableDeclarationBindingPatterns02_ES6.errors.txt @@ -0,0 +1,31 @@ +tests/cases/conformance/es6/destructuring/emptyVariableDeclarationBindingPatterns02_ES6.ts(3,9): error TS1182: A destructuring declaration must have an initializer. +tests/cases/conformance/es6/destructuring/emptyVariableDeclarationBindingPatterns02_ES6.ts(4,9): error TS1182: A destructuring declaration must have an initializer. +tests/cases/conformance/es6/destructuring/emptyVariableDeclarationBindingPatterns02_ES6.ts(5,11): error TS1182: A destructuring declaration must have an initializer. +tests/cases/conformance/es6/destructuring/emptyVariableDeclarationBindingPatterns02_ES6.ts(7,9): error TS1182: A destructuring declaration must have an initializer. +tests/cases/conformance/es6/destructuring/emptyVariableDeclarationBindingPatterns02_ES6.ts(8,9): error TS1182: A destructuring declaration must have an initializer. +tests/cases/conformance/es6/destructuring/emptyVariableDeclarationBindingPatterns02_ES6.ts(9,11): error TS1182: A destructuring declaration must have an initializer. + + +==== tests/cases/conformance/es6/destructuring/emptyVariableDeclarationBindingPatterns02_ES6.ts (6 errors) ==== + + (function () { + var {}; + ~~ +!!! error TS1182: A destructuring declaration must have an initializer. + let {}; + ~~ +!!! error TS1182: A destructuring declaration must have an initializer. + const {}; + ~~ +!!! error TS1182: A destructuring declaration must have an initializer. + + var []; + ~~ +!!! error TS1182: A destructuring declaration must have an initializer. + let []; + ~~ +!!! error TS1182: A destructuring declaration must have an initializer. + const []; + ~~ +!!! error TS1182: A destructuring declaration must have an initializer. + })(); \ No newline at end of file diff --git a/tests/baselines/reference/emptyVariableDeclarationBindingPatterns02_ES6.js b/tests/baselines/reference/emptyVariableDeclarationBindingPatterns02_ES6.js new file mode 100644 index 00000000000..8b2df68ed70 --- /dev/null +++ b/tests/baselines/reference/emptyVariableDeclarationBindingPatterns02_ES6.js @@ -0,0 +1,24 @@ +//// [emptyVariableDeclarationBindingPatterns02_ES6.ts] + +(function () { + var {}; + let {}; + const {}; + + var []; + let []; + const []; +})(); + +//// [emptyVariableDeclarationBindingPatterns02_ES6.js] +(function () { + var { }; + let { }; + const { }; + var []; + let []; + const []; +})(); + + +//// [emptyVariableDeclarationBindingPatterns02_ES6.d.ts] From a579d41a57b4b2edcfa92371d41ed2da7fa80e77 Mon Sep 17 00:00:00 2001 From: Mohamed Hegazy Date: Thu, 3 Sep 2015 13:53:00 -0700 Subject: [PATCH 05/28] Do not add symbol if it is undefined --- src/compiler/checker.ts | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index a7e9561c57f..01403c70de7 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -14166,7 +14166,10 @@ namespace ts { let symbols: Symbol[] = []; let name = symbol.name; forEach(getSymbolLinks(symbol).containingType.types, t => { - symbols.push(getPropertyOfType(t, name)); + let symbol = getPropertyOfType(t, name); + if (symbol) { + symbols.push(symbol); + } }); return symbols; } From 568e4a56014f8e0c5a06e436c37da5c7e153369a Mon Sep 17 00:00:00 2001 From: Wesley Wigham Date: Wed, 2 Sep 2015 18:33:45 -0700 Subject: [PATCH 06/28] sample --- ...genericTypeAliasIntersectionCompletions.ts | 32 +++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 tests/cases/fourslash/genericTypeAliasIntersectionCompletions.ts diff --git a/tests/cases/fourslash/genericTypeAliasIntersectionCompletions.ts b/tests/cases/fourslash/genericTypeAliasIntersectionCompletions.ts new file mode 100644 index 00000000000..7c0fa3e5b17 --- /dev/null +++ b/tests/cases/fourslash/genericTypeAliasIntersectionCompletions.ts @@ -0,0 +1,32 @@ +/// + +//// type MixinCtor = new () => A & B & { constructor: MixinCtor }; +//// function merge(a: { prototype: A }, b: { prototype: B }): MixinCtor { +//// let merged = function() { } +//// Object.assign(merged.prototype, a.prototype, b.prototype); +//// return >merged; +//// } +//// +//// class TreeNode { +//// value: any; +//// } +//// +//// abstract class LeftSideNode extends TreeNode { +//// abstract right(): TreeNode; +//// left(): TreeNode { +//// return null; +//// } +//// } +//// +//// abstract class RightSideNode extends TreeNode { +//// abstract left(): TreeNode; +//// right(): TreeNode { +//// return null; +//// }; +//// } +//// +//// var obj = new (merge(LeftSideNode, RightSideNode))(); +//// obj./**/ + +goTo.marker(); +verify.completionListItemsCountIsGreaterThan(0); From 7a0c28ccc84184763476e9d92915b7dff9de0a6b Mon Sep 17 00:00:00 2001 From: Mohamed Hegazy Date: Thu, 3 Sep 2015 14:11:54 -0700 Subject: [PATCH 07/28] make the test more specific --- .../cases/fourslash/genericTypeAliasIntersectionCompletions.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tests/cases/fourslash/genericTypeAliasIntersectionCompletions.ts b/tests/cases/fourslash/genericTypeAliasIntersectionCompletions.ts index 7c0fa3e5b17..0b2646291da 100644 --- a/tests/cases/fourslash/genericTypeAliasIntersectionCompletions.ts +++ b/tests/cases/fourslash/genericTypeAliasIntersectionCompletions.ts @@ -29,4 +29,5 @@ //// obj./**/ goTo.marker(); -verify.completionListItemsCountIsGreaterThan(0); +verify.completionListContains("left"); +verify.completionListContains("right"); From 3518ad1723625a4dcf6df0faea6f7a2585038337 Mon Sep 17 00:00:00 2001 From: Daniel Rosenwasser Date: Fri, 4 Sep 2015 12:14:57 -0700 Subject: [PATCH 08/28] Added more test cases. --- ...ariableDeclarationBindingPatterns01_ES5.ts | 34 ++++++++++++++++++- ...ariableDeclarationBindingPatterns01_ES6.ts | 34 ++++++++++++++++++- 2 files changed, 66 insertions(+), 2 deletions(-) diff --git a/tests/cases/conformance/es6/destructuring/emptyVariableDeclarationBindingPatterns01_ES5.ts b/tests/cases/conformance/es6/destructuring/emptyVariableDeclarationBindingPatterns01_ES5.ts index 50beb289f60..dec00737658 100644 --- a/tests/cases/conformance/es6/destructuring/emptyVariableDeclarationBindingPatterns01_ES5.ts +++ b/tests/cases/conformance/es6/destructuring/emptyVariableDeclarationBindingPatterns01_ES5.ts @@ -1,5 +1,4 @@ // @target: es5 -// @declaration: true (function () { var a: any; @@ -11,4 +10,37 @@ var [] = a; let [] = a; const [] = a; + + var {} = a, [] = a; + let {} = a, [] = a; + const {} = a, [] = a; + + var { p1: {}, p2: [] } = a; + let { p1: {}, p2: [] } = a; + const { p1: {}, p2: [] } = a; + + for (var {} = {}, {} = {}; false; void 0) { + } +})(); + +(function () { + const ns: number[][] = []; + + for (var {} of ns) { + } + + for (let {} of ns) { + } + + for (const {} of ns) { + } + + for (var [] of ns) { + } + + for (let [] of ns) { + } + + for (const [] of ns) { + } })(); \ No newline at end of file diff --git a/tests/cases/conformance/es6/destructuring/emptyVariableDeclarationBindingPatterns01_ES6.ts b/tests/cases/conformance/es6/destructuring/emptyVariableDeclarationBindingPatterns01_ES6.ts index 8fd5beef63b..9f90dc28998 100644 --- a/tests/cases/conformance/es6/destructuring/emptyVariableDeclarationBindingPatterns01_ES6.ts +++ b/tests/cases/conformance/es6/destructuring/emptyVariableDeclarationBindingPatterns01_ES6.ts @@ -1,5 +1,4 @@ // @target: es6 -// @declaration: true (function () { var a: any; @@ -11,4 +10,37 @@ var [] = a; let [] = a; const [] = a; + + var {} = a, [] = a; + let {} = a, [] = a; + const {} = a, [] = a; + + var { p1: {}, p2: [] } = a; + let { p1: {}, p2: [] } = a; + const { p1: {}, p2: [] } = a; + + for (var {} = {}, {} = {}; false; void 0) { + } +})(); + +(function () { + const ns: number[][] = []; + + for (var {} of ns) { + } + + for (let {} of ns) { + } + + for (const {} of ns) { + } + + for (var [] of ns) { + } + + for (let [] of ns) { + } + + for (const [] of ns) { + } })(); \ No newline at end of file From 9ba2fdaf68427574ad39b2a11f7e1b164418c0e4 Mon Sep 17 00:00:00 2001 From: Daniel Rosenwasser Date: Fri, 4 Sep 2015 12:31:54 -0700 Subject: [PATCH 09/28] Accepted baselines. --- ...ariableDeclarationBindingPatterns01_ES5.js | 65 +++++++++++++++- ...leDeclarationBindingPatterns01_ES5.symbols | 52 +++++++++++++ ...ableDeclarationBindingPatterns01_ES5.types | 74 ++++++++++++++++++- ...ariableDeclarationBindingPatterns01_ES6.js | 59 ++++++++++++++- ...leDeclarationBindingPatterns01_ES6.symbols | 52 +++++++++++++ ...ableDeclarationBindingPatterns01_ES6.types | 74 ++++++++++++++++++- 6 files changed, 364 insertions(+), 12 deletions(-) diff --git a/tests/baselines/reference/emptyVariableDeclarationBindingPatterns01_ES5.js b/tests/baselines/reference/emptyVariableDeclarationBindingPatterns01_ES5.js index 2b50bc58dd7..2c8d1c2f44f 100644 --- a/tests/baselines/reference/emptyVariableDeclarationBindingPatterns01_ES5.js +++ b/tests/baselines/reference/emptyVariableDeclarationBindingPatterns01_ES5.js @@ -10,6 +10,39 @@ var [] = a; let [] = a; const [] = a; + + var {} = a, [] = a; + let {} = a, [] = a; + const {} = a, [] = a; + + var { p1: {}, p2: [] } = a; + let { p1: {}, p2: [] } = a; + const { p1: {}, p2: [] } = a; + + for (var {} = {}, {} = {}; false; void 0) { + } +})(); + +(function () { + const ns: number[][] = []; + + for (var {} of ns) { + } + + for (let {} of ns) { + } + + for (const {} of ns) { + } + + for (var [] of ns) { + } + + for (let [] of ns) { + } + + for (const [] of ns) { + } })(); //// [emptyVariableDeclarationBindingPatterns01_ES5.js] @@ -21,7 +54,33 @@ var ; var ; var ; + var , ; + var , ; + var , ; + var _a = a.p1, _b = a.p2; + var _c = a.p1, _d = a.p2; + var _e = a.p1, _f = a.p2; + for (var _g = {}, _h = {}; false; void 0) { + } +})(); +(function () { + var ns = []; + for (var _i = 0; _i < ns.length; _i++) { + var _a = ns[_i]; + } + for (var _b = 0; _b < ns.length; _b++) { + var _c = ns[_b]; + } + for (var _d = 0; _d < ns.length; _d++) { + var _e = ns[_d]; + } + for (var _f = 0; _f < ns.length; _f++) { + var _g = ns[_f]; + } + for (var _h = 0; _h < ns.length; _h++) { + var _j = ns[_h]; + } + for (var _k = 0; _k < ns.length; _k++) { + var _l = ns[_k]; + } })(); - - -//// [emptyVariableDeclarationBindingPatterns01_ES5.d.ts] diff --git a/tests/baselines/reference/emptyVariableDeclarationBindingPatterns01_ES5.symbols b/tests/baselines/reference/emptyVariableDeclarationBindingPatterns01_ES5.symbols index eac59730e49..f8cc7d2546f 100644 --- a/tests/baselines/reference/emptyVariableDeclarationBindingPatterns01_ES5.symbols +++ b/tests/baselines/reference/emptyVariableDeclarationBindingPatterns01_ES5.symbols @@ -22,4 +22,56 @@ const [] = a; >a : Symbol(a, Decl(emptyVariableDeclarationBindingPatterns01_ES5.ts, 2, 7)) + var {} = a, [] = a; +>a : Symbol(a, Decl(emptyVariableDeclarationBindingPatterns01_ES5.ts, 2, 7)) +>a : Symbol(a, Decl(emptyVariableDeclarationBindingPatterns01_ES5.ts, 2, 7)) + + let {} = a, [] = a; +>a : Symbol(a, Decl(emptyVariableDeclarationBindingPatterns01_ES5.ts, 2, 7)) +>a : Symbol(a, Decl(emptyVariableDeclarationBindingPatterns01_ES5.ts, 2, 7)) + + const {} = a, [] = a; +>a : Symbol(a, Decl(emptyVariableDeclarationBindingPatterns01_ES5.ts, 2, 7)) +>a : Symbol(a, Decl(emptyVariableDeclarationBindingPatterns01_ES5.ts, 2, 7)) + + var { p1: {}, p2: [] } = a; +>a : Symbol(a, Decl(emptyVariableDeclarationBindingPatterns01_ES5.ts, 2, 7)) + + let { p1: {}, p2: [] } = a; +>a : Symbol(a, Decl(emptyVariableDeclarationBindingPatterns01_ES5.ts, 2, 7)) + + const { p1: {}, p2: [] } = a; +>a : Symbol(a, Decl(emptyVariableDeclarationBindingPatterns01_ES5.ts, 2, 7)) + + for (var {} = {}, {} = {}; false; void 0) { + } +})(); + +(function () { + const ns: number[][] = []; +>ns : Symbol(ns, Decl(emptyVariableDeclarationBindingPatterns01_ES5.ts, 25, 9)) + + for (var {} of ns) { +>ns : Symbol(ns, Decl(emptyVariableDeclarationBindingPatterns01_ES5.ts, 25, 9)) + } + + for (let {} of ns) { +>ns : Symbol(ns, Decl(emptyVariableDeclarationBindingPatterns01_ES5.ts, 25, 9)) + } + + for (const {} of ns) { +>ns : Symbol(ns, Decl(emptyVariableDeclarationBindingPatterns01_ES5.ts, 25, 9)) + } + + for (var [] of ns) { +>ns : Symbol(ns, Decl(emptyVariableDeclarationBindingPatterns01_ES5.ts, 25, 9)) + } + + for (let [] of ns) { +>ns : Symbol(ns, Decl(emptyVariableDeclarationBindingPatterns01_ES5.ts, 25, 9)) + } + + for (const [] of ns) { +>ns : Symbol(ns, Decl(emptyVariableDeclarationBindingPatterns01_ES5.ts, 25, 9)) + } })(); diff --git a/tests/baselines/reference/emptyVariableDeclarationBindingPatterns01_ES5.types b/tests/baselines/reference/emptyVariableDeclarationBindingPatterns01_ES5.types index 9508ef00a54..b4e3da1454b 100644 --- a/tests/baselines/reference/emptyVariableDeclarationBindingPatterns01_ES5.types +++ b/tests/baselines/reference/emptyVariableDeclarationBindingPatterns01_ES5.types @@ -1,9 +1,9 @@ === tests/cases/conformance/es6/destructuring/emptyVariableDeclarationBindingPatterns01_ES5.ts === (function () { ->(function () { var a: any; var {} = a; let {} = a; const {} = a; var [] = a; let [] = a; const [] = a;})() : void ->(function () { var a: any; var {} = a; let {} = a; const {} = a; var [] = a; let [] = a; const [] = a;}) : () => void ->function () { var a: any; var {} = a; let {} = a; const {} = a; var [] = a; let [] = a; const [] = a;} : () => void +>(function () { var a: any; var {} = a; let {} = a; const {} = a; var [] = a; let [] = a; const [] = a; var {} = a, [] = a; let {} = a, [] = a; const {} = a, [] = a; var { p1: {}, p2: [] } = a; let { p1: {}, p2: [] } = a; const { p1: {}, p2: [] } = a; for (var {} = {}, {} = {}; false; void 0) { }})() : void +>(function () { var a: any; var {} = a; let {} = a; const {} = a; var [] = a; let [] = a; const [] = a; var {} = a, [] = a; let {} = a, [] = a; const {} = a, [] = a; var { p1: {}, p2: [] } = a; let { p1: {}, p2: [] } = a; const { p1: {}, p2: [] } = a; for (var {} = {}, {} = {}; false; void 0) { }}) : () => void +>function () { var a: any; var {} = a; let {} = a; const {} = a; var [] = a; let [] = a; const [] = a; var {} = a, [] = a; let {} = a, [] = a; const {} = a, [] = a; var { p1: {}, p2: [] } = a; let { p1: {}, p2: [] } = a; const { p1: {}, p2: [] } = a; for (var {} = {}, {} = {}; false; void 0) { }} : () => void var a: any; >a : any @@ -26,4 +26,72 @@ const [] = a; >a : any + var {} = a, [] = a; +>a : any +>a : any + + let {} = a, [] = a; +>a : any +>a : any + + const {} = a, [] = a; +>a : any +>a : any + + var { p1: {}, p2: [] } = a; +>p1 : any +>p2 : any +>a : any + + let { p1: {}, p2: [] } = a; +>p1 : any +>p2 : any +>a : any + + const { p1: {}, p2: [] } = a; +>p1 : any +>p2 : any +>a : any + + for (var {} = {}, {} = {}; false; void 0) { +>{} : {} +>{} : {} +>false : boolean +>void 0 : undefined +>0 : number + } +})(); + +(function () { +>(function () { const ns: number[][] = []; for (var {} of ns) { } for (let {} of ns) { } for (const {} of ns) { } for (var [] of ns) { } for (let [] of ns) { } for (const [] of ns) { }})() : void +>(function () { const ns: number[][] = []; for (var {} of ns) { } for (let {} of ns) { } for (const {} of ns) { } for (var [] of ns) { } for (let [] of ns) { } for (const [] of ns) { }}) : () => void +>function () { const ns: number[][] = []; for (var {} of ns) { } for (let {} of ns) { } for (const {} of ns) { } for (var [] of ns) { } for (let [] of ns) { } for (const [] of ns) { }} : () => void + + const ns: number[][] = []; +>ns : number[][] +>[] : undefined[] + + for (var {} of ns) { +>ns : number[][] + } + + for (let {} of ns) { +>ns : number[][] + } + + for (const {} of ns) { +>ns : number[][] + } + + for (var [] of ns) { +>ns : number[][] + } + + for (let [] of ns) { +>ns : number[][] + } + + for (const [] of ns) { +>ns : number[][] + } })(); diff --git a/tests/baselines/reference/emptyVariableDeclarationBindingPatterns01_ES6.js b/tests/baselines/reference/emptyVariableDeclarationBindingPatterns01_ES6.js index ba08ad93c3c..924303c1976 100644 --- a/tests/baselines/reference/emptyVariableDeclarationBindingPatterns01_ES6.js +++ b/tests/baselines/reference/emptyVariableDeclarationBindingPatterns01_ES6.js @@ -10,6 +10,39 @@ var [] = a; let [] = a; const [] = a; + + var {} = a, [] = a; + let {} = a, [] = a; + const {} = a, [] = a; + + var { p1: {}, p2: [] } = a; + let { p1: {}, p2: [] } = a; + const { p1: {}, p2: [] } = a; + + for (var {} = {}, {} = {}; false; void 0) { + } +})(); + +(function () { + const ns: number[][] = []; + + for (var {} of ns) { + } + + for (let {} of ns) { + } + + for (const {} of ns) { + } + + for (var [] of ns) { + } + + for (let [] of ns) { + } + + for (const [] of ns) { + } })(); //// [emptyVariableDeclarationBindingPatterns01_ES6.js] @@ -21,7 +54,27 @@ var [] = a; let [] = a; const [] = a; + var { } = a, [] = a; + let { } = a, [] = a; + const { } = a, [] = a; + var { p1: { }, p2: [] } = a; + let { p1: { }, p2: [] } = a; + const { p1: { }, p2: [] } = a; + for (var { } = {}, { } = {}; false; void 0) { + } +})(); +(function () { + const ns = []; + for (var { } of ns) { + } + for (let { } of ns) { + } + for (const { } of ns) { + } + for (var [] of ns) { + } + for (let [] of ns) { + } + for (const [] of ns) { + } })(); - - -//// [emptyVariableDeclarationBindingPatterns01_ES6.d.ts] diff --git a/tests/baselines/reference/emptyVariableDeclarationBindingPatterns01_ES6.symbols b/tests/baselines/reference/emptyVariableDeclarationBindingPatterns01_ES6.symbols index 9a8130c87ca..d158e3a4891 100644 --- a/tests/baselines/reference/emptyVariableDeclarationBindingPatterns01_ES6.symbols +++ b/tests/baselines/reference/emptyVariableDeclarationBindingPatterns01_ES6.symbols @@ -22,4 +22,56 @@ const [] = a; >a : Symbol(a, Decl(emptyVariableDeclarationBindingPatterns01_ES6.ts, 2, 7)) + var {} = a, [] = a; +>a : Symbol(a, Decl(emptyVariableDeclarationBindingPatterns01_ES6.ts, 2, 7)) +>a : Symbol(a, Decl(emptyVariableDeclarationBindingPatterns01_ES6.ts, 2, 7)) + + let {} = a, [] = a; +>a : Symbol(a, Decl(emptyVariableDeclarationBindingPatterns01_ES6.ts, 2, 7)) +>a : Symbol(a, Decl(emptyVariableDeclarationBindingPatterns01_ES6.ts, 2, 7)) + + const {} = a, [] = a; +>a : Symbol(a, Decl(emptyVariableDeclarationBindingPatterns01_ES6.ts, 2, 7)) +>a : Symbol(a, Decl(emptyVariableDeclarationBindingPatterns01_ES6.ts, 2, 7)) + + var { p1: {}, p2: [] } = a; +>a : Symbol(a, Decl(emptyVariableDeclarationBindingPatterns01_ES6.ts, 2, 7)) + + let { p1: {}, p2: [] } = a; +>a : Symbol(a, Decl(emptyVariableDeclarationBindingPatterns01_ES6.ts, 2, 7)) + + const { p1: {}, p2: [] } = a; +>a : Symbol(a, Decl(emptyVariableDeclarationBindingPatterns01_ES6.ts, 2, 7)) + + for (var {} = {}, {} = {}; false; void 0) { + } +})(); + +(function () { + const ns: number[][] = []; +>ns : Symbol(ns, Decl(emptyVariableDeclarationBindingPatterns01_ES6.ts, 25, 9)) + + for (var {} of ns) { +>ns : Symbol(ns, Decl(emptyVariableDeclarationBindingPatterns01_ES6.ts, 25, 9)) + } + + for (let {} of ns) { +>ns : Symbol(ns, Decl(emptyVariableDeclarationBindingPatterns01_ES6.ts, 25, 9)) + } + + for (const {} of ns) { +>ns : Symbol(ns, Decl(emptyVariableDeclarationBindingPatterns01_ES6.ts, 25, 9)) + } + + for (var [] of ns) { +>ns : Symbol(ns, Decl(emptyVariableDeclarationBindingPatterns01_ES6.ts, 25, 9)) + } + + for (let [] of ns) { +>ns : Symbol(ns, Decl(emptyVariableDeclarationBindingPatterns01_ES6.ts, 25, 9)) + } + + for (const [] of ns) { +>ns : Symbol(ns, Decl(emptyVariableDeclarationBindingPatterns01_ES6.ts, 25, 9)) + } })(); diff --git a/tests/baselines/reference/emptyVariableDeclarationBindingPatterns01_ES6.types b/tests/baselines/reference/emptyVariableDeclarationBindingPatterns01_ES6.types index 09c04100695..e8dd5025288 100644 --- a/tests/baselines/reference/emptyVariableDeclarationBindingPatterns01_ES6.types +++ b/tests/baselines/reference/emptyVariableDeclarationBindingPatterns01_ES6.types @@ -1,9 +1,9 @@ === tests/cases/conformance/es6/destructuring/emptyVariableDeclarationBindingPatterns01_ES6.ts === (function () { ->(function () { var a: any; var {} = a; let {} = a; const {} = a; var [] = a; let [] = a; const [] = a;})() : void ->(function () { var a: any; var {} = a; let {} = a; const {} = a; var [] = a; let [] = a; const [] = a;}) : () => void ->function () { var a: any; var {} = a; let {} = a; const {} = a; var [] = a; let [] = a; const [] = a;} : () => void +>(function () { var a: any; var {} = a; let {} = a; const {} = a; var [] = a; let [] = a; const [] = a; var {} = a, [] = a; let {} = a, [] = a; const {} = a, [] = a; var { p1: {}, p2: [] } = a; let { p1: {}, p2: [] } = a; const { p1: {}, p2: [] } = a; for (var {} = {}, {} = {}; false; void 0) { }})() : void +>(function () { var a: any; var {} = a; let {} = a; const {} = a; var [] = a; let [] = a; const [] = a; var {} = a, [] = a; let {} = a, [] = a; const {} = a, [] = a; var { p1: {}, p2: [] } = a; let { p1: {}, p2: [] } = a; const { p1: {}, p2: [] } = a; for (var {} = {}, {} = {}; false; void 0) { }}) : () => void +>function () { var a: any; var {} = a; let {} = a; const {} = a; var [] = a; let [] = a; const [] = a; var {} = a, [] = a; let {} = a, [] = a; const {} = a, [] = a; var { p1: {}, p2: [] } = a; let { p1: {}, p2: [] } = a; const { p1: {}, p2: [] } = a; for (var {} = {}, {} = {}; false; void 0) { }} : () => void var a: any; >a : any @@ -26,4 +26,72 @@ const [] = a; >a : any + var {} = a, [] = a; +>a : any +>a : any + + let {} = a, [] = a; +>a : any +>a : any + + const {} = a, [] = a; +>a : any +>a : any + + var { p1: {}, p2: [] } = a; +>p1 : any +>p2 : any +>a : any + + let { p1: {}, p2: [] } = a; +>p1 : any +>p2 : any +>a : any + + const { p1: {}, p2: [] } = a; +>p1 : any +>p2 : any +>a : any + + for (var {} = {}, {} = {}; false; void 0) { +>{} : {} +>{} : {} +>false : boolean +>void 0 : undefined +>0 : number + } +})(); + +(function () { +>(function () { const ns: number[][] = []; for (var {} of ns) { } for (let {} of ns) { } for (const {} of ns) { } for (var [] of ns) { } for (let [] of ns) { } for (const [] of ns) { }})() : void +>(function () { const ns: number[][] = []; for (var {} of ns) { } for (let {} of ns) { } for (const {} of ns) { } for (var [] of ns) { } for (let [] of ns) { } for (const [] of ns) { }}) : () => void +>function () { const ns: number[][] = []; for (var {} of ns) { } for (let {} of ns) { } for (const {} of ns) { } for (var [] of ns) { } for (let [] of ns) { } for (const [] of ns) { }} : () => void + + const ns: number[][] = []; +>ns : number[][] +>[] : undefined[] + + for (var {} of ns) { +>ns : number[][] + } + + for (let {} of ns) { +>ns : number[][] + } + + for (const {} of ns) { +>ns : number[][] + } + + for (var [] of ns) { +>ns : number[][] + } + + for (let [] of ns) { +>ns : number[][] + } + + for (const [] of ns) { +>ns : number[][] + } })(); From 97b846c444843c3c2c1bdad332c7d0407fcea5df Mon Sep 17 00:00:00 2001 From: Vladimir Matveev Date: Fri, 4 Sep 2015 10:53:33 -0700 Subject: [PATCH 10/28] handle jsx identifiers correctly, indent content of JsxSelfClosingElement --- src/services/formatting/formattingScanner.ts | 25 ++++++- src/services/formatting/smartIndenter.ts | 1 + .../cases/fourslash/formattingJsxElements.ts | 70 ++++++++++++++++++- 3 files changed, 92 insertions(+), 4 deletions(-) diff --git a/src/services/formatting/formattingScanner.ts b/src/services/formatting/formattingScanner.ts index 7e77878051c..6f6167d6ba9 100644 --- a/src/services/formatting/formattingScanner.ts +++ b/src/services/formatting/formattingScanner.ts @@ -17,7 +17,8 @@ namespace ts.formatting { Scan, RescanGreaterThanToken, RescanSlashToken, - RescanTemplateToken + RescanTemplateToken, + RescanJsxIdentifier } export function getFormattingScanner(sourceFile: SourceFile, startPos: number, endPos: number): FormattingScanner { @@ -108,6 +109,20 @@ namespace ts.formatting { return false; } + + function shouldRescanJsxIdentifier(node: Node): boolean { + if (node.parent) { + switch(node.parent.kind) { + case SyntaxKind.JsxAttribute: + case SyntaxKind.JsxOpeningElement: + case SyntaxKind.JsxClosingElement: + case SyntaxKind.JsxSelfClosingElement: + return node.kind === SyntaxKind.Identifier; + } + } + + return false; + } function shouldRescanSlashToken(container: Node): boolean { return container.kind === SyntaxKind.RegularExpressionLiteral; @@ -141,7 +156,9 @@ namespace ts.formatting { ? ScanAction.RescanSlashToken : shouldRescanTemplateToken(n) ? ScanAction.RescanTemplateToken - : ScanAction.Scan + : shouldRescanJsxIdentifier(n) + ? ScanAction.RescanJsxIdentifier + : ScanAction.Scan if (lastTokenInfo && expectedScanAction === lastScanAction) { // readTokenInfo was called before with the same expected scan action. @@ -176,6 +193,10 @@ namespace ts.formatting { currentToken = scanner.reScanTemplateToken(); lastScanAction = ScanAction.RescanTemplateToken; } + else if (expectedScanAction === ScanAction.RescanJsxIdentifier && currentToken === SyntaxKind.Identifier) { + currentToken = scanner.scanJsxIdentifier(); + lastScanAction = ScanAction.RescanJsxIdentifier; + } else { lastScanAction = ScanAction.Scan; } diff --git a/src/services/formatting/smartIndenter.ts b/src/services/formatting/smartIndenter.ts index 9c19e32ab6f..8355fac03f5 100644 --- a/src/services/formatting/smartIndenter.ts +++ b/src/services/formatting/smartIndenter.ts @@ -431,6 +431,7 @@ namespace ts.formatting { case SyntaxKind.ArrayBindingPattern: case SyntaxKind.ObjectBindingPattern: case SyntaxKind.JsxElement: + case SyntaxKind.JsxSelfClosingElement: case SyntaxKind.MethodSignature: case SyntaxKind.CallSignature: case SyntaxKind.ConstructSignature: diff --git a/tests/cases/fourslash/formattingJsxElements.ts b/tests/cases/fourslash/formattingJsxElements.ts index d0c77804ed5..fd4ccc504a4 100644 --- a/tests/cases/fourslash/formattingJsxElements.ts +++ b/tests/cases/fourslash/formattingJsxElements.ts @@ -1,7 +1,7 @@ /// //@Filename: file.tsx -////function () { +////function foo0() { //// return ( ////
////Hello, World!/*autoformat*/ @@ -10,10 +10,76 @@ //// ) ////} //// +////function foo1() { +//// return ( +////
+////Hello, World!/*autoformat1*/ +/////*indent1*/ +////
+//// ) +////} +//// +////function foo2() { +//// return ( +////
/*2*/ +////Hello, World!/*autoformat2*/ +/////*indent2*/ +////
+//// ) +////} +////function foo3() { +//// return ( +//// /*4*/ +//// Hello, World!/*autoformat3*/ +//// /*indent3*/ +//// +//// ) +////} +////function foo4() { +//// return ( +//// /*6*/ +//// ) +////} format.document(); goTo.marker("autoformat"); verify.currentLineContentIs(' Hello, World!'); goTo.marker("indent"); -verify.indentationIs(12); \ No newline at end of file +verify.indentationIs(12); + +goTo.marker("autoformat1"); +verify.currentLineContentIs(' Hello, World!'); +goTo.marker("indent1"); +verify.indentationIs(12); + +goTo.marker("1"); +verify.currentLineContentIs(' class1= {'); +goTo.marker("2"); +verify.currentLineContentIs(' }>'); + +goTo.marker("autoformat2"); +verify.currentLineContentIs(' Hello, World!'); +goTo.marker("indent2"); +verify.indentationIs(12); + +goTo.marker("3"); +verify.currentLineContentIs(' class2= {'); +goTo.marker("4"); +verify.currentLineContentIs(' }>'); + +goTo.marker("autoformat3"); +verify.currentLineContentIs(' Hello, World!'); +goTo.marker("indent3"); +verify.indentationIs(12); + +goTo.marker("5"); +verify.currentLineContentIs(' class3= {'); +goTo.marker("6"); +verify.currentLineContentIs(' }/>'); From 5297a7f319d1c76b07f995418e25600eda974a9a Mon Sep 17 00:00:00 2001 From: Daniel Rosenwasser Date: Fri, 4 Sep 2015 17:53:56 -0700 Subject: [PATCH 11/28] Ensure that zero-element binding patterns don't try to reuse assigned identifiers. --- src/compiler/emitter.ts | 59 ++++++++++++++++++++++++++--------------- 1 file changed, 37 insertions(+), 22 deletions(-) diff --git a/src/compiler/emitter.ts b/src/compiler/emitter.ts index eeaab6d2123..485181a91cc 100644 --- a/src/compiler/emitter.ts +++ b/src/compiler/emitter.ts @@ -3210,22 +3210,32 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, Promi } } - function ensureIdentifier(expr: Expression): Expression { - if (expr.kind !== SyntaxKind.Identifier) { - let identifier = createTempVariable(TempFlags.Auto); - if (!canDefineTempVariablesInPlace) { - recordTempDeclaration(identifier); - } - emitAssignment(identifier, expr); - expr = identifier; + /** + * Ensures that there exists a declared identifier whose value holds the given expression. + * This function is useful to ensure that the expression's value can be read from in subsequent expressions. + * Unless 'reuseIdentifierExpressions' is false, 'expr' will be returned if it is just an identifier. + * + * @param expr the expression whose value needs to be bound. + * @param reuseIdentifierExpressions true if identifier expressions can simply be returned; + * false if it is necessary to always emit an identifier. + */ + function ensureIdentifier(expr: Expression, reuseIdentifierExpressions: boolean): Expression { + if (expr.kind === SyntaxKind.Identifier && reuseIdentifierExpressions) { + return expr; } - return expr; + + let identifier = createTempVariable(TempFlags.Auto); + if (!canDefineTempVariablesInPlace) { + recordTempDeclaration(identifier); + } + emitAssignment(identifier, expr); + return identifier; } function createDefaultValueCheck(value: Expression, defaultValue: Expression): Expression { // The value expression will be evaluated twice, so for anything but a simple identifier // we need to generate a temporary variable - value = ensureIdentifier(value); + value = ensureIdentifier(value, /*reuseIdentifierExpressions*/ true); // Return the expression 'value === void 0 ? defaultValue : value' let equals = createSynthesizedNode(SyntaxKind.BinaryExpression); equals.left = value; @@ -3276,7 +3286,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, Promi if (properties.length !== 1) { // For anything but a single element destructuring we need to generate a temporary // to ensure value is evaluated exactly once. - value = ensureIdentifier(value); + value = ensureIdentifier(value, /*reuseIdentifierExpressions*/ true); } for (let p of properties) { if (p.kind === SyntaxKind.PropertyAssignment || p.kind === SyntaxKind.ShorthandPropertyAssignment) { @@ -3291,7 +3301,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, Promi if (elements.length !== 1) { // For anything but a single element destructuring we need to generate a temporary // to ensure value is evaluated exactly once. - value = ensureIdentifier(value); + value = ensureIdentifier(value, /*reuseIdentifierExpressions*/ true); } for (let i = 0; i < elements.length; i++) { let e = elements[i]; @@ -3336,7 +3346,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, Promi if (root.parent.kind !== SyntaxKind.ParenthesizedExpression) { write("("); } - value = ensureIdentifier(value); + value = ensureIdentifier(value, /*reuseIdentifierExpressions*/ true); emitDestructuringAssignment(target, value); write(", "); emit(value); @@ -3346,7 +3356,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, Promi } } - function emitBindingElement(target: BindingElement, value: Expression) { + function emitBindingElement(target: BindingElement | VariableDeclaration, value: Expression) { if (target.initializer) { // Combine value and initializer value = value ? createDefaultValueCheck(value, target.initializer) : target.initializer; @@ -3356,14 +3366,19 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, Promi value = createVoidZero(); } if (isBindingPattern(target.name)) { - let pattern = target.name; - let elements = pattern.elements; - if (elements.length !== 1) { - // For anything but a single element destructuring we need to generate a temporary - // to ensure value is evaluated exactly once. - value = ensureIdentifier(value); + const pattern = target.name; + const elements = pattern.elements; + const numElements = elements.length; + + if (numElements !== 1) { + // For anything other than a single-element destructuring we need to generate a temporary + // to ensure value is evaluated exactly once. Additionally, if we have zero elements + // we need to emit *something* to ensure that in case a 'var' keyword was already emitted, + // so in that case, we'll intentionally create that temporary. + value = ensureIdentifier(value, /*reuseIdentifierExpressions*/ numElements !== 0); } - for (let i = 0; i < elements.length; i++) { + + for (let i = 0; i < numElements; i++) { let element = elements[i]; if (pattern.kind === SyntaxKind.ObjectBindingPattern) { // Rewrite element to a declaration with an initializer that fetches property @@ -3375,7 +3390,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, Promi // Rewrite element to a declaration that accesses array element at index i emitBindingElement(element, createElementAccessExpression(value, createNumericLiteral(i))); } - else if (i === elements.length - 1) { + else if (i === numElements - 1) { emitBindingElement(element, createSliceCall(value, i)); } } From 8952ed66b2e3ba78d64e8399384dd55ecfccabd8 Mon Sep 17 00:00:00 2001 From: Daniel Rosenwasser Date: Fri, 4 Sep 2015 17:57:06 -0700 Subject: [PATCH 12/28] Accepted baselines. --- ...ariableDeclarationBindingPatterns01_ES5.js | 26 +++++++++---------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/tests/baselines/reference/emptyVariableDeclarationBindingPatterns01_ES5.js b/tests/baselines/reference/emptyVariableDeclarationBindingPatterns01_ES5.js index 2c8d1c2f44f..9ce2a04dad4 100644 --- a/tests/baselines/reference/emptyVariableDeclarationBindingPatterns01_ES5.js +++ b/tests/baselines/reference/emptyVariableDeclarationBindingPatterns01_ES5.js @@ -48,19 +48,19 @@ //// [emptyVariableDeclarationBindingPatterns01_ES5.js] (function () { var a; - var ; - var ; - var ; - var ; - var ; - var ; - var , ; - var , ; - var , ; - var _a = a.p1, _b = a.p2; - var _c = a.p1, _d = a.p2; - var _e = a.p1, _f = a.p2; - for (var _g = {}, _h = {}; false; void 0) { + var _a = a; + var _b = a; + var _c = a; + var _d = a; + var _e = a; + var _f = a; + var _g = a, _h = a; + var _j = a, _k = a; + var _l = a, _m = a; + var _o = a.p1, _p = a.p2; + var _q = a.p1, _r = a.p2; + var _s = a.p1, _t = a.p2; + for (var _u = {}, _v = {}; false; void 0) { } })(); (function () { From 8a38a1e4b9d67181d91b21f1ffc1879e42106b72 Mon Sep 17 00:00:00 2001 From: Mohamed Hegazy Date: Tue, 8 Sep 2015 12:26:29 -0700 Subject: [PATCH 13/28] Change typescript.d.ts to be an external module instead of an ambient external module declaration --- Jakefile.js | 15 ++++++++++++--- lib/typescript.d.ts | 18 ++++++++++-------- tests/cases/compiler/APISample_compile.ts | 2 +- tests/cases/compiler/APISample_linter.ts | 2 +- tests/cases/compiler/APISample_transform.ts | 2 +- tests/cases/compiler/APISample_watcher.ts | 2 +- 6 files changed, 26 insertions(+), 15 deletions(-) diff --git a/Jakefile.js b/Jakefile.js index ea13cce6685..96c2b44c088 100644 --- a/Jakefile.js +++ b/Jakefile.js @@ -394,6 +394,7 @@ var servicesFile = path.join(builtLocalDirectory, "typescriptServices.js"); var standaloneDefinitionsFile = path.join(builtLocalDirectory, "typescriptServices.d.ts"); var nodePackageFile = path.join(builtLocalDirectory, "typescript.js"); var nodeDefinitionsFile = path.join(builtLocalDirectory, "typescript.d.ts"); +var nodeStandaloneDefinitionsFile = path.join(builtLocalDirectory, "typescript_standalone.d.ts"); compileFile(servicesFile, servicesSources,[builtLocalDirectory, copyright].concat(servicesSources), /*prefixes*/ [copyright], @@ -410,11 +411,19 @@ compileFile(servicesFile, servicesSources,[builtLocalDirectory, copyright].conca prependFile(copyright, standaloneDefinitionsFile); - // Create the node definition file by replacing 'ts' module with '"typescript"' as a module. + // Stanalone/web definition file using global 'ts' namespace jake.cpR(standaloneDefinitionsFile, nodeDefinitionsFile, {silent: true}); var definitionFileContents = fs.readFileSync(nodeDefinitionsFile).toString(); - definitionFileContents = definitionFileContents.replace(/declare (namespace|module) ts/g, 'declare module "typescript"'); - fs.writeFileSync(nodeDefinitionsFile, definitionFileContents); + + // Official node package definition file, pointed to by 'typings' in package.json + // Created by appending 'export = ts;' at the end of the standalone file to turn it into an external module + var nodeDefinitionsFileContents = definitionFileContents + "\r\nexport = ts;"; + fs.writeFileSync(nodeDefinitionsFile, nodeDefinitionsFileContents); + + // Node package definition file to be distributed without the package. Created by replacing + // 'ts' namespace with '"typescript"' as a module. + var nodeStandaloneDefinitionsFileContents = definitionFileContents.replace(/declare (namespace|module) ts/g, 'declare module "typescript"'); + fs.writeFileSync(nodeStandaloneDefinitionsFile, nodeStandaloneDefinitionsFileContents); }); diff --git a/lib/typescript.d.ts b/lib/typescript.d.ts index bf0510cf1c8..5e6492cfe1e 100644 --- a/lib/typescript.d.ts +++ b/lib/typescript.d.ts @@ -13,7 +13,7 @@ See the Apache Version 2.0 License for specific language governing permissions and limitations under the License. ***************************************************************************** */ -declare module "typescript" { +declare namespace ts { interface Map { [index: string]: T; } @@ -1405,7 +1405,7 @@ declare module "typescript" { newLength: number; } } -declare module "typescript" { +declare namespace ts { interface System { args: string[]; newLine: string; @@ -1429,7 +1429,7 @@ declare module "typescript" { } var sys: System; } -declare module "typescript" { +declare namespace ts { interface ErrorCallback { (message: DiagnosticMessage, length: number): void; } @@ -1474,7 +1474,7 @@ declare module "typescript" { function isIdentifierPart(ch: number, languageVersion: ScriptTarget): boolean; function createScanner(languageVersion: ScriptTarget, skipTrivia: boolean, languageVariant?: LanguageVariant, text?: string, onError?: ErrorCallback, start?: number, length?: number): Scanner; } -declare module "typescript" { +declare namespace ts { function getDefaultLibFileName(options: CompilerOptions): string; function textSpanEnd(span: TextSpan): number; function textSpanIsEmpty(span: TextSpan): boolean; @@ -1504,14 +1504,14 @@ declare module "typescript" { function collapseTextChangeRangesAcrossMultipleVersions(changes: TextChangeRange[]): TextChangeRange; function getTypeParameterOwner(d: Declaration): Declaration; } -declare module "typescript" { +declare namespace ts { function getNodeConstructor(kind: SyntaxKind): new () => Node; function createNode(kind: SyntaxKind): Node; function forEachChild(node: Node, cbNode: (node: Node) => T, cbNodeArray?: (nodes: Node[]) => T): T; function createSourceFile(fileName: string, sourceText: string, languageVersion: ScriptTarget, setParentNodes?: boolean): SourceFile; function updateSourceFile(sourceFile: SourceFile, newText: string, textChangeRange: TextChangeRange, aggressiveChecks?: boolean): SourceFile; } -declare module "typescript" { +declare namespace ts { const version: string; function findConfigFile(searchPath: string): string; function resolveTripleslashReference(moduleName: string, containingFile: string): string; @@ -1524,7 +1524,7 @@ declare module "typescript" { function flattenDiagnosticMessageText(messageText: string | DiagnosticMessageChain, newLine: string): string; function createProgram(rootNames: string[], options: CompilerOptions, host?: CompilerHost, oldProgram?: Program): Program; } -declare module "typescript" { +declare namespace ts { function parseCommandLine(commandLine: string[], readFile?: (path: string) => string): ParsedCommandLine; /** * Read tsconfig.json file @@ -1551,7 +1551,7 @@ declare module "typescript" { */ function parseConfigFile(json: any, host: ParseConfigHost, basePath: string): ParsedCommandLine; } -declare module "typescript" { +declare namespace ts { /** The version of the language service API */ let servicesVersion: string; interface Node { @@ -2139,3 +2139,5 @@ declare module "typescript" { */ function getDefaultLibFilePath(options: CompilerOptions): string; } + +export = ts; \ No newline at end of file diff --git a/tests/cases/compiler/APISample_compile.ts b/tests/cases/compiler/APISample_compile.ts index d3cc650dd2a..c63009f7d63 100644 --- a/tests/cases/compiler/APISample_compile.ts +++ b/tests/cases/compiler/APISample_compile.ts @@ -1,5 +1,5 @@ // @module: commonjs -// @includebuiltfile: typescript.d.ts +// @includebuiltfile: typescript_standalone.d.ts // @stripInternal:true /* diff --git a/tests/cases/compiler/APISample_linter.ts b/tests/cases/compiler/APISample_linter.ts index 9f9b55a0a67..8cb6934cee3 100644 --- a/tests/cases/compiler/APISample_linter.ts +++ b/tests/cases/compiler/APISample_linter.ts @@ -1,5 +1,5 @@ // @module: commonjs -// @includebuiltfile: typescript.d.ts +// @includebuiltfile: typescript_standalone.d.ts // @stripInternal:true /* diff --git a/tests/cases/compiler/APISample_transform.ts b/tests/cases/compiler/APISample_transform.ts index 48e27c4e008..88b9754536a 100644 --- a/tests/cases/compiler/APISample_transform.ts +++ b/tests/cases/compiler/APISample_transform.ts @@ -1,5 +1,5 @@ // @module: commonjs -// @includebuiltfile: typescript.d.ts +// @includebuiltfile: typescript_standalone.d.ts // @stripInternal:true /* diff --git a/tests/cases/compiler/APISample_watcher.ts b/tests/cases/compiler/APISample_watcher.ts index b152f86c378..9afa53ddf14 100644 --- a/tests/cases/compiler/APISample_watcher.ts +++ b/tests/cases/compiler/APISample_watcher.ts @@ -1,5 +1,5 @@ // @module: commonjs -// @includebuiltfile: typescript.d.ts +// @includebuiltfile: typescript_standalone.d.ts // @stripInternal:true /* From 5aa17cd671ff56bc9a97f62a76191d640196c17d Mon Sep 17 00:00:00 2001 From: Daniel Rosenwasser Date: Wed, 9 Sep 2015 12:47:31 -0700 Subject: [PATCH 14/28] Added tests for parameter initializers. --- .../emptyVariableDeclarationBindingPatterns01_ES5.ts | 4 ++++ .../emptyVariableDeclarationBindingPatterns01_ES6.ts | 4 ++++ 2 files changed, 8 insertions(+) diff --git a/tests/cases/conformance/es6/destructuring/emptyVariableDeclarationBindingPatterns01_ES5.ts b/tests/cases/conformance/es6/destructuring/emptyVariableDeclarationBindingPatterns01_ES5.ts index dec00737658..bc7a729fd1e 100644 --- a/tests/cases/conformance/es6/destructuring/emptyVariableDeclarationBindingPatterns01_ES5.ts +++ b/tests/cases/conformance/es6/destructuring/emptyVariableDeclarationBindingPatterns01_ES5.ts @@ -21,6 +21,10 @@ for (var {} = {}, {} = {}; false; void 0) { } + + function f({} = a, [] = a, { p: {} = a} = a) { + return ({} = a, [] = a, { p: {} = a } = a) => a; + } })(); (function () { diff --git a/tests/cases/conformance/es6/destructuring/emptyVariableDeclarationBindingPatterns01_ES6.ts b/tests/cases/conformance/es6/destructuring/emptyVariableDeclarationBindingPatterns01_ES6.ts index 9f90dc28998..9f2a9905480 100644 --- a/tests/cases/conformance/es6/destructuring/emptyVariableDeclarationBindingPatterns01_ES6.ts +++ b/tests/cases/conformance/es6/destructuring/emptyVariableDeclarationBindingPatterns01_ES6.ts @@ -21,6 +21,10 @@ for (var {} = {}, {} = {}; false; void 0) { } + + function f({} = a, [] = a, { p: {} = a} = a) { + return ({} = a, [] = a, { p: {} = a } = a) => a; + } })(); (function () { From fb889bee4ee5b4cba2083b12ae878e4833bd2dfd Mon Sep 17 00:00:00 2001 From: Daniel Rosenwasser Date: Wed, 9 Sep 2015 13:05:39 -0700 Subject: [PATCH 15/28] Accepted baselines. --- ...ariableDeclarationBindingPatterns01_ES5.js | 15 ++++++++++ ...leDeclarationBindingPatterns01_ES5.symbols | 29 ++++++++++++++----- ...ableDeclarationBindingPatterns01_ES5.types | 24 +++++++++++++-- ...ariableDeclarationBindingPatterns01_ES6.js | 7 +++++ ...leDeclarationBindingPatterns01_ES6.symbols | 29 ++++++++++++++----- ...ableDeclarationBindingPatterns01_ES6.types | 24 +++++++++++++-- 6 files changed, 108 insertions(+), 20 deletions(-) diff --git a/tests/baselines/reference/emptyVariableDeclarationBindingPatterns01_ES5.js b/tests/baselines/reference/emptyVariableDeclarationBindingPatterns01_ES5.js index 9ce2a04dad4..11c4f4e1807 100644 --- a/tests/baselines/reference/emptyVariableDeclarationBindingPatterns01_ES5.js +++ b/tests/baselines/reference/emptyVariableDeclarationBindingPatterns01_ES5.js @@ -21,6 +21,10 @@ for (var {} = {}, {} = {}; false; void 0) { } + + function f({} = a, [] = a, { p: {} = a} = a) { + return ({} = a, [] = a, { p: {} = a } = a) => a; + } })(); (function () { @@ -62,6 +66,17 @@ var _s = a.p1, _t = a.p2; for (var _u = {}, _v = {}; false; void 0) { } + function f(_a, _b, _c) { + var _a = a; + var _b = a; + var _d = (_c === void 0 ? a : _c).p, _e = _d === void 0 ? a : _d; + return function (_a, _b, _c) { + var _a = a; + var _b = a; + var _d = (_c === void 0 ? a : _c).p, _e = _d === void 0 ? a : _d; + return a; + }; + } })(); (function () { var ns = []; diff --git a/tests/baselines/reference/emptyVariableDeclarationBindingPatterns01_ES5.symbols b/tests/baselines/reference/emptyVariableDeclarationBindingPatterns01_ES5.symbols index f8cc7d2546f..ddba9738e08 100644 --- a/tests/baselines/reference/emptyVariableDeclarationBindingPatterns01_ES5.symbols +++ b/tests/baselines/reference/emptyVariableDeclarationBindingPatterns01_ES5.symbols @@ -45,33 +45,48 @@ for (var {} = {}, {} = {}; false; void 0) { } + + function f({} = a, [] = a, { p: {} = a} = a) { +>f : Symbol(f, Decl(emptyVariableDeclarationBindingPatterns01_ES5.ts, 21, 5)) +>a : Symbol(a, Decl(emptyVariableDeclarationBindingPatterns01_ES5.ts, 2, 7)) +>a : Symbol(a, Decl(emptyVariableDeclarationBindingPatterns01_ES5.ts, 2, 7)) +>a : Symbol(a, Decl(emptyVariableDeclarationBindingPatterns01_ES5.ts, 2, 7)) +>a : Symbol(a, Decl(emptyVariableDeclarationBindingPatterns01_ES5.ts, 2, 7)) + + return ({} = a, [] = a, { p: {} = a } = a) => a; +>a : Symbol(a, Decl(emptyVariableDeclarationBindingPatterns01_ES5.ts, 2, 7)) +>a : Symbol(a, Decl(emptyVariableDeclarationBindingPatterns01_ES5.ts, 2, 7)) +>a : Symbol(a, Decl(emptyVariableDeclarationBindingPatterns01_ES5.ts, 2, 7)) +>a : Symbol(a, Decl(emptyVariableDeclarationBindingPatterns01_ES5.ts, 2, 7)) +>a : Symbol(a, Decl(emptyVariableDeclarationBindingPatterns01_ES5.ts, 2, 7)) + } })(); (function () { const ns: number[][] = []; ->ns : Symbol(ns, Decl(emptyVariableDeclarationBindingPatterns01_ES5.ts, 25, 9)) +>ns : Symbol(ns, Decl(emptyVariableDeclarationBindingPatterns01_ES5.ts, 29, 9)) for (var {} of ns) { ->ns : Symbol(ns, Decl(emptyVariableDeclarationBindingPatterns01_ES5.ts, 25, 9)) +>ns : Symbol(ns, Decl(emptyVariableDeclarationBindingPatterns01_ES5.ts, 29, 9)) } for (let {} of ns) { ->ns : Symbol(ns, Decl(emptyVariableDeclarationBindingPatterns01_ES5.ts, 25, 9)) +>ns : Symbol(ns, Decl(emptyVariableDeclarationBindingPatterns01_ES5.ts, 29, 9)) } for (const {} of ns) { ->ns : Symbol(ns, Decl(emptyVariableDeclarationBindingPatterns01_ES5.ts, 25, 9)) +>ns : Symbol(ns, Decl(emptyVariableDeclarationBindingPatterns01_ES5.ts, 29, 9)) } for (var [] of ns) { ->ns : Symbol(ns, Decl(emptyVariableDeclarationBindingPatterns01_ES5.ts, 25, 9)) +>ns : Symbol(ns, Decl(emptyVariableDeclarationBindingPatterns01_ES5.ts, 29, 9)) } for (let [] of ns) { ->ns : Symbol(ns, Decl(emptyVariableDeclarationBindingPatterns01_ES5.ts, 25, 9)) +>ns : Symbol(ns, Decl(emptyVariableDeclarationBindingPatterns01_ES5.ts, 29, 9)) } for (const [] of ns) { ->ns : Symbol(ns, Decl(emptyVariableDeclarationBindingPatterns01_ES5.ts, 25, 9)) +>ns : Symbol(ns, Decl(emptyVariableDeclarationBindingPatterns01_ES5.ts, 29, 9)) } })(); diff --git a/tests/baselines/reference/emptyVariableDeclarationBindingPatterns01_ES5.types b/tests/baselines/reference/emptyVariableDeclarationBindingPatterns01_ES5.types index b4e3da1454b..ed6b935db0f 100644 --- a/tests/baselines/reference/emptyVariableDeclarationBindingPatterns01_ES5.types +++ b/tests/baselines/reference/emptyVariableDeclarationBindingPatterns01_ES5.types @@ -1,9 +1,9 @@ === tests/cases/conformance/es6/destructuring/emptyVariableDeclarationBindingPatterns01_ES5.ts === (function () { ->(function () { var a: any; var {} = a; let {} = a; const {} = a; var [] = a; let [] = a; const [] = a; var {} = a, [] = a; let {} = a, [] = a; const {} = a, [] = a; var { p1: {}, p2: [] } = a; let { p1: {}, p2: [] } = a; const { p1: {}, p2: [] } = a; for (var {} = {}, {} = {}; false; void 0) { }})() : void ->(function () { var a: any; var {} = a; let {} = a; const {} = a; var [] = a; let [] = a; const [] = a; var {} = a, [] = a; let {} = a, [] = a; const {} = a, [] = a; var { p1: {}, p2: [] } = a; let { p1: {}, p2: [] } = a; const { p1: {}, p2: [] } = a; for (var {} = {}, {} = {}; false; void 0) { }}) : () => void ->function () { var a: any; var {} = a; let {} = a; const {} = a; var [] = a; let [] = a; const [] = a; var {} = a, [] = a; let {} = a, [] = a; const {} = a, [] = a; var { p1: {}, p2: [] } = a; let { p1: {}, p2: [] } = a; const { p1: {}, p2: [] } = a; for (var {} = {}, {} = {}; false; void 0) { }} : () => void +>(function () { var a: any; var {} = a; let {} = a; const {} = a; var [] = a; let [] = a; const [] = a; var {} = a, [] = a; let {} = a, [] = a; const {} = a, [] = a; var { p1: {}, p2: [] } = a; let { p1: {}, p2: [] } = a; const { p1: {}, p2: [] } = a; for (var {} = {}, {} = {}; false; void 0) { } function f({} = a, [] = a, { p: {} = a} = a) { return ({} = a, [] = a, { p: {} = a } = a) => a; }})() : void +>(function () { var a: any; var {} = a; let {} = a; const {} = a; var [] = a; let [] = a; const [] = a; var {} = a, [] = a; let {} = a, [] = a; const {} = a, [] = a; var { p1: {}, p2: [] } = a; let { p1: {}, p2: [] } = a; const { p1: {}, p2: [] } = a; for (var {} = {}, {} = {}; false; void 0) { } function f({} = a, [] = a, { p: {} = a} = a) { return ({} = a, [] = a, { p: {} = a } = a) => a; }}) : () => void +>function () { var a: any; var {} = a; let {} = a; const {} = a; var [] = a; let [] = a; const [] = a; var {} = a, [] = a; let {} = a, [] = a; const {} = a, [] = a; var { p1: {}, p2: [] } = a; let { p1: {}, p2: [] } = a; const { p1: {}, p2: [] } = a; for (var {} = {}, {} = {}; false; void 0) { } function f({} = a, [] = a, { p: {} = a} = a) { return ({} = a, [] = a, { p: {} = a } = a) => a; }} : () => void var a: any; >a : any @@ -60,6 +60,24 @@ >void 0 : undefined >0 : number } + + function f({} = a, [] = a, { p: {} = a} = a) { +>f : ({}?: any, []?: any, { p: {} = a}?: any) => ({}?: any, []?: any, { p: {} = a }?: any) => any +>a : any +>a : any +>p : any +>a : any +>a : any + + return ({} = a, [] = a, { p: {} = a } = a) => a; +>({} = a, [] = a, { p: {} = a } = a) => a : ({}?: any, []?: any, { p: {} = a }?: any) => any +>a : any +>a : any +>p : any +>a : any +>a : any +>a : any + } })(); (function () { diff --git a/tests/baselines/reference/emptyVariableDeclarationBindingPatterns01_ES6.js b/tests/baselines/reference/emptyVariableDeclarationBindingPatterns01_ES6.js index 924303c1976..1303ab1e3d0 100644 --- a/tests/baselines/reference/emptyVariableDeclarationBindingPatterns01_ES6.js +++ b/tests/baselines/reference/emptyVariableDeclarationBindingPatterns01_ES6.js @@ -21,6 +21,10 @@ for (var {} = {}, {} = {}; false; void 0) { } + + function f({} = a, [] = a, { p: {} = a} = a) { + return ({} = a, [] = a, { p: {} = a } = a) => a; + } })(); (function () { @@ -62,6 +66,9 @@ const { p1: { }, p2: [] } = a; for (var { } = {}, { } = {}; false; void 0) { } + function f({ } = a, [] = a, { p: { } = a } = a) { + return ({ } = a, [] = a, { p: { } = a } = a) => a; + } })(); (function () { const ns = []; diff --git a/tests/baselines/reference/emptyVariableDeclarationBindingPatterns01_ES6.symbols b/tests/baselines/reference/emptyVariableDeclarationBindingPatterns01_ES6.symbols index d158e3a4891..6a826d4b6c9 100644 --- a/tests/baselines/reference/emptyVariableDeclarationBindingPatterns01_ES6.symbols +++ b/tests/baselines/reference/emptyVariableDeclarationBindingPatterns01_ES6.symbols @@ -45,33 +45,48 @@ for (var {} = {}, {} = {}; false; void 0) { } + + function f({} = a, [] = a, { p: {} = a} = a) { +>f : Symbol(f, Decl(emptyVariableDeclarationBindingPatterns01_ES6.ts, 21, 5)) +>a : Symbol(a, Decl(emptyVariableDeclarationBindingPatterns01_ES6.ts, 2, 7)) +>a : Symbol(a, Decl(emptyVariableDeclarationBindingPatterns01_ES6.ts, 2, 7)) +>a : Symbol(a, Decl(emptyVariableDeclarationBindingPatterns01_ES6.ts, 2, 7)) +>a : Symbol(a, Decl(emptyVariableDeclarationBindingPatterns01_ES6.ts, 2, 7)) + + return ({} = a, [] = a, { p: {} = a } = a) => a; +>a : Symbol(a, Decl(emptyVariableDeclarationBindingPatterns01_ES6.ts, 2, 7)) +>a : Symbol(a, Decl(emptyVariableDeclarationBindingPatterns01_ES6.ts, 2, 7)) +>a : Symbol(a, Decl(emptyVariableDeclarationBindingPatterns01_ES6.ts, 2, 7)) +>a : Symbol(a, Decl(emptyVariableDeclarationBindingPatterns01_ES6.ts, 2, 7)) +>a : Symbol(a, Decl(emptyVariableDeclarationBindingPatterns01_ES6.ts, 2, 7)) + } })(); (function () { const ns: number[][] = []; ->ns : Symbol(ns, Decl(emptyVariableDeclarationBindingPatterns01_ES6.ts, 25, 9)) +>ns : Symbol(ns, Decl(emptyVariableDeclarationBindingPatterns01_ES6.ts, 29, 9)) for (var {} of ns) { ->ns : Symbol(ns, Decl(emptyVariableDeclarationBindingPatterns01_ES6.ts, 25, 9)) +>ns : Symbol(ns, Decl(emptyVariableDeclarationBindingPatterns01_ES6.ts, 29, 9)) } for (let {} of ns) { ->ns : Symbol(ns, Decl(emptyVariableDeclarationBindingPatterns01_ES6.ts, 25, 9)) +>ns : Symbol(ns, Decl(emptyVariableDeclarationBindingPatterns01_ES6.ts, 29, 9)) } for (const {} of ns) { ->ns : Symbol(ns, Decl(emptyVariableDeclarationBindingPatterns01_ES6.ts, 25, 9)) +>ns : Symbol(ns, Decl(emptyVariableDeclarationBindingPatterns01_ES6.ts, 29, 9)) } for (var [] of ns) { ->ns : Symbol(ns, Decl(emptyVariableDeclarationBindingPatterns01_ES6.ts, 25, 9)) +>ns : Symbol(ns, Decl(emptyVariableDeclarationBindingPatterns01_ES6.ts, 29, 9)) } for (let [] of ns) { ->ns : Symbol(ns, Decl(emptyVariableDeclarationBindingPatterns01_ES6.ts, 25, 9)) +>ns : Symbol(ns, Decl(emptyVariableDeclarationBindingPatterns01_ES6.ts, 29, 9)) } for (const [] of ns) { ->ns : Symbol(ns, Decl(emptyVariableDeclarationBindingPatterns01_ES6.ts, 25, 9)) +>ns : Symbol(ns, Decl(emptyVariableDeclarationBindingPatterns01_ES6.ts, 29, 9)) } })(); diff --git a/tests/baselines/reference/emptyVariableDeclarationBindingPatterns01_ES6.types b/tests/baselines/reference/emptyVariableDeclarationBindingPatterns01_ES6.types index e8dd5025288..fcb48048148 100644 --- a/tests/baselines/reference/emptyVariableDeclarationBindingPatterns01_ES6.types +++ b/tests/baselines/reference/emptyVariableDeclarationBindingPatterns01_ES6.types @@ -1,9 +1,9 @@ === tests/cases/conformance/es6/destructuring/emptyVariableDeclarationBindingPatterns01_ES6.ts === (function () { ->(function () { var a: any; var {} = a; let {} = a; const {} = a; var [] = a; let [] = a; const [] = a; var {} = a, [] = a; let {} = a, [] = a; const {} = a, [] = a; var { p1: {}, p2: [] } = a; let { p1: {}, p2: [] } = a; const { p1: {}, p2: [] } = a; for (var {} = {}, {} = {}; false; void 0) { }})() : void ->(function () { var a: any; var {} = a; let {} = a; const {} = a; var [] = a; let [] = a; const [] = a; var {} = a, [] = a; let {} = a, [] = a; const {} = a, [] = a; var { p1: {}, p2: [] } = a; let { p1: {}, p2: [] } = a; const { p1: {}, p2: [] } = a; for (var {} = {}, {} = {}; false; void 0) { }}) : () => void ->function () { var a: any; var {} = a; let {} = a; const {} = a; var [] = a; let [] = a; const [] = a; var {} = a, [] = a; let {} = a, [] = a; const {} = a, [] = a; var { p1: {}, p2: [] } = a; let { p1: {}, p2: [] } = a; const { p1: {}, p2: [] } = a; for (var {} = {}, {} = {}; false; void 0) { }} : () => void +>(function () { var a: any; var {} = a; let {} = a; const {} = a; var [] = a; let [] = a; const [] = a; var {} = a, [] = a; let {} = a, [] = a; const {} = a, [] = a; var { p1: {}, p2: [] } = a; let { p1: {}, p2: [] } = a; const { p1: {}, p2: [] } = a; for (var {} = {}, {} = {}; false; void 0) { } function f({} = a, [] = a, { p: {} = a} = a) { return ({} = a, [] = a, { p: {} = a } = a) => a; }})() : void +>(function () { var a: any; var {} = a; let {} = a; const {} = a; var [] = a; let [] = a; const [] = a; var {} = a, [] = a; let {} = a, [] = a; const {} = a, [] = a; var { p1: {}, p2: [] } = a; let { p1: {}, p2: [] } = a; const { p1: {}, p2: [] } = a; for (var {} = {}, {} = {}; false; void 0) { } function f({} = a, [] = a, { p: {} = a} = a) { return ({} = a, [] = a, { p: {} = a } = a) => a; }}) : () => void +>function () { var a: any; var {} = a; let {} = a; const {} = a; var [] = a; let [] = a; const [] = a; var {} = a, [] = a; let {} = a, [] = a; const {} = a, [] = a; var { p1: {}, p2: [] } = a; let { p1: {}, p2: [] } = a; const { p1: {}, p2: [] } = a; for (var {} = {}, {} = {}; false; void 0) { } function f({} = a, [] = a, { p: {} = a} = a) { return ({} = a, [] = a, { p: {} = a } = a) => a; }} : () => void var a: any; >a : any @@ -60,6 +60,24 @@ >void 0 : undefined >0 : number } + + function f({} = a, [] = a, { p: {} = a} = a) { +>f : ({}?: any, []?: any, { p: {} = a}?: any) => ({}?: any, []?: any, { p: {} = a }?: any) => any +>a : any +>a : any +>p : any +>a : any +>a : any + + return ({} = a, [] = a, { p: {} = a } = a) => a; +>({} = a, [] = a, { p: {} = a } = a) => a : ({}?: any, []?: any, { p: {} = a }?: any) => any +>a : any +>a : any +>p : any +>a : any +>a : any +>a : any + } })(); (function () { From ee56e60ca0772f292f604f85555a271dfc21095c Mon Sep 17 00:00:00 2001 From: Vladimir Matveev Date: Tue, 8 Sep 2015 18:40:30 -0700 Subject: [PATCH 16/28] do not emit '=' in jsx attribute if initializer is missing --- src/compiler/emitter.ts | 6 ++++-- .../reference/jsxEmitAttributeWithPreserve.js | 7 +++++++ .../reference/jsxEmitAttributeWithPreserve.symbols | 8 ++++++++ .../reference/jsxEmitAttributeWithPreserve.types | 10 ++++++++++ .../baselines/reference/jsxInvalidEsprimaTestSuite.js | 6 +++--- tests/baselines/reference/jsxReactTestSuite.js | 4 ++-- tests/baselines/reference/tsxAttributeResolution6.js | 6 +++--- .../reference/tsxGenericArrowFunctionParsing.js | 2 +- tests/cases/compiler/jsxEmitAttributeWithPreserve.tsx | 4 ++++ 9 files changed, 42 insertions(+), 11 deletions(-) create mode 100644 tests/baselines/reference/jsxEmitAttributeWithPreserve.js create mode 100644 tests/baselines/reference/jsxEmitAttributeWithPreserve.symbols create mode 100644 tests/baselines/reference/jsxEmitAttributeWithPreserve.types create mode 100644 tests/cases/compiler/jsxEmitAttributeWithPreserve.tsx diff --git a/src/compiler/emitter.ts b/src/compiler/emitter.ts index 54c308217da..2d5bda1bba2 100644 --- a/src/compiler/emitter.ts +++ b/src/compiler/emitter.ts @@ -1292,8 +1292,10 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, Promi function jsxEmitPreserve(node: JsxElement|JsxSelfClosingElement) { function emitJsxAttribute(node: JsxAttribute) { emit(node.name); - write("="); - emit(node.initializer); + if (node.initializer) { + write("="); + emit(node.initializer); + } } function emitJsxSpreadAttribute(node: JsxSpreadAttribute) { diff --git a/tests/baselines/reference/jsxEmitAttributeWithPreserve.js b/tests/baselines/reference/jsxEmitAttributeWithPreserve.js new file mode 100644 index 00000000000..07cb0dee485 --- /dev/null +++ b/tests/baselines/reference/jsxEmitAttributeWithPreserve.js @@ -0,0 +1,7 @@ +//// [jsxEmitAttributeWithPreserve.tsx] + +declare var React: any; + + +//// [jsxEmitAttributeWithPreserve.jsx] +; diff --git a/tests/baselines/reference/jsxEmitAttributeWithPreserve.symbols b/tests/baselines/reference/jsxEmitAttributeWithPreserve.symbols new file mode 100644 index 00000000000..4ffadb8e888 --- /dev/null +++ b/tests/baselines/reference/jsxEmitAttributeWithPreserve.symbols @@ -0,0 +1,8 @@ +=== tests/cases/compiler/jsxEmitAttributeWithPreserve.tsx === + +declare var React: any; +>React : Symbol(React, Decl(jsxEmitAttributeWithPreserve.tsx, 1, 11)) + + +>data : Symbol(unknown) + diff --git a/tests/baselines/reference/jsxEmitAttributeWithPreserve.types b/tests/baselines/reference/jsxEmitAttributeWithPreserve.types new file mode 100644 index 00000000000..972ca1c3d88 --- /dev/null +++ b/tests/baselines/reference/jsxEmitAttributeWithPreserve.types @@ -0,0 +1,10 @@ +=== tests/cases/compiler/jsxEmitAttributeWithPreserve.tsx === + +declare var React: any; +>React : any + + +> : any +>foo : any +>data : any + diff --git a/tests/baselines/reference/jsxInvalidEsprimaTestSuite.js b/tests/baselines/reference/jsxInvalidEsprimaTestSuite.js index daf344b08da..d623e127be7 100644 --- a/tests/baselines/reference/jsxInvalidEsprimaTestSuite.js +++ b/tests/baselines/reference/jsxInvalidEsprimaTestSuite.js @@ -47,9 +47,9 @@ a / > ; < a; b > ; b > ; -; +; b.c > ; -; +; c > ; ; < .a > ; @@ -67,7 +67,7 @@ var x =
one
two
;; var x =
one
/* intervening comment */ /* intervening comment */
two
;; {"str"}}; id="b" />; -
>; +
>;
;
stuff
...props}>; diff --git a/tests/baselines/reference/jsxReactTestSuite.js b/tests/baselines/reference/jsxReactTestSuite.js index 300274a1614..18013d4be9b 100644 --- a/tests/baselines/reference/jsxReactTestSuite.js +++ b/tests/baselines/reference/jsxReactTestSuite.js @@ -158,14 +158,14 @@ var x =
; ; ; -; +; ; ; ; ; ; ; -; +; ; ; Text; diff --git a/tests/baselines/reference/tsxAttributeResolution6.js b/tests/baselines/reference/tsxAttributeResolution6.js index f4af0ba875a..5d6ad1e20c6 100644 --- a/tests/baselines/reference/tsxAttributeResolution6.js +++ b/tests/baselines/reference/tsxAttributeResolution6.js @@ -20,10 +20,10 @@ declare module JSX { //// [tsxAttributeResolution6.jsx] // Error -; +; ; ; // OK -; +; ; -; +; diff --git a/tests/baselines/reference/tsxGenericArrowFunctionParsing.js b/tests/baselines/reference/tsxGenericArrowFunctionParsing.js index f493347ca9c..ece48831f8e 100644 --- a/tests/baselines/reference/tsxGenericArrowFunctionParsing.js +++ b/tests/baselines/reference/tsxGenericArrowFunctionParsing.js @@ -42,5 +42,5 @@ x3(); var x4 = () => ; x4.isElement; // This is an element -var x5 = () => ; +var x5 = () => ; x5.isElement; diff --git a/tests/cases/compiler/jsxEmitAttributeWithPreserve.tsx b/tests/cases/compiler/jsxEmitAttributeWithPreserve.tsx new file mode 100644 index 00000000000..dc32ef7a0ca --- /dev/null +++ b/tests/cases/compiler/jsxEmitAttributeWithPreserve.tsx @@ -0,0 +1,4 @@ +//@jsx: preserve + +declare var React: any; + \ No newline at end of file From 7e1739604a81b9f18ee43b96b1801e9cbfda10bb Mon Sep 17 00:00:00 2001 From: Mohamed Hegazy Date: Thu, 10 Sep 2015 13:24:45 -0700 Subject: [PATCH 17/28] Fix #4727: prerocess `export import` declarations correctelly --- src/services/services.ts | 20 +++++++++++++++++++ .../unittests/services/preProcessFile.ts | 14 +++++++++++++ 2 files changed, 34 insertions(+) diff --git a/src/services/services.ts b/src/services/services.ts index b174f240875..58f59843078 100644 --- a/src/services/services.ts +++ b/src/services/services.ts @@ -2152,6 +2152,7 @@ namespace ts { // // export * from "mod" // export {a as b} from "mod" + // export import i = require("mod") while (token !== SyntaxKind.EndOfFileToken) { if (token === SyntaxKind.DeclareKeyword) { @@ -2276,6 +2277,25 @@ namespace ts { } } } + else if (token === SyntaxKind.ImportKeyword) { + token = scanner.scan(); + if (token === SyntaxKind.Identifier || isKeyword(token)) { + token = scanner.scan(); + if (token === SyntaxKind.EqualsToken) { + token = scanner.scan(); + if (token === SyntaxKind.RequireKeyword) { + token = scanner.scan(); + if (token === SyntaxKind.OpenParenToken) { + token = scanner.scan(); + if (token === SyntaxKind.StringLiteral) { + // export import i = require("mod"); + recordModuleName(); + } + } + } + } + } + } } token = scanner.scan(); } diff --git a/tests/cases/unittests/services/preProcessFile.ts b/tests/cases/unittests/services/preProcessFile.ts index 982c45f0f2d..7b645069212 100644 --- a/tests/cases/unittests/services/preProcessFile.ts +++ b/tests/cases/unittests/services/preProcessFile.ts @@ -173,6 +173,20 @@ describe('PreProcessFile:', function () { isLibFile: false }) }); + + it("Correctly handeles export import declarations", function () { + test("export import a = require(\"m1\");", + true, + { + referencedFiles: [], + importedFiles: [ + { fileName: "m1", pos: 26, end: 28 } + ], + ambientExternalModules: undefined, + isLibFile: false + }) + }); + }); }); From fae7a129eb91e66d7a32bbfddfec1d0c24ce66dc Mon Sep 17 00:00:00 2001 From: Daniel Rosenwasser Date: Thu, 10 Sep 2015 13:50:12 -0700 Subject: [PATCH 18/28] Assert condition to track root cause of issue. --- src/compiler/commandLineParser.ts | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/compiler/commandLineParser.ts b/src/compiler/commandLineParser.ts index c56a18b3ab2..c9df1747999 100644 --- a/src/compiler/commandLineParser.ts +++ b/src/compiler/commandLineParser.ts @@ -326,9 +326,12 @@ namespace ts { if (hasProperty(map, key)) { options[opt.name] = map[key]; } - else { + else if (opt.error) { errors.push(createCompilerDiagnostic(opt.error)); } + else { + Debug.fail(`Command line option for '${opt.name}' doesn't account for invalid options.`); + } } } else { From c18051d5fff0ed5e2f0904a81b6eed28f7bc7368 Mon Sep 17 00:00:00 2001 From: Mohamed Hegazy Date: Thu, 10 Sep 2015 14:22:31 -0700 Subject: [PATCH 19/28] Update version to 1.6.2 --- package.json | 2 +- src/compiler/program.ts | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index abd81e12f47..8ce9989b617 100644 --- a/package.json +++ b/package.json @@ -2,7 +2,7 @@ "name": "typescript", "author": "Microsoft Corp.", "homepage": "http://typescriptlang.org/", - "version": "1.6.0", + "version": "1.6.2", "license": "Apache-2.0", "description": "TypeScript is a language for application scale JavaScript development", "keywords": [ diff --git a/src/compiler/program.ts b/src/compiler/program.ts index a1861f6b462..c239b18efb7 100644 --- a/src/compiler/program.ts +++ b/src/compiler/program.ts @@ -12,7 +12,7 @@ namespace ts { let emptyArray: any[] = []; - export const version = "1.6.0"; + export const version = "1.6.2"; export function findConfigFile(searchPath: string): string { let fileName = "tsconfig.json"; From 4b15c5f6281f6022eda2433382bbc19dc225b1cc Mon Sep 17 00:00:00 2001 From: Daniel Rosenwasser Date: Thu, 10 Sep 2015 14:23:33 -0700 Subject: [PATCH 20/28] Added error for bad argument, fixed diagnostic for '--help' message. --- src/compiler/commandLineParser.ts | 5 +++-- src/compiler/diagnosticInformationMap.generated.ts | 3 ++- src/compiler/diagnosticMessages.json | 7 ++++++- 3 files changed, 11 insertions(+), 4 deletions(-) diff --git a/src/compiler/commandLineParser.ts b/src/compiler/commandLineParser.ts index c9df1747999..93153e5fddb 100644 --- a/src/compiler/commandLineParser.ts +++ b/src/compiler/commandLineParser.ts @@ -243,8 +243,9 @@ namespace ts { "node": ModuleResolutionKind.NodeJs, "classic": ModuleResolutionKind.Classic }, - description: Diagnostics.Specifies_module_resolution_strategy_Colon_node_Node_or_classic_TypeScript_pre_1_6 - } + description: Diagnostics.Specifies_module_resolution_strategy_Colon_node_Node_js_or_classic_TypeScript_pre_1_6, + error: Diagnostics.Argument_for_moduleResolution_option_must_be_node_or_classic, + } ]; /* @internal */ diff --git a/src/compiler/diagnosticInformationMap.generated.ts b/src/compiler/diagnosticInformationMap.generated.ts index f7351bf6912..1c9232d1515 100644 --- a/src/compiler/diagnosticInformationMap.generated.ts +++ b/src/compiler/diagnosticInformationMap.generated.ts @@ -560,13 +560,14 @@ namespace ts { Specifies_the_end_of_line_sequence_to_be_used_when_emitting_files_Colon_CRLF_dos_or_LF_unix: { code: 6060, category: DiagnosticCategory.Message, key: "Specifies the end of line sequence to be used when emitting files: 'CRLF' (dos) or 'LF' (unix)." }, NEWLINE: { code: 6061, category: DiagnosticCategory.Message, key: "NEWLINE" }, Argument_for_newLine_option_must_be_CRLF_or_LF: { code: 6062, category: DiagnosticCategory.Error, key: "Argument for '--newLine' option must be 'CRLF' or 'LF'." }, + Argument_for_moduleResolution_option_must_be_node_or_classic: { code: 6063, category: DiagnosticCategory.Error, key: "Argument for '--moduleResolution' option must be 'node' or 'classic'." }, Specify_JSX_code_generation_Colon_preserve_or_react: { code: 6080, category: DiagnosticCategory.Message, key: "Specify JSX code generation: 'preserve' or 'react'" }, Argument_for_jsx_must_be_preserve_or_react: { code: 6081, category: DiagnosticCategory.Message, key: "Argument for '--jsx' must be 'preserve' or 'react'." }, Enables_experimental_support_for_ES7_decorators: { code: 6065, category: DiagnosticCategory.Message, key: "Enables experimental support for ES7 decorators." }, Enables_experimental_support_for_emitting_type_metadata_for_decorators: { code: 6066, category: DiagnosticCategory.Message, key: "Enables experimental support for emitting type metadata for decorators." }, Option_experimentalAsyncFunctions_cannot_be_specified_when_targeting_ES5_or_lower: { code: 6067, category: DiagnosticCategory.Message, key: "Option 'experimentalAsyncFunctions' cannot be specified when targeting ES5 or lower." }, Enables_experimental_support_for_ES7_async_functions: { code: 6068, category: DiagnosticCategory.Message, key: "Enables experimental support for ES7 async functions." }, - Specifies_module_resolution_strategy_Colon_node_Node_or_classic_TypeScript_pre_1_6: { code: 6069, category: DiagnosticCategory.Message, key: "Specifies module resolution strategy: 'node' (Node) or 'classic' (TypeScript pre 1.6) ." }, + Specifies_module_resolution_strategy_Colon_node_Node_js_or_classic_TypeScript_pre_1_6: { code: 6069, category: DiagnosticCategory.Message, key: "Specifies module resolution strategy: 'node' (Node.js) or 'classic' (TypeScript pre-1.6)." }, Initializes_a_TypeScript_project_and_creates_a_tsconfig_json_file: { code: 6070, category: DiagnosticCategory.Message, key: "Initializes a TypeScript project and creates a tsconfig.json file." }, Successfully_created_a_tsconfig_json_file: { code: 6071, category: DiagnosticCategory.Message, key: "Successfully created a tsconfig.json file." }, Suppress_excess_property_checks_for_object_literals: { code: 6072, category: DiagnosticCategory.Message, key: "Suppress excess property checks for object literals." }, diff --git a/src/compiler/diagnosticMessages.json b/src/compiler/diagnosticMessages.json index 9fd08ef9bca..f6875c45c47 100644 --- a/src/compiler/diagnosticMessages.json +++ b/src/compiler/diagnosticMessages.json @@ -2230,6 +2230,11 @@ "category": "Error", "code": 6062 }, + "Argument for '--moduleResolution' option must be 'node' or 'classic'.": { + "category": "Error", + "code": 6063 + }, + "Specify JSX code generation: 'preserve' or 'react'": { "category": "Message", "code": 6080 @@ -2254,7 +2259,7 @@ "category": "Message", "code": 6068 }, - "Specifies module resolution strategy: 'node' (Node) or 'classic' (TypeScript pre 1.6) .": { + "Specifies module resolution strategy: 'node' (Node.js) or 'classic' (TypeScript pre-1.6).": { "category": "Message", "code": 6069 }, From 535efd1b5de9cf86a6bf04a4a003f01c5c0d215b Mon Sep 17 00:00:00 2001 From: Daniel Rosenwasser Date: Thu, 10 Sep 2015 14:23:56 -0700 Subject: [PATCH 21/28] Encode the conditional presence of 'error' in the type system. --- src/compiler/commandLineParser.ts | 7 ++----- src/compiler/types.ts | 17 +++++++++++++++-- 2 files changed, 17 insertions(+), 7 deletions(-) diff --git a/src/compiler/commandLineParser.ts b/src/compiler/commandLineParser.ts index 93153e5fddb..9b7558f315a 100644 --- a/src/compiler/commandLineParser.ts +++ b/src/compiler/commandLineParser.ts @@ -327,11 +327,8 @@ namespace ts { if (hasProperty(map, key)) { options[opt.name] = map[key]; } - else if (opt.error) { - errors.push(createCompilerDiagnostic(opt.error)); - } else { - Debug.fail(`Command line option for '${opt.name}' doesn't account for invalid options.`); + errors.push(createCompilerDiagnostic((opt).error)); } } } @@ -444,7 +441,7 @@ namespace ts { value = optType[key]; } else { - errors.push(createCompilerDiagnostic(opt.error)); + errors.push(createCompilerDiagnostic((opt).error)); value = 0; } } diff --git a/src/compiler/types.ts b/src/compiler/types.ts index 47182e39527..f9d1b506274 100644 --- a/src/compiler/types.ts +++ b/src/compiler/types.ts @@ -2112,17 +2112,30 @@ namespace ts { } /* @internal */ - export interface CommandLineOption { + interface CommandLineOptionBase { name: string; type: string | Map; // "string", "number", "boolean", or an object literal mapping named values to actual values isFilePath?: boolean; // True if option value is a path or fileName shortName?: string; // A short mnemonic for convenience - for instance, 'h' can be used in place of 'help' description?: DiagnosticMessage; // The message describing what the command line switch does paramType?: DiagnosticMessage; // The name to be used for a non-boolean option's parameter - error?: DiagnosticMessage; // The error given when the argument does not fit a customized 'type' experimental?: boolean; } + /* @internal */ + export interface CommandLineOptionOfPrimitiveType extends CommandLineOptionBase { + type: string; // "string" | "number" | "boolean" + } + + /* @internal */ + export interface CommandLineOptionOfCustomType extends CommandLineOptionBase { + type: Map; // an object literal mapping named values to actual values + error: DiagnosticMessage; // The error given when the argument does not fit a customized 'type' + } + + /* @internal */ + export type CommandLineOption = CommandLineOptionOfCustomType | CommandLineOptionOfPrimitiveType; + /* @internal */ export const enum CharacterCodes { nullCharacter = 0, From 50e122f90162d3715287268633536da5bfc0331f Mon Sep 17 00:00:00 2001 From: Mohamed Hegazy Date: Thu, 10 Sep 2015 15:19:59 -0700 Subject: [PATCH 22/28] Update LKG --- lib/lib.d.ts | 32 ++++- lib/lib.dom.d.ts | 32 ++++- lib/lib.es6.d.ts | 32 ++++- lib/lib.webworker.d.ts | 32 ++++- lib/tsc.js | 143 +++++++++++---------- lib/tsserver.js | 215 +++++++++++++++++++------------- lib/typescript.js | 252 ++++++++++++++++++++++++-------------- lib/typescriptServices.js | 252 ++++++++++++++++++++++++-------------- 8 files changed, 653 insertions(+), 337 deletions(-) diff --git a/lib/lib.d.ts b/lib/lib.d.ts index c55970d9aca..d25e29bddb4 100644 --- a/lib/lib.d.ts +++ b/lib/lib.d.ts @@ -3928,6 +3928,7 @@ declare module Intl { timeZoneName?: string; formatMatcher?: string; hour12?: boolean; + timeZone?: string; } interface ResolvedDateTimeFormatOptions { @@ -3997,18 +3998,45 @@ interface Number { interface Date { /** - * Converts a date to a string by using the current or specified locale. + * Converts a date and time to a string by using the current or specified locale. * @param locales An array of locale strings that contain one or more language or locale tags. If you include more than one locale string, list them in descending order of priority so that the first entry is the preferred locale. If you omit this parameter, the default locale of the JavaScript runtime is used. * @param options An object that contains one or more properties that specify comparison options. */ toLocaleString(locales?: string[], options?: Intl.DateTimeFormatOptions): string; + /** + * Converts a date to a string by using the current or specified locale. + * @param locales An array of locale strings that contain one or more language or locale tags. If you include more than one locale string, list them in descending order of priority so that the first entry is the preferred locale. If you omit this parameter, the default locale of the JavaScript runtime is used. + * @param options An object that contains one or more properties that specify comparison options. + */ + toLocaleDateString(locales?: string[], options?: Intl.DateTimeFormatOptions): string; + /** + * Converts a time to a string by using the current or specified locale. + * @param locale Locale tag. If you omit this parameter, the default locale of the JavaScript runtime is used. + * @param options An object that contains one or more properties that specify comparison options. + */ + toLocaleTimeString(locale?: string[], options?: Intl.DateTimeFormatOptions): string; + + /** + * Converts a date and time to a string by using the current or specified locale. + * @param locale Locale tag. If you omit this parameter, the default locale of the JavaScript runtime is used. + * @param options An object that contains one or more properties that specify comparison options. + */ + toLocaleString(locale?: string, options?: Intl.DateTimeFormatOptions): string; + /** * Converts a date to a string by using the current or specified locale. * @param locale Locale tag. If you omit this parameter, the default locale of the JavaScript runtime is used. * @param options An object that contains one or more properties that specify comparison options. */ - toLocaleString(locale?: string, options?: Intl.DateTimeFormatOptions): string; + toLocaleDateString(locale?: string, options?: Intl.DateTimeFormatOptions): string; + + /** + * Converts a time to a string by using the current or specified locale. + * @param locale Locale tag. If you omit this parameter, the default locale of the JavaScript runtime is used. + * @param options An object that contains one or more properties that specify comparison options. + */ + toLocaleTimeString(locale?: string, options?: Intl.DateTimeFormatOptions): string; } diff --git a/lib/lib.dom.d.ts b/lib/lib.dom.d.ts index 54461afef40..76e5f1b20a1 100644 --- a/lib/lib.dom.d.ts +++ b/lib/lib.dom.d.ts @@ -104,6 +104,7 @@ declare module Intl { timeZoneName?: string; formatMatcher?: string; hour12?: boolean; + timeZone?: string; } interface ResolvedDateTimeFormatOptions { @@ -173,18 +174,45 @@ interface Number { interface Date { /** - * Converts a date to a string by using the current or specified locale. + * Converts a date and time to a string by using the current or specified locale. * @param locales An array of locale strings that contain one or more language or locale tags. If you include more than one locale string, list them in descending order of priority so that the first entry is the preferred locale. If you omit this parameter, the default locale of the JavaScript runtime is used. * @param options An object that contains one or more properties that specify comparison options. */ toLocaleString(locales?: string[], options?: Intl.DateTimeFormatOptions): string; + /** + * Converts a date to a string by using the current or specified locale. + * @param locales An array of locale strings that contain one or more language or locale tags. If you include more than one locale string, list them in descending order of priority so that the first entry is the preferred locale. If you omit this parameter, the default locale of the JavaScript runtime is used. + * @param options An object that contains one or more properties that specify comparison options. + */ + toLocaleDateString(locales?: string[], options?: Intl.DateTimeFormatOptions): string; + /** + * Converts a time to a string by using the current or specified locale. + * @param locale Locale tag. If you omit this parameter, the default locale of the JavaScript runtime is used. + * @param options An object that contains one or more properties that specify comparison options. + */ + toLocaleTimeString(locale?: string[], options?: Intl.DateTimeFormatOptions): string; + + /** + * Converts a date and time to a string by using the current or specified locale. + * @param locale Locale tag. If you omit this parameter, the default locale of the JavaScript runtime is used. + * @param options An object that contains one or more properties that specify comparison options. + */ + toLocaleString(locale?: string, options?: Intl.DateTimeFormatOptions): string; + /** * Converts a date to a string by using the current or specified locale. * @param locale Locale tag. If you omit this parameter, the default locale of the JavaScript runtime is used. * @param options An object that contains one or more properties that specify comparison options. */ - toLocaleString(locale?: string, options?: Intl.DateTimeFormatOptions): string; + toLocaleDateString(locale?: string, options?: Intl.DateTimeFormatOptions): string; + + /** + * Converts a time to a string by using the current or specified locale. + * @param locale Locale tag. If you omit this parameter, the default locale of the JavaScript runtime is used. + * @param options An object that contains one or more properties that specify comparison options. + */ + toLocaleTimeString(locale?: string, options?: Intl.DateTimeFormatOptions): string; } diff --git a/lib/lib.es6.d.ts b/lib/lib.es6.d.ts index de051a44edd..507f0da5004 100644 --- a/lib/lib.es6.d.ts +++ b/lib/lib.es6.d.ts @@ -5216,6 +5216,7 @@ declare module Intl { timeZoneName?: string; formatMatcher?: string; hour12?: boolean; + timeZone?: string; } interface ResolvedDateTimeFormatOptions { @@ -5285,18 +5286,45 @@ interface Number { interface Date { /** - * Converts a date to a string by using the current or specified locale. + * Converts a date and time to a string by using the current or specified locale. * @param locales An array of locale strings that contain one or more language or locale tags. If you include more than one locale string, list them in descending order of priority so that the first entry is the preferred locale. If you omit this parameter, the default locale of the JavaScript runtime is used. * @param options An object that contains one or more properties that specify comparison options. */ toLocaleString(locales?: string[], options?: Intl.DateTimeFormatOptions): string; + /** + * Converts a date to a string by using the current or specified locale. + * @param locales An array of locale strings that contain one or more language or locale tags. If you include more than one locale string, list them in descending order of priority so that the first entry is the preferred locale. If you omit this parameter, the default locale of the JavaScript runtime is used. + * @param options An object that contains one or more properties that specify comparison options. + */ + toLocaleDateString(locales?: string[], options?: Intl.DateTimeFormatOptions): string; + /** + * Converts a time to a string by using the current or specified locale. + * @param locale Locale tag. If you omit this parameter, the default locale of the JavaScript runtime is used. + * @param options An object that contains one or more properties that specify comparison options. + */ + toLocaleTimeString(locale?: string[], options?: Intl.DateTimeFormatOptions): string; + + /** + * Converts a date and time to a string by using the current or specified locale. + * @param locale Locale tag. If you omit this parameter, the default locale of the JavaScript runtime is used. + * @param options An object that contains one or more properties that specify comparison options. + */ + toLocaleString(locale?: string, options?: Intl.DateTimeFormatOptions): string; + /** * Converts a date to a string by using the current or specified locale. * @param locale Locale tag. If you omit this parameter, the default locale of the JavaScript runtime is used. * @param options An object that contains one or more properties that specify comparison options. */ - toLocaleString(locale?: string, options?: Intl.DateTimeFormatOptions): string; + toLocaleDateString(locale?: string, options?: Intl.DateTimeFormatOptions): string; + + /** + * Converts a time to a string by using the current or specified locale. + * @param locale Locale tag. If you omit this parameter, the default locale of the JavaScript runtime is used. + * @param options An object that contains one or more properties that specify comparison options. + */ + toLocaleTimeString(locale?: string, options?: Intl.DateTimeFormatOptions): string; } diff --git a/lib/lib.webworker.d.ts b/lib/lib.webworker.d.ts index 0f3e85da9f1..56e08ff6efc 100644 --- a/lib/lib.webworker.d.ts +++ b/lib/lib.webworker.d.ts @@ -104,6 +104,7 @@ declare module Intl { timeZoneName?: string; formatMatcher?: string; hour12?: boolean; + timeZone?: string; } interface ResolvedDateTimeFormatOptions { @@ -173,18 +174,45 @@ interface Number { interface Date { /** - * Converts a date to a string by using the current or specified locale. + * Converts a date and time to a string by using the current or specified locale. * @param locales An array of locale strings that contain one or more language or locale tags. If you include more than one locale string, list them in descending order of priority so that the first entry is the preferred locale. If you omit this parameter, the default locale of the JavaScript runtime is used. * @param options An object that contains one or more properties that specify comparison options. */ toLocaleString(locales?: string[], options?: Intl.DateTimeFormatOptions): string; + /** + * Converts a date to a string by using the current or specified locale. + * @param locales An array of locale strings that contain one or more language or locale tags. If you include more than one locale string, list them in descending order of priority so that the first entry is the preferred locale. If you omit this parameter, the default locale of the JavaScript runtime is used. + * @param options An object that contains one or more properties that specify comparison options. + */ + toLocaleDateString(locales?: string[], options?: Intl.DateTimeFormatOptions): string; + /** + * Converts a time to a string by using the current or specified locale. + * @param locale Locale tag. If you omit this parameter, the default locale of the JavaScript runtime is used. + * @param options An object that contains one or more properties that specify comparison options. + */ + toLocaleTimeString(locale?: string[], options?: Intl.DateTimeFormatOptions): string; + + /** + * Converts a date and time to a string by using the current or specified locale. + * @param locale Locale tag. If you omit this parameter, the default locale of the JavaScript runtime is used. + * @param options An object that contains one or more properties that specify comparison options. + */ + toLocaleString(locale?: string, options?: Intl.DateTimeFormatOptions): string; + /** * Converts a date to a string by using the current or specified locale. * @param locale Locale tag. If you omit this parameter, the default locale of the JavaScript runtime is used. * @param options An object that contains one or more properties that specify comparison options. */ - toLocaleString(locale?: string, options?: Intl.DateTimeFormatOptions): string; + toLocaleDateString(locale?: string, options?: Intl.DateTimeFormatOptions): string; + + /** + * Converts a time to a string by using the current or specified locale. + * @param locale Locale tag. If you omit this parameter, the default locale of the JavaScript runtime is used. + * @param options An object that contains one or more properties that specify comparison options. + */ + toLocaleTimeString(locale?: string, options?: Intl.DateTimeFormatOptions): string; } diff --git a/lib/tsc.js b/lib/tsc.js index 591a22bceb9..019ef143cc8 100644 --- a/lib/tsc.js +++ b/lib/tsc.js @@ -1564,13 +1564,14 @@ var ts; Specifies_the_end_of_line_sequence_to_be_used_when_emitting_files_Colon_CRLF_dos_or_LF_unix: { code: 6060, category: ts.DiagnosticCategory.Message, key: "Specifies the end of line sequence to be used when emitting files: 'CRLF' (dos) or 'LF' (unix)." }, NEWLINE: { code: 6061, category: ts.DiagnosticCategory.Message, key: "NEWLINE" }, Argument_for_newLine_option_must_be_CRLF_or_LF: { code: 6062, category: ts.DiagnosticCategory.Error, key: "Argument for '--newLine' option must be 'CRLF' or 'LF'." }, + Argument_for_moduleResolution_option_must_be_node_or_classic: { code: 6063, category: ts.DiagnosticCategory.Error, key: "Argument for '--moduleResolution' option must be 'node' or 'classic'." }, Specify_JSX_code_generation_Colon_preserve_or_react: { code: 6080, category: ts.DiagnosticCategory.Message, key: "Specify JSX code generation: 'preserve' or 'react'" }, Argument_for_jsx_must_be_preserve_or_react: { code: 6081, category: ts.DiagnosticCategory.Message, key: "Argument for '--jsx' must be 'preserve' or 'react'." }, Enables_experimental_support_for_ES7_decorators: { code: 6065, category: ts.DiagnosticCategory.Message, key: "Enables experimental support for ES7 decorators." }, Enables_experimental_support_for_emitting_type_metadata_for_decorators: { code: 6066, category: ts.DiagnosticCategory.Message, key: "Enables experimental support for emitting type metadata for decorators." }, Option_experimentalAsyncFunctions_cannot_be_specified_when_targeting_ES5_or_lower: { code: 6067, category: ts.DiagnosticCategory.Message, key: "Option 'experimentalAsyncFunctions' cannot be specified when targeting ES5 or lower." }, Enables_experimental_support_for_ES7_async_functions: { code: 6068, category: ts.DiagnosticCategory.Message, key: "Enables experimental support for ES7 async functions." }, - Specifies_module_resolution_strategy_Colon_node_Node_or_classic_TypeScript_pre_1_6: { code: 6069, category: ts.DiagnosticCategory.Message, key: "Specifies module resolution strategy: 'node' (Node) or 'classic' (TypeScript pre 1.6) ." }, + Specifies_module_resolution_strategy_Colon_node_Node_js_or_classic_TypeScript_pre_1_6: { code: 6069, category: ts.DiagnosticCategory.Message, key: "Specifies module resolution strategy: 'node' (Node.js) or 'classic' (TypeScript pre-1.6)." }, Initializes_a_TypeScript_project_and_creates_a_tsconfig_json_file: { code: 6070, category: ts.DiagnosticCategory.Message, key: "Initializes a TypeScript project and creates a tsconfig.json file." }, Successfully_created_a_tsconfig_json_file: { code: 6071, category: ts.DiagnosticCategory.Message, key: "Successfully created a tsconfig.json file." }, Suppress_excess_property_checks_for_object_literals: { code: 6072, category: ts.DiagnosticCategory.Message, key: "Suppress excess property checks for object literals." }, @@ -14049,6 +14050,7 @@ var ts; var prop = _a[_i]; if (!isKnownProperty(target, prop.name)) { if (reportErrors) { + errorNode = prop.valueDeclaration; reportError(ts.Diagnostics.Object_literal_may_only_specify_known_properties_and_0_does_not_exist_in_type_1, symbolToString(prop), typeToString(target)); } return true; @@ -20970,7 +20972,10 @@ var ts; var symbols = []; var name_15 = symbol.name; ts.forEach(getSymbolLinks(symbol).containingType.types, function (t) { - symbols.push(getPropertyOfType(t, name_15)); + var symbol = getPropertyOfType(t, name_15); + if (symbol) { + symbols.push(symbol); + } }); return symbols; } @@ -24505,8 +24510,10 @@ var ts; function jsxEmitPreserve(node) { function emitJsxAttribute(node) { emit(node.name); - write("="); - emit(node.initializer); + if (node.initializer) { + write("="); + emit(node.initializer); + } } function emitJsxSpreadAttribute(node) { write("{..."); @@ -26029,19 +26036,19 @@ var ts; write(")"); } } - function ensureIdentifier(expr) { - if (expr.kind !== 67) { - var identifier = createTempVariable(0); - if (!canDefineTempVariablesInPlace) { - recordTempDeclaration(identifier); - } - emitAssignment(identifier, expr); - expr = identifier; + function ensureIdentifier(expr, reuseIdentifierExpressions) { + if (expr.kind === 67 && reuseIdentifierExpressions) { + return expr; } - return expr; + var identifier = createTempVariable(0); + if (!canDefineTempVariablesInPlace) { + recordTempDeclaration(identifier); + } + emitAssignment(identifier, expr); + return identifier; } function createDefaultValueCheck(value, defaultValue) { - value = ensureIdentifier(value); + value = ensureIdentifier(value, true); var equals = ts.createSynthesizedNode(179); equals.left = value; equals.operatorToken = ts.createSynthesizedNode(32); @@ -26082,7 +26089,7 @@ var ts; function emitObjectLiteralAssignment(target, value) { var properties = target.properties; if (properties.length !== 1) { - value = ensureIdentifier(value); + value = ensureIdentifier(value, true); } for (var _a = 0; _a < properties.length; _a++) { var p = properties[_a]; @@ -26095,7 +26102,7 @@ var ts; function emitArrayLiteralAssignment(target, value) { var elements = target.elements; if (elements.length !== 1) { - value = ensureIdentifier(value); + value = ensureIdentifier(value, true); } for (var i = 0; i < elements.length; i++) { var e = elements[i]; @@ -26137,7 +26144,7 @@ var ts; if (root.parent.kind !== 170) { write("("); } - value = ensureIdentifier(value); + value = ensureIdentifier(value, true); emitDestructuringAssignment(target, value); write(", "); emit(value); @@ -26156,10 +26163,11 @@ var ts; if (ts.isBindingPattern(target.name)) { var pattern = target.name; var elements = pattern.elements; - if (elements.length !== 1) { - value = ensureIdentifier(value); + var numElements = elements.length; + if (numElements !== 1) { + value = ensureIdentifier(value, numElements !== 0); } - for (var i = 0; i < elements.length; i++) { + for (var i = 0; i < numElements; i++) { var element = elements[i]; if (pattern.kind === 159) { var propName = element.propertyName || element.name; @@ -26169,7 +26177,7 @@ var ts; if (!element.dotDotDotToken) { emitBindingElement(element, createElementAccessExpression(value, createNumericLiteral(i))); } - else if (i === elements.length - 1) { + else if (i === numElements - 1) { emitBindingElement(element, createSliceCall(value, i)); } } @@ -27289,50 +27297,49 @@ var ts; write("void 0"); } function emitSerializedTypeNode(node) { - if (!node) { - return; - } - switch (node.kind) { - case 101: - write("void 0"); - return; - case 158: - emitSerializedTypeNode(node.type); - return; - case 150: - case 151: - write("Function"); - return; - case 154: - case 155: - write("Array"); - return; - case 148: - case 118: - write("Boolean"); - return; - case 128: - case 9: - write("String"); - return; - case 126: - write("Number"); - return; - case 129: - write("Symbol"); - return; - case 149: - emitSerializedTypeReferenceNode(node); - return; - case 152: - case 153: - case 156: - case 157: - case 115: - break; - default: - ts.Debug.fail("Cannot serialize unexpected type node."); - break; + if (node) { + switch (node.kind) { + case 101: + write("void 0"); + return; + case 158: + emitSerializedTypeNode(node.type); + return; + case 150: + case 151: + write("Function"); + return; + case 154: + case 155: + write("Array"); + return; + case 148: + case 118: + write("Boolean"); + return; + case 128: + case 9: + write("String"); + return; + case 126: + write("Number"); + return; + case 129: + write("Symbol"); + return; + case 149: + emitSerializedTypeReferenceNode(node); + return; + case 152: + case 153: + case 156: + case 157: + case 115: + break; + default: + ts.Debug.fail("Cannot serialize unexpected type node."); + break; + } } write("Object"); } @@ -29332,7 +29339,7 @@ var ts; ts.ioReadTime = 0; ts.ioWriteTime = 0; var emptyArray = []; - ts.version = "1.6.0"; + ts.version = "1.6.2"; function findConfigFile(searchPath) { var fileName = "tsconfig.json"; while (true) { @@ -30397,8 +30404,8 @@ var ts; "node": 2, "classic": 1 }, - experimental: true, - description: ts.Diagnostics.Specifies_module_resolution_strategy_Colon_node_Node_or_classic_TypeScript_pre_1_6 + description: ts.Diagnostics.Specifies_module_resolution_strategy_Colon_node_Node_js_or_classic_TypeScript_pre_1_6, + error: ts.Diagnostics.Argument_for_moduleResolution_option_must_be_node_or_classic } ]; var optionNameMapCache; diff --git a/lib/tsserver.js b/lib/tsserver.js index 78836160678..fc5f34dec2a 100644 --- a/lib/tsserver.js +++ b/lib/tsserver.js @@ -1564,13 +1564,14 @@ var ts; Specifies_the_end_of_line_sequence_to_be_used_when_emitting_files_Colon_CRLF_dos_or_LF_unix: { code: 6060, category: ts.DiagnosticCategory.Message, key: "Specifies the end of line sequence to be used when emitting files: 'CRLF' (dos) or 'LF' (unix)." }, NEWLINE: { code: 6061, category: ts.DiagnosticCategory.Message, key: "NEWLINE" }, Argument_for_newLine_option_must_be_CRLF_or_LF: { code: 6062, category: ts.DiagnosticCategory.Error, key: "Argument for '--newLine' option must be 'CRLF' or 'LF'." }, + Argument_for_moduleResolution_option_must_be_node_or_classic: { code: 6063, category: ts.DiagnosticCategory.Error, key: "Argument for '--moduleResolution' option must be 'node' or 'classic'." }, Specify_JSX_code_generation_Colon_preserve_or_react: { code: 6080, category: ts.DiagnosticCategory.Message, key: "Specify JSX code generation: 'preserve' or 'react'" }, Argument_for_jsx_must_be_preserve_or_react: { code: 6081, category: ts.DiagnosticCategory.Message, key: "Argument for '--jsx' must be 'preserve' or 'react'." }, Enables_experimental_support_for_ES7_decorators: { code: 6065, category: ts.DiagnosticCategory.Message, key: "Enables experimental support for ES7 decorators." }, Enables_experimental_support_for_emitting_type_metadata_for_decorators: { code: 6066, category: ts.DiagnosticCategory.Message, key: "Enables experimental support for emitting type metadata for decorators." }, Option_experimentalAsyncFunctions_cannot_be_specified_when_targeting_ES5_or_lower: { code: 6067, category: ts.DiagnosticCategory.Message, key: "Option 'experimentalAsyncFunctions' cannot be specified when targeting ES5 or lower." }, Enables_experimental_support_for_ES7_async_functions: { code: 6068, category: ts.DiagnosticCategory.Message, key: "Enables experimental support for ES7 async functions." }, - Specifies_module_resolution_strategy_Colon_node_Node_or_classic_TypeScript_pre_1_6: { code: 6069, category: ts.DiagnosticCategory.Message, key: "Specifies module resolution strategy: 'node' (Node) or 'classic' (TypeScript pre 1.6) ." }, + Specifies_module_resolution_strategy_Colon_node_Node_js_or_classic_TypeScript_pre_1_6: { code: 6069, category: ts.DiagnosticCategory.Message, key: "Specifies module resolution strategy: 'node' (Node.js) or 'classic' (TypeScript pre-1.6)." }, Initializes_a_TypeScript_project_and_creates_a_tsconfig_json_file: { code: 6070, category: ts.DiagnosticCategory.Message, key: "Initializes a TypeScript project and creates a tsconfig.json file." }, Successfully_created_a_tsconfig_json_file: { code: 6071, category: ts.DiagnosticCategory.Message, key: "Successfully created a tsconfig.json file." }, Suppress_excess_property_checks_for_object_literals: { code: 6072, category: ts.DiagnosticCategory.Message, key: "Suppress excess property checks for object literals." }, @@ -3223,8 +3224,8 @@ var ts; "node": 2, "classic": 1 }, - experimental: true, - description: ts.Diagnostics.Specifies_module_resolution_strategy_Colon_node_Node_or_classic_TypeScript_pre_1_6 + description: ts.Diagnostics.Specifies_module_resolution_strategy_Colon_node_Node_js_or_classic_TypeScript_pre_1_6, + error: ts.Diagnostics.Argument_for_moduleResolution_option_must_be_node_or_classic } ]; var optionNameMapCache; @@ -14511,6 +14512,7 @@ var ts; var prop = _a[_i]; if (!isKnownProperty(target, prop.name)) { if (reportErrors) { + errorNode = prop.valueDeclaration; reportError(ts.Diagnostics.Object_literal_may_only_specify_known_properties_and_0_does_not_exist_in_type_1, symbolToString(prop), typeToString(target)); } return true; @@ -21432,7 +21434,10 @@ var ts; var symbols = []; var name_16 = symbol.name; ts.forEach(getSymbolLinks(symbol).containingType.types, function (t) { - symbols.push(getPropertyOfType(t, name_16)); + var symbol = getPropertyOfType(t, name_16); + if (symbol) { + symbols.push(symbol); + } }); return symbols; } @@ -24967,8 +24972,10 @@ var ts; function jsxEmitPreserve(node) { function emitJsxAttribute(node) { emit(node.name); - write("="); - emit(node.initializer); + if (node.initializer) { + write("="); + emit(node.initializer); + } } function emitJsxSpreadAttribute(node) { write("{..."); @@ -26491,19 +26498,19 @@ var ts; write(")"); } } - function ensureIdentifier(expr) { - if (expr.kind !== 67) { - var identifier = createTempVariable(0); - if (!canDefineTempVariablesInPlace) { - recordTempDeclaration(identifier); - } - emitAssignment(identifier, expr); - expr = identifier; + function ensureIdentifier(expr, reuseIdentifierExpressions) { + if (expr.kind === 67 && reuseIdentifierExpressions) { + return expr; } - return expr; + var identifier = createTempVariable(0); + if (!canDefineTempVariablesInPlace) { + recordTempDeclaration(identifier); + } + emitAssignment(identifier, expr); + return identifier; } function createDefaultValueCheck(value, defaultValue) { - value = ensureIdentifier(value); + value = ensureIdentifier(value, true); var equals = ts.createSynthesizedNode(179); equals.left = value; equals.operatorToken = ts.createSynthesizedNode(32); @@ -26544,7 +26551,7 @@ var ts; function emitObjectLiteralAssignment(target, value) { var properties = target.properties; if (properties.length !== 1) { - value = ensureIdentifier(value); + value = ensureIdentifier(value, true); } for (var _a = 0; _a < properties.length; _a++) { var p = properties[_a]; @@ -26557,7 +26564,7 @@ var ts; function emitArrayLiteralAssignment(target, value) { var elements = target.elements; if (elements.length !== 1) { - value = ensureIdentifier(value); + value = ensureIdentifier(value, true); } for (var i = 0; i < elements.length; i++) { var e = elements[i]; @@ -26599,7 +26606,7 @@ var ts; if (root.parent.kind !== 170) { write("("); } - value = ensureIdentifier(value); + value = ensureIdentifier(value, true); emitDestructuringAssignment(target, value); write(", "); emit(value); @@ -26618,10 +26625,11 @@ var ts; if (ts.isBindingPattern(target.name)) { var pattern = target.name; var elements = pattern.elements; - if (elements.length !== 1) { - value = ensureIdentifier(value); + var numElements = elements.length; + if (numElements !== 1) { + value = ensureIdentifier(value, numElements !== 0); } - for (var i = 0; i < elements.length; i++) { + for (var i = 0; i < numElements; i++) { var element = elements[i]; if (pattern.kind === 159) { var propName = element.propertyName || element.name; @@ -26631,7 +26639,7 @@ var ts; if (!element.dotDotDotToken) { emitBindingElement(element, createElementAccessExpression(value, createNumericLiteral(i))); } - else if (i === elements.length - 1) { + else if (i === numElements - 1) { emitBindingElement(element, createSliceCall(value, i)); } } @@ -27751,50 +27759,49 @@ var ts; write("void 0"); } function emitSerializedTypeNode(node) { - if (!node) { - return; - } - switch (node.kind) { - case 101: - write("void 0"); - return; - case 158: - emitSerializedTypeNode(node.type); - return; - case 150: - case 151: - write("Function"); - return; - case 154: - case 155: - write("Array"); - return; - case 148: - case 118: - write("Boolean"); - return; - case 128: - case 9: - write("String"); - return; - case 126: - write("Number"); - return; - case 129: - write("Symbol"); - return; - case 149: - emitSerializedTypeReferenceNode(node); - return; - case 152: - case 153: - case 156: - case 157: - case 115: - break; - default: - ts.Debug.fail("Cannot serialize unexpected type node."); - break; + if (node) { + switch (node.kind) { + case 101: + write("void 0"); + return; + case 158: + emitSerializedTypeNode(node.type); + return; + case 150: + case 151: + write("Function"); + return; + case 154: + case 155: + write("Array"); + return; + case 148: + case 118: + write("Boolean"); + return; + case 128: + case 9: + write("String"); + return; + case 126: + write("Number"); + return; + case 129: + write("Symbol"); + return; + case 149: + emitSerializedTypeReferenceNode(node); + return; + case 152: + case 153: + case 156: + case 157: + case 115: + break; + default: + ts.Debug.fail("Cannot serialize unexpected type node."); + break; + } } write("Object"); } @@ -29794,7 +29801,7 @@ var ts; ts.ioReadTime = 0; ts.ioWriteTime = 0; var emptyArray = []; - ts.version = "1.6.0"; + ts.version = "1.6.2"; function findConfigFile(searchPath) { var fileName = "tsconfig.json"; while (true) { @@ -32681,7 +32688,7 @@ var ts; function findPrecedingToken(position, sourceFile, startNode) { return find(startNode || sourceFile); function findRightmostToken(n) { - if (isToken(n)) { + if (isToken(n) || n.kind === 234) { return n; } var children = n.getChildren(); @@ -32689,21 +32696,22 @@ var ts; return candidate && findRightmostToken(candidate); } function find(n) { - if (isToken(n)) { + if (isToken(n) || n.kind === 234) { return n; } var children = n.getChildren(); for (var i = 0, len = children.length; i < len; i++) { var child = children[i]; - if (nodeHasTokens(child)) { - if (position <= child.end) { - if (child.getStart(sourceFile) >= position) { - var candidate = findRightmostChildNodeWithTokens(children, i); - return candidate && findRightmostToken(candidate); - } - else { - return find(child); - } + if (position < child.end && (nodeHasTokens(child) || child.kind === 234)) { + var start = child.getStart(sourceFile); + var lookInPreviousChild = (start >= position) || + (child.kind === 234 && start === child.end); + if (lookInPreviousChild) { + var candidate = findRightmostChildNodeWithTokens(children, i); + return candidate && findRightmostToken(candidate); + } + else { + return find(child); } } } @@ -33143,6 +33151,18 @@ var ts; } return false; } + function shouldRescanJsxIdentifier(node) { + if (node.parent) { + switch (node.parent.kind) { + case 236: + case 233: + case 235: + case 232: + return node.kind === 67; + } + } + return false; + } function shouldRescanSlashToken(container) { return container.kind === 10; } @@ -33167,7 +33187,9 @@ var ts; ? 2 : shouldRescanTemplateToken(n) ? 3 - : 0; + : shouldRescanJsxIdentifier(n) + ? 4 + : 0; if (lastTokenInfo && expectedScanAction === lastScanAction) { return fixTokenKind(lastTokenInfo, n); } @@ -33191,6 +33213,10 @@ var ts; currentToken = scanner.reScanTemplateToken(); lastScanAction = 3; } + else if (expectedScanAction === 4 && currentToken === 67) { + currentToken = scanner.scanJsxIdentifier(); + lastScanAction = 4; + } else { lastScanAction = 0; } @@ -33469,7 +33495,7 @@ var ts; this.NoSpaceAfterCloseBracket = new formatting.Rule(formatting.RuleDescriptor.create3(20, formatting.Shared.TokenRange.Any), formatting.RuleOperation.create2(new formatting.RuleOperationContext(Rules.IsSameLineTokenContext, Rules.IsNotBeforeBlockInFunctionDeclarationContext), 8)); this.FunctionOpenBraceLeftTokenRange = formatting.Shared.TokenRange.AnyIncludingMultilineComments; this.SpaceBeforeOpenBraceInFunction = new formatting.Rule(formatting.RuleDescriptor.create2(this.FunctionOpenBraceLeftTokenRange, 15), formatting.RuleOperation.create2(new formatting.RuleOperationContext(Rules.IsFunctionDeclContext, Rules.IsBeforeBlockContext, Rules.IsNotFormatOnEnter, Rules.IsSameLineTokenOrBeforeMultilineBlockContext), 2), 1); - this.TypeScriptOpenBraceLeftTokenRange = formatting.Shared.TokenRange.FromTokens([67, 3]); + this.TypeScriptOpenBraceLeftTokenRange = formatting.Shared.TokenRange.FromTokens([67, 3, 71]); this.SpaceBeforeOpenBraceInTypeScriptDeclWithBlock = new formatting.Rule(formatting.RuleDescriptor.create2(this.TypeScriptOpenBraceLeftTokenRange, 15), formatting.RuleOperation.create2(new formatting.RuleOperationContext(Rules.IsTypeScriptDeclWithBlockContext, Rules.IsNotFormatOnEnter, Rules.IsSameLineTokenOrBeforeMultilineBlockContext), 2), 1); this.ControlOpenBraceLeftTokenRange = formatting.Shared.TokenRange.FromTokens([18, 3, 77, 98, 83, 78]); this.SpaceBeforeOpenBraceInControl = new formatting.Rule(formatting.RuleDescriptor.create2(this.ControlOpenBraceLeftTokenRange, 15), formatting.RuleOperation.create2(new formatting.RuleOperationContext(Rules.IsControlDeclContext, Rules.IsNotFormatOnEnter, Rules.IsSameLineTokenOrBeforeMultilineBlockContext), 2), 1); @@ -33536,6 +33562,8 @@ var ts; this.NoSpaceBeforeBar = new formatting.Rule(formatting.RuleDescriptor.create3(46, formatting.Shared.TokenRange.Any), formatting.RuleOperation.create2(new formatting.RuleOperationContext(Rules.IsSameLineTokenContext), 8)); this.SpaceAfterBar = new formatting.Rule(formatting.RuleDescriptor.create2(formatting.Shared.TokenRange.Any, 46), formatting.RuleOperation.create2(new formatting.RuleOperationContext(Rules.IsSameLineTokenContext), 2)); this.NoSpaceAfterBar = new formatting.Rule(formatting.RuleDescriptor.create2(formatting.Shared.TokenRange.Any, 46), formatting.RuleOperation.create2(new formatting.RuleOperationContext(Rules.IsSameLineTokenContext), 8)); + this.SpaceBeforeAmpersand = new formatting.Rule(formatting.RuleDescriptor.create3(45, formatting.Shared.TokenRange.Any), formatting.RuleOperation.create2(new formatting.RuleOperationContext(Rules.IsSameLineTokenContext), 2)); + this.SpaceAfterAmpersand = new formatting.Rule(formatting.RuleDescriptor.create2(formatting.Shared.TokenRange.Any, 45), formatting.RuleOperation.create2(new formatting.RuleOperationContext(Rules.IsSameLineTokenContext), 2)); this.HighPriorityCommonRules = [ this.IgnoreBeforeComment, this.IgnoreAfterLineComment, @@ -33566,6 +33594,7 @@ var ts; this.SpaceAfterTypeKeyword, this.NoSpaceAfterTypeKeyword, this.SpaceBetweenTagAndTemplateString, this.NoSpaceBetweenTagAndTemplateString, this.SpaceBeforeBar, this.NoSpaceBeforeBar, this.SpaceAfterBar, this.NoSpaceAfterBar, + this.SpaceBeforeAmpersand, this.SpaceAfterAmpersand, this.NoSpaceAfterConstructor, this.NoSpaceAfterModuleImport, this.SpaceAfterCertainTypeScriptKeywords, this.SpaceBeforeCertainTypeScriptKeywords, this.SpaceAfterModuleName, @@ -33736,6 +33765,7 @@ var ts; Rules.NodeIsTypeScriptDeclWithBlockContext = function (node) { switch (node.kind) { case 212: + case 184: case 213: case 215: case 153: @@ -35266,6 +35296,7 @@ var ts; function nodeContentIsAlwaysIndented(kind) { switch (kind) { case 212: + case 184: case 213: case 215: case 214: @@ -35290,13 +35321,13 @@ var ts; case 160: case 159: case 231: + case 232: case 140: case 145: case 146: case 136: case 150: case 151: - case 156: case 158: case 168: case 176: @@ -36267,7 +36298,7 @@ var ts; var outputText; var sourceMapText; var compilerHost = { - getSourceFile: function (fileName, target) { return fileName === inputFileName ? sourceFile : undefined; }, + getSourceFile: function (fileName, target) { return fileName === ts.normalizeSlashes(inputFileName) ? sourceFile : undefined; }, writeFile: function (name, text, writeByteOrderMark) { if (ts.fileExtensionIs(name, ".map")) { ts.Debug.assert(sourceMapText === undefined, "Unexpected multiple source map outputs for the file '" + name + "'"); @@ -36581,6 +36612,24 @@ var ts; } } } + else if (token === 87) { + token = scanner.scan(); + if (token === 67 || ts.isKeyword(token)) { + token = scanner.scan(); + if (token === 55) { + token = scanner.scan(); + if (token === 125) { + token = scanner.scan(); + if (token === 17) { + token = scanner.scan(); + if (token === 9) { + recordModuleName(); + } + } + } + } + } + } } token = scanner.scan(); } diff --git a/lib/typescript.js b/lib/typescript.js index b4d21639d3b..f6701d019cc 100644 --- a/lib/typescript.js +++ b/lib/typescript.js @@ -2433,13 +2433,14 @@ var ts; Specifies_the_end_of_line_sequence_to_be_used_when_emitting_files_Colon_CRLF_dos_or_LF_unix: { code: 6060, category: ts.DiagnosticCategory.Message, key: "Specifies the end of line sequence to be used when emitting files: 'CRLF' (dos) or 'LF' (unix)." }, NEWLINE: { code: 6061, category: ts.DiagnosticCategory.Message, key: "NEWLINE" }, Argument_for_newLine_option_must_be_CRLF_or_LF: { code: 6062, category: ts.DiagnosticCategory.Error, key: "Argument for '--newLine' option must be 'CRLF' or 'LF'." }, + Argument_for_moduleResolution_option_must_be_node_or_classic: { code: 6063, category: ts.DiagnosticCategory.Error, key: "Argument for '--moduleResolution' option must be 'node' or 'classic'." }, Specify_JSX_code_generation_Colon_preserve_or_react: { code: 6080, category: ts.DiagnosticCategory.Message, key: "Specify JSX code generation: 'preserve' or 'react'" }, Argument_for_jsx_must_be_preserve_or_react: { code: 6081, category: ts.DiagnosticCategory.Message, key: "Argument for '--jsx' must be 'preserve' or 'react'." }, Enables_experimental_support_for_ES7_decorators: { code: 6065, category: ts.DiagnosticCategory.Message, key: "Enables experimental support for ES7 decorators." }, Enables_experimental_support_for_emitting_type_metadata_for_decorators: { code: 6066, category: ts.DiagnosticCategory.Message, key: "Enables experimental support for emitting type metadata for decorators." }, Option_experimentalAsyncFunctions_cannot_be_specified_when_targeting_ES5_or_lower: { code: 6067, category: ts.DiagnosticCategory.Message, key: "Option 'experimentalAsyncFunctions' cannot be specified when targeting ES5 or lower." }, Enables_experimental_support_for_ES7_async_functions: { code: 6068, category: ts.DiagnosticCategory.Message, key: "Enables experimental support for ES7 async functions." }, - Specifies_module_resolution_strategy_Colon_node_Node_or_classic_TypeScript_pre_1_6: { code: 6069, category: ts.DiagnosticCategory.Message, key: "Specifies module resolution strategy: 'node' (Node) or 'classic' (TypeScript pre 1.6) ." }, + Specifies_module_resolution_strategy_Colon_node_Node_js_or_classic_TypeScript_pre_1_6: { code: 6069, category: ts.DiagnosticCategory.Message, key: "Specifies module resolution strategy: 'node' (Node.js) or 'classic' (TypeScript pre-1.6)." }, Initializes_a_TypeScript_project_and_creates_a_tsconfig_json_file: { code: 6070, category: ts.DiagnosticCategory.Message, key: "Initializes a TypeScript project and creates a tsconfig.json file." }, Successfully_created_a_tsconfig_json_file: { code: 6071, category: ts.DiagnosticCategory.Message, key: "Successfully created a tsconfig.json file." }, Suppress_excess_property_checks_for_object_literals: { code: 6072, category: ts.DiagnosticCategory.Message, key: "Suppress excess property checks for object literals." }, @@ -17021,7 +17022,7 @@ var ts; * @param target The right-hand-side of the relation. * @param relation The relation considered. One of 'identityRelation', 'assignableRelation', or 'subTypeRelation'. * Used as both to determine which checks are performed and as a cache of previously computed results. - * @param errorNode The node upon which all errors will be reported, if defined. + * @param errorNode The suggested node upon which all errors will be reported, if defined. This may or may not be the actual node used. * @param headMessage If the error chain should be prepended by a head message, then headMessage will be used. * @param containingMessageChain A chain of errors to prepend any new errors found. */ @@ -17228,6 +17229,10 @@ var ts; var prop = _a[_i]; if (!isKnownProperty(target, prop.name)) { if (reportErrors) { + // We know *exactly* where things went wrong when comparing the types. + // Use this property as the error node as this will be more helpful in + // reasoning about what went wrong. + errorNode = prop.valueDeclaration; reportError(ts.Diagnostics.Object_literal_may_only_specify_known_properties_and_0_does_not_exist_in_type_1, symbolToString(prop), typeToString(target)); } return true; @@ -25637,7 +25642,10 @@ var ts; var symbols = []; var name_15 = symbol.name; ts.forEach(getSymbolLinks(symbol).containingType.types, function (t) { - symbols.push(getPropertyOfType(t, name_15)); + var symbol = getPropertyOfType(t, name_15); + if (symbol) { + symbols.push(symbol); + } }); return symbols; } @@ -29561,8 +29569,10 @@ var ts; function jsxEmitPreserve(node) { function emitJsxAttribute(node) { emit(node.name); - write("="); - emit(node.initializer); + if (node.initializer) { + write("="); + emit(node.initializer); + } } function emitJsxSpreadAttribute(node) { write("{..."); @@ -31270,21 +31280,30 @@ var ts; write(")"); } } - function ensureIdentifier(expr) { - if (expr.kind !== 67 /* Identifier */) { - var identifier = createTempVariable(0 /* Auto */); - if (!canDefineTempVariablesInPlace) { - recordTempDeclaration(identifier); - } - emitAssignment(identifier, expr); - expr = identifier; + /** + * Ensures that there exists a declared identifier whose value holds the given expression. + * This function is useful to ensure that the expression's value can be read from in subsequent expressions. + * Unless 'reuseIdentifierExpressions' is false, 'expr' will be returned if it is just an identifier. + * + * @param expr the expression whose value needs to be bound. + * @param reuseIdentifierExpressions true if identifier expressions can simply be returned; + * false if it is necessary to always emit an identifier. + */ + function ensureIdentifier(expr, reuseIdentifierExpressions) { + if (expr.kind === 67 /* Identifier */ && reuseIdentifierExpressions) { + return expr; } - return expr; + var identifier = createTempVariable(0 /* Auto */); + if (!canDefineTempVariablesInPlace) { + recordTempDeclaration(identifier); + } + emitAssignment(identifier, expr); + return identifier; } function createDefaultValueCheck(value, defaultValue) { // The value expression will be evaluated twice, so for anything but a simple identifier // we need to generate a temporary variable - value = ensureIdentifier(value); + value = ensureIdentifier(value, /*reuseIdentifierExpressions*/ true); // Return the expression 'value === void 0 ? defaultValue : value' var equals = ts.createSynthesizedNode(179 /* BinaryExpression */); equals.left = value; @@ -31330,7 +31349,7 @@ var ts; if (properties.length !== 1) { // For anything but a single element destructuring we need to generate a temporary // to ensure value is evaluated exactly once. - value = ensureIdentifier(value); + value = ensureIdentifier(value, /*reuseIdentifierExpressions*/ true); } for (var _a = 0; _a < properties.length; _a++) { var p = properties[_a]; @@ -31345,7 +31364,7 @@ var ts; if (elements.length !== 1) { // For anything but a single element destructuring we need to generate a temporary // to ensure value is evaluated exactly once. - value = ensureIdentifier(value); + value = ensureIdentifier(value, /*reuseIdentifierExpressions*/ true); } for (var i = 0; i < elements.length; i++) { var e = elements[i]; @@ -31387,7 +31406,7 @@ var ts; if (root.parent.kind !== 170 /* ParenthesizedExpression */) { write("("); } - value = ensureIdentifier(value); + value = ensureIdentifier(value, /*reuseIdentifierExpressions*/ true); emitDestructuringAssignment(target, value); write(", "); emit(value); @@ -31408,12 +31427,15 @@ var ts; if (ts.isBindingPattern(target.name)) { var pattern = target.name; var elements = pattern.elements; - if (elements.length !== 1) { - // For anything but a single element destructuring we need to generate a temporary - // to ensure value is evaluated exactly once. - value = ensureIdentifier(value); + var numElements = elements.length; + if (numElements !== 1) { + // For anything other than a single-element destructuring we need to generate a temporary + // to ensure value is evaluated exactly once. Additionally, if we have zero elements + // we need to emit *something* to ensure that in case a 'var' keyword was already emitted, + // so in that case, we'll intentionally create that temporary. + value = ensureIdentifier(value, /*reuseIdentifierExpressions*/ numElements !== 0); } - for (var i = 0; i < elements.length; i++) { + for (var i = 0; i < numElements; i++) { var element = elements[i]; if (pattern.kind === 159 /* ObjectBindingPattern */) { // Rewrite element to a declaration with an initializer that fetches property @@ -31425,7 +31447,7 @@ var ts; // Rewrite element to a declaration that accesses array element at index i emitBindingElement(element, createElementAccessExpression(value, createNumericLiteral(i))); } - else if (i === elements.length - 1) { + else if (i === numElements - 1) { emitBindingElement(element, createSliceCall(value, i)); } } @@ -32840,50 +32862,49 @@ var ts; write("void 0"); } function emitSerializedTypeNode(node) { - if (!node) { - return; - } - switch (node.kind) { - case 101 /* VoidKeyword */: - write("void 0"); - return; - case 158 /* ParenthesizedType */: - emitSerializedTypeNode(node.type); - return; - case 150 /* FunctionType */: - case 151 /* ConstructorType */: - write("Function"); - return; - case 154 /* ArrayType */: - case 155 /* TupleType */: - write("Array"); - return; - case 148 /* TypePredicate */: - case 118 /* BooleanKeyword */: - write("Boolean"); - return; - case 128 /* StringKeyword */: - case 9 /* StringLiteral */: - write("String"); - return; - case 126 /* NumberKeyword */: - write("Number"); - return; - case 129 /* SymbolKeyword */: - write("Symbol"); - return; - case 149 /* TypeReference */: - emitSerializedTypeReferenceNode(node); - return; - case 152 /* TypeQuery */: - case 153 /* TypeLiteral */: - case 156 /* UnionType */: - case 157 /* IntersectionType */: - case 115 /* AnyKeyword */: - break; - default: - ts.Debug.fail("Cannot serialize unexpected type node."); - break; + if (node) { + switch (node.kind) { + case 101 /* VoidKeyword */: + write("void 0"); + return; + case 158 /* ParenthesizedType */: + emitSerializedTypeNode(node.type); + return; + case 150 /* FunctionType */: + case 151 /* ConstructorType */: + write("Function"); + return; + case 154 /* ArrayType */: + case 155 /* TupleType */: + write("Array"); + return; + case 148 /* TypePredicate */: + case 118 /* BooleanKeyword */: + write("Boolean"); + return; + case 128 /* StringKeyword */: + case 9 /* StringLiteral */: + write("String"); + return; + case 126 /* NumberKeyword */: + write("Number"); + return; + case 129 /* SymbolKeyword */: + write("Symbol"); + return; + case 149 /* TypeReference */: + emitSerializedTypeReferenceNode(node); + return; + case 152 /* TypeQuery */: + case 153 /* TypeLiteral */: + case 156 /* UnionType */: + case 157 /* IntersectionType */: + case 115 /* AnyKeyword */: + break; + default: + ts.Debug.fail("Cannot serialize unexpected type node."); + break; + } } write("Object"); } @@ -35103,7 +35124,7 @@ var ts; /* @internal */ ts.ioWriteTime = 0; /** The version of the TypeScript compiler release */ var emptyArray = []; - ts.version = "1.6.0"; + ts.version = "1.6.2"; function findConfigFile(searchPath) { var fileName = "tsconfig.json"; while (true) { @@ -36251,8 +36272,8 @@ var ts; "node": 2 /* NodeJs */, "classic": 1 /* Classic */ }, - experimental: true, - description: ts.Diagnostics.Specifies_module_resolution_strategy_Colon_node_Node_or_classic_TypeScript_pre_1_6 + description: ts.Diagnostics.Specifies_module_resolution_strategy_Colon_node_Node_js_or_classic_TypeScript_pre_1_6, + error: ts.Diagnostics.Argument_for_moduleResolution_option_must_be_node_or_classic } ]; var optionNameMapCache; @@ -38721,7 +38742,7 @@ var ts; function findPrecedingToken(position, sourceFile, startNode) { return find(startNode || sourceFile); function findRightmostToken(n) { - if (isToken(n)) { + if (isToken(n) || n.kind === 234 /* JsxText */) { return n; } var children = n.getChildren(); @@ -38729,23 +38750,32 @@ var ts; return candidate && findRightmostToken(candidate); } function find(n) { - if (isToken(n)) { + if (isToken(n) || n.kind === 234 /* JsxText */) { return n; } var children = n.getChildren(); for (var i = 0, len = children.length; i < len; i++) { var child = children[i]; - if (nodeHasTokens(child)) { - if (position <= child.end) { - if (child.getStart(sourceFile) >= position) { - // actual start of the node is past the position - previous token should be at the end of previous child - var candidate = findRightmostChildNodeWithTokens(children, /*exclusiveStartPosition*/ i); - return candidate && findRightmostToken(candidate); - } - else { - // candidate should be in this node - return find(child); - } + // condition 'position < child.end' checks if child node end after the position + // in the example below this condition will be false for 'aaaa' and 'bbbb' and true for 'ccc' + // aaaa___bbbb___$__ccc + // after we found child node with end after the position we check if start of the node is after the position. + // if yes - then position is in the trivia and we need to look into the previous child to find the token in question. + // if no - position is in the node itself so we should recurse in it. + // NOTE: JsxText is a weird kind of node that can contain only whitespaces (since they are not counted as trivia). + // if this is the case - then we should assume that token in question is located in previous child. + if (position < child.end && (nodeHasTokens(child) || child.kind === 234 /* JsxText */)) { + var start = child.getStart(sourceFile); + var lookInPreviousChild = (start >= position) || + (child.kind === 234 /* JsxText */ && start === child.end); // whitespace only JsxText + if (lookInPreviousChild) { + // actual start of the node is past the position - previous token should be at the end of previous child + var candidate = findRightmostChildNodeWithTokens(children, /*exclusiveStartPosition*/ i); + return candidate && findRightmostToken(candidate); + } + else { + // candidate should be in this node + return find(child); } } } @@ -39162,6 +39192,7 @@ var ts; ScanAction[ScanAction["RescanGreaterThanToken"] = 1] = "RescanGreaterThanToken"; ScanAction[ScanAction["RescanSlashToken"] = 2] = "RescanSlashToken"; ScanAction[ScanAction["RescanTemplateToken"] = 3] = "RescanTemplateToken"; + ScanAction[ScanAction["RescanJsxIdentifier"] = 4] = "RescanJsxIdentifier"; })(ScanAction || (ScanAction = {})); function getFormattingScanner(sourceFile, startPos, endPos) { scanner.setText(sourceFile.text); @@ -39235,6 +39266,18 @@ var ts; } return false; } + function shouldRescanJsxIdentifier(node) { + if (node.parent) { + switch (node.parent.kind) { + case 236 /* JsxAttribute */: + case 233 /* JsxOpeningElement */: + case 235 /* JsxClosingElement */: + case 232 /* JsxSelfClosingElement */: + return node.kind === 67 /* Identifier */; + } + } + return false; + } function shouldRescanSlashToken(container) { return container.kind === 10 /* RegularExpressionLiteral */; } @@ -39262,7 +39305,9 @@ var ts; ? 2 /* RescanSlashToken */ : shouldRescanTemplateToken(n) ? 3 /* RescanTemplateToken */ - : 0 /* Scan */; + : shouldRescanJsxIdentifier(n) + ? 4 /* RescanJsxIdentifier */ + : 0 /* Scan */; if (lastTokenInfo && expectedScanAction === lastScanAction) { // readTokenInfo was called before with the same expected scan action. // No need to re-scan text, return existing 'lastTokenInfo' @@ -39293,6 +39338,10 @@ var ts; currentToken = scanner.reScanTemplateToken(); lastScanAction = 3 /* RescanTemplateToken */; } + else if (expectedScanAction === 4 /* RescanJsxIdentifier */ && currentToken === 67 /* Identifier */) { + currentToken = scanner.scanJsxIdentifier(); + lastScanAction = 4 /* RescanJsxIdentifier */; + } else { lastScanAction = 0 /* Scan */; } @@ -39633,7 +39682,7 @@ var ts; this.FunctionOpenBraceLeftTokenRange = formatting.Shared.TokenRange.AnyIncludingMultilineComments; this.SpaceBeforeOpenBraceInFunction = new formatting.Rule(formatting.RuleDescriptor.create2(this.FunctionOpenBraceLeftTokenRange, 15 /* OpenBraceToken */), formatting.RuleOperation.create2(new formatting.RuleOperationContext(Rules.IsFunctionDeclContext, Rules.IsBeforeBlockContext, Rules.IsNotFormatOnEnter, Rules.IsSameLineTokenOrBeforeMultilineBlockContext), 2 /* Space */), 1 /* CanDeleteNewLines */); // Place a space before open brace in a TypeScript declaration that has braces as children (class, module, enum, etc) - this.TypeScriptOpenBraceLeftTokenRange = formatting.Shared.TokenRange.FromTokens([67 /* Identifier */, 3 /* MultiLineCommentTrivia */]); + this.TypeScriptOpenBraceLeftTokenRange = formatting.Shared.TokenRange.FromTokens([67 /* Identifier */, 3 /* MultiLineCommentTrivia */, 71 /* ClassKeyword */]); this.SpaceBeforeOpenBraceInTypeScriptDeclWithBlock = new formatting.Rule(formatting.RuleDescriptor.create2(this.TypeScriptOpenBraceLeftTokenRange, 15 /* OpenBraceToken */), formatting.RuleOperation.create2(new formatting.RuleOperationContext(Rules.IsTypeScriptDeclWithBlockContext, Rules.IsNotFormatOnEnter, Rules.IsSameLineTokenOrBeforeMultilineBlockContext), 2 /* Space */), 1 /* CanDeleteNewLines */); // Place a space before open brace in a control flow construct this.ControlOpenBraceLeftTokenRange = formatting.Shared.TokenRange.FromTokens([18 /* CloseParenToken */, 3 /* MultiLineCommentTrivia */, 77 /* DoKeyword */, 98 /* TryKeyword */, 83 /* FinallyKeyword */, 78 /* ElseKeyword */]); @@ -39727,11 +39776,13 @@ var ts; // template string this.SpaceBetweenTagAndTemplateString = new formatting.Rule(formatting.RuleDescriptor.create3(67 /* Identifier */, formatting.Shared.TokenRange.FromTokens([11 /* NoSubstitutionTemplateLiteral */, 12 /* TemplateHead */])), formatting.RuleOperation.create2(new formatting.RuleOperationContext(Rules.IsSameLineTokenContext), 2 /* Space */)); this.NoSpaceBetweenTagAndTemplateString = new formatting.Rule(formatting.RuleDescriptor.create3(67 /* Identifier */, formatting.Shared.TokenRange.FromTokens([11 /* NoSubstitutionTemplateLiteral */, 12 /* TemplateHead */])), formatting.RuleOperation.create2(new formatting.RuleOperationContext(Rules.IsSameLineTokenContext), 8 /* Delete */)); - // union type + // type operation this.SpaceBeforeBar = new formatting.Rule(formatting.RuleDescriptor.create3(46 /* BarToken */, formatting.Shared.TokenRange.Any), formatting.RuleOperation.create2(new formatting.RuleOperationContext(Rules.IsSameLineTokenContext), 2 /* Space */)); this.NoSpaceBeforeBar = new formatting.Rule(formatting.RuleDescriptor.create3(46 /* BarToken */, formatting.Shared.TokenRange.Any), formatting.RuleOperation.create2(new formatting.RuleOperationContext(Rules.IsSameLineTokenContext), 8 /* Delete */)); this.SpaceAfterBar = new formatting.Rule(formatting.RuleDescriptor.create2(formatting.Shared.TokenRange.Any, 46 /* BarToken */), formatting.RuleOperation.create2(new formatting.RuleOperationContext(Rules.IsSameLineTokenContext), 2 /* Space */)); this.NoSpaceAfterBar = new formatting.Rule(formatting.RuleDescriptor.create2(formatting.Shared.TokenRange.Any, 46 /* BarToken */), formatting.RuleOperation.create2(new formatting.RuleOperationContext(Rules.IsSameLineTokenContext), 8 /* Delete */)); + this.SpaceBeforeAmpersand = new formatting.Rule(formatting.RuleDescriptor.create3(45 /* AmpersandToken */, formatting.Shared.TokenRange.Any), formatting.RuleOperation.create2(new formatting.RuleOperationContext(Rules.IsSameLineTokenContext), 2 /* Space */)); + this.SpaceAfterAmpersand = new formatting.Rule(formatting.RuleDescriptor.create2(formatting.Shared.TokenRange.Any, 45 /* AmpersandToken */), formatting.RuleOperation.create2(new formatting.RuleOperationContext(Rules.IsSameLineTokenContext), 2 /* Space */)); // These rules are higher in priority than user-configurable rules. this.HighPriorityCommonRules = [ @@ -39763,6 +39814,7 @@ var ts; this.SpaceAfterTypeKeyword, this.NoSpaceAfterTypeKeyword, this.SpaceBetweenTagAndTemplateString, this.NoSpaceBetweenTagAndTemplateString, this.SpaceBeforeBar, this.NoSpaceBeforeBar, this.SpaceAfterBar, this.NoSpaceAfterBar, + this.SpaceBeforeAmpersand, this.SpaceAfterAmpersand, // TypeScript-specific rules this.NoSpaceAfterConstructor, this.NoSpaceAfterModuleImport, this.SpaceAfterCertainTypeScriptKeywords, this.SpaceBeforeCertainTypeScriptKeywords, @@ -39967,6 +40019,7 @@ var ts; Rules.NodeIsTypeScriptDeclWithBlockContext = function (node) { switch (node.kind) { case 212 /* ClassDeclaration */: + case 184 /* ClassExpression */: case 213 /* InterfaceDeclaration */: case 215 /* EnumDeclaration */: case 153 /* TypeLiteral */: @@ -41704,6 +41757,7 @@ var ts; function nodeContentIsAlwaysIndented(kind) { switch (kind) { case 212 /* ClassDeclaration */: + case 184 /* ClassExpression */: case 213 /* InterfaceDeclaration */: case 215 /* EnumDeclaration */: case 214 /* TypeAliasDeclaration */: @@ -41728,13 +41782,13 @@ var ts; case 160 /* ArrayBindingPattern */: case 159 /* ObjectBindingPattern */: case 231 /* JsxElement */: + case 232 /* JsxSelfClosingElement */: case 140 /* MethodSignature */: case 145 /* CallSignature */: case 146 /* ConstructSignature */: case 136 /* Parameter */: case 150 /* FunctionType */: case 151 /* ConstructorType */: - case 156 /* UnionType */: case 158 /* ParenthesizedType */: case 168 /* TaggedTemplateExpression */: case 176 /* AwaitExpression */: @@ -42858,7 +42912,7 @@ var ts; var sourceMapText; // Create a compilerHost object to allow the compiler to read and write files var compilerHost = { - getSourceFile: function (fileName, target) { return fileName === inputFileName ? sourceFile : undefined; }, + getSourceFile: function (fileName, target) { return fileName === ts.normalizeSlashes(inputFileName) ? sourceFile : undefined; }, writeFile: function (name, text, writeByteOrderMark) { if (ts.fileExtensionIs(name, ".map")) { ts.Debug.assert(sourceMapText === undefined, "Unexpected multiple source map outputs for the file '" + name + "'"); @@ -43106,6 +43160,7 @@ var ts; // // export * from "mod" // export {a as b} from "mod" + // export import i = require("mod") while (token !== 1 /* EndOfFileToken */) { if (token === 120 /* DeclareKeyword */) { // declare module "mod" @@ -43226,6 +43281,25 @@ var ts; } } } + else if (token === 87 /* ImportKeyword */) { + token = scanner.scan(); + if (token === 67 /* Identifier */ || ts.isKeyword(token)) { + token = scanner.scan(); + if (token === 55 /* EqualsToken */) { + token = scanner.scan(); + if (token === 125 /* RequireKeyword */) { + token = scanner.scan(); + if (token === 17 /* OpenParenToken */) { + token = scanner.scan(); + if (token === 9 /* StringLiteral */) { + // export import i = require("mod"); + recordModuleName(); + } + } + } + } + } + } } token = scanner.scan(); } diff --git a/lib/typescriptServices.js b/lib/typescriptServices.js index b4d21639d3b..f6701d019cc 100644 --- a/lib/typescriptServices.js +++ b/lib/typescriptServices.js @@ -2433,13 +2433,14 @@ var ts; Specifies_the_end_of_line_sequence_to_be_used_when_emitting_files_Colon_CRLF_dos_or_LF_unix: { code: 6060, category: ts.DiagnosticCategory.Message, key: "Specifies the end of line sequence to be used when emitting files: 'CRLF' (dos) or 'LF' (unix)." }, NEWLINE: { code: 6061, category: ts.DiagnosticCategory.Message, key: "NEWLINE" }, Argument_for_newLine_option_must_be_CRLF_or_LF: { code: 6062, category: ts.DiagnosticCategory.Error, key: "Argument for '--newLine' option must be 'CRLF' or 'LF'." }, + Argument_for_moduleResolution_option_must_be_node_or_classic: { code: 6063, category: ts.DiagnosticCategory.Error, key: "Argument for '--moduleResolution' option must be 'node' or 'classic'." }, Specify_JSX_code_generation_Colon_preserve_or_react: { code: 6080, category: ts.DiagnosticCategory.Message, key: "Specify JSX code generation: 'preserve' or 'react'" }, Argument_for_jsx_must_be_preserve_or_react: { code: 6081, category: ts.DiagnosticCategory.Message, key: "Argument for '--jsx' must be 'preserve' or 'react'." }, Enables_experimental_support_for_ES7_decorators: { code: 6065, category: ts.DiagnosticCategory.Message, key: "Enables experimental support for ES7 decorators." }, Enables_experimental_support_for_emitting_type_metadata_for_decorators: { code: 6066, category: ts.DiagnosticCategory.Message, key: "Enables experimental support for emitting type metadata for decorators." }, Option_experimentalAsyncFunctions_cannot_be_specified_when_targeting_ES5_or_lower: { code: 6067, category: ts.DiagnosticCategory.Message, key: "Option 'experimentalAsyncFunctions' cannot be specified when targeting ES5 or lower." }, Enables_experimental_support_for_ES7_async_functions: { code: 6068, category: ts.DiagnosticCategory.Message, key: "Enables experimental support for ES7 async functions." }, - Specifies_module_resolution_strategy_Colon_node_Node_or_classic_TypeScript_pre_1_6: { code: 6069, category: ts.DiagnosticCategory.Message, key: "Specifies module resolution strategy: 'node' (Node) or 'classic' (TypeScript pre 1.6) ." }, + Specifies_module_resolution_strategy_Colon_node_Node_js_or_classic_TypeScript_pre_1_6: { code: 6069, category: ts.DiagnosticCategory.Message, key: "Specifies module resolution strategy: 'node' (Node.js) or 'classic' (TypeScript pre-1.6)." }, Initializes_a_TypeScript_project_and_creates_a_tsconfig_json_file: { code: 6070, category: ts.DiagnosticCategory.Message, key: "Initializes a TypeScript project and creates a tsconfig.json file." }, Successfully_created_a_tsconfig_json_file: { code: 6071, category: ts.DiagnosticCategory.Message, key: "Successfully created a tsconfig.json file." }, Suppress_excess_property_checks_for_object_literals: { code: 6072, category: ts.DiagnosticCategory.Message, key: "Suppress excess property checks for object literals." }, @@ -17021,7 +17022,7 @@ var ts; * @param target The right-hand-side of the relation. * @param relation The relation considered. One of 'identityRelation', 'assignableRelation', or 'subTypeRelation'. * Used as both to determine which checks are performed and as a cache of previously computed results. - * @param errorNode The node upon which all errors will be reported, if defined. + * @param errorNode The suggested node upon which all errors will be reported, if defined. This may or may not be the actual node used. * @param headMessage If the error chain should be prepended by a head message, then headMessage will be used. * @param containingMessageChain A chain of errors to prepend any new errors found. */ @@ -17228,6 +17229,10 @@ var ts; var prop = _a[_i]; if (!isKnownProperty(target, prop.name)) { if (reportErrors) { + // We know *exactly* where things went wrong when comparing the types. + // Use this property as the error node as this will be more helpful in + // reasoning about what went wrong. + errorNode = prop.valueDeclaration; reportError(ts.Diagnostics.Object_literal_may_only_specify_known_properties_and_0_does_not_exist_in_type_1, symbolToString(prop), typeToString(target)); } return true; @@ -25637,7 +25642,10 @@ var ts; var symbols = []; var name_15 = symbol.name; ts.forEach(getSymbolLinks(symbol).containingType.types, function (t) { - symbols.push(getPropertyOfType(t, name_15)); + var symbol = getPropertyOfType(t, name_15); + if (symbol) { + symbols.push(symbol); + } }); return symbols; } @@ -29561,8 +29569,10 @@ var ts; function jsxEmitPreserve(node) { function emitJsxAttribute(node) { emit(node.name); - write("="); - emit(node.initializer); + if (node.initializer) { + write("="); + emit(node.initializer); + } } function emitJsxSpreadAttribute(node) { write("{..."); @@ -31270,21 +31280,30 @@ var ts; write(")"); } } - function ensureIdentifier(expr) { - if (expr.kind !== 67 /* Identifier */) { - var identifier = createTempVariable(0 /* Auto */); - if (!canDefineTempVariablesInPlace) { - recordTempDeclaration(identifier); - } - emitAssignment(identifier, expr); - expr = identifier; + /** + * Ensures that there exists a declared identifier whose value holds the given expression. + * This function is useful to ensure that the expression's value can be read from in subsequent expressions. + * Unless 'reuseIdentifierExpressions' is false, 'expr' will be returned if it is just an identifier. + * + * @param expr the expression whose value needs to be bound. + * @param reuseIdentifierExpressions true if identifier expressions can simply be returned; + * false if it is necessary to always emit an identifier. + */ + function ensureIdentifier(expr, reuseIdentifierExpressions) { + if (expr.kind === 67 /* Identifier */ && reuseIdentifierExpressions) { + return expr; } - return expr; + var identifier = createTempVariable(0 /* Auto */); + if (!canDefineTempVariablesInPlace) { + recordTempDeclaration(identifier); + } + emitAssignment(identifier, expr); + return identifier; } function createDefaultValueCheck(value, defaultValue) { // The value expression will be evaluated twice, so for anything but a simple identifier // we need to generate a temporary variable - value = ensureIdentifier(value); + value = ensureIdentifier(value, /*reuseIdentifierExpressions*/ true); // Return the expression 'value === void 0 ? defaultValue : value' var equals = ts.createSynthesizedNode(179 /* BinaryExpression */); equals.left = value; @@ -31330,7 +31349,7 @@ var ts; if (properties.length !== 1) { // For anything but a single element destructuring we need to generate a temporary // to ensure value is evaluated exactly once. - value = ensureIdentifier(value); + value = ensureIdentifier(value, /*reuseIdentifierExpressions*/ true); } for (var _a = 0; _a < properties.length; _a++) { var p = properties[_a]; @@ -31345,7 +31364,7 @@ var ts; if (elements.length !== 1) { // For anything but a single element destructuring we need to generate a temporary // to ensure value is evaluated exactly once. - value = ensureIdentifier(value); + value = ensureIdentifier(value, /*reuseIdentifierExpressions*/ true); } for (var i = 0; i < elements.length; i++) { var e = elements[i]; @@ -31387,7 +31406,7 @@ var ts; if (root.parent.kind !== 170 /* ParenthesizedExpression */) { write("("); } - value = ensureIdentifier(value); + value = ensureIdentifier(value, /*reuseIdentifierExpressions*/ true); emitDestructuringAssignment(target, value); write(", "); emit(value); @@ -31408,12 +31427,15 @@ var ts; if (ts.isBindingPattern(target.name)) { var pattern = target.name; var elements = pattern.elements; - if (elements.length !== 1) { - // For anything but a single element destructuring we need to generate a temporary - // to ensure value is evaluated exactly once. - value = ensureIdentifier(value); + var numElements = elements.length; + if (numElements !== 1) { + // For anything other than a single-element destructuring we need to generate a temporary + // to ensure value is evaluated exactly once. Additionally, if we have zero elements + // we need to emit *something* to ensure that in case a 'var' keyword was already emitted, + // so in that case, we'll intentionally create that temporary. + value = ensureIdentifier(value, /*reuseIdentifierExpressions*/ numElements !== 0); } - for (var i = 0; i < elements.length; i++) { + for (var i = 0; i < numElements; i++) { var element = elements[i]; if (pattern.kind === 159 /* ObjectBindingPattern */) { // Rewrite element to a declaration with an initializer that fetches property @@ -31425,7 +31447,7 @@ var ts; // Rewrite element to a declaration that accesses array element at index i emitBindingElement(element, createElementAccessExpression(value, createNumericLiteral(i))); } - else if (i === elements.length - 1) { + else if (i === numElements - 1) { emitBindingElement(element, createSliceCall(value, i)); } } @@ -32840,50 +32862,49 @@ var ts; write("void 0"); } function emitSerializedTypeNode(node) { - if (!node) { - return; - } - switch (node.kind) { - case 101 /* VoidKeyword */: - write("void 0"); - return; - case 158 /* ParenthesizedType */: - emitSerializedTypeNode(node.type); - return; - case 150 /* FunctionType */: - case 151 /* ConstructorType */: - write("Function"); - return; - case 154 /* ArrayType */: - case 155 /* TupleType */: - write("Array"); - return; - case 148 /* TypePredicate */: - case 118 /* BooleanKeyword */: - write("Boolean"); - return; - case 128 /* StringKeyword */: - case 9 /* StringLiteral */: - write("String"); - return; - case 126 /* NumberKeyword */: - write("Number"); - return; - case 129 /* SymbolKeyword */: - write("Symbol"); - return; - case 149 /* TypeReference */: - emitSerializedTypeReferenceNode(node); - return; - case 152 /* TypeQuery */: - case 153 /* TypeLiteral */: - case 156 /* UnionType */: - case 157 /* IntersectionType */: - case 115 /* AnyKeyword */: - break; - default: - ts.Debug.fail("Cannot serialize unexpected type node."); - break; + if (node) { + switch (node.kind) { + case 101 /* VoidKeyword */: + write("void 0"); + return; + case 158 /* ParenthesizedType */: + emitSerializedTypeNode(node.type); + return; + case 150 /* FunctionType */: + case 151 /* ConstructorType */: + write("Function"); + return; + case 154 /* ArrayType */: + case 155 /* TupleType */: + write("Array"); + return; + case 148 /* TypePredicate */: + case 118 /* BooleanKeyword */: + write("Boolean"); + return; + case 128 /* StringKeyword */: + case 9 /* StringLiteral */: + write("String"); + return; + case 126 /* NumberKeyword */: + write("Number"); + return; + case 129 /* SymbolKeyword */: + write("Symbol"); + return; + case 149 /* TypeReference */: + emitSerializedTypeReferenceNode(node); + return; + case 152 /* TypeQuery */: + case 153 /* TypeLiteral */: + case 156 /* UnionType */: + case 157 /* IntersectionType */: + case 115 /* AnyKeyword */: + break; + default: + ts.Debug.fail("Cannot serialize unexpected type node."); + break; + } } write("Object"); } @@ -35103,7 +35124,7 @@ var ts; /* @internal */ ts.ioWriteTime = 0; /** The version of the TypeScript compiler release */ var emptyArray = []; - ts.version = "1.6.0"; + ts.version = "1.6.2"; function findConfigFile(searchPath) { var fileName = "tsconfig.json"; while (true) { @@ -36251,8 +36272,8 @@ var ts; "node": 2 /* NodeJs */, "classic": 1 /* Classic */ }, - experimental: true, - description: ts.Diagnostics.Specifies_module_resolution_strategy_Colon_node_Node_or_classic_TypeScript_pre_1_6 + description: ts.Diagnostics.Specifies_module_resolution_strategy_Colon_node_Node_js_or_classic_TypeScript_pre_1_6, + error: ts.Diagnostics.Argument_for_moduleResolution_option_must_be_node_or_classic } ]; var optionNameMapCache; @@ -38721,7 +38742,7 @@ var ts; function findPrecedingToken(position, sourceFile, startNode) { return find(startNode || sourceFile); function findRightmostToken(n) { - if (isToken(n)) { + if (isToken(n) || n.kind === 234 /* JsxText */) { return n; } var children = n.getChildren(); @@ -38729,23 +38750,32 @@ var ts; return candidate && findRightmostToken(candidate); } function find(n) { - if (isToken(n)) { + if (isToken(n) || n.kind === 234 /* JsxText */) { return n; } var children = n.getChildren(); for (var i = 0, len = children.length; i < len; i++) { var child = children[i]; - if (nodeHasTokens(child)) { - if (position <= child.end) { - if (child.getStart(sourceFile) >= position) { - // actual start of the node is past the position - previous token should be at the end of previous child - var candidate = findRightmostChildNodeWithTokens(children, /*exclusiveStartPosition*/ i); - return candidate && findRightmostToken(candidate); - } - else { - // candidate should be in this node - return find(child); - } + // condition 'position < child.end' checks if child node end after the position + // in the example below this condition will be false for 'aaaa' and 'bbbb' and true for 'ccc' + // aaaa___bbbb___$__ccc + // after we found child node with end after the position we check if start of the node is after the position. + // if yes - then position is in the trivia and we need to look into the previous child to find the token in question. + // if no - position is in the node itself so we should recurse in it. + // NOTE: JsxText is a weird kind of node that can contain only whitespaces (since they are not counted as trivia). + // if this is the case - then we should assume that token in question is located in previous child. + if (position < child.end && (nodeHasTokens(child) || child.kind === 234 /* JsxText */)) { + var start = child.getStart(sourceFile); + var lookInPreviousChild = (start >= position) || + (child.kind === 234 /* JsxText */ && start === child.end); // whitespace only JsxText + if (lookInPreviousChild) { + // actual start of the node is past the position - previous token should be at the end of previous child + var candidate = findRightmostChildNodeWithTokens(children, /*exclusiveStartPosition*/ i); + return candidate && findRightmostToken(candidate); + } + else { + // candidate should be in this node + return find(child); } } } @@ -39162,6 +39192,7 @@ var ts; ScanAction[ScanAction["RescanGreaterThanToken"] = 1] = "RescanGreaterThanToken"; ScanAction[ScanAction["RescanSlashToken"] = 2] = "RescanSlashToken"; ScanAction[ScanAction["RescanTemplateToken"] = 3] = "RescanTemplateToken"; + ScanAction[ScanAction["RescanJsxIdentifier"] = 4] = "RescanJsxIdentifier"; })(ScanAction || (ScanAction = {})); function getFormattingScanner(sourceFile, startPos, endPos) { scanner.setText(sourceFile.text); @@ -39235,6 +39266,18 @@ var ts; } return false; } + function shouldRescanJsxIdentifier(node) { + if (node.parent) { + switch (node.parent.kind) { + case 236 /* JsxAttribute */: + case 233 /* JsxOpeningElement */: + case 235 /* JsxClosingElement */: + case 232 /* JsxSelfClosingElement */: + return node.kind === 67 /* Identifier */; + } + } + return false; + } function shouldRescanSlashToken(container) { return container.kind === 10 /* RegularExpressionLiteral */; } @@ -39262,7 +39305,9 @@ var ts; ? 2 /* RescanSlashToken */ : shouldRescanTemplateToken(n) ? 3 /* RescanTemplateToken */ - : 0 /* Scan */; + : shouldRescanJsxIdentifier(n) + ? 4 /* RescanJsxIdentifier */ + : 0 /* Scan */; if (lastTokenInfo && expectedScanAction === lastScanAction) { // readTokenInfo was called before with the same expected scan action. // No need to re-scan text, return existing 'lastTokenInfo' @@ -39293,6 +39338,10 @@ var ts; currentToken = scanner.reScanTemplateToken(); lastScanAction = 3 /* RescanTemplateToken */; } + else if (expectedScanAction === 4 /* RescanJsxIdentifier */ && currentToken === 67 /* Identifier */) { + currentToken = scanner.scanJsxIdentifier(); + lastScanAction = 4 /* RescanJsxIdentifier */; + } else { lastScanAction = 0 /* Scan */; } @@ -39633,7 +39682,7 @@ var ts; this.FunctionOpenBraceLeftTokenRange = formatting.Shared.TokenRange.AnyIncludingMultilineComments; this.SpaceBeforeOpenBraceInFunction = new formatting.Rule(formatting.RuleDescriptor.create2(this.FunctionOpenBraceLeftTokenRange, 15 /* OpenBraceToken */), formatting.RuleOperation.create2(new formatting.RuleOperationContext(Rules.IsFunctionDeclContext, Rules.IsBeforeBlockContext, Rules.IsNotFormatOnEnter, Rules.IsSameLineTokenOrBeforeMultilineBlockContext), 2 /* Space */), 1 /* CanDeleteNewLines */); // Place a space before open brace in a TypeScript declaration that has braces as children (class, module, enum, etc) - this.TypeScriptOpenBraceLeftTokenRange = formatting.Shared.TokenRange.FromTokens([67 /* Identifier */, 3 /* MultiLineCommentTrivia */]); + this.TypeScriptOpenBraceLeftTokenRange = formatting.Shared.TokenRange.FromTokens([67 /* Identifier */, 3 /* MultiLineCommentTrivia */, 71 /* ClassKeyword */]); this.SpaceBeforeOpenBraceInTypeScriptDeclWithBlock = new formatting.Rule(formatting.RuleDescriptor.create2(this.TypeScriptOpenBraceLeftTokenRange, 15 /* OpenBraceToken */), formatting.RuleOperation.create2(new formatting.RuleOperationContext(Rules.IsTypeScriptDeclWithBlockContext, Rules.IsNotFormatOnEnter, Rules.IsSameLineTokenOrBeforeMultilineBlockContext), 2 /* Space */), 1 /* CanDeleteNewLines */); // Place a space before open brace in a control flow construct this.ControlOpenBraceLeftTokenRange = formatting.Shared.TokenRange.FromTokens([18 /* CloseParenToken */, 3 /* MultiLineCommentTrivia */, 77 /* DoKeyword */, 98 /* TryKeyword */, 83 /* FinallyKeyword */, 78 /* ElseKeyword */]); @@ -39727,11 +39776,13 @@ var ts; // template string this.SpaceBetweenTagAndTemplateString = new formatting.Rule(formatting.RuleDescriptor.create3(67 /* Identifier */, formatting.Shared.TokenRange.FromTokens([11 /* NoSubstitutionTemplateLiteral */, 12 /* TemplateHead */])), formatting.RuleOperation.create2(new formatting.RuleOperationContext(Rules.IsSameLineTokenContext), 2 /* Space */)); this.NoSpaceBetweenTagAndTemplateString = new formatting.Rule(formatting.RuleDescriptor.create3(67 /* Identifier */, formatting.Shared.TokenRange.FromTokens([11 /* NoSubstitutionTemplateLiteral */, 12 /* TemplateHead */])), formatting.RuleOperation.create2(new formatting.RuleOperationContext(Rules.IsSameLineTokenContext), 8 /* Delete */)); - // union type + // type operation this.SpaceBeforeBar = new formatting.Rule(formatting.RuleDescriptor.create3(46 /* BarToken */, formatting.Shared.TokenRange.Any), formatting.RuleOperation.create2(new formatting.RuleOperationContext(Rules.IsSameLineTokenContext), 2 /* Space */)); this.NoSpaceBeforeBar = new formatting.Rule(formatting.RuleDescriptor.create3(46 /* BarToken */, formatting.Shared.TokenRange.Any), formatting.RuleOperation.create2(new formatting.RuleOperationContext(Rules.IsSameLineTokenContext), 8 /* Delete */)); this.SpaceAfterBar = new formatting.Rule(formatting.RuleDescriptor.create2(formatting.Shared.TokenRange.Any, 46 /* BarToken */), formatting.RuleOperation.create2(new formatting.RuleOperationContext(Rules.IsSameLineTokenContext), 2 /* Space */)); this.NoSpaceAfterBar = new formatting.Rule(formatting.RuleDescriptor.create2(formatting.Shared.TokenRange.Any, 46 /* BarToken */), formatting.RuleOperation.create2(new formatting.RuleOperationContext(Rules.IsSameLineTokenContext), 8 /* Delete */)); + this.SpaceBeforeAmpersand = new formatting.Rule(formatting.RuleDescriptor.create3(45 /* AmpersandToken */, formatting.Shared.TokenRange.Any), formatting.RuleOperation.create2(new formatting.RuleOperationContext(Rules.IsSameLineTokenContext), 2 /* Space */)); + this.SpaceAfterAmpersand = new formatting.Rule(formatting.RuleDescriptor.create2(formatting.Shared.TokenRange.Any, 45 /* AmpersandToken */), formatting.RuleOperation.create2(new formatting.RuleOperationContext(Rules.IsSameLineTokenContext), 2 /* Space */)); // These rules are higher in priority than user-configurable rules. this.HighPriorityCommonRules = [ @@ -39763,6 +39814,7 @@ var ts; this.SpaceAfterTypeKeyword, this.NoSpaceAfterTypeKeyword, this.SpaceBetweenTagAndTemplateString, this.NoSpaceBetweenTagAndTemplateString, this.SpaceBeforeBar, this.NoSpaceBeforeBar, this.SpaceAfterBar, this.NoSpaceAfterBar, + this.SpaceBeforeAmpersand, this.SpaceAfterAmpersand, // TypeScript-specific rules this.NoSpaceAfterConstructor, this.NoSpaceAfterModuleImport, this.SpaceAfterCertainTypeScriptKeywords, this.SpaceBeforeCertainTypeScriptKeywords, @@ -39967,6 +40019,7 @@ var ts; Rules.NodeIsTypeScriptDeclWithBlockContext = function (node) { switch (node.kind) { case 212 /* ClassDeclaration */: + case 184 /* ClassExpression */: case 213 /* InterfaceDeclaration */: case 215 /* EnumDeclaration */: case 153 /* TypeLiteral */: @@ -41704,6 +41757,7 @@ var ts; function nodeContentIsAlwaysIndented(kind) { switch (kind) { case 212 /* ClassDeclaration */: + case 184 /* ClassExpression */: case 213 /* InterfaceDeclaration */: case 215 /* EnumDeclaration */: case 214 /* TypeAliasDeclaration */: @@ -41728,13 +41782,13 @@ var ts; case 160 /* ArrayBindingPattern */: case 159 /* ObjectBindingPattern */: case 231 /* JsxElement */: + case 232 /* JsxSelfClosingElement */: case 140 /* MethodSignature */: case 145 /* CallSignature */: case 146 /* ConstructSignature */: case 136 /* Parameter */: case 150 /* FunctionType */: case 151 /* ConstructorType */: - case 156 /* UnionType */: case 158 /* ParenthesizedType */: case 168 /* TaggedTemplateExpression */: case 176 /* AwaitExpression */: @@ -42858,7 +42912,7 @@ var ts; var sourceMapText; // Create a compilerHost object to allow the compiler to read and write files var compilerHost = { - getSourceFile: function (fileName, target) { return fileName === inputFileName ? sourceFile : undefined; }, + getSourceFile: function (fileName, target) { return fileName === ts.normalizeSlashes(inputFileName) ? sourceFile : undefined; }, writeFile: function (name, text, writeByteOrderMark) { if (ts.fileExtensionIs(name, ".map")) { ts.Debug.assert(sourceMapText === undefined, "Unexpected multiple source map outputs for the file '" + name + "'"); @@ -43106,6 +43160,7 @@ var ts; // // export * from "mod" // export {a as b} from "mod" + // export import i = require("mod") while (token !== 1 /* EndOfFileToken */) { if (token === 120 /* DeclareKeyword */) { // declare module "mod" @@ -43226,6 +43281,25 @@ var ts; } } } + else if (token === 87 /* ImportKeyword */) { + token = scanner.scan(); + if (token === 67 /* Identifier */ || ts.isKeyword(token)) { + token = scanner.scan(); + if (token === 55 /* EqualsToken */) { + token = scanner.scan(); + if (token === 125 /* RequireKeyword */) { + token = scanner.scan(); + if (token === 17 /* OpenParenToken */) { + token = scanner.scan(); + if (token === 9 /* StringLiteral */) { + // export import i = require("mod"); + recordModuleName(); + } + } + } + } + } + } } token = scanner.scan(); } From 4b5c2fe31c94a6f3e4422024107a70e96a14c3d8 Mon Sep 17 00:00:00 2001 From: Vladimir Matveev Date: Thu, 10 Sep 2015 10:46:39 -0700 Subject: [PATCH 23/28] reattach file diagnostics for modified files when reusing program structure --- src/compiler/program.ts | 78 +++++++++++-------- src/compiler/types.ts | 3 + src/compiler/utilities.ts | 13 +++- .../cases/unittests/reuseProgramStructure.ts | 9 ++- 4 files changed, 67 insertions(+), 36 deletions(-) diff --git a/src/compiler/program.ts b/src/compiler/program.ts index c239b18efb7..925ebfeb8af 100644 --- a/src/compiler/program.ts +++ b/src/compiler/program.ts @@ -358,7 +358,8 @@ namespace ts { export function createProgram(rootNames: string[], options: CompilerOptions, host?: CompilerHost, oldProgram?: Program): Program { let program: Program; let files: SourceFile[] = []; - let diagnostics = createDiagnosticCollection(); + let fileProcessingDiagnostics = createDiagnosticCollection(); + let programDiagnostics = createDiagnosticCollection(); let commonSourceDirectory: string; let diagnosticsProducingTypeChecker: TypeChecker; @@ -428,6 +429,7 @@ namespace ts { getIdentifierCount: () => getDiagnosticsProducingTypeChecker().getIdentifierCount(), getSymbolCount: () => getDiagnosticsProducingTypeChecker().getSymbolCount(), getTypeCount: () => getDiagnosticsProducingTypeChecker().getTypeCount(), + getFileProcessingDiagnostics: () => fileProcessingDiagnostics }; return program; @@ -460,6 +462,7 @@ namespace ts { // check if program source files has changed in the way that can affect structure of the program let newSourceFiles: SourceFile[] = []; + let modifiedSourceFiles: SourceFile[] = []; for (let oldSourceFile of oldProgram.getSourceFiles()) { let newSourceFile = host.getSourceFile(oldSourceFile.fileName, options.target); if (!newSourceFile) { @@ -499,6 +502,7 @@ namespace ts { } // pass the cache of module resolutions from the old source file newSourceFile.resolvedModules = oldSourceFile.resolvedModules; + modifiedSourceFiles.push(newSourceFile); } else { // file has no changes - use it as is @@ -515,7 +519,11 @@ namespace ts { } files = newSourceFiles; + fileProcessingDiagnostics = oldProgram.getFileProcessingDiagnostics(); + for (let modifiedFile of modifiedSourceFiles) { + fileProcessingDiagnostics.reattachFileDiagnostics(modifiedFile); + } oldProgram.structureIsReused = true; return true; @@ -645,9 +653,10 @@ namespace ts { Debug.assert(!!sourceFile.bindDiagnostics); let bindDiagnostics = sourceFile.bindDiagnostics; let checkDiagnostics = typeChecker.getDiagnostics(sourceFile, cancellationToken); - let programDiagnostics = diagnostics.getDiagnostics(sourceFile.fileName); + let fileProcessingDiagnosticsInFile = fileProcessingDiagnostics.getDiagnostics(sourceFile.fileName); + let programDiagnosticsInFile = programDiagnostics.getDiagnostics(sourceFile.fileName); - return bindDiagnostics.concat(checkDiagnostics).concat(programDiagnostics); + return bindDiagnostics.concat(checkDiagnostics).concat(fileProcessingDiagnosticsInFile).concat(programDiagnosticsInFile); }); } @@ -664,7 +673,8 @@ namespace ts { function getOptionsDiagnostics(): Diagnostic[] { let allDiagnostics: Diagnostic[] = []; - addRange(allDiagnostics, diagnostics.getGlobalDiagnostics()); + addRange(allDiagnostics, fileProcessingDiagnostics.getGlobalDiagnostics()) + addRange(allDiagnostics, programDiagnostics.getGlobalDiagnostics()); return sortAndDeduplicateDiagnostics(allDiagnostics); } @@ -772,10 +782,10 @@ namespace ts { if (diagnostic) { if (refFile !== undefined && refEnd !== undefined && refPos !== undefined) { - diagnostics.add(createFileDiagnostic(refFile, refPos, refEnd - refPos, diagnostic, ...diagnosticArgument)); + fileProcessingDiagnostics.add(createFileDiagnostic(refFile, refPos, refEnd - refPos, diagnostic, ...diagnosticArgument)); } else { - diagnostics.add(createCompilerDiagnostic(diagnostic, ...diagnosticArgument)); + fileProcessingDiagnostics.add(createCompilerDiagnostic(diagnostic, ...diagnosticArgument)); } } } @@ -797,11 +807,11 @@ namespace ts { // We haven't looked for this file, do so now and cache result let file = host.getSourceFile(fileName, options.target, hostErrorMessage => { if (refFile !== undefined && refPos !== undefined && refEnd !== undefined) { - diagnostics.add(createFileDiagnostic(refFile, refPos, refEnd - refPos, + fileProcessingDiagnostics.add(createFileDiagnostic(refFile, refPos, refEnd - refPos, Diagnostics.Cannot_read_file_0_Colon_1, fileName, hostErrorMessage)); } else { - diagnostics.add(createCompilerDiagnostic(Diagnostics.Cannot_read_file_0_Colon_1, fileName, hostErrorMessage)); + fileProcessingDiagnostics.add(createCompilerDiagnostic(Diagnostics.Cannot_read_file_0_Colon_1, fileName, hostErrorMessage)); } }); filesByName.set(canonicalName, file); @@ -837,11 +847,11 @@ namespace ts { let sourceFileName = useAbsolutePath ? getNormalizedAbsolutePath(file.fileName, host.getCurrentDirectory()) : file.fileName; if (canonicalName !== sourceFileName) { if (refFile !== undefined && refPos !== undefined && refEnd !== undefined) { - diagnostics.add(createFileDiagnostic(refFile, refPos, refEnd - refPos, + fileProcessingDiagnostics.add(createFileDiagnostic(refFile, refPos, refEnd - refPos, Diagnostics.File_name_0_differs_from_already_included_file_name_1_only_in_casing, fileName, sourceFileName)); } else { - diagnostics.add(createCompilerDiagnostic(Diagnostics.File_name_0_differs_from_already_included_file_name_1_only_in_casing, fileName, sourceFileName)); + fileProcessingDiagnostics.add(createCompilerDiagnostic(Diagnostics.File_name_0_differs_from_already_included_file_name_1_only_in_casing, fileName, sourceFileName)); } } } @@ -877,7 +887,7 @@ namespace ts { return; function findModuleSourceFile(fileName: string, nameLiteral: Expression) { - return findSourceFile(fileName, /* isDefaultLib */ false, file, nameLiteral.pos, nameLiteral.end); + return findSourceFile(fileName, /* isDefaultLib */ false, file, skipTrivia(file.text, nameLiteral.pos), nameLiteral.end); } } @@ -902,7 +912,7 @@ namespace ts { for (let i = 0, n = Math.min(commonPathComponents.length, sourcePathComponents.length); i < n; i++) { if (commonPathComponents[i] !== sourcePathComponents[i]) { if (i === 0) { - diagnostics.add(createCompilerDiagnostic(Diagnostics.Cannot_find_the_common_subdirectory_path_for_the_input_files)); + programDiagnostics.add(createCompilerDiagnostic(Diagnostics.Cannot_find_the_common_subdirectory_path_for_the_input_files)); return; } @@ -931,7 +941,7 @@ namespace ts { if (!isDeclarationFile(sourceFile)) { let absoluteSourceFilePath = host.getCanonicalFileName(getNormalizedAbsolutePath(sourceFile.fileName, currentDirectory)); if (absoluteSourceFilePath.indexOf(absoluteRootDirectoryPath) !== 0) { - diagnostics.add(createCompilerDiagnostic(Diagnostics.File_0_is_not_under_rootDir_1_rootDir_is_expected_to_contain_all_source_files, sourceFile.fileName, options.rootDir)); + programDiagnostics.add(createCompilerDiagnostic(Diagnostics.File_0_is_not_under_rootDir_1_rootDir_is_expected_to_contain_all_source_files, sourceFile.fileName, options.rootDir)); allFilesBelongToPath = false; } } @@ -944,52 +954,52 @@ namespace ts { function verifyCompilerOptions() { if (options.isolatedModules) { if (options.declaration) { - diagnostics.add(createCompilerDiagnostic(Diagnostics.Option_0_cannot_be_specified_with_option_1, "declaration", "isolatedModules")); + programDiagnostics.add(createCompilerDiagnostic(Diagnostics.Option_0_cannot_be_specified_with_option_1, "declaration", "isolatedModules")); } if (options.noEmitOnError) { - diagnostics.add(createCompilerDiagnostic(Diagnostics.Option_0_cannot_be_specified_with_option_1, "noEmitOnError", "isolatedModules")); + programDiagnostics.add(createCompilerDiagnostic(Diagnostics.Option_0_cannot_be_specified_with_option_1, "noEmitOnError", "isolatedModules")); } if (options.out) { - diagnostics.add(createCompilerDiagnostic(Diagnostics.Option_0_cannot_be_specified_with_option_1, "out", "isolatedModules")); + programDiagnostics.add(createCompilerDiagnostic(Diagnostics.Option_0_cannot_be_specified_with_option_1, "out", "isolatedModules")); } if (options.outFile) { - diagnostics.add(createCompilerDiagnostic(Diagnostics.Option_0_cannot_be_specified_with_option_1, "outFile", "isolatedModules")); + programDiagnostics.add(createCompilerDiagnostic(Diagnostics.Option_0_cannot_be_specified_with_option_1, "outFile", "isolatedModules")); } } if (options.inlineSourceMap) { if (options.sourceMap) { - diagnostics.add(createCompilerDiagnostic(Diagnostics.Option_0_cannot_be_specified_with_option_1, "sourceMap", "inlineSourceMap")); + programDiagnostics.add(createCompilerDiagnostic(Diagnostics.Option_0_cannot_be_specified_with_option_1, "sourceMap", "inlineSourceMap")); } if (options.mapRoot) { - diagnostics.add(createCompilerDiagnostic(Diagnostics.Option_0_cannot_be_specified_with_option_1, "mapRoot", "inlineSourceMap")); + programDiagnostics.add(createCompilerDiagnostic(Diagnostics.Option_0_cannot_be_specified_with_option_1, "mapRoot", "inlineSourceMap")); } if (options.sourceRoot) { - diagnostics.add(createCompilerDiagnostic(Diagnostics.Option_0_cannot_be_specified_with_option_1, "sourceRoot", "inlineSourceMap")); + programDiagnostics.add(createCompilerDiagnostic(Diagnostics.Option_0_cannot_be_specified_with_option_1, "sourceRoot", "inlineSourceMap")); } } if (options.inlineSources) { if (!options.sourceMap && !options.inlineSourceMap) { - diagnostics.add(createCompilerDiagnostic(Diagnostics.Option_inlineSources_can_only_be_used_when_either_option_inlineSourceMap_or_option_sourceMap_is_provided)); + programDiagnostics.add(createCompilerDiagnostic(Diagnostics.Option_inlineSources_can_only_be_used_when_either_option_inlineSourceMap_or_option_sourceMap_is_provided)); } } if (options.out && options.outFile) { - diagnostics.add(createCompilerDiagnostic(Diagnostics.Option_0_cannot_be_specified_with_option_1, "out", "outFile")); + programDiagnostics.add(createCompilerDiagnostic(Diagnostics.Option_0_cannot_be_specified_with_option_1, "out", "outFile")); } if (!options.sourceMap && (options.mapRoot || options.sourceRoot)) { // Error to specify --mapRoot or --sourceRoot without mapSourceFiles if (options.mapRoot) { - diagnostics.add(createCompilerDiagnostic(Diagnostics.Option_0_cannot_be_specified_without_specifying_option_1, "mapRoot", "sourceMap")); + programDiagnostics.add(createCompilerDiagnostic(Diagnostics.Option_0_cannot_be_specified_without_specifying_option_1, "mapRoot", "sourceMap")); } if (options.sourceRoot) { - diagnostics.add(createCompilerDiagnostic(Diagnostics.Option_0_cannot_be_specified_without_specifying_option_1, "sourceRoot", "sourceMap")); + programDiagnostics.add(createCompilerDiagnostic(Diagnostics.Option_0_cannot_be_specified_without_specifying_option_1, "sourceRoot", "sourceMap")); } return; } @@ -1000,24 +1010,24 @@ namespace ts { let firstExternalModuleSourceFile = forEach(files, f => isExternalModule(f) ? f : undefined); if (options.isolatedModules) { if (!options.module && languageVersion < ScriptTarget.ES6) { - diagnostics.add(createCompilerDiagnostic(Diagnostics.Option_isolatedModules_can_only_be_used_when_either_option_module_is_provided_or_option_target_is_ES6_or_higher)); + programDiagnostics.add(createCompilerDiagnostic(Diagnostics.Option_isolatedModules_can_only_be_used_when_either_option_module_is_provided_or_option_target_is_ES6_or_higher)); } let firstNonExternalModuleSourceFile = forEach(files, f => !isExternalModule(f) && !isDeclarationFile(f) ? f : undefined); if (firstNonExternalModuleSourceFile) { let span = getErrorSpanForNode(firstNonExternalModuleSourceFile, firstNonExternalModuleSourceFile); - diagnostics.add(createFileDiagnostic(firstNonExternalModuleSourceFile, span.start, span.length, Diagnostics.Cannot_compile_namespaces_when_the_isolatedModules_flag_is_provided)); + programDiagnostics.add(createFileDiagnostic(firstNonExternalModuleSourceFile, span.start, span.length, Diagnostics.Cannot_compile_namespaces_when_the_isolatedModules_flag_is_provided)); } } else if (firstExternalModuleSourceFile && languageVersion < ScriptTarget.ES6 && !options.module) { // We cannot use createDiagnosticFromNode because nodes do not have parents yet let span = getErrorSpanForNode(firstExternalModuleSourceFile, firstExternalModuleSourceFile.externalModuleIndicator); - diagnostics.add(createFileDiagnostic(firstExternalModuleSourceFile, span.start, span.length, Diagnostics.Cannot_compile_modules_unless_the_module_flag_is_provided)); + programDiagnostics.add(createFileDiagnostic(firstExternalModuleSourceFile, span.start, span.length, Diagnostics.Cannot_compile_modules_unless_the_module_flag_is_provided)); } // Cannot specify module gen target when in es6 or above if (options.module && languageVersion >= ScriptTarget.ES6) { - diagnostics.add(createCompilerDiagnostic(Diagnostics.Cannot_compile_modules_into_commonjs_amd_system_or_umd_when_targeting_ES6_or_higher)); + programDiagnostics.add(createCompilerDiagnostic(Diagnostics.Cannot_compile_modules_into_commonjs_amd_system_or_umd_when_targeting_ES6_or_higher)); } // there has to be common source directory if user specified --outdir || --sourceRoot @@ -1046,30 +1056,30 @@ namespace ts { if (options.noEmit) { if (options.out) { - diagnostics.add(createCompilerDiagnostic(Diagnostics.Option_0_cannot_be_specified_with_option_1, "noEmit", "out")); + programDiagnostics.add(createCompilerDiagnostic(Diagnostics.Option_0_cannot_be_specified_with_option_1, "noEmit", "out")); } if (options.outFile) { - diagnostics.add(createCompilerDiagnostic(Diagnostics.Option_0_cannot_be_specified_with_option_1, "noEmit", "outFile")); + programDiagnostics.add(createCompilerDiagnostic(Diagnostics.Option_0_cannot_be_specified_with_option_1, "noEmit", "outFile")); } if (options.outDir) { - diagnostics.add(createCompilerDiagnostic(Diagnostics.Option_0_cannot_be_specified_with_option_1, "noEmit", "outDir")); + programDiagnostics.add(createCompilerDiagnostic(Diagnostics.Option_0_cannot_be_specified_with_option_1, "noEmit", "outDir")); } if (options.declaration) { - diagnostics.add(createCompilerDiagnostic(Diagnostics.Option_0_cannot_be_specified_with_option_1, "noEmit", "declaration")); + programDiagnostics.add(createCompilerDiagnostic(Diagnostics.Option_0_cannot_be_specified_with_option_1, "noEmit", "declaration")); } } if (options.emitDecoratorMetadata && !options.experimentalDecorators) { - diagnostics.add(createCompilerDiagnostic(Diagnostics.Option_0_cannot_be_specified_without_specifying_option_1, "emitDecoratorMetadata", "experimentalDecorators")); + programDiagnostics.add(createCompilerDiagnostic(Diagnostics.Option_0_cannot_be_specified_without_specifying_option_1, "emitDecoratorMetadata", "experimentalDecorators")); } if (options.experimentalAsyncFunctions && options.target !== ScriptTarget.ES6) { - diagnostics.add(createCompilerDiagnostic(Diagnostics.Option_experimentalAsyncFunctions_cannot_be_specified_when_targeting_ES5_or_lower)); + programDiagnostics.add(createCompilerDiagnostic(Diagnostics.Option_experimentalAsyncFunctions_cannot_be_specified_when_targeting_ES5_or_lower)); } } } diff --git a/src/compiler/types.ts b/src/compiler/types.ts index f9d1b506274..5b5e7aef743 100644 --- a/src/compiler/types.ts +++ b/src/compiler/types.ts @@ -1359,6 +1359,7 @@ namespace ts { /* @internal */ getSymbolCount(): number; /* @internal */ getTypeCount(): number; + /* @internal */ getFileProcessingDiagnostics(): DiagnosticCollection; // For testing purposes only. /* @internal */ structureIsReused?: boolean; } @@ -2335,5 +2336,7 @@ namespace ts { // operation caused diagnostics to be returned by storing and comparing the return value // of this method before/after the operation is performed. getModificationCount(): number; + + /* @internal */ reattachFileDiagnostics(newFile: SourceFile): void; } } diff --git a/src/compiler/utilities.ts b/src/compiler/utilities.ts index 99ea06532a0..6c5bd8df95d 100644 --- a/src/compiler/utilities.ts +++ b/src/compiler/utilities.ts @@ -1507,12 +1507,23 @@ namespace ts { add, getGlobalDiagnostics, getDiagnostics, - getModificationCount + getModificationCount, + reattachFileDiagnostics }; function getModificationCount() { return modificationCount; } + + function reattachFileDiagnostics(newFile: SourceFile): void { + if (!hasProperty(fileDiagnostics, newFile.fileName)) { + return; + } + + for (let diagnostic of fileDiagnostics[newFile.fileName]) { + diagnostic.file = newFile; + } + } function add(diagnostic: Diagnostic): void { let diagnostics: Diagnostic[]; diff --git a/tests/cases/unittests/reuseProgramStructure.ts b/tests/cases/unittests/reuseProgramStructure.ts index 6c043299c8f..56b1dedbcbb 100644 --- a/tests/cases/unittests/reuseProgramStructure.ts +++ b/tests/cases/unittests/reuseProgramStructure.ts @@ -184,7 +184,11 @@ module ts { describe("Reuse program structure", () => { let target = ScriptTarget.Latest; let files = [ - { name: "a.ts", text: SourceText.New(`/// `, "", `var x = 1`) }, + { name: "a.ts", text: SourceText.New( + ` +/// +/// +`, "",`var x = 1`) }, { name: "b.ts", text: SourceText.New(`/// `, "", `var y = 2`) }, { name: "c.ts", text: SourceText.New("", "", `var z = 1;`) }, ] @@ -195,6 +199,9 @@ module ts { files[0].text = files[0].text.updateProgram("var x = 100"); }); assert.isTrue(program_1.structureIsReused); + let program1Diagnostics = program_1.getSemanticDiagnostics(program_1.getSourceFile("a.ts")) + let program2Diagnostics = program_2.getSemanticDiagnostics(program_1.getSourceFile("a.ts")) + assert.equal(program1Diagnostics.length, program2Diagnostics.length); }); it("fails if change affects tripleslash references", () => { From 98f31635f89ac52da14f8ccbeb8fc6bfbfc18014 Mon Sep 17 00:00:00 2001 From: Vladimir Matveev Date: Thu, 10 Sep 2015 11:36:31 -0700 Subject: [PATCH 24/28] Check if imported file is a proper external module --- src/compiler/checker.ts | 4 +- .../diagnosticInformationMap.generated.ts | 2 + src/compiler/diagnosticMessages.json | 8 ++ src/compiler/program.ts | 91 +++++++++---------- src/compiler/types.ts | 17 +++- src/compiler/utilities.ts | 10 +- src/harness/harnessLanguageService.ts | 4 +- src/server/editorServices.ts | 14 +-- src/services/services.ts | 4 +- src/services/shims.ts | 13 ++- tests/baselines/reference/nodeResolution4.js | 17 ++++ .../reference/nodeResolution4.symbols | 14 +++ .../baselines/reference/nodeResolution4.types | 15 +++ .../reference/nodeResolution5.errors.txt | 14 +++ tests/baselines/reference/nodeResolution5.js | 13 +++ .../reference/nodeResolution6.errors.txt | 17 ++++ tests/baselines/reference/nodeResolution6.js | 18 ++++ .../reference/nodeResolution7.errors.txt | 14 +++ tests/baselines/reference/nodeResolution7.js | 13 +++ .../reference/nodeResolution8.errors.txt | 16 ++++ tests/baselines/reference/nodeResolution8.js | 17 ++++ tests/cases/compiler/nodeResolution4.ts | 12 +++ tests/cases/compiler/nodeResolution5.ts | 10 ++ tests/cases/compiler/nodeResolution6.ts | 13 +++ tests/cases/compiler/nodeResolution7.ts | 10 ++ tests/cases/compiler/nodeResolution8.ts | 13 +++ tests/cases/unittests/moduleResolution.ts | 79 +++------------- .../cases/unittests/reuseProgramStructure.ts | 19 +++- 28 files changed, 347 insertions(+), 144 deletions(-) create mode 100644 tests/baselines/reference/nodeResolution4.js create mode 100644 tests/baselines/reference/nodeResolution4.symbols create mode 100644 tests/baselines/reference/nodeResolution4.types create mode 100644 tests/baselines/reference/nodeResolution5.errors.txt create mode 100644 tests/baselines/reference/nodeResolution5.js create mode 100644 tests/baselines/reference/nodeResolution6.errors.txt create mode 100644 tests/baselines/reference/nodeResolution6.js create mode 100644 tests/baselines/reference/nodeResolution7.errors.txt create mode 100644 tests/baselines/reference/nodeResolution7.js create mode 100644 tests/baselines/reference/nodeResolution8.errors.txt create mode 100644 tests/baselines/reference/nodeResolution8.js create mode 100644 tests/cases/compiler/nodeResolution4.ts create mode 100644 tests/cases/compiler/nodeResolution5.ts create mode 100644 tests/cases/compiler/nodeResolution6.ts create mode 100644 tests/cases/compiler/nodeResolution7.ts create mode 100644 tests/cases/compiler/nodeResolution8.ts diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 6c45f630ed7..0ae5bc8e795 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -976,8 +976,8 @@ namespace ts { } } - let fileName = getResolvedModuleFileName(getSourceFile(location), moduleReferenceLiteral.text); - let sourceFile = fileName && host.getSourceFile(fileName); + let resolvedModule = getResolvedModule(getSourceFile(location), moduleReferenceLiteral.text); + let sourceFile = resolvedModule && host.getSourceFile(resolvedModule.resolvedFileName); if (sourceFile) { if (sourceFile.symbol) { return sourceFile.symbol; diff --git a/src/compiler/diagnosticInformationMap.generated.ts b/src/compiler/diagnosticInformationMap.generated.ts index 1c9232d1515..2b67d676d51 100644 --- a/src/compiler/diagnosticInformationMap.generated.ts +++ b/src/compiler/diagnosticInformationMap.generated.ts @@ -427,6 +427,8 @@ namespace ts { Cannot_emit_namespaced_JSX_elements_in_React: { code: 2650, category: DiagnosticCategory.Error, key: "Cannot emit namespaced JSX elements in React" }, A_member_initializer_in_a_enum_declaration_cannot_reference_members_declared_after_it_including_members_defined_in_other_enums: { code: 2651, category: DiagnosticCategory.Error, key: "A member initializer in a enum declaration cannot reference members declared after it, including members defined in other enums." }, Merged_declaration_0_cannot_include_a_default_export_declaration_Consider_adding_a_separate_export_default_0_declaration_instead: { code: 2652, category: DiagnosticCategory.Error, key: "Merged declaration '{0}' cannot include a default export declaration. Consider adding a separate 'export default {0}' declaration instead." }, + Proper_external_module_that_carries_external_typings_cannot_contain_tripleslash_references: { code: 2654, category: DiagnosticCategory.Error, key: "Proper external module that carries external typings cannot contain tripleslash references." }, + Proper_external_module_that_carries_external_typings_should_be_d_ts_file: { code: 2655, category: DiagnosticCategory.Error, key: "Proper external module that carries external typings should be '.d.ts' file." }, Import_declaration_0_is_using_private_name_1: { code: 4000, category: DiagnosticCategory.Error, key: "Import declaration '{0}' is using private name '{1}'." }, Type_parameter_0_of_exported_class_has_or_is_using_private_name_1: { code: 4002, category: DiagnosticCategory.Error, key: "Type parameter '{0}' of exported class has or is using private name '{1}'." }, Type_parameter_0_of_exported_interface_has_or_is_using_private_name_1: { code: 4004, category: DiagnosticCategory.Error, key: "Type parameter '{0}' of exported interface has or is using private name '{1}'." }, diff --git a/src/compiler/diagnosticMessages.json b/src/compiler/diagnosticMessages.json index f6875c45c47..ad82541ad79 100644 --- a/src/compiler/diagnosticMessages.json +++ b/src/compiler/diagnosticMessages.json @@ -1697,6 +1697,14 @@ "category": "Error", "code": 2652 }, + "Proper external module that carries external typings cannot contain tripleslash references.": { + "category": "Error", + "code": 2654 + }, + "Proper external module that carries external typings should be '.d.ts' file.": { + "category": "Error", + "code": 2655 + }, "Import declaration '{0}' is using private name '{1}'.": { "category": "Error", "code": 4000 diff --git a/src/compiler/program.ts b/src/compiler/program.ts index 925ebfeb8af..f6931aea545 100644 --- a/src/compiler/program.ts +++ b/src/compiler/program.ts @@ -36,7 +36,7 @@ namespace ts { return normalizePath(referencedFileName); } - export function resolveModuleName(moduleName: string, containingFile: string, compilerOptions: CompilerOptions, host: ModuleResolutionHost): ResolvedModule { + export function resolveModuleName(moduleName: string, containingFile: string, compilerOptions: CompilerOptions, host: ModuleResolutionHost): ResolvedModuleWithFailedLookupLocations { let moduleResolution = compilerOptions.moduleResolution !== undefined ? compilerOptions.moduleResolution : compilerOptions.module === ModuleKind.CommonJS ? ModuleResolutionKind.NodeJs : ModuleResolutionKind.Classic; @@ -47,7 +47,7 @@ namespace ts { } } - export function nodeModuleNameResolver(moduleName: string, containingFile: string, host: ModuleResolutionHost): ResolvedModule { + export function nodeModuleNameResolver(moduleName: string, containingFile: string, host: ModuleResolutionHost): ResolvedModuleWithFailedLookupLocations { let containingDirectory = getDirectoryPath(containingFile); if (getRootLength(moduleName) !== 0 || nameStartsWithDotSlashOrDotDotSlash(moduleName)) { @@ -56,11 +56,13 @@ namespace ts { let resolvedFileName = loadNodeModuleFromFile(candidate, /* loadOnlyDts */ false, failedLookupLocations, host); if (resolvedFileName) { - return { resolvedFileName, failedLookupLocations }; + return { resolvedModule: { resolvedFileName }, failedLookupLocations }; } resolvedFileName = loadNodeModuleFromDirectory(candidate, /* loadOnlyDts */ false, failedLookupLocations, host); - return { resolvedFileName, failedLookupLocations }; + return resolvedFileName + ? { resolvedModule: { resolvedFileName }, failedLookupLocations } + : { resolvedModule: undefined, failedLookupLocations }; } else { return loadModuleFromNodeModules(moduleName, containingDirectory, host); @@ -117,7 +119,7 @@ namespace ts { return loadNodeModuleFromFile(combinePaths(candidate, "index"), loadOnlyDts, failedLookupLocation, host); } - function loadModuleFromNodeModules(moduleName: string, directory: string, host: ModuleResolutionHost): ResolvedModule { + function loadModuleFromNodeModules(moduleName: string, directory: string, host: ModuleResolutionHost): ResolvedModuleWithFailedLookupLocations { let failedLookupLocations: string[] = []; directory = normalizeSlashes(directory); while (true) { @@ -127,12 +129,12 @@ namespace ts { let candidate = normalizePath(combinePaths(nodeModulesFolder, moduleName)); let result = loadNodeModuleFromFile(candidate, /* loadOnlyDts */ true, failedLookupLocations, host); if (result) { - return { resolvedFileName: result, failedLookupLocations }; + return { resolvedModule: { resolvedFileName: result, shouldBeProperExternalModule: true }, failedLookupLocations }; } result = loadNodeModuleFromDirectory(candidate, /* loadOnlyDts */ true, failedLookupLocations, host); if (result) { - return { resolvedFileName: result, failedLookupLocations }; + return { resolvedModule: { resolvedFileName: result, shouldBeProperExternalModule: true }, failedLookupLocations }; } } @@ -144,47 +146,19 @@ namespace ts { directory = parentPath; } - return { resolvedFileName: undefined, failedLookupLocations }; - } - - export function baseUrlModuleNameResolver(moduleName: string, containingFile: string, baseUrl: string, host: ModuleResolutionHost): ResolvedModule { - Debug.assert(baseUrl !== undefined); - - let normalizedModuleName = normalizeSlashes(moduleName); - let basePart = useBaseUrl(moduleName) ? baseUrl : getDirectoryPath(containingFile); - let candidate = normalizePath(combinePaths(basePart, moduleName)); - - let failedLookupLocations: string[] = []; - - return forEach(supportedExtensions, ext => tryLoadFile(candidate + ext)) || { resolvedFileName: undefined, failedLookupLocations }; - - function tryLoadFile(location: string): ResolvedModule { - if (host.fileExists(location)) { - return { resolvedFileName: location, failedLookupLocations }; - } - else { - failedLookupLocations.push(location); - return undefined; - } - } + return { resolvedModule: undefined, failedLookupLocations }; } function nameStartsWithDotSlashOrDotDotSlash(name: string) { let i = name.lastIndexOf("./", 1); return i === 0 || (i === 1 && name.charCodeAt(0) === CharacterCodes.dot); } - - function useBaseUrl(moduleName: string): boolean { - // path is not rooted - // module name does not start with './' or '../' - return getRootLength(moduleName) === 0 && !nameStartsWithDotSlashOrDotDotSlash(moduleName); - } - export function classicNameResolver(moduleName: string, containingFile: string, compilerOptions: CompilerOptions, host: ModuleResolutionHost): ResolvedModule { + export function classicNameResolver(moduleName: string, containingFile: string, compilerOptions: CompilerOptions, host: ModuleResolutionHost): ResolvedModuleWithFailedLookupLocations { // module names that contain '!' are used to reference resources and are not resolved to actual files on disk if (moduleName.indexOf('!') != -1) { - return { resolvedFileName: undefined, failedLookupLocations: [] }; + return { resolvedModule: undefined, failedLookupLocations: [] }; } let searchPath = getDirectoryPath(containingFile); @@ -222,7 +196,9 @@ namespace ts { searchPath = parentPath; } - return { resolvedFileName: referencedSourceFile, failedLookupLocations }; + return referencedSourceFile + ? { resolvedModule: { resolvedFileName: referencedSourceFile }, failedLookupLocations } + : { resolvedModule: undefined, failedLookupLocations }; } /* @internal */ @@ -372,9 +348,9 @@ namespace ts { host = host || createCompilerHost(options); - const resolveModuleNamesWorker = - host.resolveModuleNames || - ((moduleNames, containingFile) => map(moduleNames, moduleName => resolveModuleName(moduleName, containingFile, options, host).resolvedFileName)); + const resolveModuleNamesWorker = host.resolveModuleNames + ? ((moduleNames: string[], containingFile: string) => host.resolveModuleNames(moduleNames, containingFile)) + : ((moduleNames: string[], containingFile: string) => map(moduleNames, moduleName => resolveModuleName(moduleName, containingFile, options, host).resolvedModule)); let filesByName = createFileMap(fileName => host.getCanonicalFileName(fileName)); @@ -494,10 +470,17 @@ namespace ts { let resolutions = resolveModuleNamesWorker(moduleNames, newSourceFile.fileName); // ensure that module resolution results are still correct for (let i = 0; i < moduleNames.length; ++i) { - let oldResolution = getResolvedModuleFileName(oldSourceFile, moduleNames[i]); - if (oldResolution !== resolutions[i]) { + let newResolution = resolutions[i]; + let oldResolution = getResolvedModule(oldSourceFile, moduleNames[i]); + let resolutionChanged = oldResolution + ? !newResolution || + oldResolution.resolvedFileName !== newResolution.resolvedFileName || + !!oldResolution.shouldBeProperExternalModule !== !!newResolution.shouldBeProperExternalModule + : newResolution; + + if (resolutionChanged) { return false; - } + } } } // pass the cache of module resolutions from the old source file @@ -874,9 +857,23 @@ namespace ts { let resolutions = resolveModuleNamesWorker(moduleNames, file.fileName); for (let i = 0; i < file.imports.length; ++i) { let resolution = resolutions[i]; - setResolvedModuleName(file, moduleNames[i], resolution); + setResolvedModule(file, moduleNames[i], resolution); if (resolution && !options.noResolve) { - findModuleSourceFile(resolution, file.imports[i]); + const importedFile = findModuleSourceFile(resolution.resolvedFileName, file.imports[i]); + if (importedFile && resolution.shouldBeProperExternalModule) { + if (!isExternalModule(importedFile)) { + let start = getTokenPosOfNode(file.imports[i], file) + diagnostics.add(createFileDiagnostic(file, start, file.imports[i].end - start, Diagnostics.File_0_is_not_a_module, importedFile.fileName)); + } + else if (!fileExtensionIs(importedFile.fileName, ".d.ts")) { + let start = getTokenPosOfNode(file.imports[i], file) + diagnostics.add(createFileDiagnostic(file, start, file.imports[i].end - start, Diagnostics.Proper_external_module_that_carries_external_typings_should_be_d_ts_file)); + } + else if (importedFile.referencedFiles.length) { + let firstRef = importedFile.referencedFiles[0]; + diagnostics.add(createFileDiagnostic(importedFile, firstRef.pos, firstRef.end - firstRef.pos, Diagnostics.Proper_external_module_that_carries_external_typings_cannot_contain_tripleslash_references)); + } + } } } } diff --git a/src/compiler/types.ts b/src/compiler/types.ts index 5b5e7aef743..191d723afa2 100644 --- a/src/compiler/types.ts +++ b/src/compiler/types.ts @@ -1284,7 +1284,7 @@ namespace ts { // Stores a mapping 'external module reference text' -> 'resolved file name' | undefined // It is used to resolve module names in the checker. // Content of this fiels should never be used directly - use getResolvedModuleFileName/setResolvedModuleFileName functions instead - /* @internal */ resolvedModules: Map; + /* @internal */ resolvedModules: Map; /* @internal */ imports: LiteralExpression[]; } @@ -2283,11 +2283,20 @@ namespace ts { export interface ResolvedModule { resolvedFileName: string; + /* + * Denotes if 'resolvedFileName' should be proper external module: + * - be a .d.ts file + * - use top level imports\exports + * - don't use tripleslash references + */ + shouldBeProperExternalModule?: boolean; + } + + export interface ResolvedModuleWithFailedLookupLocations { + resolvedModule: ResolvedModule; failedLookupLocations: string[]; } - export type ModuleNameResolver = (moduleName: string, containingFile: string, options: CompilerOptions, host: ModuleResolutionHost) => ResolvedModule; - export interface CompilerHost extends ModuleResolutionHost { getSourceFile(fileName: string, languageVersion: ScriptTarget, onError?: (message: string) => void): SourceFile; getCancellationToken?(): CancellationToken; @@ -2305,7 +2314,7 @@ namespace ts { * If resolveModuleNames is implemented then implementation for members from ModuleResolutionHost can be just * 'throw new Error("NotImplemented")' */ - resolveModuleNames?(moduleNames: string[], containingFile: string): string[]; + resolveModuleNames?(moduleNames: string[], containingFile: string): ResolvedModule[]; } export interface TextSpan { diff --git a/src/compiler/utilities.ts b/src/compiler/utilities.ts index 6c5bd8df95d..5332c8fb440 100644 --- a/src/compiler/utilities.ts +++ b/src/compiler/utilities.ts @@ -99,20 +99,20 @@ namespace ts { return true; } - export function hasResolvedModuleName(sourceFile: SourceFile, moduleNameText: string): boolean { + export function hasResolvedModule(sourceFile: SourceFile, moduleNameText: string): boolean { return sourceFile.resolvedModules && hasProperty(sourceFile.resolvedModules, moduleNameText); } - export function getResolvedModuleFileName(sourceFile: SourceFile, moduleNameText: string): string { - return hasResolvedModuleName(sourceFile, moduleNameText) ? sourceFile.resolvedModules[moduleNameText] : undefined; + export function getResolvedModule(sourceFile: SourceFile, moduleNameText: string): ResolvedModule { + return hasResolvedModule(sourceFile, moduleNameText) ? sourceFile.resolvedModules[moduleNameText] : undefined; } - export function setResolvedModuleName(sourceFile: SourceFile, moduleNameText: string, resolvedFileName: string): void { + export function setResolvedModule(sourceFile: SourceFile, moduleNameText: string, resolvedModule: ResolvedModule): void { if (!sourceFile.resolvedModules) { sourceFile.resolvedModules = {}; } - sourceFile.resolvedModules[moduleNameText] = resolvedFileName; + sourceFile.resolvedModules[moduleNameText] = resolvedModule; } // Returns true if this node contains a parse error anywhere underneath it. diff --git a/src/harness/harnessLanguageService.ts b/src/harness/harnessLanguageService.ts index f228bc862d8..c97ce50d275 100644 --- a/src/harness/harnessLanguageService.ts +++ b/src/harness/harnessLanguageService.ts @@ -225,8 +225,8 @@ module Harness.LanguageService { let imports: ts.Map = {}; for (let module of preprocessInfo.importedFiles) { let resolutionInfo = ts.resolveModuleName(module.fileName, fileName, compilerOptions, moduleResolutionHost); - if (resolutionInfo.resolvedFileName) { - imports[module.fileName] = resolutionInfo.resolvedFileName; + if (resolutionInfo.resolvedModule) { + imports[module.fileName] = resolutionInfo.resolvedModule.resolvedFileName; } } return JSON.stringify(imports); diff --git a/src/server/editorServices.ts b/src/server/editorServices.ts index dd29d3cf2c9..572656b98fb 100644 --- a/src/server/editorServices.ts +++ b/src/server/editorServices.ts @@ -79,7 +79,7 @@ namespace ts.server { } } - interface TimestampedResolvedModule extends ResolvedModule { + interface TimestampedResolvedModule extends ResolvedModuleWithFailedLookupLocations { lastCheckTime: number; } @@ -99,11 +99,11 @@ namespace ts.server { } } - resolveModuleNames(moduleNames: string[], containingFile: string): string[] { + resolveModuleNames(moduleNames: string[], containingFile: string): ResolvedModule[] { let currentResolutionsInFile = this.resolvedModuleNames.get(containingFile); let newResolutions: Map = {}; - let resolvedFileNames: string[] = []; + let resolvedModules: ResolvedModule[] = []; let compilerOptions = this.getCompilationSettings(); @@ -119,25 +119,25 @@ namespace ts.server { else { resolution = resolveModuleName(moduleName, containingFile, compilerOptions, this.moduleResolutionHost); resolution.lastCheckTime = Date.now(); - newResolutions[moduleName] = resolution; + newResolutions[moduleName] = resolution; } } ts.Debug.assert(resolution !== undefined); - resolvedFileNames.push(resolution.resolvedFileName); + resolvedModules.push(resolution.resolvedModule); } // replace old results with a new one this.resolvedModuleNames.set(containingFile, newResolutions); - return resolvedFileNames; + return resolvedModules; function moduleResolutionIsValid(resolution: TimestampedResolvedModule): boolean { if (!resolution) { return false; } - if (resolution.resolvedFileName) { + if (resolution.resolvedModule) { // TODO: consider checking failedLookupLocations // TODO: use lastCheckTime to track expiration for module name resolution return true; diff --git a/src/services/services.ts b/src/services/services.ts index 58f59843078..c3df7a8a9f8 100644 --- a/src/services/services.ts +++ b/src/services/services.ts @@ -802,7 +802,7 @@ namespace ts { public languageVariant: LanguageVariant; public identifiers: Map; public nameTable: Map; - public resolvedModules: Map; + public resolvedModules: Map; public imports: LiteralExpression[]; private namedDeclarations: Map; @@ -1022,7 +1022,7 @@ namespace ts { * if implementation is omitted then language service will use built-in module resolution logic and get answers to * host specific questions using 'getScriptSnapshot'. */ - resolveModuleNames?(moduleNames: string[], containingFile: string): string[]; + resolveModuleNames?(moduleNames: string[], containingFile: string): ResolvedModule[]; } // diff --git a/src/services/shims.ts b/src/services/shims.ts index 307062cebd8..351514a1499 100644 --- a/src/services/shims.ts +++ b/src/services/shims.ts @@ -273,7 +273,7 @@ namespace ts { private loggingEnabled = false; private tracingEnabled = false; - public resolveModuleNames: (moduleName: string[], containingFile: string) => string[]; + public resolveModuleNames: (moduleName: string[], containingFile: string) => ResolvedModule[]; constructor(private shimHost: LanguageServiceShimHost) { // if shimHost is a COM object then property check will become method call with no arguments. @@ -281,7 +281,10 @@ namespace ts { if ("getModuleResolutionsForFile" in this.shimHost) { this.resolveModuleNames = (moduleNames: string[], containingFile: string) => { let resolutionsInFile = >JSON.parse(this.shimHost.getModuleResolutionsForFile(containingFile)); - return map(moduleNames, name => lookUp(resolutionsInFile, name)); + return map(moduleNames, name => { + const result = lookUp(resolutionsInFile, name); + return result ? { resolvedFileName: result } : undefined; + }); }; } } @@ -942,7 +945,11 @@ namespace ts { public resolveModuleName(fileName: string, moduleName: string, compilerOptionsJson: string): string { return this.forwardJSONCall(`resolveModuleName('${fileName}')`, () => { let compilerOptions = JSON.parse(compilerOptionsJson); - return resolveModuleName(moduleName, normalizeSlashes(fileName), compilerOptions, this.host); + const result = resolveModuleName(moduleName, normalizeSlashes(fileName), compilerOptions, this.host); + return { + resolvedFileName: result.resolvedModule ? result.resolvedModule.resolvedFileName: undefined, + failedLookupLocations: result.failedLookupLocations + }; }); } diff --git a/tests/baselines/reference/nodeResolution4.js b/tests/baselines/reference/nodeResolution4.js new file mode 100644 index 00000000000..0965c257da9 --- /dev/null +++ b/tests/baselines/reference/nodeResolution4.js @@ -0,0 +1,17 @@ +//// [tests/cases/compiler/nodeResolution4.ts] //// + +//// [ref.ts] + +var x = 1; + +//// [a.ts] +/// +export var y; + +//// [b.ts] +import y = require("./a"); + +//// [ref.js] +var x = 1; +//// [a.js] +//// [b.js] diff --git a/tests/baselines/reference/nodeResolution4.symbols b/tests/baselines/reference/nodeResolution4.symbols new file mode 100644 index 00000000000..b8e0b59284a --- /dev/null +++ b/tests/baselines/reference/nodeResolution4.symbols @@ -0,0 +1,14 @@ +=== tests/cases/compiler/b.ts === +import y = require("./a"); +>y : Symbol(y, Decl(b.ts, 0, 0)) + +=== tests/cases/compiler/ref.ts === + +var x = 1; +>x : Symbol(x, Decl(ref.ts, 1, 3)) + +=== tests/cases/compiler/a.ts === +/// +export var y; +>y : Symbol(y, Decl(a.ts, 1, 10)) + diff --git a/tests/baselines/reference/nodeResolution4.types b/tests/baselines/reference/nodeResolution4.types new file mode 100644 index 00000000000..b273b203bde --- /dev/null +++ b/tests/baselines/reference/nodeResolution4.types @@ -0,0 +1,15 @@ +=== tests/cases/compiler/b.ts === +import y = require("./a"); +>y : typeof y + +=== tests/cases/compiler/ref.ts === + +var x = 1; +>x : number +>1 : number + +=== tests/cases/compiler/a.ts === +/// +export var y; +>y : any + diff --git a/tests/baselines/reference/nodeResolution5.errors.txt b/tests/baselines/reference/nodeResolution5.errors.txt new file mode 100644 index 00000000000..1fc4e1cee52 --- /dev/null +++ b/tests/baselines/reference/nodeResolution5.errors.txt @@ -0,0 +1,14 @@ +tests/cases/compiler/b.ts(1,20): error TS2306: File 'tests/cases/compiler/node_modules/a.d.ts' is not a module. + + +==== tests/cases/compiler/b.ts (1 errors) ==== + import y = require("a"); + ~~~ +!!! error TS2306: File 'a.d.ts' is not a module. + +==== tests/cases/compiler/node_modules/a.d.ts (0 errors) ==== + + declare module "a" { + var x: number; + } + \ No newline at end of file diff --git a/tests/baselines/reference/nodeResolution5.js b/tests/baselines/reference/nodeResolution5.js new file mode 100644 index 00000000000..2bc009c1522 --- /dev/null +++ b/tests/baselines/reference/nodeResolution5.js @@ -0,0 +1,13 @@ +//// [tests/cases/compiler/nodeResolution5.ts] //// + +//// [a.d.ts] + +declare module "a" { + var x: number; +} + +//// [b.ts] +import y = require("a"); + + +//// [b.js] diff --git a/tests/baselines/reference/nodeResolution6.errors.txt b/tests/baselines/reference/nodeResolution6.errors.txt new file mode 100644 index 00000000000..8a462043207 --- /dev/null +++ b/tests/baselines/reference/nodeResolution6.errors.txt @@ -0,0 +1,17 @@ +tests/cases/compiler/node_modules/a.d.ts(1,1): error TS2654: Proper external module that carries external typings cannot contain tripleslash references. + + +==== tests/cases/compiler/b.ts (0 errors) ==== + import y = require("a"); + +==== tests/cases/compiler/node_modules/ref.ts (0 errors) ==== + + var x = 1; + +==== tests/cases/compiler/node_modules/a.d.ts (1 errors) ==== + /// + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +!!! error TS2654: Proper external module that carries external typings cannot contain tripleslash references. + export declare var y; + + \ No newline at end of file diff --git a/tests/baselines/reference/nodeResolution6.js b/tests/baselines/reference/nodeResolution6.js new file mode 100644 index 00000000000..140edd61f5a --- /dev/null +++ b/tests/baselines/reference/nodeResolution6.js @@ -0,0 +1,18 @@ +//// [tests/cases/compiler/nodeResolution6.ts] //// + +//// [ref.ts] + +var x = 1; + +//// [a.d.ts] +/// +export declare var y; + + +//// [b.ts] +import y = require("a"); + + +//// [ref.js] +var x = 1; +//// [b.js] diff --git a/tests/baselines/reference/nodeResolution7.errors.txt b/tests/baselines/reference/nodeResolution7.errors.txt new file mode 100644 index 00000000000..1e1f822f0d4 --- /dev/null +++ b/tests/baselines/reference/nodeResolution7.errors.txt @@ -0,0 +1,14 @@ +tests/cases/compiler/b.ts(1,20): error TS2306: File 'tests/cases/compiler/node_modules/a/index.d.ts' is not a module. + + +==== tests/cases/compiler/b.ts (1 errors) ==== + import y = require("a"); + ~~~ +!!! error TS2306: File 'index.d.ts' is not a module. + +==== tests/cases/compiler/node_modules/a/index.d.ts (0 errors) ==== + + declare module "a" { + var x: number; + } + \ No newline at end of file diff --git a/tests/baselines/reference/nodeResolution7.js b/tests/baselines/reference/nodeResolution7.js new file mode 100644 index 00000000000..abfbbad52a6 --- /dev/null +++ b/tests/baselines/reference/nodeResolution7.js @@ -0,0 +1,13 @@ +//// [tests/cases/compiler/nodeResolution7.ts] //// + +//// [index.d.ts] + +declare module "a" { + var x: number; +} + +//// [b.ts] +import y = require("a"); + + +//// [b.js] diff --git a/tests/baselines/reference/nodeResolution8.errors.txt b/tests/baselines/reference/nodeResolution8.errors.txt new file mode 100644 index 00000000000..82753a2049b --- /dev/null +++ b/tests/baselines/reference/nodeResolution8.errors.txt @@ -0,0 +1,16 @@ +tests/cases/compiler/node_modules/a/index.d.ts(1,1): error TS2654: Proper external module that carries external typings cannot contain tripleslash references. + + +==== tests/cases/compiler/b.ts (0 errors) ==== + import y = require("a"); +==== tests/cases/compiler/node_modules/a/ref.ts (0 errors) ==== + + var x = 1; + +==== tests/cases/compiler/node_modules/a/index.d.ts (1 errors) ==== + /// + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +!!! error TS2654: Proper external module that carries external typings cannot contain tripleslash references. + export declare var y; + + \ No newline at end of file diff --git a/tests/baselines/reference/nodeResolution8.js b/tests/baselines/reference/nodeResolution8.js new file mode 100644 index 00000000000..aa67f4bf9cc --- /dev/null +++ b/tests/baselines/reference/nodeResolution8.js @@ -0,0 +1,17 @@ +//// [tests/cases/compiler/nodeResolution8.ts] //// + +//// [ref.ts] + +var x = 1; + +//// [index.d.ts] +/// +export declare var y; + + +//// [b.ts] +import y = require("a"); + +//// [ref.js] +var x = 1; +//// [b.js] diff --git a/tests/cases/compiler/nodeResolution4.ts b/tests/cases/compiler/nodeResolution4.ts new file mode 100644 index 00000000000..247546c3f0c --- /dev/null +++ b/tests/cases/compiler/nodeResolution4.ts @@ -0,0 +1,12 @@ +// @module: commonjs +// @moduleResolution: node + +// @filename: ref.ts +var x = 1; + +// @filename: a.ts +/// +export var y; + +// @filename: b.ts +import y = require("./a"); \ No newline at end of file diff --git a/tests/cases/compiler/nodeResolution5.ts b/tests/cases/compiler/nodeResolution5.ts new file mode 100644 index 00000000000..313dabd7899 --- /dev/null +++ b/tests/cases/compiler/nodeResolution5.ts @@ -0,0 +1,10 @@ +// @module: commonjs +// @moduleResolution: node + +// @filename: node_modules/a.d.ts +declare module "a" { + var x: number; +} + +// @filename: b.ts +import y = require("a"); diff --git a/tests/cases/compiler/nodeResolution6.ts b/tests/cases/compiler/nodeResolution6.ts new file mode 100644 index 00000000000..3f6dc81c847 --- /dev/null +++ b/tests/cases/compiler/nodeResolution6.ts @@ -0,0 +1,13 @@ +// @module: commonjs +// @moduleResolution: node + +// @filename: node_modules/ref.ts +var x = 1; + +// @filename: node_modules/a.d.ts +/// +export declare var y; + + +// @filename: b.ts +import y = require("a"); diff --git a/tests/cases/compiler/nodeResolution7.ts b/tests/cases/compiler/nodeResolution7.ts new file mode 100644 index 00000000000..b4283edb76a --- /dev/null +++ b/tests/cases/compiler/nodeResolution7.ts @@ -0,0 +1,10 @@ +// @module: commonjs +// @moduleResolution: node + +// @filename: node_modules/a/index.d.ts +declare module "a" { + var x: number; +} + +// @filename: b.ts +import y = require("a"); diff --git a/tests/cases/compiler/nodeResolution8.ts b/tests/cases/compiler/nodeResolution8.ts new file mode 100644 index 00000000000..0a6e528f20a --- /dev/null +++ b/tests/cases/compiler/nodeResolution8.ts @@ -0,0 +1,13 @@ +// @module: commonjs +// @moduleResolution: node + +// @filename: node_modules/a/ref.ts +var x = 1; + +// @filename: node_modules/a/index.d.ts +/// +export declare var y; + + +// @filename: b.ts +import y = require("a"); \ No newline at end of file diff --git a/tests/cases/unittests/moduleResolution.ts b/tests/cases/unittests/moduleResolution.ts index 0917e72f1ce..ab12119ec5a 100644 --- a/tests/cases/unittests/moduleResolution.ts +++ b/tests/cases/unittests/moduleResolution.ts @@ -40,8 +40,9 @@ module ts { let containingFile = { name: containingFileName } let moduleFile = { name: moduleFileNameNoExt + ext } let resolution = nodeModuleNameResolver(moduleName, containingFile.name, createModuleResolutionHost(containingFile, moduleFile)); - assert.equal(resolution.resolvedFileName, moduleFile.name); - + assert.equal(resolution.resolvedModule.resolvedFileName, moduleFile.name); + assert.equal(!!resolution.resolvedModule.shouldBeProperExternalModule, false); + let failedLookupLocations: string[] = []; let dir = getDirectoryPath(containingFileName); for (let e of supportedExtensions) { @@ -78,7 +79,8 @@ module ts { let packageJson = { name: packageJsonFileName, content: JSON.stringify({ "typings": fieldRef }) }; let moduleFile = { name: moduleFileName }; let resolution = nodeModuleNameResolver(moduleName, containingFile.name, createModuleResolutionHost(containingFile, packageJson, moduleFile)); - assert.equal(resolution.resolvedFileName, moduleFile.name); + assert.equal(resolution.resolvedModule.resolvedFileName, moduleFile.name); + assert.equal(!!resolution.resolvedModule.shouldBeProperExternalModule, false); // expect three failed lookup location - attempt to load module as file with all supported extensions assert.equal(resolution.failedLookupLocations.length, 3); } @@ -95,7 +97,8 @@ module ts { let packageJson = {name: "/a/b/foo/package.json", content: JSON.stringify({main: "/c/d"})}; let indexFile = { name: "/a/b/foo/index.d.ts" }; let resolution = nodeModuleNameResolver("./foo", containingFile.name, createModuleResolutionHost(containingFile, packageJson, indexFile)); - assert.equal(resolution.resolvedFileName, indexFile.name); + assert.equal(resolution.resolvedModule.resolvedFileName, indexFile.name); + assert.equal(!!resolution.resolvedModule.shouldBeProperExternalModule, false); assert.deepEqual(resolution.failedLookupLocations, [ "/a/b/foo.ts", "/a/b/foo.tsx", @@ -111,7 +114,7 @@ module ts { let containingFile = { name: "/a/b/c/d/e.ts" }; let moduleFile = { name: "/a/b/node_modules/foo.ts" }; let resolution = nodeModuleNameResolver("foo", containingFile.name, createModuleResolutionHost(containingFile, moduleFile)); - assert.equal(resolution.resolvedFileName, undefined); + assert.equal(resolution.resolvedModule, undefined); assert.deepEqual(resolution.failedLookupLocations, [ "/a/b/c/d/node_modules/foo.d.ts", "/a/b/c/d/node_modules/foo/package.json", @@ -135,14 +138,16 @@ module ts { let containingFile = { name: "/a/b/c/d/e.ts" }; let moduleFile = { name: "/a/b/node_modules/foo.d.ts" }; let resolution = nodeModuleNameResolver("foo", containingFile.name, createModuleResolutionHost(containingFile, moduleFile)); - assert.equal(resolution.resolvedFileName, moduleFile.name); + assert.equal(resolution.resolvedModule.resolvedFileName, moduleFile.name); + assert.equal(resolution.resolvedModule.shouldBeProperExternalModule, true); }); it("load module as directory", () => { let containingFile = { name: "/a/node_modules/b/c/node_modules/d/e.ts" }; let moduleFile = { name: "/a/node_modules/foo/index.d.ts" }; let resolution = nodeModuleNameResolver("foo", containingFile.name, createModuleResolutionHost(containingFile, moduleFile)); - assert.equal(resolution.resolvedFileName, moduleFile.name); + assert.equal(resolution.resolvedModule.resolvedFileName, moduleFile.name); + assert.equal(resolution.resolvedModule.shouldBeProperExternalModule, true); assert.deepEqual(resolution.failedLookupLocations, [ "/a/node_modules/b/c/node_modules/d/node_modules/foo.d.ts", "/a/node_modules/b/c/node_modules/d/node_modules/foo/package.json", @@ -158,64 +163,4 @@ module ts { ]); }); }); - - describe("BaseUrl mode", () => { - - it ("load module as relative url", () => { - function test(containingFileName: string, moduleFileName: string, moduleName: string): void { - let containingFile = {name: containingFileName }; - let moduleFile = { name: moduleFileName }; - let resolution = baseUrlModuleNameResolver(moduleName, containingFile.name, "", createModuleResolutionHost(containingFile, moduleFile)); - assert.equal(resolution.resolvedFileName, moduleFile.name); - let expectedFailedLookupLocations: string[] = []; - - let moduleNameHasExt = forEach(supportedExtensions, e => fileExtensionIs(moduleName, e)); - if (!moduleNameHasExt) { - let dir = getDirectoryPath(containingFileName); - - // add candidates with extensions that precede extension of the actual module name file in the list of supportd extensions - for (let ext of supportedExtensions) { - - let hasExtension = ext !== ".ts" - ? fileExtensionIs(moduleFileName, ext) - : fileExtensionIs(moduleFileName, ".ts") && !fileExtensionIs(moduleFileName, ".d.ts"); - - if (hasExtension) { - break; - } - else { - expectedFailedLookupLocations.push(normalizePath(combinePaths(dir, moduleName + ext))); - } - } - } - - assert.deepEqual(resolution.failedLookupLocations, expectedFailedLookupLocations) - } - - test("/a/b/c/d.ts", "/foo.ts", "/foo"); - test("/a/b/c/d.ts", "/foo.d.ts", "/foo"); - test("/a/b/c/d.ts", "/foo.tsx", "/foo"); - - test("/a/b/c/d.ts", "/a/b/c/foo.ts", "./foo"); - test("/a/b/c/d.ts", "/a/b/c/foo.d.ts", "./foo"); - test("/a/b/c/d.ts", "/a/b/c/foo.tsx", "./foo"); - - test("/a/b/c/d.ts", "/a/b/foo.ts", "../foo"); - test("/a/b/c/d.ts", "/a/b/foo.d.ts", "../foo"); - test("/a/b/c/d.ts", "/a/b/foo.tsx", "../foo"); - }); - - it ("load module using base url", () => { - function test(containingFileName: string, moduleFileName: string, moduleName: string, baseUrl: string): void { - let containingFile = { name: containingFileName }; - let moduleFile = { name: moduleFileName }; - let resolution = baseUrlModuleNameResolver(moduleName, containingFileName, baseUrl, createModuleResolutionHost(containingFile, moduleFile)); - assert.equal(resolution.resolvedFileName, moduleFile.name); - } - - test("/a/base/c/d.ts", "/a/base/c/d/e.ts", "c/d/e", "/a/base"); - test("/a/base/c/d.ts", "/a/base/c/d/e.d.ts", "c/d/e", "/a/base"); - test("/a/base/c/d.ts", "/a/base/c/d/e.tsx", "c/d/e", "/a/base"); - }); - }); } \ No newline at end of file diff --git a/tests/cases/unittests/reuseProgramStructure.ts b/tests/cases/unittests/reuseProgramStructure.ts index 56b1dedbcbb..4d167cb1bb0 100644 --- a/tests/cases/unittests/reuseProgramStructure.ts +++ b/tests/cases/unittests/reuseProgramStructure.ts @@ -160,7 +160,7 @@ module ts { return size; } - function checkResolvedModulesCache(program: Program, fileName: string, expectedContent: Map): void { + function checkResolvedModulesCache(program: Program, fileName: string, expectedContent: Map): void { let file = program.getSourceFile(fileName); assert.isTrue(file !== undefined, `cannot find file ${fileName}`); if (expectedContent === undefined) { @@ -175,7 +175,16 @@ module ts { for (let id in expectedContent) { if (hasProperty(expectedContent, id)) { assert.isTrue(hasProperty(file.resolvedModules, id), `expected ${id} to be found in resolved modules`); - assert.isTrue(expectedContent[id] === file.resolvedModules[id], `expected '${expectedContent[id]}' to be equal to '${file.resolvedModules[id]}'`); + if (expectedContent[id]) { + const expected = expectedContent[id]; + const actual = file.resolvedModules[id]; + assert.isTrue(actual !== undefined); + assert.isTrue(expected.resolvedFileName === actual.resolvedFileName, `'resolvedFileName': expected '${expected.resolvedFileName}' to be equal to '${actual.resolvedFileName}'`); + assert.isTrue(expected.shouldBeProperExternalModule === actual.shouldBeProperExternalModule, `'shouldBeProperExternalModule': expected '${expected.shouldBeProperExternalModule}' to be equal to '${actual.shouldBeProperExternalModule}'`); + } + else { + assert.isTrue(file.resolvedModules[id] === undefined); + } } } } @@ -237,7 +246,7 @@ module ts { var options: CompilerOptions = { target }; var program_1 = newProgram(files, ["a.ts"], options); - checkResolvedModulesCache(program_1, "a.ts", { "b": "b.ts" }); + checkResolvedModulesCache(program_1, "a.ts", { "b": { resolvedFileName: "b.ts" } }); checkResolvedModulesCache(program_1, "b.ts", undefined); var program_2 = updateProgram(program_1, ["a.ts"], options, files => { @@ -246,7 +255,7 @@ module ts { assert.isTrue(program_1.structureIsReused); // content of resolution cache should not change - checkResolvedModulesCache(program_1, "a.ts", { "b": "b.ts" }); + checkResolvedModulesCache(program_1, "a.ts", { "b": { resolvedFileName: "b.ts" } }); checkResolvedModulesCache(program_1, "b.ts", undefined); // imports has changed - program is not reused @@ -263,7 +272,7 @@ module ts { files[0].text = files[0].text.updateImportsAndExports(newImports); }); assert.isTrue(!program_3.structureIsReused); - checkResolvedModulesCache(program_4, "a.ts", { "b": "b.ts", "c": undefined }); + checkResolvedModulesCache(program_4, "a.ts", { "b": { resolvedFileName: "b.ts" }, "c": undefined }); }); }) } \ No newline at end of file From 031fdf19e03af0a29b200bda58420942bcaa379e Mon Sep 17 00:00:00 2001 From: Vladimir Matveev Date: Thu, 10 Sep 2015 16:42:02 -0700 Subject: [PATCH 25/28] addressed PR feedback --- src/compiler/diagnosticInformationMap.generated.ts | 4 ++-- src/compiler/diagnosticMessages.json | 4 ++-- src/compiler/program.ts | 12 ++++++------ src/compiler/types.ts | 4 ++-- 4 files changed, 12 insertions(+), 12 deletions(-) diff --git a/src/compiler/diagnosticInformationMap.generated.ts b/src/compiler/diagnosticInformationMap.generated.ts index 2b67d676d51..1ff650a399f 100644 --- a/src/compiler/diagnosticInformationMap.generated.ts +++ b/src/compiler/diagnosticInformationMap.generated.ts @@ -427,8 +427,8 @@ namespace ts { Cannot_emit_namespaced_JSX_elements_in_React: { code: 2650, category: DiagnosticCategory.Error, key: "Cannot emit namespaced JSX elements in React" }, A_member_initializer_in_a_enum_declaration_cannot_reference_members_declared_after_it_including_members_defined_in_other_enums: { code: 2651, category: DiagnosticCategory.Error, key: "A member initializer in a enum declaration cannot reference members declared after it, including members defined in other enums." }, Merged_declaration_0_cannot_include_a_default_export_declaration_Consider_adding_a_separate_export_default_0_declaration_instead: { code: 2652, category: DiagnosticCategory.Error, key: "Merged declaration '{0}' cannot include a default export declaration. Consider adding a separate 'export default {0}' declaration instead." }, - Proper_external_module_that_carries_external_typings_cannot_contain_tripleslash_references: { code: 2654, category: DiagnosticCategory.Error, key: "Proper external module that carries external typings cannot contain tripleslash references." }, - Proper_external_module_that_carries_external_typings_should_be_d_ts_file: { code: 2655, category: DiagnosticCategory.Error, key: "Proper external module that carries external typings should be '.d.ts' file." }, + Exported_external_package_typings_file_cannot_contain_tripleslash_references_Please_contact_the_package_author_to_update_the_package_definition: { code: 2654, category: DiagnosticCategory.Error, key: "Exported external package typings file cannot contain tripleslash references. Please contact the package author to update the package definition." }, + Exported_external_package_typings_can_only_be_in_d_ts_files_Please_contact_the_package_author_to_update_the_package_definition: { code: 2655, category: DiagnosticCategory.Error, key: "Exported external package typings can only be in '.d.ts' files. Please contact the package author to update the package definition." }, Import_declaration_0_is_using_private_name_1: { code: 4000, category: DiagnosticCategory.Error, key: "Import declaration '{0}' is using private name '{1}'." }, Type_parameter_0_of_exported_class_has_or_is_using_private_name_1: { code: 4002, category: DiagnosticCategory.Error, key: "Type parameter '{0}' of exported class has or is using private name '{1}'." }, Type_parameter_0_of_exported_interface_has_or_is_using_private_name_1: { code: 4004, category: DiagnosticCategory.Error, key: "Type parameter '{0}' of exported interface has or is using private name '{1}'." }, diff --git a/src/compiler/diagnosticMessages.json b/src/compiler/diagnosticMessages.json index ad82541ad79..2fdf5869d1a 100644 --- a/src/compiler/diagnosticMessages.json +++ b/src/compiler/diagnosticMessages.json @@ -1697,11 +1697,11 @@ "category": "Error", "code": 2652 }, - "Proper external module that carries external typings cannot contain tripleslash references.": { + "Exported external package typings file cannot contain tripleslash references. Please contact the package author to update the package definition.": { "category": "Error", "code": 2654 }, - "Proper external module that carries external typings should be '.d.ts' file.": { + "Exported external package typings can only be in '.d.ts' files. Please contact the package author to update the package definition.": { "category": "Error", "code": 2655 }, diff --git a/src/compiler/program.ts b/src/compiler/program.ts index f6931aea545..dba608c2ebc 100644 --- a/src/compiler/program.ts +++ b/src/compiler/program.ts @@ -129,12 +129,12 @@ namespace ts { let candidate = normalizePath(combinePaths(nodeModulesFolder, moduleName)); let result = loadNodeModuleFromFile(candidate, /* loadOnlyDts */ true, failedLookupLocations, host); if (result) { - return { resolvedModule: { resolvedFileName: result, shouldBeProperExternalModule: true }, failedLookupLocations }; + return { resolvedModule: { resolvedFileName: result, isExternalLibraryImport: true }, failedLookupLocations }; } result = loadNodeModuleFromDirectory(candidate, /* loadOnlyDts */ true, failedLookupLocations, host); if (result) { - return { resolvedModule: { resolvedFileName: result, shouldBeProperExternalModule: true }, failedLookupLocations }; + return { resolvedModule: { resolvedFileName: result, isExternalLibraryImport: true }, failedLookupLocations }; } } @@ -475,7 +475,7 @@ namespace ts { let resolutionChanged = oldResolution ? !newResolution || oldResolution.resolvedFileName !== newResolution.resolvedFileName || - !!oldResolution.shouldBeProperExternalModule !== !!newResolution.shouldBeProperExternalModule + !!oldResolution.isExternalLibraryImport !== !!newResolution.isExternalLibraryImport : newResolution; if (resolutionChanged) { @@ -860,18 +860,18 @@ namespace ts { setResolvedModule(file, moduleNames[i], resolution); if (resolution && !options.noResolve) { const importedFile = findModuleSourceFile(resolution.resolvedFileName, file.imports[i]); - if (importedFile && resolution.shouldBeProperExternalModule) { + if (importedFile && resolution.isExternalLibraryImport) { if (!isExternalModule(importedFile)) { let start = getTokenPosOfNode(file.imports[i], file) diagnostics.add(createFileDiagnostic(file, start, file.imports[i].end - start, Diagnostics.File_0_is_not_a_module, importedFile.fileName)); } else if (!fileExtensionIs(importedFile.fileName, ".d.ts")) { let start = getTokenPosOfNode(file.imports[i], file) - diagnostics.add(createFileDiagnostic(file, start, file.imports[i].end - start, Diagnostics.Proper_external_module_that_carries_external_typings_should_be_d_ts_file)); + diagnostics.add(createFileDiagnostic(file, start, file.imports[i].end - start, Diagnostics.Exported_external_package_typings_can_only_be_in_d_ts_files_Please_contact_the_package_author_to_update_the_package_definition)); } else if (importedFile.referencedFiles.length) { let firstRef = importedFile.referencedFiles[0]; - diagnostics.add(createFileDiagnostic(importedFile, firstRef.pos, firstRef.end - firstRef.pos, Diagnostics.Proper_external_module_that_carries_external_typings_cannot_contain_tripleslash_references)); + diagnostics.add(createFileDiagnostic(importedFile, firstRef.pos, firstRef.end - firstRef.pos, Diagnostics.Exported_external_package_typings_file_cannot_contain_tripleslash_references_Please_contact_the_package_author_to_update_the_package_definition)); } } } diff --git a/src/compiler/types.ts b/src/compiler/types.ts index 191d723afa2..880feb0bf73 100644 --- a/src/compiler/types.ts +++ b/src/compiler/types.ts @@ -2284,12 +2284,12 @@ namespace ts { export interface ResolvedModule { resolvedFileName: string; /* - * Denotes if 'resolvedFileName' should be proper external module: + * Denotes if 'resolvedFileName' is isExternalLibraryImport and thus should be proper external module: * - be a .d.ts file * - use top level imports\exports * - don't use tripleslash references */ - shouldBeProperExternalModule?: boolean; + isExternalLibraryImport?: boolean; } export interface ResolvedModuleWithFailedLookupLocations { From a880be1f7555d0b2ad167fd3f18e2d4d665c5cae Mon Sep 17 00:00:00 2001 From: Vladimir Matveev Date: Thu, 10 Sep 2015 17:00:29 -0700 Subject: [PATCH 26/28] resolve merge conflicts, update tests --- src/compiler/program.ts | 6 +++--- tests/baselines/reference/nodeResolution6.errors.txt | 4 ++-- tests/baselines/reference/nodeResolution8.errors.txt | 4 ++-- tests/cases/unittests/moduleResolution.ts | 10 +++++----- tests/cases/unittests/reuseProgramStructure.ts | 2 +- 5 files changed, 13 insertions(+), 13 deletions(-) diff --git a/src/compiler/program.ts b/src/compiler/program.ts index dba608c2ebc..0acb81f1908 100644 --- a/src/compiler/program.ts +++ b/src/compiler/program.ts @@ -863,15 +863,15 @@ namespace ts { if (importedFile && resolution.isExternalLibraryImport) { if (!isExternalModule(importedFile)) { let start = getTokenPosOfNode(file.imports[i], file) - diagnostics.add(createFileDiagnostic(file, start, file.imports[i].end - start, Diagnostics.File_0_is_not_a_module, importedFile.fileName)); + fileProcessingDiagnostics.add(createFileDiagnostic(file, start, file.imports[i].end - start, Diagnostics.File_0_is_not_a_module, importedFile.fileName)); } else if (!fileExtensionIs(importedFile.fileName, ".d.ts")) { let start = getTokenPosOfNode(file.imports[i], file) - diagnostics.add(createFileDiagnostic(file, start, file.imports[i].end - start, Diagnostics.Exported_external_package_typings_can_only_be_in_d_ts_files_Please_contact_the_package_author_to_update_the_package_definition)); + fileProcessingDiagnostics.add(createFileDiagnostic(file, start, file.imports[i].end - start, Diagnostics.Exported_external_package_typings_can_only_be_in_d_ts_files_Please_contact_the_package_author_to_update_the_package_definition)); } else if (importedFile.referencedFiles.length) { let firstRef = importedFile.referencedFiles[0]; - diagnostics.add(createFileDiagnostic(importedFile, firstRef.pos, firstRef.end - firstRef.pos, Diagnostics.Exported_external_package_typings_file_cannot_contain_tripleslash_references_Please_contact_the_package_author_to_update_the_package_definition)); + fileProcessingDiagnostics.add(createFileDiagnostic(importedFile, firstRef.pos, firstRef.end - firstRef.pos, Diagnostics.Exported_external_package_typings_file_cannot_contain_tripleslash_references_Please_contact_the_package_author_to_update_the_package_definition)); } } } diff --git a/tests/baselines/reference/nodeResolution6.errors.txt b/tests/baselines/reference/nodeResolution6.errors.txt index 8a462043207..6bab6e34389 100644 --- a/tests/baselines/reference/nodeResolution6.errors.txt +++ b/tests/baselines/reference/nodeResolution6.errors.txt @@ -1,4 +1,4 @@ -tests/cases/compiler/node_modules/a.d.ts(1,1): error TS2654: Proper external module that carries external typings cannot contain tripleslash references. +tests/cases/compiler/node_modules/a.d.ts(1,1): error TS2654: Exported external package typings file cannot contain tripleslash references. Please contact the package author to update the package definition. ==== tests/cases/compiler/b.ts (0 errors) ==== @@ -11,7 +11,7 @@ tests/cases/compiler/node_modules/a.d.ts(1,1): error TS2654: Proper external mod ==== tests/cases/compiler/node_modules/a.d.ts (1 errors) ==== /// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -!!! error TS2654: Proper external module that carries external typings cannot contain tripleslash references. +!!! error TS2654: Exported external package typings file cannot contain tripleslash references. Please contact the package author to update the package definition. export declare var y; \ No newline at end of file diff --git a/tests/baselines/reference/nodeResolution8.errors.txt b/tests/baselines/reference/nodeResolution8.errors.txt index 82753a2049b..3f14a4313c8 100644 --- a/tests/baselines/reference/nodeResolution8.errors.txt +++ b/tests/baselines/reference/nodeResolution8.errors.txt @@ -1,4 +1,4 @@ -tests/cases/compiler/node_modules/a/index.d.ts(1,1): error TS2654: Proper external module that carries external typings cannot contain tripleslash references. +tests/cases/compiler/node_modules/a/index.d.ts(1,1): error TS2654: Exported external package typings file cannot contain tripleslash references. Please contact the package author to update the package definition. ==== tests/cases/compiler/b.ts (0 errors) ==== @@ -10,7 +10,7 @@ tests/cases/compiler/node_modules/a/index.d.ts(1,1): error TS2654: Proper extern ==== tests/cases/compiler/node_modules/a/index.d.ts (1 errors) ==== /// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -!!! error TS2654: Proper external module that carries external typings cannot contain tripleslash references. +!!! error TS2654: Exported external package typings file cannot contain tripleslash references. Please contact the package author to update the package definition. export declare var y; \ No newline at end of file diff --git a/tests/cases/unittests/moduleResolution.ts b/tests/cases/unittests/moduleResolution.ts index ab12119ec5a..ed9f0b0a986 100644 --- a/tests/cases/unittests/moduleResolution.ts +++ b/tests/cases/unittests/moduleResolution.ts @@ -41,7 +41,7 @@ module ts { let moduleFile = { name: moduleFileNameNoExt + ext } let resolution = nodeModuleNameResolver(moduleName, containingFile.name, createModuleResolutionHost(containingFile, moduleFile)); assert.equal(resolution.resolvedModule.resolvedFileName, moduleFile.name); - assert.equal(!!resolution.resolvedModule.shouldBeProperExternalModule, false); + assert.equal(!!resolution.resolvedModule.isExternalLibraryImport, false); let failedLookupLocations: string[] = []; let dir = getDirectoryPath(containingFileName); @@ -80,7 +80,7 @@ module ts { let moduleFile = { name: moduleFileName }; let resolution = nodeModuleNameResolver(moduleName, containingFile.name, createModuleResolutionHost(containingFile, packageJson, moduleFile)); assert.equal(resolution.resolvedModule.resolvedFileName, moduleFile.name); - assert.equal(!!resolution.resolvedModule.shouldBeProperExternalModule, false); + assert.equal(!!resolution.resolvedModule.isExternalLibraryImport, false); // expect three failed lookup location - attempt to load module as file with all supported extensions assert.equal(resolution.failedLookupLocations.length, 3); } @@ -98,7 +98,7 @@ module ts { let indexFile = { name: "/a/b/foo/index.d.ts" }; let resolution = nodeModuleNameResolver("./foo", containingFile.name, createModuleResolutionHost(containingFile, packageJson, indexFile)); assert.equal(resolution.resolvedModule.resolvedFileName, indexFile.name); - assert.equal(!!resolution.resolvedModule.shouldBeProperExternalModule, false); + assert.equal(!!resolution.resolvedModule.isExternalLibraryImport, false); assert.deepEqual(resolution.failedLookupLocations, [ "/a/b/foo.ts", "/a/b/foo.tsx", @@ -139,7 +139,7 @@ module ts { let moduleFile = { name: "/a/b/node_modules/foo.d.ts" }; let resolution = nodeModuleNameResolver("foo", containingFile.name, createModuleResolutionHost(containingFile, moduleFile)); assert.equal(resolution.resolvedModule.resolvedFileName, moduleFile.name); - assert.equal(resolution.resolvedModule.shouldBeProperExternalModule, true); + assert.equal(resolution.resolvedModule.isExternalLibraryImport, true); }); it("load module as directory", () => { @@ -147,7 +147,7 @@ module ts { let moduleFile = { name: "/a/node_modules/foo/index.d.ts" }; let resolution = nodeModuleNameResolver("foo", containingFile.name, createModuleResolutionHost(containingFile, moduleFile)); assert.equal(resolution.resolvedModule.resolvedFileName, moduleFile.name); - assert.equal(resolution.resolvedModule.shouldBeProperExternalModule, true); + assert.equal(resolution.resolvedModule.isExternalLibraryImport, true); assert.deepEqual(resolution.failedLookupLocations, [ "/a/node_modules/b/c/node_modules/d/node_modules/foo.d.ts", "/a/node_modules/b/c/node_modules/d/node_modules/foo/package.json", diff --git a/tests/cases/unittests/reuseProgramStructure.ts b/tests/cases/unittests/reuseProgramStructure.ts index 4d167cb1bb0..5f313eeae2b 100644 --- a/tests/cases/unittests/reuseProgramStructure.ts +++ b/tests/cases/unittests/reuseProgramStructure.ts @@ -180,7 +180,7 @@ module ts { const actual = file.resolvedModules[id]; assert.isTrue(actual !== undefined); assert.isTrue(expected.resolvedFileName === actual.resolvedFileName, `'resolvedFileName': expected '${expected.resolvedFileName}' to be equal to '${actual.resolvedFileName}'`); - assert.isTrue(expected.shouldBeProperExternalModule === actual.shouldBeProperExternalModule, `'shouldBeProperExternalModule': expected '${expected.shouldBeProperExternalModule}' to be equal to '${actual.shouldBeProperExternalModule}'`); + assert.isTrue(expected.isExternalLibraryImport === actual.isExternalLibraryImport, `'shouldBeProperExternalModule': expected '${expected.isExternalLibraryImport}' to be equal to '${actual.isExternalLibraryImport}'`); } else { assert.isTrue(file.resolvedModules[id] === undefined); From 0e5196180e03c66f92efd0713d8b4a00aea81f55 Mon Sep 17 00:00:00 2001 From: Vladimir Matveev Date: Fri, 11 Sep 2015 09:36:17 -0700 Subject: [PATCH 27/28] emit export specifiers in system modules only if export has a value side --- src/compiler/emitter.ts | 6 +- tests/baselines/reference/systemModule17.js | 84 ++++++++++++++++ .../reference/systemModule17.symbols | 93 ++++++++++++++++++ .../baselines/reference/systemModule17.types | 95 +++++++++++++++++++ tests/cases/compiler/systemModule17.ts | 41 ++++++++ 5 files changed, 318 insertions(+), 1 deletion(-) create mode 100644 tests/baselines/reference/systemModule17.js create mode 100644 tests/baselines/reference/systemModule17.symbols create mode 100644 tests/baselines/reference/systemModule17.types create mode 100644 tests/cases/compiler/systemModule17.ts diff --git a/src/compiler/emitter.ts b/src/compiler/emitter.ts index 2d5bda1bba2..a5c9b88b7dd 100644 --- a/src/compiler/emitter.ts +++ b/src/compiler/emitter.ts @@ -3144,6 +3144,10 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, Promi function emitExportSpecifierInSystemModule(specifier: ExportSpecifier): void { Debug.assert(compilerOptions.module === ModuleKind.System); + + if (!resolver.getReferencedValueDeclaration(specifier.propertyName || specifier.name) && !resolver.isValueAliasDeclaration(specifier) ) { + return; + } writeLine(); emitStart(specifier.name); @@ -6106,7 +6110,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, Promi return; } - if (isInternalModuleImportEqualsDeclaration(node)) { + if (isInternalModuleImportEqualsDeclaration(node) && resolver.isValueAliasDeclaration(node)) { if (!hoistedVars) { hoistedVars = []; } diff --git a/tests/baselines/reference/systemModule17.js b/tests/baselines/reference/systemModule17.js new file mode 100644 index 00000000000..90efdc8872a --- /dev/null +++ b/tests/baselines/reference/systemModule17.js @@ -0,0 +1,84 @@ +//// [tests/cases/compiler/systemModule17.ts] //// + +//// [f1.ts] + + +export class A {} +export interface I {} + +//// [f2.ts] + +var x = 1; +interface I { } + +namespace N { + export var x = 1; + export interface I { } +} + +import IX = N.x; +import II = N.I; +import { A, A as EA, I as EI } from "f1"; + +export {x}; +export {x as x1}; + +export {I}; +export {I as I1}; + +export {A}; +export {A as A1}; + +export {EA}; +export {EA as EA1}; + +export {EI }; +export {EI as EI1}; + +export {IX}; +export {IX as IX1}; + +export {II}; +export {II as II1}; + +//// [f1.js] +System.register([], function(exports_1) { + var A; + return { + setters:[], + execute: function() { + A = (function () { + function A() { + } + return A; + })(); + exports_1("A", A); + } + } +}); +//// [f2.js] +System.register(["f1"], function(exports_1) { + var f1_1; + var x, N, IX; + return { + setters:[ + function (f1_1_1) { + f1_1 = f1_1_1; + }], + execute: function() { + x = 1; + (function (N) { + N.x = 1; + })(N || (N = {})); + IX = N.x; + exports_1("x", x); + exports_1("x1", x); + exports_1("A", f1_1.A); + exports_1("A1", f1_1.A); + exports_1("EA", f1_1.A); + exports_1("EA1", f1_1.A); + exports_1("IX", IX); + exports_1("IX1", IX); + } + } +}); diff --git a/tests/baselines/reference/systemModule17.symbols b/tests/baselines/reference/systemModule17.symbols new file mode 100644 index 00000000000..3bf19dad950 --- /dev/null +++ b/tests/baselines/reference/systemModule17.symbols @@ -0,0 +1,93 @@ +=== tests/cases/compiler/f1.ts === + + +export class A {} +>A : Symbol(A, Decl(f1.ts, 0, 0)) + +export interface I {} +>I : Symbol(I, Decl(f1.ts, 2, 17)) + +=== tests/cases/compiler/f2.ts === + +var x = 1; +>x : Symbol(x, Decl(f2.ts, 1, 3)) + +interface I { } +>I : Symbol(I, Decl(f2.ts, 1, 10)) + +namespace N { +>N : Symbol(N, Decl(f2.ts, 2, 15)) + + export var x = 1; +>x : Symbol(x, Decl(f2.ts, 5, 11)) + + export interface I { } +>I : Symbol(I, Decl(f2.ts, 5, 18)) +} + +import IX = N.x; +>IX : Symbol(IX, Decl(f2.ts, 7, 1)) +>N : Symbol(N, Decl(f2.ts, 2, 15)) +>x : Symbol(IX, Decl(f2.ts, 5, 11)) + +import II = N.I; +>II : Symbol(II, Decl(f2.ts, 9, 16)) +>N : Symbol(N, Decl(f2.ts, 2, 15)) +>I : Symbol(II, Decl(f2.ts, 5, 18)) + +import { A, A as EA, I as EI } from "f1"; +>A : Symbol(A, Decl(f2.ts, 11, 8)) +>A : Symbol(EA, Decl(f2.ts, 11, 11)) +>EA : Symbol(EA, Decl(f2.ts, 11, 11)) +>I : Symbol(EI, Decl(f2.ts, 11, 20)) +>EI : Symbol(EI, Decl(f2.ts, 11, 20)) + +export {x}; +>x : Symbol(x, Decl(f2.ts, 13, 8)) + +export {x as x1}; +>x : Symbol(x1, Decl(f2.ts, 14, 8)) +>x1 : Symbol(x1, Decl(f2.ts, 14, 8)) + +export {I}; +>I : Symbol(I, Decl(f2.ts, 16, 8)) + +export {I as I1}; +>I : Symbol(I1, Decl(f2.ts, 17, 8)) +>I1 : Symbol(I1, Decl(f2.ts, 17, 8)) + +export {A}; +>A : Symbol(A, Decl(f2.ts, 19, 8)) + +export {A as A1}; +>A : Symbol(A1, Decl(f2.ts, 20, 8)) +>A1 : Symbol(A1, Decl(f2.ts, 20, 8)) + +export {EA}; +>EA : Symbol(EA, Decl(f2.ts, 22, 8)) + +export {EA as EA1}; +>EA : Symbol(EA1, Decl(f2.ts, 23, 8)) +>EA1 : Symbol(EA1, Decl(f2.ts, 23, 8)) + +export {EI }; +>EI : Symbol(EI, Decl(f2.ts, 25, 8)) + +export {EI as EI1}; +>EI : Symbol(EI1, Decl(f2.ts, 26, 8)) +>EI1 : Symbol(EI1, Decl(f2.ts, 26, 8)) + +export {IX}; +>IX : Symbol(IX, Decl(f2.ts, 28, 8)) + +export {IX as IX1}; +>IX : Symbol(IX1, Decl(f2.ts, 29, 8)) +>IX1 : Symbol(IX1, Decl(f2.ts, 29, 8)) + +export {II}; +>II : Symbol(II, Decl(f2.ts, 31, 8)) + +export {II as II1}; +>II : Symbol(II1, Decl(f2.ts, 32, 8)) +>II1 : Symbol(II1, Decl(f2.ts, 32, 8)) + diff --git a/tests/baselines/reference/systemModule17.types b/tests/baselines/reference/systemModule17.types new file mode 100644 index 00000000000..1f0b1b51842 --- /dev/null +++ b/tests/baselines/reference/systemModule17.types @@ -0,0 +1,95 @@ +=== tests/cases/compiler/f1.ts === + + +export class A {} +>A : A + +export interface I {} +>I : I + +=== tests/cases/compiler/f2.ts === + +var x = 1; +>x : number +>1 : number + +interface I { } +>I : I + +namespace N { +>N : typeof N + + export var x = 1; +>x : number +>1 : number + + export interface I { } +>I : I +} + +import IX = N.x; +>IX : number +>N : typeof N +>x : number + +import II = N.I; +>II : any +>N : typeof N +>I : II + +import { A, A as EA, I as EI } from "f1"; +>A : typeof A +>A : typeof A +>EA : typeof A +>I : any +>EI : any + +export {x}; +>x : number + +export {x as x1}; +>x : number +>x1 : number + +export {I}; +>I : any + +export {I as I1}; +>I : any +>I1 : any + +export {A}; +>A : typeof A + +export {A as A1}; +>A : typeof A +>A1 : typeof A + +export {EA}; +>EA : typeof A + +export {EA as EA1}; +>EA : typeof A +>EA1 : typeof A + +export {EI }; +>EI : any + +export {EI as EI1}; +>EI : any +>EI1 : any + +export {IX}; +>IX : number + +export {IX as IX1}; +>IX : number +>IX1 : number + +export {II}; +>II : any + +export {II as II1}; +>II : any +>II1 : any + diff --git a/tests/cases/compiler/systemModule17.ts b/tests/cases/compiler/systemModule17.ts new file mode 100644 index 00000000000..f6b6d6ea2f2 --- /dev/null +++ b/tests/cases/compiler/systemModule17.ts @@ -0,0 +1,41 @@ +// @module: system + +// @filename: f1.ts + +export class A {} +export interface I {} + +// @filename: f2.ts + +var x = 1; +interface I { } + +namespace N { + export var x = 1; + export interface I { } +} + +import IX = N.x; +import II = N.I; +import { A, A as EA, I as EI } from "f1"; + +export {x}; +export {x as x1}; + +export {I}; +export {I as I1}; + +export {A}; +export {A as A1}; + +export {EA}; +export {EA as EA1}; + +export {EI }; +export {EI as EI1}; + +export {IX}; +export {IX as IX1}; + +export {II}; +export {II as II1}; \ No newline at end of file From a44d8e76c68e7c685cef3d34943158021acd04e5 Mon Sep 17 00:00:00 2001 From: Mohamed Hegazy Date: Fri, 11 Sep 2015 11:32:35 -0700 Subject: [PATCH 28/28] Update LKG --- lib/tsc.js | 192 ++++++++++++++++++------------- lib/tsserver.js | 219 +++++++++++++++++++++--------------- lib/typescript.d.ts | 16 +-- lib/typescript.js | 213 ++++++++++++++++++++--------------- lib/typescriptServices.d.ts | 16 +-- lib/typescriptServices.js | 213 ++++++++++++++++++++--------------- 6 files changed, 505 insertions(+), 364 deletions(-) diff --git a/lib/tsc.js b/lib/tsc.js index 019ef143cc8..a98799b1d86 100644 --- a/lib/tsc.js +++ b/lib/tsc.js @@ -1431,6 +1431,8 @@ var ts; Cannot_emit_namespaced_JSX_elements_in_React: { code: 2650, category: ts.DiagnosticCategory.Error, key: "Cannot emit namespaced JSX elements in React" }, A_member_initializer_in_a_enum_declaration_cannot_reference_members_declared_after_it_including_members_defined_in_other_enums: { code: 2651, category: ts.DiagnosticCategory.Error, key: "A member initializer in a enum declaration cannot reference members declared after it, including members defined in other enums." }, Merged_declaration_0_cannot_include_a_default_export_declaration_Consider_adding_a_separate_export_default_0_declaration_instead: { code: 2652, category: ts.DiagnosticCategory.Error, key: "Merged declaration '{0}' cannot include a default export declaration. Consider adding a separate 'export default {0}' declaration instead." }, + Exported_external_package_typings_file_cannot_contain_tripleslash_references_Please_contact_the_package_author_to_update_the_package_definition: { code: 2654, category: ts.DiagnosticCategory.Error, key: "Exported external package typings file cannot contain tripleslash references. Please contact the package author to update the package definition." }, + Exported_external_package_typings_can_only_be_in_d_ts_files_Please_contact_the_package_author_to_update_the_package_definition: { code: 2655, category: ts.DiagnosticCategory.Error, key: "Exported external package typings can only be in '.d.ts' files. Please contact the package author to update the package definition." }, Import_declaration_0_is_using_private_name_1: { code: 4000, category: ts.DiagnosticCategory.Error, key: "Import declaration '{0}' is using private name '{1}'." }, Type_parameter_0_of_exported_class_has_or_is_using_private_name_1: { code: 4002, category: ts.DiagnosticCategory.Error, key: "Type parameter '{0}' of exported class has or is using private name '{1}'." }, Type_parameter_0_of_exported_interface_has_or_is_using_private_name_1: { code: 4004, category: ts.DiagnosticCategory.Error, key: "Type parameter '{0}' of exported interface has or is using private name '{1}'." }, @@ -3760,21 +3762,21 @@ var ts; return true; } ts.arrayIsEqualTo = arrayIsEqualTo; - function hasResolvedModuleName(sourceFile, moduleNameText) { + function hasResolvedModule(sourceFile, moduleNameText) { return sourceFile.resolvedModules && ts.hasProperty(sourceFile.resolvedModules, moduleNameText); } - ts.hasResolvedModuleName = hasResolvedModuleName; - function getResolvedModuleFileName(sourceFile, moduleNameText) { - return hasResolvedModuleName(sourceFile, moduleNameText) ? sourceFile.resolvedModules[moduleNameText] : undefined; + ts.hasResolvedModule = hasResolvedModule; + function getResolvedModule(sourceFile, moduleNameText) { + return hasResolvedModule(sourceFile, moduleNameText) ? sourceFile.resolvedModules[moduleNameText] : undefined; } - ts.getResolvedModuleFileName = getResolvedModuleFileName; - function setResolvedModuleName(sourceFile, moduleNameText, resolvedFileName) { + ts.getResolvedModule = getResolvedModule; + function setResolvedModule(sourceFile, moduleNameText, resolvedModule) { if (!sourceFile.resolvedModules) { sourceFile.resolvedModules = {}; } - sourceFile.resolvedModules[moduleNameText] = resolvedFileName; + sourceFile.resolvedModules[moduleNameText] = resolvedModule; } - ts.setResolvedModuleName = setResolvedModuleName; + ts.setResolvedModule = setResolvedModule; function containsParseError(node) { aggregateChildData(node); return (node.parserContextFlags & 64) !== 0; @@ -4976,11 +4978,21 @@ var ts; add: add, getGlobalDiagnostics: getGlobalDiagnostics, getDiagnostics: getDiagnostics, - getModificationCount: getModificationCount + getModificationCount: getModificationCount, + reattachFileDiagnostics: reattachFileDiagnostics }; function getModificationCount() { return modificationCount; } + function reattachFileDiagnostics(newFile) { + if (!ts.hasProperty(fileDiagnostics, newFile.fileName)) { + return; + } + for (var _i = 0, _a = fileDiagnostics[newFile.fileName]; _i < _a.length; _i++) { + var diagnostic = _a[_i]; + diagnostic.file = newFile; + } + } function add(diagnostic) { var diagnostics; if (diagnostic.file) { @@ -10966,8 +10978,8 @@ var ts; return symbol; } } - var fileName = ts.getResolvedModuleFileName(getSourceFile(location), moduleReferenceLiteral.text); - var sourceFile = fileName && host.getSourceFile(fileName); + var resolvedModule = ts.getResolvedModule(getSourceFile(location), moduleReferenceLiteral.text); + var sourceFile = resolvedModule && host.getSourceFile(resolvedModule.resolvedFileName); if (sourceFile) { if (sourceFile.symbol) { return sourceFile.symbol; @@ -25985,6 +25997,9 @@ var ts; } function emitExportSpecifierInSystemModule(specifier) { ts.Debug.assert(compilerOptions.module === 4); + if (!resolver.getReferencedValueDeclaration(specifier.propertyName || specifier.name) && !resolver.isValueAliasDeclaration(specifier)) { + return; + } writeLine(); emitStart(specifier.name); write(exportFunctionForFile + "(\""); @@ -28253,7 +28268,7 @@ var ts; } return; } - if (ts.isInternalModuleImportEqualsDeclaration(node)) { + if (ts.isInternalModuleImportEqualsDeclaration(node) && resolver.isValueAliasDeclaration(node)) { if (!hoistedVars) { hoistedVars = []; } @@ -29379,10 +29394,12 @@ var ts; var candidate = ts.normalizePath(ts.combinePaths(containingDirectory, moduleName)); var resolvedFileName = loadNodeModuleFromFile(candidate, false, failedLookupLocations, host); if (resolvedFileName) { - return { resolvedFileName: resolvedFileName, failedLookupLocations: failedLookupLocations }; + return { resolvedModule: { resolvedFileName: resolvedFileName }, failedLookupLocations: failedLookupLocations }; } resolvedFileName = loadNodeModuleFromDirectory(candidate, false, failedLookupLocations, host); - return { resolvedFileName: resolvedFileName, failedLookupLocations: failedLookupLocations }; + return resolvedFileName + ? { resolvedModule: { resolvedFileName: resolvedFileName }, failedLookupLocations: failedLookupLocations } + : { resolvedModule: undefined, failedLookupLocations: failedLookupLocations }; } else { return loadModuleFromNodeModules(moduleName, containingDirectory, host); @@ -29440,11 +29457,11 @@ var ts; var candidate = ts.normalizePath(ts.combinePaths(nodeModulesFolder, moduleName)); var result = loadNodeModuleFromFile(candidate, true, failedLookupLocations, host); if (result) { - return { resolvedFileName: result, failedLookupLocations: failedLookupLocations }; + return { resolvedModule: { resolvedFileName: result, isExternalLibraryImport: true }, failedLookupLocations: failedLookupLocations }; } result = loadNodeModuleFromDirectory(candidate, true, failedLookupLocations, host); if (result) { - return { resolvedFileName: result, failedLookupLocations: failedLookupLocations }; + return { resolvedModule: { resolvedFileName: result, isExternalLibraryImport: true }, failedLookupLocations: failedLookupLocations }; } } var parentPath = ts.getDirectoryPath(directory); @@ -29453,36 +29470,15 @@ var ts; } directory = parentPath; } - return { resolvedFileName: undefined, failedLookupLocations: failedLookupLocations }; + return { resolvedModule: undefined, failedLookupLocations: failedLookupLocations }; } - function baseUrlModuleNameResolver(moduleName, containingFile, baseUrl, host) { - ts.Debug.assert(baseUrl !== undefined); - var normalizedModuleName = ts.normalizeSlashes(moduleName); - var basePart = useBaseUrl(moduleName) ? baseUrl : ts.getDirectoryPath(containingFile); - var candidate = ts.normalizePath(ts.combinePaths(basePart, moduleName)); - var failedLookupLocations = []; - return ts.forEach(ts.supportedExtensions, function (ext) { return tryLoadFile(candidate + ext); }) || { resolvedFileName: undefined, failedLookupLocations: failedLookupLocations }; - function tryLoadFile(location) { - if (host.fileExists(location)) { - return { resolvedFileName: location, failedLookupLocations: failedLookupLocations }; - } - else { - failedLookupLocations.push(location); - return undefined; - } - } - } - ts.baseUrlModuleNameResolver = baseUrlModuleNameResolver; function nameStartsWithDotSlashOrDotDotSlash(name) { var i = name.lastIndexOf("./", 1); return i === 0 || (i === 1 && name.charCodeAt(0) === 46); } - function useBaseUrl(moduleName) { - return ts.getRootLength(moduleName) === 0 && !nameStartsWithDotSlashOrDotDotSlash(moduleName); - } function classicNameResolver(moduleName, containingFile, compilerOptions, host) { if (moduleName.indexOf('!') != -1) { - return { resolvedFileName: undefined, failedLookupLocations: [] }; + return { resolvedModule: undefined, failedLookupLocations: [] }; } var searchPath = ts.getDirectoryPath(containingFile); var searchName; @@ -29511,7 +29507,9 @@ var ts; } searchPath = parentPath; } - return { resolvedFileName: referencedSourceFile, failedLookupLocations: failedLookupLocations }; + return referencedSourceFile + ? { resolvedModule: { resolvedFileName: referencedSourceFile }, failedLookupLocations: failedLookupLocations } + : { resolvedModule: undefined, failedLookupLocations: failedLookupLocations }; } ts.classicNameResolver = classicNameResolver; ts.defaultInitCompilerOptions = { @@ -29624,7 +29622,8 @@ var ts; function createProgram(rootNames, options, host, oldProgram) { var program; var files = []; - var diagnostics = ts.createDiagnosticCollection(); + var fileProcessingDiagnostics = ts.createDiagnosticCollection(); + var programDiagnostics = ts.createDiagnosticCollection(); var commonSourceDirectory; var diagnosticsProducingTypeChecker; var noDiagnosticsTypeChecker; @@ -29632,8 +29631,9 @@ var ts; var skipDefaultLib = options.noLib; var start = new Date().getTime(); host = host || createCompilerHost(options); - var resolveModuleNamesWorker = host.resolveModuleNames || - (function (moduleNames, containingFile) { return ts.map(moduleNames, function (moduleName) { return resolveModuleName(moduleName, containingFile, options, host).resolvedFileName; }); }); + var resolveModuleNamesWorker = host.resolveModuleNames + ? (function (moduleNames, containingFile) { return host.resolveModuleNames(moduleNames, containingFile); }) + : (function (moduleNames, containingFile) { return ts.map(moduleNames, function (moduleName) { return resolveModuleName(moduleName, containingFile, options, host).resolvedModule; }); }); var filesByName = ts.createFileMap(function (fileName) { return host.getCanonicalFileName(fileName); }); if (oldProgram) { var oldOptions = oldProgram.getCompilerOptions(); @@ -29673,7 +29673,8 @@ var ts; getNodeCount: function () { return getDiagnosticsProducingTypeChecker().getNodeCount(); }, getIdentifierCount: function () { return getDiagnosticsProducingTypeChecker().getIdentifierCount(); }, getSymbolCount: function () { return getDiagnosticsProducingTypeChecker().getSymbolCount(); }, - getTypeCount: function () { return getDiagnosticsProducingTypeChecker().getTypeCount(); } + getTypeCount: function () { return getDiagnosticsProducingTypeChecker().getTypeCount(); }, + getFileProcessingDiagnostics: function () { return fileProcessingDiagnostics; } }; return program; function getClassifiableNames() { @@ -29697,6 +29698,7 @@ var ts; return false; } var newSourceFiles = []; + var modifiedSourceFiles = []; for (var _i = 0, _a = oldProgram.getSourceFiles(); _i < _a.length; _i++) { var oldSourceFile = _a[_i]; var newSourceFile = host.getSourceFile(oldSourceFile.fileName, options.target); @@ -29718,13 +29720,20 @@ var ts; var moduleNames = ts.map(newSourceFile.imports, function (name) { return name.text; }); var resolutions = resolveModuleNamesWorker(moduleNames, newSourceFile.fileName); for (var i = 0; i < moduleNames.length; ++i) { - var oldResolution = ts.getResolvedModuleFileName(oldSourceFile, moduleNames[i]); - if (oldResolution !== resolutions[i]) { + var newResolution = resolutions[i]; + var oldResolution = ts.getResolvedModule(oldSourceFile, moduleNames[i]); + var resolutionChanged = oldResolution + ? !newResolution || + oldResolution.resolvedFileName !== newResolution.resolvedFileName || + !!oldResolution.isExternalLibraryImport !== !!newResolution.isExternalLibraryImport + : newResolution; + if (resolutionChanged) { return false; } } } newSourceFile.resolvedModules = oldSourceFile.resolvedModules; + modifiedSourceFiles.push(newSourceFile); } else { newSourceFile = oldSourceFile; @@ -29736,6 +29745,11 @@ var ts; filesByName.set(file.fileName, file); } files = newSourceFiles; + fileProcessingDiagnostics = oldProgram.getFileProcessingDiagnostics(); + for (var _c = 0; _c < modifiedSourceFiles.length; _c++) { + var modifiedFile = modifiedSourceFiles[_c]; + fileProcessingDiagnostics.reattachFileDiagnostics(modifiedFile); + } oldProgram.structureIsReused = true; return true; } @@ -29817,8 +29831,9 @@ var ts; ts.Debug.assert(!!sourceFile.bindDiagnostics); var bindDiagnostics = sourceFile.bindDiagnostics; var checkDiagnostics = typeChecker.getDiagnostics(sourceFile, cancellationToken); - var programDiagnostics = diagnostics.getDiagnostics(sourceFile.fileName); - return bindDiagnostics.concat(checkDiagnostics).concat(programDiagnostics); + var fileProcessingDiagnosticsInFile = fileProcessingDiagnostics.getDiagnostics(sourceFile.fileName); + var programDiagnosticsInFile = programDiagnostics.getDiagnostics(sourceFile.fileName); + return bindDiagnostics.concat(checkDiagnostics).concat(fileProcessingDiagnosticsInFile).concat(programDiagnosticsInFile); }); } function getDeclarationDiagnosticsForFile(sourceFile, cancellationToken) { @@ -29832,7 +29847,8 @@ var ts; } function getOptionsDiagnostics() { var allDiagnostics = []; - ts.addRange(allDiagnostics, diagnostics.getGlobalDiagnostics()); + ts.addRange(allDiagnostics, fileProcessingDiagnostics.getGlobalDiagnostics()); + ts.addRange(allDiagnostics, programDiagnostics.getGlobalDiagnostics()); return ts.sortAndDeduplicateDiagnostics(allDiagnostics); } function getGlobalDiagnostics() { @@ -29922,10 +29938,10 @@ var ts; } if (diagnostic) { if (refFile !== undefined && refEnd !== undefined && refPos !== undefined) { - diagnostics.add(ts.createFileDiagnostic.apply(void 0, [refFile, refPos, refEnd - refPos, diagnostic].concat(diagnosticArgument))); + fileProcessingDiagnostics.add(ts.createFileDiagnostic.apply(void 0, [refFile, refPos, refEnd - refPos, diagnostic].concat(diagnosticArgument))); } else { - diagnostics.add(ts.createCompilerDiagnostic.apply(void 0, [diagnostic].concat(diagnosticArgument))); + fileProcessingDiagnostics.add(ts.createCompilerDiagnostic.apply(void 0, [diagnostic].concat(diagnosticArgument))); } } } @@ -29942,10 +29958,10 @@ var ts; } var file = host.getSourceFile(fileName, options.target, function (hostErrorMessage) { if (refFile !== undefined && refPos !== undefined && refEnd !== undefined) { - diagnostics.add(ts.createFileDiagnostic(refFile, refPos, refEnd - refPos, ts.Diagnostics.Cannot_read_file_0_Colon_1, fileName, hostErrorMessage)); + fileProcessingDiagnostics.add(ts.createFileDiagnostic(refFile, refPos, refEnd - refPos, ts.Diagnostics.Cannot_read_file_0_Colon_1, fileName, hostErrorMessage)); } else { - diagnostics.add(ts.createCompilerDiagnostic(ts.Diagnostics.Cannot_read_file_0_Colon_1, fileName, hostErrorMessage)); + fileProcessingDiagnostics.add(ts.createCompilerDiagnostic(ts.Diagnostics.Cannot_read_file_0_Colon_1, fileName, hostErrorMessage)); } }); filesByName.set(canonicalName, file); @@ -29973,10 +29989,10 @@ var ts; var sourceFileName = useAbsolutePath ? ts.getNormalizedAbsolutePath(file.fileName, host.getCurrentDirectory()) : file.fileName; if (canonicalName !== sourceFileName) { if (refFile !== undefined && refPos !== undefined && refEnd !== undefined) { - diagnostics.add(ts.createFileDiagnostic(refFile, refPos, refEnd - refPos, ts.Diagnostics.File_name_0_differs_from_already_included_file_name_1_only_in_casing, fileName, sourceFileName)); + fileProcessingDiagnostics.add(ts.createFileDiagnostic(refFile, refPos, refEnd - refPos, ts.Diagnostics.File_name_0_differs_from_already_included_file_name_1_only_in_casing, fileName, sourceFileName)); } else { - diagnostics.add(ts.createCompilerDiagnostic(ts.Diagnostics.File_name_0_differs_from_already_included_file_name_1_only_in_casing, fileName, sourceFileName)); + fileProcessingDiagnostics.add(ts.createCompilerDiagnostic(ts.Diagnostics.File_name_0_differs_from_already_included_file_name_1_only_in_casing, fileName, sourceFileName)); } } } @@ -29997,9 +30013,23 @@ var ts; var resolutions = resolveModuleNamesWorker(moduleNames, file.fileName); for (var i = 0; i < file.imports.length; ++i) { var resolution = resolutions[i]; - ts.setResolvedModuleName(file, moduleNames[i], resolution); + ts.setResolvedModule(file, moduleNames[i], resolution); if (resolution && !options.noResolve) { - findModuleSourceFile(resolution, file.imports[i]); + var importedFile = findModuleSourceFile(resolution.resolvedFileName, file.imports[i]); + if (importedFile && resolution.isExternalLibraryImport) { + if (!ts.isExternalModule(importedFile)) { + var start_2 = ts.getTokenPosOfNode(file.imports[i], file); + fileProcessingDiagnostics.add(ts.createFileDiagnostic(file, start_2, file.imports[i].end - start_2, ts.Diagnostics.File_0_is_not_a_module, importedFile.fileName)); + } + else if (!ts.fileExtensionIs(importedFile.fileName, ".d.ts")) { + var start_3 = ts.getTokenPosOfNode(file.imports[i], file); + fileProcessingDiagnostics.add(ts.createFileDiagnostic(file, start_3, file.imports[i].end - start_3, ts.Diagnostics.Exported_external_package_typings_can_only_be_in_d_ts_files_Please_contact_the_package_author_to_update_the_package_definition)); + } + else if (importedFile.referencedFiles.length) { + var firstRef = importedFile.referencedFiles[0]; + fileProcessingDiagnostics.add(ts.createFileDiagnostic(importedFile, firstRef.pos, firstRef.end - firstRef.pos, ts.Diagnostics.Exported_external_package_typings_file_cannot_contain_tripleslash_references_Please_contact_the_package_author_to_update_the_package_definition)); + } + } } } } @@ -30008,7 +30038,7 @@ var ts; } return; function findModuleSourceFile(fileName, nameLiteral) { - return findSourceFile(fileName, false, file, nameLiteral.pos, nameLiteral.end); + return findSourceFile(fileName, false, file, ts.skipTrivia(file.text, nameLiteral.pos), nameLiteral.end); } } function computeCommonSourceDirectory(sourceFiles) { @@ -30027,7 +30057,7 @@ var ts; for (var i = 0, n = Math.min(commonPathComponents.length, sourcePathComponents.length); i < n; i++) { if (commonPathComponents[i] !== sourcePathComponents[i]) { if (i === 0) { - diagnostics.add(ts.createCompilerDiagnostic(ts.Diagnostics.Cannot_find_the_common_subdirectory_path_for_the_input_files)); + programDiagnostics.add(ts.createCompilerDiagnostic(ts.Diagnostics.Cannot_find_the_common_subdirectory_path_for_the_input_files)); return; } commonPathComponents.length = i; @@ -30050,7 +30080,7 @@ var ts; if (!ts.isDeclarationFile(sourceFile)) { var absoluteSourceFilePath = host.getCanonicalFileName(ts.getNormalizedAbsolutePath(sourceFile.fileName, currentDirectory)); if (absoluteSourceFilePath.indexOf(absoluteRootDirectoryPath) !== 0) { - diagnostics.add(ts.createCompilerDiagnostic(ts.Diagnostics.File_0_is_not_under_rootDir_1_rootDir_is_expected_to_contain_all_source_files, sourceFile.fileName, options.rootDir)); + programDiagnostics.add(ts.createCompilerDiagnostic(ts.Diagnostics.File_0_is_not_under_rootDir_1_rootDir_is_expected_to_contain_all_source_files, sourceFile.fileName, options.rootDir)); allFilesBelongToPath = false; } } @@ -30061,43 +30091,43 @@ var ts; function verifyCompilerOptions() { if (options.isolatedModules) { if (options.declaration) { - diagnostics.add(ts.createCompilerDiagnostic(ts.Diagnostics.Option_0_cannot_be_specified_with_option_1, "declaration", "isolatedModules")); + programDiagnostics.add(ts.createCompilerDiagnostic(ts.Diagnostics.Option_0_cannot_be_specified_with_option_1, "declaration", "isolatedModules")); } if (options.noEmitOnError) { - diagnostics.add(ts.createCompilerDiagnostic(ts.Diagnostics.Option_0_cannot_be_specified_with_option_1, "noEmitOnError", "isolatedModules")); + programDiagnostics.add(ts.createCompilerDiagnostic(ts.Diagnostics.Option_0_cannot_be_specified_with_option_1, "noEmitOnError", "isolatedModules")); } if (options.out) { - diagnostics.add(ts.createCompilerDiagnostic(ts.Diagnostics.Option_0_cannot_be_specified_with_option_1, "out", "isolatedModules")); + programDiagnostics.add(ts.createCompilerDiagnostic(ts.Diagnostics.Option_0_cannot_be_specified_with_option_1, "out", "isolatedModules")); } if (options.outFile) { - diagnostics.add(ts.createCompilerDiagnostic(ts.Diagnostics.Option_0_cannot_be_specified_with_option_1, "outFile", "isolatedModules")); + programDiagnostics.add(ts.createCompilerDiagnostic(ts.Diagnostics.Option_0_cannot_be_specified_with_option_1, "outFile", "isolatedModules")); } } if (options.inlineSourceMap) { if (options.sourceMap) { - diagnostics.add(ts.createCompilerDiagnostic(ts.Diagnostics.Option_0_cannot_be_specified_with_option_1, "sourceMap", "inlineSourceMap")); + programDiagnostics.add(ts.createCompilerDiagnostic(ts.Diagnostics.Option_0_cannot_be_specified_with_option_1, "sourceMap", "inlineSourceMap")); } if (options.mapRoot) { - diagnostics.add(ts.createCompilerDiagnostic(ts.Diagnostics.Option_0_cannot_be_specified_with_option_1, "mapRoot", "inlineSourceMap")); + programDiagnostics.add(ts.createCompilerDiagnostic(ts.Diagnostics.Option_0_cannot_be_specified_with_option_1, "mapRoot", "inlineSourceMap")); } if (options.sourceRoot) { - diagnostics.add(ts.createCompilerDiagnostic(ts.Diagnostics.Option_0_cannot_be_specified_with_option_1, "sourceRoot", "inlineSourceMap")); + programDiagnostics.add(ts.createCompilerDiagnostic(ts.Diagnostics.Option_0_cannot_be_specified_with_option_1, "sourceRoot", "inlineSourceMap")); } } if (options.inlineSources) { if (!options.sourceMap && !options.inlineSourceMap) { - diagnostics.add(ts.createCompilerDiagnostic(ts.Diagnostics.Option_inlineSources_can_only_be_used_when_either_option_inlineSourceMap_or_option_sourceMap_is_provided)); + programDiagnostics.add(ts.createCompilerDiagnostic(ts.Diagnostics.Option_inlineSources_can_only_be_used_when_either_option_inlineSourceMap_or_option_sourceMap_is_provided)); } } if (options.out && options.outFile) { - diagnostics.add(ts.createCompilerDiagnostic(ts.Diagnostics.Option_0_cannot_be_specified_with_option_1, "out", "outFile")); + programDiagnostics.add(ts.createCompilerDiagnostic(ts.Diagnostics.Option_0_cannot_be_specified_with_option_1, "out", "outFile")); } if (!options.sourceMap && (options.mapRoot || options.sourceRoot)) { if (options.mapRoot) { - diagnostics.add(ts.createCompilerDiagnostic(ts.Diagnostics.Option_0_cannot_be_specified_without_specifying_option_1, "mapRoot", "sourceMap")); + programDiagnostics.add(ts.createCompilerDiagnostic(ts.Diagnostics.Option_0_cannot_be_specified_without_specifying_option_1, "mapRoot", "sourceMap")); } if (options.sourceRoot) { - diagnostics.add(ts.createCompilerDiagnostic(ts.Diagnostics.Option_0_cannot_be_specified_without_specifying_option_1, "sourceRoot", "sourceMap")); + programDiagnostics.add(ts.createCompilerDiagnostic(ts.Diagnostics.Option_0_cannot_be_specified_without_specifying_option_1, "sourceRoot", "sourceMap")); } return; } @@ -30106,20 +30136,20 @@ var ts; var firstExternalModuleSourceFile = ts.forEach(files, function (f) { return ts.isExternalModule(f) ? f : undefined; }); if (options.isolatedModules) { if (!options.module && languageVersion < 2) { - diagnostics.add(ts.createCompilerDiagnostic(ts.Diagnostics.Option_isolatedModules_can_only_be_used_when_either_option_module_is_provided_or_option_target_is_ES6_or_higher)); + programDiagnostics.add(ts.createCompilerDiagnostic(ts.Diagnostics.Option_isolatedModules_can_only_be_used_when_either_option_module_is_provided_or_option_target_is_ES6_or_higher)); } var firstNonExternalModuleSourceFile = ts.forEach(files, function (f) { return !ts.isExternalModule(f) && !ts.isDeclarationFile(f) ? f : undefined; }); if (firstNonExternalModuleSourceFile) { var span = ts.getErrorSpanForNode(firstNonExternalModuleSourceFile, firstNonExternalModuleSourceFile); - diagnostics.add(ts.createFileDiagnostic(firstNonExternalModuleSourceFile, span.start, span.length, ts.Diagnostics.Cannot_compile_namespaces_when_the_isolatedModules_flag_is_provided)); + programDiagnostics.add(ts.createFileDiagnostic(firstNonExternalModuleSourceFile, span.start, span.length, ts.Diagnostics.Cannot_compile_namespaces_when_the_isolatedModules_flag_is_provided)); } } else if (firstExternalModuleSourceFile && languageVersion < 2 && !options.module) { var span = ts.getErrorSpanForNode(firstExternalModuleSourceFile, firstExternalModuleSourceFile.externalModuleIndicator); - diagnostics.add(ts.createFileDiagnostic(firstExternalModuleSourceFile, span.start, span.length, ts.Diagnostics.Cannot_compile_modules_unless_the_module_flag_is_provided)); + programDiagnostics.add(ts.createFileDiagnostic(firstExternalModuleSourceFile, span.start, span.length, ts.Diagnostics.Cannot_compile_modules_unless_the_module_flag_is_provided)); } if (options.module && languageVersion >= 2) { - diagnostics.add(ts.createCompilerDiagnostic(ts.Diagnostics.Cannot_compile_modules_into_commonjs_amd_system_or_umd_when_targeting_ES6_or_higher)); + programDiagnostics.add(ts.createCompilerDiagnostic(ts.Diagnostics.Cannot_compile_modules_into_commonjs_amd_system_or_umd_when_targeting_ES6_or_higher)); } if (options.outDir || options.sourceRoot || @@ -30137,25 +30167,25 @@ var ts; } if (options.noEmit) { if (options.out) { - diagnostics.add(ts.createCompilerDiagnostic(ts.Diagnostics.Option_0_cannot_be_specified_with_option_1, "noEmit", "out")); + programDiagnostics.add(ts.createCompilerDiagnostic(ts.Diagnostics.Option_0_cannot_be_specified_with_option_1, "noEmit", "out")); } if (options.outFile) { - diagnostics.add(ts.createCompilerDiagnostic(ts.Diagnostics.Option_0_cannot_be_specified_with_option_1, "noEmit", "outFile")); + programDiagnostics.add(ts.createCompilerDiagnostic(ts.Diagnostics.Option_0_cannot_be_specified_with_option_1, "noEmit", "outFile")); } if (options.outDir) { - diagnostics.add(ts.createCompilerDiagnostic(ts.Diagnostics.Option_0_cannot_be_specified_with_option_1, "noEmit", "outDir")); + programDiagnostics.add(ts.createCompilerDiagnostic(ts.Diagnostics.Option_0_cannot_be_specified_with_option_1, "noEmit", "outDir")); } if (options.declaration) { - diagnostics.add(ts.createCompilerDiagnostic(ts.Diagnostics.Option_0_cannot_be_specified_with_option_1, "noEmit", "declaration")); + programDiagnostics.add(ts.createCompilerDiagnostic(ts.Diagnostics.Option_0_cannot_be_specified_with_option_1, "noEmit", "declaration")); } } if (options.emitDecoratorMetadata && !options.experimentalDecorators) { - diagnostics.add(ts.createCompilerDiagnostic(ts.Diagnostics.Option_0_cannot_be_specified_without_specifying_option_1, "emitDecoratorMetadata", "experimentalDecorators")); + programDiagnostics.add(ts.createCompilerDiagnostic(ts.Diagnostics.Option_0_cannot_be_specified_without_specifying_option_1, "emitDecoratorMetadata", "experimentalDecorators")); } if (options.experimentalAsyncFunctions && options.target !== 2) { - diagnostics.add(ts.createCompilerDiagnostic(ts.Diagnostics.Option_experimentalAsyncFunctions_cannot_be_specified_when_targeting_ES5_or_lower)); + programDiagnostics.add(ts.createCompilerDiagnostic(ts.Diagnostics.Option_experimentalAsyncFunctions_cannot_be_specified_when_targeting_ES5_or_lower)); } } } diff --git a/lib/tsserver.js b/lib/tsserver.js index fc5f34dec2a..ce095409d9a 100644 --- a/lib/tsserver.js +++ b/lib/tsserver.js @@ -1431,6 +1431,8 @@ var ts; Cannot_emit_namespaced_JSX_elements_in_React: { code: 2650, category: ts.DiagnosticCategory.Error, key: "Cannot emit namespaced JSX elements in React" }, A_member_initializer_in_a_enum_declaration_cannot_reference_members_declared_after_it_including_members_defined_in_other_enums: { code: 2651, category: ts.DiagnosticCategory.Error, key: "A member initializer in a enum declaration cannot reference members declared after it, including members defined in other enums." }, Merged_declaration_0_cannot_include_a_default_export_declaration_Consider_adding_a_separate_export_default_0_declaration_instead: { code: 2652, category: ts.DiagnosticCategory.Error, key: "Merged declaration '{0}' cannot include a default export declaration. Consider adding a separate 'export default {0}' declaration instead." }, + Exported_external_package_typings_file_cannot_contain_tripleslash_references_Please_contact_the_package_author_to_update_the_package_definition: { code: 2654, category: ts.DiagnosticCategory.Error, key: "Exported external package typings file cannot contain tripleslash references. Please contact the package author to update the package definition." }, + Exported_external_package_typings_can_only_be_in_d_ts_files_Please_contact_the_package_author_to_update_the_package_definition: { code: 2655, category: ts.DiagnosticCategory.Error, key: "Exported external package typings can only be in '.d.ts' files. Please contact the package author to update the package definition." }, Import_declaration_0_is_using_private_name_1: { code: 4000, category: ts.DiagnosticCategory.Error, key: "Import declaration '{0}' is using private name '{1}'." }, Type_parameter_0_of_exported_class_has_or_is_using_private_name_1: { code: 4002, category: ts.DiagnosticCategory.Error, key: "Type parameter '{0}' of exported class has or is using private name '{1}'." }, Type_parameter_0_of_exported_interface_has_or_is_using_private_name_1: { code: 4004, category: ts.DiagnosticCategory.Error, key: "Type parameter '{0}' of exported interface has or is using private name '{1}'." }, @@ -3508,21 +3510,21 @@ var ts; return true; } ts.arrayIsEqualTo = arrayIsEqualTo; - function hasResolvedModuleName(sourceFile, moduleNameText) { + function hasResolvedModule(sourceFile, moduleNameText) { return sourceFile.resolvedModules && ts.hasProperty(sourceFile.resolvedModules, moduleNameText); } - ts.hasResolvedModuleName = hasResolvedModuleName; - function getResolvedModuleFileName(sourceFile, moduleNameText) { - return hasResolvedModuleName(sourceFile, moduleNameText) ? sourceFile.resolvedModules[moduleNameText] : undefined; + ts.hasResolvedModule = hasResolvedModule; + function getResolvedModule(sourceFile, moduleNameText) { + return hasResolvedModule(sourceFile, moduleNameText) ? sourceFile.resolvedModules[moduleNameText] : undefined; } - ts.getResolvedModuleFileName = getResolvedModuleFileName; - function setResolvedModuleName(sourceFile, moduleNameText, resolvedFileName) { + ts.getResolvedModule = getResolvedModule; + function setResolvedModule(sourceFile, moduleNameText, resolvedModule) { if (!sourceFile.resolvedModules) { sourceFile.resolvedModules = {}; } - sourceFile.resolvedModules[moduleNameText] = resolvedFileName; + sourceFile.resolvedModules[moduleNameText] = resolvedModule; } - ts.setResolvedModuleName = setResolvedModuleName; + ts.setResolvedModule = setResolvedModule; function containsParseError(node) { aggregateChildData(node); return (node.parserContextFlags & 64) !== 0; @@ -4724,11 +4726,21 @@ var ts; add: add, getGlobalDiagnostics: getGlobalDiagnostics, getDiagnostics: getDiagnostics, - getModificationCount: getModificationCount + getModificationCount: getModificationCount, + reattachFileDiagnostics: reattachFileDiagnostics }; function getModificationCount() { return modificationCount; } + function reattachFileDiagnostics(newFile) { + if (!ts.hasProperty(fileDiagnostics, newFile.fileName)) { + return; + } + for (var _i = 0, _a = fileDiagnostics[newFile.fileName]; _i < _a.length; _i++) { + var diagnostic = _a[_i]; + diagnostic.file = newFile; + } + } function add(diagnostic) { var diagnostics; if (diagnostic.file) { @@ -11428,8 +11440,8 @@ var ts; return symbol; } } - var fileName = ts.getResolvedModuleFileName(getSourceFile(location), moduleReferenceLiteral.text); - var sourceFile = fileName && host.getSourceFile(fileName); + var resolvedModule = ts.getResolvedModule(getSourceFile(location), moduleReferenceLiteral.text); + var sourceFile = resolvedModule && host.getSourceFile(resolvedModule.resolvedFileName); if (sourceFile) { if (sourceFile.symbol) { return sourceFile.symbol; @@ -26447,6 +26459,9 @@ var ts; } function emitExportSpecifierInSystemModule(specifier) { ts.Debug.assert(compilerOptions.module === 4); + if (!resolver.getReferencedValueDeclaration(specifier.propertyName || specifier.name) && !resolver.isValueAliasDeclaration(specifier)) { + return; + } writeLine(); emitStart(specifier.name); write(exportFunctionForFile + "(\""); @@ -28715,7 +28730,7 @@ var ts; } return; } - if (ts.isInternalModuleImportEqualsDeclaration(node)) { + if (ts.isInternalModuleImportEqualsDeclaration(node) && resolver.isValueAliasDeclaration(node)) { if (!hoistedVars) { hoistedVars = []; } @@ -29841,10 +29856,12 @@ var ts; var candidate = ts.normalizePath(ts.combinePaths(containingDirectory, moduleName)); var resolvedFileName = loadNodeModuleFromFile(candidate, false, failedLookupLocations, host); if (resolvedFileName) { - return { resolvedFileName: resolvedFileName, failedLookupLocations: failedLookupLocations }; + return { resolvedModule: { resolvedFileName: resolvedFileName }, failedLookupLocations: failedLookupLocations }; } resolvedFileName = loadNodeModuleFromDirectory(candidate, false, failedLookupLocations, host); - return { resolvedFileName: resolvedFileName, failedLookupLocations: failedLookupLocations }; + return resolvedFileName + ? { resolvedModule: { resolvedFileName: resolvedFileName }, failedLookupLocations: failedLookupLocations } + : { resolvedModule: undefined, failedLookupLocations: failedLookupLocations }; } else { return loadModuleFromNodeModules(moduleName, containingDirectory, host); @@ -29902,11 +29919,11 @@ var ts; var candidate = ts.normalizePath(ts.combinePaths(nodeModulesFolder, moduleName)); var result = loadNodeModuleFromFile(candidate, true, failedLookupLocations, host); if (result) { - return { resolvedFileName: result, failedLookupLocations: failedLookupLocations }; + return { resolvedModule: { resolvedFileName: result, isExternalLibraryImport: true }, failedLookupLocations: failedLookupLocations }; } result = loadNodeModuleFromDirectory(candidate, true, failedLookupLocations, host); if (result) { - return { resolvedFileName: result, failedLookupLocations: failedLookupLocations }; + return { resolvedModule: { resolvedFileName: result, isExternalLibraryImport: true }, failedLookupLocations: failedLookupLocations }; } } var parentPath = ts.getDirectoryPath(directory); @@ -29915,36 +29932,15 @@ var ts; } directory = parentPath; } - return { resolvedFileName: undefined, failedLookupLocations: failedLookupLocations }; + return { resolvedModule: undefined, failedLookupLocations: failedLookupLocations }; } - function baseUrlModuleNameResolver(moduleName, containingFile, baseUrl, host) { - ts.Debug.assert(baseUrl !== undefined); - var normalizedModuleName = ts.normalizeSlashes(moduleName); - var basePart = useBaseUrl(moduleName) ? baseUrl : ts.getDirectoryPath(containingFile); - var candidate = ts.normalizePath(ts.combinePaths(basePart, moduleName)); - var failedLookupLocations = []; - return ts.forEach(ts.supportedExtensions, function (ext) { return tryLoadFile(candidate + ext); }) || { resolvedFileName: undefined, failedLookupLocations: failedLookupLocations }; - function tryLoadFile(location) { - if (host.fileExists(location)) { - return { resolvedFileName: location, failedLookupLocations: failedLookupLocations }; - } - else { - failedLookupLocations.push(location); - return undefined; - } - } - } - ts.baseUrlModuleNameResolver = baseUrlModuleNameResolver; function nameStartsWithDotSlashOrDotDotSlash(name) { var i = name.lastIndexOf("./", 1); return i === 0 || (i === 1 && name.charCodeAt(0) === 46); } - function useBaseUrl(moduleName) { - return ts.getRootLength(moduleName) === 0 && !nameStartsWithDotSlashOrDotDotSlash(moduleName); - } function classicNameResolver(moduleName, containingFile, compilerOptions, host) { if (moduleName.indexOf('!') != -1) { - return { resolvedFileName: undefined, failedLookupLocations: [] }; + return { resolvedModule: undefined, failedLookupLocations: [] }; } var searchPath = ts.getDirectoryPath(containingFile); var searchName; @@ -29973,7 +29969,9 @@ var ts; } searchPath = parentPath; } - return { resolvedFileName: referencedSourceFile, failedLookupLocations: failedLookupLocations }; + return referencedSourceFile + ? { resolvedModule: { resolvedFileName: referencedSourceFile }, failedLookupLocations: failedLookupLocations } + : { resolvedModule: undefined, failedLookupLocations: failedLookupLocations }; } ts.classicNameResolver = classicNameResolver; ts.defaultInitCompilerOptions = { @@ -30086,7 +30084,8 @@ var ts; function createProgram(rootNames, options, host, oldProgram) { var program; var files = []; - var diagnostics = ts.createDiagnosticCollection(); + var fileProcessingDiagnostics = ts.createDiagnosticCollection(); + var programDiagnostics = ts.createDiagnosticCollection(); var commonSourceDirectory; var diagnosticsProducingTypeChecker; var noDiagnosticsTypeChecker; @@ -30094,8 +30093,9 @@ var ts; var skipDefaultLib = options.noLib; var start = new Date().getTime(); host = host || createCompilerHost(options); - var resolveModuleNamesWorker = host.resolveModuleNames || - (function (moduleNames, containingFile) { return ts.map(moduleNames, function (moduleName) { return resolveModuleName(moduleName, containingFile, options, host).resolvedFileName; }); }); + var resolveModuleNamesWorker = host.resolveModuleNames + ? (function (moduleNames, containingFile) { return host.resolveModuleNames(moduleNames, containingFile); }) + : (function (moduleNames, containingFile) { return ts.map(moduleNames, function (moduleName) { return resolveModuleName(moduleName, containingFile, options, host).resolvedModule; }); }); var filesByName = ts.createFileMap(function (fileName) { return host.getCanonicalFileName(fileName); }); if (oldProgram) { var oldOptions = oldProgram.getCompilerOptions(); @@ -30135,7 +30135,8 @@ var ts; getNodeCount: function () { return getDiagnosticsProducingTypeChecker().getNodeCount(); }, getIdentifierCount: function () { return getDiagnosticsProducingTypeChecker().getIdentifierCount(); }, getSymbolCount: function () { return getDiagnosticsProducingTypeChecker().getSymbolCount(); }, - getTypeCount: function () { return getDiagnosticsProducingTypeChecker().getTypeCount(); } + getTypeCount: function () { return getDiagnosticsProducingTypeChecker().getTypeCount(); }, + getFileProcessingDiagnostics: function () { return fileProcessingDiagnostics; } }; return program; function getClassifiableNames() { @@ -30159,6 +30160,7 @@ var ts; return false; } var newSourceFiles = []; + var modifiedSourceFiles = []; for (var _i = 0, _a = oldProgram.getSourceFiles(); _i < _a.length; _i++) { var oldSourceFile = _a[_i]; var newSourceFile = host.getSourceFile(oldSourceFile.fileName, options.target); @@ -30180,13 +30182,20 @@ var ts; var moduleNames = ts.map(newSourceFile.imports, function (name) { return name.text; }); var resolutions = resolveModuleNamesWorker(moduleNames, newSourceFile.fileName); for (var i = 0; i < moduleNames.length; ++i) { - var oldResolution = ts.getResolvedModuleFileName(oldSourceFile, moduleNames[i]); - if (oldResolution !== resolutions[i]) { + var newResolution = resolutions[i]; + var oldResolution = ts.getResolvedModule(oldSourceFile, moduleNames[i]); + var resolutionChanged = oldResolution + ? !newResolution || + oldResolution.resolvedFileName !== newResolution.resolvedFileName || + !!oldResolution.isExternalLibraryImport !== !!newResolution.isExternalLibraryImport + : newResolution; + if (resolutionChanged) { return false; } } } newSourceFile.resolvedModules = oldSourceFile.resolvedModules; + modifiedSourceFiles.push(newSourceFile); } else { newSourceFile = oldSourceFile; @@ -30198,6 +30207,11 @@ var ts; filesByName.set(file.fileName, file); } files = newSourceFiles; + fileProcessingDiagnostics = oldProgram.getFileProcessingDiagnostics(); + for (var _c = 0; _c < modifiedSourceFiles.length; _c++) { + var modifiedFile = modifiedSourceFiles[_c]; + fileProcessingDiagnostics.reattachFileDiagnostics(modifiedFile); + } oldProgram.structureIsReused = true; return true; } @@ -30279,8 +30293,9 @@ var ts; ts.Debug.assert(!!sourceFile.bindDiagnostics); var bindDiagnostics = sourceFile.bindDiagnostics; var checkDiagnostics = typeChecker.getDiagnostics(sourceFile, cancellationToken); - var programDiagnostics = diagnostics.getDiagnostics(sourceFile.fileName); - return bindDiagnostics.concat(checkDiagnostics).concat(programDiagnostics); + var fileProcessingDiagnosticsInFile = fileProcessingDiagnostics.getDiagnostics(sourceFile.fileName); + var programDiagnosticsInFile = programDiagnostics.getDiagnostics(sourceFile.fileName); + return bindDiagnostics.concat(checkDiagnostics).concat(fileProcessingDiagnosticsInFile).concat(programDiagnosticsInFile); }); } function getDeclarationDiagnosticsForFile(sourceFile, cancellationToken) { @@ -30294,7 +30309,8 @@ var ts; } function getOptionsDiagnostics() { var allDiagnostics = []; - ts.addRange(allDiagnostics, diagnostics.getGlobalDiagnostics()); + ts.addRange(allDiagnostics, fileProcessingDiagnostics.getGlobalDiagnostics()); + ts.addRange(allDiagnostics, programDiagnostics.getGlobalDiagnostics()); return ts.sortAndDeduplicateDiagnostics(allDiagnostics); } function getGlobalDiagnostics() { @@ -30384,10 +30400,10 @@ var ts; } if (diagnostic) { if (refFile !== undefined && refEnd !== undefined && refPos !== undefined) { - diagnostics.add(ts.createFileDiagnostic.apply(void 0, [refFile, refPos, refEnd - refPos, diagnostic].concat(diagnosticArgument))); + fileProcessingDiagnostics.add(ts.createFileDiagnostic.apply(void 0, [refFile, refPos, refEnd - refPos, diagnostic].concat(diagnosticArgument))); } else { - diagnostics.add(ts.createCompilerDiagnostic.apply(void 0, [diagnostic].concat(diagnosticArgument))); + fileProcessingDiagnostics.add(ts.createCompilerDiagnostic.apply(void 0, [diagnostic].concat(diagnosticArgument))); } } } @@ -30404,10 +30420,10 @@ var ts; } var file = host.getSourceFile(fileName, options.target, function (hostErrorMessage) { if (refFile !== undefined && refPos !== undefined && refEnd !== undefined) { - diagnostics.add(ts.createFileDiagnostic(refFile, refPos, refEnd - refPos, ts.Diagnostics.Cannot_read_file_0_Colon_1, fileName, hostErrorMessage)); + fileProcessingDiagnostics.add(ts.createFileDiagnostic(refFile, refPos, refEnd - refPos, ts.Diagnostics.Cannot_read_file_0_Colon_1, fileName, hostErrorMessage)); } else { - diagnostics.add(ts.createCompilerDiagnostic(ts.Diagnostics.Cannot_read_file_0_Colon_1, fileName, hostErrorMessage)); + fileProcessingDiagnostics.add(ts.createCompilerDiagnostic(ts.Diagnostics.Cannot_read_file_0_Colon_1, fileName, hostErrorMessage)); } }); filesByName.set(canonicalName, file); @@ -30435,10 +30451,10 @@ var ts; var sourceFileName = useAbsolutePath ? ts.getNormalizedAbsolutePath(file.fileName, host.getCurrentDirectory()) : file.fileName; if (canonicalName !== sourceFileName) { if (refFile !== undefined && refPos !== undefined && refEnd !== undefined) { - diagnostics.add(ts.createFileDiagnostic(refFile, refPos, refEnd - refPos, ts.Diagnostics.File_name_0_differs_from_already_included_file_name_1_only_in_casing, fileName, sourceFileName)); + fileProcessingDiagnostics.add(ts.createFileDiagnostic(refFile, refPos, refEnd - refPos, ts.Diagnostics.File_name_0_differs_from_already_included_file_name_1_only_in_casing, fileName, sourceFileName)); } else { - diagnostics.add(ts.createCompilerDiagnostic(ts.Diagnostics.File_name_0_differs_from_already_included_file_name_1_only_in_casing, fileName, sourceFileName)); + fileProcessingDiagnostics.add(ts.createCompilerDiagnostic(ts.Diagnostics.File_name_0_differs_from_already_included_file_name_1_only_in_casing, fileName, sourceFileName)); } } } @@ -30459,9 +30475,23 @@ var ts; var resolutions = resolveModuleNamesWorker(moduleNames, file.fileName); for (var i = 0; i < file.imports.length; ++i) { var resolution = resolutions[i]; - ts.setResolvedModuleName(file, moduleNames[i], resolution); + ts.setResolvedModule(file, moduleNames[i], resolution); if (resolution && !options.noResolve) { - findModuleSourceFile(resolution, file.imports[i]); + var importedFile = findModuleSourceFile(resolution.resolvedFileName, file.imports[i]); + if (importedFile && resolution.isExternalLibraryImport) { + if (!ts.isExternalModule(importedFile)) { + var start_2 = ts.getTokenPosOfNode(file.imports[i], file); + fileProcessingDiagnostics.add(ts.createFileDiagnostic(file, start_2, file.imports[i].end - start_2, ts.Diagnostics.File_0_is_not_a_module, importedFile.fileName)); + } + else if (!ts.fileExtensionIs(importedFile.fileName, ".d.ts")) { + var start_3 = ts.getTokenPosOfNode(file.imports[i], file); + fileProcessingDiagnostics.add(ts.createFileDiagnostic(file, start_3, file.imports[i].end - start_3, ts.Diagnostics.Exported_external_package_typings_can_only_be_in_d_ts_files_Please_contact_the_package_author_to_update_the_package_definition)); + } + else if (importedFile.referencedFiles.length) { + var firstRef = importedFile.referencedFiles[0]; + fileProcessingDiagnostics.add(ts.createFileDiagnostic(importedFile, firstRef.pos, firstRef.end - firstRef.pos, ts.Diagnostics.Exported_external_package_typings_file_cannot_contain_tripleslash_references_Please_contact_the_package_author_to_update_the_package_definition)); + } + } } } } @@ -30470,7 +30500,7 @@ var ts; } return; function findModuleSourceFile(fileName, nameLiteral) { - return findSourceFile(fileName, false, file, nameLiteral.pos, nameLiteral.end); + return findSourceFile(fileName, false, file, ts.skipTrivia(file.text, nameLiteral.pos), nameLiteral.end); } } function computeCommonSourceDirectory(sourceFiles) { @@ -30489,7 +30519,7 @@ var ts; for (var i = 0, n = Math.min(commonPathComponents.length, sourcePathComponents.length); i < n; i++) { if (commonPathComponents[i] !== sourcePathComponents[i]) { if (i === 0) { - diagnostics.add(ts.createCompilerDiagnostic(ts.Diagnostics.Cannot_find_the_common_subdirectory_path_for_the_input_files)); + programDiagnostics.add(ts.createCompilerDiagnostic(ts.Diagnostics.Cannot_find_the_common_subdirectory_path_for_the_input_files)); return; } commonPathComponents.length = i; @@ -30512,7 +30542,7 @@ var ts; if (!ts.isDeclarationFile(sourceFile)) { var absoluteSourceFilePath = host.getCanonicalFileName(ts.getNormalizedAbsolutePath(sourceFile.fileName, currentDirectory)); if (absoluteSourceFilePath.indexOf(absoluteRootDirectoryPath) !== 0) { - diagnostics.add(ts.createCompilerDiagnostic(ts.Diagnostics.File_0_is_not_under_rootDir_1_rootDir_is_expected_to_contain_all_source_files, sourceFile.fileName, options.rootDir)); + programDiagnostics.add(ts.createCompilerDiagnostic(ts.Diagnostics.File_0_is_not_under_rootDir_1_rootDir_is_expected_to_contain_all_source_files, sourceFile.fileName, options.rootDir)); allFilesBelongToPath = false; } } @@ -30523,43 +30553,43 @@ var ts; function verifyCompilerOptions() { if (options.isolatedModules) { if (options.declaration) { - diagnostics.add(ts.createCompilerDiagnostic(ts.Diagnostics.Option_0_cannot_be_specified_with_option_1, "declaration", "isolatedModules")); + programDiagnostics.add(ts.createCompilerDiagnostic(ts.Diagnostics.Option_0_cannot_be_specified_with_option_1, "declaration", "isolatedModules")); } if (options.noEmitOnError) { - diagnostics.add(ts.createCompilerDiagnostic(ts.Diagnostics.Option_0_cannot_be_specified_with_option_1, "noEmitOnError", "isolatedModules")); + programDiagnostics.add(ts.createCompilerDiagnostic(ts.Diagnostics.Option_0_cannot_be_specified_with_option_1, "noEmitOnError", "isolatedModules")); } if (options.out) { - diagnostics.add(ts.createCompilerDiagnostic(ts.Diagnostics.Option_0_cannot_be_specified_with_option_1, "out", "isolatedModules")); + programDiagnostics.add(ts.createCompilerDiagnostic(ts.Diagnostics.Option_0_cannot_be_specified_with_option_1, "out", "isolatedModules")); } if (options.outFile) { - diagnostics.add(ts.createCompilerDiagnostic(ts.Diagnostics.Option_0_cannot_be_specified_with_option_1, "outFile", "isolatedModules")); + programDiagnostics.add(ts.createCompilerDiagnostic(ts.Diagnostics.Option_0_cannot_be_specified_with_option_1, "outFile", "isolatedModules")); } } if (options.inlineSourceMap) { if (options.sourceMap) { - diagnostics.add(ts.createCompilerDiagnostic(ts.Diagnostics.Option_0_cannot_be_specified_with_option_1, "sourceMap", "inlineSourceMap")); + programDiagnostics.add(ts.createCompilerDiagnostic(ts.Diagnostics.Option_0_cannot_be_specified_with_option_1, "sourceMap", "inlineSourceMap")); } if (options.mapRoot) { - diagnostics.add(ts.createCompilerDiagnostic(ts.Diagnostics.Option_0_cannot_be_specified_with_option_1, "mapRoot", "inlineSourceMap")); + programDiagnostics.add(ts.createCompilerDiagnostic(ts.Diagnostics.Option_0_cannot_be_specified_with_option_1, "mapRoot", "inlineSourceMap")); } if (options.sourceRoot) { - diagnostics.add(ts.createCompilerDiagnostic(ts.Diagnostics.Option_0_cannot_be_specified_with_option_1, "sourceRoot", "inlineSourceMap")); + programDiagnostics.add(ts.createCompilerDiagnostic(ts.Diagnostics.Option_0_cannot_be_specified_with_option_1, "sourceRoot", "inlineSourceMap")); } } if (options.inlineSources) { if (!options.sourceMap && !options.inlineSourceMap) { - diagnostics.add(ts.createCompilerDiagnostic(ts.Diagnostics.Option_inlineSources_can_only_be_used_when_either_option_inlineSourceMap_or_option_sourceMap_is_provided)); + programDiagnostics.add(ts.createCompilerDiagnostic(ts.Diagnostics.Option_inlineSources_can_only_be_used_when_either_option_inlineSourceMap_or_option_sourceMap_is_provided)); } } if (options.out && options.outFile) { - diagnostics.add(ts.createCompilerDiagnostic(ts.Diagnostics.Option_0_cannot_be_specified_with_option_1, "out", "outFile")); + programDiagnostics.add(ts.createCompilerDiagnostic(ts.Diagnostics.Option_0_cannot_be_specified_with_option_1, "out", "outFile")); } if (!options.sourceMap && (options.mapRoot || options.sourceRoot)) { if (options.mapRoot) { - diagnostics.add(ts.createCompilerDiagnostic(ts.Diagnostics.Option_0_cannot_be_specified_without_specifying_option_1, "mapRoot", "sourceMap")); + programDiagnostics.add(ts.createCompilerDiagnostic(ts.Diagnostics.Option_0_cannot_be_specified_without_specifying_option_1, "mapRoot", "sourceMap")); } if (options.sourceRoot) { - diagnostics.add(ts.createCompilerDiagnostic(ts.Diagnostics.Option_0_cannot_be_specified_without_specifying_option_1, "sourceRoot", "sourceMap")); + programDiagnostics.add(ts.createCompilerDiagnostic(ts.Diagnostics.Option_0_cannot_be_specified_without_specifying_option_1, "sourceRoot", "sourceMap")); } return; } @@ -30568,20 +30598,20 @@ var ts; var firstExternalModuleSourceFile = ts.forEach(files, function (f) { return ts.isExternalModule(f) ? f : undefined; }); if (options.isolatedModules) { if (!options.module && languageVersion < 2) { - diagnostics.add(ts.createCompilerDiagnostic(ts.Diagnostics.Option_isolatedModules_can_only_be_used_when_either_option_module_is_provided_or_option_target_is_ES6_or_higher)); + programDiagnostics.add(ts.createCompilerDiagnostic(ts.Diagnostics.Option_isolatedModules_can_only_be_used_when_either_option_module_is_provided_or_option_target_is_ES6_or_higher)); } var firstNonExternalModuleSourceFile = ts.forEach(files, function (f) { return !ts.isExternalModule(f) && !ts.isDeclarationFile(f) ? f : undefined; }); if (firstNonExternalModuleSourceFile) { var span = ts.getErrorSpanForNode(firstNonExternalModuleSourceFile, firstNonExternalModuleSourceFile); - diagnostics.add(ts.createFileDiagnostic(firstNonExternalModuleSourceFile, span.start, span.length, ts.Diagnostics.Cannot_compile_namespaces_when_the_isolatedModules_flag_is_provided)); + programDiagnostics.add(ts.createFileDiagnostic(firstNonExternalModuleSourceFile, span.start, span.length, ts.Diagnostics.Cannot_compile_namespaces_when_the_isolatedModules_flag_is_provided)); } } else if (firstExternalModuleSourceFile && languageVersion < 2 && !options.module) { var span = ts.getErrorSpanForNode(firstExternalModuleSourceFile, firstExternalModuleSourceFile.externalModuleIndicator); - diagnostics.add(ts.createFileDiagnostic(firstExternalModuleSourceFile, span.start, span.length, ts.Diagnostics.Cannot_compile_modules_unless_the_module_flag_is_provided)); + programDiagnostics.add(ts.createFileDiagnostic(firstExternalModuleSourceFile, span.start, span.length, ts.Diagnostics.Cannot_compile_modules_unless_the_module_flag_is_provided)); } if (options.module && languageVersion >= 2) { - diagnostics.add(ts.createCompilerDiagnostic(ts.Diagnostics.Cannot_compile_modules_into_commonjs_amd_system_or_umd_when_targeting_ES6_or_higher)); + programDiagnostics.add(ts.createCompilerDiagnostic(ts.Diagnostics.Cannot_compile_modules_into_commonjs_amd_system_or_umd_when_targeting_ES6_or_higher)); } if (options.outDir || options.sourceRoot || @@ -30599,25 +30629,25 @@ var ts; } if (options.noEmit) { if (options.out) { - diagnostics.add(ts.createCompilerDiagnostic(ts.Diagnostics.Option_0_cannot_be_specified_with_option_1, "noEmit", "out")); + programDiagnostics.add(ts.createCompilerDiagnostic(ts.Diagnostics.Option_0_cannot_be_specified_with_option_1, "noEmit", "out")); } if (options.outFile) { - diagnostics.add(ts.createCompilerDiagnostic(ts.Diagnostics.Option_0_cannot_be_specified_with_option_1, "noEmit", "outFile")); + programDiagnostics.add(ts.createCompilerDiagnostic(ts.Diagnostics.Option_0_cannot_be_specified_with_option_1, "noEmit", "outFile")); } if (options.outDir) { - diagnostics.add(ts.createCompilerDiagnostic(ts.Diagnostics.Option_0_cannot_be_specified_with_option_1, "noEmit", "outDir")); + programDiagnostics.add(ts.createCompilerDiagnostic(ts.Diagnostics.Option_0_cannot_be_specified_with_option_1, "noEmit", "outDir")); } if (options.declaration) { - diagnostics.add(ts.createCompilerDiagnostic(ts.Diagnostics.Option_0_cannot_be_specified_with_option_1, "noEmit", "declaration")); + programDiagnostics.add(ts.createCompilerDiagnostic(ts.Diagnostics.Option_0_cannot_be_specified_with_option_1, "noEmit", "declaration")); } } if (options.emitDecoratorMetadata && !options.experimentalDecorators) { - diagnostics.add(ts.createCompilerDiagnostic(ts.Diagnostics.Option_0_cannot_be_specified_without_specifying_option_1, "emitDecoratorMetadata", "experimentalDecorators")); + programDiagnostics.add(ts.createCompilerDiagnostic(ts.Diagnostics.Option_0_cannot_be_specified_without_specifying_option_1, "emitDecoratorMetadata", "experimentalDecorators")); } if (options.experimentalAsyncFunctions && options.target !== 2) { - diagnostics.add(ts.createCompilerDiagnostic(ts.Diagnostics.Option_experimentalAsyncFunctions_cannot_be_specified_when_targeting_ES5_or_lower)); + programDiagnostics.add(ts.createCompilerDiagnostic(ts.Diagnostics.Option_experimentalAsyncFunctions_cannot_be_specified_when_targeting_ES5_or_lower)); } } } @@ -37213,9 +37243,9 @@ var ts; log("getCompletionData: Get previous token 1: " + (new Date().getTime() - start)); var contextToken = previousToken; if (contextToken && position <= contextToken.end && ts.isWord(contextToken.kind)) { - var start_2 = new Date().getTime(); + var start_4 = new Date().getTime(); contextToken = ts.findPrecedingToken(contextToken.getFullStart(), sourceFile); - log("getCompletionData: Get previous token 2: " + (new Date().getTime() - start_2)); + log("getCompletionData: Get previous token 2: " + (new Date().getTime() - start_4)); } var node = currentToken; var isRightOfDot = false; @@ -37410,9 +37440,9 @@ var ts; if (contextToken.kind === 9 || contextToken.kind === 10 || ts.isTemplateLiteralKind(contextToken.kind)) { - var start_3 = contextToken.getStart(); + var start_5 = contextToken.getStart(); var end = contextToken.getEnd(); - if (start_3 < position && position < end) { + if (start_5 < position && position < end) { return true; } if (position === end) { @@ -41760,7 +41790,7 @@ var ts; LSHost.prototype.resolveModuleNames = function (moduleNames, containingFile) { var currentResolutionsInFile = this.resolvedModuleNames.get(containingFile); var newResolutions = {}; - var resolvedFileNames = []; + var resolvedModules = []; var compilerOptions = this.getCompilationSettings(); for (var _i = 0; _i < moduleNames.length; _i++) { var moduleName = moduleNames[_i]; @@ -41777,15 +41807,15 @@ var ts; } } ts.Debug.assert(resolution !== undefined); - resolvedFileNames.push(resolution.resolvedFileName); + resolvedModules.push(resolution.resolvedModule); } this.resolvedModuleNames.set(containingFile, newResolutions); - return resolvedFileNames; + return resolvedModules; function moduleResolutionIsValid(resolution) { if (!resolution) { return false; } - if (resolution.resolvedFileName) { + if (resolution.resolvedModule) { return true; } return resolution.failedLookupLocations.length === 0; @@ -43749,7 +43779,10 @@ var ts; if ("getModuleResolutionsForFile" in this.shimHost) { this.resolveModuleNames = function (moduleNames, containingFile) { var resolutionsInFile = JSON.parse(_this.shimHost.getModuleResolutionsForFile(containingFile)); - return ts.map(moduleNames, function (name) { return ts.lookUp(resolutionsInFile, name); }); + return ts.map(moduleNames, function (name) { + var result = ts.lookUp(resolutionsInFile, name); + return result ? { resolvedFileName: result } : undefined; + }); }; } } @@ -44224,7 +44257,11 @@ var ts; var _this = this; return this.forwardJSONCall("resolveModuleName('" + fileName + "')", function () { var compilerOptions = JSON.parse(compilerOptionsJson); - return ts.resolveModuleName(moduleName, ts.normalizeSlashes(fileName), compilerOptions, _this.host); + var result = ts.resolveModuleName(moduleName, ts.normalizeSlashes(fileName), compilerOptions, _this.host); + return { + resolvedFileName: result.resolvedModule ? result.resolvedModule.resolvedFileName : undefined, + failedLookupLocations: result.failedLookupLocations + }; }); }; CoreServicesShimObject.prototype.getPreProcessedFileInfo = function (fileName, sourceTextSnapshot) { diff --git a/lib/typescript.d.ts b/lib/typescript.d.ts index 5e6492cfe1e..ec4ccd15589 100644 --- a/lib/typescript.d.ts +++ b/lib/typescript.d.ts @@ -1382,9 +1382,12 @@ declare namespace ts { } interface ResolvedModule { resolvedFileName: string; + isExternalLibraryImport?: boolean; + } + interface ResolvedModuleWithFailedLookupLocations { + resolvedModule: ResolvedModule; failedLookupLocations: string[]; } - type ModuleNameResolver = (moduleName: string, containingFile: string, options: CompilerOptions, host: ModuleResolutionHost) => ResolvedModule; interface CompilerHost extends ModuleResolutionHost { getSourceFile(fileName: string, languageVersion: ScriptTarget, onError?: (message: string) => void): SourceFile; getCancellationToken?(): CancellationToken; @@ -1394,7 +1397,7 @@ declare namespace ts { getCanonicalFileName(fileName: string): string; useCaseSensitiveFileNames(): boolean; getNewLine(): string; - resolveModuleNames?(moduleNames: string[], containingFile: string): string[]; + resolveModuleNames?(moduleNames: string[], containingFile: string): ResolvedModule[]; } interface TextSpan { start: number; @@ -1515,10 +1518,9 @@ declare namespace ts { const version: string; function findConfigFile(searchPath: string): string; function resolveTripleslashReference(moduleName: string, containingFile: string): string; - function resolveModuleName(moduleName: string, containingFile: string, compilerOptions: CompilerOptions, host: ModuleResolutionHost): ResolvedModule; - function nodeModuleNameResolver(moduleName: string, containingFile: string, host: ModuleResolutionHost): ResolvedModule; - function baseUrlModuleNameResolver(moduleName: string, containingFile: string, baseUrl: string, host: ModuleResolutionHost): ResolvedModule; - function classicNameResolver(moduleName: string, containingFile: string, compilerOptions: CompilerOptions, host: ModuleResolutionHost): ResolvedModule; + function resolveModuleName(moduleName: string, containingFile: string, compilerOptions: CompilerOptions, host: ModuleResolutionHost): ResolvedModuleWithFailedLookupLocations; + function nodeModuleNameResolver(moduleName: string, containingFile: string, host: ModuleResolutionHost): ResolvedModuleWithFailedLookupLocations; + function classicNameResolver(moduleName: string, containingFile: string, compilerOptions: CompilerOptions, host: ModuleResolutionHost): ResolvedModuleWithFailedLookupLocations; function createCompilerHost(options: CompilerOptions, setParentNodes?: boolean): CompilerHost; function getPreEmitDiagnostics(program: Program, sourceFile?: SourceFile, cancellationToken?: CancellationToken): Diagnostic[]; function flattenDiagnosticMessageText(messageText: string | DiagnosticMessageChain, newLine: string): string; @@ -1649,7 +1651,7 @@ declare namespace ts { trace?(s: string): void; error?(s: string): void; useCaseSensitiveFileNames?(): boolean; - resolveModuleNames?(moduleNames: string[], containingFile: string): string[]; + resolveModuleNames?(moduleNames: string[], containingFile: string): ResolvedModule[]; } interface LanguageService { cleanupSemanticCache(): void; diff --git a/lib/typescript.js b/lib/typescript.js index f6701d019cc..ebc0ba70357 100644 --- a/lib/typescript.js +++ b/lib/typescript.js @@ -2300,6 +2300,8 @@ var ts; Cannot_emit_namespaced_JSX_elements_in_React: { code: 2650, category: ts.DiagnosticCategory.Error, key: "Cannot emit namespaced JSX elements in React" }, A_member_initializer_in_a_enum_declaration_cannot_reference_members_declared_after_it_including_members_defined_in_other_enums: { code: 2651, category: ts.DiagnosticCategory.Error, key: "A member initializer in a enum declaration cannot reference members declared after it, including members defined in other enums." }, Merged_declaration_0_cannot_include_a_default_export_declaration_Consider_adding_a_separate_export_default_0_declaration_instead: { code: 2652, category: ts.DiagnosticCategory.Error, key: "Merged declaration '{0}' cannot include a default export declaration. Consider adding a separate 'export default {0}' declaration instead." }, + Exported_external_package_typings_file_cannot_contain_tripleslash_references_Please_contact_the_package_author_to_update_the_package_definition: { code: 2654, category: ts.DiagnosticCategory.Error, key: "Exported external package typings file cannot contain tripleslash references. Please contact the package author to update the package definition." }, + Exported_external_package_typings_can_only_be_in_d_ts_files_Please_contact_the_package_author_to_update_the_package_definition: { code: 2655, category: ts.DiagnosticCategory.Error, key: "Exported external package typings can only be in '.d.ts' files. Please contact the package author to update the package definition." }, Import_declaration_0_is_using_private_name_1: { code: 4000, category: ts.DiagnosticCategory.Error, key: "Import declaration '{0}' is using private name '{1}'." }, Type_parameter_0_of_exported_class_has_or_is_using_private_name_1: { code: 4002, category: ts.DiagnosticCategory.Error, key: "Type parameter '{0}' of exported class has or is using private name '{1}'." }, Type_parameter_0_of_exported_interface_has_or_is_using_private_name_1: { code: 4004, category: ts.DiagnosticCategory.Error, key: "Type parameter '{0}' of exported interface has or is using private name '{1}'." }, @@ -5012,21 +5014,21 @@ var ts; return true; } ts.arrayIsEqualTo = arrayIsEqualTo; - function hasResolvedModuleName(sourceFile, moduleNameText) { + function hasResolvedModule(sourceFile, moduleNameText) { return sourceFile.resolvedModules && ts.hasProperty(sourceFile.resolvedModules, moduleNameText); } - ts.hasResolvedModuleName = hasResolvedModuleName; - function getResolvedModuleFileName(sourceFile, moduleNameText) { - return hasResolvedModuleName(sourceFile, moduleNameText) ? sourceFile.resolvedModules[moduleNameText] : undefined; + ts.hasResolvedModule = hasResolvedModule; + function getResolvedModule(sourceFile, moduleNameText) { + return hasResolvedModule(sourceFile, moduleNameText) ? sourceFile.resolvedModules[moduleNameText] : undefined; } - ts.getResolvedModuleFileName = getResolvedModuleFileName; - function setResolvedModuleName(sourceFile, moduleNameText, resolvedFileName) { + ts.getResolvedModule = getResolvedModule; + function setResolvedModule(sourceFile, moduleNameText, resolvedModule) { if (!sourceFile.resolvedModules) { sourceFile.resolvedModules = {}; } - sourceFile.resolvedModules[moduleNameText] = resolvedFileName; + sourceFile.resolvedModules[moduleNameText] = resolvedModule; } - ts.setResolvedModuleName = setResolvedModuleName; + ts.setResolvedModule = setResolvedModule; // Returns true if this node contains a parse error anywhere underneath it. function containsParseError(node) { aggregateChildData(node); @@ -6363,11 +6365,21 @@ var ts; add: add, getGlobalDiagnostics: getGlobalDiagnostics, getDiagnostics: getDiagnostics, - getModificationCount: getModificationCount + getModificationCount: getModificationCount, + reattachFileDiagnostics: reattachFileDiagnostics }; function getModificationCount() { return modificationCount; } + function reattachFileDiagnostics(newFile) { + if (!ts.hasProperty(fileDiagnostics, newFile.fileName)) { + return; + } + for (var _i = 0, _a = fileDiagnostics[newFile.fileName]; _i < _a.length; _i++) { + var diagnostic = _a[_i]; + diagnostic.file = newFile; + } + } function add(diagnostic) { var diagnostics; if (diagnostic.file) { @@ -13745,8 +13757,8 @@ var ts; return symbol; } } - var fileName = ts.getResolvedModuleFileName(getSourceFile(location), moduleReferenceLiteral.text); - var sourceFile = fileName && host.getSourceFile(fileName); + var resolvedModule = ts.getResolvedModule(getSourceFile(location), moduleReferenceLiteral.text); + var sourceFile = resolvedModule && host.getSourceFile(resolvedModule.resolvedFileName); if (sourceFile) { if (sourceFile.symbol) { return sourceFile.symbol; @@ -31225,6 +31237,9 @@ var ts; } function emitExportSpecifierInSystemModule(specifier) { ts.Debug.assert(compilerOptions.module === 4 /* System */); + if (!resolver.getReferencedValueDeclaration(specifier.propertyName || specifier.name) && !resolver.isValueAliasDeclaration(specifier)) { + return; + } writeLine(); emitStart(specifier.name); write(exportFunctionForFile + "(\""); @@ -33896,7 +33911,7 @@ var ts; } return; } - if (ts.isInternalModuleImportEqualsDeclaration(node)) { + if (ts.isInternalModuleImportEqualsDeclaration(node) && resolver.isValueAliasDeclaration(node)) { if (!hoistedVars) { hoistedVars = []; } @@ -35164,10 +35179,12 @@ var ts; var candidate = ts.normalizePath(ts.combinePaths(containingDirectory, moduleName)); var resolvedFileName = loadNodeModuleFromFile(candidate, /* loadOnlyDts */ false, failedLookupLocations, host); if (resolvedFileName) { - return { resolvedFileName: resolvedFileName, failedLookupLocations: failedLookupLocations }; + return { resolvedModule: { resolvedFileName: resolvedFileName }, failedLookupLocations: failedLookupLocations }; } resolvedFileName = loadNodeModuleFromDirectory(candidate, /* loadOnlyDts */ false, failedLookupLocations, host); - return { resolvedFileName: resolvedFileName, failedLookupLocations: failedLookupLocations }; + return resolvedFileName + ? { resolvedModule: { resolvedFileName: resolvedFileName }, failedLookupLocations: failedLookupLocations } + : { resolvedModule: undefined, failedLookupLocations: failedLookupLocations }; } else { return loadModuleFromNodeModules(moduleName, containingDirectory, host); @@ -35227,11 +35244,11 @@ var ts; var candidate = ts.normalizePath(ts.combinePaths(nodeModulesFolder, moduleName)); var result = loadNodeModuleFromFile(candidate, /* loadOnlyDts */ true, failedLookupLocations, host); if (result) { - return { resolvedFileName: result, failedLookupLocations: failedLookupLocations }; + return { resolvedModule: { resolvedFileName: result, isExternalLibraryImport: true }, failedLookupLocations: failedLookupLocations }; } result = loadNodeModuleFromDirectory(candidate, /* loadOnlyDts */ true, failedLookupLocations, host); if (result) { - return { resolvedFileName: result, failedLookupLocations: failedLookupLocations }; + return { resolvedModule: { resolvedFileName: result, isExternalLibraryImport: true }, failedLookupLocations: failedLookupLocations }; } } var parentPath = ts.getDirectoryPath(directory); @@ -35240,39 +35257,16 @@ var ts; } directory = parentPath; } - return { resolvedFileName: undefined, failedLookupLocations: failedLookupLocations }; + return { resolvedModule: undefined, failedLookupLocations: failedLookupLocations }; } - function baseUrlModuleNameResolver(moduleName, containingFile, baseUrl, host) { - ts.Debug.assert(baseUrl !== undefined); - var normalizedModuleName = ts.normalizeSlashes(moduleName); - var basePart = useBaseUrl(moduleName) ? baseUrl : ts.getDirectoryPath(containingFile); - var candidate = ts.normalizePath(ts.combinePaths(basePart, moduleName)); - var failedLookupLocations = []; - return ts.forEach(ts.supportedExtensions, function (ext) { return tryLoadFile(candidate + ext); }) || { resolvedFileName: undefined, failedLookupLocations: failedLookupLocations }; - function tryLoadFile(location) { - if (host.fileExists(location)) { - return { resolvedFileName: location, failedLookupLocations: failedLookupLocations }; - } - else { - failedLookupLocations.push(location); - return undefined; - } - } - } - ts.baseUrlModuleNameResolver = baseUrlModuleNameResolver; function nameStartsWithDotSlashOrDotDotSlash(name) { var i = name.lastIndexOf("./", 1); return i === 0 || (i === 1 && name.charCodeAt(0) === 46 /* dot */); } - function useBaseUrl(moduleName) { - // path is not rooted - // module name does not start with './' or '../' - return ts.getRootLength(moduleName) === 0 && !nameStartsWithDotSlashOrDotDotSlash(moduleName); - } function classicNameResolver(moduleName, containingFile, compilerOptions, host) { // module names that contain '!' are used to reference resources and are not resolved to actual files on disk if (moduleName.indexOf('!') != -1) { - return { resolvedFileName: undefined, failedLookupLocations: [] }; + return { resolvedModule: undefined, failedLookupLocations: [] }; } var searchPath = ts.getDirectoryPath(containingFile); var searchName; @@ -35303,7 +35297,9 @@ var ts; } searchPath = parentPath; } - return { resolvedFileName: referencedSourceFile, failedLookupLocations: failedLookupLocations }; + return referencedSourceFile + ? { resolvedModule: { resolvedFileName: referencedSourceFile }, failedLookupLocations: failedLookupLocations } + : { resolvedModule: undefined, failedLookupLocations: failedLookupLocations }; } ts.classicNameResolver = classicNameResolver; /* @internal */ @@ -35420,7 +35416,8 @@ var ts; function createProgram(rootNames, options, host, oldProgram) { var program; var files = []; - var diagnostics = ts.createDiagnosticCollection(); + var fileProcessingDiagnostics = ts.createDiagnosticCollection(); + var programDiagnostics = ts.createDiagnosticCollection(); var commonSourceDirectory; var diagnosticsProducingTypeChecker; var noDiagnosticsTypeChecker; @@ -35428,8 +35425,9 @@ var ts; var skipDefaultLib = options.noLib; var start = new Date().getTime(); host = host || createCompilerHost(options); - var resolveModuleNamesWorker = host.resolveModuleNames || - (function (moduleNames, containingFile) { return ts.map(moduleNames, function (moduleName) { return resolveModuleName(moduleName, containingFile, options, host).resolvedFileName; }); }); + var resolveModuleNamesWorker = host.resolveModuleNames + ? (function (moduleNames, containingFile) { return host.resolveModuleNames(moduleNames, containingFile); }) + : (function (moduleNames, containingFile) { return ts.map(moduleNames, function (moduleName) { return resolveModuleName(moduleName, containingFile, options, host).resolvedModule; }); }); var filesByName = ts.createFileMap(function (fileName) { return host.getCanonicalFileName(fileName); }); if (oldProgram) { // check properties that can affect structure of the program or module resolution strategy @@ -35476,7 +35474,8 @@ var ts; getNodeCount: function () { return getDiagnosticsProducingTypeChecker().getNodeCount(); }, getIdentifierCount: function () { return getDiagnosticsProducingTypeChecker().getIdentifierCount(); }, getSymbolCount: function () { return getDiagnosticsProducingTypeChecker().getSymbolCount(); }, - getTypeCount: function () { return getDiagnosticsProducingTypeChecker().getTypeCount(); } + getTypeCount: function () { return getDiagnosticsProducingTypeChecker().getTypeCount(); }, + getFileProcessingDiagnostics: function () { return fileProcessingDiagnostics; } }; return program; function getClassifiableNames() { @@ -35503,6 +35502,7 @@ var ts; } // check if program source files has changed in the way that can affect structure of the program var newSourceFiles = []; + var modifiedSourceFiles = []; for (var _i = 0, _a = oldProgram.getSourceFiles(); _i < _a.length; _i++) { var oldSourceFile = _a[_i]; var newSourceFile = host.getSourceFile(oldSourceFile.fileName, options.target); @@ -35531,14 +35531,21 @@ var ts; var resolutions = resolveModuleNamesWorker(moduleNames, newSourceFile.fileName); // ensure that module resolution results are still correct for (var i = 0; i < moduleNames.length; ++i) { - var oldResolution = ts.getResolvedModuleFileName(oldSourceFile, moduleNames[i]); - if (oldResolution !== resolutions[i]) { + var newResolution = resolutions[i]; + var oldResolution = ts.getResolvedModule(oldSourceFile, moduleNames[i]); + var resolutionChanged = oldResolution + ? !newResolution || + oldResolution.resolvedFileName !== newResolution.resolvedFileName || + !!oldResolution.isExternalLibraryImport !== !!newResolution.isExternalLibraryImport + : newResolution; + if (resolutionChanged) { return false; } } } // pass the cache of module resolutions from the old source file newSourceFile.resolvedModules = oldSourceFile.resolvedModules; + modifiedSourceFiles.push(newSourceFile); } else { // file has no changes - use it as is @@ -35553,6 +35560,11 @@ var ts; filesByName.set(file.fileName, file); } files = newSourceFiles; + fileProcessingDiagnostics = oldProgram.getFileProcessingDiagnostics(); + for (var _c = 0; _c < modifiedSourceFiles.length; _c++) { + var modifiedFile = modifiedSourceFiles[_c]; + fileProcessingDiagnostics.reattachFileDiagnostics(modifiedFile); + } oldProgram.structureIsReused = true; return true; } @@ -35654,8 +35666,9 @@ var ts; ts.Debug.assert(!!sourceFile.bindDiagnostics); var bindDiagnostics = sourceFile.bindDiagnostics; var checkDiagnostics = typeChecker.getDiagnostics(sourceFile, cancellationToken); - var programDiagnostics = diagnostics.getDiagnostics(sourceFile.fileName); - return bindDiagnostics.concat(checkDiagnostics).concat(programDiagnostics); + var fileProcessingDiagnosticsInFile = fileProcessingDiagnostics.getDiagnostics(sourceFile.fileName); + var programDiagnosticsInFile = programDiagnostics.getDiagnostics(sourceFile.fileName); + return bindDiagnostics.concat(checkDiagnostics).concat(fileProcessingDiagnosticsInFile).concat(programDiagnosticsInFile); }); } function getDeclarationDiagnosticsForFile(sourceFile, cancellationToken) { @@ -35670,7 +35683,8 @@ var ts; } function getOptionsDiagnostics() { var allDiagnostics = []; - ts.addRange(allDiagnostics, diagnostics.getGlobalDiagnostics()); + ts.addRange(allDiagnostics, fileProcessingDiagnostics.getGlobalDiagnostics()); + ts.addRange(allDiagnostics, programDiagnostics.getGlobalDiagnostics()); return ts.sortAndDeduplicateDiagnostics(allDiagnostics); } function getGlobalDiagnostics() { @@ -35768,10 +35782,10 @@ var ts; } if (diagnostic) { if (refFile !== undefined && refEnd !== undefined && refPos !== undefined) { - diagnostics.add(ts.createFileDiagnostic.apply(void 0, [refFile, refPos, refEnd - refPos, diagnostic].concat(diagnosticArgument))); + fileProcessingDiagnostics.add(ts.createFileDiagnostic.apply(void 0, [refFile, refPos, refEnd - refPos, diagnostic].concat(diagnosticArgument))); } else { - diagnostics.add(ts.createCompilerDiagnostic.apply(void 0, [diagnostic].concat(diagnosticArgument))); + fileProcessingDiagnostics.add(ts.createCompilerDiagnostic.apply(void 0, [diagnostic].concat(diagnosticArgument))); } } } @@ -35791,10 +35805,10 @@ var ts; // We haven't looked for this file, do so now and cache result var file = host.getSourceFile(fileName, options.target, function (hostErrorMessage) { if (refFile !== undefined && refPos !== undefined && refEnd !== undefined) { - diagnostics.add(ts.createFileDiagnostic(refFile, refPos, refEnd - refPos, ts.Diagnostics.Cannot_read_file_0_Colon_1, fileName, hostErrorMessage)); + fileProcessingDiagnostics.add(ts.createFileDiagnostic(refFile, refPos, refEnd - refPos, ts.Diagnostics.Cannot_read_file_0_Colon_1, fileName, hostErrorMessage)); } else { - diagnostics.add(ts.createCompilerDiagnostic(ts.Diagnostics.Cannot_read_file_0_Colon_1, fileName, hostErrorMessage)); + fileProcessingDiagnostics.add(ts.createCompilerDiagnostic(ts.Diagnostics.Cannot_read_file_0_Colon_1, fileName, hostErrorMessage)); } }); filesByName.set(canonicalName, file); @@ -35824,10 +35838,10 @@ var ts; var sourceFileName = useAbsolutePath ? ts.getNormalizedAbsolutePath(file.fileName, host.getCurrentDirectory()) : file.fileName; if (canonicalName !== sourceFileName) { if (refFile !== undefined && refPos !== undefined && refEnd !== undefined) { - diagnostics.add(ts.createFileDiagnostic(refFile, refPos, refEnd - refPos, ts.Diagnostics.File_name_0_differs_from_already_included_file_name_1_only_in_casing, fileName, sourceFileName)); + fileProcessingDiagnostics.add(ts.createFileDiagnostic(refFile, refPos, refEnd - refPos, ts.Diagnostics.File_name_0_differs_from_already_included_file_name_1_only_in_casing, fileName, sourceFileName)); } else { - diagnostics.add(ts.createCompilerDiagnostic(ts.Diagnostics.File_name_0_differs_from_already_included_file_name_1_only_in_casing, fileName, sourceFileName)); + fileProcessingDiagnostics.add(ts.createCompilerDiagnostic(ts.Diagnostics.File_name_0_differs_from_already_included_file_name_1_only_in_casing, fileName, sourceFileName)); } } } @@ -35848,9 +35862,23 @@ var ts; var resolutions = resolveModuleNamesWorker(moduleNames, file.fileName); for (var i = 0; i < file.imports.length; ++i) { var resolution = resolutions[i]; - ts.setResolvedModuleName(file, moduleNames[i], resolution); + ts.setResolvedModule(file, moduleNames[i], resolution); if (resolution && !options.noResolve) { - findModuleSourceFile(resolution, file.imports[i]); + var importedFile = findModuleSourceFile(resolution.resolvedFileName, file.imports[i]); + if (importedFile && resolution.isExternalLibraryImport) { + if (!ts.isExternalModule(importedFile)) { + var start_2 = ts.getTokenPosOfNode(file.imports[i], file); + fileProcessingDiagnostics.add(ts.createFileDiagnostic(file, start_2, file.imports[i].end - start_2, ts.Diagnostics.File_0_is_not_a_module, importedFile.fileName)); + } + else if (!ts.fileExtensionIs(importedFile.fileName, ".d.ts")) { + var start_3 = ts.getTokenPosOfNode(file.imports[i], file); + fileProcessingDiagnostics.add(ts.createFileDiagnostic(file, start_3, file.imports[i].end - start_3, ts.Diagnostics.Exported_external_package_typings_can_only_be_in_d_ts_files_Please_contact_the_package_author_to_update_the_package_definition)); + } + else if (importedFile.referencedFiles.length) { + var firstRef = importedFile.referencedFiles[0]; + fileProcessingDiagnostics.add(ts.createFileDiagnostic(importedFile, firstRef.pos, firstRef.end - firstRef.pos, ts.Diagnostics.Exported_external_package_typings_file_cannot_contain_tripleslash_references_Please_contact_the_package_author_to_update_the_package_definition)); + } + } } } } @@ -35860,7 +35888,7 @@ var ts; } return; function findModuleSourceFile(fileName, nameLiteral) { - return findSourceFile(fileName, /* isDefaultLib */ false, file, nameLiteral.pos, nameLiteral.end); + return findSourceFile(fileName, /* isDefaultLib */ false, file, ts.skipTrivia(file.text, nameLiteral.pos), nameLiteral.end); } } function computeCommonSourceDirectory(sourceFiles) { @@ -35881,7 +35909,7 @@ var ts; for (var i = 0, n = Math.min(commonPathComponents.length, sourcePathComponents.length); i < n; i++) { if (commonPathComponents[i] !== sourcePathComponents[i]) { if (i === 0) { - diagnostics.add(ts.createCompilerDiagnostic(ts.Diagnostics.Cannot_find_the_common_subdirectory_path_for_the_input_files)); + programDiagnostics.add(ts.createCompilerDiagnostic(ts.Diagnostics.Cannot_find_the_common_subdirectory_path_for_the_input_files)); return; } // New common path found that is 0 -> i-1 @@ -35906,7 +35934,7 @@ var ts; if (!ts.isDeclarationFile(sourceFile)) { var absoluteSourceFilePath = host.getCanonicalFileName(ts.getNormalizedAbsolutePath(sourceFile.fileName, currentDirectory)); if (absoluteSourceFilePath.indexOf(absoluteRootDirectoryPath) !== 0) { - diagnostics.add(ts.createCompilerDiagnostic(ts.Diagnostics.File_0_is_not_under_rootDir_1_rootDir_is_expected_to_contain_all_source_files, sourceFile.fileName, options.rootDir)); + programDiagnostics.add(ts.createCompilerDiagnostic(ts.Diagnostics.File_0_is_not_under_rootDir_1_rootDir_is_expected_to_contain_all_source_files, sourceFile.fileName, options.rootDir)); allFilesBelongToPath = false; } } @@ -35917,44 +35945,44 @@ var ts; function verifyCompilerOptions() { if (options.isolatedModules) { if (options.declaration) { - diagnostics.add(ts.createCompilerDiagnostic(ts.Diagnostics.Option_0_cannot_be_specified_with_option_1, "declaration", "isolatedModules")); + programDiagnostics.add(ts.createCompilerDiagnostic(ts.Diagnostics.Option_0_cannot_be_specified_with_option_1, "declaration", "isolatedModules")); } if (options.noEmitOnError) { - diagnostics.add(ts.createCompilerDiagnostic(ts.Diagnostics.Option_0_cannot_be_specified_with_option_1, "noEmitOnError", "isolatedModules")); + programDiagnostics.add(ts.createCompilerDiagnostic(ts.Diagnostics.Option_0_cannot_be_specified_with_option_1, "noEmitOnError", "isolatedModules")); } if (options.out) { - diagnostics.add(ts.createCompilerDiagnostic(ts.Diagnostics.Option_0_cannot_be_specified_with_option_1, "out", "isolatedModules")); + programDiagnostics.add(ts.createCompilerDiagnostic(ts.Diagnostics.Option_0_cannot_be_specified_with_option_1, "out", "isolatedModules")); } if (options.outFile) { - diagnostics.add(ts.createCompilerDiagnostic(ts.Diagnostics.Option_0_cannot_be_specified_with_option_1, "outFile", "isolatedModules")); + programDiagnostics.add(ts.createCompilerDiagnostic(ts.Diagnostics.Option_0_cannot_be_specified_with_option_1, "outFile", "isolatedModules")); } } if (options.inlineSourceMap) { if (options.sourceMap) { - diagnostics.add(ts.createCompilerDiagnostic(ts.Diagnostics.Option_0_cannot_be_specified_with_option_1, "sourceMap", "inlineSourceMap")); + programDiagnostics.add(ts.createCompilerDiagnostic(ts.Diagnostics.Option_0_cannot_be_specified_with_option_1, "sourceMap", "inlineSourceMap")); } if (options.mapRoot) { - diagnostics.add(ts.createCompilerDiagnostic(ts.Diagnostics.Option_0_cannot_be_specified_with_option_1, "mapRoot", "inlineSourceMap")); + programDiagnostics.add(ts.createCompilerDiagnostic(ts.Diagnostics.Option_0_cannot_be_specified_with_option_1, "mapRoot", "inlineSourceMap")); } if (options.sourceRoot) { - diagnostics.add(ts.createCompilerDiagnostic(ts.Diagnostics.Option_0_cannot_be_specified_with_option_1, "sourceRoot", "inlineSourceMap")); + programDiagnostics.add(ts.createCompilerDiagnostic(ts.Diagnostics.Option_0_cannot_be_specified_with_option_1, "sourceRoot", "inlineSourceMap")); } } if (options.inlineSources) { if (!options.sourceMap && !options.inlineSourceMap) { - diagnostics.add(ts.createCompilerDiagnostic(ts.Diagnostics.Option_inlineSources_can_only_be_used_when_either_option_inlineSourceMap_or_option_sourceMap_is_provided)); + programDiagnostics.add(ts.createCompilerDiagnostic(ts.Diagnostics.Option_inlineSources_can_only_be_used_when_either_option_inlineSourceMap_or_option_sourceMap_is_provided)); } } if (options.out && options.outFile) { - diagnostics.add(ts.createCompilerDiagnostic(ts.Diagnostics.Option_0_cannot_be_specified_with_option_1, "out", "outFile")); + programDiagnostics.add(ts.createCompilerDiagnostic(ts.Diagnostics.Option_0_cannot_be_specified_with_option_1, "out", "outFile")); } if (!options.sourceMap && (options.mapRoot || options.sourceRoot)) { // Error to specify --mapRoot or --sourceRoot without mapSourceFiles if (options.mapRoot) { - diagnostics.add(ts.createCompilerDiagnostic(ts.Diagnostics.Option_0_cannot_be_specified_without_specifying_option_1, "mapRoot", "sourceMap")); + programDiagnostics.add(ts.createCompilerDiagnostic(ts.Diagnostics.Option_0_cannot_be_specified_without_specifying_option_1, "mapRoot", "sourceMap")); } if (options.sourceRoot) { - diagnostics.add(ts.createCompilerDiagnostic(ts.Diagnostics.Option_0_cannot_be_specified_without_specifying_option_1, "sourceRoot", "sourceMap")); + programDiagnostics.add(ts.createCompilerDiagnostic(ts.Diagnostics.Option_0_cannot_be_specified_without_specifying_option_1, "sourceRoot", "sourceMap")); } return; } @@ -35963,22 +35991,22 @@ var ts; var firstExternalModuleSourceFile = ts.forEach(files, function (f) { return ts.isExternalModule(f) ? f : undefined; }); if (options.isolatedModules) { if (!options.module && languageVersion < 2 /* ES6 */) { - diagnostics.add(ts.createCompilerDiagnostic(ts.Diagnostics.Option_isolatedModules_can_only_be_used_when_either_option_module_is_provided_or_option_target_is_ES6_or_higher)); + programDiagnostics.add(ts.createCompilerDiagnostic(ts.Diagnostics.Option_isolatedModules_can_only_be_used_when_either_option_module_is_provided_or_option_target_is_ES6_or_higher)); } var firstNonExternalModuleSourceFile = ts.forEach(files, function (f) { return !ts.isExternalModule(f) && !ts.isDeclarationFile(f) ? f : undefined; }); if (firstNonExternalModuleSourceFile) { var span = ts.getErrorSpanForNode(firstNonExternalModuleSourceFile, firstNonExternalModuleSourceFile); - diagnostics.add(ts.createFileDiagnostic(firstNonExternalModuleSourceFile, span.start, span.length, ts.Diagnostics.Cannot_compile_namespaces_when_the_isolatedModules_flag_is_provided)); + programDiagnostics.add(ts.createFileDiagnostic(firstNonExternalModuleSourceFile, span.start, span.length, ts.Diagnostics.Cannot_compile_namespaces_when_the_isolatedModules_flag_is_provided)); } } else if (firstExternalModuleSourceFile && languageVersion < 2 /* ES6 */ && !options.module) { // We cannot use createDiagnosticFromNode because nodes do not have parents yet var span = ts.getErrorSpanForNode(firstExternalModuleSourceFile, firstExternalModuleSourceFile.externalModuleIndicator); - diagnostics.add(ts.createFileDiagnostic(firstExternalModuleSourceFile, span.start, span.length, ts.Diagnostics.Cannot_compile_modules_unless_the_module_flag_is_provided)); + programDiagnostics.add(ts.createFileDiagnostic(firstExternalModuleSourceFile, span.start, span.length, ts.Diagnostics.Cannot_compile_modules_unless_the_module_flag_is_provided)); } // Cannot specify module gen target when in es6 or above if (options.module && languageVersion >= 2 /* ES6 */) { - diagnostics.add(ts.createCompilerDiagnostic(ts.Diagnostics.Cannot_compile_modules_into_commonjs_amd_system_or_umd_when_targeting_ES6_or_higher)); + programDiagnostics.add(ts.createCompilerDiagnostic(ts.Diagnostics.Cannot_compile_modules_into_commonjs_amd_system_or_umd_when_targeting_ES6_or_higher)); } // there has to be common source directory if user specified --outdir || --sourceRoot // if user specified --mapRoot, there needs to be common source directory if there would be multiple files being emitted @@ -36003,25 +36031,25 @@ var ts; } if (options.noEmit) { if (options.out) { - diagnostics.add(ts.createCompilerDiagnostic(ts.Diagnostics.Option_0_cannot_be_specified_with_option_1, "noEmit", "out")); + programDiagnostics.add(ts.createCompilerDiagnostic(ts.Diagnostics.Option_0_cannot_be_specified_with_option_1, "noEmit", "out")); } if (options.outFile) { - diagnostics.add(ts.createCompilerDiagnostic(ts.Diagnostics.Option_0_cannot_be_specified_with_option_1, "noEmit", "outFile")); + programDiagnostics.add(ts.createCompilerDiagnostic(ts.Diagnostics.Option_0_cannot_be_specified_with_option_1, "noEmit", "outFile")); } if (options.outDir) { - diagnostics.add(ts.createCompilerDiagnostic(ts.Diagnostics.Option_0_cannot_be_specified_with_option_1, "noEmit", "outDir")); + programDiagnostics.add(ts.createCompilerDiagnostic(ts.Diagnostics.Option_0_cannot_be_specified_with_option_1, "noEmit", "outDir")); } if (options.declaration) { - diagnostics.add(ts.createCompilerDiagnostic(ts.Diagnostics.Option_0_cannot_be_specified_with_option_1, "noEmit", "declaration")); + programDiagnostics.add(ts.createCompilerDiagnostic(ts.Diagnostics.Option_0_cannot_be_specified_with_option_1, "noEmit", "declaration")); } } if (options.emitDecoratorMetadata && !options.experimentalDecorators) { - diagnostics.add(ts.createCompilerDiagnostic(ts.Diagnostics.Option_0_cannot_be_specified_without_specifying_option_1, "emitDecoratorMetadata", "experimentalDecorators")); + programDiagnostics.add(ts.createCompilerDiagnostic(ts.Diagnostics.Option_0_cannot_be_specified_without_specifying_option_1, "emitDecoratorMetadata", "experimentalDecorators")); } if (options.experimentalAsyncFunctions && options.target !== 2 /* ES6 */) { - diagnostics.add(ts.createCompilerDiagnostic(ts.Diagnostics.Option_experimentalAsyncFunctions_cannot_be_specified_when_targeting_ES5_or_lower)); + programDiagnostics.add(ts.createCompilerDiagnostic(ts.Diagnostics.Option_experimentalAsyncFunctions_cannot_be_specified_when_targeting_ES5_or_lower)); } } } @@ -44003,9 +44031,9 @@ var ts; // Check if the caret is at the end of an identifier; this is a partial identifier that we want to complete: e.g. a.toS| // Skip this partial identifier and adjust the contextToken to the token that precedes it. if (contextToken && position <= contextToken.end && ts.isWord(contextToken.kind)) { - var start_2 = new Date().getTime(); + var start_4 = new Date().getTime(); contextToken = ts.findPrecedingToken(contextToken.getFullStart(), sourceFile); - log("getCompletionData: Get previous token 2: " + (new Date().getTime() - start_2)); + log("getCompletionData: Get previous token 2: " + (new Date().getTime() - start_4)); } // Find the node where completion is requested on. // Also determine whether we are trying to complete with members of that node @@ -44253,13 +44281,13 @@ var ts; if (contextToken.kind === 9 /* StringLiteral */ || contextToken.kind === 10 /* RegularExpressionLiteral */ || ts.isTemplateLiteralKind(contextToken.kind)) { - var start_3 = contextToken.getStart(); + var start_5 = contextToken.getStart(); var end = contextToken.getEnd(); // To be "in" one of these literals, the position has to be: // 1. entirely within the token text. // 2. at the end position of an unterminated token. // 3. at the end of a regular expression (due to trailing flags like '/foo/g'). - if (start_3 < position && position < end) { + if (start_5 < position && position < end) { return true; } if (position === end) { @@ -48631,7 +48659,10 @@ var ts; if ("getModuleResolutionsForFile" in this.shimHost) { this.resolveModuleNames = function (moduleNames, containingFile) { var resolutionsInFile = JSON.parse(_this.shimHost.getModuleResolutionsForFile(containingFile)); - return ts.map(moduleNames, function (name) { return ts.lookUp(resolutionsInFile, name); }); + return ts.map(moduleNames, function (name) { + var result = ts.lookUp(resolutionsInFile, name); + return result ? { resolvedFileName: result } : undefined; + }); }; } } @@ -49178,7 +49209,11 @@ var ts; var _this = this; return this.forwardJSONCall("resolveModuleName('" + fileName + "')", function () { var compilerOptions = JSON.parse(compilerOptionsJson); - return ts.resolveModuleName(moduleName, ts.normalizeSlashes(fileName), compilerOptions, _this.host); + var result = ts.resolveModuleName(moduleName, ts.normalizeSlashes(fileName), compilerOptions, _this.host); + return { + resolvedFileName: result.resolvedModule ? result.resolvedModule.resolvedFileName : undefined, + failedLookupLocations: result.failedLookupLocations + }; }); }; CoreServicesShimObject.prototype.getPreProcessedFileInfo = function (fileName, sourceTextSnapshot) { diff --git a/lib/typescriptServices.d.ts b/lib/typescriptServices.d.ts index 3d4418a9750..4ce3cd34cb5 100644 --- a/lib/typescriptServices.d.ts +++ b/lib/typescriptServices.d.ts @@ -1382,9 +1382,12 @@ declare namespace ts { } interface ResolvedModule { resolvedFileName: string; + isExternalLibraryImport?: boolean; + } + interface ResolvedModuleWithFailedLookupLocations { + resolvedModule: ResolvedModule; failedLookupLocations: string[]; } - type ModuleNameResolver = (moduleName: string, containingFile: string, options: CompilerOptions, host: ModuleResolutionHost) => ResolvedModule; interface CompilerHost extends ModuleResolutionHost { getSourceFile(fileName: string, languageVersion: ScriptTarget, onError?: (message: string) => void): SourceFile; getCancellationToken?(): CancellationToken; @@ -1394,7 +1397,7 @@ declare namespace ts { getCanonicalFileName(fileName: string): string; useCaseSensitiveFileNames(): boolean; getNewLine(): string; - resolveModuleNames?(moduleNames: string[], containingFile: string): string[]; + resolveModuleNames?(moduleNames: string[], containingFile: string): ResolvedModule[]; } interface TextSpan { start: number; @@ -1515,10 +1518,9 @@ declare namespace ts { const version: string; function findConfigFile(searchPath: string): string; function resolveTripleslashReference(moduleName: string, containingFile: string): string; - function resolveModuleName(moduleName: string, containingFile: string, compilerOptions: CompilerOptions, host: ModuleResolutionHost): ResolvedModule; - function nodeModuleNameResolver(moduleName: string, containingFile: string, host: ModuleResolutionHost): ResolvedModule; - function baseUrlModuleNameResolver(moduleName: string, containingFile: string, baseUrl: string, host: ModuleResolutionHost): ResolvedModule; - function classicNameResolver(moduleName: string, containingFile: string, compilerOptions: CompilerOptions, host: ModuleResolutionHost): ResolvedModule; + function resolveModuleName(moduleName: string, containingFile: string, compilerOptions: CompilerOptions, host: ModuleResolutionHost): ResolvedModuleWithFailedLookupLocations; + function nodeModuleNameResolver(moduleName: string, containingFile: string, host: ModuleResolutionHost): ResolvedModuleWithFailedLookupLocations; + function classicNameResolver(moduleName: string, containingFile: string, compilerOptions: CompilerOptions, host: ModuleResolutionHost): ResolvedModuleWithFailedLookupLocations; function createCompilerHost(options: CompilerOptions, setParentNodes?: boolean): CompilerHost; function getPreEmitDiagnostics(program: Program, sourceFile?: SourceFile, cancellationToken?: CancellationToken): Diagnostic[]; function flattenDiagnosticMessageText(messageText: string | DiagnosticMessageChain, newLine: string): string; @@ -1649,7 +1651,7 @@ declare namespace ts { trace?(s: string): void; error?(s: string): void; useCaseSensitiveFileNames?(): boolean; - resolveModuleNames?(moduleNames: string[], containingFile: string): string[]; + resolveModuleNames?(moduleNames: string[], containingFile: string): ResolvedModule[]; } interface LanguageService { cleanupSemanticCache(): void; diff --git a/lib/typescriptServices.js b/lib/typescriptServices.js index f6701d019cc..ebc0ba70357 100644 --- a/lib/typescriptServices.js +++ b/lib/typescriptServices.js @@ -2300,6 +2300,8 @@ var ts; Cannot_emit_namespaced_JSX_elements_in_React: { code: 2650, category: ts.DiagnosticCategory.Error, key: "Cannot emit namespaced JSX elements in React" }, A_member_initializer_in_a_enum_declaration_cannot_reference_members_declared_after_it_including_members_defined_in_other_enums: { code: 2651, category: ts.DiagnosticCategory.Error, key: "A member initializer in a enum declaration cannot reference members declared after it, including members defined in other enums." }, Merged_declaration_0_cannot_include_a_default_export_declaration_Consider_adding_a_separate_export_default_0_declaration_instead: { code: 2652, category: ts.DiagnosticCategory.Error, key: "Merged declaration '{0}' cannot include a default export declaration. Consider adding a separate 'export default {0}' declaration instead." }, + Exported_external_package_typings_file_cannot_contain_tripleslash_references_Please_contact_the_package_author_to_update_the_package_definition: { code: 2654, category: ts.DiagnosticCategory.Error, key: "Exported external package typings file cannot contain tripleslash references. Please contact the package author to update the package definition." }, + Exported_external_package_typings_can_only_be_in_d_ts_files_Please_contact_the_package_author_to_update_the_package_definition: { code: 2655, category: ts.DiagnosticCategory.Error, key: "Exported external package typings can only be in '.d.ts' files. Please contact the package author to update the package definition." }, Import_declaration_0_is_using_private_name_1: { code: 4000, category: ts.DiagnosticCategory.Error, key: "Import declaration '{0}' is using private name '{1}'." }, Type_parameter_0_of_exported_class_has_or_is_using_private_name_1: { code: 4002, category: ts.DiagnosticCategory.Error, key: "Type parameter '{0}' of exported class has or is using private name '{1}'." }, Type_parameter_0_of_exported_interface_has_or_is_using_private_name_1: { code: 4004, category: ts.DiagnosticCategory.Error, key: "Type parameter '{0}' of exported interface has or is using private name '{1}'." }, @@ -5012,21 +5014,21 @@ var ts; return true; } ts.arrayIsEqualTo = arrayIsEqualTo; - function hasResolvedModuleName(sourceFile, moduleNameText) { + function hasResolvedModule(sourceFile, moduleNameText) { return sourceFile.resolvedModules && ts.hasProperty(sourceFile.resolvedModules, moduleNameText); } - ts.hasResolvedModuleName = hasResolvedModuleName; - function getResolvedModuleFileName(sourceFile, moduleNameText) { - return hasResolvedModuleName(sourceFile, moduleNameText) ? sourceFile.resolvedModules[moduleNameText] : undefined; + ts.hasResolvedModule = hasResolvedModule; + function getResolvedModule(sourceFile, moduleNameText) { + return hasResolvedModule(sourceFile, moduleNameText) ? sourceFile.resolvedModules[moduleNameText] : undefined; } - ts.getResolvedModuleFileName = getResolvedModuleFileName; - function setResolvedModuleName(sourceFile, moduleNameText, resolvedFileName) { + ts.getResolvedModule = getResolvedModule; + function setResolvedModule(sourceFile, moduleNameText, resolvedModule) { if (!sourceFile.resolvedModules) { sourceFile.resolvedModules = {}; } - sourceFile.resolvedModules[moduleNameText] = resolvedFileName; + sourceFile.resolvedModules[moduleNameText] = resolvedModule; } - ts.setResolvedModuleName = setResolvedModuleName; + ts.setResolvedModule = setResolvedModule; // Returns true if this node contains a parse error anywhere underneath it. function containsParseError(node) { aggregateChildData(node); @@ -6363,11 +6365,21 @@ var ts; add: add, getGlobalDiagnostics: getGlobalDiagnostics, getDiagnostics: getDiagnostics, - getModificationCount: getModificationCount + getModificationCount: getModificationCount, + reattachFileDiagnostics: reattachFileDiagnostics }; function getModificationCount() { return modificationCount; } + function reattachFileDiagnostics(newFile) { + if (!ts.hasProperty(fileDiagnostics, newFile.fileName)) { + return; + } + for (var _i = 0, _a = fileDiagnostics[newFile.fileName]; _i < _a.length; _i++) { + var diagnostic = _a[_i]; + diagnostic.file = newFile; + } + } function add(diagnostic) { var diagnostics; if (diagnostic.file) { @@ -13745,8 +13757,8 @@ var ts; return symbol; } } - var fileName = ts.getResolvedModuleFileName(getSourceFile(location), moduleReferenceLiteral.text); - var sourceFile = fileName && host.getSourceFile(fileName); + var resolvedModule = ts.getResolvedModule(getSourceFile(location), moduleReferenceLiteral.text); + var sourceFile = resolvedModule && host.getSourceFile(resolvedModule.resolvedFileName); if (sourceFile) { if (sourceFile.symbol) { return sourceFile.symbol; @@ -31225,6 +31237,9 @@ var ts; } function emitExportSpecifierInSystemModule(specifier) { ts.Debug.assert(compilerOptions.module === 4 /* System */); + if (!resolver.getReferencedValueDeclaration(specifier.propertyName || specifier.name) && !resolver.isValueAliasDeclaration(specifier)) { + return; + } writeLine(); emitStart(specifier.name); write(exportFunctionForFile + "(\""); @@ -33896,7 +33911,7 @@ var ts; } return; } - if (ts.isInternalModuleImportEqualsDeclaration(node)) { + if (ts.isInternalModuleImportEqualsDeclaration(node) && resolver.isValueAliasDeclaration(node)) { if (!hoistedVars) { hoistedVars = []; } @@ -35164,10 +35179,12 @@ var ts; var candidate = ts.normalizePath(ts.combinePaths(containingDirectory, moduleName)); var resolvedFileName = loadNodeModuleFromFile(candidate, /* loadOnlyDts */ false, failedLookupLocations, host); if (resolvedFileName) { - return { resolvedFileName: resolvedFileName, failedLookupLocations: failedLookupLocations }; + return { resolvedModule: { resolvedFileName: resolvedFileName }, failedLookupLocations: failedLookupLocations }; } resolvedFileName = loadNodeModuleFromDirectory(candidate, /* loadOnlyDts */ false, failedLookupLocations, host); - return { resolvedFileName: resolvedFileName, failedLookupLocations: failedLookupLocations }; + return resolvedFileName + ? { resolvedModule: { resolvedFileName: resolvedFileName }, failedLookupLocations: failedLookupLocations } + : { resolvedModule: undefined, failedLookupLocations: failedLookupLocations }; } else { return loadModuleFromNodeModules(moduleName, containingDirectory, host); @@ -35227,11 +35244,11 @@ var ts; var candidate = ts.normalizePath(ts.combinePaths(nodeModulesFolder, moduleName)); var result = loadNodeModuleFromFile(candidate, /* loadOnlyDts */ true, failedLookupLocations, host); if (result) { - return { resolvedFileName: result, failedLookupLocations: failedLookupLocations }; + return { resolvedModule: { resolvedFileName: result, isExternalLibraryImport: true }, failedLookupLocations: failedLookupLocations }; } result = loadNodeModuleFromDirectory(candidate, /* loadOnlyDts */ true, failedLookupLocations, host); if (result) { - return { resolvedFileName: result, failedLookupLocations: failedLookupLocations }; + return { resolvedModule: { resolvedFileName: result, isExternalLibraryImport: true }, failedLookupLocations: failedLookupLocations }; } } var parentPath = ts.getDirectoryPath(directory); @@ -35240,39 +35257,16 @@ var ts; } directory = parentPath; } - return { resolvedFileName: undefined, failedLookupLocations: failedLookupLocations }; + return { resolvedModule: undefined, failedLookupLocations: failedLookupLocations }; } - function baseUrlModuleNameResolver(moduleName, containingFile, baseUrl, host) { - ts.Debug.assert(baseUrl !== undefined); - var normalizedModuleName = ts.normalizeSlashes(moduleName); - var basePart = useBaseUrl(moduleName) ? baseUrl : ts.getDirectoryPath(containingFile); - var candidate = ts.normalizePath(ts.combinePaths(basePart, moduleName)); - var failedLookupLocations = []; - return ts.forEach(ts.supportedExtensions, function (ext) { return tryLoadFile(candidate + ext); }) || { resolvedFileName: undefined, failedLookupLocations: failedLookupLocations }; - function tryLoadFile(location) { - if (host.fileExists(location)) { - return { resolvedFileName: location, failedLookupLocations: failedLookupLocations }; - } - else { - failedLookupLocations.push(location); - return undefined; - } - } - } - ts.baseUrlModuleNameResolver = baseUrlModuleNameResolver; function nameStartsWithDotSlashOrDotDotSlash(name) { var i = name.lastIndexOf("./", 1); return i === 0 || (i === 1 && name.charCodeAt(0) === 46 /* dot */); } - function useBaseUrl(moduleName) { - // path is not rooted - // module name does not start with './' or '../' - return ts.getRootLength(moduleName) === 0 && !nameStartsWithDotSlashOrDotDotSlash(moduleName); - } function classicNameResolver(moduleName, containingFile, compilerOptions, host) { // module names that contain '!' are used to reference resources and are not resolved to actual files on disk if (moduleName.indexOf('!') != -1) { - return { resolvedFileName: undefined, failedLookupLocations: [] }; + return { resolvedModule: undefined, failedLookupLocations: [] }; } var searchPath = ts.getDirectoryPath(containingFile); var searchName; @@ -35303,7 +35297,9 @@ var ts; } searchPath = parentPath; } - return { resolvedFileName: referencedSourceFile, failedLookupLocations: failedLookupLocations }; + return referencedSourceFile + ? { resolvedModule: { resolvedFileName: referencedSourceFile }, failedLookupLocations: failedLookupLocations } + : { resolvedModule: undefined, failedLookupLocations: failedLookupLocations }; } ts.classicNameResolver = classicNameResolver; /* @internal */ @@ -35420,7 +35416,8 @@ var ts; function createProgram(rootNames, options, host, oldProgram) { var program; var files = []; - var diagnostics = ts.createDiagnosticCollection(); + var fileProcessingDiagnostics = ts.createDiagnosticCollection(); + var programDiagnostics = ts.createDiagnosticCollection(); var commonSourceDirectory; var diagnosticsProducingTypeChecker; var noDiagnosticsTypeChecker; @@ -35428,8 +35425,9 @@ var ts; var skipDefaultLib = options.noLib; var start = new Date().getTime(); host = host || createCompilerHost(options); - var resolveModuleNamesWorker = host.resolveModuleNames || - (function (moduleNames, containingFile) { return ts.map(moduleNames, function (moduleName) { return resolveModuleName(moduleName, containingFile, options, host).resolvedFileName; }); }); + var resolveModuleNamesWorker = host.resolveModuleNames + ? (function (moduleNames, containingFile) { return host.resolveModuleNames(moduleNames, containingFile); }) + : (function (moduleNames, containingFile) { return ts.map(moduleNames, function (moduleName) { return resolveModuleName(moduleName, containingFile, options, host).resolvedModule; }); }); var filesByName = ts.createFileMap(function (fileName) { return host.getCanonicalFileName(fileName); }); if (oldProgram) { // check properties that can affect structure of the program or module resolution strategy @@ -35476,7 +35474,8 @@ var ts; getNodeCount: function () { return getDiagnosticsProducingTypeChecker().getNodeCount(); }, getIdentifierCount: function () { return getDiagnosticsProducingTypeChecker().getIdentifierCount(); }, getSymbolCount: function () { return getDiagnosticsProducingTypeChecker().getSymbolCount(); }, - getTypeCount: function () { return getDiagnosticsProducingTypeChecker().getTypeCount(); } + getTypeCount: function () { return getDiagnosticsProducingTypeChecker().getTypeCount(); }, + getFileProcessingDiagnostics: function () { return fileProcessingDiagnostics; } }; return program; function getClassifiableNames() { @@ -35503,6 +35502,7 @@ var ts; } // check if program source files has changed in the way that can affect structure of the program var newSourceFiles = []; + var modifiedSourceFiles = []; for (var _i = 0, _a = oldProgram.getSourceFiles(); _i < _a.length; _i++) { var oldSourceFile = _a[_i]; var newSourceFile = host.getSourceFile(oldSourceFile.fileName, options.target); @@ -35531,14 +35531,21 @@ var ts; var resolutions = resolveModuleNamesWorker(moduleNames, newSourceFile.fileName); // ensure that module resolution results are still correct for (var i = 0; i < moduleNames.length; ++i) { - var oldResolution = ts.getResolvedModuleFileName(oldSourceFile, moduleNames[i]); - if (oldResolution !== resolutions[i]) { + var newResolution = resolutions[i]; + var oldResolution = ts.getResolvedModule(oldSourceFile, moduleNames[i]); + var resolutionChanged = oldResolution + ? !newResolution || + oldResolution.resolvedFileName !== newResolution.resolvedFileName || + !!oldResolution.isExternalLibraryImport !== !!newResolution.isExternalLibraryImport + : newResolution; + if (resolutionChanged) { return false; } } } // pass the cache of module resolutions from the old source file newSourceFile.resolvedModules = oldSourceFile.resolvedModules; + modifiedSourceFiles.push(newSourceFile); } else { // file has no changes - use it as is @@ -35553,6 +35560,11 @@ var ts; filesByName.set(file.fileName, file); } files = newSourceFiles; + fileProcessingDiagnostics = oldProgram.getFileProcessingDiagnostics(); + for (var _c = 0; _c < modifiedSourceFiles.length; _c++) { + var modifiedFile = modifiedSourceFiles[_c]; + fileProcessingDiagnostics.reattachFileDiagnostics(modifiedFile); + } oldProgram.structureIsReused = true; return true; } @@ -35654,8 +35666,9 @@ var ts; ts.Debug.assert(!!sourceFile.bindDiagnostics); var bindDiagnostics = sourceFile.bindDiagnostics; var checkDiagnostics = typeChecker.getDiagnostics(sourceFile, cancellationToken); - var programDiagnostics = diagnostics.getDiagnostics(sourceFile.fileName); - return bindDiagnostics.concat(checkDiagnostics).concat(programDiagnostics); + var fileProcessingDiagnosticsInFile = fileProcessingDiagnostics.getDiagnostics(sourceFile.fileName); + var programDiagnosticsInFile = programDiagnostics.getDiagnostics(sourceFile.fileName); + return bindDiagnostics.concat(checkDiagnostics).concat(fileProcessingDiagnosticsInFile).concat(programDiagnosticsInFile); }); } function getDeclarationDiagnosticsForFile(sourceFile, cancellationToken) { @@ -35670,7 +35683,8 @@ var ts; } function getOptionsDiagnostics() { var allDiagnostics = []; - ts.addRange(allDiagnostics, diagnostics.getGlobalDiagnostics()); + ts.addRange(allDiagnostics, fileProcessingDiagnostics.getGlobalDiagnostics()); + ts.addRange(allDiagnostics, programDiagnostics.getGlobalDiagnostics()); return ts.sortAndDeduplicateDiagnostics(allDiagnostics); } function getGlobalDiagnostics() { @@ -35768,10 +35782,10 @@ var ts; } if (diagnostic) { if (refFile !== undefined && refEnd !== undefined && refPos !== undefined) { - diagnostics.add(ts.createFileDiagnostic.apply(void 0, [refFile, refPos, refEnd - refPos, diagnostic].concat(diagnosticArgument))); + fileProcessingDiagnostics.add(ts.createFileDiagnostic.apply(void 0, [refFile, refPos, refEnd - refPos, diagnostic].concat(diagnosticArgument))); } else { - diagnostics.add(ts.createCompilerDiagnostic.apply(void 0, [diagnostic].concat(diagnosticArgument))); + fileProcessingDiagnostics.add(ts.createCompilerDiagnostic.apply(void 0, [diagnostic].concat(diagnosticArgument))); } } } @@ -35791,10 +35805,10 @@ var ts; // We haven't looked for this file, do so now and cache result var file = host.getSourceFile(fileName, options.target, function (hostErrorMessage) { if (refFile !== undefined && refPos !== undefined && refEnd !== undefined) { - diagnostics.add(ts.createFileDiagnostic(refFile, refPos, refEnd - refPos, ts.Diagnostics.Cannot_read_file_0_Colon_1, fileName, hostErrorMessage)); + fileProcessingDiagnostics.add(ts.createFileDiagnostic(refFile, refPos, refEnd - refPos, ts.Diagnostics.Cannot_read_file_0_Colon_1, fileName, hostErrorMessage)); } else { - diagnostics.add(ts.createCompilerDiagnostic(ts.Diagnostics.Cannot_read_file_0_Colon_1, fileName, hostErrorMessage)); + fileProcessingDiagnostics.add(ts.createCompilerDiagnostic(ts.Diagnostics.Cannot_read_file_0_Colon_1, fileName, hostErrorMessage)); } }); filesByName.set(canonicalName, file); @@ -35824,10 +35838,10 @@ var ts; var sourceFileName = useAbsolutePath ? ts.getNormalizedAbsolutePath(file.fileName, host.getCurrentDirectory()) : file.fileName; if (canonicalName !== sourceFileName) { if (refFile !== undefined && refPos !== undefined && refEnd !== undefined) { - diagnostics.add(ts.createFileDiagnostic(refFile, refPos, refEnd - refPos, ts.Diagnostics.File_name_0_differs_from_already_included_file_name_1_only_in_casing, fileName, sourceFileName)); + fileProcessingDiagnostics.add(ts.createFileDiagnostic(refFile, refPos, refEnd - refPos, ts.Diagnostics.File_name_0_differs_from_already_included_file_name_1_only_in_casing, fileName, sourceFileName)); } else { - diagnostics.add(ts.createCompilerDiagnostic(ts.Diagnostics.File_name_0_differs_from_already_included_file_name_1_only_in_casing, fileName, sourceFileName)); + fileProcessingDiagnostics.add(ts.createCompilerDiagnostic(ts.Diagnostics.File_name_0_differs_from_already_included_file_name_1_only_in_casing, fileName, sourceFileName)); } } } @@ -35848,9 +35862,23 @@ var ts; var resolutions = resolveModuleNamesWorker(moduleNames, file.fileName); for (var i = 0; i < file.imports.length; ++i) { var resolution = resolutions[i]; - ts.setResolvedModuleName(file, moduleNames[i], resolution); + ts.setResolvedModule(file, moduleNames[i], resolution); if (resolution && !options.noResolve) { - findModuleSourceFile(resolution, file.imports[i]); + var importedFile = findModuleSourceFile(resolution.resolvedFileName, file.imports[i]); + if (importedFile && resolution.isExternalLibraryImport) { + if (!ts.isExternalModule(importedFile)) { + var start_2 = ts.getTokenPosOfNode(file.imports[i], file); + fileProcessingDiagnostics.add(ts.createFileDiagnostic(file, start_2, file.imports[i].end - start_2, ts.Diagnostics.File_0_is_not_a_module, importedFile.fileName)); + } + else if (!ts.fileExtensionIs(importedFile.fileName, ".d.ts")) { + var start_3 = ts.getTokenPosOfNode(file.imports[i], file); + fileProcessingDiagnostics.add(ts.createFileDiagnostic(file, start_3, file.imports[i].end - start_3, ts.Diagnostics.Exported_external_package_typings_can_only_be_in_d_ts_files_Please_contact_the_package_author_to_update_the_package_definition)); + } + else if (importedFile.referencedFiles.length) { + var firstRef = importedFile.referencedFiles[0]; + fileProcessingDiagnostics.add(ts.createFileDiagnostic(importedFile, firstRef.pos, firstRef.end - firstRef.pos, ts.Diagnostics.Exported_external_package_typings_file_cannot_contain_tripleslash_references_Please_contact_the_package_author_to_update_the_package_definition)); + } + } } } } @@ -35860,7 +35888,7 @@ var ts; } return; function findModuleSourceFile(fileName, nameLiteral) { - return findSourceFile(fileName, /* isDefaultLib */ false, file, nameLiteral.pos, nameLiteral.end); + return findSourceFile(fileName, /* isDefaultLib */ false, file, ts.skipTrivia(file.text, nameLiteral.pos), nameLiteral.end); } } function computeCommonSourceDirectory(sourceFiles) { @@ -35881,7 +35909,7 @@ var ts; for (var i = 0, n = Math.min(commonPathComponents.length, sourcePathComponents.length); i < n; i++) { if (commonPathComponents[i] !== sourcePathComponents[i]) { if (i === 0) { - diagnostics.add(ts.createCompilerDiagnostic(ts.Diagnostics.Cannot_find_the_common_subdirectory_path_for_the_input_files)); + programDiagnostics.add(ts.createCompilerDiagnostic(ts.Diagnostics.Cannot_find_the_common_subdirectory_path_for_the_input_files)); return; } // New common path found that is 0 -> i-1 @@ -35906,7 +35934,7 @@ var ts; if (!ts.isDeclarationFile(sourceFile)) { var absoluteSourceFilePath = host.getCanonicalFileName(ts.getNormalizedAbsolutePath(sourceFile.fileName, currentDirectory)); if (absoluteSourceFilePath.indexOf(absoluteRootDirectoryPath) !== 0) { - diagnostics.add(ts.createCompilerDiagnostic(ts.Diagnostics.File_0_is_not_under_rootDir_1_rootDir_is_expected_to_contain_all_source_files, sourceFile.fileName, options.rootDir)); + programDiagnostics.add(ts.createCompilerDiagnostic(ts.Diagnostics.File_0_is_not_under_rootDir_1_rootDir_is_expected_to_contain_all_source_files, sourceFile.fileName, options.rootDir)); allFilesBelongToPath = false; } } @@ -35917,44 +35945,44 @@ var ts; function verifyCompilerOptions() { if (options.isolatedModules) { if (options.declaration) { - diagnostics.add(ts.createCompilerDiagnostic(ts.Diagnostics.Option_0_cannot_be_specified_with_option_1, "declaration", "isolatedModules")); + programDiagnostics.add(ts.createCompilerDiagnostic(ts.Diagnostics.Option_0_cannot_be_specified_with_option_1, "declaration", "isolatedModules")); } if (options.noEmitOnError) { - diagnostics.add(ts.createCompilerDiagnostic(ts.Diagnostics.Option_0_cannot_be_specified_with_option_1, "noEmitOnError", "isolatedModules")); + programDiagnostics.add(ts.createCompilerDiagnostic(ts.Diagnostics.Option_0_cannot_be_specified_with_option_1, "noEmitOnError", "isolatedModules")); } if (options.out) { - diagnostics.add(ts.createCompilerDiagnostic(ts.Diagnostics.Option_0_cannot_be_specified_with_option_1, "out", "isolatedModules")); + programDiagnostics.add(ts.createCompilerDiagnostic(ts.Diagnostics.Option_0_cannot_be_specified_with_option_1, "out", "isolatedModules")); } if (options.outFile) { - diagnostics.add(ts.createCompilerDiagnostic(ts.Diagnostics.Option_0_cannot_be_specified_with_option_1, "outFile", "isolatedModules")); + programDiagnostics.add(ts.createCompilerDiagnostic(ts.Diagnostics.Option_0_cannot_be_specified_with_option_1, "outFile", "isolatedModules")); } } if (options.inlineSourceMap) { if (options.sourceMap) { - diagnostics.add(ts.createCompilerDiagnostic(ts.Diagnostics.Option_0_cannot_be_specified_with_option_1, "sourceMap", "inlineSourceMap")); + programDiagnostics.add(ts.createCompilerDiagnostic(ts.Diagnostics.Option_0_cannot_be_specified_with_option_1, "sourceMap", "inlineSourceMap")); } if (options.mapRoot) { - diagnostics.add(ts.createCompilerDiagnostic(ts.Diagnostics.Option_0_cannot_be_specified_with_option_1, "mapRoot", "inlineSourceMap")); + programDiagnostics.add(ts.createCompilerDiagnostic(ts.Diagnostics.Option_0_cannot_be_specified_with_option_1, "mapRoot", "inlineSourceMap")); } if (options.sourceRoot) { - diagnostics.add(ts.createCompilerDiagnostic(ts.Diagnostics.Option_0_cannot_be_specified_with_option_1, "sourceRoot", "inlineSourceMap")); + programDiagnostics.add(ts.createCompilerDiagnostic(ts.Diagnostics.Option_0_cannot_be_specified_with_option_1, "sourceRoot", "inlineSourceMap")); } } if (options.inlineSources) { if (!options.sourceMap && !options.inlineSourceMap) { - diagnostics.add(ts.createCompilerDiagnostic(ts.Diagnostics.Option_inlineSources_can_only_be_used_when_either_option_inlineSourceMap_or_option_sourceMap_is_provided)); + programDiagnostics.add(ts.createCompilerDiagnostic(ts.Diagnostics.Option_inlineSources_can_only_be_used_when_either_option_inlineSourceMap_or_option_sourceMap_is_provided)); } } if (options.out && options.outFile) { - diagnostics.add(ts.createCompilerDiagnostic(ts.Diagnostics.Option_0_cannot_be_specified_with_option_1, "out", "outFile")); + programDiagnostics.add(ts.createCompilerDiagnostic(ts.Diagnostics.Option_0_cannot_be_specified_with_option_1, "out", "outFile")); } if (!options.sourceMap && (options.mapRoot || options.sourceRoot)) { // Error to specify --mapRoot or --sourceRoot without mapSourceFiles if (options.mapRoot) { - diagnostics.add(ts.createCompilerDiagnostic(ts.Diagnostics.Option_0_cannot_be_specified_without_specifying_option_1, "mapRoot", "sourceMap")); + programDiagnostics.add(ts.createCompilerDiagnostic(ts.Diagnostics.Option_0_cannot_be_specified_without_specifying_option_1, "mapRoot", "sourceMap")); } if (options.sourceRoot) { - diagnostics.add(ts.createCompilerDiagnostic(ts.Diagnostics.Option_0_cannot_be_specified_without_specifying_option_1, "sourceRoot", "sourceMap")); + programDiagnostics.add(ts.createCompilerDiagnostic(ts.Diagnostics.Option_0_cannot_be_specified_without_specifying_option_1, "sourceRoot", "sourceMap")); } return; } @@ -35963,22 +35991,22 @@ var ts; var firstExternalModuleSourceFile = ts.forEach(files, function (f) { return ts.isExternalModule(f) ? f : undefined; }); if (options.isolatedModules) { if (!options.module && languageVersion < 2 /* ES6 */) { - diagnostics.add(ts.createCompilerDiagnostic(ts.Diagnostics.Option_isolatedModules_can_only_be_used_when_either_option_module_is_provided_or_option_target_is_ES6_or_higher)); + programDiagnostics.add(ts.createCompilerDiagnostic(ts.Diagnostics.Option_isolatedModules_can_only_be_used_when_either_option_module_is_provided_or_option_target_is_ES6_or_higher)); } var firstNonExternalModuleSourceFile = ts.forEach(files, function (f) { return !ts.isExternalModule(f) && !ts.isDeclarationFile(f) ? f : undefined; }); if (firstNonExternalModuleSourceFile) { var span = ts.getErrorSpanForNode(firstNonExternalModuleSourceFile, firstNonExternalModuleSourceFile); - diagnostics.add(ts.createFileDiagnostic(firstNonExternalModuleSourceFile, span.start, span.length, ts.Diagnostics.Cannot_compile_namespaces_when_the_isolatedModules_flag_is_provided)); + programDiagnostics.add(ts.createFileDiagnostic(firstNonExternalModuleSourceFile, span.start, span.length, ts.Diagnostics.Cannot_compile_namespaces_when_the_isolatedModules_flag_is_provided)); } } else if (firstExternalModuleSourceFile && languageVersion < 2 /* ES6 */ && !options.module) { // We cannot use createDiagnosticFromNode because nodes do not have parents yet var span = ts.getErrorSpanForNode(firstExternalModuleSourceFile, firstExternalModuleSourceFile.externalModuleIndicator); - diagnostics.add(ts.createFileDiagnostic(firstExternalModuleSourceFile, span.start, span.length, ts.Diagnostics.Cannot_compile_modules_unless_the_module_flag_is_provided)); + programDiagnostics.add(ts.createFileDiagnostic(firstExternalModuleSourceFile, span.start, span.length, ts.Diagnostics.Cannot_compile_modules_unless_the_module_flag_is_provided)); } // Cannot specify module gen target when in es6 or above if (options.module && languageVersion >= 2 /* ES6 */) { - diagnostics.add(ts.createCompilerDiagnostic(ts.Diagnostics.Cannot_compile_modules_into_commonjs_amd_system_or_umd_when_targeting_ES6_or_higher)); + programDiagnostics.add(ts.createCompilerDiagnostic(ts.Diagnostics.Cannot_compile_modules_into_commonjs_amd_system_or_umd_when_targeting_ES6_or_higher)); } // there has to be common source directory if user specified --outdir || --sourceRoot // if user specified --mapRoot, there needs to be common source directory if there would be multiple files being emitted @@ -36003,25 +36031,25 @@ var ts; } if (options.noEmit) { if (options.out) { - diagnostics.add(ts.createCompilerDiagnostic(ts.Diagnostics.Option_0_cannot_be_specified_with_option_1, "noEmit", "out")); + programDiagnostics.add(ts.createCompilerDiagnostic(ts.Diagnostics.Option_0_cannot_be_specified_with_option_1, "noEmit", "out")); } if (options.outFile) { - diagnostics.add(ts.createCompilerDiagnostic(ts.Diagnostics.Option_0_cannot_be_specified_with_option_1, "noEmit", "outFile")); + programDiagnostics.add(ts.createCompilerDiagnostic(ts.Diagnostics.Option_0_cannot_be_specified_with_option_1, "noEmit", "outFile")); } if (options.outDir) { - diagnostics.add(ts.createCompilerDiagnostic(ts.Diagnostics.Option_0_cannot_be_specified_with_option_1, "noEmit", "outDir")); + programDiagnostics.add(ts.createCompilerDiagnostic(ts.Diagnostics.Option_0_cannot_be_specified_with_option_1, "noEmit", "outDir")); } if (options.declaration) { - diagnostics.add(ts.createCompilerDiagnostic(ts.Diagnostics.Option_0_cannot_be_specified_with_option_1, "noEmit", "declaration")); + programDiagnostics.add(ts.createCompilerDiagnostic(ts.Diagnostics.Option_0_cannot_be_specified_with_option_1, "noEmit", "declaration")); } } if (options.emitDecoratorMetadata && !options.experimentalDecorators) { - diagnostics.add(ts.createCompilerDiagnostic(ts.Diagnostics.Option_0_cannot_be_specified_without_specifying_option_1, "emitDecoratorMetadata", "experimentalDecorators")); + programDiagnostics.add(ts.createCompilerDiagnostic(ts.Diagnostics.Option_0_cannot_be_specified_without_specifying_option_1, "emitDecoratorMetadata", "experimentalDecorators")); } if (options.experimentalAsyncFunctions && options.target !== 2 /* ES6 */) { - diagnostics.add(ts.createCompilerDiagnostic(ts.Diagnostics.Option_experimentalAsyncFunctions_cannot_be_specified_when_targeting_ES5_or_lower)); + programDiagnostics.add(ts.createCompilerDiagnostic(ts.Diagnostics.Option_experimentalAsyncFunctions_cannot_be_specified_when_targeting_ES5_or_lower)); } } } @@ -44003,9 +44031,9 @@ var ts; // Check if the caret is at the end of an identifier; this is a partial identifier that we want to complete: e.g. a.toS| // Skip this partial identifier and adjust the contextToken to the token that precedes it. if (contextToken && position <= contextToken.end && ts.isWord(contextToken.kind)) { - var start_2 = new Date().getTime(); + var start_4 = new Date().getTime(); contextToken = ts.findPrecedingToken(contextToken.getFullStart(), sourceFile); - log("getCompletionData: Get previous token 2: " + (new Date().getTime() - start_2)); + log("getCompletionData: Get previous token 2: " + (new Date().getTime() - start_4)); } // Find the node where completion is requested on. // Also determine whether we are trying to complete with members of that node @@ -44253,13 +44281,13 @@ var ts; if (contextToken.kind === 9 /* StringLiteral */ || contextToken.kind === 10 /* RegularExpressionLiteral */ || ts.isTemplateLiteralKind(contextToken.kind)) { - var start_3 = contextToken.getStart(); + var start_5 = contextToken.getStart(); var end = contextToken.getEnd(); // To be "in" one of these literals, the position has to be: // 1. entirely within the token text. // 2. at the end position of an unterminated token. // 3. at the end of a regular expression (due to trailing flags like '/foo/g'). - if (start_3 < position && position < end) { + if (start_5 < position && position < end) { return true; } if (position === end) { @@ -48631,7 +48659,10 @@ var ts; if ("getModuleResolutionsForFile" in this.shimHost) { this.resolveModuleNames = function (moduleNames, containingFile) { var resolutionsInFile = JSON.parse(_this.shimHost.getModuleResolutionsForFile(containingFile)); - return ts.map(moduleNames, function (name) { return ts.lookUp(resolutionsInFile, name); }); + return ts.map(moduleNames, function (name) { + var result = ts.lookUp(resolutionsInFile, name); + return result ? { resolvedFileName: result } : undefined; + }); }; } } @@ -49178,7 +49209,11 @@ var ts; var _this = this; return this.forwardJSONCall("resolveModuleName('" + fileName + "')", function () { var compilerOptions = JSON.parse(compilerOptionsJson); - return ts.resolveModuleName(moduleName, ts.normalizeSlashes(fileName), compilerOptions, _this.host); + var result = ts.resolveModuleName(moduleName, ts.normalizeSlashes(fileName), compilerOptions, _this.host); + return { + resolvedFileName: result.resolvedModule ? result.resolvedModule.resolvedFileName : undefined, + failedLookupLocations: result.failedLookupLocations + }; }); }; CoreServicesShimObject.prototype.getPreProcessedFileInfo = function (fileName, sourceTextSnapshot) {