diff --git a/packages/parser/package.json b/packages/parser/package.json index 3131dabaaf9..21445c36ece 100644 --- a/packages/parser/package.json +++ b/packages/parser/package.json @@ -2,8 +2,8 @@ "name": "@typescript-eslint/parser", "version": "2.34.0", "description": "An ESLint custom parser which leverages TypeScript ESTree", - "main": "dist/parser.js", - "types": "dist/parser.d.ts", + "main": "dist/index.js", + "types": "dist/index.d.ts", "files": [ "dist", "README.md", diff --git a/packages/parser/src/index.ts b/packages/parser/src/index.ts new file mode 100644 index 00000000000..1795fe1b36f --- /dev/null +++ b/packages/parser/src/index.ts @@ -0,0 +1,6 @@ +export { parse, parseForESLint, ParserOptions } from './parser'; +export { ParserServices } from '@typescript-eslint/typescript-estree'; +export { clearCaches } from '@typescript-eslint/typescript-estree'; + +// note - cannot migrate this to an import statement because it will make TSC copy the package.json to the dist folder +export const version: string = require('../package.json').version; diff --git a/packages/parser/src/parser.ts b/packages/parser/src/parser.ts index 00c0fe57d43..b658c96c82d 100644 --- a/packages/parser/src/parser.ts +++ b/packages/parser/src/parser.ts @@ -1,6 +1,5 @@ import { TSESLint } from '@typescript-eslint/experimental-utils'; import { - AST_NODE_TYPES, parseAndGenerateServices, ParserServices, TSESTreeOptions, @@ -11,9 +10,6 @@ import { analyzeScope } from './analyze-scope'; type ParserOptions = TSESLint.ParserOptions; -// note - cannot migrate this to an import statement because it will make TSC copy the package.json to the dist folder -const packageJSON = require('../package.json'); - interface ParseForESLintResult { ast: TSESTree.Program & { range?: [number, number]; @@ -35,22 +31,14 @@ function validateBoolean( return value; } -//------------------------------------------------------------------------------ -// Public -//------------------------------------------------------------------------------ - -export const version = packageJSON.version; - -export const Syntax = Object.freeze(AST_NODE_TYPES); - -export function parse( +function parse( code: string, options?: ParserOptions, ): ParseForESLintResult['ast'] { return parseForESLint(code, options).ast; } -export function parseForESLint( +function parseForESLint( code: string, options?: ParserOptions | null, ): ParseForESLintResult { @@ -98,5 +86,4 @@ export function parseForESLint( return { ast, services, scopeManager, visitorKeys }; } -export { ParserServices, ParserOptions }; -export { clearCaches } from '@typescript-eslint/typescript-estree'; +export { parse, parseForESLint, ParserOptions }; diff --git a/packages/parser/tests/lib/parser.ts b/packages/parser/tests/lib/parser.ts index 3881456d2ff..442332b3a84 100644 --- a/packages/parser/tests/lib/parser.ts +++ b/packages/parser/tests/lib/parser.ts @@ -1,10 +1,8 @@ import { TSESLint } from '@typescript-eslint/experimental-utils'; import * as typescriptESTree from '@typescript-eslint/typescript-estree'; -import { parse, parseForESLint, Syntax } from '../../src/parser'; +import { parse, parseForESLint } from '../../src/parser'; import * as scope from '../../src/analyze-scope'; -const { AST_NODE_TYPES } = typescriptESTree; - describe('parser', () => { it('parse() should return just the AST from parseForESLint()', () => { const code = 'const valid = true;'; @@ -65,17 +63,6 @@ describe('parser', () => { }); }); - it('Syntax should contain a frozen object of AST_NODE_TYPES', () => { - expect(Syntax).toEqual(AST_NODE_TYPES); - expect( - // intentionally breaking the readonly - // eslint-disable-next-line @typescript-eslint/no-explicit-any - () => ((Syntax as any).ArrayExpression = 'foo'), - ).toThrowErrorMatchingInlineSnapshot( - `"Cannot assign to read only property 'ArrayExpression' of object '#'"`, - ); - }); - it('`warnOnUnsupportedTypeScriptVersion: false` should set `loggerFn: false` on typescript-estree', () => { const code = 'const valid = true;'; const spy = jest.spyOn(typescriptESTree, 'parseAndGenerateServices'); diff --git a/packages/typescript-estree/package.json b/packages/typescript-estree/package.json index 14e3b4d6cac..0f4827286da 100644 --- a/packages/typescript-estree/package.json +++ b/packages/typescript-estree/package.json @@ -2,8 +2,8 @@ "name": "@typescript-eslint/typescript-estree", "version": "2.34.0", "description": "A parser that converts TypeScript source code into an ESTree compatible form", - "main": "dist/parser.js", - "types": "dist/parser.d.ts", + "main": "dist/index.js", + "types": "dist/index.d.ts", "files": [ "dist", "README.md", diff --git a/packages/typescript-estree/src/index.ts b/packages/typescript-estree/src/index.ts new file mode 100644 index 00000000000..d7dc009d4b4 --- /dev/null +++ b/packages/typescript-estree/src/index.ts @@ -0,0 +1,14 @@ +export { + AST, + parse, + parseAndGenerateServices, + ParseAndGenerateServicesResult, +} from './parser'; +export { ParserServices, TSESTreeOptions } from './parser-options'; +export { simpleTraverse } from './simple-traverse'; +export { visitorKeys } from './visitor-keys'; +export * from './ts-estree'; +export { clearCaches } from './create-program/createWatchProgram'; + +// note - cannot migrate this to an import statement because it will make TSC copy the package.json to the dist folder +export const version: string = require('../package.json').version; diff --git a/packages/typescript-estree/src/parser.ts b/packages/typescript-estree/src/parser.ts index f4a1d2047c9..7c2744d32a0 100644 --- a/packages/typescript-estree/src/parser.ts +++ b/packages/typescript-estree/src/parser.ts @@ -323,10 +323,6 @@ function warnAboutTSVersion(): void { } } -//------------------------------------------------------------------------------ -// Parser -//------------------------------------------------------------------------------ - // eslint-disable-next-line @typescript-eslint/no-empty-interface interface EmptyObject {} type AST = TSESTree.Program & @@ -338,12 +334,6 @@ interface ParseAndGenerateServicesResult { services: ParserServices; } -//------------------------------------------------------------------------------ -// Public -//------------------------------------------------------------------------------ - -const version: string = require('../package.json').version; - function parse( code: string, options?: T, @@ -472,15 +462,4 @@ function parseAndGenerateServices( }; } -export { - AST, - parse, - parseAndGenerateServices, - ParseAndGenerateServicesResult, - version, -}; -export { ParserServices, TSESTreeOptions } from './parser-options'; -export { simpleTraverse } from './simple-traverse'; -export { visitorKeys } from './visitor-keys'; -export * from './ts-estree'; -export { clearCaches } from './create-program/createWatchProgram'; +export { AST, parse, parseAndGenerateServices, ParseAndGenerateServicesResult }; diff --git a/packages/typescript-estree/tests/lib/parse.ts b/packages/typescript-estree/tests/lib/parse.ts index 2504a2fe332..1e8eaa2305f 100644 --- a/packages/typescript-estree/tests/lib/parse.ts +++ b/packages/typescript-estree/tests/lib/parse.ts @@ -1,6 +1,6 @@ import debug from 'debug'; import { join, resolve } from 'path'; -import * as parser from '../../src/parser'; +import * as parser from '../../src'; import * as astConverter from '../../src/ast-converter'; import { TSESTreeOptions } from '../../src/parser-options'; import * as sharedParserUtils from '../../src/create-program/shared'; diff --git a/packages/typescript-estree/tests/lib/persistentParse.ts b/packages/typescript-estree/tests/lib/persistentParse.ts index 2b45974e677..d002cd869c0 100644 --- a/packages/typescript-estree/tests/lib/persistentParse.ts +++ b/packages/typescript-estree/tests/lib/persistentParse.ts @@ -1,7 +1,7 @@ import fs from 'fs'; import path from 'path'; import tmp from 'tmp'; -import { clearCaches, parseAndGenerateServices } from '../../src/parser'; +import { clearCaches, parseAndGenerateServices } from '../../src'; const CONTENTS = { foo: 'console.log("foo")', diff --git a/packages/typescript-estree/tests/lib/semantic-diagnostics-enabled.ts b/packages/typescript-estree/tests/lib/semantic-diagnostics-enabled.ts index fc05b04ec58..150e55792c6 100644 --- a/packages/typescript-estree/tests/lib/semantic-diagnostics-enabled.ts +++ b/packages/typescript-estree/tests/lib/semantic-diagnostics-enabled.ts @@ -1,6 +1,6 @@ import { readFileSync } from 'fs'; import glob from 'glob'; -import * as parser from '../../src/parser'; +import * as parser from '../../src'; import { extname } from 'path'; import { formatSnapshotName, isJSXFileType } from '../../tools/test-utils'; diff --git a/packages/typescript-estree/tests/lib/semanticInfo.ts b/packages/typescript-estree/tests/lib/semanticInfo.ts index ee9f4c9150d..36726ac1d52 100644 --- a/packages/typescript-estree/tests/lib/semanticInfo.ts +++ b/packages/typescript-estree/tests/lib/semanticInfo.ts @@ -12,7 +12,7 @@ import { clearCaches, parseAndGenerateServices, ParseAndGenerateServicesResult, -} from '../../src/parser'; +} from '../../src'; import { TSESTree } from '../../src/ts-estree'; const FIXTURES_DIR = './tests/fixtures/semanticInfo'; diff --git a/packages/typescript-estree/tools/test-utils.ts b/packages/typescript-estree/tools/test-utils.ts index 2a9b2f11ddf..1b386be1449 100644 --- a/packages/typescript-estree/tools/test-utils.ts +++ b/packages/typescript-estree/tools/test-utils.ts @@ -1,4 +1,4 @@ -import * as parser from '../src/parser'; +import * as parser from '../src'; import { TSESTreeOptions } from '../src/parser-options'; export function parseCodeAndGenerateServices(