Skip to content

Commit

Permalink
feature: putout: migrate to Babel 8 (https://babeljs.io/docs/v8-migra…
Browse files Browse the repository at this point in the history
  • Loading branch information
coderaiser committed Aug 4, 2023
1 parent e43a0a3 commit a114f95
Show file tree
Hide file tree
Showing 54 changed files with 130 additions and 152 deletions.
4 changes: 2 additions & 2 deletions packages/babel-plugin-putout/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@
"tag": false,
"changelog": false,
"devDependencies": {
"@babel/core": "^7.12.3",
"@babel/eslint-plugin-development": "^7.14.5",
"@babel/core": "^8.0.0-alpha.1",
"@babel/eslint-plugin-development": "^8.0.0-alpha.1",
"babel-plugin-transform-inline-consecutive-adds": "^0.5.0-alpha.9",
"c8": "^8.0.0",
"eslint": "^8.0.1",
Expand Down
4 changes: 2 additions & 2 deletions packages/babel-plugin-putout/test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ const test = require('supertape');

const {
transformFileSync,
createConfigItem,
createConfigItemSync,
} = require('@babel/core');

const plugin = require('..');
Expand All @@ -26,7 +26,7 @@ for (const caseName of fs.readdirSync(fixturesDir)) {

const {code} = transformFileSync(actualPath, {
code: true,
plugins: ['transform-inline-consecutive-adds', createConfigItem([plugin, {
plugins: ['transform-inline-consecutive-adds', createConfigItemSync([plugin, {
rules: {
'strict-mode': 'on',
},
Expand Down
3 changes: 2 additions & 1 deletion packages/compare/lib/comparators.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,13 @@ const {
isLinkedRegExp,
} = require('./is');

const {types} = require('@putout/babel');
const {
isClassBody,
isBlock,
isJSXText,
isTemplateElement,
} = require('@babel/types');
} = types;

const isEmptyBlock = (a) => isBlock(a) && !a.body.length;
const isPrimitive = (a) => typeof a !== 'object' || a === null;
Expand Down
12 changes: 6 additions & 6 deletions packages/compare/lib/compare.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,7 @@
'use strict';

const {template} = require('@putout/engine-parser');

const {
isIdentifier,
isExpressionStatement,
isStringLiteral,
} = require('@babel/types');
const {types} = require('@putout/babel');

const {
findVarsWays,
Expand All @@ -31,6 +26,11 @@ const {
parseTemplate,
} = require('./is');

const {
isIdentifier,
isExpressionStatement,
isStringLiteral,
} = types;
const {keys} = Object;
const {isArray} = Array;
const noop = () => {};
Expand Down
7 changes: 3 additions & 4 deletions packages/compare/lib/is.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
'use strict';

const {template} = require('@putout/engine-parser');

const {types} = require('@putout/babel');
const {
isBlockStatement,
isBooleanLiteral,
Expand All @@ -16,7 +16,7 @@ const {
isJSXIdentifier,
isJSXAttribute,
isTSTypeReference,
} = require('@babel/types');
} = types;

const isStr = (a) => typeof a === 'string';

Expand Down Expand Up @@ -275,9 +275,8 @@ module.exports.isLinkedNode = (a) => {
if (isTemplateElement(a) && LINKED_NODE.test(a.value.raw))
return true;

if (isTSTypeReference(a) && LINKED_NODE.test(a.typeName.name)) {
if (isTSTypeReference(a) && LINKED_NODE.test(a.typeName.name))
return true;
}

return isTSTypeParameter(a) && LINKED_NODE.test(a.name);
};
Expand Down
6 changes: 5 additions & 1 deletion packages/compare/lib/link.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
'use strict';

const {types} = require('@putout/babel');
const {
isIdentifier,
isLiteral,
isStringLiteral,
isTemplateElement,
isTSTypeReference,
} = require('@babel/types');
} = types;

const parseName = (node) => {
node = node[0] || node;
Expand Down Expand Up @@ -36,6 +37,9 @@ module.exports = ({add, value, nodeValue, templateStore}) => {
return true;
}

if (isTSTypeReference(templateStore[name]) && isIdentifier(nodeValue))
return true;

add(templateStore[name], nodeValue);

return true;
Expand Down
23 changes: 11 additions & 12 deletions packages/compare/lib/vars.js
Original file line number Diff line number Diff line change
@@ -1,21 +1,12 @@
'use strict';

const traverse = require('@babel/traverse').default;
const jessy = require('jessy');
const nessy = require('nessy');
const {traverse, types} = require('@putout/babel');
const {template} = require('@putout/engine-parser');

const {replaceWith, extract} = require('@putout/operate');

const {
isIdentifier,
isStatement,
isJSXElement,
isLiteral,
isTemplateLiteral,
TemplateElement,
} = require('@babel/types');

const {
is,
isArgsStr,
Expand All @@ -25,6 +16,14 @@ const {
isInsideTypeReference,
} = require('./is');

const {
isIdentifier,
isStatement,
isJSXElement,
isLiteral,
isTemplateLiteral,
TemplateElement,
} = types;
const {entries} = Object;
const isNumber = (a) => typeof a === 'number';
const isString = (a) => typeof a === 'string';
Expand Down Expand Up @@ -62,11 +61,11 @@ function findVarsWays(node) {
traverse(node, {
noScope: true,
'Identifier|BooleanLiteral|StringLiteral|TemplateElement|RegExpLiteral|JSXText|JSXAttribute|TSTypeReference'(path) {
const {node} = path;

if (isInsideTypeReference(path))
return;

const {node} = path;

const way = [];
const name = extract(node);

Expand Down
3 changes: 1 addition & 2 deletions packages/compare/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,7 @@
"report": "madrun report"
},
"dependencies": {
"@babel/traverse": "^7.12.5",
"@babel/types": "^7.12.6",
"@putout/babel": "^1.0.5",
"@putout/engine-parser": "^7.0.0",
"@putout/operate": "^9.0.0",
"debug": "^4.1.1",
Expand Down
1 change: 0 additions & 1 deletion packages/compare/test/compare.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ const test = require('supertape');
const montag = require('montag');

const {template, parse} = require('@putout/engine-parser');

const {traverse, types} = require('putout');

const {
Expand Down
7 changes: 4 additions & 3 deletions packages/engine-loader/lib/transforms/babel.js
Original file line number Diff line number Diff line change
@@ -1,20 +1,21 @@
'use strict';

const {
createConfigItem,
createConfigItemSync,
transformFromAstSync,
} = require('@babel/core');

const isString = (a) => typeof a === 'string';

module.exports = (ast, code, name) => {
const plugin = !isString(name) ? name : require(name);
// globally installed modules support
const configItem = createConfigItemSync(plugin);

transformFromAstSync(ast, code, {
cloneInputAst: false,
plugins: [
// globally installed modules support
createConfigItem(plugin),
configItem,
],
});

Expand Down
2 changes: 1 addition & 1 deletion packages/engine-loader/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
"report": "madrun report"
},
"dependencies": {
"@babel/core": "^7.12.3",
"@babel/core": "^8.0.0-alpha.1",
"@putout/engine-parser": "^7.1.0",
"diff-match-patch": "^1.0.4",
"nano-memoize": "^3.0.11",
Expand Down
2 changes: 1 addition & 1 deletion packages/engine-parser/lib/generate.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
'use strict';

const generate = require('@babel/generator').default;
const {generate} = require('@putout/babel');

module.exports = (node, options, sourceMaps) => {
return generate(node, {
Expand Down
2 changes: 1 addition & 1 deletion packages/engine-parser/lib/parsers/babel/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ const plugins = require('./plugins');
const options = require('./options');
const getFlow = (a) => !a.indexOf('// @flow');
const clean = (a) => a.filter(Boolean);
const initBabel = once(() => require('@babel/parser'));
const initBabel = once(() => require('@putout/babel'));
const {assign} = Object;

// There is a difference in options naming for babel and recast
Expand Down
2 changes: 1 addition & 1 deletion packages/engine-parser/lib/print.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

const recast = require('@putout/recast');
const putoutPrinter = require('@putout/printer');
const generate = require('@babel/generator').default;
const {generate} = require('@putout/babel');

const {stringify} = JSON;
const {isArray} = Array;
Expand Down
3 changes: 2 additions & 1 deletion packages/engine-parser/lib/recast/move-out-directives.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
'use strict';

const {types} = require('@putout/babel');
const {
StringLiteral,
ExpressionStatement,
} = require('@babel/types');
} = types;

const {assign} = Object;

Expand Down
2 changes: 1 addition & 1 deletion packages/engine-parser/lib/template.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
'use strict';

const template = require('@babel/template').default;
const {template} = require('@putout/babel');
const {nanomemoize} = require('nano-memoize');
const plugins = require('./parsers/babel/plugins');
const options = require('./parsers/babel/options');
Expand Down
6 changes: 3 additions & 3 deletions packages/engine-parser/lib/template.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@

const tryCatch = require('try-catch');
const test = require('supertape');

const {Identifier, StringLiteral} = require('@babel/types');

const {types} = require('@putout/babel');
const template = require('./template');

const {Identifier, StringLiteral} = types;

test('parser: template', (t) => {
const buildOnce = template(`await once(%%emitter%%, %%event%%)`);

Expand Down
5 changes: 1 addition & 4 deletions packages/engine-parser/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,7 @@
"report": "madrun report"
},
"dependencies": {
"@babel/generator": "^7.19.0",
"@babel/parser": "^7.19.0",
"@babel/template": "^7.18.10",
"@babel/types": "^7.19.0",
"@putout/babel": "^1.0.4",
"@putout/printer": "^2.0.0",
"@putout/recast": "^1.12.1",
"estree-to-babel": "^6.0.0",
Expand Down
2 changes: 1 addition & 1 deletion packages/engine-runner/lib/index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
'use strict';

const traverse = require('@babel/traverse').default;
const {traverse} = require('@putout/babel');
const once = require('once');
const debug = require('debug')('putout:runner:find');

Expand Down
2 changes: 1 addition & 1 deletion packages/engine-runner/lib/merge-visitors.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
'use strict';

const traverse = require('@babel/traverse').default;
const {traverse} = require('@putout/babel');
const {generate} = require('@putout/engine-parser');

const runFix = require('./run-fix');
Expand Down
12 changes: 7 additions & 5 deletions packages/engine-runner/lib/replace/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,7 @@

const {template, print} = require('@putout/engine-parser');
const {remove, replaceWith} = require('@putout/operate');
const {
isExpression,
isStatement,
isExpressionStatement,
} = require('@babel/types');
const {types} = require('@putout/babel');

const {
compare,
Expand All @@ -19,6 +15,12 @@ const debug = require('debug')('putout:runner:replace');
const maybeArray = require('../maybe-array');

const watermark = require('./watermark');
const {
isExpression,
isStatement,
isExpressionStatement,
} = types;

const PRINT_OPTIONS = {
printer: ['putout', {
format: {
Expand Down
5 changes: 2 additions & 3 deletions packages/engine-runner/lib/replace/watermark.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
'use strict';

const {isProgram} = require('@babel/types');
const wraptile = require('wraptile');

const findPath = require('./find-path');

const {types} = require('@putout/babel');
const {isProgram} = types;
const name = '__putout_runner_replace';
const hasWatermark = (watermark) => (path) => path.node?.[name]?.has(watermark);

Expand Down
3 changes: 1 addition & 2 deletions packages/engine-runner/lib/super-find.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
'use strict';

const babelTraverse = require('@babel/traverse').default;
const {types} = require('@babel/types');
const {traverse: babelTraverse, types} = require('@putout/babel');

const {generate} = require('@putout/engine-parser');
const {merge} = babelTraverse.visitors;
Expand Down
3 changes: 1 addition & 2 deletions packages/engine-runner/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,7 @@
"report": "madrun report"
},
"dependencies": {
"@babel/traverse": "^7.12.7",
"@babel/types": "^7.12.7",
"@putout/babel": "^1.0.5",
"@putout/compare": "^11.0.0",
"@putout/engine-parser": "^7.0.0",
"@putout/operate": "^9.0.0",
Expand Down
1 change: 0 additions & 1 deletion packages/eslint-plugin-putout/lib/markdown.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ const parserOptions = {
...parserPlugins,
],
},
plugins: ['@babel/plugin-syntax-class-properties'],
},
};

Expand Down
Loading

0 comments on commit a114f95

Please sign in to comment.