Skip to content

Commit

Permalink
fix(aot): output the sources in the sourcemap. (#3107)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
hansl authored Nov 11, 2016
1 parent 215e555 commit 7127dba
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 6 deletions.
15 changes: 9 additions & 6 deletions packages/webpack/src/loader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -107,10 +107,10 @@ function _replaceBootstrap(fileName: string,
}).then(() => sourceText);
}

function _transpile(plugin: AotPlugin, filePath: string, sourceText: string) {
function _transpile(plugin: AotPlugin, fileName: string, sourceText: string) {
const program = plugin.program;
if (plugin.typeCheck) {
const sourceFile = program.getSourceFile(filePath);
const sourceFile = program.getSourceFile(fileName);
const diagnostics = program.getSyntacticDiagnostics(sourceFile)
.concat(program.getSemanticDiagnostics(sourceFile))
.concat(program.getDeclarationDiagnostics(sourceFile));
Expand All @@ -127,11 +127,14 @@ function _transpile(plugin: AotPlugin, filePath: string, sourceText: string) {
}
}

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

const result = ts.transpileModule(sourceText, { compilerOptions, fileName });
return {
outputText: result.outputText,
sourceMap: JSON.parse(result.sourceMapText)
Expand All @@ -151,7 +154,7 @@ export function ngcLoader(source: string) {
.then(() => _removeDecorators(this.resource, source))
.then(sourceText => _replaceBootstrap(this.resource, sourceText, plugin))
.then(sourceText => {
const result = _transpile(plugin, this.resource, sourceText);
const result = _transpile(plugin, this.resourcePath, sourceText);
cb(null, result.outputText, result.sourceMap);
})
.catch(err => cb(err));
Expand Down
1 change: 1 addition & 0 deletions packages/webpack/src/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ export class AotPlugin {

get basePath() { return this._basePath; }
get compilation() { return this._compilation; }
get compilerHost() { return this._compilerHost; }
get compilerOptions() { return this._compilerOptions; }
get done() { return this._donePromise; }
get entryModule() { return this._entryModule; }
Expand Down

0 comments on commit 7127dba

Please sign in to comment.