mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-02-05 08:11:30 -06:00
Merge pull request #29380 from Microsoft/sourceMap
Use the SourceMapSource to get line and column instead of current source file
This commit is contained in:
commit
d69b2ea448
@ -4391,7 +4391,7 @@ namespace ts {
|
||||
return;
|
||||
}
|
||||
|
||||
const { line: sourceLine, character: sourceCharacter } = getLineAndCharacterOfPosition(currentSourceFile!, pos);
|
||||
const { line: sourceLine, character: sourceCharacter } = getLineAndCharacterOfPosition(sourceMapSource, pos);
|
||||
sourceMapGenerator!.addMapping(
|
||||
writer.getLine(),
|
||||
writer.getColumn(),
|
||||
|
||||
@ -95,6 +95,39 @@ namespace ts {
|
||||
module: ModuleKind.ES2015,
|
||||
emitDecoratorMetadata: true,
|
||||
experimentalDecorators: true
|
||||
});
|
||||
});
|
||||
|
||||
emitsCorrectly("sourceMapExternalSourceFiles",
|
||||
[
|
||||
{
|
||||
file: "source.ts",
|
||||
// The text of length 'changed' is made to be on two lines so we know the line map change
|
||||
text: `\`multi
|
||||
line\`
|
||||
'change'`
|
||||
},
|
||||
],
|
||||
{
|
||||
before: [
|
||||
context => node => visitNode(node, function visitor(node: Node): Node {
|
||||
if (isStringLiteral(node) && node.text === "change") {
|
||||
const text = "'changed'";
|
||||
const lineMap = computeLineStarts(text);
|
||||
setSourceMapRange(node, {
|
||||
pos: 0, end: text.length, source: {
|
||||
text,
|
||||
fileName: "another.html",
|
||||
lineMap,
|
||||
getLineAndCharacterOfPosition: pos => computeLineAndCharacterOfPosition(lineMap, pos)
|
||||
}
|
||||
});
|
||||
return node;
|
||||
}
|
||||
return visitEachChild(node, visitor, context);
|
||||
})
|
||||
]
|
||||
},
|
||||
{ sourceMap: true }
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
@ -0,0 +1,7 @@
|
||||
// [source.js.map]
|
||||
{"version":3,"file":"source.js","sourceRoot":"","sources":["source.ts","another.html"],"names":[],"mappings":"AAAA,iCACyB,CAAA;ACDzB,QAAS,CDED"}
|
||||
|
||||
// [source.js]
|
||||
"multi\n line";
|
||||
'change';
|
||||
//# sourceMappingURL=source.js.map
|
||||
Loading…
x
Reference in New Issue
Block a user