Merge pull request #8509 from Microsoft/Fix8507

Fix #8507: Consider UnknownSymbols values for import/export purposes
This commit is contained in:
Mohamed Hegazy 2016-05-12 11:03:22 -07:00
commit 977a7ec1ba
35 changed files with 94 additions and 23 deletions

View File

@ -1136,9 +1136,8 @@ namespace ts {
const symbol = getSymbolOfNode(node);
const target = resolveAlias(symbol);
if (target) {
const markAlias =
(target === unknownSymbol && compilerOptions.isolatedModules) ||
(target !== unknownSymbol && (target.flags & SymbolFlags.Value) && !isConstEnumOrConstEnumOnlyModule(target));
const markAlias = target === unknownSymbol ||
((target.flags & SymbolFlags.Value) && !isConstEnumOrConstEnumOnlyModule(target));
if (markAlias) {
markAliasSymbolAsReferenced(symbol);
@ -2633,7 +2632,7 @@ namespace ts {
const internalModuleReference = <Identifier | QualifiedName>(<ImportEqualsDeclaration>declaration).moduleReference;
const firstIdentifier = getFirstIdentifier(internalModuleReference);
const importSymbol = resolveName(declaration, firstIdentifier.text, SymbolFlags.Value | SymbolFlags.Type | SymbolFlags.Namespace,
Diagnostics.Cannot_find_name_0, firstIdentifier);
undefined, undefined);
if (importSymbol) {
buildVisibleNodeList(importSymbol.declarations);
}
@ -17113,14 +17112,12 @@ namespace ts {
function isAliasResolvedToValue(symbol: Symbol): boolean {
const target = resolveAlias(symbol);
if (target === unknownSymbol && compilerOptions.isolatedModules) {
if (target === unknownSymbol) {
return true;
}
// const enums and modules that contain only const enums are not considered values from the emit perspective
// unless 'preserveConstEnums' option is set to true
return target !== unknownSymbol &&
target &&
target.flags & SymbolFlags.Value &&
return target.flags & SymbolFlags.Value &&
(compilerOptions.preserveConstEnums || !isConstEnumOrConstEnumOnlyModule(target));
}

View File

@ -12,3 +12,4 @@ var C = (function () {
return C;
}());
exports.C = C;
module.exports = B;

View File

@ -12,3 +12,4 @@ var C = (function () {
return C;
}());
exports.C = C;
module.exports = B;

View File

@ -55,9 +55,12 @@ var foo;
var provide = foo;
var booz = foo.bar.baz;
var beez = foo.bar;
var m = no;
var m2 = no.mod;
5;
"s";
null;
var r = undefined;
var p = new provide.Provide();
function use() {
beez.baz.boo;

View File

@ -13,4 +13,5 @@ define(["require", "exports"], function (require, exports) {
function foo() { }
foo(); // ok
}
return foo;
});

View File

@ -6,6 +6,8 @@ import abstract class D {}
//// [classAbstractManyKeywords.js]
"use strict";
exports.__esModule = true;
exports["default"] = abstract;
var A = (function () {
function A() {
}
@ -22,6 +24,7 @@ var C = (function () {
}
return C;
}());
var abstract = ;
var D = (function () {
function D() {
}

View File

@ -1,4 +1,4 @@
tests/cases/compiler/declarationEmit_UnknownImport.ts(2,1): error TS2304: Cannot find name 'SomeNonExistingName'.
tests/cases/compiler/declarationEmit_UnknownImport.ts(2,14): error TS2304: Cannot find name 'SomeNonExistingName'.
tests/cases/compiler/declarationEmit_UnknownImport.ts(2,14): error TS2503: Cannot find namespace 'SomeNonExistingName'.
tests/cases/compiler/declarationEmit_UnknownImport.ts(2,14): error TS4000: Import declaration 'Foo' is using private name 'SomeNonExistingName'.
@ -6,7 +6,7 @@ tests/cases/compiler/declarationEmit_UnknownImport.ts(2,14): error TS4000: Impor
==== tests/cases/compiler/declarationEmit_UnknownImport.ts (3 errors) ====
import Foo = SomeNonExistingName
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
~~~~~~~~~~~~~~~~~~~
!!! error TS2304: Cannot find name 'SomeNonExistingName'.
~~~~~~~~~~~~~~~~~~~
!!! error TS2503: Cannot find namespace 'SomeNonExistingName'.

View File

@ -5,3 +5,5 @@ export {Foo}
//// [declarationEmit_UnknownImport.js]
"use strict";
var Foo = SomeNonExistingName;
exports.Foo = Foo;

View File

@ -1,5 +1,5 @@
tests/cases/compiler/declarationEmit_UnknownImport2.ts(2,1): error TS2304: Cannot find name 'From'.
tests/cases/compiler/declarationEmit_UnknownImport2.ts(2,12): error TS1005: '=' expected.
tests/cases/compiler/declarationEmit_UnknownImport2.ts(2,12): error TS2304: Cannot find name 'From'.
tests/cases/compiler/declarationEmit_UnknownImport2.ts(2,12): error TS2503: Cannot find namespace 'From'.
tests/cases/compiler/declarationEmit_UnknownImport2.ts(2,12): error TS4000: Import declaration 'Foo' is using private name 'From'.
tests/cases/compiler/declarationEmit_UnknownImport2.ts(2,17): error TS1005: ';' expected.
@ -8,11 +8,11 @@ tests/cases/compiler/declarationEmit_UnknownImport2.ts(2,17): error TS1005: ';'
==== tests/cases/compiler/declarationEmit_UnknownImport2.ts (5 errors) ====
import Foo From './Foo'; // Syntax error
~~~~~~~~~~~~~~~
!!! error TS2304: Cannot find name 'From'.
~~~~
!!! error TS1005: '=' expected.
~~~~
!!! error TS2304: Cannot find name 'From'.
~~~~
!!! error TS2503: Cannot find namespace 'From'.
~~~~
!!! error TS4000: Import declaration 'Foo' is using private name 'From'.

View File

@ -5,4 +5,7 @@ export default Foo
//// [declarationEmit_UnknownImport2.js]
"use strict";
var Foo = From;
'./Foo'; // Syntax error
Object.defineProperty(exports, "__esModule", { value: true });
exports.default = Foo;

View File

@ -275,6 +275,8 @@ function_module_1.a;
class_1.a;
class_module_1.a;
// named export
var interface_2 = require("interface");
exports.a1 = interface_2.a;
var variable_2 = require("variable");
exports.a2 = variable_2.a;
var interface_variable_2 = require("interface-variable");
@ -285,8 +287,12 @@ var interface_module_2 = require("interface-module");
exports.a5 = interface_module_2.a;
var variable_module_2 = require("variable-module");
exports.a6 = variable_module_2.a;
var function_2 = require("function");
exports.a7 = function_2.a;
var function_module_2 = require("function-module");
exports.a8 = function_module_2.a;
var class_2 = require("class");
exports.a9 = class_2.a;
var class_module_2 = require("class-module");
exports.a0 = class_module_2.a;
// export-star

View File

@ -1,12 +1,15 @@
tests/cases/compiler/importDeclWithClassModifiers.ts(5,8): error TS1044: 'public' modifier cannot appear on a module or namespace element.
tests/cases/compiler/importDeclWithClassModifiers.ts(5,26): error TS2304: Cannot find name 'x'.
tests/cases/compiler/importDeclWithClassModifiers.ts(5,28): error TS2305: Module 'x' has no exported member 'c'.
tests/cases/compiler/importDeclWithClassModifiers.ts(6,8): error TS1044: 'private' modifier cannot appear on a module or namespace element.
tests/cases/compiler/importDeclWithClassModifiers.ts(6,27): error TS2304: Cannot find name 'x'.
tests/cases/compiler/importDeclWithClassModifiers.ts(6,29): error TS2305: Module 'x' has no exported member 'c'.
tests/cases/compiler/importDeclWithClassModifiers.ts(7,8): error TS1044: 'static' modifier cannot appear on a module or namespace element.
tests/cases/compiler/importDeclWithClassModifiers.ts(7,26): error TS2304: Cannot find name 'x'.
tests/cases/compiler/importDeclWithClassModifiers.ts(7,28): error TS2305: Module 'x' has no exported member 'c'.
==== tests/cases/compiler/importDeclWithClassModifiers.ts (6 errors) ====
==== tests/cases/compiler/importDeclWithClassModifiers.ts (9 errors) ====
module x {
interface c {
}
@ -14,16 +17,22 @@ tests/cases/compiler/importDeclWithClassModifiers.ts(7,28): error TS2305: Module
export public import a = x.c;
~~~~~~
!!! error TS1044: 'public' modifier cannot appear on a module or namespace element.
~
!!! error TS2304: Cannot find name 'x'.
~
!!! error TS2305: Module 'x' has no exported member 'c'.
export private import b = x.c;
~~~~~~~
!!! error TS1044: 'private' modifier cannot appear on a module or namespace element.
~
!!! error TS2304: Cannot find name 'x'.
~
!!! error TS2305: Module 'x' has no exported member 'c'.
export static import c = x.c;
~~~~~~
!!! error TS1044: 'static' modifier cannot appear on a module or namespace element.
~
!!! error TS2304: Cannot find name 'x'.
~
!!! error TS2305: Module 'x' has no exported member 'c'.
var b: a;

View File

@ -12,5 +12,8 @@ var b: a;
//// [importDeclWithClassModifiers.js]
define(["require", "exports"], function (require, exports) {
"use strict";
exports.a = x.c;
exports.b = x.c;
exports.c = x.c;
var b;
});

View File

@ -1,8 +1,9 @@
tests/cases/compiler/importDeclWithDeclareModifier.ts(5,9): error TS1029: 'export' modifier must precede 'declare' modifier.
tests/cases/compiler/importDeclWithDeclareModifier.ts(5,27): error TS2304: Cannot find name 'x'.
tests/cases/compiler/importDeclWithDeclareModifier.ts(5,29): error TS2305: Module 'x' has no exported member 'c'.
==== tests/cases/compiler/importDeclWithDeclareModifier.ts (2 errors) ====
==== tests/cases/compiler/importDeclWithDeclareModifier.ts (3 errors) ====
module x {
interface c {
}
@ -10,6 +11,8 @@ tests/cases/compiler/importDeclWithDeclareModifier.ts(5,29): error TS2305: Modul
declare export import a = x.c;
~~~~~~
!!! error TS1029: 'export' modifier must precede 'declare' modifier.
~
!!! error TS2304: Cannot find name 'x'.
~
!!! error TS2305: Module 'x' has no exported member 'c'.
var b: a;

View File

@ -1,12 +1,15 @@
tests/cases/compiler/importDeclWithExportModifier.ts(5,19): error TS2304: Cannot find name 'x'.
tests/cases/compiler/importDeclWithExportModifier.ts(5,21): error TS2305: Module 'x' has no exported member 'c'.
==== tests/cases/compiler/importDeclWithExportModifier.ts (1 errors) ====
==== tests/cases/compiler/importDeclWithExportModifier.ts (2 errors) ====
module x {
interface c {
}
}
export import a = x.c;
~
!!! error TS2304: Cannot find name 'x'.
~
!!! error TS2305: Module 'x' has no exported member 'c'.
var b: a;

View File

@ -10,5 +10,6 @@ var b: a;
//// [importDeclWithExportModifier.js]
define(["require", "exports"], function (require, exports) {
"use strict";
exports.a = x.c;
var b;
});

View File

@ -1,13 +1,16 @@
tests/cases/compiler/importDeclWithExportModifierAndExportAssignment.ts(5,19): error TS2304: Cannot find name 'x'.
tests/cases/compiler/importDeclWithExportModifierAndExportAssignment.ts(5,21): error TS2305: Module 'x' has no exported member 'c'.
tests/cases/compiler/importDeclWithExportModifierAndExportAssignment.ts(6,1): error TS2309: An export assignment cannot be used in a module with other exported elements.
==== tests/cases/compiler/importDeclWithExportModifierAndExportAssignment.ts (2 errors) ====
==== tests/cases/compiler/importDeclWithExportModifierAndExportAssignment.ts (3 errors) ====
module x {
interface c {
}
}
export import a = x.c;
~
!!! error TS2304: Cannot find name 'x'.
~
!!! error TS2305: Module 'x' has no exported member 'c'.
export = x;

View File

@ -8,3 +8,4 @@ export = x;
//// [importDeclWithExportModifierAndExportAssignment.js]
"use strict";
exports.a = x.c;

View File

@ -27,13 +27,17 @@ import i = I;
//// [invalidImportAliasIdentifiers.js]
// none of these should work, since non are actually modules
var V = 12;
var v = V;
var C = (function () {
function C() {
}
return C;
}());
var c = C;
var E;
(function (E) {
E[E["Red"] = 0] = "Red";
E[E["Blue"] = 1] = "Blue";
})(E || (E = {}));
var e = E;
var i = I;

View File

@ -34,6 +34,8 @@
{
var v;
function foo() { }
var ambient_2 = require("ambient");
exports.b = ambient_2.baz;
exports["default"] = v;
var C = (function () {
function C() {

View File

@ -34,6 +34,8 @@ function blah () {
function blah() {
var v;
function foo() { }
var ambient_2 = require("ambient");
exports.b = ambient_2.baz;
exports["default"] = v;
var C = (function () {
function C() {

View File

@ -37,6 +37,8 @@ var P;
{
var v;
function foo() { }
var ambient_2 = require("ambient");
P.b = ambient_2.baz;
P["default"] = v;
var C = (function () {
function C() {

View File

@ -3,3 +3,4 @@ export = foo
//// [parserExportAssignment1.js]
"use strict";
module.exports = foo;

View File

@ -3,3 +3,4 @@ export = foo;
//// [parserExportAssignment2.js]
"use strict";
module.exports = foo;

View File

@ -3,3 +3,4 @@ export =
//// [parserExportAssignment3.js]
"use strict";
module.exports = ;

View File

@ -3,3 +3,4 @@ export = ;
//// [parserExportAssignment4.js]
"use strict";
module.exports = ;

View File

@ -12,3 +12,4 @@ var C = (function () {
return C;
}());
exports.C = C;
module.exports = B;

View File

@ -12,3 +12,4 @@ var C = (function () {
return C;
}());
exports.C = C;
module.exports = B;

View File

@ -2,3 +2,4 @@
import TypeScript = TypeScriptServices.TypeScript;
//// [parserImportDeclaration1.js]
var TypeScript = TypeScriptServices.TypeScript;

View File

@ -560,6 +560,8 @@ var glo_im4_private_v4_private = glo_im4_private.f1();
// Parse error to export module
exports.glo_im1_public = glo_M1_public;
exports.glo_im2_public = glo_M3_private;
exports.glo_im3_public = require("glo_M2_public");
exports.glo_im4_public = require("glo_M4_private");
var m2;
(function (m2_1) {
var m4;

View File

@ -14,8 +14,9 @@ import ClassB = require("recursiveExportAssignmentAndFindAliasedType4_moduleB");
export var b: ClassB; // This should result in type ClassB
//// [recursiveExportAssignmentAndFindAliasedType4_moduleC.js]
define(["require", "exports"], function (require, exports) {
define(["require", "exports", "recursiveExportAssignmentAndFindAliasedType4_moduleC"], function (require, exports, self) {
"use strict";
return self;
});
//// [recursiveExportAssignmentAndFindAliasedType4_moduleB.js]
define(["require", "exports"], function (require, exports) {

View File

@ -18,12 +18,14 @@ import ClassB = require("recursiveExportAssignmentAndFindAliasedType5_moduleB");
export var b: ClassB; // This should result in type ClassB
//// [recursiveExportAssignmentAndFindAliasedType5_moduleD.js]
define(["require", "exports"], function (require, exports) {
define(["require", "exports", "recursiveExportAssignmentAndFindAliasedType5_moduleC"], function (require, exports, self) {
"use strict";
return self;
});
//// [recursiveExportAssignmentAndFindAliasedType5_moduleC.js]
define(["require", "exports"], function (require, exports) {
define(["require", "exports", "recursiveExportAssignmentAndFindAliasedType5_moduleD"], function (require, exports, self) {
"use strict";
return self;
});
//// [recursiveExportAssignmentAndFindAliasedType5_moduleB.js]
define(["require", "exports"], function (require, exports) {

View File

@ -22,16 +22,19 @@ import ClassB = require("recursiveExportAssignmentAndFindAliasedType6_moduleB");
export var b: ClassB; // This should result in type ClassB
//// [recursiveExportAssignmentAndFindAliasedType6_moduleE.js]
define(["require", "exports"], function (require, exports) {
define(["require", "exports", "recursiveExportAssignmentAndFindAliasedType6_moduleC"], function (require, exports, self) {
"use strict";
return self;
});
//// [recursiveExportAssignmentAndFindAliasedType6_moduleD.js]
define(["require", "exports"], function (require, exports) {
define(["require", "exports", "recursiveExportAssignmentAndFindAliasedType6_moduleE"], function (require, exports, self) {
"use strict";
return self;
});
//// [recursiveExportAssignmentAndFindAliasedType6_moduleC.js]
define(["require", "exports"], function (require, exports) {
define(["require", "exports", "recursiveExportAssignmentAndFindAliasedType6_moduleD"], function (require, exports, self) {
"use strict";
return self;
});
//// [recursiveExportAssignmentAndFindAliasedType6_moduleB.js]
define(["require", "exports"], function (require, exports) {

View File

@ -2,3 +2,4 @@
import TypeScript = TypeScriptServices.TypeScript;
//// [scannerImportDeclaration1.js]
var TypeScript = TypeScriptServices.TypeScript;

View File

@ -23,13 +23,18 @@ exports.x = "x";
"use strict";
var t1_1 = require("./t1");
exports.x = t1_1.x;
exports.from = t1_1.from;
//// [t3.js]
"use strict";
var t1_1 = require("./t1");
exports.from = t1_1.from;
//// [t4.js]
"use strict";
var t1_1 = require("./t1");
exports.a = t1_1.x;
exports.from = t1_1.from;
//// [t5.js]
"use strict";
var t1_1 = require("./t1");
exports.a = t1_1.x;
exports.from = t1_1.from;