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

Commit

Permalink
New: Add visitor keys (#516)
Browse files Browse the repository at this point in the history
  • Loading branch information
michalsnik authored and JamesHenry committed Oct 31, 2018
1 parent 4172933 commit bacac5f
Show file tree
Hide file tree
Showing 4 changed files with 93 additions and 3 deletions.
2 changes: 1 addition & 1 deletion Makefile.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ const JEST = "jest",

// Files
MAKEFILE = "./Makefile.js",
JS_FILES = "parser.js",
JS_FILES = "parser.js visitor-keys.js",
TEST_FILES = find("tests/lib/").filter(fileType("js")).join(" "),
TOOLS_FILES = find("tools/").filter(fileType("js")).join(" ");

Expand Down
4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@
"main": "parser.js",
"version": "20.0.0",
"files": [
"parser.js"
"parser.js",
"visitor-keys.js"
],
"engines": {
"node": ">=6.14.0"
Expand Down Expand Up @@ -49,6 +50,7 @@
},
"dependencies": {
"eslint": "4.19.1",
"eslint-visitor-keys": "^1.0.0",
"typescript-estree": "2.1.0"
},
"peerDependencies": {
Expand Down
3 changes: 2 additions & 1 deletion parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
const parse = require("typescript-estree").parse;
const astNodeTypes = require("typescript-estree").AST_NODE_TYPES;
const traverser = require("eslint/lib/util/traverser");
const visitorKeys = require("./visitor-keys");

//------------------------------------------------------------------------------
// Public
Expand All @@ -29,7 +30,7 @@ exports.parseForESLint = function parseForESLint(code, options) {
}
}
});
return { ast };
return { ast, visitorKeys };
};

exports.parse = function(code, options) {
Expand Down
87 changes: 87 additions & 0 deletions visitor-keys.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
/**
* @fileoverview The visitor keys for the new and updated node types
* @author Michał Sajnóg <https://github.com/michalsnik>
* MIT License
*/

"use strict";

const Evk = require("eslint-visitor-keys");

module.exports = Evk.unionWith({
ArrayPattern: ["typeAnnotation"],
ArrowFunctionExpression: ["returnType", "typeParameters"],
AssignmentPattern: ["typeAnnotation"],
CallExpression: ["typeParameters"],
ClassDeclaration: ["superTypeParameters", "typeParameters"],
ClassExpression: ["superTypeParameters", "typeParameters"],
ClassImplements: ["typeParameters"],
ClassProperty: ["typeAnnotation"],
FunctionDeclaration: ["returnType", "typeParameters"],
FunctionExpression: ["returnType", "typeParameters"],
Identifier: ["typeAnnotation"],
InterfaceDeclaration: ["typeParameters"],
NewExpression: ["typeParameters"],
ObjectPattern: ["typeAnnotation"],
/**
* According to https://github.com/estree/estree/blob/master/extensions/type-annotations.md
* RestElement should have "typeAnnotation", but has not. Annotation is added on the "parameter" node
*/
RestElement: [],
TaggedTemplateExpression: ["typeParameters"],
VariableDeclarator: ["typeParameters"],

TSAbstractClassProperty: ["typeAnnotation", "key", "value"],
TSAbstractClassDeclaration: ["id", "body", "superClass", "implements"],
TSAbstractKeyword: [],
TSAbstractMethodDefinition: ["key", "value"],
TSAnyKeyword: [],
TSArrayType: ["elementType"],
TSAsyncKeyword: [],
TSBooleanKeyword: [],
TSConstructorType: ["typeAnnotation", "parameters"],
TSConstructSignature: ["typeAnnotation", "typeParameters"],
TSDeclareKeyword: [],
TSEnumDeclaration: ["members"],
TSEnumMember: ["initializer"],
TSExportAssignment: ["expression"],
TSExportKeyword: [],
TSImportType: ["parameter", "qualifier", "typeParameters"],
TSLiteralType: ["literal"],
TSIndexSignature: ["typeAnnotation", "index"],
TSInterfaceBody: ["body"],
TSInterfaceDeclaration: ["body", "id", "heritage"],
TSInterfaceHeritage: ["id", "typeParameters"],
TSFunctionType: ["typeAnnotation"],
TSMethodSignature: ["typeAnnotation", "typeParameters", "key", "params"],
TSModuleBlock: ["body"],
TSModuleDeclaration: ["id", "body"],
TSNamespaceFunctionDeclaration: [],
TSNonNullExpression: ["expression"],
TSNeverKeyword: [],
TSNullKeyword: [],
TSNumberKeyword: [],
TSObjectKeyword: [],
TSParameterProperty: ["parameter"],
TSPrivateKeyword: [],
TSPropertySignature: ["typeAnnotation", "key", "initializer"],
TSProtectedKeyword: [],
TSPublicKeyword: [],
TSQualifiedName: ["left", "right"],
TSQuestionToken: [],
TSReadonlyKeyword: [],
TSStaticKeyword: [],
TSStringKeyword: [],
TSSymbolKeyword: [],
TSTypeAnnotation: ["typeAnnotation"],
TSTypeLiteral: ["members"],
TSTypeOperator: ["typeAnnotation"],
TSTypeParameter: ["constraint", "default"],
TSTypeParameterDeclaration: ["params"],
TSTypeParameterInstantiation: ["params"],
TSTypePredicate: ["typeAnnotation", "parameterName"],
TSTypeReference: ["typeName", "typeParameters"],
TSUnionType: ["types"],
TSUndefinedKeyword: [],
TSVoidKeyword: []
});

0 comments on commit bacac5f

Please sign in to comment.