Skip to content

Commit 35583e6

Browse files
committed
Process ES6 imports when creating program
1 parent 36c9cf0 commit 35583e6

File tree

1 file changed

+18
-5
lines changed

1 file changed

+18
-5
lines changed

Diff for: src/compiler/program.ts

+18-5
Original file line numberDiff line numberDiff line change
@@ -274,13 +274,26 @@ module ts {
274274
});
275275
}
276276

277+
function getImportedModuleName(node: Node): StringLiteralExpression {
278+
if (node.kind === SyntaxKind.ImportDeclaration) {
279+
return (<ImportDeclaration>node).moduleSpecifier;
280+
}
281+
if (node.kind === SyntaxKind.ImportEqualsDeclaration) {
282+
var reference = (<ImportEqualsDeclaration>node).moduleReference;
283+
if (reference.kind === SyntaxKind.ExternalModuleReference) {
284+
var expr = (<ExternalModuleReference>reference).expression;
285+
if (expr && expr.kind === SyntaxKind.StringLiteral) {
286+
return <StringLiteralExpression>expr;
287+
}
288+
}
289+
}
290+
}
291+
277292
function processImportedModules(file: SourceFile, basePath: string) {
278293
forEach(file.statements, node => {
279-
if (isExternalModuleImportEqualsDeclaration(node) &&
280-
getExternalModuleImportEqualsDeclarationExpression(node).kind === SyntaxKind.StringLiteral) {
281-
282-
var nameLiteral = <LiteralExpression>getExternalModuleImportEqualsDeclarationExpression(node);
283-
var moduleName = nameLiteral.text;
294+
if (node.kind === SyntaxKind.ImportDeclaration || node.kind === SyntaxKind.ImportEqualsDeclaration) {
295+
var nameLiteral = getImportedModuleName(node);
296+
var moduleName = nameLiteral && nameLiteral.text;
284297
if (moduleName) {
285298
var searchPath = basePath;
286299
while (true) {

0 commit comments

Comments
 (0)