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

New: Pass services generated by typescript-estree to consumer #568

Closed
wants to merge 7 commits into from
Closed
Show file tree
Hide file tree
Changes from 3 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 package.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
"eslint-scope": "^4.0.0",
"eslint-visitor-keys": "^1.0.0",
"lodash": "^4.17.11",
"typescript-estree": "5.0.0"
"typescript-estree": "^5.1.0"
},
"devDependencies": {
"eslint": "^4.19.1",
Expand Down
10 changes: 7 additions & 3 deletions parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

"use strict";

const parse = require("typescript-estree").parse;
const converter = require("typescript-estree");
const astNodeTypes = require("typescript-estree").AST_NODE_TYPES;
const traverser = require("eslint/lib/util/traverser");
const analyzeScope = require("./analyze-scope");
Expand All @@ -21,6 +21,7 @@ const visitorKeys = require("./visitor-keys");
exports.version = require("./package.json").version;

exports.parseForESLint = function parseForESLint(code, options) {
let generateServices = false;
if (typeof options !== "object" || options === null) {
options = { useJSXTextNode: true };
} else if (typeof options.useJSXTextNode !== "boolean") {
Expand All @@ -32,8 +33,11 @@ exports.parseForESLint = function parseForESLint(code, options) {
options = Object.assign({}, options, { jsx: tsx });
}
}
if (typeof options.generateServices === "boolean" && options.generateServices) {
generateServices = true;
}

const ast = parse(code, options);
const { ast, services } = generateServices ? converter.parseAndGenerateServices(code, options) : { ast: converter.parse(code, options) };
const extraOptions = {
sourceType: ast.sourceType
};
Expand Down Expand Up @@ -72,7 +76,7 @@ exports.parseForESLint = function parseForESLint(code, options) {
});

const scopeManager = analyzeScope(ast, options, extraOptions);
return { ast, scopeManager, visitorKeys };
return { ast, services, scopeManager, visitorKeys };
};

exports.parse = function(code, options) {
Expand Down
1 change: 1 addition & 0 deletions tests/fixtures/services/isolated-file.src.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
const x = [3, 4, 5];
8 changes: 8 additions & 0 deletions tests/fixtures/services/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"compilerOptions": {
"target": "es5",
"module": "commonjs",
"strict": true,
"esModuleInterop": true
}
}
Loading