Skip to content

Instantly share code, notes, and snippets.

@phenomnomnominal
Last active May 30, 2019 08:14
Show Gist options
  • Save phenomnomnominal/01d1abeac1259434efdbba3b815d7b36 to your computer and use it in GitHub Desktop.
Save phenomnomnominal/01d1abeac1259434efdbba3b815d7b36 to your computer and use it in GitHub Desktop.
Fourth version of our transform, which keeps all other decorators
// Constants:
// ...
const OTHER_DECORATORS_QUERY = `Decorator:has(Decorator > CallExpression[expression.name!="Value"])`;
export function transformer (source: SourceFile): TransformerFactory<Node> {
// ...
}
export function valueDecoratorToGetterAndSetterFactory (nodes: Array<Node>): TransformerFactory<Node> {
return function (context: TransformationContext): Transformer<Node> {
// ...
function visit (node: Node): Node | Array<Node> {
if (nodes.includes(node)) {
// Create the base structure of the new getter/setter:
// ...
// Re-attach any other decorators:
getter.decorators = tsquery(node, OTHER_DECORATORS_QUERY);
// Return the new AST nodes to replace the old one:
// ...
}
}
};
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment