Skip to content

Commit 2558e3e

Browse files
hanslMRHarrison
authored andcommitted
fix(aot): output the sources in the sourcemap. (angular#3107)
This allows browsers to at least debug and breakpoints with `--aot`. Note that the source will be different than the source on disk, because we still perform some refactoring and we don't transform the sourcemap.
1 parent c60bfa2 commit 2558e3e

File tree

2 files changed

+10
-6
lines changed

2 files changed

+10
-6
lines changed

packages/webpack/src/loader.ts

+9-6
Original file line numberDiff line numberDiff line change
@@ -107,10 +107,10 @@ function _replaceBootstrap(fileName: string,
107107
}).then(() => sourceText);
108108
}
109109

110-
function _transpile(plugin: AotPlugin, filePath: string, sourceText: string) {
110+
function _transpile(plugin: AotPlugin, fileName: string, sourceText: string) {
111111
const program = plugin.program;
112112
if (plugin.typeCheck) {
113-
const sourceFile = program.getSourceFile(filePath);
113+
const sourceFile = program.getSourceFile(fileName);
114114
const diagnostics = program.getSyntacticDiagnostics(sourceFile)
115115
.concat(program.getSemanticDiagnostics(sourceFile))
116116
.concat(program.getDeclarationDiagnostics(sourceFile));
@@ -127,11 +127,14 @@ function _transpile(plugin: AotPlugin, filePath: string, sourceText: string) {
127127
}
128128
}
129129

130-
const result = ts.transpileModule(sourceText, {
131-
compilerOptions: plugin.compilerOptions,
132-
fileName: filePath
130+
// Force a few compiler options to make sure we get the result we want.
131+
const compilerOptions: ts.CompilerOptions = Object.assign({}, plugin.compilerOptions, {
132+
inlineSources: true,
133+
inlineSourceMap: false,
134+
sourceRoot: plugin.basePath
133135
});
134136

137+
const result = ts.transpileModule(sourceText, { compilerOptions, fileName });
135138
return {
136139
outputText: result.outputText,
137140
sourceMap: JSON.parse(result.sourceMapText)
@@ -151,7 +154,7 @@ export function ngcLoader(source: string) {
151154
.then(() => _removeDecorators(this.resource, source))
152155
.then(sourceText => _replaceBootstrap(this.resource, sourceText, plugin))
153156
.then(sourceText => {
154-
const result = _transpile(plugin, this.resource, sourceText);
157+
const result = _transpile(plugin, this.resourcePath, sourceText);
155158
cb(null, result.outputText, result.sourceMap);
156159
})
157160
.catch(err => cb(err));

packages/webpack/src/plugin.ts

+1
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ export class AotPlugin {
7979

8080
get basePath() { return this._basePath; }
8181
get compilation() { return this._compilation; }
82+
get compilerHost() { return this._compilerHost; }
8283
get compilerOptions() { return this._compilerOptions; }
8384
get done() { return this._donePromise; }
8485
get entryModule() { return this._entryModule; }

0 commit comments

Comments
 (0)