-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
18 changed files
with
279 additions
and
209 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
import { AST_NODE_TYPES, TSESTree } from "@typescript-eslint/types"; | ||
import * as BabelTypes from "@babel/types"; | ||
|
||
export const MemberLikeNodeTypesArray = [ | ||
// ts-es-tree | ||
AST_NODE_TYPES.PropertyDefinition, | ||
AST_NODE_TYPES.MethodDefinition, | ||
AST_NODE_TYPES.TSAbstractMethodDefinition, | ||
AST_NODE_TYPES.TSAbstractPropertyDefinition, | ||
AST_NODE_TYPES.TSConstructSignatureDeclaration, | ||
AST_NODE_TYPES.TSIndexSignature, | ||
AST_NODE_TYPES.TSMethodSignature, | ||
AST_NODE_TYPES.TSPropertySignature, | ||
|
||
// babel-ast | ||
"ClassMethod", | ||
"ClassPrivateMethod", | ||
"ClassPrivateProperty", | ||
"ClassProperty", | ||
"TSDeclareMethod", | ||
] as const; | ||
|
||
export const MemberTypes = Object.fromEntries( | ||
MemberLikeNodeTypesArray.map((type) => [type, type]), | ||
) as { [K in MemberType]: K }; | ||
|
||
export type MemberType = (typeof MemberLikeNodeTypesArray)[number]; | ||
|
||
export type MemberNode<K extends MemberType = MemberType> = ( | ||
| never // avoid prettier bug | ||
|
||
// babel-ast | ||
| TSESTree.PropertyDefinition | ||
| TSESTree.MethodDefinition | ||
| TSESTree.TSAbstractMethodDefinition | ||
| TSESTree.TSAbstractPropertyDefinition | ||
| TSESTree.TSConstructSignatureDeclaration | ||
| TSESTree.TSIndexSignature | ||
| TSESTree.TSMethodSignature | ||
| TSESTree.TSPropertySignature | ||
|
||
// ts-es-tree | ||
| BabelTypes.ClassMethod | ||
| BabelTypes.ClassPrivateMethod | ||
| BabelTypes.ClassPrivateProperty | ||
| BabelTypes.ClassProperty | ||
| BabelTypes.TSDeclareMethod | ||
) & { type: K }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import { NodeTypes } from "."; | ||
import { | ||
MemberNode, | ||
MemberType, | ||
MemberLikeNodeTypesArray, | ||
} from "./member-like"; | ||
|
||
(function _() { | ||
check<MemberType, NodeTypes>; | ||
check<MemberNode["type"], MemberType>; | ||
check<MemberType, MemberNode["type"]>; | ||
check<typeof MemberLikeNodeTypesArray, readonly MemberType[]>; | ||
check<MemberType, (typeof MemberLikeNodeTypesArray)[number]>; | ||
|
||
// eslint-disable-next-line @typescript-eslint/no-unused-vars | ||
function check<S extends T, T>(_a: T, _b: S): never { | ||
throw new Error("Just for type check"); | ||
} | ||
})(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import { Node } from "../ast"; | ||
import { C, Comparator } from "./comparator"; | ||
|
||
export function classMember(): Comparator<Node> { | ||
return C.by(($) => { | ||
if ("static" in $) return $.static === true; | ||
return false; | ||
}, C.prefer); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,15 @@ | ||
import { AST_NODE_TYPES } from "@typescript-eslint/types"; | ||
import { Node } from "../ast"; | ||
import { MemberTypes } from "../ast/member-like"; | ||
|
||
export function decorated(node: Node): boolean { | ||
switch (node.type) { | ||
case AST_NODE_TYPES.PropertyDefinition: | ||
case AST_NODE_TYPES.MethodDefinition: | ||
return node.decorators.length > 0; | ||
case MemberTypes.PropertyDefinition: | ||
case MemberTypes.MethodDefinition: | ||
case MemberTypes.ClassProperty: | ||
case MemberTypes.ClassPrivateProperty: | ||
case MemberTypes.ClassMethod: | ||
case MemberTypes.ClassPrivateMethod: | ||
return (node.decorators?.length ?? 0) > 0; | ||
} | ||
return false; | ||
} |
Oops, something went wrong.