From 8415910375e6c8bf226dbed94e34719d347d6f90 Mon Sep 17 00:00:00 2001 From: Tobias Bosch Date: Fri, 17 Mar 2017 09:44:27 -0700 Subject: [PATCH] fix(compiler): add an empty content for source file of non mapped code. (#15246) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Before this when using ngc, tools tried to load `ng://….ts` if `….ts` was the source file of a template. PR Close #15246 --- packages/compiler/src/output/abstract_emitter.ts | 5 ++++- packages/compiler/test/aot/compiler_spec.ts | 2 +- packages/compiler/test/output/js_emitter_node_only_spec.ts | 2 +- packages/compiler/test/output/ts_emitter_node_only_spec.ts | 2 +- .../test/linker/source_map_integration_node_only_spec.ts | 2 +- 5 files changed, 8 insertions(+), 5 deletions(-) diff --git a/packages/compiler/src/output/abstract_emitter.ts b/packages/compiler/src/output/abstract_emitter.ts index f7082d6f6b..28918302f5 100644 --- a/packages/compiler/src/output/abstract_emitter.ts +++ b/packages/compiler/src/output/abstract_emitter.ts @@ -98,7 +98,10 @@ export class EmitterVisitorContext { let firstOffsetMapped = false; const mapFirstOffsetIfNeeded = () => { if (!firstOffsetMapped) { - map.addSource(sourceFilePath).addMapping(0, sourceFilePath, 0, 0); + // Add a single space so that tools won't try to load the file from disk. + // Note: We are using virtual urls like `ng:///`, so we have to + // provide a content here. + map.addSource(sourceFilePath, ' ').addMapping(0, sourceFilePath, 0, 0); firstOffsetMapped = true; } }; diff --git a/packages/compiler/test/aot/compiler_spec.ts b/packages/compiler/test/aot/compiler_spec.ts index 11e526e935..aa4d4fa33d 100644 --- a/packages/compiler/test/aot/compiler_spec.ts +++ b/packages/compiler/test/aot/compiler_spec.ts @@ -188,7 +188,7 @@ describe('compiler (unbundled Angular)', () => { // for the mapping to the original source file we don't store the source code // as we want to keep whatever TypeScript / ... produced for them. const sourceIndex = sourceMap.sources.indexOf(ngComponentPath); - expect(sourceMap.sourcesContent[sourceIndex]).toBe(null); + expect(sourceMap.sourcesContent[sourceIndex]).toBe(' '); }); })); diff --git a/packages/compiler/test/output/js_emitter_node_only_spec.ts b/packages/compiler/test/output/js_emitter_node_only_spec.ts index c5bcf79ac2..111364d8b0 100644 --- a/packages/compiler/test/output/js_emitter_node_only_spec.ts +++ b/packages/compiler/test/output/js_emitter_node_only_spec.ts @@ -57,7 +57,7 @@ export function main() { const sm = emitSourceMap(someVar.toStmt(), [], '/* MyPreamble \n */'); expect(sm.sources).toEqual([someSourceFilePath, 'in.js']); - expect(sm.sourcesContent).toEqual([null, ';;;var']); + expect(sm.sourcesContent).toEqual([' ', ';;;var']); expect(originalPositionFor(sm, {line: 3, column: 0})) .toEqual({line: 1, column: 3, source: 'in.js'}); }); diff --git a/packages/compiler/test/output/ts_emitter_node_only_spec.ts b/packages/compiler/test/output/ts_emitter_node_only_spec.ts index 2c1a2869b8..d728f23426 100644 --- a/packages/compiler/test/output/ts_emitter_node_only_spec.ts +++ b/packages/compiler/test/output/ts_emitter_node_only_spec.ts @@ -62,7 +62,7 @@ export function main() { const sm = emitSourceMap(someVar.toStmt(), [], '/* MyPreamble \n */'); expect(sm.sources).toEqual([someSourceFilePath, 'in.js']); - expect(sm.sourcesContent).toEqual([null, ';;;var']); + expect(sm.sourcesContent).toEqual([' ', ';;;var']); expect(originalPositionFor(sm, {line: 3, column: 0})) .toEqual({line: 1, column: 3, source: 'in.js'}); }); diff --git a/packages/core/test/linker/source_map_integration_node_only_spec.ts b/packages/core/test/linker/source_map_integration_node_only_spec.ts index b6f0afacfc..9c3cb368cb 100644 --- a/packages/core/test/linker/source_map_integration_node_only_spec.ts +++ b/packages/core/test/linker/source_map_integration_node_only_spec.ts @@ -128,7 +128,7 @@ export function main() { expect(sourceMap.sources).toEqual([ 'ng:///DynamicTestModule/MyComp.ngfactory.js', ngUrl ]); - expect(sourceMap.sourcesContent).toEqual([null, template]); + expect(sourceMap.sourcesContent).toEqual([' ', template]); }));