@putout/bundle 1.1.6 → 1.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -34,7 +34,7 @@ import pluginPutout from 'https://esm.sh/@putout/bundle/plugin-putout';
34
34
 
35
35
  console.log(putout('compare(a, b)', {
36
36
  plugins: [
37
- ['putout', pluginPutout], r,
37
+ ['putout', pluginPutout],
38
38
  ],
39
39
  }));
40
40
 
@@ -507,8 +507,8 @@ function requireConvertBabelTypes () {
507
507
  const {replaceWith} = operator;
508
508
 
509
509
  const astRequire = template.ast(`
510
- require('putout').types
511
- `);
510
+ require('putout').types
511
+ `);
512
512
 
513
513
  convertBabelTypes.report = () => {
514
514
  return `"putout.types" should be used instead of "@babel/types"`;
@@ -846,8 +846,16 @@ function requireConvertNumberToNumeric () {
846
846
  convertNumberToNumeric.report = () => `Use 'isNumericLiteral()' instead of 'isNumberLiteral()'`;
847
847
 
848
848
  convertNumberToNumeric.fix = (path) => {
849
- path.scope.rename('isNumberLiteral', 'isNumericLiteral');
850
- path.scope.rename('NumberLiteral', 'NumericLiteral');
849
+ const bindings = path.scope.getAllBindings();
850
+ const {name} = path.node.callee;
851
+
852
+ if (!bindings.isNumericLiteral)
853
+ path.scope.rename('isNumberLiteral', 'isNumericLiteral');
854
+
855
+ if (!bindings.NumericLiteral)
856
+ path.scope.rename('NumberLiteral', 'NumericLiteral');
857
+
858
+ path.node.callee.name = name.replace('Number', 'Numeric');
851
859
  };
852
860
 
853
861
  convertNumberToNumeric.traverse = ({push}) => ({
@@ -1017,8 +1025,8 @@ function requireConvertReplaceWith () {
1017
1025
 
1018
1026
  if (!bindings.replaceWithMultiple && !bindings.insertAfter && !isInserted()) {
1019
1027
  const replaceWithAST = template.ast.fresh(`
1020
- const {replaceWith} = require('putout').operator;
1021
- `);
1028
+ const {replaceWith} = require('putout').operator;
1029
+ `);
1022
1030
 
1023
1031
  const {types} = bindings;
1024
1032
  const pathToInsertAfter = types ? types.path.parentPath : strictModePath;
@@ -1108,8 +1116,8 @@ function requireConvertReplaceWithMultiple () {
1108
1116
  };
1109
1117
 
1110
1118
  const replaceWithAST = template.ast(`
1111
- const {replaceWithMultiple} = require('putout').operate;
1112
- `);
1119
+ const {replaceWithMultiple} = require('putout').operate;
1120
+ `);
1113
1121
 
1114
1122
  convertReplaceWithMultiple.fix = ({path, calleePath, property, object, program}) => {
1115
1123
  const strictModePath = program.get('body.0');
@@ -1352,7 +1360,7 @@ function requireConvertTraverseToReplace () {
1352
1360
  if (withFix)
1353
1361
  return false;
1354
1362
 
1355
- if (hasPushCall(path))
1363
+ if (check(path))
1356
1364
  return false;
1357
1365
 
1358
1366
  if (!__args.length)
@@ -1373,17 +1381,30 @@ function requireConvertTraverseToReplace () {
1373
1381
  'module.exports.traverse = (__args) => __a': 'module.exports.replace = (__args) => __a',
1374
1382
  });
1375
1383
 
1376
- function hasPushCall(path) {
1377
- let is = false;
1384
+ function check(path) {
1385
+ let hasPushCall = false;
1386
+ let hasTraverseMethod = false;
1378
1387
 
1379
1388
  traverse(path, {
1389
+ 'ObjectMethod|ObjectProperty': (path) => {
1390
+ const keyPath = path.get('key');
1391
+
1392
+ if (!path.parentPath.isObjectExpression())
1393
+ return;
1394
+
1395
+ if (!keyPath.isIdentifier())
1396
+ return;
1397
+
1398
+ hasTraverseMethod = true;
1399
+ path.stop();
1400
+ },
1380
1401
  'push(__a)': (path) => {
1381
- is = true;
1402
+ hasPushCall = true;
1382
1403
  path.stop();
1383
1404
  },
1384
1405
  });
1385
1406
 
1386
- return is;
1407
+ return hasPushCall || hasTraverseMethod;
1387
1408
  }
1388
1409
  return convertTraverseToReplace;
1389
1410
  }
@@ -2836,16 +2857,16 @@ function requireMoveRequireOnTopLevel () {
2836
2857
  } = require$$0$1;
2837
2858
 
2838
2859
  const TEST = `
2839
- const test = require('@putout/test')(__dirname, {
2840
- __a: __b
2841
- });
2842
- `;
2860
+ const test = require('@putout/test')(__dirname, {
2861
+ __a: __b
2862
+ });
2863
+ `;
2843
2864
 
2844
2865
  const TRANSFORM = `
2845
- t.transform(__c, {
2846
- __a: __b
2847
- });
2848
- `;
2866
+ t.transform(__c, {
2867
+ __a: __b
2868
+ });
2869
+ `;
2849
2870
 
2850
2871
  const {
2851
2872
  Identifier,
@@ -2867,10 +2888,10 @@ function requireMoveRequireOnTopLevel () {
2867
2888
  const value = __a.value || __a.name;
2868
2889
 
2869
2890
  return `
2870
- const test = require('@putout/test')(__dirname, {
2871
- '${value}': ${name},
2872
- });
2873
- `;
2891
+ const test = require('@putout/test')(__dirname, {
2892
+ '${value}': ${name},
2893
+ });
2894
+ `;
2874
2895
  },
2875
2896
  [TRANSFORM]: (vars, path) => {
2876
2897
  const name = declareRequire(vars, path);
@@ -2878,10 +2899,10 @@ function requireMoveRequireOnTopLevel () {
2878
2899
  const value = __a.value || __a.name;
2879
2900
 
2880
2901
  return `
2881
- t.transform(__c, {
2882
- '${value}': ${name},
2883
- });
2884
- `;
2902
+ t.transform(__c, {
2903
+ '${value}': ${name},
2904
+ });
2905
+ `;
2885
2906
  },
2886
2907
  });
2887
2908