This repository has been archived by the owner on Aug 20, 2024. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: tool to build keys out of AST definitions
Also: 1. Removes `ExperimentalRestProperty`, `ExperimentalSpreadProperty` 2. Adds `JSXSpreadChild`
- Loading branch information
Showing
5 changed files
with
547 additions
and
6 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
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,32 @@ | ||
/** | ||
* @fileoverview Tests for checking that our build tool can retrieve keys out of TypeScript AST. | ||
* @author Brett Zamir | ||
*/ | ||
|
||
import { diffString } from "json-diff"; | ||
import { expect } from "chai"; | ||
import { alphabetizeKeyInterfaces, getKeysFromTsFile } from "../../tools/get-keys-from-ts.js"; | ||
import { KEYS } from "../../lib/index.js"; | ||
|
||
describe("getKeysFromTsFile", () => { | ||
it("gets keys", async () => { | ||
const { keys, tsInterfaceDeclarations } = await getKeysFromTsFile( | ||
"./node_modules/@types/estree/index.d.ts" | ||
); | ||
const { keys: jsxKeys } = await getKeysFromTsFile( | ||
"./node_modules/@types/estree-jsx/index.d.ts", | ||
{ | ||
supplementaryDeclarations: tsInterfaceDeclarations | ||
} | ||
); | ||
|
||
const actual = alphabetizeKeyInterfaces({ ...keys, ...jsxKeys }); | ||
|
||
const expected = KEYS; | ||
|
||
// eslint-disable-next-line no-console -- Mocha's may drop diffs so show with json-diff | ||
console.log("JSON Diffs:", diffString(actual, expected) || "(none)"); | ||
|
||
expect(actual).to.deep.equal(expected); | ||
}); | ||
}); |
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,54 @@ | ||
/** | ||
* @fileoverview Script to build our visitor keys based on TypeScript AST. | ||
* | ||
* Uses `get-keys-from-ts.js` to read the files and build the keys and then | ||
* merges them in alphabetical order of Node type before writing to file. | ||
* | ||
* @author Brett Zamir | ||
*/ | ||
|
||
import fs from "fs"; | ||
import { alphabetizeKeyInterfaces, getKeysFromTsFile } from "./get-keys-from-ts.js"; | ||
|
||
const { promises: { writeFile } } = fs; | ||
|
||
(async () => { | ||
const { keys, tsInterfaceDeclarations } = await getKeysFromTsFile("./node_modules/@types/estree/index.d.ts"); | ||
const { keys: jsxKeys } = await getKeysFromTsFile( | ||
"./node_modules/@types/estree-jsx/index.d.ts", | ||
{ | ||
supplementaryDeclarations: tsInterfaceDeclarations | ||
} | ||
); | ||
|
||
const mergedKeys = alphabetizeKeyInterfaces({ ...keys, ...jsxKeys }); | ||
|
||
// eslint-disable-next-line no-console -- CLI | ||
console.log("keys", mergedKeys); | ||
|
||
writeFile( | ||
"./lib/visitor-keys.js", | ||
// eslint-disable-next-line indent -- Readability | ||
`/** | ||
* @typedef {import('./index.js').VisitorKeys} VisitorKeys | ||
*/ | ||
/** | ||
* @type {VisitorKeys} | ||
*/ | ||
const KEYS = ${JSON.stringify(mergedKeys, null, 4).replace(/"(.*?)":/gu, "$1:")}; | ||
// Types. | ||
const NODE_TYPES = Object.keys(KEYS); | ||
// Freeze the keys. | ||
for (const type of NODE_TYPES) { | ||
Object.freeze(KEYS[type]); | ||
} | ||
Object.freeze(KEYS); | ||
export default KEYS; | ||
` | ||
); | ||
|
||
})(); |
Oops, something went wrong.