Skip to content

Instantly share code, notes, and snippets.

@longlho
Created March 31, 2019 19:56
Show Gist options
  • Save longlho/66ff74023b7006ce74c8ac00ef4f4d86 to your computer and use it in GitHub Desktop.
Save longlho/66ff74023b7006ce74c8ac00ef4f4d86 to your computer and use it in GitHub Desktop.
transformer-p4
const visitor: ts.Visitor = (node: ts.Node): ts.Node => {
if (ts.isImportDeclaration(node) && node.moduleSpecifier) {
const newNode = ts.getMutableClone(node) // Clone the node
const oldPathWithQuotes = node.moduleSpecifier.getText(sf)
const newPath = rewritePath(oldPathWithQuotes.slice(1, oldPathWithQuotes.length - 2))
newNode.moduleSpecifier = ts.createStringLiteral(newPath)
ts.setSourceMapRange(newNode, ts.getSourceMapRange(node))
return newNode
}
return ts.visitEachChild(node, visitor)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment