Skip to content

feat(typescript-estree): remove parseWithNodeMaps #7120

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
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
33 changes: 0 additions & 33 deletions docs/architecture/TypeScript_ESTree.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -290,39 +290,6 @@ const { ast, services } = parseAndGenerateServices(code, {
});
```

#### `parseWithNodeMaps(code, options)`

Parses the given string of code with the options provided and returns both the ESTree-compatible AST as well as the node maps.
This allows you to work with both ASTs without the overhead of types that may come with `parseAndGenerateServices`.

```ts
interface ParseWithNodeMapsResult<T extends TSESTreeOptions> {
ast: TSESTree.Program;
esTreeNodeToTSNodeMap: ParserServices['esTreeNodeToTSNodeMap'];
tsNodeToESTreeNodeMap: ParserServices['tsNodeToESTreeNodeMap'];
}

declare function parseWithNodeMaps(
code: string,
options: ParseOptions = PARSE_DEFAULT_OPTIONS,
): ParseWithNodeMapsResult;
```

Example usage:

```js
import { parseWithNodeMaps } from '@typescript-eslint/typescript-estree';

const code = `const hello: string = 'world';`;
const { ast, esTreeNodeToTSNodeMap, tsNodeToESTreeNodeMap } = parseWithNodeMaps(
code,
{
loc: true,
range: true,
},
);
```

### `TSESTree`, `AST_NODE_TYPES` and `AST_TOKEN_TYPES`

Types for the AST produced by the parse functions.
Expand Down
2 changes: 0 additions & 2 deletions packages/typescript-estree/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,7 @@ export {
AST,
parse,
parseAndGenerateServices,
parseWithNodeMaps,
ParseAndGenerateServicesResult,
ParseWithNodeMapsResult,
} from './parser';
export {
ParserServices,
Expand Down
9 changes: 0 additions & 9 deletions packages/typescript-estree/src/parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -142,13 +142,6 @@ function parseWithNodeMapsInternal<T extends TSESTreeOptions = TSESTreeOptions>(
};
}

function parseWithNodeMaps<T extends TSESTreeOptions = TSESTreeOptions>(
code: string,
options?: T,
): ParseWithNodeMapsResult<T> {
return parseWithNodeMapsInternal(code, options, true);
}

let parseAndGenerateServicesCalls: { [fileName: string]: number } = {};
// Privately exported utility intended for use in typescript-eslint unit tests only
function clearParseAndGenerateServicesCalls(): void {
Expand Down Expand Up @@ -278,9 +271,7 @@ export {
AST,
parse,
parseAndGenerateServices,
parseWithNodeMaps,
ParseAndGenerateServicesResult,
ParseWithNodeMapsResult,
clearProgramCache,
clearParseAndGenerateServicesCalls,
};
Loading