@putout/plugin-esm 8.0.1 → 8.0.2

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.
@@ -69,6 +69,7 @@ export const scan = (rootPath, {push, trackFile}) => {
69
69
 
70
70
  for (const [name, source, importedFilename] of importsTuples) {
71
71
  const is = hasImportDefault({
72
+ name,
72
73
  rootPath,
73
74
  importedFilename,
74
75
  privateImports,
@@ -113,7 +114,7 @@ function parseImportedFilename({importedFilename, privateImports}) {
113
114
  return importedFilename;
114
115
  }
115
116
 
116
- function hasImportDefault({rootPath, importedFilename, privateImports}) {
117
+ function hasImportDefault({name, rootPath, importedFilename, privateImports}) {
117
118
  const parsedName = parseImportedFilename({
118
119
  importedFilename,
119
120
  privateImports,
@@ -140,6 +141,13 @@ function hasImportDefault({rootPath, importedFilename, privateImports}) {
140
141
  if (defaultExport.length)
141
142
  return true;
142
143
 
144
+ for (const {message} of esm) {
145
+ const [, exportName] = message.split(':');
146
+
147
+ if (name === exportName)
148
+ return true;
149
+ }
150
+
143
151
  return !esm.length;
144
152
  }
145
153
 
@@ -1,4 +1,37 @@
1
- export const report = (path) => path.type;
1
+ import {types} from 'putout';
2
+
3
+ const {
4
+ isIdentifier,
5
+ isVariableDeclaration,
6
+ isFunction,
7
+ isExportNamedDeclaration,
8
+ } = types;
9
+
10
+ export const report = (path) => {
11
+ const {type} = path;
12
+
13
+ if (isExportNamedDeclaration(path)) {
14
+ const {declaration} = path.node;
15
+
16
+ if (isFunction(declaration))
17
+ return `${type}:${declaration.id.name}`;
18
+
19
+ if (isVariableDeclaration(declaration)) {
20
+ const {declarations} = declaration;
21
+
22
+ if (declarations.length !== 1)
23
+ return type;
24
+
25
+ const [first] = declarations;
26
+ const {id} = first;
27
+
28
+ if (isIdentifier(id))
29
+ return `${type}:${id.name}`;
30
+ }
31
+ }
32
+
33
+ return type;
34
+ };
2
35
 
3
36
  export const fix = (path) => {
4
37
  path.node.leadingComments = [
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@putout/plugin-esm",
3
- "version": "8.0.1",
3
+ "version": "8.0.2",
4
4
  "type": "module",
5
5
  "author": "coderaiser <mnemonic.enemy@gmail.com> (https://github.com/coderaiser)",
6
6
  "description": "🐊Putout plugin improves ability to transform ESM code",