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 1.5.0 to 1.5.1

28

dist/cjs/__tests__/index.test.js

@@ -28,2 +28,30 @@ "use strict";

};
describe('literal', () => {
test('string', () => {
expect(String((0, __1.literal)('hello'))).eq('hello');
});
test('boolean', () => {
expect(String((0, __1.literal)(true))).eq(`true`);
});
test('null', () => {
expect(String((0, __1.literal)(null))).eq(`null`);
});
test('number', () => {
expect(String((0, __1.literal)(9))).eq(`9`);
});
});
describe('exportAllDeclaration', () => {
test('basic', () => {
expect(String((0, __1.exportAllDeclaration)({
exported: null,
source: (0, __1.literal)('@atlaskit/modal-dialog'),
}))).eq(`export * from '@atlaskit/modal-dialog'`);
});
test('with alias', () => {
expect(String((0, __1.exportAllDeclaration)({
exported: (0, __1.identifier)('modal'),
source: (0, __1.literal)('@atlaskit/modal-dialog'),
}))).eq(`export * as modal from '@atlaskit/modal-dialog'`);
});
});
describe('importDeclaration', () => {

@@ -30,0 +58,0 @@ test('basic', () => {

2

dist/cjs/__tests__/ts-node.test.js

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

// @ts-ignore
expression: (0, __1.literal)("'hello'"),
expression: (0, __1.literal)('hello'),
// @ts-ignore

@@ -35,0 +35,0 @@ typeAnnotation: (0, __1.literal)({ value: 'any' }),

@@ -64,4 +64,3 @@ "use strict";

ObjectPattern: nodes_1.objectPattern,
// TODO: needs implementation
RestElement: identity_1.identity,
RestElement: nodes_1.restElement,
MemberExpression: nodes_1.memberExpression,

@@ -98,3 +97,3 @@ // TODO: needs implementation

ReturnStatement: nodes_1.returnStatement,
Super: identity_1.identity,
Super: nodes_1.superCallExpression,
SequenceExpression: nodes_1.sequenceExpression,

@@ -117,2 +116,4 @@ SpreadElement: nodes_1.spreadElement,

TSTypeReference: ts_nodes_1.tsTypeReference,
TSAnyKeyword: ts_nodes_1.tsAnyKeyword,
TSNullKeyword: ts_nodes_1.tsNullKeyword,
}, {

@@ -119,0 +120,0 @@ // dynamic getter will fail and provide debug information

@@ -20,5 +20,41 @@ import type * as estree from 'estree-jsx';

export declare const jsxIdentifier: (param: WithoutType<estree.JSXIdentifier> | string) => StringableASTNode<estree.JSXIdentifier>;
/**
* __JSXOpeningFragment__
*
* @example
* ```ts
* <>hello</>
* ^^
* ```
*/
export declare const jsxOpeningFragment: StringableASTNodeFn<estree.JSXOpeningFragment>;
/**
* __JSXClosingFragment__
*
* @example
* ```ts
* <>hello</>
* ^^
* ```
*/
export declare const jsxClosingFragment: StringableASTNodeFn<estree.JSXClosingFragment>;
/**
* __JSXFragment__
*
* @example
* ```ts
* <>hello</>
* ^^^^^^^^^^
* ```
*/
export declare const jsxFragment: StringableASTNodeFn<estree.JSXFragment>;
/**
* __JSXSpreadChild__
*
* @example
* ```ts
* <>{...child}</>
* ^^^^^^^^^^
* ```
*/
export declare const jsxSpreadChild: StringableASTNodeFn<estree.JSXSpreadChild>;

@@ -72,3 +108,3 @@ export declare const jsxMemberExpression: StringableASTNodeFn<estree.JSXMemberExpression>;

*
* @returns {JSXSpreadAttribute}
* @returns {estree.JSXSpreadAttribute}
*/

@@ -88,3 +124,3 @@ export declare const jsxSpreadAttribute: StringableASTNodeFn<estree.JSXSpreadAttribute>;

*
* @returns {JSXClosingElement}
* @returns {estree.JSXClosingElement}
*/

@@ -103,3 +139,3 @@ export declare const jsxClosingElement: StringableASTNodeFn<estree.JSXClosingElement>;

*
* @returns {JSXText}
* @returns {estree.JSXText}
*/

@@ -120,2 +156,14 @@ export declare const jsxText: StringableASTNodeFn<estree.JSXText>;

export declare const jsxEmptyExpression: StringableASTNodeFn<estree.JSXEmptyExpression>;
/**
* __JSXExpressionContainer__
*
* @example
*
* ```tsx
* <SomeJSX attribute={someValue} />
* ^^^^^^^^^^^
* ```
*
* @returns {estree.JSXExpressionContainer}
*/
export declare const jsxExpressionContainer: StringableASTNodeFn<estree.JSXExpressionContainer>;

@@ -122,0 +170,0 @@ /**

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

exports.jsxIdentifier = jsxIdentifier;
/**
* __JSXOpeningFragment__
*
* @example
* ```ts
* <>hello</>
* ^^
* ```
*/
const jsxOpeningFragment = ({ ...other }) => {

@@ -45,2 +54,11 @@ return {

exports.jsxOpeningFragment = jsxOpeningFragment;
/**
* __JSXClosingFragment__
*
* @example
* ```ts
* <>hello</>
* ^^
* ```
*/
const jsxClosingFragment = ({ ...other }) => {

@@ -54,2 +72,11 @@ return {

exports.jsxClosingFragment = jsxClosingFragment;
/**
* __JSXFragment__
*
* @example
* ```ts
* <>hello</>
* ^^^^^^^^^^
* ```
*/
const jsxFragment = ({ openingFragment, closingFragment, children, ...other }) => ({

@@ -69,2 +96,11 @@ ...other,

exports.jsxFragment = jsxFragment;
/**
* __JSXSpreadChild__
*
* @example
* ```ts
* <>{...child}</>
* ^^^^^^^^^^
* ```
*/
const jsxSpreadChild = ({ expression, ...other }) => {

@@ -159,3 +195,3 @@ return {

*
* @returns {JSXSpreadAttribute}
* @returns {estree.JSXSpreadAttribute}
*/

@@ -179,14 +215,3 @@ const jsxSpreadAttribute = ({ argument }) => ({

name}${attributes && attributes.length
? ' ' +
attributes
.map((attr) => {
if ('__pragma' in attr) {
return attr;
}
else {
return (0, node_1.node)(attr);
}
})
.map(String)
.join(' ')
? ' ' + attributes.map(node_1.node).map(String).join(' ')
: ''}${selfClosing ? ' />' : '>'}`,

@@ -206,3 +231,3 @@ });

*
* @returns {JSXClosingElement}
* @returns {estree.JSXClosingElement}
*/

@@ -228,3 +253,3 @@ const jsxClosingElement = ({ name }) => {

*
* @returns {JSXText}
* @returns {estree.JSXText}
*/

@@ -258,2 +283,14 @@ const jsxText = ({ value, raw, }) => ({

exports.jsxEmptyExpression = jsxEmptyExpression;
/**
* __JSXExpressionContainer__
*
* @example
*
* ```tsx
* <SomeJSX attribute={someValue} />
* ^^^^^^^^^^^
* ```
*
* @returns {estree.JSXExpressionContainer}
*/
const jsxExpressionContainer = ({ expression }) => ({

@@ -291,10 +328,4 @@ expression,

value,
toString: () => `${name.name}${value
? `=${value.type === 'Literal'
? (0, node_1.node)(value)
: value.type === 'JSXElement'
? (0, exports.jsxElement)(value)
: (0, exports.jsxExpressionContainer)(value)}`
: ''}`,
toString: () => `${name.name}${value ? `=${(0, node_1.node)(value)}` : ''}`,
});
exports.jsxAttribute = jsxAttribute;

@@ -21,5 +21,20 @@ import type * as estree from 'estree-jsx';

*
* @returns {CallExpression}
* @returns {estree.CallExpression}
*/
export declare const callExpression: StringableASTNodeFn<estree.SimpleCallExpression>;
/**
* __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>;

@@ -177,5 +192,57 @@ /**

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>;

@@ -237,2 +304,20 @@ export declare const exportSpecifier: StringableASTNodeFn<estree.ExportSpecifier>;

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>;
export declare const objectExpression: StringableASTNodeFn<estree.ObjectExpression>;

@@ -239,0 +324,0 @@ export declare const emptyStatement: StringableASTNodeFn<estree.EmptyStatement>;

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.templateLiteral = exports.switchStatement = exports.switchCase = exports.whileStatement = exports.doWhileStatement = exports.identifier = exports.literal = exports.regExpLiteral = exports.bigIntLiteral = exports.importDeclaration = exports.templateElement = exports.importNamespaceSpecifier = exports.variableDeclaration = exports.variableDeclarator = exports.logicalExpression = exports.memberExpression = exports.emptyStatement = exports.objectExpression = exports.spreadElement = exports.objectPattern = exports.property = exports.newExpression = exports.expressionStatement = exports.updateExpression = exports.arrayPattern = exports.arrayExpression = exports.yieldExpression = exports.importSpecifier = exports.exportSpecifier = exports.exportAllDeclaration = exports.exportDefaultDeclaration = exports.exportNamedDeclaration = exports.importDefaultSpecifier = exports.importExpression = exports.withStatement = exports.tryStatement = exports.catchClause = exports.ifStatement = exports.thisExpression = exports.unaryExpression = exports.throwStatement = exports.returnStatement = exports.blockStatement = exports.functionExpression = exports.taggedTemplateExpression = exports.arrowFunctionExpression = exports.sequenceExpression = exports.binaryExpression = exports.chainExpression = exports.callExpression = void 0;
exports.program = exports.classExpression = exports.classDeclaration = exports.classBody = exports.propertyDefinition = exports.methodDefinition = exports.methodOrPropertyFn = exports.functionDeclaration = exports.staticBlock = exports.awaitExpression = exports.assignmentExpression = exports.conditionalExpression = exports.debuggerStatement = exports.breakStatement = exports.continueStatement = exports.forOfStatement = exports.forInStatement = exports.forStatement = void 0;
exports.switchCase = exports.whileStatement = exports.doWhileStatement = exports.identifier = exports.literal = exports.regExpLiteral = exports.bigIntLiteral = exports.importDeclaration = exports.templateElement = exports.importNamespaceSpecifier = exports.variableDeclaration = exports.variableDeclarator = exports.logicalExpression = exports.memberExpression = exports.emptyStatement = exports.objectExpression = exports.restElement = exports.spreadElement = exports.objectPattern = exports.property = exports.newExpression = exports.expressionStatement = exports.updateExpression = exports.arrayPattern = exports.arrayExpression = exports.yieldExpression = exports.importSpecifier = exports.exportSpecifier = exports.exportAllDeclaration = exports.exportDefaultDeclaration = exports.exportNamedDeclaration = exports.importDefaultSpecifier = exports.importExpression = exports.withStatement = exports.tryStatement = exports.catchClause = exports.ifStatement = exports.thisExpression = exports.unaryExpression = exports.throwStatement = exports.returnStatement = exports.blockStatement = exports.functionExpression = exports.taggedTemplateExpression = exports.arrowFunctionExpression = exports.sequenceExpression = exports.binaryExpression = exports.chainExpression = exports.superCallExpression = exports.callExpression = void 0;
exports.program = exports.classExpression = exports.classDeclaration = exports.classBody = exports.propertyDefinition = exports.methodDefinition = exports.methodOrPropertyFn = exports.functionDeclaration = exports.staticBlock = exports.awaitExpression = exports.assignmentExpression = exports.conditionalExpression = exports.debuggerStatement = exports.breakStatement = exports.continueStatement = exports.forOfStatement = exports.forInStatement = exports.forStatement = exports.templateLiteral = exports.switchStatement = void 0;
const node_1 = require("./utils/node");

@@ -25,3 +25,3 @@ const constants_1 = require("./constants");

*
* @returns {CallExpression}
* @returns {estree.CallExpression}
*/

@@ -35,6 +35,30 @@ const callExpression = ({ arguments: calleeArgs, callee, optional, ...other }) => {

type: 'CallExpression',
toString: () => `${callee.type === 'Super' ? 'super' : (0, node_1.node)(callee)}${optional ? '?.' : ''}(${calleeArgs.map(node_1.node).join(', ')})`,
toString: () => `${(0, node_1.node)(callee)}${optional ? '?.' : ''}(${calleeArgs
.map(node_1.node)
.join(', ')})`,
};
};
exports.callExpression = callExpression;
/**
* __Super__
*
* @example
*
* ```
* // note the whole expression is a `CallExpression`
* // super is simply the callee / identifier
* super()
* ^^^^^
* ```
*
* @returns {estree.Super}
*/
const superCallExpression = ({ ...other }) => {
return {
...other,
type: 'Super',
toString: () => `super`,
};
};
exports.superCallExpression = superCallExpression;
const chainExpression = ({ expression, ...other }) => {

@@ -342,2 +366,14 @@ return {

exports.importExpression = importExpression;
/**
* __ImportDefaultSpecifier__
*
* @example
*
* ```ts
* import Hello from 'world'
* ^^^^^
* ```
*
* @returns {estree.ImportDefaultSpecifier}
*/
const importDefaultSpecifier = ({ local, ...other }) => ({

@@ -350,2 +386,14 @@ ...other,

exports.importDefaultSpecifier = importDefaultSpecifier;
/**
* __ExportNamedDeclaration__
*
* @example
*
* ```ts
* export { Hello } from 'world'
* ^^^^^^^^^^^^^^^^
* ```
*
* @returns {estree.ExportNamedDeclaration}
*/
const exportNamedDeclaration = ({ declaration, specifiers, source, ...other }) => {

@@ -364,2 +412,14 @@ return {

exports.exportNamedDeclaration = exportNamedDeclaration;
/**
* __ExportDefaultDeclaration__
*
* @example
*
* ```ts
* export default HelloWorld
* ^^^^^^^^^^^^^^^^^^^^^^^^^
* ```
*
* @returns {estree.ExportDefaultDeclaration}
*/
const exportDefaultDeclaration = ({ declaration, ...other }) => {

@@ -374,3 +434,19 @@ return {

exports.exportDefaultDeclaration = exportDefaultDeclaration;
const exportAllDeclaration = ({ source, ...other }) => {
/**
* __ExportAllDeclaration__
*
* @example
*
* ```ts
* export * from 'world'
* ^^^^^^^^^^^^^^^^^^^^^^^^^
* ```
* ```ts
* export * as Hello from 'world'
* ^^^^^^^^^^^^^^^^^^^^^^^^^
* ```
*
* @returns {estree.ExportAllDeclaration}
*/
const exportAllDeclaration = ({ source, exported, ...other }) => {
return {

@@ -380,3 +456,4 @@ ...other,

source,
toString: () => `export * from ${(0, node_1.node)(source)}`,
exported,
toString: () => `export * ${exported ? `as ${(0, node_1.node)(exported)} ` : ''}from ${(0, node_1.node)(source)}`,
};

@@ -545,2 +622,28 @@ };

exports.spreadElement = spreadElement;
/**
* __RestElement__
*
* @example
* ```ts
* const [a, ...b] = c
* ^^^^
* ```
*
* * @example
* ```ts
* const { a, ...b } = c
* ^^^^
* ```
*
* @returns {estree.RestElement}
*/
const restElement = ({ argument, ...other }) => {
return {
...other,
argument,
type: 'RestElement',
toString: () => `...${(0, node_1.node)(argument)}`,
};
};
exports.restElement = restElement;
const objectExpression = ({ properties, ...other }) => {

@@ -678,6 +781,5 @@ return {

typeof n === 'number' ||
typeof n === 'undefined' ||
n === null) {
return {
raw: String(n),
raw: typeof n === 'string' ? `\'${n}\'` : String(n),
value: n,

@@ -684,0 +786,0 @@ type: 'Literal',

@@ -1,2 +0,2 @@

import { TSAnyKeyword, TSAsExpression, TSStringKeyword, TSTypeReference } from '@typescript-eslint/types/dist/generated/ast-spec';
import { TSAnyKeyword, TSAsExpression, TSNullKeyword, TSStringKeyword, TSTypeReference } from '@typescript-eslint/types/dist/generated/ast-spec';
import type { StringableASTNodeFn } from './types';

@@ -53,1 +53,13 @@ /**

export declare const tsTypeReference: StringableASTNodeFn<TSTypeReference>;
/**
* __TSNullKeyword__
*
* @example
* ```ts
* const x = 'hello' as null
* ^^^^
* ```
*
* @returns {TSNullKeyword}
*/
export declare const tsNullKeyword: StringableASTNodeFn<TSNullKeyword>;
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.tsTypeReference = exports.tsAnyKeyword = exports.tsStringKeyword = exports.tsAsExpression = void 0;
exports.tsNullKeyword = exports.tsTypeReference = exports.tsAnyKeyword = exports.tsStringKeyword = exports.tsAsExpression = void 0;
const ast_spec_1 = require("@typescript-eslint/types/dist/generated/ast-spec");

@@ -88,1 +88,20 @@ const node_1 = require("./utils/node");

exports.tsTypeReference = tsTypeReference;
/**
* __TSNullKeyword__
*
* @example
* ```ts
* const x = 'hello' as null
* ^^^^
* ```
*
* @returns {TSNullKeyword}
*/
const tsNullKeyword = ({ ...other }) => {
return {
...other,
type: ast_spec_1.AST_NODE_TYPES.TSNullKeyword,
toString: () => `null`,
};
};
exports.tsNullKeyword = tsNullKeyword;
import type { EslintNode } from '../types';
/**
* Traverses the node's parents until the specified `type` is found. If no `type` is found
* in the traversal it will return `null`.
*/
export declare function closestOfType<NodeType extends EslintNode['type']>(node: EslintNode, type: NodeType): Extract<EslintNode, {
type: NodeType;
}> | null;

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

const is_node_of_type_1 = require("./is-node-of-type");
/**
* Traverses the node's parents until the specified `type` is found. If no `type` is found
* in the traversal it will return `null`.
*/
function closestOfType(node, type) {

@@ -7,0 +11,0 @@ if ((0, is_node_of_type_1.isNodeOfType)(node, type)) {

import type { EslintNode } from '../types';
/**
* Given a valid node return true if the node is of the specified type.
*
* This function uses the `is` assertion to resolve the correct TS type for the consumer.
*
* @return boolean
*/
export declare function isNodeOfType<T extends EslintNode, K extends T['type']>(node: EslintNode, type: K): node is Extract<EslintNode, {
type: K;
}>;
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.isNodeOfType = void 0;
/**
* Given a valid node return true if the node is of the specified type.
*
* This function uses the `is` assertion to resolve the correct TS type for the consumer.
*
* @return boolean
*/
function isNodeOfType(node, type) {

@@ -5,0 +12,0 @@ if (!(node && node['type'])) {

@@ -5,2 +5,11 @@ import type { EslintCodemodUtilsBaseNode, StringableASTNode } from '../types';

};
/**
* Internally focused function to help resolve / parse the AST. It hands off to the
* `typeToHelperLookup` map to apply the correct transformation.
*
* In theory this function can be applied to any valid esprima node blindly and
* it will correctly resolve to an `eslint-codemod-utils` stringable node.
*
* @internal
*/
export declare const node: <EstreeNodeType extends EslintCodemodUtilsBaseNode>(estNode: EstreeNodeType) => StringableASTNode<EstreeNodeType>;

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

const constants_1 = require("../constants");
/**
* Internally focused function to help resolve / parse the AST. It hands off to the
* `typeToHelperLookup` map to apply the correct transformation.
*
* In theory this function can be applied to any valid esprima node blindly and
* it will correctly resolve to an `eslint-codemod-utils` stringable node.
*
* @internal
*/
const node = (estNode) => {

@@ -7,0 +16,0 @@ // @ts-ignore

import { jsxAttribute, jsxClosingElement, jsxClosingFragment, jsxElement, jsxEmptyExpression, jsxExpressionContainer, jsxFragment, jsxIdentifier, jsxMemberExpression, jsxOpeningElement, jsxOpeningFragment, jsxSpreadAttribute, jsxSpreadChild, jsxText, } from './jsx-nodes';
import { arrayExpression, arrayPattern, arrowFunctionExpression, assignmentExpression, awaitExpression, binaryExpression, blockStatement, breakStatement, callExpression, catchClause, chainExpression, classBody, classDeclaration, classExpression, conditionalExpression, continueStatement, debuggerStatement, doWhileStatement, emptyStatement, exportAllDeclaration, exportDefaultDeclaration, exportNamedDeclaration, exportSpecifier, expressionStatement, forInStatement, forOfStatement, forStatement, functionDeclaration, functionExpression, identifier, ifStatement, importDeclaration, importDefaultSpecifier, importExpression, importNamespaceSpecifier, importSpecifier, literal, logicalExpression, memberExpression, methodDefinition, newExpression, objectExpression, objectPattern, program, property, propertyDefinition, returnStatement, sequenceExpression, spreadElement, staticBlock, switchCase, switchStatement, taggedTemplateExpression, templateElement, templateLiteral, thisExpression, throwStatement, tryStatement, unaryExpression, updateExpression, variableDeclaration, variableDeclarator, whileStatement, withStatement, yieldExpression, } from './nodes';
import { tsAsExpression, tsStringKeyword, tsTypeReference } from './ts-nodes';
import { arrayExpression, arrayPattern, arrowFunctionExpression, assignmentExpression, awaitExpression, binaryExpression, blockStatement, breakStatement, callExpression, catchClause, chainExpression, classBody, classDeclaration, classExpression, conditionalExpression, continueStatement, debuggerStatement, doWhileStatement, emptyStatement, exportAllDeclaration, exportDefaultDeclaration, exportNamedDeclaration, exportSpecifier, expressionStatement, forInStatement, forOfStatement, forStatement, functionDeclaration, functionExpression, identifier, ifStatement, importDeclaration, importDefaultSpecifier, importExpression, importNamespaceSpecifier, importSpecifier, literal, logicalExpression, memberExpression, methodDefinition, newExpression, objectExpression, objectPattern, program, property, propertyDefinition, restElement, returnStatement, sequenceExpression, spreadElement, staticBlock, superCallExpression, switchCase, switchStatement, taggedTemplateExpression, templateElement, templateLiteral, thisExpression, throwStatement, tryStatement, unaryExpression, updateExpression, variableDeclaration, variableDeclarator, whileStatement, withStatement, yieldExpression, } from './nodes';
import { tsAnyKeyword, tsAsExpression, tsNullKeyword, tsStringKeyword, tsTypeReference, } from './ts-nodes';
import { identity } from './utils/identity';

@@ -61,4 +61,3 @@ export const DEFAULT_WHITESPACE = '\n ';

ObjectPattern: objectPattern,
// TODO: needs implementation
RestElement: identity,
RestElement: restElement,
MemberExpression: memberExpression,

@@ -95,3 +94,3 @@ // TODO: needs implementation

ReturnStatement: returnStatement,
Super: identity,
Super: superCallExpression,
SequenceExpression: sequenceExpression,

@@ -114,2 +113,4 @@ SpreadElement: spreadElement,

TSTypeReference: tsTypeReference,
TSAnyKeyword: tsAnyKeyword,
TSNullKeyword: tsNullKeyword,
}, {

@@ -116,0 +117,0 @@ // dynamic getter will fail and provide debug information

@@ -20,5 +20,41 @@ import type * as estree from 'estree-jsx';

export declare const jsxIdentifier: (param: WithoutType<estree.JSXIdentifier> | string) => StringableASTNode<estree.JSXIdentifier>;
/**
* __JSXOpeningFragment__
*
* @example
* ```ts
* <>hello</>
* ^^
* ```
*/
export declare const jsxOpeningFragment: StringableASTNodeFn<estree.JSXOpeningFragment>;
/**
* __JSXClosingFragment__
*
* @example
* ```ts
* <>hello</>
* ^^
* ```
*/
export declare const jsxClosingFragment: StringableASTNodeFn<estree.JSXClosingFragment>;
/**
* __JSXFragment__
*
* @example
* ```ts
* <>hello</>
* ^^^^^^^^^^
* ```
*/
export declare const jsxFragment: StringableASTNodeFn<estree.JSXFragment>;
/**
* __JSXSpreadChild__
*
* @example
* ```ts
* <>{...child}</>
* ^^^^^^^^^^
* ```
*/
export declare const jsxSpreadChild: StringableASTNodeFn<estree.JSXSpreadChild>;

@@ -72,3 +108,3 @@ export declare const jsxMemberExpression: StringableASTNodeFn<estree.JSXMemberExpression>;

*
* @returns {JSXSpreadAttribute}
* @returns {estree.JSXSpreadAttribute}
*/

@@ -88,3 +124,3 @@ export declare const jsxSpreadAttribute: StringableASTNodeFn<estree.JSXSpreadAttribute>;

*
* @returns {JSXClosingElement}
* @returns {estree.JSXClosingElement}
*/

@@ -103,3 +139,3 @@ export declare const jsxClosingElement: StringableASTNodeFn<estree.JSXClosingElement>;

*
* @returns {JSXText}
* @returns {estree.JSXText}
*/

@@ -120,2 +156,14 @@ export declare const jsxText: StringableASTNodeFn<estree.JSXText>;

export declare const jsxEmptyExpression: StringableASTNodeFn<estree.JSXEmptyExpression>;
/**
* __JSXExpressionContainer__
*
* @example
*
* ```tsx
* <SomeJSX attribute={someValue} />
* ^^^^^^^^^^^
* ```
*
* @returns {estree.JSXExpressionContainer}
*/
export declare const jsxExpressionContainer: StringableASTNodeFn<estree.JSXExpressionContainer>;

@@ -122,0 +170,0 @@ /**

@@ -29,2 +29,11 @@ import { DEFAULT_WHITESPACE } from './constants';

};
/**
* __JSXOpeningFragment__
*
* @example
* ```ts
* <>hello</>
* ^^
* ```
*/
export const jsxOpeningFragment = ({ ...other }) => {

@@ -37,2 +46,11 @@ return {

};
/**
* __JSXClosingFragment__
*
* @example
* ```ts
* <>hello</>
* ^^
* ```
*/
export const jsxClosingFragment = ({ ...other }) => {

@@ -45,2 +63,11 @@ return {

};
/**
* __JSXFragment__
*
* @example
* ```ts
* <>hello</>
* ^^^^^^^^^^
* ```
*/
export const jsxFragment = ({ openingFragment, closingFragment, children, ...other }) => ({

@@ -59,2 +86,11 @@ ...other,

});
/**
* __JSXSpreadChild__
*
* @example
* ```ts
* <>{...child}</>
* ^^^^^^^^^^
* ```
*/
export const jsxSpreadChild = ({ expression, ...other }) => {

@@ -146,3 +182,3 @@ return {

*
* @returns {JSXSpreadAttribute}
* @returns {estree.JSXSpreadAttribute}
*/

@@ -165,14 +201,3 @@ export const jsxSpreadAttribute = ({ argument }) => ({

name}${attributes && attributes.length
? ' ' +
attributes
.map((attr) => {
if ('__pragma' in attr) {
return attr;
}
else {
return node(attr);
}
})
.map(String)
.join(' ')
? ' ' + attributes.map(node).map(String).join(' ')
: ''}${selfClosing ? ' />' : '>'}`,

@@ -191,3 +216,3 @@ });

*
* @returns {JSXClosingElement}
* @returns {estree.JSXClosingElement}
*/

@@ -212,3 +237,3 @@ export const jsxClosingElement = ({ name }) => {

*
* @returns {JSXText}
* @returns {estree.JSXText}
*/

@@ -240,2 +265,14 @@ export const jsxText = ({ value, raw, }) => ({

};
/**
* __JSXExpressionContainer__
*
* @example
*
* ```tsx
* <SomeJSX attribute={someValue} />
* ^^^^^^^^^^^
* ```
*
* @returns {estree.JSXExpressionContainer}
*/
export const jsxExpressionContainer = ({ expression }) => ({

@@ -272,9 +309,3 @@ expression,

value,
toString: () => `${name.name}${value
? `=${value.type === 'Literal'
? node(value)
: value.type === 'JSXElement'
? jsxElement(value)
: jsxExpressionContainer(value)}`
: ''}`,
toString: () => `${name.name}${value ? `=${node(value)}` : ''}`,
});

@@ -21,5 +21,20 @@ import type * as estree from 'estree-jsx';

*
* @returns {CallExpression}
* @returns {estree.CallExpression}
*/
export declare const callExpression: StringableASTNodeFn<estree.SimpleCallExpression>;
/**
* __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>;

@@ -177,5 +192,57 @@ /**

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>;

@@ -237,2 +304,20 @@ export declare const exportSpecifier: StringableASTNodeFn<estree.ExportSpecifier>;

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>;
export declare const objectExpression: StringableASTNodeFn<estree.ObjectExpression>;

@@ -239,0 +324,0 @@ export declare const emptyStatement: StringableASTNodeFn<estree.EmptyStatement>;

@@ -21,3 +21,3 @@ import { node } from './utils/node';

*
* @returns {CallExpression}
* @returns {estree.CallExpression}
*/

@@ -31,5 +31,28 @@ export const callExpression = ({ arguments: calleeArgs, callee, optional, ...other }) => {

type: 'CallExpression',
toString: () => `${callee.type === 'Super' ? 'super' : node(callee)}${optional ? '?.' : ''}(${calleeArgs.map(node).join(', ')})`,
toString: () => `${node(callee)}${optional ? '?.' : ''}(${calleeArgs
.map(node)
.join(', ')})`,
};
};
/**
* __Super__
*
* @example
*
* ```
* // note the whole expression is a `CallExpression`
* // super is simply the callee / identifier
* super()
* ^^^^^
* ```
*
* @returns {estree.Super}
*/
export const superCallExpression = ({ ...other }) => {
return {
...other,
type: 'Super',
toString: () => `super`,
};
};
export const chainExpression = ({ expression, ...other }) => {

@@ -321,2 +344,14 @@ return {

});
/**
* __ImportDefaultSpecifier__
*
* @example
*
* ```ts
* import Hello from 'world'
* ^^^^^
* ```
*
* @returns {estree.ImportDefaultSpecifier}
*/
export const importDefaultSpecifier = ({ local, ...other }) => ({

@@ -328,2 +363,14 @@ ...other,

});
/**
* __ExportNamedDeclaration__
*
* @example
*
* ```ts
* export { Hello } from 'world'
* ^^^^^^^^^^^^^^^^
* ```
*
* @returns {estree.ExportNamedDeclaration}
*/
export const exportNamedDeclaration = ({ declaration, specifiers, source, ...other }) => {

@@ -341,2 +388,14 @@ return {

};
/**
* __ExportDefaultDeclaration__
*
* @example
*
* ```ts
* export default HelloWorld
* ^^^^^^^^^^^^^^^^^^^^^^^^^
* ```
*
* @returns {estree.ExportDefaultDeclaration}
*/
export const exportDefaultDeclaration = ({ declaration, ...other }) => {

@@ -350,3 +409,19 @@ return {

};
export const exportAllDeclaration = ({ source, ...other }) => {
/**
* __ExportAllDeclaration__
*
* @example
*
* ```ts
* export * from 'world'
* ^^^^^^^^^^^^^^^^^^^^^^^^^
* ```
* ```ts
* export * as Hello from 'world'
* ^^^^^^^^^^^^^^^^^^^^^^^^^
* ```
*
* @returns {estree.ExportAllDeclaration}
*/
export const exportAllDeclaration = ({ source, exported, ...other }) => {
return {

@@ -356,3 +431,4 @@ ...other,

source,
toString: () => `export * from ${node(source)}`,
exported,
toString: () => `export * ${exported ? `as ${node(exported)} ` : ''}from ${node(source)}`,
};

@@ -509,2 +585,27 @@ };

};
/**
* __RestElement__
*
* @example
* ```ts
* const [a, ...b] = c
* ^^^^
* ```
*
* * @example
* ```ts
* const { a, ...b } = c
* ^^^^
* ```
*
* @returns {estree.RestElement}
*/
export const restElement = ({ argument, ...other }) => {
return {
...other,
argument,
type: 'RestElement',
toString: () => `...${node(argument)}`,
};
};
export const objectExpression = ({ properties, ...other }) => {

@@ -631,6 +732,5 @@ return {

typeof n === 'number' ||
typeof n === 'undefined' ||
n === null) {
return {
raw: String(n),
raw: typeof n === 'string' ? `\'${n}\'` : String(n),
value: n,

@@ -637,0 +737,0 @@ type: 'Literal',

@@ -1,2 +0,2 @@

import { TSAnyKeyword, TSAsExpression, TSStringKeyword, TSTypeReference } from '@typescript-eslint/types/dist/generated/ast-spec';
import { TSAnyKeyword, TSAsExpression, TSNullKeyword, TSStringKeyword, TSTypeReference } from '@typescript-eslint/types/dist/generated/ast-spec';
import type { StringableASTNodeFn } from './types';

@@ -53,1 +53,13 @@ /**

export declare const tsTypeReference: StringableASTNodeFn<TSTypeReference>;
/**
* __TSNullKeyword__
*
* @example
* ```ts
* const x = 'hello' as null
* ^^^^
* ```
*
* @returns {TSNullKeyword}
*/
export declare const tsNullKeyword: StringableASTNodeFn<TSNullKeyword>;

@@ -81,1 +81,19 @@ import { AST_NODE_TYPES, } from '@typescript-eslint/types/dist/generated/ast-spec';

};
/**
* __TSNullKeyword__
*
* @example
* ```ts
* const x = 'hello' as null
* ^^^^
* ```
*
* @returns {TSNullKeyword}
*/
export const tsNullKeyword = ({ ...other }) => {
return {
...other,
type: AST_NODE_TYPES.TSNullKeyword,
toString: () => `null`,
};
};
import type { EslintNode } from '../types';
/**
* Traverses the node's parents until the specified `type` is found. If no `type` is found
* in the traversal it will return `null`.
*/
export declare function closestOfType<NodeType extends EslintNode['type']>(node: EslintNode, type: NodeType): Extract<EslintNode, {
type: NodeType;
}> | null;
import { isNodeOfType } from './is-node-of-type';
/**
* Traverses the node's parents until the specified `type` is found. If no `type` is found
* in the traversal it will return `null`.
*/
export function closestOfType(node, type) {

@@ -3,0 +7,0 @@ if (isNodeOfType(node, type)) {

import type { EslintNode } from '../types';
/**
* Given a valid node return true if the node is of the specified type.
*
* This function uses the `is` assertion to resolve the correct TS type for the consumer.
*
* @return boolean
*/
export declare function isNodeOfType<T extends EslintNode, K extends T['type']>(node: EslintNode, type: K): node is Extract<EslintNode, {
type: K;
}>;

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

/**
* Given a valid node return true if the node is of the specified type.
*
* This function uses the `is` assertion to resolve the correct TS type for the consumer.
*
* @return boolean
*/
export function isNodeOfType(node, type) {

@@ -2,0 +9,0 @@ if (!(node && node['type'])) {

@@ -5,2 +5,11 @@ import type { EslintCodemodUtilsBaseNode, StringableASTNode } from '../types';

};
/**
* Internally focused function to help resolve / parse the AST. It hands off to the
* `typeToHelperLookup` map to apply the correct transformation.
*
* In theory this function can be applied to any valid esprima node blindly and
* it will correctly resolve to an `eslint-codemod-utils` stringable node.
*
* @internal
*/
export declare const node: <EstreeNodeType extends EslintCodemodUtilsBaseNode>(estNode: EstreeNodeType) => StringableASTNode<EstreeNodeType>;
import { typeToHelperLookup } from '../constants';
/**
* Internally focused function to help resolve / parse the AST. It hands off to the
* `typeToHelperLookup` map to apply the correct transformation.
*
* In theory this function can be applied to any valid esprima node blindly and
* it will correctly resolve to an `eslint-codemod-utils` stringable node.
*
* @internal
*/
export const node = (estNode) => {

@@ -3,0 +12,0 @@ // @ts-ignore

{
"name": "eslint-codemod-utils",
"version": "1.5.0",
"version": "1.5.1",
"description": "A collection of AST helper functions for more complex ESLint rule fixes.",

@@ -5,0 +5,0 @@ "author": "Alex Hinds",

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