Created
August 27, 2023 20:58
-
-
Save alexeychikk/f71b2ad41e885c6aa46170ad1f73c792 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const options = { | |
...this.compilerOptions, | |
target: ts.ScriptTarget.ES5, | |
}; | |
// @ts-expect-error foo | |
const scriptTransformers = ts.getTransformers(options).scriptTransformers; | |
const transformer: ts.TransformerFactory<ts.SourceFile> = (context) => { | |
return (sourceFile) => { | |
const visitor = (node: ts.Node): ts.Node => { | |
if (ts.isParameter(node)) { | |
return context.factory.updateParameterDeclaration( | |
node, | |
node.modifiers, | |
node.dotDotDotToken, | |
'foo', | |
node.questionToken, | |
node.type, | |
node.initializer, | |
); | |
} | |
return ts.visitEachChild(node, visitor, context); | |
}; | |
return ts.visitNode(sourceFile, visitor) as ts.SourceFile; | |
}; | |
}; | |
const customTransformers = scriptTransformers.slice(3, 11); | |
const { transformed } = ts.transform(this.sourceFile, customTransformers); | |
const printer = ts.createPrinter(); | |
const str = printer.printNode( | |
ts.EmitHint.SourceFile, | |
transformed[0], | |
transformed[0], | |
); | |
console.log(str); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment