Skip to content

Commit b23664a

Browse files
committed
Test to verify external source map range addition
1 parent aba0b70 commit b23664a

File tree

2 files changed

+41
-1
lines changed

2 files changed

+41
-1
lines changed

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)