Last active
May 30, 2019 08:14
-
-
Save phenomnomnominal/01d1abeac1259434efdbba3b815d7b36 to your computer and use it in GitHub Desktop.
Fourth version of our transform, which keeps all other decorators
This file contains hidden or 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
// 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