Skip to content
This repository was archived by the owner on Aug 20, 2024. It is now read-only.

Commit 6ece4bd

Browse files
feat: add JSXSpreadChild and tool to build keys out of AST definitions (#36)
* refactor: Alphabetize for easier comparisons * chore: tool to build keys out of AST definitions Also: 1. Removes `ExperimentalRestProperty`, `ExperimentalSpreadProperty` 2. Adds `JSXSpreadChild` * refactor: sort alphabetically after known keys * refactor: restore backward compatible experimental keys * refactor: put backward compatible keys into own file * refactor: file rename * refactor: drop `propertiesToIgnore` in favor of `getKeys` blacklist * refactor: allow for more primitiveish types; fix error Also: - test: improve coverage * refactor: drop optional chaining fix for Node 12 * refactor: update testing/build devDeps. * refactor: exclude keys if not leading to an object with a non-comment type * refactor: no need for async on function * refactor: Remove commented out properties * refactor: Avoid unnecessary await Co-authored-by: Milos Djermanovic <[email protected]> Co-authored-by: Milos Djermanovic <[email protected]>
1 parent 4beb7a7 commit 6ece4bd

17 files changed

+993
-39
lines changed

lib/visitor-keys.js

Lines changed: 38 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,6 @@
66
* @type {VisitorKeys}
77
*/
88
const KEYS = {
9-
AssignmentExpression: [
10-
"left",
11-
"right"
12-
],
13-
AssignmentPattern: [
14-
"left",
15-
"right"
16-
],
179
ArrayExpression: [
1810
"elements"
1911
],
@@ -24,16 +16,24 @@ const KEYS = {
2416
"params",
2517
"body"
2618
],
19+
AssignmentExpression: [
20+
"left",
21+
"right"
22+
],
23+
AssignmentPattern: [
24+
"left",
25+
"right"
26+
],
2727
AwaitExpression: [
2828
"argument"
2929
],
30-
BlockStatement: [
31-
"body"
32-
],
3330
BinaryExpression: [
3431
"left",
3532
"right"
3633
],
34+
BlockStatement: [
35+
"body"
36+
],
3737
BreakStatement: [
3838
"label"
3939
],
@@ -75,6 +75,12 @@ const KEYS = {
7575
"test"
7676
],
7777
EmptyStatement: [],
78+
ExperimentalRestProperty: [
79+
"argument"
80+
],
81+
ExperimentalSpreadProperty: [
82+
"argument"
83+
],
7884
ExportAllDeclaration: [
7985
"exported",
8086
"source"
@@ -94,18 +100,6 @@ const KEYS = {
94100
ExpressionStatement: [
95101
"expression"
96102
],
97-
ExperimentalRestProperty: [
98-
"argument"
99-
],
100-
ExperimentalSpreadProperty: [
101-
"argument"
102-
],
103-
ForStatement: [
104-
"init",
105-
"test",
106-
"update",
107-
"body"
108-
],
109103
ForInStatement: [
110104
"left",
111105
"right",
@@ -116,6 +110,12 @@ const KEYS = {
116110
"right",
117111
"body"
118112
],
113+
ForStatement: [
114+
"init",
115+
"test",
116+
"update",
117+
"body"
118+
],
119119
FunctionDeclaration: [
120120
"id",
121121
"params",
@@ -156,6 +156,7 @@ const KEYS = {
156156
JSXClosingElement: [
157157
"name"
158158
],
159+
JSXClosingFragment: [],
159160
JSXElement: [
160161
"openingElement",
161162
"children",
@@ -165,6 +166,11 @@ const KEYS = {
165166
JSXExpressionContainer: [
166167
"expression"
167168
],
169+
JSXFragment: [
170+
"openingFragment",
171+
"children",
172+
"closingFragment"
173+
],
168174
JSXIdentifier: [],
169175
JSXMemberExpression: [
170176
"object",
@@ -178,22 +184,19 @@ const KEYS = {
178184
"name",
179185
"attributes"
180186
],
187+
JSXOpeningFragment: [],
181188
JSXSpreadAttribute: [
182189
"argument"
183190
],
184-
JSXText: [],
185-
JSXFragment: [
186-
"openingFragment",
187-
"children",
188-
"closingFragment"
191+
JSXSpreadChild: [
192+
"expression"
189193
],
190-
JSXClosingFragment: [],
191-
JSXOpeningFragment: [],
192-
Literal: [],
194+
JSXText: [],
193195
LabeledStatement: [
194196
"label",
195197
"body"
196198
],
199+
Literal: [],
197200
LogicalExpression: [
198201
"left",
199202
"right"
@@ -248,14 +251,14 @@ const KEYS = {
248251
"body"
249252
],
250253
Super: [],
251-
SwitchStatement: [
252-
"discriminant",
253-
"cases"
254-
],
255254
SwitchCase: [
256255
"test",
257256
"consequent"
258257
],
258+
SwitchStatement: [
259+
"discriminant",
260+
"cases"
261+
],
259262
TaggedTemplateExpression: [
260263
"tag",
261264
"quasi"

package.json

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,24 +25,31 @@
2525
"node": "^12.22.0 || ^14.17.0 || >=16.0.0"
2626
},
2727
"devDependencies": {
28-
"c8": "^7.7.3",
28+
"@types/estree": "^0.0.51",
29+
"@types/estree-jsx": "^0.0.1",
30+
"@typescript-eslint/parser": "^5.14.0",
31+
"c8": "^7.11.0",
32+
"chai": "^4.3.6",
2933
"eslint": "^7.29.0",
3034
"eslint-config-eslint": "^7.0.0",
3135
"eslint-plugin-jsdoc": "^35.4.0",
3236
"eslint-plugin-node": "^11.1.0",
3337
"eslint-release": "^3.2.0",
34-
"mocha": "^9.0.1",
38+
"esquery": "^1.4.0",
39+
"json-diff": "^0.7.3",
40+
"mocha": "^9.2.1",
3541
"opener": "^1.5.2",
36-
"rollup": "^2.52.1",
42+
"rollup": "^2.70.0",
3743
"tsd": "^0.19.1",
38-
"typescript": "^4.5.5"
44+
"typescript": "^4.6.2"
3945
},
4046
"scripts": {
4147
"prepare": "npm run build",
4248
"build": "rollup -c && npm run tsc",
4349
"lint": "eslint .",
4450
"tsc": "tsc",
4551
"tsd": "tsd",
52+
"build-keys": "node tools/build-keys-from-ts",
4653
"test": "mocha tests/lib/**/*.cjs && c8 mocha tests/lib/**/*.js && npm run tsd",
4754
"coverage": "c8 report --reporter lcov && opener coverage/lcov-report/index.html",
4855
"generate-release": "eslint-generate-release",
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
export interface Something extends BadSomething {
2+
type: "Something";
3+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
export interface Statement {}
2+
3+
export interface StaticBlock extends BadTypeParam<Statement, 'type'> {
4+
type: "StaticBlock";
5+
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
export interface StaticBlock extends Omit<SomeUnknownStatement, 'type'> {
2+
type: "StaticBlock";
3+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
interface BadExpression {
2+
type: undefined;
3+
}
4+
5+
export interface NewFangledExpression {
6+
type: "NewFangledExpression";
7+
right: BadExpression;
8+
}

tests/lib/fixtures/bad-type.d.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
export interface SomeExpression {
2+
type: "SomeExpression";
3+
someProperty: any;
4+
}

tests/lib/fixtures/new-keys-bad.d.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
export interface NewFangledExpression {
2+
type: "NewFangledExpression";
3+
right: BadExpression;
4+
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
export type AssignmentOperator = "=";
2+
interface Pattern {
3+
type: "Pattern"
4+
};
5+
interface MemberExpression {
6+
type: "MemberExpression"
7+
};
8+
interface Expression {
9+
type: "Expression"
10+
};
11+
12+
export interface AssignmentExpression {
13+
type: "AssignmentExpression";
14+
operator: AssignmentOperator;
15+
down: Expression;
16+
up: Expression;
17+
left: Pattern | MemberExpression;
18+
right: Expression;
19+
nontraversable: RegExp;
20+
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
export type AssignmentOperator = "=";
2+
interface Pattern {
3+
type: "Pattern"
4+
};
5+
interface MemberExpression {
6+
type: "MemberExpression"
7+
};
8+
interface Expression {
9+
type: "Expression"
10+
};
11+
12+
export interface AssignmentExpression {
13+
type: "AssignmentExpression";
14+
operator: AssignmentOperator;
15+
up: Expression;
16+
left: Pattern | MemberExpression;
17+
down: Expression;
18+
right: Expression;
19+
nontraversable: RegExp;
20+
}
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
export type AssignmentOperator = "=";
2+
3+
interface IgnoreBase {
4+
type: "Line";
5+
}
6+
7+
type AnotherIgnore = IgnoreBase;
8+
9+
interface BasePattern {
10+
type: "Pattern"
11+
};
12+
interface IgnoreChild extends Omit<BasePattern, "type"> {
13+
};
14+
15+
interface Pattern {
16+
type: "Pattern"
17+
};
18+
interface MemberExpression {
19+
type: "MemberExpression"
20+
};
21+
interface Expression {
22+
type: "Expression"
23+
};
24+
25+
export interface AssignmentExpression {
26+
type: "AssignmentExpression";
27+
ignore: IgnoreChild;
28+
anotherIgnore: AnotherIgnore;
29+
operator: AssignmentOperator;
30+
up: Expression;
31+
down: Expression;
32+
left: Pattern | MemberExpression;
33+
right: Expression;
34+
nontraversable: RegExp;
35+
}

tests/lib/fixtures/new-keys.d.ts

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
export type AssignmentOperator = "=";
2+
interface Pattern {
3+
type: "Pattern"
4+
};
5+
interface MemberExpression {
6+
type: "MemberExpression"
7+
};
8+
interface Expression {
9+
type: "Expression"
10+
};
11+
12+
export interface NewFangledExpression {
13+
type: "NewFangledExpression";
14+
operator: AssignmentOperator;
15+
up: Expression;
16+
down: Expression;
17+
left: Pattern | MemberExpression;
18+
right: Expression;
19+
}

tests/lib/fixtures/union-omit.d.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
export interface IgnoredStatement {
2+
type: "IgnoredStatement"
3+
}
4+
export interface AnotherStatement {
5+
type: "AnotherStatement";
6+
anotherToIgnore: IgnoredStatement;
7+
}
8+
9+
export interface StaticBlock extends Omit<AnotherStatement, 'type' | 'anotherToIgnore'> {
10+
type: "StaticBlock";
11+
}

0 commit comments

Comments
 (0)