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

New: Add visitor keys #516

Merged
merged 5 commits into from
Oct 31, 2018
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Makefile.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ const NODE_MODULES = "./node_modules/",
// Files
MAKEFILE = "./Makefile.js",
/* eslint-disable no-use-before-define */
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(" ");
/* eslint-enable no-use-before-define */
Expand Down
6 changes: 4 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@
"main": "parser.js",
"version": "19.0.1",
"files": [
"parser.js"
"parser.js",
"visitor-keys.js"
],
"engines": {
"node": ">=6.14.0"
Expand Down Expand Up @@ -49,7 +50,8 @@
},
"dependencies": {
"eslint": "4.19.1",
"typescript-estree": "1.0.0"
"typescript-estree": "1.0.0",
"eslint-visitor-keys": "^1.0.0"
},
"peerDependencies": {
"typescript": "*"
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 };
};

// Deep copy.
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: []
});