Merge pull request #14915 from Microsoft/master-fix14870
[Master] exception when emitting with malformed namespace import
This commit is contained in:
commit
bc1bda542c
11 changed files with 199 additions and 21 deletions
|
@ -359,6 +359,10 @@ namespace ts {
|
||||||
|
|
||||||
// Find the name of the module alias, if there is one
|
// Find the name of the module alias, if there is one
|
||||||
const importAliasName = getLocalNameForExternalImport(importNode, currentSourceFile);
|
const importAliasName = getLocalNameForExternalImport(importNode, currentSourceFile);
|
||||||
|
// It is possible that externalModuleName is undefined if it is not string literal.
|
||||||
|
// This can happen in the invalid import syntax.
|
||||||
|
// E.g : "import * from alias from 'someLib';"
|
||||||
|
if (externalModuleName) {
|
||||||
if (includeNonAmdDependencies && importAliasName) {
|
if (includeNonAmdDependencies && importAliasName) {
|
||||||
// Set emitFlags on the name of the classDeclaration
|
// Set emitFlags on the name of the classDeclaration
|
||||||
// This is so that when printer will not substitute the identifier
|
// This is so that when printer will not substitute the identifier
|
||||||
|
@ -370,6 +374,7 @@ namespace ts {
|
||||||
unaliasedModuleNames.push(externalModuleName);
|
unaliasedModuleNames.push(externalModuleName);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return { aliasedModuleNames, unaliasedModuleNames, importAliasNames };
|
return { aliasedModuleNames, unaliasedModuleNames, importAliasNames };
|
||||||
}
|
}
|
||||||
|
|
|
@ -151,6 +151,7 @@ namespace ts {
|
||||||
for (let i = 0; i < externalImports.length; i++) {
|
for (let i = 0; i < externalImports.length; i++) {
|
||||||
const externalImport = externalImports[i];
|
const externalImport = externalImports[i];
|
||||||
const externalModuleName = getExternalModuleNameLiteral(externalImport, currentSourceFile, host, resolver, compilerOptions);
|
const externalModuleName = getExternalModuleNameLiteral(externalImport, currentSourceFile, host, resolver, compilerOptions);
|
||||||
|
if (externalModuleName) {
|
||||||
const text = externalModuleName.text;
|
const text = externalModuleName.text;
|
||||||
const groupIndex = groupIndices.get(text);
|
const groupIndex = groupIndices.get(text);
|
||||||
if (groupIndex !== undefined) {
|
if (groupIndex !== undefined) {
|
||||||
|
@ -165,6 +166,7 @@ namespace ts {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return dependencyGroups;
|
return dependencyGroups;
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,22 @@
|
||||||
|
tests/cases/conformance/externalModules/1.ts(1,10): error TS1005: 'as' expected.
|
||||||
|
tests/cases/conformance/externalModules/1.ts(1,15): error TS1005: 'from' expected.
|
||||||
|
tests/cases/conformance/externalModules/1.ts(1,15): error TS1141: String literal expected.
|
||||||
|
tests/cases/conformance/externalModules/1.ts(1,20): error TS1005: ';' expected.
|
||||||
|
tests/cases/conformance/externalModules/1.ts(1,25): error TS1005: ';' expected.
|
||||||
|
|
||||||
|
|
||||||
|
==== tests/cases/conformance/externalModules/0.ts (0 errors) ====
|
||||||
|
export class C { }
|
||||||
|
|
||||||
|
==== tests/cases/conformance/externalModules/1.ts (5 errors) ====
|
||||||
|
import * from Zero from "./0"
|
||||||
|
~~~~
|
||||||
|
!!! error TS1005: 'as' expected.
|
||||||
|
~~~~
|
||||||
|
!!! error TS1005: 'from' expected.
|
||||||
|
~~~~
|
||||||
|
!!! error TS1141: String literal expected.
|
||||||
|
~~~~
|
||||||
|
!!! error TS1005: ';' expected.
|
||||||
|
~~~~~
|
||||||
|
!!! error TS1005: ';' expected.
|
|
@ -0,0 +1,26 @@
|
||||||
|
//// [tests/cases/conformance/externalModules/invalidSyntaxNamespaceImportWithAMD.ts] ////
|
||||||
|
|
||||||
|
//// [0.ts]
|
||||||
|
export class C { }
|
||||||
|
|
||||||
|
//// [1.ts]
|
||||||
|
import * from Zero from "./0"
|
||||||
|
|
||||||
|
//// [0.js]
|
||||||
|
define(["require", "exports"], function (require, exports) {
|
||||||
|
"use strict";
|
||||||
|
exports.__esModule = true;
|
||||||
|
var C = (function () {
|
||||||
|
function C() {
|
||||||
|
}
|
||||||
|
return C;
|
||||||
|
}());
|
||||||
|
exports.C = C;
|
||||||
|
});
|
||||||
|
//// [1.js]
|
||||||
|
define(["require", "exports"], function (require, exports) {
|
||||||
|
"use strict";
|
||||||
|
exports.__esModule = true;
|
||||||
|
from;
|
||||||
|
"./0";
|
||||||
|
});
|
|
@ -0,0 +1,22 @@
|
||||||
|
tests/cases/conformance/externalModules/1.ts(1,10): error TS1005: 'as' expected.
|
||||||
|
tests/cases/conformance/externalModules/1.ts(1,15): error TS1005: 'from' expected.
|
||||||
|
tests/cases/conformance/externalModules/1.ts(1,15): error TS1141: String literal expected.
|
||||||
|
tests/cases/conformance/externalModules/1.ts(1,20): error TS1005: ';' expected.
|
||||||
|
tests/cases/conformance/externalModules/1.ts(1,25): error TS1005: ';' expected.
|
||||||
|
|
||||||
|
|
||||||
|
==== tests/cases/conformance/externalModules/0.ts (0 errors) ====
|
||||||
|
export class C { }
|
||||||
|
|
||||||
|
==== tests/cases/conformance/externalModules/1.ts (5 errors) ====
|
||||||
|
import * from Zero from "./0"
|
||||||
|
~~~~
|
||||||
|
!!! error TS1005: 'as' expected.
|
||||||
|
~~~~
|
||||||
|
!!! error TS1005: 'from' expected.
|
||||||
|
~~~~
|
||||||
|
!!! error TS1141: String literal expected.
|
||||||
|
~~~~
|
||||||
|
!!! error TS1005: ';' expected.
|
||||||
|
~~~~~
|
||||||
|
!!! error TS1005: ';' expected.
|
|
@ -0,0 +1,23 @@
|
||||||
|
//// [tests/cases/conformance/externalModules/invalidSyntaxNamespaceImportWithCommonjs.ts] ////
|
||||||
|
|
||||||
|
//// [0.ts]
|
||||||
|
export class C { }
|
||||||
|
|
||||||
|
//// [1.ts]
|
||||||
|
import * from Zero from "./0"
|
||||||
|
|
||||||
|
//// [0.js]
|
||||||
|
"use strict";
|
||||||
|
exports.__esModule = true;
|
||||||
|
var C = (function () {
|
||||||
|
function C() {
|
||||||
|
}
|
||||||
|
return C;
|
||||||
|
}());
|
||||||
|
exports.C = C;
|
||||||
|
//// [1.js]
|
||||||
|
"use strict";
|
||||||
|
exports.__esModule = true;
|
||||||
|
var from = require();
|
||||||
|
from;
|
||||||
|
"./0";
|
|
@ -0,0 +1,22 @@
|
||||||
|
tests/cases/conformance/externalModules/1.ts(1,10): error TS1005: 'as' expected.
|
||||||
|
tests/cases/conformance/externalModules/1.ts(1,15): error TS1005: 'from' expected.
|
||||||
|
tests/cases/conformance/externalModules/1.ts(1,15): error TS1141: String literal expected.
|
||||||
|
tests/cases/conformance/externalModules/1.ts(1,20): error TS1005: ';' expected.
|
||||||
|
tests/cases/conformance/externalModules/1.ts(1,25): error TS1005: ';' expected.
|
||||||
|
|
||||||
|
|
||||||
|
==== tests/cases/conformance/externalModules/0.ts (0 errors) ====
|
||||||
|
export class C { }
|
||||||
|
|
||||||
|
==== tests/cases/conformance/externalModules/1.ts (5 errors) ====
|
||||||
|
import * from Zero from "./0"
|
||||||
|
~~~~
|
||||||
|
!!! error TS1005: 'as' expected.
|
||||||
|
~~~~
|
||||||
|
!!! error TS1005: 'from' expected.
|
||||||
|
~~~~
|
||||||
|
!!! error TS1141: String literal expected.
|
||||||
|
~~~~
|
||||||
|
!!! error TS1005: ';' expected.
|
||||||
|
~~~~~
|
||||||
|
!!! error TS1005: ';' expected.
|
|
@ -0,0 +1,38 @@
|
||||||
|
//// [tests/cases/conformance/externalModules/invalidSyntaxNamespaceImportWithSystem.ts] ////
|
||||||
|
|
||||||
|
//// [0.ts]
|
||||||
|
export class C { }
|
||||||
|
|
||||||
|
//// [1.ts]
|
||||||
|
import * from Zero from "./0"
|
||||||
|
|
||||||
|
//// [0.js]
|
||||||
|
System.register([], function (exports_1, context_1) {
|
||||||
|
"use strict";
|
||||||
|
var __moduleName = context_1 && context_1.id;
|
||||||
|
var C;
|
||||||
|
return {
|
||||||
|
setters: [],
|
||||||
|
execute: function () {
|
||||||
|
C = (function () {
|
||||||
|
function C() {
|
||||||
|
}
|
||||||
|
return C;
|
||||||
|
}());
|
||||||
|
exports_1("C", C);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
});
|
||||||
|
//// [1.js]
|
||||||
|
System.register([], function (exports_1, context_1) {
|
||||||
|
"use strict";
|
||||||
|
var __moduleName = context_1 && context_1.id;
|
||||||
|
var from;
|
||||||
|
return {
|
||||||
|
setters: [],
|
||||||
|
execute: function () {
|
||||||
|
from;
|
||||||
|
"./0";
|
||||||
|
}
|
||||||
|
};
|
||||||
|
});
|
|
@ -0,0 +1,6 @@
|
||||||
|
// @module: amd
|
||||||
|
// @filename: 0.ts
|
||||||
|
export class C { }
|
||||||
|
|
||||||
|
// @filename: 1.ts
|
||||||
|
import * from Zero from "./0"
|
|
@ -0,0 +1,6 @@
|
||||||
|
// @module: commonjs
|
||||||
|
// @filename: 0.ts
|
||||||
|
export class C { }
|
||||||
|
|
||||||
|
// @filename: 1.ts
|
||||||
|
import * from Zero from "./0"
|
|
@ -0,0 +1,6 @@
|
||||||
|
// @module: system
|
||||||
|
// @filename: 0.ts
|
||||||
|
export class C { }
|
||||||
|
|
||||||
|
// @filename: 1.ts
|
||||||
|
import * from Zero from "./0"
|
Loading…
Reference in a new issue