Skip to content

Commit db79614

Browse files
committed
feat(typescript-estree): add fragment options
1 parent c8fe515 commit db79614

File tree

4 files changed

+13
-0
lines changed

4 files changed

+13
-0
lines changed

packages/experimental-utils/src/ts-eslint/ParserOptions.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,4 +19,5 @@ export interface ParserOptions {
1919
tsconfigRootDir?: string;
2020
useJSXTextNode?: boolean;
2121
warnOnUnsupportedTypeScriptVersion?: boolean;
22+
fragment?: boolean;
2223
}

packages/parser/src/parser.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,9 @@ export function parseForESLint(
6666
if (typeof options.ecmaFeatures !== 'object') {
6767
options.ecmaFeatures = {};
6868
}
69+
if (!('fragment' in options)) {
70+
options.fragment = false;
71+
}
6972

7073
const parserOptions: TSESTreeOptions = {};
7174
Object.assign(parserOptions, options, {

packages/typescript-estree/src/parser-options.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ export interface Extra {
2020
tokens: null | TSESTree.Token[];
2121
tsconfigRootDir: string;
2222
useJSXTextNode: boolean;
23+
fragment: boolean;
2324
}
2425

2526
export interface TSESTreeOptions {
@@ -38,6 +39,7 @@ export interface TSESTreeOptions {
3839
tokens?: boolean;
3940
tsconfigRootDir?: string;
4041
useJSXTextNode?: boolean;
42+
fragment?: boolean;
4143
}
4244

4345
// This lets us use generics to type the return value, and removes the need to

packages/typescript-estree/src/parser.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,12 +59,15 @@ function getProgramAndAST(
5959
code: string,
6060
shouldProvideParserServices: boolean,
6161
shouldCreateDefaultProgram: boolean,
62+
shouldFragment: boolean,
6263
): ASTAndProgram | undefined {
6364
return (
6465
(shouldProvideParserServices &&
66+
!shouldFragment &&
6567
createProjectProgram(code, shouldCreateDefaultProgram, extra)) ||
6668
(shouldProvideParserServices &&
6769
shouldCreateDefaultProgram &&
70+
!shouldFragment &&
6871
createDefaultProgram(code, extra)) ||
6972
createIsolatedProgram(code, extra)
7073
);
@@ -105,6 +108,7 @@ function resetExtra(): void {
105108
tokens: null,
106109
tsconfigRootDir: process.cwd(),
107110
useJSXTextNode: false,
111+
fragment: false,
108112
};
109113
}
110114

@@ -228,6 +232,8 @@ function applyParserOptionsToExtra(options: TSESTreeOptions): void {
228232
extra.createDefaultProgram =
229233
typeof options.createDefaultProgram === 'boolean' &&
230234
options.createDefaultProgram;
235+
236+
extra.fragment = typeof options.fragment === 'boolean' && options.fragment;
231237
}
232238

233239
function warnAboutTSVersion(): void {
@@ -363,6 +369,7 @@ function parseAndGenerateServices<T extends TSESTreeOptions = TSESTreeOptions>(
363369
code,
364370
shouldProvideParserServices,
365371
extra.createDefaultProgram,
372+
extra.fragment,
366373
)!;
367374

368375
/**

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy