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 all 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
6 changes: 3 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 parse = require("typescript-estree").parseAndGenerateServices;
const astNodeTypes = require("typescript-estree").AST_NODE_TYPES;
const traverser = require("eslint/lib/util/traverser");
const analyzeScope = require("./analyze-scope");
Expand Down Expand Up @@ -40,7 +40,7 @@ exports.parseForESLint = function parseForESLint(code, options) {
options.sourceType = "script";
}

const ast = parse(code, options);
const { ast, services } = parse(code, options);
ast.sourceType = options.sourceType;

traverser.traverse(ast, {
Expand All @@ -58,7 +58,7 @@ exports.parseForESLint = function parseForESLint(code, options) {
});

const scopeManager = analyzeScope(ast, options);
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
}
}
356 changes: 356 additions & 0 deletions tests/lib/__snapshots__/services.js.snap
Original file line number Diff line number Diff line change
@@ -0,0 +1,356 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`services fixtures/isolated-file.src 1`] = `
Object {
"body": Array [
Object {
"declarations": Array [
Object {
"id": Object {
"loc": Object {
"end": Object {
"column": 7,
"line": 1,
},
"start": Object {
"column": 6,
"line": 1,
},
},
"name": "x",
"range": Array [
6,
7,
],
"type": "Identifier",
},
"init": Object {
"elements": Array [
Object {
"loc": Object {
"end": Object {
"column": 12,
"line": 1,
},
"start": Object {
"column": 11,
"line": 1,
},
},
"range": Array [
11,
12,
],
"raw": "3",
"type": "Literal",
"value": 3,
},
Object {
"loc": Object {
"end": Object {
"column": 15,
"line": 1,
},
"start": Object {
"column": 14,
"line": 1,
},
},
"range": Array [
14,
15,
],
"raw": "4",
"type": "Literal",
"value": 4,
},
Object {
"loc": Object {
"end": Object {
"column": 18,
"line": 1,
},
"start": Object {
"column": 17,
"line": 1,
},
},
"range": Array [
17,
18,
],
"raw": "5",
"type": "Literal",
"value": 5,
},
],
"loc": Object {
"end": Object {
"column": 19,
"line": 1,
},
"start": Object {
"column": 10,
"line": 1,
},
},
"range": Array [
10,
19,
],
"type": "ArrayExpression",
},
"loc": Object {
"end": Object {
"column": 19,
"line": 1,
},
"start": Object {
"column": 6,
"line": 1,
},
},
"range": Array [
6,
19,
],
"type": "VariableDeclarator",
},
],
"kind": "const",
"loc": Object {
"end": Object {
"column": 20,
"line": 1,
},
"start": Object {
"column": 0,
"line": 1,
},
},
"range": Array [
0,
20,
],
"type": "VariableDeclaration",
},
],
"comments": Array [],
"loc": Object {
"end": Object {
"column": 20,
"line": 1,
},
"start": Object {
"column": 0,
"line": 1,
},
},
"range": Array [
0,
20,
],
"sourceType": "script",
"tokens": Array [
Object {
"loc": Object {
"end": Object {
"column": 5,
"line": 1,
},
"start": Object {
"column": 0,
"line": 1,
},
},
"range": Array [
0,
5,
],
"type": "Keyword",
"value": "const",
},
Object {
"loc": Object {
"end": Object {
"column": 7,
"line": 1,
},
"start": Object {
"column": 6,
"line": 1,
},
},
"range": Array [
6,
7,
],
"type": "Identifier",
"value": "x",
},
Object {
"loc": Object {
"end": Object {
"column": 9,
"line": 1,
},
"start": Object {
"column": 8,
"line": 1,
},
},
"range": Array [
8,
9,
],
"type": "Punctuator",
"value": "=",
},
Object {
"loc": Object {
"end": Object {
"column": 11,
"line": 1,
},
"start": Object {
"column": 10,
"line": 1,
},
},
"range": Array [
10,
11,
],
"type": "Punctuator",
"value": "[",
},
Object {
"loc": Object {
"end": Object {
"column": 12,
"line": 1,
},
"start": Object {
"column": 11,
"line": 1,
},
},
"range": Array [
11,
12,
],
"type": "Numeric",
"value": "3",
},
Object {
"loc": Object {
"end": Object {
"column": 13,
"line": 1,
},
"start": Object {
"column": 12,
"line": 1,
},
},
"range": Array [
12,
13,
],
"type": "Punctuator",
"value": ",",
},
Object {
"loc": Object {
"end": Object {
"column": 15,
"line": 1,
},
"start": Object {
"column": 14,
"line": 1,
},
},
"range": Array [
14,
15,
],
"type": "Numeric",
"value": "4",
},
Object {
"loc": Object {
"end": Object {
"column": 16,
"line": 1,
},
"start": Object {
"column": 15,
"line": 1,
},
},
"range": Array [
15,
16,
],
"type": "Punctuator",
"value": ",",
},
Object {
"loc": Object {
"end": Object {
"column": 18,
"line": 1,
},
"start": Object {
"column": 17,
"line": 1,
},
},
"range": Array [
17,
18,
],
"type": "Numeric",
"value": "5",
},
Object {
"loc": Object {
"end": Object {
"column": 19,
"line": 1,
},
"start": Object {
"column": 18,
"line": 1,
},
},
"range": Array [
18,
19,
],
"type": "Punctuator",
"value": "]",
},
Object {
"loc": Object {
"end": Object {
"column": 20,
"line": 1,
},
"start": Object {
"column": 19,
"line": 1,
},
},
"range": Array [
19,
20,
],
"type": "Punctuator",
"value": ";",
},
],
"type": "Program",
}
`;
Loading