@@ -692,6 +692,12 @@ namespace ts {
692692
693693 let imports : LiteralExpression [ ] ;
694694 for ( let node of file . statements ) {
695+ collect ( node , /* allowRelativeModuleNames */ true ) ;
696+ }
697+
698+ file . imports = imports || emptyArray ;
699+
700+ function collect ( node : Node , allowRelativeModuleNames : boolean ) : void {
695701 switch ( node . kind ) {
696702 case SyntaxKind . ImportDeclaration :
697703 case SyntaxKind . ImportEqualsDeclaration :
@@ -704,7 +710,9 @@ namespace ts {
704710 break ;
705711 }
706712
707- ( imports || ( imports = [ ] ) ) . push ( < LiteralExpression > moduleNameExpr ) ;
713+ if ( allowRelativeModuleNames || ! isExternalModuleNameRelative ( ( < LiteralExpression > moduleNameExpr ) . text ) ) {
714+ ( imports || ( imports = [ ] ) ) . push ( < LiteralExpression > moduleNameExpr ) ;
715+ }
708716 break ;
709717 case SyntaxKind . ModuleDeclaration :
710718 if ( ( < ModuleDeclaration > node ) . name . kind === SyntaxKind . StringLiteral && ( node . flags & NodeFlags . Ambient || isDeclarationFile ( file ) ) ) {
@@ -714,23 +722,15 @@ namespace ts {
714722 // The StringLiteral must specify a top - level external module name.
715723 // Relative external module names are not permitted
716724 forEachChild ( ( < ModuleDeclaration > node ) . body , node => {
717- if ( isExternalModuleImportEqualsDeclaration ( node ) &&
718- getExternalModuleImportEqualsDeclarationExpression ( node ) . kind === SyntaxKind . StringLiteral ) {
719- let moduleName = < LiteralExpression > getExternalModuleImportEqualsDeclarationExpression ( node ) ;
720- // TypeScript 1.0 spec (April 2014): 12.1.6
721- // An ExternalImportDeclaration in anAmbientExternalModuleDeclaration may reference other external modules
722- // only through top - level external module names. Relative external module names are not permitted.
723- if ( moduleName ) {
724- ( imports || ( imports = [ ] ) ) . push ( moduleName ) ;
725- }
726- }
725+ // TypeScript 1.0 spec (April 2014): 12.1.6
726+ // An ExternalImportDeclaration in anAmbientExternalModuleDeclaration may reference other external modules
727+ // only through top - level external module names. Relative external module names are not permitted.
728+ collect ( node , /* allowRelativeModuleNames */ false ) ;
727729 } ) ;
728730 }
729731 break ;
730732 }
731733 }
732-
733- file . imports = imports || emptyArray ;
734734 }
735735
736736 function processSourceFile ( fileName : string , isDefaultLib : boolean , refFile ?: SourceFile , refPos ?: number , refEnd ?: number ) {
0 commit comments