diff --git a/Makefile.js b/Makefile.js index ed73020..3cf9d1f 100644 --- a/Makefile.js +++ b/Makefile.js @@ -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(" "); diff --git a/package.json b/package.json index 94ee326..81130e6 100644 --- a/package.json +++ b/package.json @@ -6,7 +6,8 @@ "main": "parser.js", "version": "20.0.0", "files": [ - "parser.js" + "parser.js", + "visitor-keys.js" ], "engines": { "node": ">=6.14.0" @@ -49,6 +50,7 @@ }, "dependencies": { "eslint": "4.19.1", + "eslint-visitor-keys": "^1.0.0", "typescript-estree": "2.1.0" }, "peerDependencies": { diff --git a/parser.js b/parser.js index c5ed514..32b4e7c 100644 --- a/parser.js +++ b/parser.js @@ -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 @@ -29,7 +30,7 @@ exports.parseForESLint = function parseForESLint(code, options) { } } }); - return { ast }; + return { ast, visitorKeys }; }; exports.parse = function(code, options) { diff --git a/visitor-keys.js b/visitor-keys.js new file mode 100644 index 0000000..18cf592 --- /dev/null +++ b/visitor-keys.js @@ -0,0 +1,87 @@ +/** + * @fileoverview The visitor keys for the new and updated node types + * @author Michał Sajnóg + * 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: [] +});