Skip to content

Commit

Permalink
feat: add JSXSpreadChild and tool to build keys out of AST definiti…
Browse files Browse the repository at this point in the history
…ons (#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]>
  • Loading branch information
brettz9 and mdjermanovic committed Mar 29, 2022
1 parent 4beb7a7 commit 6ece4bd
Show file tree
Hide file tree
Showing 17 changed files with 993 additions and 39 deletions.
73 changes: 38 additions & 35 deletions lib/visitor-keys.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,6 @@
* @type {VisitorKeys}
*/
const KEYS = {
AssignmentExpression: [
"left",
"right"
],
AssignmentPattern: [
"left",
"right"
],
ArrayExpression: [
"elements"
],
Expand All @@ -24,16 +16,24 @@ const KEYS = {
"params",
"body"
],
AssignmentExpression: [
"left",
"right"
],
AssignmentPattern: [
"left",
"right"
],
AwaitExpression: [
"argument"
],
BlockStatement: [
"body"
],
BinaryExpression: [
"left",
"right"
],
BlockStatement: [
"body"
],
BreakStatement: [
"label"
],
Expand Down Expand Up @@ -75,6 +75,12 @@ const KEYS = {
"test"
],
EmptyStatement: [],
ExperimentalRestProperty: [
"argument"
],
ExperimentalSpreadProperty: [
"argument"
],
ExportAllDeclaration: [
"exported",
"source"
Expand All @@ -94,18 +100,6 @@ const KEYS = {
ExpressionStatement: [
"expression"
],
ExperimentalRestProperty: [
"argument"
],
ExperimentalSpreadProperty: [
"argument"
],
ForStatement: [
"init",
"test",
"update",
"body"
],
ForInStatement: [
"left",
"right",
Expand All @@ -116,6 +110,12 @@ const KEYS = {
"right",
"body"
],
ForStatement: [
"init",
"test",
"update",
"body"
],
FunctionDeclaration: [
"id",
"params",
Expand Down Expand Up @@ -156,6 +156,7 @@ const KEYS = {
JSXClosingElement: [
"name"
],
JSXClosingFragment: [],
JSXElement: [
"openingElement",
"children",
Expand All @@ -165,6 +166,11 @@ const KEYS = {
JSXExpressionContainer: [
"expression"
],
JSXFragment: [
"openingFragment",
"children",
"closingFragment"
],
JSXIdentifier: [],
JSXMemberExpression: [
"object",
Expand All @@ -178,22 +184,19 @@ const KEYS = {
"name",
"attributes"
],
JSXOpeningFragment: [],
JSXSpreadAttribute: [
"argument"
],
JSXText: [],
JSXFragment: [
"openingFragment",
"children",
"closingFragment"
JSXSpreadChild: [
"expression"
],
JSXClosingFragment: [],
JSXOpeningFragment: [],
Literal: [],
JSXText: [],
LabeledStatement: [
"label",
"body"
],
Literal: [],
LogicalExpression: [
"left",
"right"
Expand Down Expand Up @@ -248,14 +251,14 @@ const KEYS = {
"body"
],
Super: [],
SwitchStatement: [
"discriminant",
"cases"
],
SwitchCase: [
"test",
"consequent"
],
SwitchStatement: [
"discriminant",
"cases"
],
TaggedTemplateExpression: [
"tag",
"quasi"
Expand Down
15 changes: 11 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,24 +25,31 @@
"node": "^12.22.0 || ^14.17.0 || >=16.0.0"
},
"devDependencies": {
"c8": "^7.7.3",
"@types/estree": "^0.0.51",
"@types/estree-jsx": "^0.0.1",
"@typescript-eslint/parser": "^5.14.0",
"c8": "^7.11.0",
"chai": "^4.3.6",
"eslint": "^7.29.0",
"eslint-config-eslint": "^7.0.0",
"eslint-plugin-jsdoc": "^35.4.0",
"eslint-plugin-node": "^11.1.0",
"eslint-release": "^3.2.0",
"mocha": "^9.0.1",
"esquery": "^1.4.0",
"json-diff": "^0.7.3",
"mocha": "^9.2.1",
"opener": "^1.5.2",
"rollup": "^2.52.1",
"rollup": "^2.70.0",
"tsd": "^0.19.1",
"typescript": "^4.5.5"
"typescript": "^4.6.2"
},
"scripts": {
"prepare": "npm run build",
"build": "rollup -c && npm run tsc",
"lint": "eslint .",
"tsc": "tsc",
"tsd": "tsd",
"build-keys": "node tools/build-keys-from-ts",
"test": "mocha tests/lib/**/*.cjs && c8 mocha tests/lib/**/*.js && npm run tsd",
"coverage": "c8 report --reporter lcov && opener coverage/lcov-report/index.html",
"generate-release": "eslint-generate-release",
Expand Down
3 changes: 3 additions & 0 deletions tests/lib/fixtures/bad-extends-type-reference.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export interface Something extends BadSomething {
type: "Something";
}
5 changes: 5 additions & 0 deletions tests/lib/fixtures/bad-type-parameters.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
export interface Statement {}

export interface StaticBlock extends BadTypeParam<Statement, 'type'> {
type: "StaticBlock";
}
3 changes: 3 additions & 0 deletions tests/lib/fixtures/bad-type-reference.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export interface StaticBlock extends Omit<SomeUnknownStatement, 'type'> {
type: "StaticBlock";
}
8 changes: 8 additions & 0 deletions tests/lib/fixtures/bad-type-value.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
interface BadExpression {
type: undefined;
}

export interface NewFangledExpression {
type: "NewFangledExpression";
right: BadExpression;
}
4 changes: 4 additions & 0 deletions tests/lib/fixtures/bad-type.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
export interface SomeExpression {
type: "SomeExpression";
someProperty: any;
}
4 changes: 4 additions & 0 deletions tests/lib/fixtures/new-keys-bad.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
export interface NewFangledExpression {
type: "NewFangledExpression";
right: BadExpression;
}
20 changes: 20 additions & 0 deletions tests/lib/fixtures/new-keys-on-old-order-switched.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
export type AssignmentOperator = "=";
interface Pattern {
type: "Pattern"
};
interface MemberExpression {
type: "MemberExpression"
};
interface Expression {
type: "Expression"
};

export interface AssignmentExpression {
type: "AssignmentExpression";
operator: AssignmentOperator;
down: Expression;
up: Expression;
left: Pattern | MemberExpression;
right: Expression;
nontraversable: RegExp;
}
20 changes: 20 additions & 0 deletions tests/lib/fixtures/new-keys-on-old-other-order.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
export type AssignmentOperator = "=";
interface Pattern {
type: "Pattern"
};
interface MemberExpression {
type: "MemberExpression"
};
interface Expression {
type: "Expression"
};

export interface AssignmentExpression {
type: "AssignmentExpression";
operator: AssignmentOperator;
up: Expression;
left: Pattern | MemberExpression;
down: Expression;
right: Expression;
nontraversable: RegExp;
}
35 changes: 35 additions & 0 deletions tests/lib/fixtures/new-keys-on-old.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
export type AssignmentOperator = "=";

interface IgnoreBase {
type: "Line";
}

type AnotherIgnore = IgnoreBase;

interface BasePattern {
type: "Pattern"
};
interface IgnoreChild extends Omit<BasePattern, "type"> {
};

interface Pattern {
type: "Pattern"
};
interface MemberExpression {
type: "MemberExpression"
};
interface Expression {
type: "Expression"
};

export interface AssignmentExpression {
type: "AssignmentExpression";
ignore: IgnoreChild;
anotherIgnore: AnotherIgnore;
operator: AssignmentOperator;
up: Expression;
down: Expression;
left: Pattern | MemberExpression;
right: Expression;
nontraversable: RegExp;
}
19 changes: 19 additions & 0 deletions tests/lib/fixtures/new-keys.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
export type AssignmentOperator = "=";
interface Pattern {
type: "Pattern"
};
interface MemberExpression {
type: "MemberExpression"
};
interface Expression {
type: "Expression"
};

export interface NewFangledExpression {
type: "NewFangledExpression";
operator: AssignmentOperator;
up: Expression;
down: Expression;
left: Pattern | MemberExpression;
right: Expression;
}
11 changes: 11 additions & 0 deletions tests/lib/fixtures/union-omit.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
export interface IgnoredStatement {
type: "IgnoredStatement"
}
export interface AnotherStatement {
type: "AnotherStatement";
anotherToIgnore: IgnoredStatement;
}

export interface StaticBlock extends Omit<AnotherStatement, 'type' | 'anotherToIgnore'> {
type: "StaticBlock";
}

0 comments on commit 6ece4bd

Please sign in to comment.