From 35583e66948cffb3c1246825eea1f12e989e3d70 Mon Sep 17 00:00:00 2001 From: Anders Hejlsberg Date: Fri, 6 Feb 2015 06:15:03 -0800 Subject: [PATCH] Process ES6 imports when creating program --- src/compiler/program.ts | 23 ++++++++++++++++++----- 1 file changed, 18 insertions(+), 5 deletions(-) diff --git a/src/compiler/program.ts b/src/compiler/program.ts index 998e2512395..8b2d899f321 100644 --- a/src/compiler/program.ts +++ b/src/compiler/program.ts @@ -274,13 +274,26 @@ module ts { }); } + function getImportedModuleName(node: Node): StringLiteralExpression { + if (node.kind === SyntaxKind.ImportDeclaration) { + return (node).moduleSpecifier; + } + if (node.kind === SyntaxKind.ImportEqualsDeclaration) { + var reference = (node).moduleReference; + if (reference.kind === SyntaxKind.ExternalModuleReference) { + var expr = (reference).expression; + if (expr && expr.kind === SyntaxKind.StringLiteral) { + return expr; + } + } + } + } + function processImportedModules(file: SourceFile, basePath: string) { forEach(file.statements, node => { - if (isExternalModuleImportEqualsDeclaration(node) && - getExternalModuleImportEqualsDeclarationExpression(node).kind === SyntaxKind.StringLiteral) { - - var nameLiteral = getExternalModuleImportEqualsDeclarationExpression(node); - var moduleName = nameLiteral.text; + if (node.kind === SyntaxKind.ImportDeclaration || node.kind === SyntaxKind.ImportEqualsDeclaration) { + var nameLiteral = getImportedModuleName(node); + var moduleName = nameLiteral && nameLiteral.text; if (moduleName) { var searchPath = basePath; while (true) {