Process ES6 imports when creating program

This commit is contained in:
Anders Hejlsberg 2015-02-06 06:15:03 -08:00
parent 36c9cf09e6
commit 35583e6694

View File

@ -274,13 +274,26 @@ module ts {
});
}
function getImportedModuleName(node: Node): StringLiteralExpression {
if (node.kind === SyntaxKind.ImportDeclaration) {
return (<ImportDeclaration>node).moduleSpecifier;
}
if (node.kind === SyntaxKind.ImportEqualsDeclaration) {
var reference = (<ImportEqualsDeclaration>node).moduleReference;
if (reference.kind === SyntaxKind.ExternalModuleReference) {
var expr = (<ExternalModuleReference>reference).expression;
if (expr && expr.kind === SyntaxKind.StringLiteral) {
return <StringLiteralExpression>expr;
}
}
}
}
function processImportedModules(file: SourceFile, basePath: string) {
forEach(file.statements, node => {
if (isExternalModuleImportEqualsDeclaration(node) &&
getExternalModuleImportEqualsDeclarationExpression(node).kind === SyntaxKind.StringLiteral) {
var nameLiteral = <LiteralExpression>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) {