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
chore: Derive keys from AST definitions #35
Closed
Closed
Changes from all commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
caa7fec
feat: bundle JSDoc-built TypeScript declaration file
brettz9 354f720
refactor: allow undefined keys (but not for keys argument or return v…
brettz9 0a1c5d0
fix: `types` and `files` location
brettz9 0e06d8f
fix: resolve "Cannot find module" error by using `outDir`
brettz9 e4d83bc
refactor: Shorten types with typedefs
brettz9 4283795
refactor: Remove extra `types`
brettz9 ef69df6
refactor: revert switch to `nodenext`
brettz9 3362133
refactor: Drop use of `KeysLooseReadonly`
brettz9 03da79c
refactor: set target to `es6`
brettz9 8413d10
chore: move `tsc` to build step
brettz9 ab6d321
test: tsd tests of declaration file
brettz9 fe4725e
test: exported type checks
brettz9 dbed685
refactor: Alphabetize for easier comparisons
brettz9 0071631
refactor: alphabetize inner keys
brettz9 7b41cb6
chore: tool to build keys out of AST definitions
brettz9 4c62e51
refactor: write to file
brettz9 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 |
---|---|---|
@@ -1,4 +1,21 @@ | ||
/** | ||
* @typedef {import('./index.js').KeysStrictReadonly} KeysStrictReadonly | ||
*/ | ||
|
||
/** | ||
* @type {KeysStrictReadonly} | ||
*/ | ||
const KEYS = { | ||
ArrayExpression: [ | ||
"elements" | ||
], | ||
ArrayPattern: [ | ||
"elements" | ||
], | ||
ArrowFunctionExpression: [ | ||
"body", | ||
"params" | ||
], | ||
AssignmentExpression: [ | ||
"left", | ||
"right" | ||
|
@@ -7,36 +24,27 @@ const KEYS = { | |
"left", | ||
"right" | ||
], | ||
ArrayExpression: [ | ||
"elements" | ||
], | ||
ArrayPattern: [ | ||
"elements" | ||
], | ||
ArrowFunctionExpression: [ | ||
"params", | ||
"body" | ||
AssignmentProperty: [ | ||
"key", | ||
"value" | ||
], | ||
AwaitExpression: [ | ||
"argument" | ||
], | ||
BlockStatement: [ | ||
"body" | ||
], | ||
BigIntLiteral: [], | ||
BinaryExpression: [ | ||
"left", | ||
"right" | ||
], | ||
BlockStatement: [ | ||
"body" | ||
], | ||
BreakStatement: [ | ||
"label" | ||
], | ||
CallExpression: [ | ||
"callee", | ||
"arguments" | ||
], | ||
CatchClause: [ | ||
"param", | ||
"body" | ||
"body", | ||
"param" | ||
], | ||
brettz9 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
ChainExpression: [ | ||
"expression" | ||
|
@@ -45,24 +53,27 @@ const KEYS = { | |
"body" | ||
], | ||
ClassDeclaration: [ | ||
"body", | ||
"id", | ||
"superClass", | ||
"body" | ||
"superClass" | ||
], | ||
ClassExpression: [ | ||
"body", | ||
"id", | ||
"superClass", | ||
"body" | ||
"superClass" | ||
], | ||
ConditionalExpression: [ | ||
"test", | ||
"alternate", | ||
"consequent", | ||
"alternate" | ||
"test" | ||
], | ||
ContinueStatement: [ | ||
"label" | ||
], | ||
DebuggerStatement: [], | ||
Directive: [ | ||
"expression" | ||
], | ||
DoWhileStatement: [ | ||
"body", | ||
"test" | ||
|
@@ -87,43 +98,37 @@ const KEYS = { | |
ExpressionStatement: [ | ||
"expression" | ||
], | ||
ExperimentalRestProperty: [ | ||
"argument" | ||
], | ||
ExperimentalSpreadProperty: [ | ||
"argument" | ||
], | ||
ForStatement: [ | ||
"init", | ||
"test", | ||
"update", | ||
"body" | ||
], | ||
ForInStatement: [ | ||
"body", | ||
"left", | ||
"right", | ||
"body" | ||
"right" | ||
], | ||
ForOfStatement: [ | ||
"body", | ||
"left", | ||
"right", | ||
"body" | ||
"right" | ||
], | ||
ForStatement: [ | ||
"body", | ||
"init", | ||
"test", | ||
"update" | ||
], | ||
FunctionDeclaration: [ | ||
"body", | ||
"id", | ||
"params", | ||
"body" | ||
"params" | ||
], | ||
FunctionExpression: [ | ||
"body", | ||
"id", | ||
"params", | ||
"body" | ||
"params" | ||
], | ||
Identifier: [], | ||
IfStatement: [ | ||
"test", | ||
"alternate", | ||
"consequent", | ||
"alternate" | ||
"test" | ||
], | ||
ImportDeclaration: [ | ||
"specifiers", | ||
|
@@ -146,18 +151,27 @@ const KEYS = { | |
"name", | ||
"value" | ||
], | ||
JSXBoundaryElement: [ | ||
"name" | ||
], | ||
JSXClosingElement: [ | ||
"name" | ||
], | ||
JSXClosingFragment: [], | ||
JSXElement: [ | ||
"openingElement", | ||
"children", | ||
"closingElement" | ||
"closingElement", | ||
"openingElement" | ||
], | ||
JSXEmptyExpression: [], | ||
JSXExpressionContainer: [ | ||
"expression" | ||
], | ||
JSXFragment: [ | ||
"children", | ||
"closingFragment", | ||
"openingFragment" | ||
], | ||
JSXIdentifier: [], | ||
JSXMemberExpression: [ | ||
"object", | ||
|
@@ -168,24 +182,20 @@ const KEYS = { | |
"name" | ||
], | ||
JSXOpeningElement: [ | ||
"name", | ||
"attributes" | ||
"attributes", | ||
"name" | ||
], | ||
JSXOpeningFragment: [], | ||
JSXSpreadAttribute: [ | ||
"argument" | ||
], | ||
JSXText: [], | ||
JSXFragment: [ | ||
"openingFragment", | ||
"children", | ||
"closingFragment" | ||
JSXSpreadChild: [ | ||
"expression" | ||
], | ||
JSXClosingFragment: [], | ||
JSXOpeningFragment: [], | ||
Literal: [], | ||
JSXText: [], | ||
LabeledStatement: [ | ||
"label", | ||
"body" | ||
"body", | ||
"label" | ||
], | ||
LogicalExpression: [ | ||
"left", | ||
|
@@ -204,8 +214,8 @@ const KEYS = { | |
"value" | ||
], | ||
NewExpression: [ | ||
"callee", | ||
"arguments" | ||
"arguments", | ||
"callee" | ||
], | ||
ObjectExpression: [ | ||
"properties" | ||
|
@@ -225,6 +235,7 @@ const KEYS = { | |
"key", | ||
"value" | ||
], | ||
RegExpLiteral: [], | ||
RestElement: [ | ||
"argument" | ||
], | ||
|
@@ -234,38 +245,43 @@ const KEYS = { | |
SequenceExpression: [ | ||
"expressions" | ||
], | ||
SimpleCallExpression: [ | ||
"arguments", | ||
"callee" | ||
], | ||
Comment on lines
+248
to
+251
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nodes with There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. With this approach:
I imagine there may be not too much work to adapt this to use |
||
SimpleLiteral: [], | ||
SpreadElement: [ | ||
"argument" | ||
], | ||
StaticBlock: [ | ||
"body" | ||
], | ||
Super: [], | ||
SwitchStatement: [ | ||
"discriminant", | ||
"cases" | ||
], | ||
SwitchCase: [ | ||
"test", | ||
"consequent" | ||
"consequent", | ||
"test" | ||
], | ||
SwitchStatement: [ | ||
"cases", | ||
"discriminant" | ||
], | ||
TaggedTemplateExpression: [ | ||
"tag", | ||
"quasi" | ||
"quasi", | ||
"tag" | ||
], | ||
TemplateElement: [], | ||
TemplateLiteral: [ | ||
"quasis", | ||
"expressions" | ||
"expressions", | ||
"quasis" | ||
], | ||
ThisExpression: [], | ||
ThrowStatement: [ | ||
"argument" | ||
], | ||
TryStatement: [ | ||
"block", | ||
"handler", | ||
"finalizer" | ||
"finalizer", | ||
"handler" | ||
], | ||
UnaryExpression: [ | ||
"argument" | ||
|
@@ -281,12 +297,12 @@ const KEYS = { | |
"init" | ||
], | ||
WhileStatement: [ | ||
"test", | ||
"body" | ||
"body", | ||
"test" | ||
], | ||
WithStatement: [ | ||
"object", | ||
"body" | ||
"body", | ||
"object" | ||
], | ||
YieldExpression: [ | ||
"argument" | ||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
The order is important here as it indicates which property should be traversed first. As such, we can change the order to alphabetical. (Same comment throughout this file.)
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.
Ok, sure, understood. But if the AST definers can't be convinced to define the properties in the order of iteration (taking into account nested interfaces, etc.), we'd have to add our own logic on how to sort these (and it might not be correct once new properties are added).