Skip to content

Commit 689dae3

Browse files
authored
feat: split visitor keys into their own package (typescript-eslint#2230)
1 parent 5f45918 commit 689dae3

File tree

23 files changed

+206
-33
lines changed

23 files changed

+206
-33
lines changed

.github/workflows/ci.yml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,12 @@ jobs:
9797
env:
9898
CI: true
9999

100+
- name: Run unit tests for visitor-keys
101+
run: yarn test
102+
working-directory: packages/visitor-keys
103+
env:
104+
CI: true
105+
100106
- name: Run unit tests for experimental-utils
101107
run: yarn test
102108
working-directory: packages/experimental-utils
@@ -257,6 +263,12 @@ jobs:
257263
env:
258264
CI: true
259265

266+
- name: Run unit tests for visitor-keys
267+
run: yarn test
268+
working-directory: packages/visitor-keys
269+
env:
270+
CI: true
271+
260272
- name: Run unit tests for experimental-utils
261273
run: yarn test
262274
working-directory: packages/experimental-utils

.vscode/launch.json

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@
3030
"${workspaceFolder}/packages/typescript-estree/dist/index.js",
3131
"${workspaceFolder}/packages/types/src/index.ts",
3232
"${workspaceFolder}/packages/types/dist/index.js",
33+
"${workspaceFolder}/packages/visitor-keys/src/index.ts",
34+
"${workspaceFolder}/packages/visitor-keys/dist/index.js",
3335
],
3436
},
3537
{
@@ -58,6 +60,8 @@
5860
"${workspaceFolder}/packages/typescript-estree/dist/index.js",
5961
"${workspaceFolder}/packages/types/src/index.ts",
6062
"${workspaceFolder}/packages/types/dist/index.js",
63+
"${workspaceFolder}/packages/visitor-keys/src/index.ts",
64+
"${workspaceFolder}/packages/visitor-keys/dist/index.js",
6165
],
6266
},
6367
{
@@ -86,6 +90,8 @@
8690
"${workspaceFolder}/packages/typescript-estree/dist/index.js",
8791
"${workspaceFolder}/packages/types/src/index.ts",
8892
"${workspaceFolder}/packages/types/dist/index.js",
93+
"${workspaceFolder}/packages/visitor-keys/src/index.ts",
94+
"${workspaceFolder}/packages/visitor-keys/dist/index.js",
8995
],
9096
},
9197
{
@@ -114,6 +120,8 @@
114120
"${workspaceFolder}/packages/typescript-estree/dist/index.js",
115121
"${workspaceFolder}/packages/types/src/index.ts",
116122
"${workspaceFolder}/packages/types/dist/index.js",
123+
"${workspaceFolder}/packages/visitor-keys/src/index.ts",
124+
"${workspaceFolder}/packages/visitor-keys/dist/index.js",
117125
],
118126
},
119127
{
@@ -142,6 +150,8 @@
142150
"${workspaceFolder}/packages/typescript-estree/dist/index.js",
143151
"${workspaceFolder}/packages/types/src/index.ts",
144152
"${workspaceFolder}/packages/types/dist/index.js",
153+
"${workspaceFolder}/packages/visitor-keys/src/index.ts",
154+
"${workspaceFolder}/packages/visitor-keys/dist/index.js",
145155
],
146156
}
147157
]

packages/typescript-estree/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,8 @@
4141
},
4242
"dependencies": {
4343
"@typescript-eslint/types": "3.4.0",
44+
"@typescript-eslint/visitor-keys": "3.4.0",
4445
"debug": "^4.1.1",
45-
"eslint-visitor-keys": "^1.1.0",
4646
"glob": "^7.1.6",
4747
"is-glob": "^4.0.1",
4848
"lodash": "^4.17.15",

packages/typescript-estree/src/index.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,11 @@ export {
66
} from './parser';
77
export { ParserServices, TSESTreeOptions } from './parser-options';
88
export { simpleTraverse } from './simple-traverse';
9-
export { visitorKeys } from './visitor-keys';
109
export * from './ts-estree';
1110
export { clearCaches } from './create-program/createWatchProgram';
1211

12+
// re-export for backwards-compat
13+
export { visitorKeys } from '@typescript-eslint/visitor-keys';
14+
1315
// note - cannot migrate this to an import statement because it will make TSC copy the package.json to the dist folder
1416
export const version: string = require('../package.json').version;

packages/typescript-estree/src/simple-traverse.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1+
import { visitorKeys } from '@typescript-eslint/visitor-keys';
12
import { TSESTree } from './ts-estree';
2-
import { visitorKeys } from './visitor-keys';
33

44
// eslint-disable-next-line @typescript-eslint/no-explicit-any
55
function isValidNode(x: any): x is TSESTree.Node {

packages/typescript-estree/tests/lib/visitor-keys.ts

Lines changed: 0 additions & 28 deletions
This file was deleted.

packages/typescript-estree/tsconfig.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
"exclude": ["tests/fixtures/**/*"],
99
"references": [
1010
{ "path": "../shared-fixtures/tsconfig.build.json" },
11-
{ "path": "../types/tsconfig.build.json" }
11+
{ "path": "../types/tsconfig.build.json" },
12+
{ "path": "../visitor-keys/tsconfig.build.json" }
1213
]
1314
}

packages/visitor-keys/LICENSE

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2019 TypeScript ESLint and other contributors
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

packages/visitor-keys/README.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<h1 align="center">TypeScript-ESTree Visitor Keys</h1>
2+
3+
<p align="center">Visitor keys used to help traverse the TypeScript-ESTree AST</p>
4+
5+
<p align="center">
6+
<img src="https://github.com/typescript-eslint/typescript-eslint/workflows/CI/badge.svg" alt="CI" />
7+
<a href="https://www.npmjs.com/package/@typescript-eslint/visitor-keys"><img src="https://img.shields.io/npm/v/@typescript-eslint/visitor-keys.svg?style=flat-square" alt="NPM Version" /></a>
8+
<a href="https://www.npmjs.com/package/@typescript-eslint/visitor-keys"><img src="https://img.shields.io/npm/dm/@typescript-eslint/visitor-keys.svg?style=flat-square" alt="NPM Downloads" /></a>
9+
</p>
10+
11+
## Contributing
12+
13+
[See the contributing guide here](../../CONTRIBUTING.md)

packages/visitor-keys/jest.config.js

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
'use strict';
2+
3+
// @ts-check
4+
/** @type {import('@jest/types').Config.InitialOptions} */
5+
module.exports = {
6+
globals: {
7+
'ts-jest': {
8+
isolatedModules: true,
9+
},
10+
},
11+
testEnvironment: 'node',
12+
transform: {
13+
[/^.+\.tsx?$/.source]: 'ts-jest',
14+
},
15+
testRegex: [/.\/tests\/.+\.test\.ts$/.source],
16+
collectCoverage: false,
17+
collectCoverageFrom: ['src/**/*.{js,jsx,ts,tsx}'],
18+
moduleFileExtensions: ['ts', 'tsx', 'js', 'jsx', 'json', 'node'],
19+
coverageReporters: ['text-summary', 'lcov'],
20+
};

packages/visitor-keys/package.json

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
{
2+
"name": "@typescript-eslint/visitor-keys",
3+
"version": "3.4.0",
4+
"description": "Visitor keys used to help traverse the TypeScript-ESTree AST",
5+
"keywords": [
6+
"eslint",
7+
"typescript",
8+
"estree"
9+
],
10+
"engines": {
11+
"node": "^8.10.0 || ^10.13.0 || >=11.10.1"
12+
},
13+
"files": [
14+
"dist",
15+
"package.json",
16+
"README.md",
17+
"LICENSE"
18+
],
19+
"repository": {
20+
"type": "git",
21+
"url": "https://github.com/typescript-eslint/typescript-eslint.git",
22+
"directory": "packages/visitor-keys"
23+
},
24+
"bugs": {
25+
"url": "https://github.com/typescript-eslint/typescript-eslint/issues"
26+
},
27+
"license": "MIT",
28+
"main": "dist/index.js",
29+
"types": "dist/index.d.ts",
30+
"scripts": {
31+
"build": "tsc -b tsconfig.build.json",
32+
"clean": "tsc -b tsconfig.build.json --clean",
33+
"format": "prettier --write \"./**/*.{ts,js,json,md}\" --ignore-path ../../.prettierignore",
34+
"lint": "eslint . --ext .js,.ts --ignore-path='../../.eslintignore'",
35+
"test": "jest --coverage",
36+
"typecheck": "tsc -p tsconfig.json --noEmit"
37+
},
38+
"dependencies": {
39+
"eslint-visitor-keys": "^1.1.0"
40+
},
41+
"devDependencies": {
42+
"@typescript-eslint/types": "3.4.0"
43+
},
44+
"funding": {
45+
"type": "opencollective",
46+
"url": "https://opencollective.com/typescript-eslint"
47+
}
48+
}

packages/visitor-keys/src/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export { visitorKeys, VisitorKeys } from './visitor-keys';

packages/typescript-estree/src/visitor-keys.ts renamed to packages/visitor-keys/src/visitor-keys.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
import * as eslintVisitorKeys from 'eslint-visitor-keys';
22

3-
export const visitorKeys = eslintVisitorKeys.unionWith({
3+
interface VisitorKeys {
4+
readonly [type: string]: readonly string[] | undefined;
5+
}
6+
7+
const visitorKeys: VisitorKeys = eslintVisitorKeys.unionWith({
48
// Additional estree nodes.
59
Import: [],
610
// ES2020
@@ -125,3 +129,5 @@ export const visitorKeys = eslintVisitorKeys.unionWith({
125129
TSUnknownKeyword: [],
126130
TSVoidKeyword: [],
127131
});
132+
133+
export { visitorKeys, VisitorKeys };
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
import { AST_NODE_TYPES } from '@typescript-eslint/types';
2+
import { visitorKeys } from '../src';
3+
4+
const types = new Set(Object.keys(AST_NODE_TYPES));
5+
const keys = new Set(Object.keys(visitorKeys));
6+
7+
describe('Every ast node type should have a visitor key defined', () => {
8+
for (const type of types) {
9+
it(type, () => {
10+
expect(keys.has(type)).toBeTruthy();
11+
});
12+
}
13+
});
14+
15+
// these keys are defined by the base eslint module, and are not covered by our AST
16+
const IGNORED_KEYS = new Set([
17+
'ExperimentalRestProperty',
18+
'ExperimentalSpreadProperty',
19+
'JSXNamespacedName',
20+
]);
21+
describe('Every visitor key should have an ast node type defined', () => {
22+
for (const key of keys) {
23+
if (IGNORED_KEYS.has(key)) {
24+
continue;
25+
}
26+
27+
it(key, () => {
28+
expect(types.has(key)).toBeTruthy();
29+
});
30+
}
31+
});
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{
2+
"extends": "../../tsconfig.base.json",
3+
"compilerOptions": {
4+
"composite": true,
5+
"outDir": "./dist",
6+
"rootDir": "./src",
7+
"resolveJsonModule": true
8+
},
9+
"include": ["src", "typings"]
10+
}

packages/visitor-keys/tsconfig.json

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"extends": "./tsconfig.build.json",
3+
"compilerOptions": {
4+
"composite": false,
5+
"rootDir": "."
6+
},
7+
"include": ["src", "typings", "tests", "tools"]
8+
}

tests/integration/docker-compose.yml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ services:
2121
- /usr/eslint-plugin-tslint/tests
2222
- ../../packages/types/:/usr/types
2323
- /usr/types/tests
24+
- ../../packages/visitor-keys/:/usr/visitor-keys
25+
- /usr/types/visitor-keys
2426
# Runtime link to all the specific integration test files, so that most updates don't require a rebuild.
2527
- ./fixtures/typescript-and-tslint-plugins-together:/usr/linked
2628

@@ -42,6 +44,8 @@ services:
4244
- /usr/eslint-plugin/tests
4345
- ../../packages/types/:/usr/types
4446
- /usr/types/tests
47+
- ../../packages/visitor-keys/:/usr/visitor-keys
48+
- /usr/types/visitor-keys
4549
# Runtime link to all the specific integration test files, so that most updates don't require a rebuild.
4650
- ./fixtures/vue-sfc:/usr/linked
4751

@@ -63,6 +67,8 @@ services:
6367
- /usr/eslint-plugin/tests
6468
- ../../packages/types/:/usr/types
6569
- /usr/types/tests
70+
- ../../packages/visitor-keys/:/usr/visitor-keys
71+
- /usr/types/visitor-keys
6672
# Runtime link to all the specific integration test files, so that most updates don't require a rebuild.
6773
- ./fixtures/vue-jsx:/usr/linked
6874

@@ -84,6 +90,8 @@ services:
8490
- /usr/eslint-plugin/tests
8591
- ../../packages/types/:/usr/types
8692
- /usr/types/tests
93+
- ../../packages/visitor-keys/:/usr/visitor-keys
94+
- /usr/types/visitor-keys
8795
# Runtime link to all the specific integration test files, so that most updates don't require a rebuild.
8896
- ./fixtures/recommended-does-not-require-program:/usr/linked
8997

@@ -105,6 +113,8 @@ services:
105113
- /usr/eslint-plugin/tests
106114
- ../../packages/types/:/usr/types
107115
- /usr/types/tests
116+
- ../../packages/visitor-keys/:/usr/visitor-keys
117+
- /usr/types/visitor-keys
108118
# Runtime link to all the specific integration test files, so that most updates don't require a rebuild.
109119
- ./fixtures/markdown:/usr/linked
110120

@@ -126,5 +136,7 @@ services:
126136
- /usr/eslint-plugin/tests
127137
- ../../packages/types/:/usr/types
128138
- /usr/types/tests
139+
- ../../packages/visitor-keys/:/usr/visitor-keys
140+
- /usr/types/visitor-keys
129141
# Runtime link to all the specific integration test files, so that most updates don't require a rebuild.
130142
- ./fixtures/eslint-v6:/usr/linked

tests/integration/fixtures/eslint-v6/test.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ npm install eslint@6.0.0
1010

1111
# Use the local volumes for our own packages
1212
npm install $(npm pack /usr/types | tail -1)
13+
npm install $(npm pack /usr/visitor-keys | tail -1)
1314
npm install $(npm pack /usr/typescript-estree | tail -1)
1415
npm install $(npm pack /usr/parser | tail -1)
1516
npm install $(npm pack /usr/experimental-utils | tail -1)

tests/integration/fixtures/markdown/test.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ npm install
99

1010
# Use the local volumes for our own packages
1111
npm install $(npm pack /usr/types | tail -1)
12+
npm install $(npm pack /usr/visitor-keys | tail -1)
1213
npm install $(npm pack /usr/typescript-estree | tail -1)
1314
npm install $(npm pack /usr/parser | tail -1)
1415
npm install $(npm pack /usr/experimental-utils | tail -1)

tests/integration/fixtures/recommended-does-not-require-program/test.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ npm install
99

1010
# Use the local volumes for our own packages
1111
npm install $(npm pack /usr/types | tail -1)
12+
npm install $(npm pack /usr/visitor-keys | tail -1)
1213
npm install $(npm pack /usr/typescript-estree | tail -1)
1314
npm install $(npm pack /usr/parser | tail -1)
1415
npm install $(npm pack /usr/experimental-utils | tail -1)

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy