fix(compiler): add an empty content for source file of non mapped code. (#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
This commit is contained in:
parent
5486e5417b
commit
8415910375
|
@ -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;
|
||||
}
|
||||
};
|
||||
|
|
|
@ -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(' ');
|
||||
});
|
||||
}));
|
||||
|
||||
|
|
|
@ -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'});
|
||||
});
|
||||
|
|
|
@ -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'});
|
||||
});
|
||||
|
|
|
@ -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]);
|
||||
}));
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue