Stringifier
Class for converting AST into string.
Summary
Properties
| addReactImport | If we encounter JSX elements, we add React's createElement as import. |
| parents | |
| spaces | A string of two spaces per indentation. |
Methods
Details
Constructor
Stringifier() #
Properties
If we encounter JSX elements, we add React's createElement as import.
Methods
ArrayExpression(node) #
Parameters
| node | import("@babel/types").ArrayExpression | The Babel AST node. |
Returns
stringStringification of the node.
ArrayPattern(node) #
for (const [a, b] in c) --> [a, b] is the array pattern
Parameters
| node | import("@babel/types").ArrayPattern | The Babel AST node. |
Returns
stringStringification of the node.
ArrowFunctionExpression(node) #
Parameters
| node | import("@babel/types").ArrowFunctionExpression | The Babel AST node. |
Returns
stringStringification of the node.
AssignmentExpression(node) #
Parameters
| node | import("@babel/types").AssignmentExpression | The Babel AST node. |
Returns
stringStringification of the node.
AssignmentPattern(node) #
Parameters
| node | import("@babel/types").AssignmentPattern | The Babel AST node. |
Returns
stringStringification of the node.
AwaitExpression(node) #
await something();
Parameters
| node | import("@babel/types").AwaitExpression | The Babel AST node. |
Returns
stringStringification of the node.
BigIntLiteral(node) #
Parameters
| node | import("@babel/types").BigIntLiteral | The Babel AST node. |
Returns
stringStringification of the node.
BinaryExpression(node) #
Parameters
| node | import("@babel/types").BinaryExpression | The Babel AST node. |
Returns
stringStringification of the node.
BlockStatement(node) #
Parameters
| node | import("@babel/types").BlockStatement | The Babel AST node. |
Returns
stringStringification of the node.
BooleanLiteral(node) #
Parameters
| node | import("@babel/types").BooleanLiteral | The Babel AST node. |
Returns
stringStringification of the node.
BreakStatement(node) #
Parameters
| node | import("@babel/types").BreakStatement | The Babel AST node. |
Returns
stringStringification of the node.
CallExpression(node) #
Parameters
| node | import("@babel/types").CallExpression | The Babel AST node. |
Returns
stringStringification of the node.
CatchClause(node) #
Parameters
| node | import("@babel/types").CatchClause | The Babel AST node. |
Returns
stringStringification of the node.
ClassBody(node) #
Parameters
| node | import("@babel/types").ClassBody | The Babel AST node. |
Returns
stringStringification of the node.
ClassDeclaration(node) #
Parameters
| node | import("@babel/types").ClassDeclaration | The Babel AST node. |
Returns
stringStringification of the node.
ClassExpression(node) #
Parameters
| node | import("@babel/types").ClassExpression | The Babel AST node. |
Returns
stringStringification of the node.
ClassMethod(node) #
Parameters
| node | import("@babel/types").ClassMethod | The Babel AST node. |
Returns
stringStringification of the node.
ClassPrivateMethod(node) #
Parameters
| node | import("@babel/types").ClassPrivateMethod | The Babel AST node. |
Returns
stringStringification of the node.
ClassPrivateProperty(node) #
Parameters
| node | import("@babel/types").ClassPrivateProperty | The Babel AST node. |
Returns
stringStringification of the node.
ClassProperty(node) #
asd; asd = 1; static asd; static asd = 1;
Parameters
| node | import("@babel/types").ClassProperty | The Babel AST node. |
Returns
stringStringification of the node.
CommentBlock(node) #
Parameters
| node | import("@babel/types").CommentBlock | The Babel AST node. |
Returns
stringStringification of the node.
CommentLine(node) #
Parameters
| node | import("@babel/types").CommentLine | The Babel AST node. |
Returns
stringStringification of the node.
commentToSource(comment, pos) #
Parameters
| comment | * | The comment "node" (not a real Babel Node node though, hence this special treatment) |
| pos | 'leading', 'trailing' | The position, either 'leading' or 'trailing'. |
Returns
stringThe comment "node" as a string.
ConditionalExpression(node) #
Parameters
| node | import("@babel/types").ConditionalExpression | The Babel AST node. |
Returns
stringStringification of the node.
ContinueStatement(node) #
Parameters
| node | import("@babel/types").ContinueStatement | The Babel AST node. |
Returns
stringStringification of the node.
DebuggerStatement(node) #
Parameters
| node | import("@babel/types").DebuggerStatement | The Babel AST node. |
Returns
stringStringification of the node.
Directive(node) #
'use strict';
Parameters
| node | import("@babel/types").Directive | The Babel AST node. |
Returns
stringStringification of the node.
DirectiveLiteral(node) #
'use strict';
Parameters
| node | import("@babel/types").DirectiveLiteral | The Babel AST node. |
Returns
stringStringification of the node.
DoWhileStatement(node) #
Parameters
| node | import("@babel/types").DoWhileStatement | The Babel AST node. |
Returns
stringStringification of the node.
EmptyStatement(node) #
showAST("if (true);");
Parameters
| node | import("@babel/types").EmptyStatement | The Babel AST node. |
Returns
stringStringification of the node.
ExportAllDeclaration(node) #
Parameters
| node | import("@babel/types").ExportAllDeclaration | The Babel AST node. |
Returns
stringStringification of the node.
ExportDefaultDeclaration(node) #
Parameters
| node | import("@babel/types").ExportDefaultDeclaration | The Babel AST node. |
Returns
stringStringification of the node.
ExportNamedDeclaration(node) #
Parameters
| node | import("@babel/types").ExportNamedDeclaration | The Babel AST node. |
Returns
stringStringification of the node.
ExportNamespaceSpecifier(node) #
Parameters
| node | import("@babel/types").ExportNamespaceSpecifier | The Babel AST node. |
Returns
stringStringification of the node.
ExportSpecifier(node) #
Parameters
| node | import("@babel/types").ExportSpecifier | The Babel AST node. |
Returns
stringStringification of the node.
ExpressionStatement(node) #
Parameters
| node | import("@babel/types").ExpressionStatement | The Babel AST node. |
Returns
stringStringification of the node.
File(node) #
Parameters
| node | import("@babel/types").File | The Babel AST node. |
Returns
stringStringification of the node.
ForInStatement(node) #
Parameters
| node | import("@babel/types").ForInStatement | The Babel AST node. |
Returns
stringStringification of the node.
ForOfStatement(node) #
Parameters
| node | import("@babel/types").ForOfStatement | The Babel AST node. |
Returns
stringStringification of the node.
ForStatement(node) #
TODO TEST: can init be undefined in for(;;)
Parameters
| node | import("@babel/types").ForStatement | The Babel AST node. |
Returns
stringStringification of the node.
FunctionDeclaration(node) #
Parameters
| node | import("@babel/types").FunctionDeclaration | The Babel AST node. |
Returns
stringStringification of the node.
FunctionDeclarationParams(params) #
Converts an array of Babel AST nodes representing function parameters into a comma-separated string.
Each parameter node is converted to its source representation and combined into a single string suitable for inserting into a function declaration's parentheses.
Parameters
| params | Node[] | An array of Babel AST nodes representing the function parameters to be stringified. |
Returns
stringA string representing the serialized parameters, enclosed in parentheses.
FunctionExpression(node) #
Parameters
| node | import("@babel/types").FunctionExpression | The Babel AST node. |
Returns
stringStringification of the node.
generateTypeChecks(node) #
Generates a string representing type checks for a given Babel AST node.
Note: This method serves as a stub and should be overridden in subclasses. The actual implementation is expected to be provided in Asserter.js, where it would create runtime type assertions based on the AST node provided.
Parameters
| node | Node | The Babel AST node for which to generate type checks. |
Returns
stringA placeholder string, as this stub implementation does nothing; expected to be overridden.
Identifier(node) #
Parameters
| node | import("@babel/types").Identifier | The Babel AST node. |
Returns
stringStringification of the node.
IfStatement(node) #
Parameters
| node | import("@babel/types").IfStatement | The Babel AST node. |
Returns
stringStringification of the node.
Import(node) #
Parameters
| node | import("@babel/types").Import | The Babel AST node. |
Returns
stringStringification of the node.
ImportDeclaration(node) #
Parameters
| node | import("@babel/types").ImportDeclaration | The Babel AST node. |
Returns
stringStringification of the node.
ImportDefaultSpecifier(node) #
Parameters
| node | import("@babel/types").ImportDefaultSpecifier | The Babel AST node. |
Returns
stringStringification of the node.
ImportExpression(node) #
Parameters
| node | import("@babel/types").ImportExpression | The Babel AST node. |
Returns
stringStringification of the node.
ImportNamespaceSpecifier(node) #
Parameters
| node | import("@babel/types").ImportNamespaceSpecifier | The Babel AST node. |
Returns
stringStringification of the node.
ImportSpecifier(node) #
Parameters
| node | import("@babel/types").ImportSpecifier | The Babel AST node. |
Returns
stringStringification of the node.
JSXAttribute(node) #
Parameters
| node | import("@babel/types").JSXAttribute | The Babel AST node. |
Returns
stringStringification of the node.
JSXElement(node) #
Parameters
| node | import("@babel/types").JSXElement | The Babel AST node. |
Returns
stringStringification of the node.
JSXExpressionContainer(node) #
Parameters
| node | import("@babel/types").JSXExpressionContainer | The Babel AST node. |
Returns
stringStringification of the node.
JSXFragment(node) #
Parameters
| node | import("@babel/types").JSXFragment | The Babel AST node. |
Returns
stringStringification of the node.
JSXIdentifier(node) #
Parameters
| node | import("@babel/types").JSXIdentifier | The Babel AST node. |
Returns
stringStringification of the node.
JSXMemberExpression(node) #
Parameters
| node | import("@babel/types").JSXMemberExpression | The Babel AST node. |
Returns
stringStringification of the node.
JSXNamespacedName(node) #
Parameters
| node | import("@babel/types").JSXNamespacedName | The Babel AST node. |
Returns
stringStringification of the node.
JSXText(node) #
Parameters
| node | import("@babel/types").JSXText | The Babel AST node. |
Returns
stringStringification of the node.
LabeledStatement(node) #
Parameters
| node | import("@babel/types").LabeledStatement | The Babel AST node. |
Returns
stringStringification of the node.
LogicalExpression(node) #
if (...)
Parameters
| node | import("@babel/types").LogicalExpression | The Babel AST node. |
Returns
stringStringification of the node.
mapToSource(arr) #
Parameters
| arr | Node[] | Array of nodes to convert. |
Returns
string[]Array of strings for each node.
MemberExpression(node) #
Parameters
| node | import("@babel/types").MemberExpression | The Babel AST node. |
Returns
stringStringification of the node.
MetaProperty(node) #
Parameters
| node | import("@babel/types").MetaProperty | The Babel AST node. |
Returns
stringStringification of the node.
NewExpression(node) #
Parameters
| node | import("@babel/types").NewExpression | The Babel AST node. |
Returns
stringStringification of the node.
NullLiteral(node) #
Parameters
| node | import("@babel/types").NullLiteral | The Babel AST node. |
Returns
stringStringification of the node.
NumericLiteral(node) #
Parameters
| node | import("@babel/types").NumericLiteral | The Babel AST node. |
Returns
stringStringification of the node.
ObjectExpression(node) #
We replicate the exact AST for validation: x = 1; y = {x,} z = {y};
Parameters
| node | import("@babel/types").ObjectExpression | The Babel AST node. |
Returns
stringStringification of the node.
ObjectMethod(node) #
Parameters
| node | import("@babel/types").ObjectMethod | The Babel AST node. |
Returns
stringStringification of the node.
ObjectPattern(node) #
E.g. function testComma({x,y,z,}) {}
Parameters
| node | import("@babel/types").ObjectPattern | The Babel AST node. |
Returns
stringStringification of the node.
ObjectProperty(node) #
Parameters
| node | import("@babel/types").ObjectProperty | The Babel AST node. |
Returns
stringStringification of the node.
OptionalCallExpression(node) #
version?.indexOf('$'); version?.indexOf?.('$'); this.passEncoder?.pushDebugGroup(name);
Parameters
| node | import("@babel/types").OptionalCallExpression | The Babel AST node. |
Returns
stringStringification of the node.
OptionalMemberExpression(node) #
x?.y x?.y.z x[y?.z] x?.[y?.z] b?.file?.variants[variant]
Parameters
| node | import("@babel/types").OptionalMemberExpression | The Babel AST node. |
Returns
stringStringification of the node.
ParenthesizedExpression(node) #
Parameters
| node | import("@babel/types").ParenthesizedExpression | The Babel AST node. |
Returns
stringStringification of the node.
PrivateName(node) #
Parameters
| node | import("@babel/types").PrivateName | The Babel AST node. |
Returns
stringStringification of the node.
Program(node) #
Parameters
| node | import("@babel/types").Program | The Babel AST node. |
Returns
stringStringification of the node.
RegExpLiteral(node) #
Parameters
| node | import("@babel/types").RegExpLiteral | The Babel AST node. |
Returns
stringStringification of the node.
RestElement(node) #
Parameters
| node | import("@babel/types").RestElement | The Babel AST node. |
Returns
stringStringification of the node.
ReturnStatement(node) #
Parameters
| node | import("@babel/types").ReturnStatement | The Babel AST node. |
Returns
stringStringification of the node.
SequenceExpression(node) #
for (var i=0, n=arr.length; i<n; i++) sequence expression: var i=0, n=arr.length
Parameters
| node | import("@babel/types").SequenceExpression | The Babel AST node. |
Returns
stringStringification of the node.
SpreadElement(node) #
Parameters
| node | import("@babel/types").SpreadElement | The Babel AST node. |
Returns
stringStringification of the node.
StringLiteral(node) #
Parameters
| node | import("@babel/types").StringLiteral | The Babel AST node. |
Returns
stringStringification of the node.
Super(node) #
Parameters
| node | import("@babel/types").Super | The Babel AST node. |
Returns
stringStringification of the node.
SwitchCase(node) #
Parameters
| node | import("@babel/types").SwitchCase | The Babel AST node. |
Returns
stringStringification of the node.
SwitchStatement(node) #
Parameters
| node | import("@babel/types").SwitchStatement | The Babel AST node. |
Returns
stringStringification of the node.
TaggedTemplateExpression(node) #
Parameters
| node | import("@babel/types").TaggedTemplateExpression | The Babel AST node. |
Returns
stringStringification of the node.
TemplateElement(node) #
Parameters
| node | import("@babel/types").TemplateElement | The Babel AST node. |
Returns
stringStringification of the node.
TemplateLiteral(node) #
console.log(ast2json(parseSync("`${1} b ${2+3}c`").program.body[0]));Parameters
| node | import("@babel/types").TemplateLiteral | The Babel AST node. |
Returns
stringStringification of the node.
ThisExpression(node) #
Parameters
| node | import("@babel/types").ThisExpression | The Babel AST node. |
Returns
stringStringification of the node.
ThrowStatement(node) #
Parameters
| node | import("@babel/types").ThrowStatement | The Babel AST node. |
Returns
stringStringification of the node.
toSourceCurly(node) #
Only add { and } when requested (e.g. for Asserter). showAST("if (true) 2;") vs showAST("if (true) {2}")
Parameters
| node | Node | The Babel AST node. |
Returns
stringStringification of the node.
TryStatement(node) #
Parameters
| node | import("@babel/types").TryStatement | The Babel AST node. |
Returns
stringStringification of the node.
UnaryExpression(node) #
ts = require("typescript");
ts.createSourceFile("repl.ts", "a = 1", ts.ScriptTarget.Latest);
ts.createSourceFile("repl.ts", "!!(a = 1 + 2)", ts.ScriptTarget.Latest);
showAST('!!(a = 1)');Parameters
| node | import("@babel/types").UnaryExpression | The Babel AST node. |
Returns
stringStringification of the node.
UpdateExpression(node) #
showAST("++i")
Parameters
| node | import("@babel/types").UpdateExpression | The Babel AST node. |
Returns
stringStringification of the node.
VariableDeclaration(node) #
Parameters
| node | import("@babel/types").VariableDeclaration | The Babel AST node. |
Returns
stringStringification of the node.
VariableDeclarator(node) #
Parameters
| node | import("@babel/types").VariableDeclarator | The Babel AST node. |
Returns
stringStringification of the node.