@putout/plugin-nodejs 10.0.1 → 10.0.3

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/lib/index.js CHANGED
@@ -48,7 +48,7 @@ module.exports.rules = {
48
48
  'mjs-file': ['off', mjsFile],
49
49
 
50
50
  'rename-file-cjs-to-js': ['off', renameFileCjsToJs],
51
- 'rename-file-mjs-to-js': renameFileMjsToJs,
51
+ 'rename-file-mjs-to-js': ['off', renameFileMjsToJs],
52
52
 
53
53
  'add-strict-mode': strictMode.rules['add-missing'],
54
54
  'remove-strict-mode': strictMode.rules['remove-useless'],
@@ -13,7 +13,7 @@ module.exports.fix = ({node}) => {
13
13
  };
14
14
 
15
15
  module.exports.traverse = ({push, store}) => ({
16
- 'ImportExpression|ImportDeclaration|ExportNamedDeclaration|ExportDefaultDeclaration|ExportAllDeclaration|TypeAlias'() {
16
+ 'ImportDeclaration|ExportNamedDeclaration|ExportDefaultDeclaration|ExportAllDeclaration|TypeAlias'() {
17
17
  store('is-module', true);
18
18
  },
19
19
  'module.exports = __a'() {
@@ -1,7 +1,8 @@
1
1
  'use strict';
2
2
 
3
- const {operator} = require('putout');
3
+ const {types, operator} = require('putout');
4
4
  const {remove} = operator;
5
+ const {isProgram} = types;
5
6
 
6
7
  const isStrictMode = (a) => a.node.value.value === 'use strict';
7
8
 
@@ -10,10 +11,25 @@ module.exports.report = () => `Avoid 'use strict' in ESM`;
10
11
  module.exports.fix = (path) => remove(path);
11
12
 
12
13
  module.exports.traverse = ({push, store}) => ({
13
- 'ImportExpression|ImportDeclaration|ExportNamedDeclaration|ExportDefaultDeclaration|ExportAllDeclaration'() {
14
+ 'await __a(__args)'({scope}) {
15
+ if (isProgram(scope.block))
16
+ store('is-module', true);
17
+ },
18
+ 'await import(__a)'({scope}) {
19
+ if (isProgram(scope.block))
20
+ store('is-module', true);
21
+ },
22
+ 'await import(__a, __b)'({scope}) {
23
+ if (isProgram(scope.block))
24
+ store('is-module', true);
25
+ },
26
+ 'module.exports = __a': () => {
27
+ store('is-module', false);
28
+ },
29
+ 'ImportDeclaration|ExportNamedDeclaration|ExportDefaultDeclaration|ExportAllDeclaration'() {
14
30
  store('is-module', true);
15
31
  },
16
- Program: {
32
+ 'Program': {
17
33
  exit(path) {
18
34
  const [strictPath, ...paths] = path.get('body');
19
35
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@putout/plugin-nodejs",
3
- "version": "10.0.1",
3
+ "version": "10.0.3",
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",