fix(compiler-cli): propagate ts.SourceFile moduleName into metadata
This commit is contained in:
parent
b9a91a5e74
commit
f841fbe60f
|
@ -550,6 +550,7 @@ export class MetadataCollector {
|
||||||
__symbolic: 'module',
|
__symbolic: 'module',
|
||||||
version: this.options.version || METADATA_VERSION, metadata
|
version: this.options.version || METADATA_VERSION, metadata
|
||||||
};
|
};
|
||||||
|
if (sourceFile.moduleName) result.importAs = sourceFile.moduleName;
|
||||||
if (exports) result.exports = exports;
|
if (exports) result.exports = exports;
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
|
@ -112,6 +112,7 @@ function upgradeMetadataWithDtsData(
|
||||||
newMetadata.metadata[prop] = dtsMetadata.metadata[prop];
|
newMetadata.metadata[prop] = dtsMetadata.metadata[prop];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (dtsMetadata['importAs']) newMetadata['importAs'] = dtsMetadata['importAs'];
|
||||||
|
|
||||||
// Only copy exports from exports from metadata prior to version 3.
|
// Only copy exports from exports from metadata prior to version 3.
|
||||||
// Starting with version 3 the collector began collecting exports and
|
// Starting with version 3 the collector began collecting exports and
|
||||||
|
|
|
@ -45,6 +45,7 @@ describe('Collector', () => {
|
||||||
're-exports.ts',
|
're-exports.ts',
|
||||||
're-exports-2.ts',
|
're-exports-2.ts',
|
||||||
'export-as.d.ts',
|
'export-as.d.ts',
|
||||||
|
'named-module.d.ts',
|
||||||
'static-field-reference.ts',
|
'static-field-reference.ts',
|
||||||
'static-method.ts',
|
'static-method.ts',
|
||||||
'static-method-call.ts',
|
'static-method-call.ts',
|
||||||
|
@ -101,6 +102,12 @@ describe('Collector', () => {
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('should preserve module names from TypeScript sources', () => {
|
||||||
|
const sourceFile = program.getSourceFile('named-module.d.ts');
|
||||||
|
const metadata = collector.getMetadata(sourceFile);
|
||||||
|
expect(metadata !['importAs']).toEqual('some-named-module');
|
||||||
|
});
|
||||||
|
|
||||||
it('should be able to collect a simple component\'s metadata', () => {
|
it('should be able to collect a simple component\'s metadata', () => {
|
||||||
const sourceFile = program.getSourceFile('app/hero-detail.component.ts');
|
const sourceFile = program.getSourceFile('app/hero-detail.component.ts');
|
||||||
const metadata = collector.getMetadata(sourceFile);
|
const metadata = collector.getMetadata(sourceFile);
|
||||||
|
@ -1516,6 +1523,10 @@ const FILES: Directory = {
|
||||||
declare function someFunction(): void;
|
declare function someFunction(): void;
|
||||||
export { someFunction as SomeFunction };
|
export { someFunction as SomeFunction };
|
||||||
`,
|
`,
|
||||||
|
'named-module.d.ts': `
|
||||||
|
/// <amd-module name="some-named-module" />
|
||||||
|
export type SomeType = 'a';
|
||||||
|
`,
|
||||||
'local-symbol-ref.ts': `
|
'local-symbol-ref.ts': `
|
||||||
import {Component, Validators} from 'angular2/core';
|
import {Component, Validators} from 'angular2/core';
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue