@startupjs/babel-plugin-startupjs 0.61.0 → 0.61.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.
- package/index.js +52 -44
- package/package.json +2 -2
package/index.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
const { readFileSync } = require('fs')
|
|
2
2
|
const { join } = require('path')
|
|
3
3
|
|
|
4
|
-
const MAGIC_MODULE_NAME = '
|
|
4
|
+
const MAGIC_MODULE_NAME = 'startupjs-ui'
|
|
5
5
|
|
|
6
6
|
module.exports = function ({ template, types: t }) {
|
|
7
7
|
const buildImport = template('import %%name%% from %%source%%')
|
|
@@ -10,50 +10,58 @@ module.exports = function ({ template, types: t }) {
|
|
|
10
10
|
return {
|
|
11
11
|
name: 'Unwrap imports for tree shaking.',
|
|
12
12
|
visitor: {
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
//
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
13
|
+
Program ($this) {
|
|
14
|
+
let executed = false
|
|
15
|
+
$this.traverse({
|
|
16
|
+
ImportDeclaration ($this) {
|
|
17
|
+
if ($this.get('source').node.value !== MAGIC_MODULE_NAME) return
|
|
18
|
+
let transformed = false // needed to prevent infinite loops
|
|
19
|
+
const theImports = $this.get('specifiers')
|
|
20
|
+
.map($specifier => {
|
|
21
|
+
// pluck out into a separate import
|
|
22
|
+
if ($specifier.isImportSpecifier()) {
|
|
23
|
+
transformed = true
|
|
24
|
+
const originalName = $specifier.get('imported').node.name
|
|
25
|
+
if (!checkNamedExportExists(originalName)) {
|
|
26
|
+
throw $specifier.buildCodeFrameError(
|
|
27
|
+
`Named export "${originalName}" does not exist in "${MAGIC_MODULE_NAME}" "exports" field in package.json`
|
|
28
|
+
)
|
|
29
|
+
}
|
|
30
|
+
const importedName = $specifier.get('local').node.name
|
|
31
|
+
return buildImport({
|
|
32
|
+
name: importedName,
|
|
33
|
+
source: `${MAGIC_MODULE_NAME}/${originalName}`
|
|
34
|
+
})
|
|
35
|
+
}
|
|
36
|
+
// pass as is
|
|
37
|
+
return t.importDeclaration([$specifier.node], t.stringLiteral(MAGIC_MODULE_NAME))
|
|
31
38
|
})
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
|
|
39
|
+
if (!transformed) return
|
|
40
|
+
$this.replaceWithMultiple(theImports)
|
|
41
|
+
executed = true
|
|
42
|
+
},
|
|
43
|
+
ExportNamedDeclaration ($this) {
|
|
44
|
+
if ($this.get('source')?.node?.value !== MAGIC_MODULE_NAME) return
|
|
45
|
+
const theExports = $this.get('specifiers')
|
|
46
|
+
.map($specifier => {
|
|
47
|
+
const originalName = $specifier.get('local').node.name
|
|
48
|
+
if (!checkNamedExportExists(originalName)) {
|
|
49
|
+
throw $specifier.buildCodeFrameError(
|
|
50
|
+
`Named export "${originalName}" does not exist in "${MAGIC_MODULE_NAME}" "exports" field in package.json`
|
|
51
|
+
)
|
|
52
|
+
}
|
|
53
|
+
const exportedName = $specifier.get('exported').node.name
|
|
54
|
+
return buildExport({
|
|
55
|
+
name: exportedName,
|
|
56
|
+
source: `${MAGIC_MODULE_NAME}/${originalName}`
|
|
57
|
+
})
|
|
58
|
+
})
|
|
59
|
+
$this.replaceWithMultiple(theExports)
|
|
60
|
+
executed = true
|
|
61
|
+
}
|
|
62
|
+
})
|
|
63
|
+
// re-crawl to update scope bindings
|
|
64
|
+
if (executed) $this.scope.crawl()
|
|
57
65
|
}
|
|
58
66
|
}
|
|
59
67
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@startupjs/babel-plugin-startupjs",
|
|
3
|
-
"version": "0.61.
|
|
3
|
+
"version": "0.61.2",
|
|
4
4
|
"publishConfig": {
|
|
5
5
|
"access": "public"
|
|
6
6
|
},
|
|
@@ -31,5 +31,5 @@
|
|
|
31
31
|
"babel-plugin-tester": "^9.1.0",
|
|
32
32
|
"jest": "^29.2.1"
|
|
33
33
|
},
|
|
34
|
-
"gitHead": "
|
|
34
|
+
"gitHead": "00533aa32f235351daadab676a87ca9db0252cbd"
|
|
35
35
|
}
|