Skip to content

Commit ecf87f8

Browse files
committed
feature: @putout/plugin-putout: apply-lowercase-to-node-builders: add (babel/babel#17129)
1 parent 8622b32 commit ecf87f8

File tree

113 files changed

+595
-522
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

113 files changed

+595
-522
lines changed

codemods/apply-replace-all/lib/apply-replace-all.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import {types, operator} from 'putout';
22

33
const {replaceWith} = operator;
4-
const {RegExpLiteral} = types;
4+
const {regExpLiteral} = types;
55

66
export const report = () => `Replace regexp should be used instead of string`;
77

@@ -11,7 +11,7 @@ export const replace = () => ({
1111
const raw = `/${escape(value)}/g`;
1212

1313
const regexp = {
14-
...RegExpLiteral(escape(value), 'g'),
14+
...regExpLiteral(escape(value), 'g'),
1515
raw,
1616
extra: {
1717
raw,

codemods/madrun/lib/add-fresh-lint/index.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import getProperty from '../get-property.js';
77

88
const {replaceWithMultiple} = operator;
99

10-
const {ObjectProperty, StringLiteral} = types;
10+
const {objectProperty, stringLiteral} = types;
1111

1212
const freshLintScript = template.ast(`
1313
() => run('lint', '--fresh')
@@ -16,7 +16,7 @@ const freshLintScript = template.ast(`
1616
export const report = () => `fresh:lint should exist`;
1717

1818
export const fix = (path) => {
19-
replaceWithMultiple(path, [path.node, ObjectProperty(StringLiteral('fresh:lint'), freshLintScript), ObjectProperty(StringLiteral('lint:fresh'), freshLintScript)]);
19+
replaceWithMultiple(path, [path.node, objectProperty(stringLiteral('fresh:lint'), freshLintScript), objectProperty(stringLiteral('lint:fresh'), freshLintScript)]);
2020
};
2121

2222
export const traverse = ({push}) => ({

codemods/set-commit-type/lib/set-commit-type.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import {types, operator} from 'putout';
22

3-
const {StringLiteral, ObjectProperty} = types;
3+
const {objectProperty, stringLiteral} = types;
44

55
const {
66
getProperties,
@@ -30,6 +30,6 @@ export const traverse = ({push}) => ({
3030
});
3131

3232
export const fix = ({mainPath}) => {
33-
const commitTypeNode = ObjectProperty(StringLiteral('commitType'), StringLiteral('colon'));
33+
const commitTypeNode = objectProperty(stringLiteral('commitType'), stringLiteral('colon'));
3434
insertAfter(mainPath, commitTypeNode);
3535
};

packages/engine-runner/test/replace.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -488,10 +488,10 @@ test('putout: runner: replace: watermark: when function used', (t) => {
488488
489489
const {types: types} = require('putout');
490490
const {template: template} = require('putout');
491-
const {NumericLiteral} = types;
491+
const {numericLiteral} = types;
492492
493493
template('hello');
494-
NumericLiteral(5);
494+
numericLiteral(5);
495495
496496
`;
497497

packages/operator-filesystem/lib/filesystem.js

Lines changed: 15 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
'use strict';
22

33
const {join, basename} = require('node:path');
4-
const tryCatch = require('try-catch');
54
const {types} = require('@putout/babel');
5+
const tryCatch = require('try-catch');
66

77
const {
88
setLiteralValue,
@@ -11,7 +11,13 @@ const {
1111
} = require('@putout/operate');
1212

1313
const maybeFS = require('./maybe-fs');
14-
14+
const {
15+
arrayExpression,
16+
stringLiteral,
17+
objectProperty,
18+
isProgram,
19+
objectExpression,
20+
} = types;
1521
const isString = (a) => typeof a === 'string';
1622
const {isArray} = Array;
1723
const maybeArray = (a) => isArray(a) ? a : [a];
@@ -34,14 +40,6 @@ const fromBase64 = (content) => {
3440
return content;
3541
};
3642

37-
const {
38-
ObjectExpression,
39-
ArrayExpression,
40-
StringLiteral,
41-
ObjectProperty,
42-
isProgram,
43-
} = types;
44-
4543
const getRegExp = (wildcard) => {
4644
const escaped = wildcard
4745
.replace(/\./g, '\\.')
@@ -198,7 +196,7 @@ module.exports.copyFile = (filePath, dirPath) => {
198196
const newFilename = join(dirname, basename);
199197
const [hasContent, content] = getFileContent(filePath);
200198

201-
const copiedFile = ObjectExpression([
199+
const copiedFile = objectExpression([
202200
createTypeProperty('file'),
203201
createFilenameProperty(newFilename),
204202
hasContent && createContentProperty(content),
@@ -230,19 +228,19 @@ function maybeRemoveFile(dirPath, filename) {
230228
fileToOverwrite.remove();
231229
}
232230

233-
const createTypeProperty = (type) => ObjectProperty(StringLiteral('type'), StringLiteral(type));
231+
const createTypeProperty = (type) => objectProperty(stringLiteral('type'), stringLiteral(type));
234232

235233
module.exports.createTypeProperty = createTypeProperty;
236234

237-
const createFilesProperty = (files) => ObjectProperty(StringLiteral('files'), ArrayExpression(files));
235+
const createFilesProperty = (files) => objectProperty(stringLiteral('files'), arrayExpression(files));
238236

239237
module.exports.createFilesProperty = createFilesProperty;
240238

241-
const createFilenameProperty = (filename) => ObjectProperty(StringLiteral('filename'), StringLiteral(filename));
239+
const createFilenameProperty = (filename) => objectProperty(stringLiteral('filename'), stringLiteral(filename));
242240

243241
module.exports.createFilenameProperty = createFilenameProperty;
244242

245-
const createContentProperty = (content) => ObjectProperty(StringLiteral('content'), StringLiteral(content));
243+
const createContentProperty = (content) => objectProperty(stringLiteral('content'), stringLiteral(content));
246244

247245
module.exports.createContentProperty = createContentProperty;
248246

@@ -262,7 +260,7 @@ module.exports.createFile = (dirPath, name, content) => {
262260
content && createContentProperty(content),
263261
].filter(Boolean);
264262

265-
dirPathFiles.node.value.elements.push(ObjectExpression(properties));
263+
dirPathFiles.node.value.elements.push(objectExpression(properties));
266264

267265
const filePath = dirPathFiles.get('value.elements').at(-1);
268266

@@ -283,7 +281,7 @@ module.exports.createDirectory = (dirPath, name) => {
283281
const filesProperty = createFilesProperty([]);
284282
const filenameProperty = createFilenameProperty(filename);
285283

286-
dirPathFiles.node.value.elements.push(ObjectExpression([
284+
dirPathFiles.node.value.elements.push(objectExpression([
287285
typeProperty,
288286
filenameProperty,
289287
filesProperty,

packages/operator-match-files/lib/match-files.spec.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
'use strict';
22

3+
const {types} = require('@putout/babel');
34
const tryCatch = require('try-catch');
45
const test = require('supertape');
56
const putout = require('putout');
6-
const {types} = require('@putout/babel');
7+
78
const convertEsmToCommonjs = require('@putout/plugin-nodejs/convert-esm-to-commonjs');
89

910
const {
@@ -19,7 +20,7 @@ const {
1920
} = require('@putout/operator-filesystem');
2021

2122
const {matchFiles} = require('./match-files.js');
22-
const {ObjectProperty, StringLiteral} = types;
23+
const {stringLiteral, objectProperty} = types;
2324

2425
const {
2526
parse,
@@ -78,7 +79,7 @@ test('putout: operator: match-files: transform', (t) => {
7879
const plugin = {
7980
report: () => 'hello',
8081
fix: (path) => {
81-
const property = ObjectProperty(StringLiteral('hello'), StringLiteral('world'));
82+
const property = objectProperty(stringLiteral('hello'), stringLiteral('world'));
8283

8384
path.node.properties.push(property);
8485
},

packages/plugin-apply-dot-notation/lib/apply-dot-notation.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33
const {types} = require('putout');
44
const {
55
isStringLiteral,
6-
Identifier,
76
isValidIdentifier,
7+
identifier,
88
} = types;
99

1010
module.exports.report = ({value}) => {
@@ -14,7 +14,7 @@ module.exports.report = ({value}) => {
1414
module.exports.fix = ({value, path}) => {
1515
const {node} = path;
1616

17-
node.property = Identifier(value);
17+
node.property = identifier(value);
1818
node.computed = false;
1919
};
2020

packages/plugin-apply-overrides/lib/apply-overrides.js

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,17 +5,16 @@ const {
55
operator,
66
template,
77
} = require('putout');
8-
9-
const {replaceWith} = operator;
108
const {
11-
Identifier,
12-
AssignmentPattern,
9+
returnStatement,
10+
blockStatement,
11+
identifier,
1312
isAssignmentPattern,
1413
isFunction,
15-
BlockStatement,
1614
isBlockStatement,
17-
ReturnStatement,
15+
assignmentPattern,
1816
} = types;
17+
const {replaceWith} = operator;
1918

2019
const createOverrides = template('const %%overrides%% = overrides');
2120

@@ -24,12 +23,12 @@ module.exports.fix = (path) => {
2423
const {node, parentPath} = path;
2524
const {right} = node;
2625

27-
replaceWith(path, AssignmentPattern(Identifier('overrides'), right));
26+
replaceWith(path, assignmentPattern(identifier('overrides'), right));
2827

2928
const {body} = parentPath.node;
3029

3130
if (!isBlockStatement(body))
32-
parentPath.node.body = BlockStatement([ReturnStatement(body)]);
31+
parentPath.node.body = blockStatement([returnStatement(body)]);
3332

3433
path.parentPath.node.body.body.unshift(createOverrides({
3534
overrides: node.left,

packages/plugin-conditions/lib/apply-consistent-blocks/index.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ const {types, operator} = require('putout');
44
const {replaceWith} = operator;
55
const {
66
isBlockStatement,
7-
BlockStatement,
87
isVariableDeclaration,
8+
blockStatement,
99
} = types;
1010

1111
module.exports.report = () => `Use consistent blocks`;
@@ -19,7 +19,7 @@ module.exports.fix = (path) => {
1919
continue;
2020

2121
const {node} = path;
22-
replaceWith(path, BlockStatement([node]));
22+
replaceWith(path, blockStatement([node]));
2323
}
2424
else
2525
for (const path of paths) {

packages/plugin-conditions/lib/convert-comparison-to-boolean/index.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,12 @@ const {types, operator} = require('putout');
44

55
const {replaceWith, compute} = operator;
66

7-
const {isIdentifier, BooleanLiteral} = types;
7+
const {isIdentifier, booleanLiteral} = types;
88

99
module.exports.report = () => 'Avoid constant conditions';
1010

1111
module.exports.fix = ({path, value}) => {
12-
replaceWith(path, BooleanLiteral(value));
12+
replaceWith(path, booleanLiteral(value));
1313
};
1414

1515
module.exports.traverse = ({push}) => ({

0 commit comments

Comments
 (0)