-
Notifications
You must be signed in to change notification settings - Fork 29
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add AST support of JSONC (for theme check, language features, etc.)
- 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
- Loading branch information
1 parent
606304f
commit 57db721
Showing
18 changed files
with
373 additions
and
62 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
'@shopify/theme-check-common': minor | ||
--- | ||
|
||
Add JSONC support to the AST parser |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
9 changes: 7 additions & 2 deletions
9
packages/theme-check-common/src/checks/liquid-free-settings/index.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
packages/theme-check-common/src/checks/matching-translations/index.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
12 changes: 8 additions & 4 deletions
12
packages/theme-check-common/src/checks/schema-presets-block-order/index.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
11 changes: 9 additions & 2 deletions
11
packages/theme-check-common/src/checks/valid-block-target/block-utils.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
10 changes: 8 additions & 2 deletions
10
packages/theme-check-common/src/checks/valid-local-blocks/index.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
3 changes: 1 addition & 2 deletions
3
packages/theme-check-common/src/checks/valid-local-blocks/valid-block-utils.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
3 changes: 1 addition & 2 deletions
3
packages/theme-check-common/src/checks/valid-schema-name/index.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,118 @@ | ||
import { describe, expect, it } from 'vitest'; | ||
import { toJSONNode, location } from './parse'; | ||
|
||
describe('module: toJSONNode', () => { | ||
it('should parse basic key-value pairs', () => { | ||
// 0123456789012345 | ||
const ast = toJSONNode(`{"key": "value"}`); | ||
expect(ast).toEqual({ | ||
type: 'Object', | ||
loc: location(0, 16), | ||
children: [ | ||
{ | ||
type: 'Property', | ||
loc: location(1, 15), | ||
key: { | ||
type: 'Identifier', | ||
value: 'key', | ||
raw: '"key"', | ||
loc: location(1, 6), | ||
}, | ||
value: { | ||
type: 'Literal', | ||
value: 'value', | ||
raw: '"value"', | ||
loc: location(8, 15), | ||
}, | ||
}, | ||
], | ||
}); | ||
}); | ||
|
||
it('should parse basic array of literals', () => { | ||
// 0123456789012345678901234 | ||
const ast = toJSONNode(`["one", true, null, 10]`); | ||
expect(ast).toEqual({ | ||
type: 'Array', | ||
loc: location(0, 23), | ||
children: [ | ||
{ | ||
type: 'Literal', | ||
value: 'one', | ||
raw: '"one"', | ||
loc: location(1, 6), | ||
}, | ||
{ | ||
type: 'Literal', | ||
value: true, | ||
raw: 'true', | ||
loc: location(8, 12), | ||
}, | ||
{ | ||
type: 'Literal', | ||
value: null, | ||
raw: 'null', | ||
loc: location(14, 18), | ||
}, | ||
{ | ||
type: 'Literal', | ||
value: 10, | ||
raw: '10', | ||
loc: location(20, 22), | ||
}, | ||
], | ||
}); | ||
}); | ||
|
||
it('should not break on block comments', () => { | ||
// 01234567890123456789012 | ||
const ast = toJSONNode(`/** block comment */10`); | ||
expect(ast).toEqual({ | ||
type: 'Literal', | ||
value: 10, | ||
raw: '10', | ||
loc: location(20, 22), | ||
}); | ||
}); | ||
|
||
it('should not break on line comments', () => { | ||
const source = `// line comment | ||
10`; | ||
const ast = toJSONNode(source); | ||
expect(ast).toEqual({ | ||
type: 'Literal', | ||
value: 10, | ||
raw: '10', | ||
loc: location(source.indexOf('10'), source.indexOf('10') + 2), | ||
}); | ||
}); | ||
|
||
it('should not break on trailing commas', () => { | ||
const source = `{ | ||
"key": "value", | ||
}`; | ||
const ast = toJSONNode(source); | ||
expect(ast).toEqual({ | ||
type: 'Object', | ||
loc: location(0, source.length), | ||
children: [ | ||
{ | ||
type: 'Property', | ||
loc: location(source.indexOf('"key"'), source.indexOf('"value"') + '"value"'.length), | ||
key: { | ||
type: 'Identifier', | ||
value: 'key', | ||
raw: '"key"', | ||
loc: expect.anything(), | ||
}, | ||
value: { | ||
type: 'Literal', | ||
value: 'value', | ||
raw: '"value"', | ||
loc: expect.anything(), | ||
}, | ||
}, | ||
], | ||
}); | ||
}); | ||
}); |
Oops, something went wrong.