forked from parcel-bundler/lightningcss
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuild-ast.js
More file actions
30 lines (28 loc) · 1.02 KB
/
build-ast.js
File metadata and controls
30 lines (28 loc) · 1.02 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
const { compileFromFile } = require('json-schema-to-typescript');
const fs = require('fs');
const skip = {
FillRule: true,
ImportRule: true,
FontFaceRule: true,
FontPaletteValuesRule: true,
NamespaceRule: true,
CustomMediaRule: true,
LayerStatementRule: true,
PropertyRule: true,
UnknownAtRule: true,
DefaultAtRule: true
}
compileFromFile('node/ast.json', {
additionalProperties: false
}).then(ts => {
ts = ts.replaceAll('For_DefaultAtRule', '')
.replaceAll('interface DeclarationBlock', 'interface DeclarationBlock<D = Declaration>')
.replaceAll('DeclarationBlock;', 'DeclarationBlock<D>;')
.replaceAll('Declaration[]', 'D[]')
.replace(/(interface )?([A-Z][a-zA-Z]*Rule)/g, (m, x, n) => skip[n] ? m : `${m}<D${x ? ' = Declaration' : ''}>`)
.replaceAll(': Rule', ': Rule<D>')
.replaceAll('type Rule =', 'type Rule<D = Declaration> =')
.replace(/Keyframe(?![a-zA-Z])/g, 'Keyframe<D>')
.replaceAll('StyleSheet', 'StyleSheet<D = Declaration>');
fs.writeFileSync('node/ast.d.ts', ts)
});