@putout/plugin-putout 18.5.0 → 18.7.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.
@@ -9,9 +9,9 @@ const {replaceWith} = operator;
9
9
 
10
10
  const {
11
11
  ArrayPattern,
12
- ObjectPattern,
13
12
  BlockStatement,
14
13
  ObjectExpression,
14
+ ObjectPattern,
15
15
  } = types;
16
16
 
17
17
  module.exports = (rootPath, key) => {
@@ -54,17 +54,11 @@ module.exports = (rootPath, key) => {
54
54
  }
55
55
 
56
56
  if (name === '__array') {
57
- if (path.parentPath.isVariableDeclarator())
58
- return replaceWith(path, ArrayPattern([]));
59
-
60
57
  if (path.parentPath.isCallExpression())
61
58
  return replaceWith(path, ArrayPattern([]));
62
59
 
63
60
  if (path.parentPath.isFunction())
64
61
  return replaceWith(path, ArrayPattern([]));
65
-
66
- if (path.parentPath.isAssignmentExpression())
67
- return replaceWith(path, ArrayPattern([]));
68
62
  }
69
63
 
70
64
  if (name === '__object')
@@ -98,12 +92,18 @@ function createVarStore(path) {
98
92
 
99
93
  function objectify(path) {
100
94
  const {parentPath} = path;
101
- const isVar = parentPath.isVariableDeclarator();
102
95
  const isAssign = parentPath.isAssignmentExpression();
96
+ const isVar = parentPath.isVariableDeclarator();
103
97
 
104
- if (isVar && parentPath.get('id') === path)
105
- return replaceWith(path, ObjectPattern([]));
98
+ if (path.parentPath.isExportDeclaration())
99
+ return replaceWith(path, ObjectExpression([]));
100
+
101
+ if (path.parentPath.isCallExpression())
102
+ return replaceWith(path, ObjectExpression([]));
106
103
 
107
104
  if (isAssign && parentPath.get('right') === path)
108
105
  return replaceWith(path, ObjectExpression([]));
106
+
107
+ if (isVar && parentPath.get('id') === path)
108
+ return replaceWith(path, ObjectPattern([]));
109
109
  }
@@ -9,6 +9,7 @@ const {
9
9
  compare,
10
10
  extract,
11
11
  compute,
12
+ __json,
12
13
  } = operator;
13
14
 
14
15
  const name = '__putout_plugin_check_replace_code';
@@ -45,10 +46,11 @@ module.exports.traverse = ({push}) => ({
45
46
  return;
46
47
 
47
48
  for (const propertyPath of path.get('right.body.properties')) {
48
- if (!propertyPath.get('value').isStringLiteral())
49
+ const template = extractValue(propertyPath);
50
+
51
+ if (!template)
49
52
  continue;
50
53
 
51
- const {node} = propertyPath;
52
54
  const [parseError, key] = parseKey(propertyPath);
53
55
 
54
56
  if (parseError) {
@@ -61,7 +63,6 @@ module.exports.traverse = ({push}) => ({
61
63
  return;
62
64
  }
63
65
 
64
- const template = extract(node.value);
65
66
  const [generateError, keyCode] = generateCode(path, key);
66
67
 
67
68
  if (generateError) {
@@ -113,6 +114,10 @@ module.exports.traverse = ({push}) => ({
113
114
 
114
115
  function parseKey(propertyPath) {
115
116
  const keyPath = propertyPath.get('key');
117
+
118
+ if (keyPath.isIdentifier({name: '__json'}))
119
+ return [null, __json];
120
+
116
121
  const [isComputed, key] = compute(keyPath);
117
122
 
118
123
  if (!isComputed)
@@ -133,3 +138,15 @@ function hasMatch(path) {
133
138
 
134
139
  return false;
135
140
  }
141
+
142
+ function extractValue(path) {
143
+ const valuePath = path.get('value');
144
+
145
+ if (valuePath.isIdentifier({name: '__json'}))
146
+ return __json;
147
+
148
+ if (valuePath.isStringLiteral())
149
+ return valuePath.node.value;
150
+
151
+ return null;
152
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@putout/plugin-putout",
3
- "version": "18.5.0",
3
+ "version": "18.7.0",
4
4
  "type": "commonjs",
5
5
  "author": "coderaiser <mnemonic.enemy@gmail.com> (https://github.com/coderaiser)",
6
6
  "description": "🐊Putout plugin helps with plugins development",
@@ -39,8 +39,8 @@
39
39
  "devDependencies": {
40
40
  "@putout/plugin-tape": "*",
41
41
  "@putout/test": "^8.0.0",
42
- "c8": "^8.0.0",
43
- "eslint": "^8.0.1",
42
+ "c8": "^9.0.0",
43
+ "eslint": "^9.0.0-alpha.0",
44
44
  "eslint-plugin-n": "^16.0.0",
45
45
  "eslint-plugin-putout": "^22.0.0",
46
46
  "lerna": "^6.0.1",