Design Patterns · Middle · Question 15 of 75
Which pattern does a Babel or ESLint plugin use when it walks the AST with Identifier() and CallExpression() methods?
- ✓Correct answer: Visitor: operations on tree nodes are moved into a separate object
- 2Builder: the plugin creates a new tree from the source one step by step
- 3Adapter: the plugin converts the AST to another compiler's format
Explanation
Visitor lets you add new operations over a structure (checks, transformations) without changing the node classes. The traverser calls the visitor's method for each node type.