Skip to content

Commit

Permalink
fix(compiler): add an empty content for source file of non mapped cod…
Browse files Browse the repository at this point in the history
…e. (#15246)

Before this when using ngc, tools tried to load `ng://…<component>.ts`
if `…<component>.ts` was the source file of a template.

PR Close #15246
  • Loading branch information
tbosch authored and mhevery committed Mar 17, 2017
1 parent 5486e54 commit 8415910
Show file tree
Hide file tree
Showing 5 changed files with 8 additions and 5 deletions.
5 changes: 4 additions & 1 deletion packages/compiler/src/output/abstract_emitter.ts
Expand Up @@ -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;
}
};
Expand Down
2 changes: 1 addition & 1 deletion packages/compiler/test/aot/compiler_spec.ts
Expand Up @@ -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(' ');
});
}));

Expand Down
2 changes: 1 addition & 1 deletion packages/compiler/test/output/js_emitter_node_only_spec.ts
Expand Up @@ -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'});
});
Expand Down
2 changes: 1 addition & 1 deletion packages/compiler/test/output/ts_emitter_node_only_spec.ts
Expand Up @@ -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'});
});
Expand Down
Expand Up @@ -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]);
}));


Expand Down

0 comments on commit 8415910

Please sign in to comment.