Skip to content

feat(typescript-estree): remove legacy useJSXTextNode option #3109

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
merged 6 commits into from
Aug 22, 2021
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
9 changes: 0 additions & 9 deletions packages/typescript-estree/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -101,14 +101,6 @@ interface ParseOptions {
* Set to true to create a top-level array containing all tokens from the file.
*/
tokens?: boolean;

/*
* The JSX AST changed the node type for string literals
* inside a JSX Element from `Literal` to `JSXText`.
* When value is `true`, these nodes will be parsed as type `JSXText`.
* When value is `false`, these nodes will be parsed as type `Literal`.
*/
useJSXTextNode?: boolean;
}

const PARSE_DEFAULT_OPTIONS: ParseOptions = {
Expand All @@ -120,7 +112,6 @@ const PARSE_DEFAULT_OPTIONS: ParseOptions = {
loggerFn: undefined,
range: false,
tokens: false,
useJSXTextNode: false,
};

declare function parse(
Expand Down
1 change: 0 additions & 1 deletion packages/typescript-estree/src/ast-converter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ export function astConverter(
*/
const instance = new Converter(ast, {
errorOnUnknownASTType: extra.errorOnUnknownASTType || false,
useJSXTextNode: extra.useJSXTextNode || false,
shouldPreserveNodeMaps,
});

Expand Down
28 changes: 6 additions & 22 deletions packages/typescript-estree/src/convert.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ const SyntaxKind = ts.SyntaxKind;

interface ConverterOptions {
errorOnUnknownASTType: boolean;
useJSXTextNode: boolean;
shouldPreserveNodeMaps: boolean;
}

Expand Down Expand Up @@ -2246,32 +2245,17 @@ export class Converter {
});
}

/**
* The JSX AST changed the node type for string literals
* inside a JSX Element from `Literal` to `JSXText`. We
* provide a flag to support both types until `Literal`
* node type is deprecated in ESLint v5.
*/
case SyntaxKind.JsxText: {
const start = node.getFullStart();
const end = node.getEnd();
const text = this.ast.text.slice(start, end);

if (this.options.useJSXTextNode) {
return this.createNode<TSESTree.JSXText>(node, {
type: AST_NODE_TYPES.JSXText,
value: unescapeStringLiteralText(text),
raw: text,
range: [start, end],
});
} else {
return this.createNode<TSESTree.StringLiteral>(node, {
type: AST_NODE_TYPES.Literal,
value: unescapeStringLiteralText(text),
raw: text,
range: [start, end],
});
}
return this.createNode<TSESTree.JSXText>(node, {
type: AST_NODE_TYPES.JSXText,
value: unescapeStringLiteralText(text),
raw: text,
range: [start, end],
});
}

case SyntaxKind.JsxSpreadAttribute:
Expand Down
9 changes: 0 additions & 9 deletions packages/typescript-estree/src/parser-options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ export interface Extra {
strict: boolean;
tokens: null | TSESTree.Token[];
tsconfigRootDir: string;
useJSXTextNode: boolean;
moduleResolver: string;
}

Expand Down Expand Up @@ -100,14 +99,6 @@ interface ParseOptions {
* Set to true to create a top-level array containing all tokens from the file.
*/
tokens?: boolean;

/*
* The JSX AST changed the node type for string literals
* inside a JSX Element from `Literal` to `JSXText`.
* When value is `true`, these nodes will be parsed as type `JSXText`.
* When value is `false`, these nodes will be parsed as type `Literal`.
*/
useJSXTextNode?: boolean;
}

interface ParseAndGenerateServicesOptions extends ParseOptions {
Expand Down
12 changes: 0 additions & 12 deletions packages/typescript-estree/src/parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,6 @@ function resetExtra(): void {
strict: false,
tokens: null,
tsconfigRootDir: process.cwd(),
useJSXTextNode: false,
/**
* Unless we can reliably infer otherwise, we default to assuming that this run could be part
* of a long-running session (e.g. in an IDE) and watch programs will therefore be required
Expand Down Expand Up @@ -251,17 +250,6 @@ function applyParserOptionsToExtra(options: TSESTreeOptions): void {
extra.filePath = getFileName(extra);
}

/**
* The JSX AST changed the node type for string literals
* inside a JSX Element from `Literal` to `JSXText`.
*
* When value is `true`, these nodes will be parsed as type `JSXText`.
* When value is `false`, these nodes will be parsed as type `Literal`.
*/
if (typeof options.useJSXTextNode === 'boolean' && options.useJSXTextNode) {
extra.useJSXTextNode = true;
}

/**
* Allow the user to cause the parser to error if it encounters an unknown AST Node Type
* (used in testing)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,6 @@ export interface EstreeToTsNodeTypes {
| ts.StringLiteral
| ts.NumericLiteral
| ts.RegularExpressionLiteral
| ts.JsxText
| ts.NullLiteral
| ts.BooleanLiteral
| ts.BigIntLiteral;
Expand Down
1 change: 0 additions & 1 deletion packages/typescript-estree/tests/ast-alignment/parse.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@ function parseWithTypeScriptESTree(text: string, jsx = true): parser.AST<any> {
range: true,
tokens: false,
comment: false,
useJSXTextNode: true,
errorOnUnknownASTType: true,
/**
* Babel will always throw on these types of issues, so we enable
Expand Down
11 changes: 0 additions & 11 deletions packages/typescript-estree/tests/lib/convert.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ describe('convert', () => {

const instance = new Converter(ast, {
errorOnUnknownASTType: false,
useJSXTextNode: false,
shouldPreserveNodeMaps: false,
});
expect(instance.convertProgram()).toMatchSnapshot();
Expand All @@ -38,7 +37,6 @@ describe('convert', () => {

const instance = new Converter(ast, {
errorOnUnknownASTType: false,
useJSXTextNode: false,
shouldPreserveNodeMaps: false,
}) as any;

Expand All @@ -50,7 +48,6 @@ describe('convert', () => {

const instance = new Converter(ast, {
errorOnUnknownASTType: false,
useJSXTextNode: false,
shouldPreserveNodeMaps: false,
}) as any;

Expand All @@ -62,7 +59,6 @@ describe('convert', () => {

const instance = new Converter(ast, {
errorOnUnknownASTType: false,
useJSXTextNode: false,
shouldPreserveNodeMaps: false,
}) as any;

Expand All @@ -76,7 +72,6 @@ describe('convert', () => {

const instance = new Converter(ast, {
errorOnUnknownASTType: false,
useJSXTextNode: false,
shouldPreserveNodeMaps: false,
}) as any;
expect(instance.deeplyCopy(ast)).toMatchSnapshot();
Expand All @@ -87,7 +82,6 @@ describe('convert', () => {

const instance = new Converter(ast, {
errorOnUnknownASTType: true,
useJSXTextNode: false,
shouldPreserveNodeMaps: false,
}) as any;

Expand All @@ -106,7 +100,6 @@ describe('convert', () => {

const instance = new Converter(ast, {
errorOnUnknownASTType: false,
useJSXTextNode: false,
shouldPreserveNodeMaps: true,
});
instance.convertProgram();
Expand Down Expand Up @@ -140,7 +133,6 @@ describe('convert', () => {

const instance = new Converter(ast, {
errorOnUnknownASTType: false,
useJSXTextNode: false,
shouldPreserveNodeMaps: true,
});
instance.convertProgram();
Expand Down Expand Up @@ -173,7 +165,6 @@ describe('convert', () => {

const instance = new Converter(ast, {
errorOnUnknownASTType: false,
useJSXTextNode: false,
shouldPreserveNodeMaps: true,
});
const program = instance.convertProgram();
Expand Down Expand Up @@ -205,7 +196,6 @@ describe('convert', () => {
const ast = convertCode('');
const instance = new Converter(ast, {
errorOnUnknownASTType: false,
useJSXTextNode: false,
shouldPreserveNodeMaps: true,
});

Expand Down Expand Up @@ -250,7 +240,6 @@ describe('convert', () => {

const instance = new Converter(ast, {
errorOnUnknownASTType: false,
useJSXTextNode: false,
shouldPreserveNodeMaps: false,
});
expect(() => instance.convertProgram()).toThrow(
Expand Down
1 change: 0 additions & 1 deletion packages/typescript-estree/tests/lib/semanticInfo.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ function createOptions(fileName: string): TSESTreeOptions & { cwd?: string } {
tokens: true,
comment: true,
jsx: false,
useJSXTextNode: false,
errorOnUnknownASTType: true,
filePath: fileName,
tsconfigRootDir: path.join(process.cwd(), FIXTURES_DIR),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ Object {
61,
],
"raw": "http://example.com",
"type": "Literal",
"type": "JSXText",
"value": "http://example.com",
},
],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ Object {
],
"raw": "
",
"type": "Literal",
"type": "JSXText",
"value": "
",
},
Expand Down Expand Up @@ -103,7 +103,7 @@ Object {
],
"raw": "
",
"type": "Literal",
"type": "JSXText",
"value": "
",
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ Object {
],
"raw": "
",
"type": "Literal",
"type": "JSXText",
"value": "
",
},
Expand Down Expand Up @@ -190,7 +190,7 @@ Object {
],
"raw": "
",
"type": "Literal",
"type": "JSXText",
"value": "
",
},
Expand Down Expand Up @@ -374,7 +374,7 @@ Object {
],
"raw": "
",
"type": "Literal",
"type": "JSXText",
"value": "
",
},
Expand Down Expand Up @@ -558,7 +558,7 @@ Object {
],
"raw": "
",
"type": "Literal",
"type": "JSXText",
"value": "
",
},
Expand Down Expand Up @@ -779,7 +779,7 @@ Object {
"raw": "

",
"type": "Literal",
"type": "JSXText",
"value": "

",
Expand Down Expand Up @@ -927,7 +927,7 @@ Object {
],
"raw": "
",
"type": "Literal",
"type": "JSXText",
"value": "
",
},
Expand Down Expand Up @@ -1111,7 +1111,7 @@ Object {
],
"raw": "
",
"type": "Literal",
"type": "JSXText",
"value": "
",
},
Expand Down Expand Up @@ -1295,7 +1295,7 @@ Object {
],
"raw": "
",
"type": "Literal",
"type": "JSXText",
"value": "
",
},
Expand Down Expand Up @@ -1515,7 +1515,7 @@ Object {
],
"raw": "
",
"type": "Literal",
"type": "JSXText",
"value": "
",
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ Object {
],
"raw": "
",
"type": "Literal",
"type": "JSXText",
"value": "
",
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ Object {
* test
*/
",
"type": "Literal",
"type": "JSXText",
"value": "
/**
* test
Expand Down
Loading