eslint-codemod-utils
Version:
A collection of AST helper functions for more complex ESLint rule fixes.
384 lines (383 loc) • 10.6 kB
TypeScript
import { TSESTree } from '@typescript-eslint/types';
import * as ESTree from 'estree-jsx';
import type { StringableASTNode, StringableASTNodeFn, WithoutType } from './types';
/**
* __CallExpression__
*
* @example
*
* Usage
* ```
* const call = callExpression({ callee: identifier({ name: 'normalCallExpression' }) })
* ```
*
* Produces
*
* @example
*
* ```js
* normalCallExpression()
* ```
*
* @returns {ESTree.CallExpression}
*/
export declare const callExpression: StringableASTNodeFn<ESTree.SimpleCallExpression, 'optional'>;
/**
* __Super__
*
* @example
*
* ```
* // note the whole expression is a `CallExpression`
* // super is simply the callee / identifier
* super()
* ^^^^^
* ```
*
* @returns {ESTree.Super}
*/
export declare const superCallExpression: StringableASTNodeFn<ESTree.Super>;
export declare const chainExpression: StringableASTNodeFn<ESTree.ChainExpression>;
/**
* __BinaryExpression__
*
* @example
* ```ts
* const x = 'left' + 'right'
* ^^^^^^^^^^^^^^^^
* ```
*/
export declare const binaryExpression: StringableASTNodeFn<ESTree.BinaryExpression>;
/**
* __SequenceExpression__
*
* @example
* ```ts
* const x = (4, 8)
* ^^^^^^
* ```
*/
export declare const sequenceExpression: StringableASTNodeFn<ESTree.SequenceExpression>;
/**
* __ArrowFunctionExpression__
*
* @example
* ```js
* const arrow = () => 42
* ⌃⌃⌃⌃⌃⌃⌃⌃
* ```
* @returns {ESTree.ArrowFunctionExpression}
*/
export declare const arrowFunctionExpression: StringableASTNodeFn<ESTree.ArrowFunctionExpression, 'async' | 'generator'>;
/**
* __TaggedTemplateExpression__
*
* @example
* ```ts
* const style = css`color: red;`
* ^^^^^^^^^^^
* ```
*/
export declare const taggedTemplateExpression: StringableASTNodeFn<ESTree.TaggedTemplateExpression>;
export declare const functionExpression: StringableASTNodeFn<ESTree.FunctionExpression, 'generator' | 'async'>;
export declare const blockStatement: StringableASTNodeFn<ESTree.BlockStatement>;
export declare const returnStatement: StringableASTNodeFn<ESTree.ReturnStatement>;
export declare const throwStatement: StringableASTNodeFn<ESTree.ThrowStatement>;
/**
* __UnaryExpression__
*
* @example
*
* ```ts
* const y = typeof x
* ^^^^^^
* ++x
* ^^
* ```
*
* @returns {ESTree.UnaryExpression}
*/
export declare const unaryExpression: StringableASTNodeFn<ESTree.UnaryExpression>;
/**
* __ThisExpression__
*
* @example
*
* ```js
* // In `this.self` 'this' is a ThisExpression.
* this.self
* ⌃⌃⌃⌃
* ```
*
* @returns {ESTree.ThisExpression}
*/
export declare const thisExpression: StringableASTNodeFn<ESTree.ThisExpression>;
/**
* __IfStatement__
*
* @example
*
* ```ts
* if (test) {
* // consequant
* } else {
* // alternate
* }
* ⌃⌃⌃⌃^^^^^^^^
* ```
*
* @returns {ESTree.IfStatement}
*/
export declare const ifStatement: StringableASTNodeFn<ESTree.IfStatement>;
/**
* __CatchClause__
*
* @example
*
* ```ts
* // always inside a try statement
* catch (e) {}
* ⌃⌃⌃⌃^^^^^^^^
* ```
*
* @returns {ESTree.CatchClause}
*/
export declare const catchClause: StringableASTNodeFn<ESTree.CatchClause>;
/**
* __TryStatement__
*
* @example
*
* ```ts
* try {
* // block
* } catch(e) { // <--- handler
*
* } finally {} // <--- finalizer
* ⌃⌃⌃⌃^^^^^^^^
* ```
*
* @returns {ESTree.TryStatement}
*/
export declare const tryStatement: StringableASTNodeFn<ESTree.TryStatement>;
/**
* __WithStatement__
*
* @example
*
* ```ts
* with (Math) {
* a = PI * r * r;
* x = r * cos(PI);
* y = r * sin(PI / 2);
* }
* ```
*
* @returns {ESTree.WithStatement}
*/
export declare const withStatement: StringableASTNodeFn<ESTree.WithStatement>;
/**
* __ImportExpression__
*
* @example
*
* ```ts
* import('some-path')
* ⌃⌃⌃⌃^^^^^^^^^^^^^^^
* ```
*
* @returns {ESTree.ImportExpression}
*/
export declare const importExpression: StringableASTNodeFn<ESTree.ImportExpression>;
/**
* __ImportDefaultSpecifier__
*
* @example
*
* ```ts
* import Hello from 'world'
* ^^^^^
* ```
*
* @returns {ESTree.ImportDefaultSpecifier}
*/
export declare const importDefaultSpecifier: StringableASTNodeFn<ESTree.ImportDefaultSpecifier>;
/**
* __ExportNamedDeclaration__
*
* @example
*
* ```ts
* export { Hello } from 'world'
* ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
* ```
*
* @returns {ESTree.ExportNamedDeclaration}
*/
export declare const exportNamedDeclaration: StringableASTNodeFn<ESTree.ExportNamedDeclaration>;
/**
* __ExportDefaultDeclaration__
*
* @example
*
* ```ts
* export default HelloWorld
* ^^^^^^^^^^^^^^^^^^^^^^^^^
* ```
*
* @returns {ESTree.ExportDefaultDeclaration}
*/
export declare const exportDefaultDeclaration: StringableASTNodeFn<ESTree.ExportDefaultDeclaration>;
/**
* __ExportAllDeclaration__
*
* @example
*
* ```ts
* export * from 'world'
* ^^^^^^^^^^^^^^^^^^^^^^^^^
* ```
* ```ts
* export * as Hello from 'world'
* ^^^^^^^^^^^^^^^^^^^^^^^^^
* ```
*
* @returns {ESTree.ExportAllDeclaration}
*/
export declare const exportAllDeclaration: StringableASTNodeFn<ESTree.ExportAllDeclaration, 'exported'>;
export declare const exportSpecifier: StringableASTNodeFn<ESTree.ExportSpecifier>;
export declare const importSpecifier: StringableASTNodeFn<ESTree.ImportSpecifier & {
importKind?: TSESTree.ImportSpecifier['importKind'];
}>;
/**
* __YieldExpression__
*
* @example
*
* ```ts
* const thing = yield someYieldExpression
* ⌃⌃⌃⌃⌃⌃⌃⌃⌃⌃⌃⌃^^^^^^^^^^^^^
* ```
*
* @returns {ESTree.YieldExpression}
*/
export declare const yieldExpression: StringableASTNodeFn<ESTree.YieldExpression>;
export declare const arrayExpression: StringableASTNodeFn<ESTree.ArrayExpression>;
export declare const arrayPattern: StringableASTNodeFn<ESTree.ArrayPattern>;
export declare const updateExpression: StringableASTNodeFn<ESTree.UpdateExpression>;
export declare const expressionStatement: StringableASTNodeFn<ESTree.ExpressionStatement>;
/**
* __NewExpression__
*
* @example
* ```ts
* new SomeThing()
* ^^^^^^^^^^^^^^^
* ```
*/
export declare const newExpression: StringableASTNodeFn<ESTree.NewExpression>;
export declare const property: StringableASTNodeFn<ESTree.Property, 'kind' | 'computed' | 'shorthand' | 'method'>;
/**
* __ObjectPattern__
*
* @example
* ```ts
* function App({ a }) {}
* ^^^^^
* ```
* @returns
*/
export declare const objectPattern: StringableASTNodeFn<ESTree.ObjectPattern>;
/**
* __SpreadElement__
*
* @example
* ```ts
* const obj = {
* ...spread
* ^^^^^^^^^
* }
* ```
*
* @returns {ESTree.SpreadElement}
*/
export declare const spreadElement: StringableASTNodeFn<ESTree.SpreadElement>;
/**
* __RestElement__
*
* @example
* ```ts
* const [a, ...b] = c
* ^^^^
* ```
*
* * @example
* ```ts
* const { a, ...b } = c
* ^^^^
* ```
*
* @returns {ESTree.RestElement}
*/
export declare const restElement: StringableASTNodeFn<ESTree.RestElement>;
/**
* __ObjectExpression__
* @example
* ```ts
* const x = {
* key: value,
* get x() { return 1 },
* }
* ^^^^^^^^^^^^
* ```
*/
export declare const objectExpression: StringableASTNodeFn<ESTree.ObjectExpression>;
export declare const emptyStatement: StringableASTNodeFn<ESTree.EmptyStatement>;
export declare const memberExpression: StringableASTNodeFn<ESTree.MemberExpression, 'computed' | 'optional'>;
export declare const logicalExpression: StringableASTNodeFn<ESTree.LogicalExpression>;
export declare const variableDeclarator: StringableASTNodeFn<ESTree.VariableDeclarator>;
export declare const variableDeclaration: StringableASTNodeFn<ESTree.VariableDeclaration>;
export declare const importNamespaceSpecifier: StringableASTNodeFn<ESTree.ImportNamespaceSpecifier>;
export declare const templateElement: StringableASTNodeFn<ESTree.TemplateElement>;
export declare const importDeclaration: StringableASTNodeFn<ESTree.ImportDeclaration & {
importKind?: TSESTree.ImportDeclaration['importKind'];
}>;
export declare const bigIntLiteral: StringableASTNodeFn<ESTree.BigIntLiteral>;
export declare const regExpLiteral: StringableASTNodeFn<ESTree.RegExpLiteral>;
export declare const literal: (n: WithoutType<ESTree.Literal> | (string | number | boolean | null)) => StringableASTNode<ESTree.Literal>;
export declare const identifier: (param: WithoutType<ESTree.Identifier> | string) => StringableASTNode<ESTree.Identifier>;
export declare const doWhileStatement: StringableASTNodeFn<ESTree.DoWhileStatement>;
export declare const whileStatement: StringableASTNodeFn<ESTree.WhileStatement>;
export declare const switchCase: StringableASTNodeFn<ESTree.SwitchCase>;
export declare const switchStatement: StringableASTNodeFn<ESTree.SwitchStatement>;
export declare const templateLiteral: StringableASTNodeFn<ESTree.TemplateLiteral>;
export declare const forStatement: StringableASTNodeFn<ESTree.ForStatement>;
export declare const forInStatement: StringableASTNodeFn<ESTree.ForInStatement>;
export declare const forOfStatement: StringableASTNodeFn<ESTree.ForOfStatement>;
export declare const continueStatement: StringableASTNodeFn<ESTree.ContinueStatement>;
export declare const breakStatement: StringableASTNodeFn<ESTree.BreakStatement>;
export declare const debuggerStatement: StringableASTNodeFn<ESTree.DebuggerStatement>;
export declare const conditionalExpression: StringableASTNodeFn<ESTree.ConditionalExpression>;
export declare const assignmentExpression: StringableASTNodeFn<ESTree.AssignmentExpression>;
export declare const awaitExpression: StringableASTNodeFn<ESTree.AwaitExpression>;
/**
* __StaticBlock__
*
* @example
* ```ts
* class A {
* // only applicable inside a class
* static { }
* ^^^^^^^^^^
* }
* ```
*/
export declare const staticBlock: StringableASTNodeFn<ESTree.StaticBlock>;
export declare const functionDeclaration: StringableASTNodeFn<ESTree.FunctionDeclaration, 'generator' | 'async'>;
export declare const methodOrPropertyFn: ({ params, body, }: ESTree.FunctionExpression) => string;
export declare const methodDefinition: StringableASTNodeFn<ESTree.MethodDefinition>;
export declare const propertyDefinition: StringableASTNodeFn<ESTree.PropertyDefinition>;
export declare const classBody: StringableASTNodeFn<ESTree.ClassBody>;
export declare const classDeclaration: StringableASTNodeFn<ESTree.ClassDeclaration>;
export declare const classExpression: StringableASTNodeFn<ESTree.ClassExpression>;
export declare const program: StringableASTNodeFn<ESTree.Program>;