Skip to content
This repository was archived by the owner on Jan 19, 2019. It is now read-only.

Commit 1add926

Browse files
committed
Add visitorKeys
1 parent 817ff62 commit 1add926

File tree

3 files changed

+88
-4
lines changed

3 files changed

+88
-4
lines changed

lib/visitor-keys.js

+82
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
/**
2+
* @fileoverview The visitor keys for the new and updated node types
3+
* @author Michał Sajnóg <https://github.com/michalsnik>
4+
* MIT License
5+
*/
6+
7+
"use strict";
8+
9+
const Evk = require("eslint-visitor-keys");
10+
11+
module.exports = Evk.unionWith({
12+
ArrayPattern: ["typeAnnotation"],
13+
ArrowFunctionExpression: ["returnType", "typeParameters"],
14+
AssignmentPattern: ["typeAnnotation"],
15+
CallExpression: ["typeParameters"],
16+
ClassDeclaration: ["superTypeParameters", "typeParameters"],
17+
ClassExpression: ["superTypeParameters", "typeParameters"],
18+
ClassImplements: ["typeParameters"],
19+
ClassProperty: ["typeAnnotation"],
20+
FunctionDeclaration: ["returnType"],
21+
FunctionExpression: ["returnType", "typeParameters"],
22+
Identifier: ["typeAnnotation"],
23+
InterfaceDeclaration: ["typeParameters"],
24+
NewExpression: ["typeParameters"],
25+
ObjectPattern: ["typeAnnotation"],
26+
RestElement: ["typeAnnotation"],
27+
TaggedTemplateExpression: ["typeParameters"],
28+
VariableDeclarator: ["typeParameters"],
29+
30+
TSAbstractClassProperty: ["typeAnnotation", "key", "value"],
31+
TSAbstractKeyword: [],
32+
TSAbstractMethodDefinition: ["key", "value"],
33+
TSAnyKeyword: [],
34+
TSArrayType: [],
35+
TSAsyncKeyword: [],
36+
TSBooleanKeyword: [],
37+
TSConstructorType: ["typeAnnotation"],
38+
TSConstructSignature: ["typeAnnotation", "typeParameters"],
39+
TSDeclareKeyword: [],
40+
TSEnumDeclaration: ["members"],
41+
TSEnumMember: ["initializer"],
42+
TSExportAssignment: ["expression"],
43+
TSExportKeyword: [],
44+
TSImportType: ["parameter", "qualifier", "typeParameters"],
45+
TSLiteralType: [],
46+
TSIndexSignature: ["typeAnnotation", "index"],
47+
TSInterfaceBody: ["body"],
48+
TSInterfaceDeclaration: ["body", "id", "heritage"],
49+
TSInterfaceHeritage: ["id", "typeParameters"],
50+
TSFunctionType: ["typeAnnotation"],
51+
TSMethodSignature: ["typeAnnotation", "typeParameters", "key", "params"],
52+
TSModuleBlock: ["body"],
53+
TSModuleDeclaration: ["id", "body"],
54+
TSNamespaceFunctionDeclaration: [],
55+
TSNonNullExpression: [],
56+
TSNeverKeyword: [],
57+
TSNullKeyword: [],
58+
TSNumberKeyword: [],
59+
TSObjectKeyword: [],
60+
TSParameterProperty: ["parameter"],
61+
TSPrivateKeyword: [],
62+
TSPropertySignature: ["typeAnnotation", "key", "initializer"],
63+
TSProtectedKeyword: [],
64+
TSPublicKeyword: [],
65+
TSQualifiedName: ["left", "right"],
66+
TSQuestionToken: [],
67+
TSReadonlyKeyword: [],
68+
TSStaticKeyword: [],
69+
TSStringKeyword: [],
70+
TSSymbolKeyword: [],
71+
TSTypeAnnotation: ["typeAnnotation"],
72+
TSTypeLiteral: [],
73+
TSTypeOperator: ["typeAnnotation"],
74+
TSTypeParameter: ["constraint", "default"],
75+
TSTypeParameterDeclaration: ["params"],
76+
TSTypeParameterInstantiation: ["params"],
77+
TSTypePredicate: ["typeAnnotation", "parameterName"],
78+
TSTypeReference: ["typeName", "typeParameters"],
79+
TSUnionType: [],
80+
TSUndefinedKeyword: [],
81+
TSVoidKeyword: []
82+
});

package.json

+1
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@
5555
"betarelease": "eslint-prerelease beta"
5656
},
5757
"dependencies": {
58+
"eslint-visitor-keys": "^1.0.0",
5859
"lodash.unescape": "4.0.1",
5960
"semver": "5.5.0"
6061
},

parser.js

+5-4
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,11 @@
88

99
"use strict";
1010

11-
const astNodeTypes = require("./lib/ast-node-types"),
12-
ts = require("typescript"),
11+
const ts = require("typescript"),
12+
semver = require("semver"),
13+
astNodeTypes = require("./lib/ast-node-types"),
1314
convert = require("./lib/ast-converter"),
14-
semver = require("semver");
15+
visitorKeys = require("./lib/visitor-keys");
1516

1617
const SUPPORTED_TYPESCRIPT_VERSIONS = require("./package.json").devDependencies.typescript;
1718
const ACTIVE_TYPESCRIPT_VERSION = ts.version;
@@ -191,7 +192,7 @@ exports.parse = function parse(code, options) {
191192

192193
exports.parseForESLint = function parseForESLint(code, options) {
193194
const ast = generateAST(code, options, { isParseForESLint: true });
194-
return { ast };
195+
return { ast, visitorKeys };
195196
};
196197

197198
// Deep copy.

0 commit comments

Comments
 (0)