Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

eslint-codemod-utils

Package Overview
Dependencies
Maintainers
1
Versions
36
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

eslint-codemod-utils - npm Package Compare versions

Comparing version 0.1.1 to 0.1.2

6

CHANGELOG.md
# eslint-codemod-utils
## 0.1.2
### Patch Changes
- d75cbdd: Removes console statement from node parsing utility.
## 0.1.1

@@ -4,0 +10,0 @@

7

dist/__tests__/index.test.js

@@ -24,3 +24,2 @@ "use strict";

const espree = __importStar(require("espree"));
const nodes_1 = require("../nodes");
const ESPREE_OPTIONS = {

@@ -317,3 +316,3 @@ ecmaVersion: 2015,

const { body } = espree.parse(testString);
expect((0, nodes_1.doWhileStatement)(body[0]).toString()).eq(testString);
expect((0, __1.doWhileStatement)(body[0]).toString()).eq(testString);
});

@@ -331,3 +330,3 @@ });

const { body } = espree.parse(testString);
expect((0, nodes_1.ifStatement)(body[0]).toString()).eq(testString);
expect((0, __1.ifStatement)(body[0]).toString()).eq(testString);
});

@@ -339,3 +338,3 @@ });

const { body } = espree.parse(testString);
expect((0, nodes_1.throwStatement)(body[0]).toString()).eq(testString);
expect((0, __1.throwStatement)(body[0]).toString()).eq(testString);
});

@@ -342,0 +341,0 @@ });

@@ -10,2 +10,3 @@ "use strict";

test('basic', () => {
// @ts-expect-error This is fine it's just JSON
expect(String((0, __1.program)(program_1.default))).eq(`import A, { Welcome } from '@atlaskit/welcome'

@@ -12,0 +13,0 @@ import { X } from './other'

@@ -35,3 +35,2 @@ "use strict";

const program = espree.parse('<Hello name="world"></Hello>', ESPREE_OPTIONS);
console.log(program.body[0].expression);
expect((0, utils_1.closestOfType)(program.body[0].expression.openingElement, 'JSXElement')).toHaveProperty('type', 'JSXElement');

@@ -38,0 +37,0 @@ });

@@ -0,94 +1,3 @@

import { NodeMap } from './utils/node';
export declare const DEFAULT_WHITESPACE = "\n ";
export declare const typeToHelperLookup: {
readonly AssignmentProperty: <T>(node: T) => T;
readonly AssignmentPattern: <T>(node: T) => T;
readonly AssignmentExpression: import("./types").StringableASTNode<import("estree").AssignmentExpression>;
readonly AwaitExpression: import("./types").StringableASTNode<import("estree").AwaitExpression>;
readonly ArrayExpression: import("./types").StringableASTNode<import("estree").ArrayExpression>;
readonly ArrayPattern: import("./types").StringableASTNode<import("estree").ArrayPattern>;
readonly BlockStatement: import("./types").StringableASTNode<import("estree").BlockStatement>;
readonly BinaryExpression: import("./types").StringableASTNode<import("estree").BinaryExpression>;
readonly ConditionalExpression: import("./types").StringableASTNode<import("estree").ConditionalExpression>;
readonly ChainExpression: import("./types").StringableASTNode<import("estree").ChainExpression>;
readonly JSXFragment: import("./types").StringableASTNode<import("estree-jsx").JSXFragment>;
readonly JSXSpreadChild: import("./types").StringableASTNode<import("estree-jsx").JSXSpreadChild>;
readonly JSXExpressionContainer: import("./types").StringableASTNode<import("estree-jsx").JSXExpressionContainer>;
readonly JSXClosingElement: import("./types").StringableASTNode<import("estree-jsx").JSXClosingElement>;
readonly JSXOpeningElement: import("./types").StringableASTNode<import("estree-jsx").JSXOpeningElement>;
readonly JSXOpeningFragment: import("./types").StringableASTNode<import("estree-jsx").JSXOpeningFragment>;
readonly JSXClosingFragment: import("./types").StringableASTNode<import("estree-jsx").JSXClosingFragment>;
readonly JSXElement: import("./types").StringableASTNode<import("estree-jsx").JSXElement>;
readonly JSXText: import("./types").StringableASTNode<import("estree-jsx").JSXText>;
readonly JSXSpreadAttribute: import("./types").StringableASTNode<import("estree-jsx").JSXSpreadAttribute>;
readonly JSXAttribute: import("./types").StringableASTNode<import("estree-jsx").JSXAttribute>;
readonly JSXMemberExpression: import("./types").StringableASTNode<import("estree-jsx").JSXMemberExpression>;
readonly JSXNamespacedName: <T>(node: T) => T;
readonly JSXIdentifier: import("./types").StringableASTNode<import("estree-jsx").JSXIdentifier>;
readonly JSXEmptyExpression: import("./types").StringableASTNode<import("estree-jsx").JSXEmptyExpression>;
readonly ArrowFunctionExpression: import("./types").StringableASTNode<import("estree").ArrowFunctionExpression>;
readonly FunctionExpression: import("./types").StringableASTNode<import("estree").FunctionExpression>;
readonly Identifier: import("./types").StringableASTNode<import("estree").Identifier>;
readonly IfStatement: import("./types").StringableASTNode<import("estree").IfStatement>;
readonly LabeledStatement: <T>(node: T) => T;
readonly Literal: import("./types").StringableASTNode<import("estree").Literal>;
readonly LogicalExpression: import("./types").StringableASTNode<import("estree").LogicalExpression>;
/** this isn't a concrete node type */
readonly Expression: <T>(node: T) => T;
readonly ForStatement: import("./types").StringableASTNode<import("estree").ForStatement>;
readonly ForInStatement: import("./types").StringableASTNode<import("estree").ForInStatement>;
readonly ForOfStatement: import("./types").StringableASTNode<import("estree").ForOfStatement>;
readonly ImportSpecifier: import("./types").StringableASTNode<import("estree").ImportSpecifier>;
readonly ImportNamespaceSpecifier: import("./types").StringableASTNode<import("estree").ImportNamespaceSpecifier>;
readonly ImportDeclaration: import("./types").StringableASTNode<import("estree").ImportDeclaration>;
readonly ImportExpression: import("./types").StringableASTNode<import("estree").ImportExpression>;
readonly ThisExpression: import("./types").StringableASTNode<import("estree").ThisExpression>;
readonly ThrowStatement: import("./types").StringableASTNode<import("estree").ThrowStatement>;
readonly TemplateLiteral: import("./types").StringableASTNode<import("estree").TemplateLiteral>;
readonly TemplateElement: import("./types").StringableASTNode<import("estree").TemplateElement>;
readonly TaggedTemplateExpression: import("./types").StringableASTNode<import("estree").TaggedTemplateExpression>;
readonly ObjectExpression: import("./types").StringableASTNode<import("estree").ObjectExpression>;
readonly ObjectPattern: import("./types").StringableASTNode<import("estree").ObjectPattern>;
readonly RestElement: <T>(node: T) => T;
readonly MemberExpression: import("./types").StringableASTNode<import("estree").MemberExpression>;
readonly MetaProperty: <T>(node: T) => T;
readonly MethodDefinition: import("./types").StringableASTNode<import("estree").MethodDefinition>;
readonly NewExpression: import("./types").StringableASTNode<import("estree").NewExpression>;
readonly SwitchStatement: import("./types").StringableASTNode<import("estree").SwitchStatement>;
readonly EmptyStatement: import("./types").StringableASTNode<import("estree").EmptyStatement>;
readonly FunctionDeclaration: import("./types").StringableASTNode<import("estree").FunctionDeclaration>;
readonly CallExpression: import("./types").StringableASTNode<import("estree").SimpleCallExpression>;
readonly SimpleCallExpression: import("./types").StringableASTNode<import("estree").SimpleCallExpression>;
readonly CatchClause: import("./types").StringableASTNode<import("estree").CatchClause>;
readonly ContinueStatement: import("./types").StringableASTNode<import("estree").ContinueStatement>;
readonly ClassDeclaration: import("./types").StringableASTNode<import("estree").ClassDeclaration>;
readonly ClassExpression: import("./types").StringableASTNode<import("estree").ClassExpression>;
readonly ClassBody: import("./types").StringableASTNode<import("estree").ClassBody>;
readonly DebuggerStatement: import("./types").StringableASTNode<import("estree").DebuggerStatement>;
readonly DoWhileStatement: import("./types").StringableASTNode<import("estree").DoWhileStatement>;
readonly ExportNamedDeclaration: import("./types").StringableASTNode<import("estree").ExportNamedDeclaration>;
readonly ExportSpecifier: import("./types").StringableASTNode<import("estree").ExportSpecifier>;
readonly ExportAllDeclaration: import("./types").StringableASTNode<import("estree").ExportAllDeclaration>;
readonly ExportDefaultDeclaration: import("./types").StringableASTNode<import("estree").ExportDefaultDeclaration>;
/** this isn't a concrete node type */
readonly Pattern: <T>(node: T) => T;
/** this isn't a concrete node type */
readonly Statement: <T>(node: T) => T;
readonly BreakStatement: import("./types").StringableASTNode<import("estree").BreakStatement>;
readonly PrivateIdentifier: <T>(node: T) => T;
readonly Property: import("./types").StringableASTNode<import("estree").Property>;
readonly PropertyDefinition: import("./types").StringableASTNode<import("estree").PropertyDefinition>;
readonly ReturnStatement: import("./types").StringableASTNode<import("estree").ReturnStatement>;
readonly Super: <T>(node: T) => T;
readonly SequenceExpression: import("./types").StringableASTNode<import("estree").SequenceExpression>;
readonly SpreadElement: import("./types").StringableASTNode<import("estree").SpreadElement>;
readonly StaticBlock: import("./types").StringableASTNode<import("estree").StaticBlock>;
readonly TryStatement: import("./types").StringableASTNode<import("estree").TryStatement>;
readonly WhileStatement: import("./types").StringableASTNode<import("estree").WhileStatement>;
readonly WithStatement: import("./types").StringableASTNode<import("estree").WithStatement>;
readonly ExpressionStatement: import("./types").StringableASTNode<import("estree").ExpressionStatement>;
readonly UnaryExpression: import("./types").StringableASTNode<import("estree").UnaryExpression>;
readonly UpdateExpression: import("./types").StringableASTNode<import("estree").UpdateExpression>;
readonly VariableDeclaration: import("./types").StringableASTNode<import("estree").VariableDeclaration>;
readonly VariableDeclarator: import("./types").StringableASTNode<import("estree").VariableDeclarator>;
readonly YieldExpression: import("./types").StringableASTNode<import("estree").YieldExpression>;
};
export declare const typeToHelperLookup: NodeMap<import("./types").EslintCodemodUtilsBaseNode>;

@@ -11,2 +11,3 @@ "use strict";

AssignmentProperty: identity_1.identity,
// TODO implement
AssignmentPattern: identity_1.identity,

@@ -51,2 +52,3 @@ AssignmentExpression: nodes_1.assignmentExpression,

ImportNamespaceSpecifier: nodes_1.importNamespaceSpecifier,
ImportDefaultSpecifier: nodes_1.importDefaultSpecifier,
ImportDeclaration: nodes_1.importDeclaration,

@@ -91,2 +93,3 @@ ImportExpression: nodes_1.importExpression,

Property: nodes_1.property,
Program: nodes_1.program,
PropertyDefinition: nodes_1.propertyDefinition,

@@ -98,2 +101,3 @@ ReturnStatement: nodes_1.returnStatement,

StaticBlock: nodes_1.staticBlock,
SwitchCase: nodes_1.switchCase,
TryStatement: nodes_1.tryStatement,

@@ -100,0 +104,0 @@ WhileStatement: nodes_1.whileStatement,

@@ -6,1 +6,3 @@ /** constants has to be first so that it resolves the map */

export * from './utils/utils';
export * from './types';
export type { JSXIdentifier, JSXNamespacedName, JSXMemberExpression, JSXEmptyExpression, JSXExpressionContainer, JSXSpreadAttribute, JSXAttribute, JSXOpeningElement, JSXOpeningFragment, JSXClosingElement, JSXClosingFragment, JSXElement, JSXFragment, JSXText, JSXSpreadChild, ExpressionStatement, BlockStatement, StaticBlock, EmptyStatement, DebuggerStatement, WithStatement, ReturnStatement, LabeledStatement, BreakStatement, ContinueStatement, IfStatement, SwitchStatement, ThrowStatement, TryStatement, WhileStatement, DoWhileStatement, ForStatement, ForInStatement, ForOfStatement, Declaration, Identifier, Literal, Program, Function, SwitchCase, CatchClause, VariableDeclarator, Statement, Expression, PrivateIdentifier, Property, PropertyDefinition, AssignmentProperty, Super, TemplateElement, SpreadElement, Pattern, ClassBody, Class, MethodDefinition, ModuleDeclaration, ModuleSpecifier, ThisExpression, ArrayExpression, ObjectExpression, FunctionExpression, ArrowFunctionExpression, YieldExpression, UnaryExpression, UpdateExpression, BinaryExpression, AssignmentExpression, LogicalExpression, MemberExpression, ConditionalExpression, CallExpression, NewExpression, SequenceExpression, TemplateLiteral, TaggedTemplateExpression, ClassExpression, MetaProperty, AwaitExpression, ImportExpression, ChainExpression, ImportDeclaration, ImportDefaultSpecifier, ImportNamespaceSpecifier, ImportSpecifier, } from 'estree-jsx';

@@ -18,1 +18,2 @@ "use strict";

__exportStar(require("./utils/utils"), exports);
__exportStar(require("./types"), exports);

@@ -1,3 +0,3 @@

import type { JSXOpeningElement, JSXClosingElement, JSXMemberExpression, JSXIdentifier, JSXFragment, Comment, SourceLocation, JSXElement, JSXAttribute, JSXExpressionContainer, JSXText, JSXSpreadAttribute, JSXSpreadChild, JSXOpeningFragment, JSXClosingFragment, JSXEmptyExpression } from 'estree-jsx';
import type { StringableASTNode } from './types';
import { Comment, JSXAttribute, JSXClosingElement, JSXClosingFragment, JSXElement, JSXEmptyExpression, JSXExpressionContainer, JSXFragment, JSXIdentifier, JSXMemberExpression, JSXOpeningElement, JSXOpeningFragment, JSXSpreadAttribute, JSXSpreadChild, JSXText, SourceLocation } from 'estree-jsx';
import type { StringableASTNodeFn } from './types';
export declare const whiteSpace: (loc?: SourceLocation | undefined) => string;

@@ -14,8 +14,8 @@ export declare const comments: (comments?: Comment[]) => {

};
export declare const jsxIdentifier: StringableASTNode<JSXIdentifier>;
export declare const jsxOpeningFragment: StringableASTNode<JSXOpeningFragment>;
export declare const jsxClosingFragment: StringableASTNode<JSXClosingFragment>;
export declare const jsxFragment: StringableASTNode<JSXFragment>;
export declare const jsxSpreadChild: StringableASTNode<JSXSpreadChild>;
export declare const jsxMemberExpression: StringableASTNode<JSXMemberExpression>;
export declare const jsxIdentifier: StringableASTNodeFn<JSXIdentifier>;
export declare const jsxOpeningFragment: StringableASTNodeFn<JSXOpeningFragment>;
export declare const jsxClosingFragment: StringableASTNodeFn<JSXClosingFragment>;
export declare const jsxFragment: StringableASTNodeFn<JSXFragment>;
export declare const jsxSpreadChild: StringableASTNodeFn<JSXSpreadChild>;
export declare const jsxMemberExpression: StringableASTNodeFn<JSXMemberExpression>;
/**

@@ -46,3 +46,3 @@ * __JSXElement__

*/
export declare const jsxElement: StringableASTNode<JSXElement>;
export declare const jsxElement: StringableASTNodeFn<JSXElement>;
/**

@@ -70,4 +70,4 @@ * __JSXSpreadAttribute__

*/
export declare const jsxSpreadAttribute: StringableASTNode<JSXSpreadAttribute>;
export declare const jsxOpeningElement: StringableASTNode<JSXOpeningElement>;
export declare const jsxSpreadAttribute: StringableASTNodeFn<JSXSpreadAttribute>;
export declare const jsxOpeningElement: StringableASTNodeFn<JSXOpeningElement>;
/**

@@ -86,3 +86,3 @@ * __JSXClosingElement__

*/
export declare const jsxClosingElement: StringableASTNode<JSXClosingElement>;
export declare const jsxClosingElement: StringableASTNodeFn<JSXClosingElement>;
/**

@@ -101,5 +101,5 @@ * __JSXText__

*/
export declare const jsxText: StringableASTNode<JSXText>;
export declare const jsxEmptyExpression: StringableASTNode<JSXEmptyExpression>;
export declare const jsxExpressionContainer: StringableASTNode<JSXExpressionContainer>;
export declare const jsxText: StringableASTNodeFn<JSXText>;
export declare const jsxEmptyExpression: StringableASTNodeFn<JSXEmptyExpression>;
export declare const jsxExpressionContainer: StringableASTNodeFn<JSXExpressionContainer>;
/**

@@ -118,2 +118,2 @@ * __JSXAttribute__

*/
export declare const jsxAttribute: StringableASTNode<JSXAttribute>;
export declare const jsxAttribute: StringableASTNodeFn<JSXAttribute>;

@@ -20,3 +20,3 @@ "use strict";

exports.comment = comment;
const jsxIdentifier = ({ name }) => ({
const jsxIdentifier = ({ name, }) => ({
name,

@@ -23,0 +23,0 @@ type: 'JSXIdentifier',

import * as estree from 'estree';
import { StringableASTNode } from './types';
import { StringableASTNodeFn } from './types';
/**

@@ -23,4 +23,4 @@ * __CallExpression__

*/
export declare const callExpression: StringableASTNode<estree.SimpleCallExpression>;
export declare const chainExpression: StringableASTNode<estree.ChainExpression>;
export declare const callExpression: StringableASTNodeFn<estree.SimpleCallExpression>;
export declare const chainExpression: StringableASTNodeFn<estree.ChainExpression>;
/**

@@ -35,3 +35,3 @@ * __BinaryExpression__

*/
export declare const binaryExpression: StringableASTNode<estree.BinaryExpression>;
export declare const binaryExpression: StringableASTNodeFn<estree.BinaryExpression>;
/**

@@ -46,3 +46,3 @@ * __SequenceExpression__

*/
export declare const sequenceExpression: StringableASTNode<estree.SequenceExpression>;
export declare const sequenceExpression: StringableASTNodeFn<estree.SequenceExpression>;
/**

@@ -58,3 +58,3 @@ * __ArrowFunctionExpression__

*/
export declare const arrowFunctionExpression: StringableASTNode<estree.ArrowFunctionExpression>;
export declare const arrowFunctionExpression: StringableASTNodeFn<estree.ArrowFunctionExpression>;
/**

@@ -69,7 +69,7 @@ * __TaggedTemplateExpression__

*/
export declare const taggedTemplateExpression: StringableASTNode<estree.TaggedTemplateExpression>;
export declare const functionExpression: StringableASTNode<estree.FunctionExpression>;
export declare const blockStatement: StringableASTNode<estree.BlockStatement>;
export declare const returnStatement: StringableASTNode<estree.ReturnStatement>;
export declare const throwStatement: StringableASTNode<estree.ThrowStatement>;
export declare const taggedTemplateExpression: StringableASTNodeFn<estree.TaggedTemplateExpression>;
export declare const functionExpression: StringableASTNodeFn<estree.FunctionExpression>;
export declare const blockStatement: StringableASTNodeFn<estree.BlockStatement>;
export declare const returnStatement: StringableASTNodeFn<estree.ReturnStatement>;
export declare const throwStatement: StringableASTNodeFn<estree.ThrowStatement>;
/**

@@ -89,3 +89,3 @@ * __UnaryExpression__

*/
export declare const unaryExpression: StringableASTNode<estree.UnaryExpression>;
export declare const unaryExpression: StringableASTNodeFn<estree.UnaryExpression>;
/**

@@ -104,3 +104,3 @@ * __ThisExpression__

*/
export declare const thisExpression: StringableASTNode<estree.ThisExpression>;
export declare const thisExpression: StringableASTNodeFn<estree.ThisExpression>;
/**

@@ -122,3 +122,3 @@ * __IfStatement__

*/
export declare const ifStatement: StringableASTNode<estree.IfStatement>;
export declare const ifStatement: StringableASTNodeFn<estree.IfStatement>;
/**

@@ -137,3 +137,3 @@ * __CatchClause__

*/
export declare const catchClause: StringableASTNode<estree.CatchClause>;
export declare const catchClause: StringableASTNodeFn<estree.CatchClause>;
/**

@@ -155,3 +155,3 @@ * __TryStatement__

*/
export declare const tryStatement: StringableASTNode<estree.TryStatement>;
export declare const tryStatement: StringableASTNodeFn<estree.TryStatement>;
/**

@@ -172,3 +172,3 @@ * __WithStatement__

*/
export declare const withStatement: StringableASTNode<estree.WithStatement>;
export declare const withStatement: StringableASTNodeFn<estree.WithStatement>;
/**

@@ -186,9 +186,9 @@ * __ImportExpression__

*/
export declare const importExpression: StringableASTNode<estree.ImportExpression>;
export declare const importDefaultSpecifier: StringableASTNode<estree.ImportDefaultSpecifier>;
export declare const exportNamedDeclaration: StringableASTNode<estree.ExportNamedDeclaration>;
export declare const exportDefaultDeclaration: StringableASTNode<estree.ExportDefaultDeclaration>;
export declare const exportAllDeclaration: StringableASTNode<estree.ExportAllDeclaration>;
export declare const exportSpecifier: StringableASTNode<estree.ExportSpecifier>;
export declare const importSpecifier: StringableASTNode<estree.ImportSpecifier>;
export declare const importExpression: StringableASTNodeFn<estree.ImportExpression>;
export declare const importDefaultSpecifier: StringableASTNodeFn<estree.ImportDefaultSpecifier>;
export declare const exportNamedDeclaration: StringableASTNodeFn<estree.ExportNamedDeclaration>;
export declare const exportDefaultDeclaration: StringableASTNodeFn<estree.ExportDefaultDeclaration>;
export declare const exportAllDeclaration: StringableASTNodeFn<estree.ExportAllDeclaration>;
export declare const exportSpecifier: StringableASTNodeFn<estree.ExportSpecifier>;
export declare const importSpecifier: StringableASTNodeFn<estree.ImportSpecifier>;
/**

@@ -206,7 +206,7 @@ * __YieldExpression__

*/
export declare const yieldExpression: StringableASTNode<estree.YieldExpression>;
export declare const arrayExpression: StringableASTNode<estree.ArrayExpression>;
export declare const arrayPattern: StringableASTNode<estree.ArrayPattern>;
export declare const updateExpression: StringableASTNode<estree.UpdateExpression>;
export declare const expressionStatement: StringableASTNode<estree.ExpressionStatement>;
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>;
/**

@@ -221,4 +221,4 @@ * __NewExpression__

*/
export declare const newExpression: StringableASTNode<estree.NewExpression>;
export declare const property: StringableASTNode<estree.Property>;
export declare const newExpression: StringableASTNodeFn<estree.NewExpression>;
export declare const property: StringableASTNodeFn<estree.Property>;
/**

@@ -234,3 +234,3 @@ * __ObjectPattern__

*/
export declare const objectPattern: StringableASTNode<estree.ObjectPattern>;
export declare const objectPattern: StringableASTNodeFn<estree.ObjectPattern>;
/**

@@ -249,30 +249,30 @@ * __SpreadElement__

*/
export declare const spreadElement: StringableASTNode<estree.SpreadElement>;
export declare const objectExpression: StringableASTNode<estree.ObjectExpression>;
export declare const emptyStatement: StringableASTNode<estree.EmptyStatement>;
export declare const memberExpression: StringableASTNode<estree.MemberExpression>;
export declare const logicalExpression: StringableASTNode<estree.LogicalExpression>;
export declare const variableDeclarator: StringableASTNode<estree.VariableDeclarator>;
export declare const variableDeclaration: StringableASTNode<estree.VariableDeclaration>;
export declare const importNamespaceSpecifier: StringableASTNode<estree.ImportNamespaceSpecifier>;
export declare const templateElement: StringableASTNode<estree.TemplateElement>;
export declare const importDeclaration: StringableASTNode<estree.ImportDeclaration>;
export declare const bigIntLiteral: StringableASTNode<estree.BigIntLiteral>;
export declare const regExpLiteral: StringableASTNode<estree.RegExpLiteral>;
export declare const literal: StringableASTNode<estree.Literal>;
export declare const identifier: StringableASTNode<estree.Identifier>;
export declare const doWhileStatement: StringableASTNode<estree.DoWhileStatement>;
export declare const whileStatement: StringableASTNode<estree.WhileStatement>;
export declare const switchCase: StringableASTNode<estree.SwitchCase>;
export declare const switchStatement: StringableASTNode<estree.SwitchStatement>;
export declare const templateLiteral: StringableASTNode<estree.TemplateLiteral>;
export declare const forStatement: StringableASTNode<estree.ForStatement>;
export declare const forInStatement: StringableASTNode<estree.ForInStatement>;
export declare const forOfStatement: StringableASTNode<estree.ForOfStatement>;
export declare const continueStatement: StringableASTNode<estree.ContinueStatement>;
export declare const breakStatement: StringableASTNode<estree.BreakStatement>;
export declare const debuggerStatement: StringableASTNode<estree.DebuggerStatement>;
export declare const conditionalExpression: StringableASTNode<estree.ConditionalExpression>;
export declare const assignmentExpression: StringableASTNode<estree.AssignmentExpression>;
export declare const awaitExpression: StringableASTNode<estree.AwaitExpression>;
export declare const spreadElement: StringableASTNodeFn<estree.SpreadElement>;
export declare const objectExpression: StringableASTNodeFn<estree.ObjectExpression>;
export declare const emptyStatement: StringableASTNodeFn<estree.EmptyStatement>;
export declare const memberExpression: StringableASTNodeFn<estree.MemberExpression>;
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>;
export declare const bigIntLiteral: StringableASTNodeFn<estree.BigIntLiteral>;
export declare const regExpLiteral: StringableASTNodeFn<estree.RegExpLiteral>;
export declare const literal: StringableASTNodeFn<estree.Literal>;
export declare const identifier: StringableASTNodeFn<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>;
/**

@@ -290,10 +290,10 @@ * __StaticBlock__

*/
export declare const staticBlock: StringableASTNode<estree.StaticBlock>;
export declare const functionDeclaration: StringableASTNode<estree.FunctionDeclaration>;
export declare const staticBlock: StringableASTNodeFn<estree.StaticBlock>;
export declare const functionDeclaration: StringableASTNodeFn<estree.FunctionDeclaration>;
export declare const methodOrPropertyFn: (fn: estree.FunctionExpression) => string;
export declare const methodDefinition: StringableASTNode<estree.MethodDefinition>;
export declare const propertyDefinition: StringableASTNode<estree.PropertyDefinition>;
export declare const classBody: StringableASTNode<estree.ClassBody>;
export declare const classDeclaration: StringableASTNode<estree.ClassDeclaration>;
export declare const classExpression: StringableASTNode<estree.ClassExpression>;
export declare const program: StringableASTNode<estree.Program>;
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>;

@@ -720,3 +720,3 @@ "use strict";

exports.literal = literal;
const identifier = ({ name }) => ({
const identifier = ({ name, }) => ({
type: 'Identifier',

@@ -723,0 +723,0 @@ __pragma: 'ecu',

@@ -1,7 +0,11 @@

import type { BaseNode } from 'estree-jsx';
import type { Node as BaseNode, JSXSpreadChild } from 'estree-jsx';
import type { Rule } from 'eslint';
export declare type StringableASTNode<NodeType extends BaseNode> = (node: Omit<NodeType, 'type'>) => NodeType & {
__pragma: 'ecu';
export declare type EslintCodemodUtilsBaseNode = BaseNode | JSXSpreadChild;
export declare type RuleListener<T extends EslintNode = EslintNode> = {
[E in T as E['type']]?: (eventNodeListener: E) => void;
};
export declare type StringableASTNode<T extends EslintCodemodUtilsBaseNode> = T & {
toString(): string;
};
export declare type EslintNode = Rule.NodeParentExtension & BaseNode;
export declare type StringableASTNodeFn<EstreeNodeType extends EslintCodemodUtilsBaseNode> = (node: Omit<EstreeNodeType, 'type'>) => StringableASTNode<EstreeNodeType>;
export declare type EslintNode = Rule.NodeParentExtension & EslintCodemodUtilsBaseNode;

@@ -1,9 +0,5 @@

import { typeToHelperLookup } from '../constants';
import * as estree from 'estree';
declare type NodeMap = typeof typeToHelperLookup;
declare type NodeType = keyof NodeMap;
interface ESTreeNode {
type: NodeType;
}
export declare const node: <Node_1 extends estree.Identifier | estree.SimpleLiteral | estree.RegExpLiteral | estree.BigIntLiteral | estree.FunctionDeclaration | estree.FunctionExpression | estree.ArrowFunctionExpression | estree.ExpressionStatement | estree.BlockStatement | estree.StaticBlock | estree.EmptyStatement | estree.DebuggerStatement | estree.WithStatement | estree.ReturnStatement | estree.LabeledStatement | estree.BreakStatement | estree.ContinueStatement | estree.IfStatement | estree.SwitchStatement | estree.ThrowStatement | estree.TryStatement | estree.WhileStatement | estree.DoWhileStatement | estree.ForStatement | estree.ForInStatement | estree.ForOfStatement | estree.VariableDeclaration | estree.ClassDeclaration | estree.ThisExpression | estree.ArrayExpression | estree.ObjectExpression | estree.YieldExpression | estree.UnaryExpression | estree.UpdateExpression | estree.BinaryExpression | estree.AssignmentExpression | estree.LogicalExpression | estree.MemberExpression | estree.ConditionalExpression | estree.SimpleCallExpression | estree.NewExpression | estree.SequenceExpression | estree.TemplateLiteral | estree.TaggedTemplateExpression | estree.ClassExpression | estree.MetaProperty | estree.AwaitExpression | estree.ImportExpression | estree.ChainExpression | estree.ObjectPattern | estree.ArrayPattern | estree.RestElement | estree.AssignmentPattern | ESTreeNode>(node: Node_1) => NodeMap[NodeType];
export {};
import type { EslintCodemodUtilsBaseNode, StringableASTNode } from '../types';
export declare type NodeMap<T extends EslintCodemodUtilsBaseNode = EslintCodemodUtilsBaseNode> = {
[E in T as E['type']]: (eventNodeListener: E) => StringableASTNode<E>;
};
export declare const node: <EstreeNodeType extends EslintCodemodUtilsBaseNode>(estNode: EstreeNodeType) => StringableASTNode<EstreeNodeType>;

@@ -5,9 +5,6 @@ "use strict";

const constants_1 = require("../constants");
const node = (node) => {
if (!node) {
return node;
}
// @ts-expect-error
return constants_1.typeToHelperLookup[node.type](node);
const node = (estNode) => {
// @ts-ignore
return constants_1.typeToHelperLookup[estNode.type](estNode);
};
exports.node = node;

@@ -1,5 +0,6 @@

import { JSXElement } from 'estree-jsx';
import type { EslintNode } from '../types';
export declare function isNode<T extends EslintNode>(node: T, type: unknown): boolean;
import type { JSXElement } from 'estree-jsx';
import type { EslintCodemodUtilsBaseNode, EslintNode } from '../types';
export declare function isNode<T extends EslintCodemodUtilsBaseNode, K extends EslintCodemodUtilsBaseNode>(node: T, type: K['type']): boolean;
export declare function closestOfType<T extends EslintNode>(node: T, type: EslintNode['type']): EslintNode | null;
export declare function hasJSXAttribute(node: JSXElement, attributeName: string): boolean;
export declare function hasJSXChild(node: JSXElement, childIdentifier: string): boolean;
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.hasJSXAttribute = exports.closestOfType = exports.isNode = void 0;
exports.hasJSXChild = exports.hasJSXAttribute = exports.closestOfType = exports.isNode = void 0;
function isNode(node, type) {

@@ -9,3 +9,2 @@ return node.type === type;

function closestOfType(node, type) {
console.info(node);
if (isNode(node, type)) {

@@ -28,1 +27,15 @@ return node;

exports.hasJSXAttribute = hasJSXAttribute;
function isJSXIdentifier(node, id) {
return node.name === id;
}
function hasJSXChild(node, childIdentifier) {
const jsxIdentifierMatch = node.openingElement.name.type === 'JSXIdentifier' &&
node.openingElement.name.name &&
isJSXIdentifier(node.openingElement.name, childIdentifier);
return (jsxIdentifierMatch ||
Boolean(node.children &&
node.children
.filter((child) => isNode(child, 'JSXElement'))
.find((child) => hasJSXChild(child, childIdentifier))));
}
exports.hasJSXChild = hasJSXChild;
import {
callExpression,
comment,
doWhileStatement,
identifier,
ifStatement,
importDeclaration,
importDefaultSpecifier,
importSpecifier,
jsxAttribute,
jsxClosingElement,
jsxElement,
jsxExpressionContainer,
jsxIdentifier,
jsxMemberExpression,
jsxOpeningElement,
comment,
jsxElement,
jsxExpressionContainer,
identifier,
jsxAttribute,
jsxSpreadAttribute,
jsxText,
literal,
importDeclaration,
importSpecifier,
importDefaultSpecifier,
jsxText,
jsxSpreadAttribute,
callExpression,
staticBlock,
throwStatement,
variableDeclaration,

@@ -23,3 +26,2 @@ } from '..'

import * as espree from 'espree'
import { doWhileStatement, ifStatement, throwStatement } from '../nodes'

@@ -26,0 +28,0 @@ const ESPREE_OPTIONS = {

@@ -7,3 +7,4 @@ import { program } from '..'

test('basic', () => {
expect(String(program(programFixture as any))).eq(
// @ts-expect-error This is fine it's just JSON
expect(String(program(programFixture))).eq(
`import A, { Welcome } from '@atlaskit/welcome'

@@ -10,0 +11,0 @@ import { X } from './other'

@@ -16,3 +16,2 @@ import * as espree from 'espree'

const program = espree.parse('<Hello name="world"></Hello>', ESPREE_OPTIONS)
console.log(program.body[0].expression)
expect(

@@ -19,0 +18,0 @@ closestOfType(program.body[0].expression.openingElement, 'JSXElement')

@@ -19,66 +19,70 @@ import {

import {
importDeclaration,
arrayExpression,
arrayPattern,
arrowFunctionExpression,
assignmentExpression,
awaitExpression,
binaryExpression,
blockStatement,
breakStatement,
callExpression,
identifier,
importSpecifier,
literal,
newExpression,
thisExpression,
whileStatement,
switchStatement,
functionDeclaration,
expressionStatement,
variableDeclaration,
continueStatement,
catchClause,
chainExpression,
classBody,
classDeclaration,
memberExpression,
arrayExpression,
variableDeclarator,
classExpression,
objectExpression,
conditionalExpression,
continueStatement,
debuggerStatement,
doWhileStatement,
emptyStatement,
spreadElement,
sequenceExpression,
arrowFunctionExpression,
yieldExpression,
unaryExpression,
blockStatement,
objectPattern,
staticBlock,
debuggerStatement,
forStatement,
binaryExpression,
updateExpression,
returnStatement,
exportAllDeclaration,
exportDefaultDeclaration,
exportNamedDeclaration,
exportSpecifier,
exportDefaultDeclaration,
exportAllDeclaration,
logicalExpression,
expressionStatement,
forInStatement,
forOfStatement,
forStatement,
functionDeclaration,
functionExpression,
identifier,
ifStatement,
importDeclaration,
importDefaultSpecifier,
importExpression,
importNamespaceSpecifier,
importSpecifier,
literal,
logicalExpression,
memberExpression,
methodDefinition,
newExpression,
objectExpression,
objectPattern,
program,
property,
propertyDefinition,
classBody,
methodDefinition,
assignmentExpression,
breakStatement,
returnStatement,
sequenceExpression,
spreadElement,
staticBlock,
switchCase,
switchStatement,
taggedTemplateExpression,
templateElement,
templateLiteral,
templateElement,
conditionalExpression,
taggedTemplateExpression,
awaitExpression,
importExpression,
chainExpression,
withStatement,
ifStatement,
thisExpression,
throwStatement,
catchClause,
tryStatement,
doWhileStatement,
forInStatement,
forOfStatement,
arrayPattern,
unaryExpression,
updateExpression,
variableDeclaration,
variableDeclarator,
whileStatement,
withStatement,
yieldExpression,
} from './nodes'
import { identity } from './utils/identity'
import { NodeMap } from './utils/node'

@@ -91,2 +95,3 @@ export const DEFAULT_WHITESPACE = '\n '

AssignmentProperty: identity,
// TODO implement
AssignmentPattern: identity,

@@ -131,2 +136,3 @@ AssignmentExpression: assignmentExpression,

ImportNamespaceSpecifier: importNamespaceSpecifier,
ImportDefaultSpecifier: importDefaultSpecifier,
ImportDeclaration: importDeclaration,

@@ -171,2 +177,3 @@ ImportExpression: importExpression,

Property: property,
Program: program,
PropertyDefinition: propertyDefinition,

@@ -178,2 +185,3 @@ ReturnStatement: returnStatement,

StaticBlock: staticBlock,
SwitchCase: switchCase,
TryStatement: tryStatement,

@@ -188,3 +196,3 @@ WhileStatement: whileStatement,

YieldExpression: yieldExpression,
} as const,
} as NodeMap,
{

@@ -191,0 +199,0 @@ // dynamic getter will fail and provide debug information

@@ -6,1 +6,90 @@ /** constants has to be first so that it resolves the map */

export * from './utils/utils'
export * from './types'
// re-export estree-jsx - unfortunatley can't export *
export type {
JSXIdentifier,
JSXNamespacedName,
JSXMemberExpression,
JSXEmptyExpression,
JSXExpressionContainer,
JSXSpreadAttribute,
JSXAttribute,
JSXOpeningElement,
JSXOpeningFragment,
JSXClosingElement,
JSXClosingFragment,
JSXElement,
JSXFragment,
JSXText,
JSXSpreadChild,
ExpressionStatement,
BlockStatement,
StaticBlock,
EmptyStatement,
DebuggerStatement,
WithStatement,
ReturnStatement,
LabeledStatement,
BreakStatement,
ContinueStatement,
IfStatement,
SwitchStatement,
ThrowStatement,
TryStatement,
WhileStatement,
DoWhileStatement,
ForStatement,
ForInStatement,
ForOfStatement,
Declaration,
Identifier,
Literal,
Program,
Function,
SwitchCase,
CatchClause,
VariableDeclarator,
Statement,
Expression,
PrivateIdentifier,
Property,
PropertyDefinition,
AssignmentProperty,
Super,
TemplateElement,
SpreadElement,
Pattern,
ClassBody,
Class,
MethodDefinition,
ModuleDeclaration,
ModuleSpecifier,
ThisExpression,
ArrayExpression,
ObjectExpression,
FunctionExpression,
ArrowFunctionExpression,
YieldExpression,
UnaryExpression,
UpdateExpression,
BinaryExpression,
AssignmentExpression,
LogicalExpression,
MemberExpression,
ConditionalExpression,
CallExpression,
NewExpression,
SequenceExpression,
TemplateLiteral,
TaggedTemplateExpression,
ClassExpression,
MetaProperty,
AwaitExpression,
ImportExpression,
ChainExpression,
ImportDeclaration,
ImportDefaultSpecifier,
ImportNamespaceSpecifier,
ImportSpecifier,
} from 'estree-jsx'

@@ -1,22 +0,22 @@

import type {
JSXOpeningElement,
import {
Comment,
JSXAttribute,
JSXClosingElement,
JSXMemberExpression,
JSXIdentifier,
JSXFragment,
Comment,
SourceLocation,
JSXClosingFragment,
JSXElement,
JSXAttribute,
JSXEmptyExpression,
JSXExpressionContainer,
JSXText,
JSXFragment,
JSXIdentifier,
JSXMemberExpression,
JSXOpeningElement,
JSXOpeningFragment,
JSXSpreadAttribute,
JSXSpreadChild,
JSXOpeningFragment,
JSXClosingFragment,
JSXEmptyExpression,
JSXText,
SourceLocation,
} from 'estree-jsx'
import { DEFAULT_WHITESPACE } from './constants'
import type { StringableASTNode } from './types'
import type { StringableASTNodeFn } from './types'
import { node } from './utils/node'

@@ -41,4 +41,6 @@

export const jsxIdentifier: StringableASTNode<JSXIdentifier> = ({ name }) => ({
export const jsxIdentifier: StringableASTNodeFn<JSXIdentifier> = ({
name,
}) => ({
name,
type: 'JSXIdentifier',

@@ -49,3 +51,3 @@ __pragma: 'ecu',

export const jsxOpeningFragment: StringableASTNode<JSXOpeningFragment> = ({
export const jsxOpeningFragment: StringableASTNodeFn<JSXOpeningFragment> = ({
...other

@@ -61,3 +63,3 @@ }) => {

export const jsxClosingFragment: StringableASTNode<JSXClosingFragment> = ({
export const jsxClosingFragment: StringableASTNodeFn<JSXClosingFragment> = ({
...other

@@ -73,3 +75,3 @@ }) => {

export const jsxFragment: StringableASTNode<JSXFragment> = ({
export const jsxFragment: StringableASTNodeFn<JSXFragment> = ({
openingFragment,

@@ -94,3 +96,3 @@ closingFragment,

export const jsxSpreadChild: StringableASTNode<JSXSpreadChild> = ({
export const jsxSpreadChild: StringableASTNodeFn<JSXSpreadChild> = ({
expression,

@@ -108,3 +110,3 @@ ...other

export const jsxMemberExpression: StringableASTNode<JSXMemberExpression> = ({
export const jsxMemberExpression: StringableASTNodeFn<JSXMemberExpression> = ({
object,

@@ -161,3 +163,3 @@ property,

*/
export const jsxElement: StringableASTNode<JSXElement> = ({
export const jsxElement: StringableASTNodeFn<JSXElement> = ({
openingElement,

@@ -207,3 +209,3 @@ closingElement,

*/
export const jsxSpreadAttribute: StringableASTNode<JSXSpreadAttribute> = ({
export const jsxSpreadAttribute: StringableASTNodeFn<JSXSpreadAttribute> = ({
argument,

@@ -217,3 +219,3 @@ }) => ({

export const jsxOpeningElement: StringableASTNode<JSXOpeningElement> = ({
export const jsxOpeningElement: StringableASTNodeFn<JSXOpeningElement> = ({
name,

@@ -267,3 +269,3 @@ attributes = [],

*/
export const jsxClosingElement: StringableASTNode<JSXClosingElement> = ({
export const jsxClosingElement: StringableASTNodeFn<JSXClosingElement> = ({
name,

@@ -292,3 +294,3 @@ }) => {

*/
export const jsxText: StringableASTNode<JSXText> = ({ value, raw }) => ({
export const jsxText: StringableASTNodeFn<JSXText> = ({ value, raw }) => ({
type: 'JSXText',

@@ -301,3 +303,3 @@ value,

export const jsxEmptyExpression: StringableASTNode<JSXEmptyExpression> = (
export const jsxEmptyExpression: StringableASTNodeFn<JSXEmptyExpression> = (
node

@@ -313,3 +315,3 @@ ) => {

export const jsxExpressionContainer: StringableASTNode<
export const jsxExpressionContainer: StringableASTNodeFn<
JSXExpressionContainer

@@ -347,3 +349,3 @@ > = ({ expression }) => ({

*/
export const jsxAttribute: StringableASTNode<JSXAttribute> = ({
export const jsxAttribute: StringableASTNodeFn<JSXAttribute> = ({
name,

@@ -350,0 +352,0 @@ value,

import * as estree from 'estree'
import { StringableASTNode } from './types'
import { StringableASTNodeFn } from './types'
import { node } from './utils/node'

@@ -27,8 +27,5 @@ import { DEFAULT_WHITESPACE } from './constants'

*/
export const callExpression: StringableASTNode<estree.SimpleCallExpression> = ({
arguments: calleeArgs,
callee,
optional,
...other
}) => {
export const callExpression: StringableASTNodeFn<
estree.SimpleCallExpression
> = ({ arguments: calleeArgs, callee, optional, ...other }) => {
return {

@@ -48,3 +45,3 @@ ...other,

export const chainExpression: StringableASTNode<estree.ChainExpression> = ({
export const chainExpression: StringableASTNodeFn<estree.ChainExpression> = ({
expression,

@@ -71,3 +68,3 @@ ...other

*/
export const binaryExpression: StringableASTNode<estree.BinaryExpression> = ({
export const binaryExpression: StringableASTNodeFn<estree.BinaryExpression> = ({
left,

@@ -98,3 +95,3 @@ right,

*/
export const sequenceExpression: StringableASTNode<
export const sequenceExpression: StringableASTNodeFn<
estree.SequenceExpression

@@ -121,3 +118,3 @@ > = ({ expressions, ...other }) => {

*/
export const arrowFunctionExpression: StringableASTNode<
export const arrowFunctionExpression: StringableASTNodeFn<
estree.ArrowFunctionExpression

@@ -150,3 +147,3 @@ > = ({ async, body, expression, params, ...other }) => {

*/
export const taggedTemplateExpression: StringableASTNode<
export const taggedTemplateExpression: StringableASTNodeFn<
estree.TaggedTemplateExpression

@@ -164,3 +161,3 @@ > = ({ quasi, tag, ...other }) => {

export const functionExpression: StringableASTNode<
export const functionExpression: StringableASTNodeFn<
estree.FunctionExpression

@@ -184,3 +181,3 @@ > = ({ async, generator, body, params, id, ...other }) => {

export const blockStatement: StringableASTNode<estree.BlockStatement> = ({
export const blockStatement: StringableASTNodeFn<estree.BlockStatement> = ({
body,

@@ -205,3 +202,3 @@ ...other

export const returnStatement: StringableASTNode<estree.ReturnStatement> = ({
export const returnStatement: StringableASTNodeFn<estree.ReturnStatement> = ({
argument,

@@ -226,3 +223,3 @@ ...other

export const throwStatement: StringableASTNode<estree.ThrowStatement> = ({
export const throwStatement: StringableASTNodeFn<estree.ThrowStatement> = ({
argument,

@@ -262,3 +259,3 @@ ...other

*/
export const unaryExpression: StringableASTNode<estree.UnaryExpression> = ({
export const unaryExpression: StringableASTNodeFn<estree.UnaryExpression> = ({
operator,

@@ -289,3 +286,3 @@ ...other

*/
export const thisExpression: StringableASTNode<estree.ThisExpression> = (
export const thisExpression: StringableASTNodeFn<estree.ThisExpression> = (
node

@@ -315,3 +312,3 @@ ) => ({

*/
export const ifStatement: StringableASTNode<estree.IfStatement> = ({
export const ifStatement: StringableASTNodeFn<estree.IfStatement> = ({
test,

@@ -347,3 +344,3 @@ alternate,

*/
export const catchClause: StringableASTNode<estree.CatchClause> = ({
export const catchClause: StringableASTNodeFn<estree.CatchClause> = ({
body,

@@ -377,3 +374,3 @@ param,

*/
export const tryStatement: StringableASTNode<estree.TryStatement> = ({
export const tryStatement: StringableASTNodeFn<estree.TryStatement> = ({
block,

@@ -411,3 +408,3 @@ finalizer,

*/
export const withStatement: StringableASTNode<estree.WithStatement> = ({
export const withStatement: StringableASTNodeFn<estree.WithStatement> = ({
object,

@@ -437,3 +434,3 @@ body,

*/
export const importExpression: StringableASTNode<estree.ImportExpression> = ({
export const importExpression: StringableASTNodeFn<estree.ImportExpression> = ({
source,

@@ -449,3 +446,3 @@ ...other

export const importDefaultSpecifier: StringableASTNode<
export const importDefaultSpecifier: StringableASTNodeFn<
estree.ImportDefaultSpecifier

@@ -460,3 +457,3 @@ > = ({ local, ...other }) => ({

export const exportNamedDeclaration: StringableASTNode<
export const exportNamedDeclaration: StringableASTNodeFn<
estree.ExportNamedDeclaration

@@ -480,3 +477,3 @@ > = ({ declaration, specifiers, source, ...other }) => {

export const exportDefaultDeclaration: StringableASTNode<
export const exportDefaultDeclaration: StringableASTNodeFn<
estree.ExportDefaultDeclaration

@@ -493,3 +490,3 @@ > = ({ declaration, ...other }) => {

export const exportAllDeclaration: StringableASTNode<
export const exportAllDeclaration: StringableASTNodeFn<
estree.ExportAllDeclaration

@@ -506,3 +503,3 @@ > = ({ source, ...other }) => {

export const exportSpecifier: StringableASTNode<estree.ExportSpecifier> = ({
export const exportSpecifier: StringableASTNodeFn<estree.ExportSpecifier> = ({
exported,

@@ -525,3 +522,3 @@ local,

export const importSpecifier: StringableASTNode<estree.ImportSpecifier> = ({
export const importSpecifier: StringableASTNodeFn<estree.ImportSpecifier> = ({
imported,

@@ -556,3 +553,3 @@ local,

*/
export const yieldExpression: StringableASTNode<estree.YieldExpression> = ({
export const yieldExpression: StringableASTNodeFn<estree.YieldExpression> = ({
argument,

@@ -572,3 +569,3 @@ delegate,

export const arrayExpression: StringableASTNode<estree.ArrayExpression> = ({
export const arrayExpression: StringableASTNodeFn<estree.ArrayExpression> = ({
elements,

@@ -593,3 +590,3 @@ ...other

export const arrayPattern: StringableASTNode<estree.ArrayPattern> = ({
export const arrayPattern: StringableASTNodeFn<estree.ArrayPattern> = ({
elements,

@@ -612,3 +609,3 @@ ...other

export const updateExpression: StringableASTNode<estree.UpdateExpression> = ({
export const updateExpression: StringableASTNodeFn<estree.UpdateExpression> = ({
argument,

@@ -633,3 +630,3 @@ operator,

export const expressionStatement: StringableASTNode<
export const expressionStatement: StringableASTNodeFn<
estree.ExpressionStatement

@@ -653,3 +650,3 @@ > = ({ expression, ...other }) => ({

*/
export const newExpression: StringableASTNode<estree.NewExpression> = ({
export const newExpression: StringableASTNodeFn<estree.NewExpression> = ({
callee,

@@ -667,3 +664,3 @@ arguments: argumentsParam,

export const property: StringableASTNode<estree.Property> = ({
export const property: StringableASTNodeFn<estree.Property> = ({
kind,

@@ -704,3 +701,3 @@ key,

*/
export const objectPattern: StringableASTNode<estree.ObjectPattern> = ({
export const objectPattern: StringableASTNodeFn<estree.ObjectPattern> = ({
properties,

@@ -731,3 +728,3 @@ ...other

*/
export const spreadElement: StringableASTNode<estree.SpreadElement> = ({
export const spreadElement: StringableASTNodeFn<estree.SpreadElement> = ({
argument,

@@ -745,3 +742,3 @@ ...other

export const objectExpression: StringableASTNode<estree.ObjectExpression> = ({
export const objectExpression: StringableASTNodeFn<estree.ObjectExpression> = ({
properties,

@@ -765,3 +762,3 @@ ...other

export const emptyStatement: StringableASTNode<estree.EmptyStatement> = ({
export const emptyStatement: StringableASTNodeFn<estree.EmptyStatement> = ({
...other

@@ -775,3 +772,3 @@ }) => ({

export const memberExpression: StringableASTNode<estree.MemberExpression> = ({
export const memberExpression: StringableASTNodeFn<estree.MemberExpression> = ({
object,

@@ -789,8 +786,5 @@ property,

export const logicalExpression: StringableASTNode<estree.LogicalExpression> = ({
left,
right,
operator,
...other
}) => {
export const logicalExpression: StringableASTNodeFn<
estree.LogicalExpression
> = ({ left, right, operator, ...other }) => {
return {

@@ -807,3 +801,3 @@ ...other,

export const variableDeclarator: StringableASTNode<
export const variableDeclarator: StringableASTNodeFn<
estree.VariableDeclarator

@@ -821,3 +815,3 @@ > = ({ id, init, ...other }) => {

export const variableDeclaration: StringableASTNode<
export const variableDeclaration: StringableASTNodeFn<
estree.VariableDeclaration

@@ -839,3 +833,3 @@ > = ({ declarations, kind, ...other }) => {

export const importNamespaceSpecifier: StringableASTNode<
export const importNamespaceSpecifier: StringableASTNodeFn<
estree.ImportNamespaceSpecifier

@@ -851,3 +845,3 @@ > = ({ local }) => {

export const templateElement: StringableASTNode<estree.TemplateElement> = ({
export const templateElement: StringableASTNodeFn<estree.TemplateElement> = ({
value,

@@ -865,7 +859,5 @@ ...other

export const importDeclaration: StringableASTNode<estree.ImportDeclaration> = ({
specifiers,
source,
...other
}) => ({
export const importDeclaration: StringableASTNodeFn<
estree.ImportDeclaration
> = ({ specifiers, source, ...other }) => ({
...other,

@@ -918,3 +910,3 @@ __pragma: 'ecu',

export const bigIntLiteral: StringableASTNode<estree.BigIntLiteral> = ({
export const bigIntLiteral: StringableASTNodeFn<estree.BigIntLiteral> = ({
value,

@@ -934,3 +926,3 @@ raw,

export const regExpLiteral: StringableASTNode<estree.RegExpLiteral> = ({
export const regExpLiteral: StringableASTNodeFn<estree.RegExpLiteral> = ({
value,

@@ -950,3 +942,3 @@ raw,

export const literal: StringableASTNode<estree.Literal> = (n) => {
export const literal: StringableASTNodeFn<estree.Literal> = (n) => {
if ('bigint' in n) {

@@ -966,3 +958,5 @@ return bigIntLiteral(n as estree.BigIntLiteral)

export const identifier: StringableASTNode<estree.Identifier> = ({ name }) => ({
export const identifier: StringableASTNodeFn<estree.Identifier> = ({
name,
}) => ({
type: 'Identifier',

@@ -974,3 +968,3 @@ __pragma: 'ecu',

export const doWhileStatement: StringableASTNode<estree.DoWhileStatement> = ({
export const doWhileStatement: StringableASTNodeFn<estree.DoWhileStatement> = ({
test,

@@ -990,3 +984,3 @@ body,

export const whileStatement: StringableASTNode<estree.WhileStatement> = ({
export const whileStatement: StringableASTNodeFn<estree.WhileStatement> = ({
test,

@@ -1006,3 +1000,3 @@ body,

export const switchCase: StringableASTNode<estree.SwitchCase> = ({
export const switchCase: StringableASTNodeFn<estree.SwitchCase> = ({
consequent,

@@ -1026,3 +1020,3 @@ test,

export const switchStatement: StringableASTNode<estree.SwitchStatement> = ({
export const switchStatement: StringableASTNodeFn<estree.SwitchStatement> = ({
cases,

@@ -1041,3 +1035,3 @@ discriminant,

export const templateLiteral: StringableASTNode<estree.TemplateLiteral> = ({
export const templateLiteral: StringableASTNodeFn<estree.TemplateLiteral> = ({
expressions,

@@ -1078,3 +1072,3 @@ quasis,

export const forStatement: StringableASTNode<estree.ForStatement> = ({
export const forStatement: StringableASTNodeFn<estree.ForStatement> = ({
body,

@@ -1099,3 +1093,3 @@ init,

export const forInStatement: StringableASTNode<estree.ForInStatement> = ({
export const forInStatement: StringableASTNodeFn<estree.ForInStatement> = ({
body,

@@ -1115,3 +1109,3 @@ left,

export const forOfStatement: StringableASTNode<estree.ForOfStatement> = ({
export const forOfStatement: StringableASTNodeFn<estree.ForOfStatement> = ({
body,

@@ -1131,6 +1125,5 @@ left,

export const continueStatement: StringableASTNode<estree.ContinueStatement> = ({
label,
...other
}) => ({
export const continueStatement: StringableASTNodeFn<
estree.ContinueStatement
> = ({ label, ...other }) => ({
...other,

@@ -1143,3 +1136,3 @@ toString: () => `continue${label ? ` ${node(label)}` : ''}`,

export const breakStatement: StringableASTNode<estree.BreakStatement> = ({
export const breakStatement: StringableASTNodeFn<estree.BreakStatement> = ({
label,

@@ -1155,5 +1148,5 @@ ...other

export const debuggerStatement: StringableASTNode<estree.DebuggerStatement> = (
node
) => ({
export const debuggerStatement: StringableASTNodeFn<
estree.DebuggerStatement
> = (node) => ({
...node,

@@ -1165,3 +1158,3 @@ toString: () => `debugger`,

export const conditionalExpression: StringableASTNode<
export const conditionalExpression: StringableASTNodeFn<
estree.ConditionalExpression

@@ -1178,3 +1171,3 @@ > = ({ consequent, alternate, test, ...other }) => ({

export const assignmentExpression: StringableASTNode<
export const assignmentExpression: StringableASTNodeFn<
estree.AssignmentExpression

@@ -1193,3 +1186,3 @@ > = ({ left, right, operator, ...other }) => {

export const awaitExpression: StringableASTNode<estree.AwaitExpression> = ({
export const awaitExpression: StringableASTNodeFn<estree.AwaitExpression> = ({
argument,

@@ -1217,3 +1210,3 @@ ...other

*/
export const staticBlock: StringableASTNode<estree.StaticBlock> = ({
export const staticBlock: StringableASTNodeFn<estree.StaticBlock> = ({
body,

@@ -1232,3 +1225,3 @@ ...other

export const functionDeclaration: StringableASTNode<
export const functionDeclaration: StringableASTNodeFn<
estree.FunctionDeclaration

@@ -1255,3 +1248,3 @@ > = ({ body, async, id, generator, params, ...other }) => ({

export const methodDefinition: StringableASTNode<estree.MethodDefinition> = ({
export const methodDefinition: StringableASTNodeFn<estree.MethodDefinition> = ({
computed,

@@ -1275,3 +1268,3 @@ key,

export const propertyDefinition: StringableASTNode<
export const propertyDefinition: StringableASTNodeFn<
estree.PropertyDefinition

@@ -1291,3 +1284,3 @@ > = ({ computed, key, static: staticKeyWord, value, ...other }) => {

export const classBody: StringableASTNode<estree.ClassBody> = ({
export const classBody: StringableASTNodeFn<estree.ClassBody> = ({
body,

@@ -1311,3 +1304,3 @@ ...other

export const classDeclaration: StringableASTNode<estree.ClassDeclaration> = ({
export const classDeclaration: StringableASTNodeFn<estree.ClassDeclaration> = ({
superClass,

@@ -1332,3 +1325,3 @@ id,

export const classExpression: StringableASTNode<estree.ClassExpression> = ({
export const classExpression: StringableASTNodeFn<estree.ClassExpression> = ({
superClass,

@@ -1351,3 +1344,3 @@ id,

export const program: StringableASTNode<estree.Program> = ({
export const program: StringableASTNodeFn<estree.Program> = ({
body,

@@ -1354,0 +1347,0 @@ ...other

@@ -1,8 +0,19 @@

import type { BaseNode } from 'estree-jsx'
import type { Node as BaseNode, JSXSpreadChild } from 'estree-jsx'
import type { Rule } from 'eslint'
export type StringableASTNode<NodeType extends BaseNode> = (
node: Omit<NodeType, 'type'>
) => NodeType & { __pragma: 'ecu'; toString(): string }
export type EslintCodemodUtilsBaseNode = BaseNode | JSXSpreadChild
export type EslintNode = Rule.NodeParentExtension & BaseNode
export type RuleListener<T extends EslintNode = EslintNode> = {
[E in T as E['type']]?: (eventNodeListener: E) => void
}
export type StringableASTNode<T extends EslintCodemodUtilsBaseNode> = T & {
// __pragma: 'ecu'
toString(): string
}
export type StringableASTNodeFn<
EstreeNodeType extends EslintCodemodUtilsBaseNode
> = (node: Omit<EstreeNodeType, 'type'>) => StringableASTNode<EstreeNodeType>
export type EslintNode = Rule.NodeParentExtension & EslintCodemodUtilsBaseNode
import { typeToHelperLookup } from '../constants'
import * as estree from 'estree'
import type { EslintCodemodUtilsBaseNode, StringableASTNode } from '../types'
type NodeMap = typeof typeToHelperLookup
type NodeType = keyof NodeMap
interface ESTreeNode {
type: NodeType
export type NodeMap<
T extends EslintCodemodUtilsBaseNode = EslintCodemodUtilsBaseNode
> = {
[E in T as E['type']]: (eventNodeListener: E) => StringableASTNode<E>
}
export const node = <
Node extends
| ESTreeNode
| estree.Expression
| estree.Statement
| estree.Pattern
>(
node: Node
): NodeMap[NodeType] => {
if (!node) {
return node
}
// @ts-expect-error
return typeToHelperLookup[node.type](node)
export const node = <EstreeNodeType extends EslintCodemodUtilsBaseNode>(
estNode: EstreeNodeType
): StringableASTNode<EstreeNodeType> => {
// @ts-ignore
return typeToHelperLookup[estNode.type](estNode)
}

@@ -1,5 +0,8 @@

import { JSXElement } from 'estree-jsx'
import type { EslintNode } from '../types'
import type { JSXElement, JSXIdentifier } from 'estree-jsx'
import type { EslintCodemodUtilsBaseNode, EslintNode } from '../types'
export function isNode<T extends EslintNode>(node: T, type: unknown): boolean {
export function isNode<
T extends EslintCodemodUtilsBaseNode,
K extends EslintCodemodUtilsBaseNode
>(node: T, type: K['type']) {
return node.type === type

@@ -12,3 +15,2 @@ }

): EslintNode | null {
console.info(node)
if (isNode(node, type)) {

@@ -34,1 +36,25 @@ return node

}
function isJSXIdentifier(node: JSXIdentifier, id: string) {
return node.name === id
}
export function hasJSXChild(
node: JSXElement,
childIdentifier: string
): boolean {
const jsxIdentifierMatch =
node.openingElement.name.type === 'JSXIdentifier' &&
node.openingElement.name.name &&
isJSXIdentifier(node.openingElement.name, childIdentifier)
return (
jsxIdentifierMatch ||
Boolean(
node.children &&
node.children
.filter((child): child is JSXElement => isNode(child, 'JSXElement'))
.find((child) => hasJSXChild(child, childIdentifier))
)
)
}
{
"name": "eslint-codemod-utils",
"version": "0.1.1",
"version": "0.1.2",
"description": "A collection of AST helper functions for more complex ESLint rule fixes.",

@@ -19,5 +19,2 @@ "source": "lib/index.ts",

"license": "ISC",
"dependencies": {
"eslint": "^8.9.0"
},
"devDependencies": {

@@ -24,0 +21,0 @@ "@types/eslint": "^8.4.1",

{
"extends": "../../tsconfig.json",
"include": [
"lib/**/*"
],
"include": ["lib/**/*"],
"compilerOptions": {
"outDir": "dist",
},
}
"outDir": "dist"
}
}
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc