See details: ../src/parser/ast.ts
interface BaseJSONNode {
type: string;
loc: SourceLocation;
range: [number, number];
}
All nodes have type
, range
, loc
and parent
properties according to ESLint - The AST specification.
export interface JSONIdentifier extends BaseJSONNode {
type: "JSONIdentifier"
name: string
parent:
| JSONArrayExpression
| JSONProperty
| JSONExpressionStatement
| JSONUnaryExpression
}
This node is Identifier for JSON.
export interface JSONLiteralBase extends BaseJSONNode {
type: "JSONLiteral"
value: string | number | boolean | null
regex:
| {
pattern: string
flags: string
}
| null
bigint: string | null
raw: string
parent:
| JSONArrayExpression
| JSONProperty
| JSONExpressionStatement
| JSONUnaryExpression
| JSONBinaryExpression
}
This node is Literal for JSON.
export interface JSONTemplateLiteral extends BaseJSONNode {
type: "JSONTemplateLiteral"
quasis: [JSONTemplateElement]
expressions: []
parent: JSONArrayExpression | JSONProperty | JSONExpressionStatement
}
This node is TemplateLiteral for JSON. This parser can only parse static values. You cannot use template literals in actual JSON, JSONC and JSON5.
export interface JSONTemplateElement extends BaseJSONNode {
type: "JSONTemplateElement"
tail: boolean
value: {
cooked: string
raw: string
}
parent: JSONTemplateLiteral
}
This node is TemplateElement for JSON.
export type JSONExpression =
| JSONArrayExpression
| JSONObjectExpression
| JSONLiteral
| JSONUnaryExpression
| ( JSONIdentifier & { name: "Infinity" | "NaN" | "undefined" } )
| JSONTemplateLiteral
| JSONBinaryExpression
This parser can parse "Infinity"
, "NaN"
and "undefined"
as values. But you can't use these values in actual JSON, JSONC and JSON5.
export interface JSONObjectExpression extends BaseJSONNode {
type: "JSONObjectExpression"
properties: JSONProperty[]
parent: JSONArrayExpression | JSONProperty | JSONExpressionStatement
}
This node is ObjectExpression for JSON.
export interface JSONProperty extends BaseJSONNode {
type: "JSONProperty"
key: JSONIdentifier | ( JSONLiteral & { value: string | number } )
value: JSONExpression
kind: "init"
method: false
shorthand: false
computed: false
parent: JSONObjectExpression
}
This node is Property for JSON.
export interface JSONArrayExpression extends BaseJSONNode {
type: "JSONArrayExpression"
elements: (JSONExpression | null)[]
parent: JSONArrayExpression | JSONProperty | JSONExpressionStatement
}
This node is ArrayExpression for JSON.
export interface JSONUnaryExpression extends BaseJSONNode {
type: "JSONUnaryExpression"
operator: "-" | "+"
prefix: true
argument: ( JSONLiteral & { value: number } ) | ( JSONIdentifier & { name: "Infinity" | "NaN" } )
parent: JSONArrayExpression | JSONProperty | JSONExpressionStatement
}
This node is UnaryExpression for JSON.
Only "-"
can be used by operator
in JSON and JSONC.
export interface JSONUnaryExpression extends BaseJSONNode {
type: "JSONBinaryExpression"
operator: "-" | "+" | "*" | "/" | "%" | "**"
left: JSONNumberLiteral | JSONUnaryExpression | JSONBinaryExpression
right: JSONNumberLiteral | JSONUnaryExpression | JSONBinaryExpression
parent:
| JSONArrayExpression
| JSONProperty
| JSONExpressionStatement
| JSONUnaryExpression
| JSONBinaryExpression
}
This node is BinaryExpression for JSON.
This parser can only parse binary expressions of static numbers. You cannot use binary expressions in actual JSON, JSONC and JSON5.
export interface JSONExpressionStatement extends BaseJSONNode {
type: "JSONExpressionStatement"
expression: JSONExpression
parent: JSONProgram
}
This node is ExpressionStatement for JSON.
There is always one JSONExpressionStatement
in one JSON.
extend interface JSONProgram extends BaseJSONNode {
type: "Program"
body: [JSONExpressionStatement]
}
The body
of the Program
node generated by this parser is an array of one JSONExpressionStatement
.