Skip to content

feat(parser): add standalone isolatedDeclarations option #10499

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
8 changes: 8 additions & 0 deletions docs/packages/Parser.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ interface ParserOptions {
ecmaVersion?: number | 'latest';
emitDecoratorMetadata?: boolean;
experimentalDecorators?: boolean;
isolatedDeclarations?: boolean;
extraFileExtensions?: string[];
jsDocParsingMode?: 'all' | 'none' | 'type-info';
jsxFragmentName?: string | null;
Expand Down Expand Up @@ -156,6 +157,13 @@ Add extensions starting with `.`, followed by the file extension. E.g. for a `.v
See [Changes to `extraFileExtensions` with `projectService`](../troubleshooting/typed-linting/Performance.mdx#changes-to-extrafileextensions-with-projectservice) to avoid performance issues.
:::

### `isolatedDeclarations`

> Default `undefined`.

This option allow you to tell parser to act as if `isolatedDeclarations: true` is set in `tsconfig.json`, but without [type-aware linting](../getting-started/Typed_Linting.mdx).
In other words, you don't have to specify `parserOptions.project` in this case, making the linting process faster.

### `jsDocParsingMode`

> Default if `parserOptions.project` is set, then `'all'`, otherwise `'none'`
Expand Down
1 change: 1 addition & 0 deletions packages/parser/src/parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,7 @@ export function parseForESLint(
parserOptions.emitDecoratorMetadata === true;
services.experimentalDecorators ??=
parserOptions.experimentalDecorators === true;
services.isolatedDeclarations ??= parserOptions.isolatedDeclarations === true;

return { ast, scopeManager, services, visitorKeys };
}
Expand Down
2 changes: 1 addition & 1 deletion packages/scope-manager/src/analyze.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ export interface AnalyzeOptions {
*/
sourceType?: SourceType;

// TODO - remove this in v8
// TODO - remove this in v10
/**
* @deprecated This option never did what it was intended for and will be removed in a future major release.
*/
Expand Down
2 changes: 2 additions & 0 deletions packages/types/src/parser-options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,8 @@ export interface ParserOptions {
experimentalDecorators?: boolean;
extraFileExtensions?: string[];
filePath?: string;
// use isolatedDeclarations without specifying parserOptions.project
isolatedDeclarations?: boolean;
jsDocParsingMode?: JSDocParsingMode;
jsxFragmentName?: string | null;
// scope-manager specific
Expand Down
2 changes: 2 additions & 0 deletions packages/typescript-estree/src/createParserServices.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ export function createParserServices(
return {
emitDecoratorMetadata: undefined,
experimentalDecorators: undefined,
isolatedDeclarations: undefined,
program,
// we always return the node maps because
// (a) they don't require type info and
Expand All @@ -27,6 +28,7 @@ export function createParserServices(
// not set in the config is the same as off
emitDecoratorMetadata: compilerOptions.emitDecoratorMetadata ?? false,
experimentalDecorators: compilerOptions.experimentalDecorators ?? false,
isolatedDeclarations: compilerOptions.isolatedDeclarations ?? false,
...astMaps,
getSymbolAtLocation: node =>
checker.getSymbolAtLocation(astMaps.esTreeNodeToTSNodeMap.get(node)),
Expand Down
1 change: 1 addition & 0 deletions packages/typescript-estree/src/parser-options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,7 @@ export interface ParserWeakMapESTreeToTSNode<
export interface ParserServicesBase {
emitDecoratorMetadata: boolean | undefined;
experimentalDecorators: boolean | undefined;
isolatedDeclarations: boolean | undefined;
}
export interface ParserServicesNodeMaps {
esTreeNodeToTSNodeMap: ParserWeakMapESTreeToTSNode;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -290,6 +290,7 @@ exports[`parseAndGenerateServices isolated parsing should parse .js file - with
"emitDecoratorMetadata": undefined,
"esTreeNodeToTSNodeMap": WeakMap {},
"experimentalDecorators": undefined,
"isolatedDeclarations": undefined,
"program": "No Program",
"tsNodeToESTreeNodeMap": WeakMap {},
},
Expand Down Expand Up @@ -586,6 +587,7 @@ exports[`parseAndGenerateServices isolated parsing should parse .js file - with
"emitDecoratorMetadata": undefined,
"esTreeNodeToTSNodeMap": WeakMap {},
"experimentalDecorators": undefined,
"isolatedDeclarations": undefined,
"program": "No Program",
"tsNodeToESTreeNodeMap": WeakMap {},
},
Expand Down Expand Up @@ -772,6 +774,7 @@ exports[`parseAndGenerateServices isolated parsing should parse .js file - witho
"emitDecoratorMetadata": undefined,
"esTreeNodeToTSNodeMap": WeakMap {},
"experimentalDecorators": undefined,
"isolatedDeclarations": undefined,
"program": "No Program",
"tsNodeToESTreeNodeMap": WeakMap {},
},
Expand Down Expand Up @@ -958,6 +961,7 @@ exports[`parseAndGenerateServices isolated parsing should parse .js file - witho
"emitDecoratorMetadata": undefined,
"esTreeNodeToTSNodeMap": WeakMap {},
"experimentalDecorators": undefined,
"isolatedDeclarations": undefined,
"program": "No Program",
"tsNodeToESTreeNodeMap": WeakMap {},
},
Expand Down Expand Up @@ -1180,6 +1184,7 @@ exports[`parseAndGenerateServices isolated parsing should parse .json file - wit
"emitDecoratorMetadata": undefined,
"esTreeNodeToTSNodeMap": WeakMap {},
"experimentalDecorators": undefined,
"isolatedDeclarations": undefined,
"program": "No Program",
"tsNodeToESTreeNodeMap": WeakMap {},
},
Expand Down Expand Up @@ -1476,6 +1481,7 @@ exports[`parseAndGenerateServices isolated parsing should parse .jsx file - with
"emitDecoratorMetadata": undefined,
"esTreeNodeToTSNodeMap": WeakMap {},
"experimentalDecorators": undefined,
"isolatedDeclarations": undefined,
"program": "No Program",
"tsNodeToESTreeNodeMap": WeakMap {},
},
Expand Down Expand Up @@ -1772,6 +1778,7 @@ exports[`parseAndGenerateServices isolated parsing should parse .jsx file - with
"emitDecoratorMetadata": undefined,
"esTreeNodeToTSNodeMap": WeakMap {},
"experimentalDecorators": undefined,
"isolatedDeclarations": undefined,
"program": "No Program",
"tsNodeToESTreeNodeMap": WeakMap {},
},
Expand Down Expand Up @@ -1958,6 +1965,7 @@ exports[`parseAndGenerateServices isolated parsing should parse .jsx file - with
"emitDecoratorMetadata": undefined,
"esTreeNodeToTSNodeMap": WeakMap {},
"experimentalDecorators": undefined,
"isolatedDeclarations": undefined,
"program": "No Program",
"tsNodeToESTreeNodeMap": WeakMap {},
},
Expand Down Expand Up @@ -2144,6 +2152,7 @@ exports[`parseAndGenerateServices isolated parsing should parse .jsx file - with
"emitDecoratorMetadata": undefined,
"esTreeNodeToTSNodeMap": WeakMap {},
"experimentalDecorators": undefined,
"isolatedDeclarations": undefined,
"program": "No Program",
"tsNodeToESTreeNodeMap": WeakMap {},
},
Expand Down Expand Up @@ -2330,6 +2339,7 @@ exports[`parseAndGenerateServices isolated parsing should parse .ts file - witho
"emitDecoratorMetadata": undefined,
"esTreeNodeToTSNodeMap": WeakMap {},
"experimentalDecorators": undefined,
"isolatedDeclarations": undefined,
"program": "No Program",
"tsNodeToESTreeNodeMap": WeakMap {},
},
Expand Down Expand Up @@ -2516,6 +2526,7 @@ exports[`parseAndGenerateServices isolated parsing should parse .ts file - witho
"emitDecoratorMetadata": undefined,
"esTreeNodeToTSNodeMap": WeakMap {},
"experimentalDecorators": undefined,
"isolatedDeclarations": undefined,
"program": "No Program",
"tsNodeToESTreeNodeMap": WeakMap {},
},
Expand Down Expand Up @@ -2812,6 +2823,7 @@ exports[`parseAndGenerateServices isolated parsing should parse .tsx file - with
"emitDecoratorMetadata": undefined,
"esTreeNodeToTSNodeMap": WeakMap {},
"experimentalDecorators": undefined,
"isolatedDeclarations": undefined,
"program": "No Program",
"tsNodeToESTreeNodeMap": WeakMap {},
},
Expand Down Expand Up @@ -3108,6 +3120,7 @@ exports[`parseAndGenerateServices isolated parsing should parse .tsx file - with
"emitDecoratorMetadata": undefined,
"esTreeNodeToTSNodeMap": WeakMap {},
"experimentalDecorators": undefined,
"isolatedDeclarations": undefined,
"program": "No Program",
"tsNodeToESTreeNodeMap": WeakMap {},
},
Expand Down Expand Up @@ -3294,6 +3307,7 @@ exports[`parseAndGenerateServices isolated parsing should parse .tsx file - with
"emitDecoratorMetadata": undefined,
"esTreeNodeToTSNodeMap": WeakMap {},
"experimentalDecorators": undefined,
"isolatedDeclarations": undefined,
"program": "No Program",
"tsNodeToESTreeNodeMap": WeakMap {},
},
Expand Down Expand Up @@ -3480,6 +3494,7 @@ exports[`parseAndGenerateServices isolated parsing should parse .tsx file - with
"emitDecoratorMetadata": undefined,
"esTreeNodeToTSNodeMap": WeakMap {},
"experimentalDecorators": undefined,
"isolatedDeclarations": undefined,
"program": "No Program",
"tsNodeToESTreeNodeMap": WeakMap {},
},
Expand Down Expand Up @@ -3776,6 +3791,7 @@ exports[`parseAndGenerateServices isolated parsing should parse .vue file - with
"emitDecoratorMetadata": undefined,
"esTreeNodeToTSNodeMap": WeakMap {},
"experimentalDecorators": undefined,
"isolatedDeclarations": undefined,
"program": "No Program",
"tsNodeToESTreeNodeMap": WeakMap {},
},
Expand Down Expand Up @@ -3962,6 +3978,7 @@ exports[`parseAndGenerateServices isolated parsing should parse .vue file - with
"emitDecoratorMetadata": undefined,
"esTreeNodeToTSNodeMap": WeakMap {},
"experimentalDecorators": undefined,
"isolatedDeclarations": undefined,
"program": "No Program",
"tsNodeToESTreeNodeMap": WeakMap {},
},
Expand Down Expand Up @@ -4148,6 +4165,7 @@ exports[`parseAndGenerateServices isolated parsing should parse .vue file - with
"emitDecoratorMetadata": undefined,
"esTreeNodeToTSNodeMap": WeakMap {},
"experimentalDecorators": undefined,
"isolatedDeclarations": undefined,
"program": "No Program",
"tsNodeToESTreeNodeMap": WeakMap {},
},
Expand Down
1 change: 1 addition & 0 deletions packages/website/src/components/linter/createParser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ export function createParser(
checker.getTypeAtLocation(
converted.astMaps.esTreeNodeToTSNodeMap.get(node),
),
isolatedDeclarations: compilerOptions.isolatedDeclarations ?? false,
program,
tsNodeToESTreeNodeMap: converted.astMaps.tsNodeToESTreeNodeMap,
},
Expand Down
1 change: 1 addition & 0 deletions packages/website/src/vendor/sandbox.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,7 @@ export declare const createTypeScriptSandbox: (
importHelpers?: boolean;
inlineSourceMap?: boolean;
inlineSources?: boolean;
isolatedDeclarations?: boolean;
isolatedModules?: boolean;
jsx?: MonacoEditor.languages.typescript.JsxEmit;
keyofStringsOnly?: boolean;
Expand Down
Loading