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

Commit bacac5f

Browse files
michalsnikJamesHenry
authored andcommitted
New: Add visitor keys (#516)
1 parent 4172933 commit bacac5f

File tree

4 files changed

+93
-3
lines changed

4 files changed

+93
-3
lines changed

Makefile.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ const JEST = "jest",
5151

5252
// Files
5353
MAKEFILE = "./Makefile.js",
54-
JS_FILES = "parser.js",
54+
JS_FILES = "parser.js visitor-keys.js",
5555
TEST_FILES = find("tests/lib/").filter(fileType("js")).join(" "),
5656
TOOLS_FILES = find("tools/").filter(fileType("js")).join(" ");
5757

package.json

+3-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@
66
"main": "parser.js",
77
"version": "20.0.0",
88
"files": [
9-
"parser.js"
9+
"parser.js",
10+
"visitor-keys.js"
1011
],
1112
"engines": {
1213
"node": ">=6.14.0"
@@ -49,6 +50,7 @@
4950
},
5051
"dependencies": {
5152
"eslint": "4.19.1",
53+
"eslint-visitor-keys": "^1.0.0",
5254
"typescript-estree": "2.1.0"
5355
},
5456
"peerDependencies": {

parser.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
const parse = require("typescript-estree").parse;
1212
const astNodeTypes = require("typescript-estree").AST_NODE_TYPES;
1313
const traverser = require("eslint/lib/util/traverser");
14+
const visitorKeys = require("./visitor-keys");
1415

1516
//------------------------------------------------------------------------------
1617
// Public
@@ -29,7 +30,7 @@ exports.parseForESLint = function parseForESLint(code, options) {
2930
}
3031
}
3132
});
32-
return { ast };
33+
return { ast, visitorKeys };
3334
};
3435

3536
exports.parse = function(code, options) {

visitor-keys.js

+87
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
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", "typeParameters"],
21+
FunctionExpression: ["returnType", "typeParameters"],
22+
Identifier: ["typeAnnotation"],
23+
InterfaceDeclaration: ["typeParameters"],
24+
NewExpression: ["typeParameters"],
25+
ObjectPattern: ["typeAnnotation"],
26+
/**
27+
* According to https://github.com/estree/estree/blob/master/extensions/type-annotations.md
28+
* RestElement should have "typeAnnotation", but has not. Annotation is added on the "parameter" node
29+
*/
30+
RestElement: [],
31+
TaggedTemplateExpression: ["typeParameters"],
32+
VariableDeclarator: ["typeParameters"],
33+
34+
TSAbstractClassProperty: ["typeAnnotation", "key", "value"],
35+
TSAbstractClassDeclaration: ["id", "body", "superClass", "implements"],
36+
TSAbstractKeyword: [],
37+
TSAbstractMethodDefinition: ["key", "value"],
38+
TSAnyKeyword: [],
39+
TSArrayType: ["elementType"],
40+
TSAsyncKeyword: [],
41+
TSBooleanKeyword: [],
42+
TSConstructorType: ["typeAnnotation", "parameters"],
43+
TSConstructSignature: ["typeAnnotation", "typeParameters"],
44+
TSDeclareKeyword: [],
45+
TSEnumDeclaration: ["members"],
46+
TSEnumMember: ["initializer"],
47+
TSExportAssignment: ["expression"],
48+
TSExportKeyword: [],
49+
TSImportType: ["parameter", "qualifier", "typeParameters"],
50+
TSLiteralType: ["literal"],
51+
TSIndexSignature: ["typeAnnotation", "index"],
52+
TSInterfaceBody: ["body"],
53+
TSInterfaceDeclaration: ["body", "id", "heritage"],
54+
TSInterfaceHeritage: ["id", "typeParameters"],
55+
TSFunctionType: ["typeAnnotation"],
56+
TSMethodSignature: ["typeAnnotation", "typeParameters", "key", "params"],
57+
TSModuleBlock: ["body"],
58+
TSModuleDeclaration: ["id", "body"],
59+
TSNamespaceFunctionDeclaration: [],
60+
TSNonNullExpression: ["expression"],
61+
TSNeverKeyword: [],
62+
TSNullKeyword: [],
63+
TSNumberKeyword: [],
64+
TSObjectKeyword: [],
65+
TSParameterProperty: ["parameter"],
66+
TSPrivateKeyword: [],
67+
TSPropertySignature: ["typeAnnotation", "key", "initializer"],
68+
TSProtectedKeyword: [],
69+
TSPublicKeyword: [],
70+
TSQualifiedName: ["left", "right"],
71+
TSQuestionToken: [],
72+
TSReadonlyKeyword: [],
73+
TSStaticKeyword: [],
74+
TSStringKeyword: [],
75+
TSSymbolKeyword: [],
76+
TSTypeAnnotation: ["typeAnnotation"],
77+
TSTypeLiteral: ["members"],
78+
TSTypeOperator: ["typeAnnotation"],
79+
TSTypeParameter: ["constraint", "default"],
80+
TSTypeParameterDeclaration: ["params"],
81+
TSTypeParameterInstantiation: ["params"],
82+
TSTypePredicate: ["typeAnnotation", "parameterName"],
83+
TSTypeReference: ["typeName", "typeParameters"],
84+
TSUnionType: ["types"],
85+
TSUndefinedKeyword: [],
86+
TSVoidKeyword: []
87+
});

0 commit comments

Comments
 (0)