Skip to content

Commit 9d02882

Browse files
committed
fix: Source maps not correctly referenced.
The default mapRoot setting and code generation does not work with typescript 1.8+ as noted in the comments for the "fixSourceMapSources" function in broccoli-typescript.js. I removed the "fixSourceMapSources" function and also removed the default mapRoot setting. This fix was suggested by KirNekrasov in his comments to the bug. angular#1266
1 parent 2c9a371 commit 9d02882

File tree

2 files changed

+1
-49
lines changed

2 files changed

+1
-49
lines changed

addon/ng2/blueprints/ng2/files/__path__/tsconfig.json

-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
"declaration": false,
55
"emitDecoratorMetadata": true,
66
"experimentalDecorators": true,
7-
"mapRoot": "/",
87
"module": "commonjs",
98
"moduleResolution": "node",
109
"noEmitOnError": true,

lib/broccoli/broccoli-typescript.js

+1-48
Original file line numberDiff line numberDiff line change
@@ -205,8 +205,7 @@ class BroccoliTypeScriptCompiler extends Plugin {
205205
}
206206

207207
fse.mkdirsSync(path.dirname(absoluteFilePath));
208-
const content = this.fixSourceMapSources(fileContent, inputFilePath);
209-
fs.writeFileSync(absoluteFilePath, content, FS_OPTS);
208+
fs.writeFileSync(absoluteFilePath, fileContent, FS_OPTS);
210209

211210
fse.mkdirsSync(path.dirname(outputFilePath));
212211
try {
@@ -232,52 +231,6 @@ class BroccoliTypeScriptCompiler extends Plugin {
232231
outputs: new Set()
233232
};
234233
}
235-
236-
/**
237-
* There is a bug in TypeScript 1.6, where the sourceRoot and inlineSourceMap properties
238-
* are exclusive. This means that the sources property always contains relative paths
239-
* (e.g, ../../../../@angular/di/injector.ts).
240-
*
241-
* Here, we normalize the sources property and remove the ../../../
242-
*
243-
* This issue is fixed in https://github.com/Microsoft/TypeScript/pull/5620.
244-
* Once we switch to TypeScript 1.8, we can remove this method.
245-
*/
246-
fixSourceMapSources(content, inputFilePath) {
247-
try {
248-
const marker = '//# sourceMappingURL=data:application/json;base64,';
249-
250-
let index = content.indexOf(marker);
251-
if (index == -1) {
252-
const pathMarker = '//# sourceMappingURL=';
253-
index = content.indexOf(pathMarker);
254-
if (index == -1) {
255-
return content;
256-
}
257-
258-
// We have a regular path, make it relative to the input path.
259-
let base = content.substring(0, index + pathMarker.length);
260-
let mapPath = content.substring(index + pathMarker.length);
261-
if (mapPath.startsWith(this.outputPath)) {
262-
mapPath = mapPath.replace(this.outputPath, this.inputPaths[0]);
263-
} else if (!mapPath.startsWith(this.inputPaths[0])) {
264-
mapPath = path.join(this.inputPaths[0], path.dirname(this._tsConfigPath), mapPath);
265-
}
266-
267-
mapPath = path.relative(path.dirname(inputFilePath), mapPath);
268-
return '' + base + mapPath;
269-
}
270-
271-
var base = content.substring(0, index + marker.length);
272-
var sourceMapBit = new Buffer(content.substring(index + marker.length), 'base64').toString('utf8');
273-
var sourceMaps = JSON.parse(sourceMapBit);
274-
var source = sourceMaps.sources[0];
275-
sourceMaps.sources = [source.substring(source.lastIndexOf('../') + 3)];
276-
return '' + base + new Buffer(JSON.stringify(sourceMaps)).toString('base64');
277-
} catch (e) {
278-
return content;
279-
}
280-
}
281234
}
282235

283236
class CustomLanguageServiceHost {

0 commit comments

Comments
 (0)