change source map merge logic to be like applying line edits to the typescript source maps (based on the input source maps)
parent
59f0d9c20e
commit
0d5f87e9dd
File diff suppressed because one or more lines are too long
|
@ -322,6 +322,11 @@ class StaticLanguageServiceHost implements ts.LanguageServiceHost {
|
|||
realpath = ts.sys.realpath;
|
||||
}
|
||||
|
||||
export interface MangleOutput {
|
||||
out: string;
|
||||
sourceMap?: string;
|
||||
}
|
||||
|
||||
/**
|
||||
* TypeScript2TypeScript transformer that mangles all private and protected fields
|
||||
*
|
||||
|
@ -341,7 +346,7 @@ export class Mangler {
|
|||
this.service = ts.createLanguageService(new StaticLanguageServiceHost(projectPath));
|
||||
}
|
||||
|
||||
computeNewFileContents(): Map<string, { out: string; sourceMap?: string }> {
|
||||
computeNewFileContents(): Map<string, MangleOutput> {
|
||||
|
||||
// STEP: find all classes and their field info
|
||||
|
||||
|
@ -469,7 +474,7 @@ export class Mangler {
|
|||
this.log(`done preparing EDITS for ${editsByFile.size} files`);
|
||||
|
||||
// STEP: apply all rename edits (per file)
|
||||
const result = new Map<string, { out: string; sourceMap?: string }>();
|
||||
const result = new Map<string, MangleOutput>();
|
||||
let savedBytes = 0;
|
||||
|
||||
for (const item of this.service.getProgram()!.getSourceFiles()) {
|
||||
|
|
File diff suppressed because one or more lines are too long
|
@ -162,7 +162,9 @@ export function createTypeScriptBuilder(config: IConfiguration, projectFile: str
|
|||
let sourceMap = <RawSourceMap>JSON.parse(sourcemapFile.text);
|
||||
sourceMap.sources[0] = tsname.replace(/\\/g, '/');
|
||||
|
||||
// check for an input source map and combine them
|
||||
// check for an "input source" map and combine them
|
||||
// in step 1 we extract all line edit from the input source map, and
|
||||
// in step 2 we apply the line edits to the typescript source map
|
||||
const snapshot = host.getScriptSnapshot(fileName);
|
||||
if (snapshot instanceof VinylScriptSnapshot && snapshot.sourceMap) {
|
||||
const inputSMC = new SourceMapConsumer(snapshot.sourceMap);
|
||||
|
@ -172,40 +174,56 @@ export function createTypeScriptBuilder(config: IConfiguration, projectFile: str
|
|||
file: sourceMap.file,
|
||||
sourceRoot: sourceMap.sourceRoot
|
||||
});
|
||||
|
||||
// step 1
|
||||
const lineEdits = new Map<number, [from: number, to: number][]>();
|
||||
inputSMC.eachMapping(m => {
|
||||
if (m.originalLine === m.generatedLine) {
|
||||
// same line mapping
|
||||
let array = lineEdits.get(m.originalLine);
|
||||
if (!array) {
|
||||
array = [];
|
||||
lineEdits.set(m.originalLine, array);
|
||||
}
|
||||
array.push([m.originalColumn, m.generatedColumn]);
|
||||
} else {
|
||||
// NOT SUPPORTED
|
||||
}
|
||||
});
|
||||
|
||||
// step 2
|
||||
tsSMC.eachMapping(m => {
|
||||
didChange = true;
|
||||
const original = { line: m.originalLine, column: m.originalColumn };
|
||||
const generated = { line: m.generatedLine, column: m.generatedColumn };
|
||||
// JS-out position -> input original position
|
||||
const inputOriginal = inputSMC.originalPositionFor(original);
|
||||
if (inputOriginal.source !== null) {
|
||||
const inputSource = inputOriginal.source;
|
||||
smg.addMapping({
|
||||
source: inputSource,
|
||||
name: inputOriginal.name,
|
||||
generated: generated,
|
||||
original: inputOriginal
|
||||
});
|
||||
smg.setSourceContent(
|
||||
inputSource,
|
||||
inputSMC.sourceContentFor(inputSource)
|
||||
);
|
||||
} else {
|
||||
smg.addMapping({
|
||||
source: m.source,
|
||||
name: m.name,
|
||||
generated: generated,
|
||||
original: original
|
||||
});
|
||||
smg.setSourceContent(
|
||||
m.source,
|
||||
tsSMC.sourceContentFor(m.source)
|
||||
);
|
||||
|
||||
const edits = lineEdits.get(m.originalLine);
|
||||
let originalColumnDelta = 0;
|
||||
if (edits) {
|
||||
for (const [from, to] of edits) {
|
||||
if (to >= m.originalColumn) {
|
||||
break;
|
||||
}
|
||||
originalColumnDelta = from - to;
|
||||
}
|
||||
}
|
||||
}, null, SourceMapConsumer.GENERATED_ORDER);
|
||||
smg.addMapping({
|
||||
source: m.source,
|
||||
name: m.name,
|
||||
generated: { line: m.generatedLine, column: m.generatedColumn },
|
||||
original: { line: m.originalLine, column: m.originalColumn + originalColumnDelta }
|
||||
});
|
||||
});
|
||||
|
||||
if (didChange) {
|
||||
|
||||
[tsSMC, inputSMC].forEach((consumer) => {
|
||||
(<SourceMapConsumer & { sources: string[] }>consumer).sources.forEach((sourceFile: any) => {
|
||||
(<any>smg)._sources.add(sourceFile);
|
||||
const sourceContent = consumer.sourceContentFor(sourceFile);
|
||||
if (sourceContent !== null) {
|
||||
smg.setSourceContent(sourceFile, sourceContent);
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
sourceMap = JSON.parse(smg.toString());
|
||||
|
||||
// const filename = '/Users/jrieken/Code/vscode/src2/' + vinyl.relative + '.map';
|
||||
|
|
Loading…
Reference in New Issue