From 2836c17791806d7be0db65dca7bdff8385bb0db0 Mon Sep 17 00:00:00 2001 From: Vladimir Matveev Date: Mon, 23 Nov 2015 13:08:44 -0800 Subject: [PATCH 1/5] do not treat modules with '!' in names any specially --- src/compiler/checker.ts | 4 ---- tests/baselines/reference/bangInModuleName.js | 23 +++++++++++++++++++ .../reference/bangInModuleName.symbols | 21 +++++++++++++++++ .../reference/bangInModuleName.types | 21 +++++++++++++++++ tests/cases/compiler/bangInModuleName.ts | 17 ++++++++++++++ 5 files changed, 82 insertions(+), 4 deletions(-) create mode 100644 tests/baselines/reference/bangInModuleName.js create mode 100644 tests/baselines/reference/bangInModuleName.symbols create mode 100644 tests/baselines/reference/bangInModuleName.types create mode 100644 tests/cases/compiler/bangInModuleName.ts diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 1b6b31f9586..c8e3b8381c3 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -1034,10 +1034,6 @@ namespace ts { return; } - if (moduleName.indexOf("!") >= 0) { - moduleName = moduleName.substr(0, moduleName.indexOf("!")); - } - const isRelative = isExternalModuleNameRelative(moduleName); if (!isRelative) { const symbol = getSymbol(globals, "\"" + moduleName + "\"", SymbolFlags.ValueModule); diff --git a/tests/baselines/reference/bangInModuleName.js b/tests/baselines/reference/bangInModuleName.js new file mode 100644 index 00000000000..769ccbf1d42 --- /dev/null +++ b/tests/baselines/reference/bangInModuleName.js @@ -0,0 +1,23 @@ +//// [tests/cases/compiler/bangInModuleName.ts] //// + +//// [a.d.ts] + + +declare module "http" { +} + +declare module 'intern/dojo/node!http' { + import http = require('http'); + export = http; +} + +//// [a.ts] + +/// + +import * as http from 'intern/dojo/node!http'; + +//// [a.js] +/// +define(["require", "exports"], function (require, exports) { +}); diff --git a/tests/baselines/reference/bangInModuleName.symbols b/tests/baselines/reference/bangInModuleName.symbols new file mode 100644 index 00000000000..63ba5d106d8 --- /dev/null +++ b/tests/baselines/reference/bangInModuleName.symbols @@ -0,0 +1,21 @@ +=== tests/cases/compiler/a.ts === + +/// + +import * as http from 'intern/dojo/node!http'; +>http : Symbol(http, Decl(a.ts, 3, 6)) + +=== tests/cases/compiler/a.d.ts === + + +declare module "http" { +} + +declare module 'intern/dojo/node!http' { + import http = require('http'); +>http : Symbol(http, Decl(a.d.ts, 5, 40)) + + export = http; +>http : Symbol(http, Decl(a.d.ts, 5, 40)) +} + diff --git a/tests/baselines/reference/bangInModuleName.types b/tests/baselines/reference/bangInModuleName.types new file mode 100644 index 00000000000..06a602e2ff8 --- /dev/null +++ b/tests/baselines/reference/bangInModuleName.types @@ -0,0 +1,21 @@ +=== tests/cases/compiler/a.ts === + +/// + +import * as http from 'intern/dojo/node!http'; +>http : typeof http + +=== tests/cases/compiler/a.d.ts === + + +declare module "http" { +} + +declare module 'intern/dojo/node!http' { + import http = require('http'); +>http : typeof http + + export = http; +>http : typeof http +} + diff --git a/tests/cases/compiler/bangInModuleName.ts b/tests/cases/compiler/bangInModuleName.ts new file mode 100644 index 00000000000..6e8f7163109 --- /dev/null +++ b/tests/cases/compiler/bangInModuleName.ts @@ -0,0 +1,17 @@ +// @module: amd + +// @filename: a.d.ts + +declare module "http" { +} + +declare module 'intern/dojo/node!http' { + import http = require('http'); + export = http; +} + +// @filename: a.ts + +/// + +import * as http from 'intern/dojo/node!http'; \ No newline at end of file From 4beedcf4c7f47c54b91195f5529cdcadeb192b83 Mon Sep 17 00:00:00 2001 From: Anders Hejlsberg Date: Mon, 23 Nov 2015 13:09:50 -0800 Subject: [PATCH 2/5] Update relation cache after we decide to elaborate an error --- src/compiler/checker.ts | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 1b6b31f9586..bd7b02e5c1d 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -5228,9 +5228,12 @@ namespace ts { const id = relation !== identityRelation || apparentSource.id < target.id ? apparentSource.id + "," + target.id : target.id + "," + apparentSource.id; const related = relation[id]; if (related !== undefined) { - // If we computed this relation already and it was failed and reported, or if we're not being asked to elaborate - // errors, we can use the cached value. Otherwise, recompute the relation - if (!elaborateErrors || (related === RelationComparisonResult.FailedAndReported)) { + if (elaborateErrors && related === RelationComparisonResult.Failed) { + // We are elaborating errors and the cached result is an unreported failure. Record the result as a reported + // failure and continue computing the relation such that errors get reported. + relation[id] = RelationComparisonResult.FailedAndReported; + } + else { return related === RelationComparisonResult.Succeeded ? Ternary.True : Ternary.False; } } From 6a144506f49c5973498853d731362e8f5f10bb2e Mon Sep 17 00:00:00 2001 From: Anders Hejlsberg Date: Mon, 23 Nov 2015 13:21:51 -0800 Subject: [PATCH 3/5] Adding regression test --- tests/cases/compiler/errorElaboration.ts | 12 ++++++++++++ 1 file changed, 12 insertions(+) create mode 100644 tests/cases/compiler/errorElaboration.ts diff --git a/tests/cases/compiler/errorElaboration.ts b/tests/cases/compiler/errorElaboration.ts new file mode 100644 index 00000000000..97ec0dde61c --- /dev/null +++ b/tests/cases/compiler/errorElaboration.ts @@ -0,0 +1,12 @@ +// Repro for #5712 + +interface Ref { + prop: T; +} +interface Container { + m1: Container>; + m2: T; +} +declare function foo(x: () => Container>): void; +let a: () => Container>; +foo(a); From c5dd2976833f5ab58d53d660fc791d0d318755e8 Mon Sep 17 00:00:00 2001 From: Anders Hejlsberg Date: Mon, 23 Nov 2015 13:22:23 -0800 Subject: [PATCH 4/5] Accepting new baselines --- ...tructuringParameterDeclaration2.errors.txt | 2 ++ .../reference/errorElaboration.errors.txt | 25 +++++++++++++++++++ tests/baselines/reference/errorElaboration.js | 19 ++++++++++++++ .../reference/promisePermutations3.errors.txt | 8 ++++-- 4 files changed, 52 insertions(+), 2 deletions(-) create mode 100644 tests/baselines/reference/errorElaboration.errors.txt create mode 100644 tests/baselines/reference/errorElaboration.js diff --git a/tests/baselines/reference/destructuringParameterDeclaration2.errors.txt b/tests/baselines/reference/destructuringParameterDeclaration2.errors.txt index 95524d4bf4d..c8037255a32 100644 --- a/tests/baselines/reference/destructuringParameterDeclaration2.errors.txt +++ b/tests/baselines/reference/destructuringParameterDeclaration2.errors.txt @@ -8,6 +8,7 @@ tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration2.ts( Type 'number | string[][] | string' is not assignable to type 'number | string[][]'. Type 'string' is not assignable to type 'number | string[][]'. Type 'string' is not assignable to type 'string[][]'. + Property 'push' is missing in type 'String'. tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration2.ts(16,8): error TS2371: A parameter initializer is only allowed in a function or constructor implementation. tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration2.ts(16,16): error TS2371: A parameter initializer is only allowed in a function or constructor implementation. tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration2.ts(23,14): error TS2345: Argument of type '{ x: string; y: boolean; }' is not assignable to parameter of type '{ x: number; y: any; }'. @@ -77,6 +78,7 @@ tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration2.ts( !!! error TS2345: Type 'number | string[][] | string' is not assignable to type 'number | string[][]'. !!! error TS2345: Type 'string' is not assignable to type 'number | string[][]'. !!! error TS2345: Type 'string' is not assignable to type 'string[][]'. +!!! error TS2345: Property 'push' is missing in type 'String'. // If the declaration includes an initializer expression (which is permitted only diff --git a/tests/baselines/reference/errorElaboration.errors.txt b/tests/baselines/reference/errorElaboration.errors.txt new file mode 100644 index 00000000000..94742d7d98b --- /dev/null +++ b/tests/baselines/reference/errorElaboration.errors.txt @@ -0,0 +1,25 @@ +tests/cases/compiler/errorElaboration.ts(12,5): error TS2345: Argument of type '() => Container>' is not assignable to parameter of type '() => Container>'. + Type 'Container>' is not assignable to type 'Container>'. + Type 'Ref' is not assignable to type 'Ref'. + Type 'string' is not assignable to type 'number'. + + +==== tests/cases/compiler/errorElaboration.ts (1 errors) ==== + // Repro for #5712 + + interface Ref { + prop: T; + } + interface Container { + m1: Container>; + m2: T; + } + declare function foo(x: () => Container>): void; + let a: () => Container>; + foo(a); + ~ +!!! error TS2345: Argument of type '() => Container>' is not assignable to parameter of type '() => Container>'. +!!! error TS2345: Type 'Container>' is not assignable to type 'Container>'. +!!! error TS2345: Type 'Ref' is not assignable to type 'Ref'. +!!! error TS2345: Type 'string' is not assignable to type 'number'. + \ No newline at end of file diff --git a/tests/baselines/reference/errorElaboration.js b/tests/baselines/reference/errorElaboration.js new file mode 100644 index 00000000000..eed8bbd7c6b --- /dev/null +++ b/tests/baselines/reference/errorElaboration.js @@ -0,0 +1,19 @@ +//// [errorElaboration.ts] +// Repro for #5712 + +interface Ref { + prop: T; +} +interface Container { + m1: Container>; + m2: T; +} +declare function foo(x: () => Container>): void; +let a: () => Container>; +foo(a); + + +//// [errorElaboration.js] +// Repro for #5712 +var a; +foo(a); diff --git a/tests/baselines/reference/promisePermutations3.errors.txt b/tests/baselines/reference/promisePermutations3.errors.txt index 72276745c41..b17021a02b9 100644 --- a/tests/baselines/reference/promisePermutations3.errors.txt +++ b/tests/baselines/reference/promisePermutations3.errors.txt @@ -81,7 +81,9 @@ tests/cases/compiler/promisePermutations3.ts(159,21): error TS2345: Argument of Type 'number' is not assignable to type 'string'. tests/cases/compiler/promisePermutations3.ts(165,21): error TS2345: Argument of type '{ (x: T): IPromise; (x: T, y: T): Promise; }' is not assignable to parameter of type '(value: (x: any) => any) => Promise'. Type 'IPromise' is not assignable to type 'Promise'. - Property 'done' is optional in type 'IPromise' but required in type 'Promise'. + Types of property 'then' are incompatible. + Type '(success?: (value: any) => U, error?: (error: any) => U, progress?: (progress: any) => void) => IPromise' is not assignable to type '{ (success?: (value: any) => Promise, error?: (error: any) => Promise, progress?: (progress: any) => void): Promise; (success?: (value: any) => Promise, error?: (error: any) => U, progress?: (progress: any) => void): Promise; (success?: (value: any) => U, error?: (error: any) => Promise, progress?: (progress: any) => void): Promise; (success?: (value: any) => U, error?: (error: any) => U, progress?: (progress: any) => void): Promise; }'. + Type 'IPromise' is not assignable to type 'Promise'. ==== tests/cases/compiler/promisePermutations3.ts (35 errors) ==== @@ -368,5 +370,7 @@ tests/cases/compiler/promisePermutations3.ts(165,21): error TS2345: Argument of ~~~~~~~~~~~~~~~ !!! error TS2345: Argument of type '{ (x: T): IPromise; (x: T, y: T): Promise; }' is not assignable to parameter of type '(value: (x: any) => any) => Promise'. !!! error TS2345: Type 'IPromise' is not assignable to type 'Promise'. -!!! error TS2345: Property 'done' is optional in type 'IPromise' but required in type 'Promise'. +!!! error TS2345: Types of property 'then' are incompatible. +!!! error TS2345: Type '(success?: (value: any) => U, error?: (error: any) => U, progress?: (progress: any) => void) => IPromise' is not assignable to type '{ (success?: (value: any) => Promise, error?: (error: any) => Promise, progress?: (progress: any) => void): Promise; (success?: (value: any) => Promise, error?: (error: any) => U, progress?: (progress: any) => void): Promise; (success?: (value: any) => U, error?: (error: any) => Promise, progress?: (progress: any) => void): Promise; (success?: (value: any) => U, error?: (error: any) => U, progress?: (progress: any) => void): Promise; }'. +!!! error TS2345: Type 'IPromise' is not assignable to type 'Promise'. var s12c = s12.then(testFunction12P, testFunction12, testFunction12); // ok \ No newline at end of file From 566c0db54313f864103054c536372a8908162a66 Mon Sep 17 00:00:00 2001 From: Vladimir Matveev Date: Mon, 23 Nov 2015 13:24:46 -0800 Subject: [PATCH 5/5] fix lint errors --- src/compiler/checker.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index c8e3b8381c3..d06b58cbeca 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -1028,7 +1028,7 @@ namespace ts { // Module names are escaped in our symbol table. However, string literal values aren't. // Escape the name in the "require(...)" clause to ensure we find the right symbol. - let moduleName = escapeIdentifier(moduleReferenceLiteral.text); + const moduleName = escapeIdentifier(moduleReferenceLiteral.text); if (moduleName === undefined) { return;