@putout/plugin-nodejs 18.5.0 → 18.6.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.
|
@@ -39,7 +39,10 @@ const isPackage = ({value}) => /package(\.json)?$/.test(value);
|
|
|
39
39
|
|
|
40
40
|
export const match = () => ({
|
|
41
41
|
'const __a = require("__b").default': (vars, path) => {
|
|
42
|
-
|
|
42
|
+
if (isProgram(path.parentPath))
|
|
43
|
+
return true;
|
|
44
|
+
|
|
45
|
+
return isProgram(path.parentPath.parentPath);
|
|
43
46
|
},
|
|
44
47
|
'const __a = require(__b)': ({__b}, path) => {
|
|
45
48
|
if (path.scope.getBinding('require'))
|
|
@@ -1,15 +1,11 @@
|
|
|
1
1
|
import {types} from 'putout';
|
|
2
2
|
|
|
3
|
-
const {
|
|
4
|
-
isExpressionStatement,
|
|
5
|
-
stringLiteral,
|
|
6
|
-
expressionStatement,
|
|
7
|
-
} = types;
|
|
3
|
+
const {directiveLiteral} = types;
|
|
8
4
|
|
|
9
5
|
export const report = () => `Add missing 'use strict' directive on top of CommonJS`;
|
|
10
6
|
|
|
11
7
|
export const fix = ({node}) => {
|
|
12
|
-
node.
|
|
8
|
+
node.directives.push(directiveLiteral('use strict'));
|
|
13
9
|
};
|
|
14
10
|
|
|
15
11
|
export const traverse = ({push, store}) => ({
|
|
@@ -27,20 +23,18 @@ export const traverse = ({push, store}) => ({
|
|
|
27
23
|
},
|
|
28
24
|
Program: {
|
|
29
25
|
exit(path) {
|
|
30
|
-
for (const node of path.node.body)
|
|
31
|
-
if (
|
|
26
|
+
for (const node of path.node.body) {
|
|
27
|
+
if (store('is-module'))
|
|
32
28
|
return;
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
push(path);
|
|
29
|
+
|
|
30
|
+
if (path.node.directives.length)
|
|
31
|
+
return;
|
|
32
|
+
|
|
33
|
+
if (!store('is-common'))
|
|
34
|
+
return;
|
|
35
|
+
|
|
36
|
+
push(path);
|
|
37
|
+
}
|
|
44
38
|
},
|
|
45
39
|
},
|
|
46
40
|
});
|
|
@@ -16,14 +16,17 @@ export const fix = (path) => {
|
|
|
16
16
|
remove(path);
|
|
17
17
|
};
|
|
18
18
|
export const traverse = ({push}) => ({
|
|
19
|
-
DirectiveLiteral(
|
|
20
|
-
|
|
19
|
+
DirectiveLiteral({parentPath}) {
|
|
20
|
+
if (!parentPath.parentPath)
|
|
21
|
+
return;
|
|
22
|
+
|
|
23
|
+
const fnPath = parentPath.parentPath.parentPath;
|
|
21
24
|
|
|
22
25
|
if (!isFunction(fnPath))
|
|
23
26
|
return;
|
|
24
27
|
|
|
25
28
|
if (isIllegal(fnPath))
|
|
26
|
-
push(
|
|
29
|
+
push(parentPath);
|
|
27
30
|
},
|
|
28
31
|
});
|
|
29
32
|
|
|
@@ -30,13 +30,6 @@ export const traverse = ({push, store}) => ({
|
|
|
30
30
|
},
|
|
31
31
|
'Program': {
|
|
32
32
|
exit(path) {
|
|
33
|
-
const [, ...paths] = path.get('body');
|
|
34
|
-
|
|
35
|
-
for (const path of paths) {
|
|
36
|
-
if (path.isExpressionStatement() && path.node.expression.value === 'use strict')
|
|
37
|
-
push(path);
|
|
38
|
-
}
|
|
39
|
-
|
|
40
33
|
const directives = path.get('directives');
|
|
41
34
|
|
|
42
35
|
if (directives.length)
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@putout/plugin-nodejs",
|
|
3
|
-
"version": "18.
|
|
3
|
+
"version": "18.6.0",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"author": "coderaiser <mnemonic.enemy@gmail.com> (https://github.com/coderaiser)",
|
|
6
6
|
"description": "🐊Putout plugin adds ability to transform code to new API of Node.js",
|