@liam-hq/cli
Version:
Command-line tool designed to generate a web application that displays ER diagrams. See https://liambx.com/docs/cli
2,573 lines (2,289 loc) • 3.57 MB
JavaScript
#!/usr/bin/env node
import { readFile } from 'node:fs/promises';
import { fileURLToPath, URL as URL$1 } from 'node:url';
import { createRequire } from 'node:module';
import { Command } from 'commander';
import tty from 'node:tty';
import fs, { existsSync, mkdirSync, cpSync } from 'node:fs';
import path, { resolve, dirname, relative } from 'node:path';
import { glob } from 'glob';
import { exit } from 'node:process';
import inquirer from 'inquirer';
import { Transform, render, Text } from 'ink';
import require$$0 from 'os';
import require$$1 from 'tty';
import pkg from '@prisma/internals';
import { parseSync } from '@swc/core';
class ProcessError extends Error {
constructor(message) {
super(message);
this.name = 'ParseError';
}
}
let WarningError$1 = class WarningError extends ProcessError {
constructor(message) {
super(message);
this.name = 'WarningError';
}
};
class UnexpectedTokenWarningError extends WarningError$1 {
constructor(message) {
super(message);
this.name = 'UnexpectedTokenWarningError';
}
}
/* :markup: markdown */
/**
* A class that knows how to walk down the tree. None of the individual visit
* methods are implemented on this visitor, so it forces the consumer to
* implement each one that they need. For a default implementation that
* continues walking the tree, see the `Visitor` class.
*
*/
class BasicVisitor {
/**
* Calls `accept` on the given node if it is not `null`, which in turn should
* call back into this visitor by calling the appropriate `visit*` method.
*
* @param {nodes.Node} node
*/
visit(node) {
node?.accept(this);
}
/**
* Visits each node in `nodes` by calling `accept` on each one.
*
* @param {nodes.Node[]} nodes
*/
visitAll(nodes) {
nodes.forEach((node) => {
node?.accept(this);
});
}
/**
* Visits the child nodes of `node` by calling `accept` on each one.
*
* @param {nodes.Node} node
*/
visitChildNodes(node) {
node.compactChildNodes().forEach((childNode) => {
childNode.accept(this);
});
}
}
/**
* A visitor is a class that provides a default implementation for every accept
* method defined on the nodes. This means it can walk a tree without the
* caller needing to define any special handling. This allows you to handle a
* subset of the tree, while still walking the whole tree.
*
* For example, to find all of the method calls that call the `foo` method, you
* could write:
*
* @example
* class FooCalls extends Visitor {
* visitCallNode(node) {
* if (node.name === "foo") {
* // Do something with the node
* }
*
* // Call super so that the visitor continues walking the tree
* super.visitCallNode(node);
* }
* }
*
*/
class Visitor extends BasicVisitor {
/**
* Visit a AliasGlobalVariableNode node.
*
* @param {nodes.AliasGlobalVariableNode} node
*/
visitAliasGlobalVariableNode(node) {
this.visitChildNodes(node);
}
/**
* Visit a AliasMethodNode node.
*
* @param {nodes.AliasMethodNode} node
*/
visitAliasMethodNode(node) {
this.visitChildNodes(node);
}
/**
* Visit a AlternationPatternNode node.
*
* @param {nodes.AlternationPatternNode} node
*/
visitAlternationPatternNode(node) {
this.visitChildNodes(node);
}
/**
* Visit a AndNode node.
*
* @param {nodes.AndNode} node
*/
visitAndNode(node) {
this.visitChildNodes(node);
}
/**
* Visit a ArgumentsNode node.
*
* @param {nodes.ArgumentsNode} node
*/
visitArgumentsNode(node) {
this.visitChildNodes(node);
}
/**
* Visit a ArrayNode node.
*
* @param {nodes.ArrayNode} node
*/
visitArrayNode(node) {
this.visitChildNodes(node);
}
/**
* Visit a ArrayPatternNode node.
*
* @param {nodes.ArrayPatternNode} node
*/
visitArrayPatternNode(node) {
this.visitChildNodes(node);
}
/**
* Visit a AssocNode node.
*
* @param {nodes.AssocNode} node
*/
visitAssocNode(node) {
this.visitChildNodes(node);
}
/**
* Visit a AssocSplatNode node.
*
* @param {nodes.AssocSplatNode} node
*/
visitAssocSplatNode(node) {
this.visitChildNodes(node);
}
/**
* Visit a BackReferenceReadNode node.
*
* @param {nodes.BackReferenceReadNode} node
*/
visitBackReferenceReadNode(node) {
this.visitChildNodes(node);
}
/**
* Visit a BeginNode node.
*
* @param {nodes.BeginNode} node
*/
visitBeginNode(node) {
this.visitChildNodes(node);
}
/**
* Visit a BlockArgumentNode node.
*
* @param {nodes.BlockArgumentNode} node
*/
visitBlockArgumentNode(node) {
this.visitChildNodes(node);
}
/**
* Visit a BlockLocalVariableNode node.
*
* @param {nodes.BlockLocalVariableNode} node
*/
visitBlockLocalVariableNode(node) {
this.visitChildNodes(node);
}
/**
* Visit a BlockNode node.
*
* @param {nodes.BlockNode} node
*/
visitBlockNode(node) {
this.visitChildNodes(node);
}
/**
* Visit a BlockParameterNode node.
*
* @param {nodes.BlockParameterNode} node
*/
visitBlockParameterNode(node) {
this.visitChildNodes(node);
}
/**
* Visit a BlockParametersNode node.
*
* @param {nodes.BlockParametersNode} node
*/
visitBlockParametersNode(node) {
this.visitChildNodes(node);
}
/**
* Visit a BreakNode node.
*
* @param {nodes.BreakNode} node
*/
visitBreakNode(node) {
this.visitChildNodes(node);
}
/**
* Visit a CallAndWriteNode node.
*
* @param {nodes.CallAndWriteNode} node
*/
visitCallAndWriteNode(node) {
this.visitChildNodes(node);
}
/**
* Visit a CallNode node.
*
* @param {nodes.CallNode} node
*/
visitCallNode(node) {
this.visitChildNodes(node);
}
/**
* Visit a CallOperatorWriteNode node.
*
* @param {nodes.CallOperatorWriteNode} node
*/
visitCallOperatorWriteNode(node) {
this.visitChildNodes(node);
}
/**
* Visit a CallOrWriteNode node.
*
* @param {nodes.CallOrWriteNode} node
*/
visitCallOrWriteNode(node) {
this.visitChildNodes(node);
}
/**
* Visit a CallTargetNode node.
*
* @param {nodes.CallTargetNode} node
*/
visitCallTargetNode(node) {
this.visitChildNodes(node);
}
/**
* Visit a CapturePatternNode node.
*
* @param {nodes.CapturePatternNode} node
*/
visitCapturePatternNode(node) {
this.visitChildNodes(node);
}
/**
* Visit a CaseMatchNode node.
*
* @param {nodes.CaseMatchNode} node
*/
visitCaseMatchNode(node) {
this.visitChildNodes(node);
}
/**
* Visit a CaseNode node.
*
* @param {nodes.CaseNode} node
*/
visitCaseNode(node) {
this.visitChildNodes(node);
}
/**
* Visit a ClassNode node.
*
* @param {nodes.ClassNode} node
*/
visitClassNode(node) {
this.visitChildNodes(node);
}
/**
* Visit a ClassVariableAndWriteNode node.
*
* @param {nodes.ClassVariableAndWriteNode} node
*/
visitClassVariableAndWriteNode(node) {
this.visitChildNodes(node);
}
/**
* Visit a ClassVariableOperatorWriteNode node.
*
* @param {nodes.ClassVariableOperatorWriteNode} node
*/
visitClassVariableOperatorWriteNode(node) {
this.visitChildNodes(node);
}
/**
* Visit a ClassVariableOrWriteNode node.
*
* @param {nodes.ClassVariableOrWriteNode} node
*/
visitClassVariableOrWriteNode(node) {
this.visitChildNodes(node);
}
/**
* Visit a ClassVariableReadNode node.
*
* @param {nodes.ClassVariableReadNode} node
*/
visitClassVariableReadNode(node) {
this.visitChildNodes(node);
}
/**
* Visit a ClassVariableTargetNode node.
*
* @param {nodes.ClassVariableTargetNode} node
*/
visitClassVariableTargetNode(node) {
this.visitChildNodes(node);
}
/**
* Visit a ClassVariableWriteNode node.
*
* @param {nodes.ClassVariableWriteNode} node
*/
visitClassVariableWriteNode(node) {
this.visitChildNodes(node);
}
/**
* Visit a ConstantAndWriteNode node.
*
* @param {nodes.ConstantAndWriteNode} node
*/
visitConstantAndWriteNode(node) {
this.visitChildNodes(node);
}
/**
* Visit a ConstantOperatorWriteNode node.
*
* @param {nodes.ConstantOperatorWriteNode} node
*/
visitConstantOperatorWriteNode(node) {
this.visitChildNodes(node);
}
/**
* Visit a ConstantOrWriteNode node.
*
* @param {nodes.ConstantOrWriteNode} node
*/
visitConstantOrWriteNode(node) {
this.visitChildNodes(node);
}
/**
* Visit a ConstantPathAndWriteNode node.
*
* @param {nodes.ConstantPathAndWriteNode} node
*/
visitConstantPathAndWriteNode(node) {
this.visitChildNodes(node);
}
/**
* Visit a ConstantPathNode node.
*
* @param {nodes.ConstantPathNode} node
*/
visitConstantPathNode(node) {
this.visitChildNodes(node);
}
/**
* Visit a ConstantPathOperatorWriteNode node.
*
* @param {nodes.ConstantPathOperatorWriteNode} node
*/
visitConstantPathOperatorWriteNode(node) {
this.visitChildNodes(node);
}
/**
* Visit a ConstantPathOrWriteNode node.
*
* @param {nodes.ConstantPathOrWriteNode} node
*/
visitConstantPathOrWriteNode(node) {
this.visitChildNodes(node);
}
/**
* Visit a ConstantPathTargetNode node.
*
* @param {nodes.ConstantPathTargetNode} node
*/
visitConstantPathTargetNode(node) {
this.visitChildNodes(node);
}
/**
* Visit a ConstantPathWriteNode node.
*
* @param {nodes.ConstantPathWriteNode} node
*/
visitConstantPathWriteNode(node) {
this.visitChildNodes(node);
}
/**
* Visit a ConstantReadNode node.
*
* @param {nodes.ConstantReadNode} node
*/
visitConstantReadNode(node) {
this.visitChildNodes(node);
}
/**
* Visit a ConstantTargetNode node.
*
* @param {nodes.ConstantTargetNode} node
*/
visitConstantTargetNode(node) {
this.visitChildNodes(node);
}
/**
* Visit a ConstantWriteNode node.
*
* @param {nodes.ConstantWriteNode} node
*/
visitConstantWriteNode(node) {
this.visitChildNodes(node);
}
/**
* Visit a DefNode node.
*
* @param {nodes.DefNode} node
*/
visitDefNode(node) {
this.visitChildNodes(node);
}
/**
* Visit a DefinedNode node.
*
* @param {nodes.DefinedNode} node
*/
visitDefinedNode(node) {
this.visitChildNodes(node);
}
/**
* Visit a ElseNode node.
*
* @param {nodes.ElseNode} node
*/
visitElseNode(node) {
this.visitChildNodes(node);
}
/**
* Visit a EmbeddedStatementsNode node.
*
* @param {nodes.EmbeddedStatementsNode} node
*/
visitEmbeddedStatementsNode(node) {
this.visitChildNodes(node);
}
/**
* Visit a EmbeddedVariableNode node.
*
* @param {nodes.EmbeddedVariableNode} node
*/
visitEmbeddedVariableNode(node) {
this.visitChildNodes(node);
}
/**
* Visit a EnsureNode node.
*
* @param {nodes.EnsureNode} node
*/
visitEnsureNode(node) {
this.visitChildNodes(node);
}
/**
* Visit a FalseNode node.
*
* @param {nodes.FalseNode} node
*/
visitFalseNode(node) {
this.visitChildNodes(node);
}
/**
* Visit a FindPatternNode node.
*
* @param {nodes.FindPatternNode} node
*/
visitFindPatternNode(node) {
this.visitChildNodes(node);
}
/**
* Visit a FlipFlopNode node.
*
* @param {nodes.FlipFlopNode} node
*/
visitFlipFlopNode(node) {
this.visitChildNodes(node);
}
/**
* Visit a FloatNode node.
*
* @param {nodes.FloatNode} node
*/
visitFloatNode(node) {
this.visitChildNodes(node);
}
/**
* Visit a ForNode node.
*
* @param {nodes.ForNode} node
*/
visitForNode(node) {
this.visitChildNodes(node);
}
/**
* Visit a ForwardingArgumentsNode node.
*
* @param {nodes.ForwardingArgumentsNode} node
*/
visitForwardingArgumentsNode(node) {
this.visitChildNodes(node);
}
/**
* Visit a ForwardingParameterNode node.
*
* @param {nodes.ForwardingParameterNode} node
*/
visitForwardingParameterNode(node) {
this.visitChildNodes(node);
}
/**
* Visit a ForwardingSuperNode node.
*
* @param {nodes.ForwardingSuperNode} node
*/
visitForwardingSuperNode(node) {
this.visitChildNodes(node);
}
/**
* Visit a GlobalVariableAndWriteNode node.
*
* @param {nodes.GlobalVariableAndWriteNode} node
*/
visitGlobalVariableAndWriteNode(node) {
this.visitChildNodes(node);
}
/**
* Visit a GlobalVariableOperatorWriteNode node.
*
* @param {nodes.GlobalVariableOperatorWriteNode} node
*/
visitGlobalVariableOperatorWriteNode(node) {
this.visitChildNodes(node);
}
/**
* Visit a GlobalVariableOrWriteNode node.
*
* @param {nodes.GlobalVariableOrWriteNode} node
*/
visitGlobalVariableOrWriteNode(node) {
this.visitChildNodes(node);
}
/**
* Visit a GlobalVariableReadNode node.
*
* @param {nodes.GlobalVariableReadNode} node
*/
visitGlobalVariableReadNode(node) {
this.visitChildNodes(node);
}
/**
* Visit a GlobalVariableTargetNode node.
*
* @param {nodes.GlobalVariableTargetNode} node
*/
visitGlobalVariableTargetNode(node) {
this.visitChildNodes(node);
}
/**
* Visit a GlobalVariableWriteNode node.
*
* @param {nodes.GlobalVariableWriteNode} node
*/
visitGlobalVariableWriteNode(node) {
this.visitChildNodes(node);
}
/**
* Visit a HashNode node.
*
* @param {nodes.HashNode} node
*/
visitHashNode(node) {
this.visitChildNodes(node);
}
/**
* Visit a HashPatternNode node.
*
* @param {nodes.HashPatternNode} node
*/
visitHashPatternNode(node) {
this.visitChildNodes(node);
}
/**
* Visit a IfNode node.
*
* @param {nodes.IfNode} node
*/
visitIfNode(node) {
this.visitChildNodes(node);
}
/**
* Visit a ImaginaryNode node.
*
* @param {nodes.ImaginaryNode} node
*/
visitImaginaryNode(node) {
this.visitChildNodes(node);
}
/**
* Visit a ImplicitNode node.
*
* @param {nodes.ImplicitNode} node
*/
visitImplicitNode(node) {
this.visitChildNodes(node);
}
/**
* Visit a ImplicitRestNode node.
*
* @param {nodes.ImplicitRestNode} node
*/
visitImplicitRestNode(node) {
this.visitChildNodes(node);
}
/**
* Visit a InNode node.
*
* @param {nodes.InNode} node
*/
visitInNode(node) {
this.visitChildNodes(node);
}
/**
* Visit a IndexAndWriteNode node.
*
* @param {nodes.IndexAndWriteNode} node
*/
visitIndexAndWriteNode(node) {
this.visitChildNodes(node);
}
/**
* Visit a IndexOperatorWriteNode node.
*
* @param {nodes.IndexOperatorWriteNode} node
*/
visitIndexOperatorWriteNode(node) {
this.visitChildNodes(node);
}
/**
* Visit a IndexOrWriteNode node.
*
* @param {nodes.IndexOrWriteNode} node
*/
visitIndexOrWriteNode(node) {
this.visitChildNodes(node);
}
/**
* Visit a IndexTargetNode node.
*
* @param {nodes.IndexTargetNode} node
*/
visitIndexTargetNode(node) {
this.visitChildNodes(node);
}
/**
* Visit a InstanceVariableAndWriteNode node.
*
* @param {nodes.InstanceVariableAndWriteNode} node
*/
visitInstanceVariableAndWriteNode(node) {
this.visitChildNodes(node);
}
/**
* Visit a InstanceVariableOperatorWriteNode node.
*
* @param {nodes.InstanceVariableOperatorWriteNode} node
*/
visitInstanceVariableOperatorWriteNode(node) {
this.visitChildNodes(node);
}
/**
* Visit a InstanceVariableOrWriteNode node.
*
* @param {nodes.InstanceVariableOrWriteNode} node
*/
visitInstanceVariableOrWriteNode(node) {
this.visitChildNodes(node);
}
/**
* Visit a InstanceVariableReadNode node.
*
* @param {nodes.InstanceVariableReadNode} node
*/
visitInstanceVariableReadNode(node) {
this.visitChildNodes(node);
}
/**
* Visit a InstanceVariableTargetNode node.
*
* @param {nodes.InstanceVariableTargetNode} node
*/
visitInstanceVariableTargetNode(node) {
this.visitChildNodes(node);
}
/**
* Visit a InstanceVariableWriteNode node.
*
* @param {nodes.InstanceVariableWriteNode} node
*/
visitInstanceVariableWriteNode(node) {
this.visitChildNodes(node);
}
/**
* Visit a IntegerNode node.
*
* @param {nodes.IntegerNode} node
*/
visitIntegerNode(node) {
this.visitChildNodes(node);
}
/**
* Visit a InterpolatedMatchLastLineNode node.
*
* @param {nodes.InterpolatedMatchLastLineNode} node
*/
visitInterpolatedMatchLastLineNode(node) {
this.visitChildNodes(node);
}
/**
* Visit a InterpolatedRegularExpressionNode node.
*
* @param {nodes.InterpolatedRegularExpressionNode} node
*/
visitInterpolatedRegularExpressionNode(node) {
this.visitChildNodes(node);
}
/**
* Visit a InterpolatedStringNode node.
*
* @param {nodes.InterpolatedStringNode} node
*/
visitInterpolatedStringNode(node) {
this.visitChildNodes(node);
}
/**
* Visit a InterpolatedSymbolNode node.
*
* @param {nodes.InterpolatedSymbolNode} node
*/
visitInterpolatedSymbolNode(node) {
this.visitChildNodes(node);
}
/**
* Visit a InterpolatedXStringNode node.
*
* @param {nodes.InterpolatedXStringNode} node
*/
visitInterpolatedXStringNode(node) {
this.visitChildNodes(node);
}
/**
* Visit a ItLocalVariableReadNode node.
*
* @param {nodes.ItLocalVariableReadNode} node
*/
visitItLocalVariableReadNode(node) {
this.visitChildNodes(node);
}
/**
* Visit a ItParametersNode node.
*
* @param {nodes.ItParametersNode} node
*/
visitItParametersNode(node) {
this.visitChildNodes(node);
}
/**
* Visit a KeywordHashNode node.
*
* @param {nodes.KeywordHashNode} node
*/
visitKeywordHashNode(node) {
this.visitChildNodes(node);
}
/**
* Visit a KeywordRestParameterNode node.
*
* @param {nodes.KeywordRestParameterNode} node
*/
visitKeywordRestParameterNode(node) {
this.visitChildNodes(node);
}
/**
* Visit a LambdaNode node.
*
* @param {nodes.LambdaNode} node
*/
visitLambdaNode(node) {
this.visitChildNodes(node);
}
/**
* Visit a LocalVariableAndWriteNode node.
*
* @param {nodes.LocalVariableAndWriteNode} node
*/
visitLocalVariableAndWriteNode(node) {
this.visitChildNodes(node);
}
/**
* Visit a LocalVariableOperatorWriteNode node.
*
* @param {nodes.LocalVariableOperatorWriteNode} node
*/
visitLocalVariableOperatorWriteNode(node) {
this.visitChildNodes(node);
}
/**
* Visit a LocalVariableOrWriteNode node.
*
* @param {nodes.LocalVariableOrWriteNode} node
*/
visitLocalVariableOrWriteNode(node) {
this.visitChildNodes(node);
}
/**
* Visit a LocalVariableReadNode node.
*
* @param {nodes.LocalVariableReadNode} node
*/
visitLocalVariableReadNode(node) {
this.visitChildNodes(node);
}
/**
* Visit a LocalVariableTargetNode node.
*
* @param {nodes.LocalVariableTargetNode} node
*/
visitLocalVariableTargetNode(node) {
this.visitChildNodes(node);
}
/**
* Visit a LocalVariableWriteNode node.
*
* @param {nodes.LocalVariableWriteNode} node
*/
visitLocalVariableWriteNode(node) {
this.visitChildNodes(node);
}
/**
* Visit a MatchLastLineNode node.
*
* @param {nodes.MatchLastLineNode} node
*/
visitMatchLastLineNode(node) {
this.visitChildNodes(node);
}
/**
* Visit a MatchPredicateNode node.
*
* @param {nodes.MatchPredicateNode} node
*/
visitMatchPredicateNode(node) {
this.visitChildNodes(node);
}
/**
* Visit a MatchRequiredNode node.
*
* @param {nodes.MatchRequiredNode} node
*/
visitMatchRequiredNode(node) {
this.visitChildNodes(node);
}
/**
* Visit a MatchWriteNode node.
*
* @param {nodes.MatchWriteNode} node
*/
visitMatchWriteNode(node) {
this.visitChildNodes(node);
}
/**
* Visit a MissingNode node.
*
* @param {nodes.MissingNode} node
*/
visitMissingNode(node) {
this.visitChildNodes(node);
}
/**
* Visit a ModuleNode node.
*
* @param {nodes.ModuleNode} node
*/
visitModuleNode(node) {
this.visitChildNodes(node);
}
/**
* Visit a MultiTargetNode node.
*
* @param {nodes.MultiTargetNode} node
*/
visitMultiTargetNode(node) {
this.visitChildNodes(node);
}
/**
* Visit a MultiWriteNode node.
*
* @param {nodes.MultiWriteNode} node
*/
visitMultiWriteNode(node) {
this.visitChildNodes(node);
}
/**
* Visit a NextNode node.
*
* @param {nodes.NextNode} node
*/
visitNextNode(node) {
this.visitChildNodes(node);
}
/**
* Visit a NilNode node.
*
* @param {nodes.NilNode} node
*/
visitNilNode(node) {
this.visitChildNodes(node);
}
/**
* Visit a NoKeywordsParameterNode node.
*
* @param {nodes.NoKeywordsParameterNode} node
*/
visitNoKeywordsParameterNode(node) {
this.visitChildNodes(node);
}
/**
* Visit a NumberedParametersNode node.
*
* @param {nodes.NumberedParametersNode} node
*/
visitNumberedParametersNode(node) {
this.visitChildNodes(node);
}
/**
* Visit a NumberedReferenceReadNode node.
*
* @param {nodes.NumberedReferenceReadNode} node
*/
visitNumberedReferenceReadNode(node) {
this.visitChildNodes(node);
}
/**
* Visit a OptionalKeywordParameterNode node.
*
* @param {nodes.OptionalKeywordParameterNode} node
*/
visitOptionalKeywordParameterNode(node) {
this.visitChildNodes(node);
}
/**
* Visit a OptionalParameterNode node.
*
* @param {nodes.OptionalParameterNode} node
*/
visitOptionalParameterNode(node) {
this.visitChildNodes(node);
}
/**
* Visit a OrNode node.
*
* @param {nodes.OrNode} node
*/
visitOrNode(node) {
this.visitChildNodes(node);
}
/**
* Visit a ParametersNode node.
*
* @param {nodes.ParametersNode} node
*/
visitParametersNode(node) {
this.visitChildNodes(node);
}
/**
* Visit a ParenthesesNode node.
*
* @param {nodes.ParenthesesNode} node
*/
visitParenthesesNode(node) {
this.visitChildNodes(node);
}
/**
* Visit a PinnedExpressionNode node.
*
* @param {nodes.PinnedExpressionNode} node
*/
visitPinnedExpressionNode(node) {
this.visitChildNodes(node);
}
/**
* Visit a PinnedVariableNode node.
*
* @param {nodes.PinnedVariableNode} node
*/
visitPinnedVariableNode(node) {
this.visitChildNodes(node);
}
/**
* Visit a PostExecutionNode node.
*
* @param {nodes.PostExecutionNode} node
*/
visitPostExecutionNode(node) {
this.visitChildNodes(node);
}
/**
* Visit a PreExecutionNode node.
*
* @param {nodes.PreExecutionNode} node
*/
visitPreExecutionNode(node) {
this.visitChildNodes(node);
}
/**
* Visit a ProgramNode node.
*
* @param {nodes.ProgramNode} node
*/
visitProgramNode(node) {
this.visitChildNodes(node);
}
/**
* Visit a RangeNode node.
*
* @param {nodes.RangeNode} node
*/
visitRangeNode(node) {
this.visitChildNodes(node);
}
/**
* Visit a RationalNode node.
*
* @param {nodes.RationalNode} node
*/
visitRationalNode(node) {
this.visitChildNodes(node);
}
/**
* Visit a RedoNode node.
*
* @param {nodes.RedoNode} node
*/
visitRedoNode(node) {
this.visitChildNodes(node);
}
/**
* Visit a RegularExpressionNode node.
*
* @param {nodes.RegularExpressionNode} node
*/
visitRegularExpressionNode(node) {
this.visitChildNodes(node);
}
/**
* Visit a RequiredKeywordParameterNode node.
*
* @param {nodes.RequiredKeywordParameterNode} node
*/
visitRequiredKeywordParameterNode(node) {
this.visitChildNodes(node);
}
/**
* Visit a RequiredParameterNode node.
*
* @param {nodes.RequiredParameterNode} node
*/
visitRequiredParameterNode(node) {
this.visitChildNodes(node);
}
/**
* Visit a RescueModifierNode node.
*
* @param {nodes.RescueModifierNode} node
*/
visitRescueModifierNode(node) {
this.visitChildNodes(node);
}
/**
* Visit a RescueNode node.
*
* @param {nodes.RescueNode} node
*/
visitRescueNode(node) {
this.visitChildNodes(node);
}
/**
* Visit a RestParameterNode node.
*
* @param {nodes.RestParameterNode} node
*/
visitRestParameterNode(node) {
this.visitChildNodes(node);
}
/**
* Visit a RetryNode node.
*
* @param {nodes.RetryNode} node
*/
visitRetryNode(node) {
this.visitChildNodes(node);
}
/**
* Visit a ReturnNode node.
*
* @param {nodes.ReturnNode} node
*/
visitReturnNode(node) {
this.visitChildNodes(node);
}
/**
* Visit a SelfNode node.
*
* @param {nodes.SelfNode} node
*/
visitSelfNode(node) {
this.visitChildNodes(node);
}
/**
* Visit a ShareableConstantNode node.
*
* @param {nodes.ShareableConstantNode} node
*/
visitShareableConstantNode(node) {
this.visitChildNodes(node);
}
/**
* Visit a SingletonClassNode node.
*
* @param {nodes.SingletonClassNode} node
*/
visitSingletonClassNode(node) {
this.visitChildNodes(node);
}
/**
* Visit a SourceEncodingNode node.
*
* @param {nodes.SourceEncodingNode} node
*/
visitSourceEncodingNode(node) {
this.visitChildNodes(node);
}
/**
* Visit a SourceFileNode node.
*
* @param {nodes.SourceFileNode} node
*/
visitSourceFileNode(node) {
this.visitChildNodes(node);
}
/**
* Visit a SourceLineNode node.
*
* @param {nodes.SourceLineNode} node
*/
visitSourceLineNode(node) {
this.visitChildNodes(node);
}
/**
* Visit a SplatNode node.
*
* @param {nodes.SplatNode} node
*/
visitSplatNode(node) {
this.visitChildNodes(node);
}
/**
* Visit a StatementsNode node.
*
* @param {nodes.StatementsNode} node
*/
visitStatementsNode(node) {
this.visitChildNodes(node);
}
/**
* Visit a StringNode node.
*
* @param {nodes.StringNode} node
*/
visitStringNode(node) {
this.visitChildNodes(node);
}
/**
* Visit a SuperNode node.
*
* @param {nodes.SuperNode} node
*/
visitSuperNode(node) {
this.visitChildNodes(node);
}
/**
* Visit a SymbolNode node.
*
* @param {nodes.SymbolNode} node
*/
visitSymbolNode(node) {
this.visitChildNodes(node);
}
/**
* Visit a TrueNode node.
*
* @param {nodes.TrueNode} node
*/
visitTrueNode(node) {
this.visitChildNodes(node);
}
/**
* Visit a UndefNode node.
*
* @param {nodes.UndefNode} node
*/
visitUndefNode(node) {
this.visitChildNodes(node);
}
/**
* Visit a UnlessNode node.
*
* @param {nodes.UnlessNode} node
*/
visitUnlessNode(node) {
this.visitChildNodes(node);
}
/**
* Visit a UntilNode node.
*
* @param {nodes.UntilNode} node
*/
visitUntilNode(node) {
this.visitChildNodes(node);
}
/**
* Visit a WhenNode node.
*
* @param {nodes.WhenNode} node
*/
visitWhenNode(node) {
this.visitChildNodes(node);
}
/**
* Visit a WhileNode node.
*
* @param {nodes.WhileNode} node
*/
visitWhileNode(node) {
this.visitChildNodes(node);
}
/**
* Visit a XStringNode node.
*
* @param {nodes.XStringNode} node
*/
visitXStringNode(node) {
this.visitChildNodes(node);
}
/**
* Visit a YieldNode node.
*
* @param {nodes.YieldNode} node
*/
visitYieldNode(node) {
this.visitChildNodes(node);
}
}
/* :markup: markdown */
/**
* Flags for arguments nodes.
*/
const ArgumentsNodeFlags = {
CONTAINS_FORWARDING: 1 << 2,
CONTAINS_KEYWORDS: 1 << 3,
CONTAINS_KEYWORD_SPLAT: 1 << 4,
CONTAINS_SPLAT: 1 << 5,
CONTAINS_MULTIPLE_SPLATS: 1 << 6,
};
/**
* Flags for array nodes.
*/
const ArrayNodeFlags = {
CONTAINS_SPLAT: 1 << 2,
};
/**
* Flags for call nodes.
*/
const CallNodeFlags = {
SAFE_NAVIGATION: 1 << 2,
VARIABLE_CALL: 1 << 3,
ATTRIBUTE_WRITE: 1 << 4,
IGNORE_VISIBILITY: 1 << 5,
};
/**
* Flags for nodes that have unescaped content.
*/
const EncodingFlags = {
FORCED_UTF8_ENCODING: 1 << 2,
FORCED_BINARY_ENCODING: 1 << 3,
};
/**
* Flags for integer nodes that correspond to the base of the integer.
*/
const IntegerBaseFlags = {
BINARY: 1 << 2,
DECIMAL: 1 << 3,
OCTAL: 1 << 4,
HEXADECIMAL: 1 << 5,
};
/**
* Flags for interpolated string nodes that indicated mutability if they are also marked as literals.
*/
const InterpolatedStringNodeFlags = {
FROZEN: 1 << 2,
MUTABLE: 1 << 3,
};
/**
* Flags for keyword hash nodes.
*/
const KeywordHashNodeFlags = {
SYMBOL_KEYS: 1 << 2,
};
/**
* Flags for while and until loop nodes.
*/
const LoopFlags = {
BEGIN_MODIFIER: 1 << 2,
};
/**
* Flags for parameter nodes.
*/
const ParameterFlags = {
REPEATED_PARAMETER: 1 << 2,
};
/**
* Flags for parentheses nodes.
*/
const ParenthesesNodeFlags = {
MULTIPLE_STATEMENTS: 1 << 2,
};
/**
* Flags for range and flip-flop nodes.
*/
const RangeFlags = {
EXCLUDE_END: 1 << 2,
};
/**
* Flags for regular expression and match last line nodes.
*/
const RegularExpressionFlags = {
IGNORE_CASE: 1 << 2,
EXTENDED: 1 << 3,
MULTI_LINE: 1 << 4,
ONCE: 1 << 5,
EUC_JP: 1 << 6,
ASCII_8BIT: 1 << 7,
WINDOWS_31J: 1 << 8,
UTF_8: 1 << 9,
FORCED_UTF8_ENCODING: 1 << 10,
FORCED_BINARY_ENCODING: 1 << 11,
FORCED_US_ASCII_ENCODING: 1 << 12,
};
/**
* Flags for shareable constant nodes.
*/
const ShareableConstantNodeFlags = {
LITERAL: 1 << 2,
EXPERIMENTAL_EVERYTHING: 1 << 3,
EXPERIMENTAL_COPY: 1 << 4,
};
/**
* Flags for string nodes.
*/
const StringFlags = {
FORCED_UTF8_ENCODING: 1 << 2,
FORCED_BINARY_ENCODING: 1 << 3,
FROZEN: 1 << 4,
MUTABLE: 1 << 5,
};
/**
* Flags for symbol nodes.
*/
const SymbolFlags = {
FORCED_UTF8_ENCODING: 1 << 2,
FORCED_BINARY_ENCODING: 1 << 3,
FORCED_US_ASCII_ENCODING: 1 << 4,
};
/**
* A location in the source code.
*
* @typedef {{ startOffset: number, length: number }} Location
*/
/**
* An encoded Ruby string.
*
* @typedef {{ value: string, encoding: string, validEncoding: boolean }} RubyString
*/
/**
* A generic node in the tree.
*
* @typedef {(AliasGlobalVariableNode|AliasMethodNode|AlternationPatternNode|AndNode|ArgumentsNode|ArrayNode|ArrayPatternNode|AssocNode|AssocSplatNode|BackReferenceReadNode|BeginNode|BlockArgumentNode|BlockLocalVariableNode|BlockNode|BlockParameterNode|BlockParametersNode|BreakNode|CallAndWriteNode|CallNode|CallOperatorWriteNode|CallOrWriteNode|CallTargetNode|CapturePatternNode|CaseMatchNode|CaseNode|ClassNode|ClassVariableAndWriteNode|ClassVariableOperatorWriteNode|ClassVariableOrWriteNode|ClassVariableReadNode|ClassVariableTargetNode|ClassVariableWriteNode|ConstantAndWriteNode|ConstantOperatorWriteNode|ConstantOrWriteNode|ConstantPathAndWriteNode|ConstantPathNode|ConstantPathOperatorWriteNode|ConstantPathOrWriteNode|ConstantPathTargetNode|ConstantPathWriteNode|ConstantReadNode|ConstantTargetNode|ConstantWriteNode|DefNode|DefinedNode|ElseNode|EmbeddedStatementsNode|EmbeddedVariableNode|EnsureNode|FalseNode|FindPatternNode|FlipFlopNode|FloatNode|ForNode|ForwardingArgumentsNode|ForwardingParameterNode|ForwardingSuperNode|GlobalVariableAndWriteNode|GlobalVariableOperatorWriteNode|GlobalVariableOrWriteNode|GlobalVariableReadNode|GlobalVariableTargetNode|GlobalVariableWriteNode|HashNode|HashPatternNode|IfNode|ImaginaryNode|ImplicitNode|ImplicitRestNode|InNode|IndexAndWriteNode|IndexOperatorWriteNode|IndexOrWriteNode|IndexTargetNode|InstanceVariableAndWriteNode|InstanceVariableOperatorWriteNode|InstanceVariableOrWriteNode|InstanceVariableReadNode|InstanceVariableTargetNode|InstanceVariableWriteNode|IntegerNode|InterpolatedMatchLastLineNode|InterpolatedRegularExpressionNode|InterpolatedStringNode|InterpolatedSymbolNode|InterpolatedXStringNode|ItLocalVariableReadNode|ItParametersNode|KeywordHashNode|KeywordRestParameterNode|LambdaNode|LocalVariableAndWriteNode|LocalVariableOperatorWriteNode|LocalVariableOrWriteNode|LocalVariableReadNode|LocalVariableTargetNode|LocalVariableWriteNode|MatchLastLineNode|MatchPredicateNode|MatchRequiredNode|MatchWriteNode|MissingNode|ModuleNode|MultiTargetNode|MultiWriteNode|NextNode|NilNode|NoKeywordsParameterNode|NumberedParametersNode|NumberedReferenceReadNode|OptionalKeywordParameterNode|OptionalParameterNode|OrNode|ParametersNode|ParenthesesNode|PinnedExpressionNode|PinnedVariableNode|PostExecutionNode|PreExecutionNode|ProgramNode|RangeNode|RationalNode|RedoNode|RegularExpressionNode|RequiredKeywordParameterNode|RequiredParameterNode|RescueModifierNode|RescueNode|RestParameterNode|RetryNode|ReturnNode|SelfNode|ShareableConstantNode|SingletonClassNode|SourceEncodingNode|SourceFileNode|SourceLineNode|SplatNode|StatementsNode|StringNode|SuperNode|SymbolNode|TrueNode|UndefNode|UnlessNode|UntilNode|WhenNode|WhileNode|XStringNode|YieldNode)} Node
*/
/**
* Represents the use of the `alias` keyword to alias a global variable.
*
* alias $foo $bar
* ^^^^^^^^^^^^^^^
*/
class AliasGlobalVariableNode {
/**
* @type number
*/
nodeID;
/**
* @type {Location}
*/
location;
/**
* @type number
*/
#flags;
/**
* @type Node
*/
newName;
/**
* @type Node
*/
oldName;
/**
* @type Location
*/
keywordLoc;
/**
* Construct a new AliasGlobalVariableNode.
*
* @param {number} nodeID
* @param {Location} location
* @param {number} flags
* @param {Node} newName
* @param {Node} oldName
* @param {Location} keywordLoc
*/
constructor(nodeID, location, flags, newName, oldName, keywordLoc) {
this.nodeID = nodeID;
this.location = location;
this.#flags = flags;
this.newName = newName;
this.oldName = oldName;
this.keywordLoc = keywordLoc;
}
/**
* Accept a visitor for this node.
*
* @param {visitors.Visitor} visitor
*/
accept(visitor) {
visitor.visitAliasGlobalVariableNode(this);
}
/**
* Returns all child nodes of the current node.
*
* @returns {(Node | null)[]} An array of child nodes.
*/
childNodes() {
return [this.newName, this.oldName]
}
/**
* Compact and return an array of child nodes.
*
* @returns {Node[]} An array of compacted child nodes.
*/
compactChildNodes() {
return [this.newName, this.oldName];
}
/**
* Transforms the Node to a JavaScript object.
*
* @returns {Object}
*/
toJSON() {
return {
type: "AliasGlobalVariableNode",
location: this.location,
flags: this.#flags,
newName: this.newName,
oldName: this.oldName,
keywordLoc: this.keywordLoc,
};
}
}
/**
* Represents the use of the `alias` keyword to alias a method.
*
* alias foo bar
* ^^^^^^^^^^^^^
*/
class AliasMethodNode {
/**
* @type number
*/
nodeID;
/**
* @type {Location}
*/
location;
/**
* @type number
*/
#flags;
/**
* @type Node
*/
newName;
/**
* @type Node
*/
oldName;
/**
* @type Location
*/
keywordLoc;
/**
* Construct a new AliasMethodNode.
*
* @param {number} nodeID
* @param {Location} location
* @param {number} flags
* @param {Node} newName
* @param {Node} oldName
* @param {Location} keywordLoc
*/
constructor(nodeID, location, flags, newName, oldName, keywordLoc) {
this.nodeID = nodeID;
this.location = location;
this.#flags = flags;
this.newName = newName;
this.oldName = oldName;
this.keywordLoc = keywordLoc;
}
/**
* Accept a visitor for this node.
*
* @param {visitors.Visitor} visitor
*/
accept(visitor) {
visitor.visitAliasMethodNode(this);
}
/**
* Returns all child nodes of the current node.
*
* @returns {(Node | null)[]} An array of child nodes.
*/
childNodes() {
return [this.newName, this.oldName]
}
/**
* Compact and return an array of child nodes.
*
* @returns {Node[]} An array of compacted child nodes.
*/
compactChildNodes() {
return [this.newName, this.oldName];
}
/**
* Transforms the Node to a JavaScript object.
*
* @returns {Object}
*/
toJSON() {
return {
type: "AliasMethodNode",
location: this.location,
flags: this.#flags,
newName: this.newName,
oldName: this.oldName,
keywordLoc: this.keywordLoc,
};
}
}
/**
* Represents an alternation pattern in pattern matching.
*
* foo => bar | baz
* ^^^^^^^^^
*/
class AlternationPatternNode {
/**
* @type number
*/
nodeID;
/**
* @type {Location}
*/
location;
/**
* @type number
*/
#flags;
/**
* @type Node
*/
left;
/**
* @type Node
*/
right;
/**
* @type Location
*/
operatorLoc;
/**
* Construct a new AlternationPatternNode.
*
* @param {number} nodeID
* @param {Location} location
* @param {number} flags
* @param {Node} left
* @param {Node} right
* @param {Location} operatorLoc
*/
constructor(nodeID, location, flags, left, right, operatorLoc) {
this.nodeID = nodeID;
this.location = location;
this.#flags = flags;
this.left = left;
this.right = right;
this.operatorLoc = operatorLoc;
}
/**
* Accept a visitor for this node.
*
* @param {visitors.Visitor} visitor
*/
accept(visitor) {
visitor.visitAlternationPatternNode(this);
}
/**
* Returns all child nodes of the current node.
*
* @returns {(Node | null)[]} An array of child nodes.
*/
childNodes() {
return [this.left, this.right]
}
/**
* Compact and return an array of child nodes.
*
* @returns {Node[]} An array of compacted child nodes.
*/
compactChildNodes() {
return [this.left, this.right];
}
/**
* Transforms the Node to a JavaScript object.
*
* @returns {Object}
*/
toJSON() {
return {
type: "AlternationPatternNode",
location: this.location,
flags: this.#flags,
left: this.left,
right: this.right,
operatorLoc: this.operatorLoc,
};
}
}
/**
* Represents the use of the `&&` operator or the `and` keyword.
*
* left and right
* ^^^^^^^^^^^^^^
*/
class AndNode {
/**
* @type number
*/
nodeID;
/**
* @type {Location}
*/
location;
/**
* @type number
*/
#flags;
/**
* @type Node
*/
left;
/**
* @type Node
*/
right;
/**
* @type Location
*/
operatorLoc;
/**
* Construct a new AndNode.
*
* @param {number} nodeID
* @param {Location} location
* @param {number} flags
* @param {Node} left
* @param {Node} right
* @param {Location} operatorLoc
*/
constructor(nodeID, location, flags, left, right, operatorLoc) {
this.nodeID = nodeID;
this.location = location;
this.#flags = flags;
this.left = left;
this.right = right;
this.operatorLoc = operatorLoc;
}
/**
* Accept a visitor for this node.
*
* @param {visitors.Visitor} visitor
*/
accept(visitor) {
visitor.visitAndNode(this);
}
/**
* Returns all child nodes of the current node.
*
* @returns {(Node | null)[]} An array of child nodes.
*/
childNodes() {
return [this.left, this.right]
}
/**
* Compact and return an array of child nodes.
*
* @returns {Node[]} An array of compacted child nodes.
*/
compactChildNodes() {
return [this.left, this.right];
}
/**
* Transforms the Node to a JavaScript object.
*
* @returns {Object}
*/
toJSON() {
return {
type: "AndNode",
location: this.location,
flags: this.#flags,
left: this.left,
right: this.right,
operatorLoc: this.operatorLoc,
};
}
}
/**
* Represents a set of arguments to a method or a keyword.
*
* return foo, bar, baz
* ^^^^^^^^^^^^^
*/
class ArgumentsNode {
/**
* @type number
*/
nodeID;
/**
* @type {Location}
*/
location;
/**
* @type number
*/
#flags;
/**
* @type Node[]
*/
arguments_;
/**
* Construct a new ArgumentsNode.
*
* @param {number} nodeID
* @param {Location} location
* @param {number} flags
* @param {Node[]} arguments_
*/
constructor(nodeID, location, flags, arguments_) {
this.nodeID = nodeID;
this.location = location;
this.#flags = flags;
this.arguments_ = arguments_;
}
/**
* True if this node has the CONTAINS_FORWARDING flag.
*
* @returns {boolean}
*/
isContainsForwarding() {
return (this.#flags & ArgumentsNodeFlags.CONTAINS_FORWARDING) !== 0;
}
/**
* True if this node has the CONTAINS_KEYWORDS flag.
*
* @returns {boolean}
*/
isContainsKeywords() {
return (this.#flags & ArgumentsNodeFlags.CONTAINS_KEYWORDS) !== 0;
}
/**
* True if this node has the CONTAINS_KEYWORD_SPLAT flag.
*
* @returns {boolean}
*/
isContainsKeywordSplat() {
return (this.#flags & ArgumentsNodeFlags.CONTAINS_KEYWORD_SPLAT) !== 0;
}
/**
* True if this node has the CONTAINS_SPLAT flag.
*
* @returns {boolean}
*/
isContainsSplat() {
return (this.#flags & ArgumentsNodeFlags.CONTAINS_SPLAT) !== 0;
}
/**
* True if this node has the CONTAINS_MULTIPLE_SPLATS flag.
*
* @returns {boolean}
*/
isContainsMultipleSplats() {
return (this.#flags & ArgumentsNodeFlags.CONTAINS_MULTIPLE_SPLATS) !== 0;
}
/**
* Accept a visitor for this node.
*
* @param {visitors.Visitor} visitor
*/
accept(visitor) {
visitor.visitArgumentsNode(this);
}
/**
* Returns all child nodes of the current node.
*
* @returns {(Node | null)[]} An array of child nodes.
*/
childNodes() {
return [...this.arguments_]
}
/**
* Compact and return an array of child nodes.
*
* @returns {Node[]} An array of compacted child nodes.
*/
compactChildNodes() {
return [...this.arguments_];
}
/**
* Transforms the Node to a JavaScript object.
*
* @returns {Object}
*/
toJSON() {
return {
type: "ArgumentsNode",
location: this.location,
flags: this.#flags,
arguments: this.arguments_,
};
}
}
/**
* Represents an array literal. This can be a regular array using brackets or a special array using % like %w or %i.
*
* [1, 2, 3]
* ^^^^^^^^^
*/
class ArrayNode {
/**
* @type number
*/
nodeID;
/**
* @type {Location}
*/
location;
/**
* @type number
*/
#flags;
/**
* @type Node[]
*/
elements;
/**
* @type Location | null
*/
openingLoc;
/**
* @type Location | null
*/
closingLoc;
/**
* Construct a new ArrayNode.
*
* @param {number} nodeID
* @param {Location} location
* @param {number} flags
* @param {Node[]} elements
* @param {Location | null} openingLoc
* @param {Location | null} closingLoc
*/
constructor(nodeID, location, flags, elements, openingLoc, closingLoc) {
this.nodeID = nodeID;
this.location = location;
this.#flags = flags;
this.elements = elements;
this.openingLoc = openingLoc;
this.closingLoc = closingLoc;
}
/**
* True if this node has the CONTAINS_SPLAT flag.
*
* @returns {boolean}
*/
isContainsSplat() {
return (this.#flags & ArrayNodeFlags.CONTAINS_SPLAT) !== 0;
}
/**
* Accept a visitor for this node.
*
* @param {visitors.Visitor} visitor
*/
accept(visitor) {
visitor.visitArrayNode(this);
}
/**
* Returns all child nodes of the current node.
*
* @returns {(Node | null)[]} An array of child nodes.
*/
childNodes() {
return [...this.elements]
}
/**
* Compact and return an array of child nodes.
*
* @returns {Node[]} An array of compacted child nodes.
*/
compactChildNodes() {
return [...this.elements];
}
/**
* Transforms the Node to a JavaScript object.
*
* @returns {Object}
*/
toJSON() {
return {
type: "ArrayNode",
location: this.location,
flags: this.#flags,
elements: this.elements,
openingLoc: this.openingLoc,
closingLoc: this.closingLoc,
};
}
}
/**
* Represents an array pattern in pattern matching.
*
* foo in 1, 2
* ^^^^^^^^^^^
*
* foo in [1, 2]
* ^^^^^^^^^^^^^
*
* foo in *bar
* ^^^^^^^^^^^
*
* foo in Bar[]
* ^^^^^^^^^^^^
*
* foo in Bar[1, 2, 3]
* ^^^^^^^^^^^^^^^^^^^
*/
class ArrayPatternNode {
/**
* @type number
*/
nodeID;
/**
* @type {Location}
*/
location;
/**
* @type number
*/
#flags;
/**
* @type Node | null
*/
constant;
/**
* @type Node[]
*/
requireds;
/**
* @type Node | null
*/
rest;
/**
* @type Node[]
*/
posts;
/**
* @type Location | null
*/
openingLoc;
/**
* @type Location | null
*/
closingLoc;
/**
* Construct a new ArrayPatternNode.
*
* @param {number} nodeID
* @param {Location} location
* @param {number} flags
* @param {Node | null} constant
* @param {Node[]} requireds
* @param {Node | null} rest
* @param {Node[]} posts
* @param {Location | null} openingLoc
* @param {Location | null} closingLoc
*/
constructor(nodeID, location, flags, constant, requireds, rest, posts, openingLoc, closingLoc) {
this.nodeID = nodeID;
this.location = location;
this.#flags = flags;
this.constant = constant;
this.requireds = requireds;
this.rest = rest;
this.posts = posts;
this.openingLoc = openingLoc;
this.closingLoc = closingLoc;
}
/**
* Accept a visitor for this node.
*
* @param {visitors.Visitor} visitor
*/
accept(visitor) {
visitor.visitArrayPatternNode(this);
}
/**
* Returns all child nodes of the current node.
*
* @returns {(Node | null)[]} An array of child nodes.
*/
childNodes() {
return [this.constant, ...this.requireds, this.rest, ...this.posts]
}
/**
* Compact and return an array of child nodes.
*
* @returns {Node[]} An array of compacted child nodes.
*/
compactChildNodes() {
const compact = [];
if (this.constant) {
compact.push(this.constant);
}
compact.concat(this.requireds);
if (this.rest) {
compact.push(this.rest);
}
compact.concat(this.posts);
return compact;
}
/**
* Transforms the Node to a JavaScript object.
*
* @returns {Object}
*/
toJSON() {
return {
type: "ArrayPatternNode",
location: this.location,
flags: this.#flags,
constant: this.constant,
requireds: this.requireds,
rest: this.rest,
posts: this.posts,
openingLoc: this.openingLoc,
closingLoc: this.closingLoc,
};
}
}
/**
* Represents a hash key/value pair.
*
* { a => b }
* ^^^^^^
*/
class AssocNode {
/**
* @type number
*/
nodeID;
/**
* @type {Location}
*/
location;
/**
* @type number
*/
#flags;
/**
* @type Node
*/
key;
/**
* @type Node
*/
value;
/**
* @type Location | null
*/
operatorLoc;
/**
* Construct a new AssocNode.
*
* @param {number} nodeID
* @param {Location} location
* @param {number} flags
* @param {Node} key
* @param {Node} value
* @param {Location | null} operatorLoc
*/
constructor(nodeID, location, flags, key, value, operatorLoc) {
this.nodeID = nodeID;
this.location = location;
this.#flags = flags;
this.key = key;
this.value = value;
this.operatorLoc = operatorLoc;
}
/**
* Accept a visitor for this node.
*
* @param {visitors.Visitor} visitor
*/
accept(visitor) {
visitor.visitAssocNode(this);
}
/**
* Returns all child nodes of the current node.
*
* @returns {(Node | null)[]} An array of child nodes.
*/
childNodes() {
return [this.key, this.value]
}
/**
* Compact and return an array of child nodes.
*
* @returns {Node[]} An array of compacted child nodes.
*/
compactChildNodes() {
return [this.key, this.value];
}
/**
* Transforms the Node to a JavaScript object.
*
* @returns {Object}
*/
toJSON() {
return {
type: "AssocNode",
location: this.location,
flags: this.#flags,
key: this.key,
value: this.value,
operatorLoc: this.operatorLoc,
};
}
}
/**
* Represents a splat in a hash literal.
*
* { **foo }
* ^^^^^
*/
class AssocSplatNode {
/**
* @type number
*/
nodeID;
/**
* @type {Location}
*/
location;
/**
* @type number
*/
#flags;
/**
* @type Node | null
*/
value;
/**
* @type Location
*/
operatorLoc;
/**
* Construct a new AssocSplatNode.
*
* @param {number} nodeID
* @param {Location} location
* @param {number} flags
* @param {Node | null} value
* @param {Location} operatorLoc
*/
constructor(nodeID, location, flags, value, operatorLoc) {
this.nodeID = nodeID;
this.location = location;
this.#flags = flags;
this.value = value;
this.operatorLoc = operatorLoc;
}
/**
* Accept a visitor for this node.
*
* @param {visitors.Visitor} visitor
*/
accept(visitor) {
visitor.visitAssocSplatNode(this);
}
/**
* Returns all child nodes of the current node.
*
* @returns {(Node | null)[]} An array of child nodes.
*/
childNodes() {
return [this.value]
}
/**
* Compact and