Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

feat: removeTSParenthesizedType#3340

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 ourterms of service andprivacy 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 fromall 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
1 change: 0 additions & 1 deletionpackages/ast-spec/src/ast-node-types.ts
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -134,7 +134,6 @@ export enum AST_NODE_TYPES {
TSObjectKeyword = 'TSObjectKeyword',
TSOptionalType = 'TSOptionalType',
TSParameterProperty = 'TSParameterProperty',
TSParenthesizedType = 'TSParenthesizedType',
TSPrivateKeyword = 'TSPrivateKeyword',
TSPropertySignature = 'TSPropertySignature',
TSProtectedKeyword = 'TSProtectedKeyword',
Expand Down
8 changes: 0 additions & 8 deletionspackages/ast-spec/src/type/TSParenthesizedType/spec.ts
View file
Open in desktop

This file was deleted.

1 change: 0 additions & 1 deletionpackages/ast-spec/src/type/spec.ts
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -17,7 +17,6 @@ export * from './TSNullKeyword/spec';
export * from './TSNumberKeyword/spec';
export * from './TSObjectKeyword/spec';
export * from './TSOptionalType/spec';
export * from './TSParenthesizedType/spec';
export * from './TSQualifiedName/spec';
export * from './TSRestType/spec';
export * from './TSStringKeyword/spec';
Expand Down
2 changes: 0 additions & 2 deletionspackages/ast-spec/src/unions/Node.ts
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -141,7 +141,6 @@ import type { TSNullKeyword } from '../type/TSNullKeyword/spec';
import type { TSNumberKeyword } from '../type/TSNumberKeyword/spec';
import type { TSObjectKeyword } from '../type/TSObjectKeyword/spec';
import type { TSOptionalType } from '../type/TSOptionalType/spec';
import type { TSParenthesizedType } from '../type/TSParenthesizedType/spec';
import type { TSQualifiedName } from '../type/TSQualifiedName/spec';
import type { TSRestType } from '../type/TSRestType/spec';
import type { TSStringKeyword } from '../type/TSStringKeyword/spec';
Expand DownExpand Up@@ -291,7 +290,6 @@ export type Node =
| TSObjectKeyword
| TSOptionalType
| TSParameterProperty
| TSParenthesizedType
| TSPrivateKeyword
| TSPropertySignature
| TSProtectedKeyword
Expand Down
2 changes: 0 additions & 2 deletionspackages/ast-spec/src/unions/TypeNode.ts
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -18,7 +18,6 @@ import type { TSNullKeyword } from '../type/TSNullKeyword/spec';
import type { TSNumberKeyword } from '../type/TSNumberKeyword/spec';
import type { TSObjectKeyword } from '../type/TSObjectKeyword/spec';
import type { TSOptionalType } from '../type/TSOptionalType/spec';
import type { TSParenthesizedType } from '../type/TSParenthesizedType/spec';
import type { TSRestType } from '../type/TSRestType/spec';
import type { TSStringKeyword } from '../type/TSStringKeyword/spec';
import type { TSSymbolKeyword } from '../type/TSSymbolKeyword/spec';
Expand DownExpand Up@@ -56,7 +55,6 @@ export type TypeNode =
| TSNumberKeyword
| TSObjectKeyword
| TSOptionalType
| TSParenthesizedType
| TSRestType
| TSStringKeyword
| TSSymbolKeyword
Expand Down
22 changes: 8 additions & 14 deletionspackages/eslint-plugin/src/rules/array-type.ts
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -132,13 +132,8 @@ export default util.createRule<Options, MessageIds>({
* @param node the node to be evaluated.
*/
function getMessageType(node: TSESTree.Node): string {
if (node) {
if (node.type === AST_NODE_TYPES.TSParenthesizedType) {
return getMessageType(node.typeAnnotation);
}
if (isSimpleType(node)) {
return sourceCode.getText(node);
}
if (node && isSimpleType(node)) {
return sourceCode.getText(node);
}
return 'T';
}
Expand DownExpand Up@@ -172,11 +167,7 @@ export default util.createRule<Options, MessageIds>({
type: getMessageType(node.elementType),
},
fix(fixer) {
const typeNode =
node.elementType.type === AST_NODE_TYPES.TSParenthesizedType
? node.elementType.typeAnnotation
: node.elementType;

const typeNode = node.elementType;
const arrayType = isReadonly ? 'ReadonlyArray' : 'Array';

return [
Expand DownExpand Up@@ -244,9 +235,12 @@ export default util.createRule<Options, MessageIds>({
}

const type = typeParams[0];
const typeParens = typeNeedsParentheses(type);
const typeParens =
!util.isParenthesized(type, sourceCode) && typeNeedsParentheses(type);
const parentParens =
readonlyPrefix && node.parent?.type === AST_NODE_TYPES.TSArrayType;
readonlyPrefix &&
node.parent?.type === AST_NODE_TYPES.TSArrayType &&
!util.isParenthesized(node.parent.elementType, sourceCode);

const start = `${parentParens ? '(' : ''}${readonlyPrefix}${
typeParens ? '(' : ''
Expand Down
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -161,7 +161,6 @@ const KNOWN_NODES = new Set([
AST_NODE_TYPES.TSModuleDeclaration,
AST_NODE_TYPES.TSNonNullExpression,
AST_NODE_TYPES.TSParameterProperty,
AST_NODE_TYPES.TSParenthesizedType,
'TSPlusToken',
AST_NODE_TYPES.TSPropertySignature,
AST_NODE_TYPES.TSQualifiedName,
Expand Down
1 change: 0 additions & 1 deletionpackages/eslint-plugin/src/rules/indent.ts
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -67,7 +67,6 @@ const KNOWN_NODES = new Set([
AST_NODE_TYPES.TSModuleDeclaration,
AST_NODE_TYPES.TSNonNullExpression,
AST_NODE_TYPES.TSParameterProperty,
AST_NODE_TYPES.TSParenthesizedType,
'TSPlusToken',
AST_NODE_TYPES.TSPropertySignature,
AST_NODE_TYPES.TSQualifiedName,
Expand Down
4 changes: 1 addition & 3 deletionspackages/eslint-plugin/src/rules/no-extra-parens.ts
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -84,9 +84,7 @@ export default util.createRule<Options, MessageIds>({
if (
node.arguments.length === 1 &&
node.typeParameters?.params.some(
param =>
param.type === AST_NODE_TYPES.TSParenthesizedType ||
param.type === AST_NODE_TYPES.TSImportType,
param => param.type === AST_NODE_TYPES.TSImportType,
)
) {
return rule({
Expand Down
3 changes: 0 additions & 3 deletionspackages/eslint-plugin/src/rules/no-type-alias.ts
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -294,9 +294,6 @@ export default util.createRule<Options, MessageIds>({
return acc;
}, []);
}
if (node.type === AST_NODE_TYPES.TSParenthesizedType) {
return getTypes(node.typeAnnotation, compositionType);
}
return [{ node, compositionType }];
}

Expand Down
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -23,9 +23,6 @@ enum Group {

function getGroup(node: TSESTree.TypeNode): Group {
switch (node.type) {
case AST_NODE_TYPES.TSParenthesizedType:
return getGroup(node.typeAnnotation);

case AST_NODE_TYPES.TSConditionalType:
return Group.conditional;

Expand DownExpand Up@@ -91,6 +88,10 @@ function getGroup(node: TSESTree.TypeNode): Group {
}
}

function requiresParentheses(node: TSESTree.TypeNode): boolean {
return node.type === AST_NODE_TYPES.TSFunctionType;
}

export type Options = [
{
checkIntersections?: boolean;
Expand DownExpand Up@@ -212,7 +213,7 @@ export default util.createRule<Options, MessageIds>({

const fix: TSESLint.ReportFixFunction = fixer => {
const sorted = expectedOrder
.map(t =>t.text)
.map(t =>(requiresParentheses(t.node) ? `(${t.text})` : t.text))
.join(
node.type === AST_NODE_TYPES.TSIntersectionType ? ' & ' : ' | ',
);
Expand Down
23 changes: 0 additions & 23 deletionspackages/eslint-plugin/tests/rules/indent/indent.test.ts
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -451,29 +451,6 @@ class Foo {
`,
],
},
{
node: AST_NODE_TYPES.TSParenthesizedType,
code: [
`
const x: Array<(
| {
__typename: "Foo",
}
| {
__typename: "Baz",
}
| (
| {
__typename: "Baz",
}
| {
__typename: "Buzz",
}
)
)>;
`,
],
},
// TSPlusToken - tested in TSMappedType
{
node: AST_NODE_TYPES.TSPropertySignature,
Expand Down
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -28,7 +28,7 @@ for (a in b, c);
for (a in b);
a<import('')>(1);
new a<import('')>(1);
a<(A)>(1);
a<A>(1);
`,
}),
...batchedSingleLineTests({
Expand Down
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -127,7 +127,7 @@ const invalid = (
},
{
code: noFormat`type T = (B) ${operator} (A);`,
output: noFormat`type T =(A) ${operator}(B);`,
output: noFormat`type T =A ${operator}B;`,
errors: [
{
messageId: 'notSortedNamed',
Expand Down
1 change: 0 additions & 1 deletionpackages/experimental-utils/src/ts-eslint/Rule.ts
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -387,7 +387,6 @@ interface RuleListener {
TSObjectKeyword?: RuleFunction<TSESTree.TSObjectKeyword>;
TSOptionalType?: RuleFunction<TSESTree.TSOptionalType>;
TSParameterProperty?: RuleFunction<TSESTree.TSParameterProperty>;
TSParenthesizedType?: RuleFunction<TSESTree.TSParenthesizedType>;
TSPrivateKeyword?: RuleFunction<TSESTree.TSPrivateKeyword>;
TSPropertySignature?: RuleFunction<TSESTree.TSPropertySignature>;
TSProtectedKeyword?: RuleFunction<TSESTree.TSProtectedKeyword>;
Expand Down
5 changes: 1 addition & 4 deletionspackages/typescript-estree/src/convert.ts
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -2694,10 +2694,7 @@ export class Converter {

// TypeScript specific types
case SyntaxKind.ParenthesizedType: {
return this.createNode<TSESTree.TSParenthesizedType>(node, {
type: AST_NODE_TYPES.TSParenthesizedType,
typeAnnotation: this.convertType(node.type),
});
return this.convertType(node.type);
}
case SyntaxKind.UnionType: {
return this.createNode<TSESTree.TSUnionType>(node, {
Expand Down
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -191,7 +191,6 @@ export interface EstreeToTsNodeTypes {
[AST_NODE_TYPES.TSNonNullExpression]: ts.NonNullExpression;
[AST_NODE_TYPES.TSOptionalType]: ts.OptionalTypeNode;
[AST_NODE_TYPES.TSParameterProperty]: ts.ParameterDeclaration;
[AST_NODE_TYPES.TSParenthesizedType]: ts.ParenthesizedTypeNode;
[AST_NODE_TYPES.TSPropertySignature]: ts.PropertySignature;
[AST_NODE_TYPES.TSQualifiedName]: ts.QualifiedName;
[AST_NODE_TYPES.TSRestType]:
Expand Down
10 changes: 10 additions & 0 deletionspackages/typescript-estree/tests/ast-alignment/utils.ts
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -250,6 +250,16 @@ export function preprocessBabylonAST(ast: BabelTypes.File): any {
}
}
},
/**
* Remove TSParenthesizedType from babel AST. Babel 8 will stop generating the TSParenthesizedType.
* Once we use babel 8, this can be removed.
* @see https://github.com/babel/babel/pull/12608
*/
TSParenthesizedType(node: any) {
const { typeAnnotation } = node;
Object.keys(node).forEach(key => delete node[key]);
Object.assign(node, typeAnnotation);
},
},
);
}
Expand Down
Original file line numberDiff line numberDiff line change
Expand Up@@ -78,38 +78,33 @@ Object {
"elementType": Object {
"loc": Object {
"end": Object {
"column":21,
"column":20,
"line": 2,
},
"start": Object {
"column":12,
"column":13,
"line": 2,
},
},
"range": Array [
31,
40,
32,
39,
],
"type": "TSParenthesizedType",
"typeAnnotation": Object {
"type": "TSInferType",
"typeParameter": Object {
"constraint": undefined,
"default": undefined,
"loc": Object {
"end": Object {
"column": 20,
"line": 2,
},
"start": Object {
"column":13,
"column":19,
"line": 2,
},
},
"range": Array [
32,
39,
],
"type": "TSInferType",
"typeParameter": Object {
"constraint": undefined,
"default": undefined,
"name": Object {
"loc": Object {
"end": Object {
"column": 20,
Expand All@@ -120,30 +115,18 @@ Object {
"line": 2,
},
},
"name": Object {
"loc": Object {
"end": Object {
"column": 20,
"line": 2,
},
"start": Object {
"column": 19,
"line": 2,
},
},
"name": "U",
"range": Array [
38,
39,
],
"type": "Identifier",
},
"name": "U",
"range": Array [
38,
39,
],
"type": "TSTypeParameter",
"type": "Identifier",
},
"range": Array [
38,
39,
],
"type": "TSTypeParameter",
},
},
"loc": Object {
Expand Down
Loading

[8]ページ先頭

©2009-2025 Movatter.jp