Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 18 additions & 6 deletions apps/oxlint/src-js/plugins/visitor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,15 @@
//
// # Visitor objects
//
// Visitor objects which are generated by rules' `create` functions have keys being either:
// * Name of an AST type, or selector. or
// * Name of an AST type or selector, postfixed with `:exit`.
// Visitor objects which are generated by rules' `create` functions have keys being any of:
//
// Each property value must be a function that handles that AST node / selector target.
// 1. Name of an AST type
// 2. Arbitrary selector (e.g. `:matches(BinaryExpression, LogicalExpression)`)
// 3. Name of an AST type, postfixed with `:exit`
// 4. Arbitrary selector, postfixed with `:exit`
// 5. CFG handler name (e.g. `onCodePathStart`)
//
// Each property value must be a function that handles that AST node / selector target / CFG event arguments.
//
// e.g.:
//
Expand All @@ -24,19 +28,23 @@
// '*:exit'(node) {
// // Called when exiting any node
// },
// onCodePathStart(codePath, node) {
// // Called when CFG event occurs
// },
// }
// ```
//
// # Compiled visitor
//
// Compiled visitor is an array with `NODE_TYPES_COUNT` length, keyed by the ID of the node type.
// `NODE_TYPE_IDS_MAP` maps from type name to ID.
// Compiled visitor is an array with `TYPE_IDS_COUNT` length, keyed by the ID of the node type / CFG event.
// `NODE_TYPE_IDS_MAP` maps from type name / CFG event name to ID.
//
// Each element of compiled array is one of:
// * No visitor for this type = `null`.
// * Visitor for leaf node = visit function.
// * Visitor for non-leaf node = object of form `{ enter, exit }`,
// where each property is either a visitor function or `null`.
// * Visitor for CFG event = visit function.
//
// e.g.:
//
Expand All @@ -52,6 +60,9 @@
// exit: null,
// },
// // ...
//
// // CFG events
// function(codePath, node) { /* do stuff */ },
// ]
// ```
//
Expand All @@ -71,6 +82,7 @@
//
// * `{ enter, exit }` objects which are stored in compiled visitor.
// * `VisitProp` objects which are used while compiling visitor.
// * `{ enter: [], exit: [] }` objects which are used while compiling visitor.
// * Temporary array used to store multiple visit functions in `mergeVisitFns`.
//
// The aim is to reduce pressure on the garbage collector. All these recycled objects are long-lived
Expand Down
Loading