Merge pull request #14915 from Microsoft/master-fix14870
[Master] exception when emitting with malformed namespace import
This commit is contained in:
commit
bc1bda542c
|
@ -359,15 +359,20 @@ namespace ts {
|
|||
|
||||
// Find the name of the module alias, if there is one
|
||||
const importAliasName = getLocalNameForExternalImport(importNode, currentSourceFile);
|
||||
if (includeNonAmdDependencies && importAliasName) {
|
||||
// Set emitFlags on the name of the classDeclaration
|
||||
// This is so that when printer will not substitute the identifier
|
||||
setEmitFlags(importAliasName, EmitFlags.NoSubstitution);
|
||||
aliasedModuleNames.push(externalModuleName);
|
||||
importAliasNames.push(createParameter(/*decorators*/ undefined, /*modifiers*/ undefined, /*dotDotDotToken*/ undefined, importAliasName));
|
||||
}
|
||||
else {
|
||||
unaliasedModuleNames.push(externalModuleName);
|
||||
// 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) {
|
||||
// Set emitFlags on the name of the classDeclaration
|
||||
// This is so that when printer will not substitute the identifier
|
||||
setEmitFlags(importAliasName, EmitFlags.NoSubstitution);
|
||||
aliasedModuleNames.push(externalModuleName);
|
||||
importAliasNames.push(createParameter(/*decorators*/ undefined, /*modifiers*/ undefined, /*dotDotDotToken*/ undefined, importAliasName));
|
||||
}
|
||||
else {
|
||||
unaliasedModuleNames.push(externalModuleName);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -151,18 +151,20 @@ namespace ts {
|
|||
for (let i = 0; i < externalImports.length; i++) {
|
||||
const externalImport = externalImports[i];
|
||||
const externalModuleName = getExternalModuleNameLiteral(externalImport, currentSourceFile, host, resolver, compilerOptions);
|
||||
const text = externalModuleName.text;
|
||||
const groupIndex = groupIndices.get(text);
|
||||
if (groupIndex !== undefined) {
|
||||
// deduplicate/group entries in dependency list by the dependency name
|
||||
dependencyGroups[groupIndex].externalImports.push(externalImport);
|
||||
}
|
||||
else {
|
||||
groupIndices.set(text, dependencyGroups.length);
|
||||
dependencyGroups.push({
|
||||
name: externalModuleName,
|
||||
externalImports: [externalImport]
|
||||
});
|
||||
if (externalModuleName) {
|
||||
const text = externalModuleName.text;
|
||||
const groupIndex = groupIndices.get(text);
|
||||
if (groupIndex !== undefined) {
|
||||
// deduplicate/group entries in dependency list by the dependency name
|
||||
dependencyGroups[groupIndex].externalImports.push(externalImport);
|
||||
}
|
||||
else {
|
||||
groupIndices.set(text, dependencyGroups.length);
|
||||
dependencyGroups.push({
|
||||
name: externalModuleName,
|
||||
externalImports: [externalImport]
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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