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:
Sheetal Nandi 2019-01-14 14:30:27 -08:00 committed by GitHub
commit d69b2ea448
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 42 additions and 2 deletions

View File

@ -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(),

View File

@ -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 }
);
});
}

View File

@ -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