Skip to content

Commit d69b2ea

Browse files
authored
Merge pull request #29380 from Microsoft/sourceMap
Use the SourceMapSource to get line and column instead of current source file
2 parents 3d2bf6a + d106157 commit d69b2ea

File tree

3 files changed

+42
-2
lines changed

3 files changed

+42
-2
lines changed

src/compiler/emitter.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4391,7 +4391,7 @@ namespace ts {
43914391
return;
43924392
}
43934393

4394-
const { line: sourceLine, character: sourceCharacter } = getLineAndCharacterOfPosition(currentSourceFile!, pos);
4394+
const { line: sourceLine, character: sourceCharacter } = getLineAndCharacterOfPosition(sourceMapSource, pos);
43954395
sourceMapGenerator!.addMapping(
43964396
writer.getLine(),
43974397
writer.getColumn(),

src/testRunner/unittests/customTransforms.ts

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,39 @@ namespace ts {
9595
module: ModuleKind.ES2015,
9696
emitDecoratorMetadata: true,
9797
experimentalDecorators: true
98-
});
98+
});
99+
100+
emitsCorrectly("sourceMapExternalSourceFiles",
101+
[
102+
{
103+
file: "source.ts",
104+
// The text of length 'changed' is made to be on two lines so we know the line map change
105+
text: `\`multi
106+
line\`
107+
'change'`
108+
},
109+
],
110+
{
111+
before: [
112+
context => node => visitNode(node, function visitor(node: Node): Node {
113+
if (isStringLiteral(node) && node.text === "change") {
114+
const text = "'changed'";
115+
const lineMap = computeLineStarts(text);
116+
setSourceMapRange(node, {
117+
pos: 0, end: text.length, source: {
118+
text,
119+
fileName: "another.html",
120+
lineMap,
121+
getLineAndCharacterOfPosition: pos => computeLineAndCharacterOfPosition(lineMap, pos)
122+
}
123+
});
124+
return node;
125+
}
126+
return visitEachChild(node, visitor, context);
127+
})
128+
]
129+
},
130+
{ sourceMap: true }
131+
);
99132
});
100133
}

tests/baselines/reference/customTransforms/sourceMapExternalSourceFiles.js

Lines changed: 7 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)