Add opt-in behavior for custom transforms to support bundles

This commit is contained in:
Ron Buckton
2019-05-07 15:41:39 -07:00
parent 8c07b40cb6
commit 0c1a283bf9
8 changed files with 109 additions and 39 deletions

View File

@@ -140,22 +140,28 @@ namespace ts {
],
{
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);
})
context => {
const transformSourceFile: Transformer<SourceFile> = 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);
});
return {
transformSourceFile,
transformBundle: node => createBundle(map(node.sourceFiles, transformSourceFile), node.prepends),
};
}
]
},
{ sourceMap: true }
{ sourceMap: true, outFile: "source.js" }
);
});