mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-02-15 03:23:08 -06:00
Merge pull request #29555 from petebacondarwin/external-skip-trivia-fix
Use the correct source when skipping trivia
This commit is contained in:
commit
61b95fea5a
@ -4372,10 +4372,10 @@ namespace ts {
|
||||
}
|
||||
|
||||
/**
|
||||
* Skips trivia such as comments and white-space that can optionally overriden by the source map source
|
||||
* Skips trivia such as comments and white-space that can be optionally overridden by the source-map source
|
||||
*/
|
||||
function skipSourceTrivia(source: SourceMapSource, pos: number): number {
|
||||
return source.skipTrivia ? source.skipTrivia(pos) : skipTrivia(sourceMapSource.text, pos);
|
||||
return source.skipTrivia ? source.skipTrivia(pos) : skipTrivia(source.text, pos);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@ -129,5 +129,34 @@ namespace ts {
|
||||
},
|
||||
{ sourceMap: true }
|
||||
);
|
||||
|
||||
emitsCorrectly("skipTriviaExternalSourceFiles",
|
||||
[
|
||||
{
|
||||
file: "source.ts",
|
||||
// The source file contains preceding trivia (e.g. whitespace) to try to confuse the `skipSourceTrivia` function.
|
||||
text: " original;"
|
||||
},
|
||||
],
|
||||
{
|
||||
before: [
|
||||
context => node => visitNode(node, function visitor(node: Node): Node {
|
||||
if (isIdentifier(node) && node.text === "original") {
|
||||
const newNode = createIdentifier("changed");
|
||||
setSourceMapRange(newNode, {
|
||||
pos: 0,
|
||||
end: 7,
|
||||
// Do not provide a custom skipTrivia function for `source`.
|
||||
source: createSourceMapSource("another.html", "changed;")
|
||||
});
|
||||
return newNode;
|
||||
}
|
||||
return visitEachChild(node, visitor, context);
|
||||
})
|
||||
]
|
||||
},
|
||||
{ sourceMap: true }
|
||||
);
|
||||
|
||||
});
|
||||
}
|
||||
|
||||
@ -0,0 +1,6 @@
|
||||
// [source.js.map]
|
||||
{"version":3,"file":"source.js","sourceRoot":"","sources":["source.ts","another.html"],"names":[],"mappings":"ACAA,OAAO,CDAW"}
|
||||
|
||||
// [source.js]
|
||||
changed;
|
||||
//# sourceMappingURL=source.js.map
|
||||
Loading…
x
Reference in New Issue
Block a user