Skip to content

Commit

Permalink
feat(parser): pass services generated by typescript-estree to consumer (
Browse files Browse the repository at this point in the history
  • Loading branch information
uniqueiniquity authored and JamesHenry committed Jan 17, 2019
1 parent ebe638b commit 66b586d
Show file tree
Hide file tree
Showing 8 changed files with 451 additions and 15 deletions.
15 changes: 13 additions & 2 deletions packages/typescript-eslint-parser/src/parser.ts
Expand Up @@ -3,11 +3,19 @@ import * as typescriptESTree from 'typescript-estree';
import { analyzeScope } from './analyze-scope';
import { ParserOptions } from './parser-options';
import { visitorKeys } from './visitor-keys';
import { Program } from 'typescript';

const packageJSON = require('../package.json');

interface ParserServices {
program: Program | undefined;
esTreeNodeToTSNodeMap: WeakMap<object, any> | undefined;
tsNodeToESTreeNodeMap: WeakMap<object, any> | undefined;
}

interface ParseForESLintResult {
ast: any;
services: ParserServices;
visitorKeys: typeof visitorKeys;
scopeManager: ReturnType<typeof analyzeScope>;
}
Expand Down Expand Up @@ -43,7 +51,10 @@ export function parseForESLint<T extends ParserOptions = ParserOptions>(
options.sourceType = 'script';
}

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

traverser.traverse(ast, {
Expand All @@ -63,5 +74,5 @@ export function parseForESLint<T extends ParserOptions = ParserOptions>(
});

const scopeManager = analyzeScope(ast, options);
return { ast, scopeManager, visitorKeys };
return { ast, services, scopeManager, visitorKeys };
}
@@ -0,0 +1 @@
const x = [3, 4, 5];
@@ -0,0 +1,8 @@
{
"compilerOptions": {
"target": "es5",
"module": "commonjs",
"strict": true,
"esModuleInterop": true
}
}

0 comments on commit 66b586d

Please sign in to comment.