@putout/plugin-nodejs 11.10.0 → 11.11.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.
|
@@ -1,15 +1,22 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
const {types
|
|
3
|
+
const {types} = require('putout');
|
|
4
4
|
const {isImportDefaultSpecifier} = types;
|
|
5
5
|
|
|
6
|
+
const BODY = '{__body}';
|
|
7
|
+
const FN = `function __a(__args) ${BODY}`;
|
|
8
|
+
const GEN_FN = `function* __a(__args) ${BODY}`;
|
|
9
|
+
const ASYNC_FN = `async function __a(__args) ${BODY}`;
|
|
10
|
+
const CLASS = `class __a ${BODY}`;
|
|
11
|
+
|
|
6
12
|
module.exports.report = () => `Use 'CommonJS' instead of 'ESM'`;
|
|
7
13
|
|
|
8
14
|
module.exports.replace = () => ({
|
|
9
15
|
'export default __a': 'module.exports = __a',
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
16
|
+
[`export ${CLASS}`]: `module.exports.__a = ${CLASS}`,
|
|
17
|
+
[`export ${FN}`]: `module.epxorts.__a = ${FN}`,
|
|
18
|
+
[`export ${ASYNC_FN}`]: `module.epxorts.__a = ${ASYNC_FN}`,
|
|
19
|
+
[`export ${GEN_FN}`]: `module.epxorts.__a = ${GEN_FN}`,
|
|
13
20
|
'export const __a = __b': 'module.exports.__a = __b',
|
|
14
21
|
'export {__exports}': ({__exports}) => {
|
|
15
22
|
let result = 'module.exports = {\n';
|
|
@@ -56,13 +63,3 @@ module.exports.replace = () => ({
|
|
|
56
63
|
}`;
|
|
57
64
|
},
|
|
58
65
|
});
|
|
59
|
-
|
|
60
|
-
function replaceFn({__a}, path) {
|
|
61
|
-
const {name} = __a;
|
|
62
|
-
const {declaration} = path.node;
|
|
63
|
-
const node = template.ast.fresh(`module.exports.${name} = __x`);
|
|
64
|
-
|
|
65
|
-
node.right = declaration;
|
|
66
|
-
|
|
67
|
-
return node;
|
|
68
|
-
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@putout/plugin-nodejs",
|
|
3
|
-
"version": "11.
|
|
3
|
+
"version": "11.11.0",
|
|
4
4
|
"type": "commonjs",
|
|
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",
|