@@ -787,6 +787,7 @@ export class Program extends DiagnosticEmitter {
787
787
// queued imports should be resolvable now through traversing exports and queued exports
788
788
for ( let i = 0 , k = queuedImports . length ; i < k ; ++ i ) {
789
789
let queuedImport = queuedImports [ i ] ;
790
+ let localIdentifier = queuedImport . localIdentifier ;
790
791
let foreignIdentifier = queuedImport . foreignIdentifier ;
791
792
if ( foreignIdentifier ) { // i.e. import { foo [as bar] } from "./baz"
792
793
let element = this . lookupForeign (
@@ -797,9 +798,9 @@ export class Program extends DiagnosticEmitter {
797
798
) ;
798
799
if ( element ) {
799
800
queuedImport . localFile . add (
800
- queuedImport . localIdentifier . text ,
801
+ localIdentifier . text ,
801
802
element ,
802
- true // isImport
803
+ localIdentifier // isImport
803
804
) ;
804
805
} else {
805
806
// FIXME: file not found is not reported if this happens?
@@ -812,14 +813,15 @@ export class Program extends DiagnosticEmitter {
812
813
let foreignFile = this . lookupForeignFile ( queuedImport . foreignPath , queuedImport . foreignPathAlt ) ;
813
814
if ( foreignFile ) {
814
815
let localFile = queuedImport . localFile ;
815
- let localName = queuedImport . localIdentifier . text ;
816
+ let localName = localIdentifier . text ;
816
817
localFile . add (
817
818
localName ,
818
819
foreignFile . asImportedNamespace (
819
820
localName ,
820
- localFile
821
+ localFile ,
822
+ localIdentifier
821
823
) ,
822
- true // isImport
824
+ localIdentifier // isImport
823
825
) ;
824
826
} else {
825
827
assert ( false ) ; // already reported by the parser not finding the file
@@ -1775,7 +1777,7 @@ export class Program extends DiagnosticEmitter {
1775
1777
// resolve right away if the element exists
1776
1778
var element = this . lookupForeign ( declaration . foreignName . text , foreignPath , foreignPathAlt , queuedExports ) ;
1777
1779
if ( element ) {
1778
- parent . add ( declaration . name . text , element , true ) ;
1780
+ parent . add ( declaration . name . text , element , declaration . name /* isImport */ ) ;
1779
1781
return ;
1780
1782
}
1781
1783
@@ -2161,7 +2163,7 @@ export abstract class Element {
2161
2163
abstract lookup ( name : string ) : Element | null ;
2162
2164
2163
2165
/** Adds an element as a member of this one. Reports and returns `false` if a duplicate. */
2164
- add ( name : string , element : DeclaredElement ) : bool {
2166
+ add ( name : string , element : DeclaredElement , localIdentifierIfImport : IdentifierExpression | null = null ) : bool {
2165
2167
var originalDeclaration = element . declaration ;
2166
2168
var members = this . members ;
2167
2169
if ( ! members ) this . members = members = new Map ( ) ;
@@ -2174,17 +2176,18 @@ export abstract class Element {
2174
2176
if ( merged ) {
2175
2177
element = merged ; // use merged element
2176
2178
} else {
2179
+ let reportedIdentifier = localIdentifierIfImport || element . identifierNode ;
2177
2180
if ( isDeclaredElement ( existing . kind ) ) {
2178
2181
this . program . errorRelated (
2179
2182
DiagnosticCode . Duplicate_identifier_0 ,
2180
- element . identifierNode . range ,
2181
- ( < DeclaredElement > existing ) . declaration . name . range ,
2182
- element . identifierNode . text
2183
+ reportedIdentifier . range ,
2184
+ ( < DeclaredElement > existing ) . identifierNode . range ,
2185
+ reportedIdentifier . text
2183
2186
) ;
2184
2187
} else {
2185
2188
this . program . error (
2186
2189
DiagnosticCode . Duplicate_identifier_0 ,
2187
- element . identifierNode . range , element . identifierNode . text
2190
+ reportedIdentifier . range , reportedIdentifier . text
2188
2191
) ;
2189
2192
}
2190
2193
return false ;
@@ -2338,13 +2341,13 @@ export class File extends Element {
2338
2341
}
2339
2342
2340
2343
/* @override */
2341
- add ( name : string , element : DeclaredElement , isImport : bool = false ) : bool {
2344
+ add ( name : string , element : DeclaredElement , localIdentifierIfImport : IdentifierExpression | null = null ) : bool {
2342
2345
if ( element . hasDecorator ( DecoratorFlags . GLOBAL ) ) {
2343
2346
element = this . program . ensureGlobal ( name , element ) ; // possibly merged globally
2344
2347
}
2345
- if ( ! super . add ( name , element ) ) return false ;
2348
+ if ( ! super . add ( name , element , localIdentifierIfImport ) ) return false ;
2346
2349
element = assert ( this . lookupInSelf ( name ) ) ; // possibly merged locally
2347
- if ( element . is ( CommonFlags . EXPORT ) && ! isImport ) {
2350
+ if ( element . is ( CommonFlags . EXPORT ) && ! localIdentifierIfImport ) {
2348
2351
this . ensureExport (
2349
2352
element . name ,
2350
2353
element
@@ -2404,12 +2407,10 @@ export class File extends Element {
2404
2407
}
2405
2408
2406
2409
/** Creates an imported namespace from this file. */
2407
- asImportedNamespace ( name : string , parent : Element ) : Namespace {
2408
- var ns = new Namespace (
2409
- name ,
2410
- parent ,
2411
- this . program . makeNativeNamespaceDeclaration ( name )
2412
- ) ;
2410
+ asImportedNamespace ( name : string , parent : Element , localIdentifier : IdentifierExpression ) : Namespace {
2411
+ var declaration = this . program . makeNativeNamespaceDeclaration ( name ) ;
2412
+ declaration . name = localIdentifier ;
2413
+ var ns = new Namespace ( name , parent , declaration ) ;
2413
2414
var exports = this . exports ;
2414
2415
if ( exports ) {
2415
2416
for ( let [ memberName , member ] of exports ) {
@@ -3719,7 +3720,7 @@ function tryMerge(older: Element, newer: Element): DeclaredElement | null {
3719
3720
// NOTE: some of the following cases are not supported by TS, not sure why exactly.
3720
3721
// suggesting to just merge what seems to be possible for now and revisit later.
3721
3722
assert ( older . program === newer . program ) ;
3722
- assert ( ! newer . members ) ;
3723
+ if ( newer . members ) return null ;
3723
3724
var merged : DeclaredElement | null = null ;
3724
3725
switch ( older . kind ) {
3725
3726
case ElementKind . FUNCTION_PROTOTYPE : {
0 commit comments