-
Notifications
You must be signed in to change notification settings - Fork 29
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add AST support of JSONC (for theme check, language features, etc.) #656
Conversation
57db721
to
7d47a8d
Compare
export type JSONNodeTypes = 'Object' | 'Array' | 'Property' | 'Identifier' | 'Literal'; | ||
export type JSONNode = ArrayNode | IdentifierNode | LiteralNode | ObjectNode | PropertyNode; | ||
export type ValueNode = ObjectNode | ArrayNode | LiteralNode; | ||
|
||
export interface Position { | ||
offset: number; | ||
} | ||
|
||
export interface Location { | ||
start: Position; | ||
end: Position; | ||
} | ||
|
||
export interface ASTNode { | ||
type: string; | ||
// Modified from @types/json-to-ast make this not-optional | ||
loc: Location; | ||
} | ||
|
||
export interface ObjectNode extends ASTNode { | ||
type: 'Object'; | ||
children: PropertyNode[]; | ||
} | ||
|
||
export interface PropertyNode extends ASTNode { | ||
type: 'Property'; | ||
key: IdentifierNode; | ||
value: ValueNode; | ||
} | ||
|
||
export interface IdentifierNode extends ASTNode { | ||
type: 'Identifier'; | ||
value: string; | ||
raw: string; | ||
} | ||
|
||
export interface ArrayNode extends ASTNode { | ||
type: 'Array'; | ||
children: ValueNode[]; | ||
} | ||
|
||
export interface LiteralNode extends ASTNode { | ||
type: 'Literal'; | ||
value: string | number | boolean | null; | ||
raw: string; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I prefer those types to the ones from jsonc-parser
. The ones in jsonc-parser
weren't made for discriminated unions and would have made the whole visitor
logic not work nice.
The ones from jsonc-parser
are here
- Rip out `json-to-ast` - Inline the `json-to-ast` types in `theme-check-common/src/jsonc` - Make a little `jsonc-parser#Node` -> `json-to-ast#ASTNode` adapter Fixes #654
7d47a8d
to
c371b48
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🎩 + live review w/ Albert LGTM
In this PR
json-to-ast
json-to-ast
types intheme-check-common/src/jsonc
jsonc-parser#Node
->json-to-ast#ASTNode
adapterFixes #654
What did you learn?
AugmentedJSONSourceCode
had aError
whenever there was a comment in the JSON fileBefore you deploy
changeset