@startupjs/babel-plugin-startupjs 0.60.0-canary.7 → 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.
Files changed (2) hide show
  1. package/index.js +52 -44
  2. 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 = '@startupjs/ui'
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
- ImportDeclaration ($this) {
14
- if ($this.get('source').node.value !== MAGIC_MODULE_NAME) return
15
- let transformed = false // needed to prevent infinite loops
16
- const theImports = $this.get('specifiers')
17
- .map($specifier => {
18
- // pluck out into a separate import
19
- if ($specifier.isImportSpecifier()) {
20
- transformed = true
21
- const originalName = $specifier.get('imported').node.name
22
- if (!checkNamedExportExists(originalName)) {
23
- throw $specifier.buildCodeFrameError(
24
- `Named export "${originalName}" does not exist in "${MAGIC_MODULE_NAME}" "exports" field in package.json`
25
- )
26
- }
27
- const importedName = $specifier.get('local').node.name
28
- return buildImport({
29
- name: importedName,
30
- source: `${MAGIC_MODULE_NAME}/${originalName}`
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
- // pass as is
34
- return t.importDeclaration([$specifier.node], t.stringLiteral(MAGIC_MODULE_NAME))
35
- })
36
- if (!transformed) return
37
- $this.replaceWithMultiple(theImports)
38
- },
39
- ExportNamedDeclaration ($this) {
40
- if ($this.get('source').node.value !== MAGIC_MODULE_NAME) return
41
- const theExports = $this.get('specifiers')
42
- .map($specifier => {
43
- const originalName = $specifier.get('local').node.name
44
- if (!checkNamedExportExists(originalName)) {
45
- throw $specifier.buildCodeFrameError(
46
- `Named export "${originalName}" does not exist in "${MAGIC_MODULE_NAME}" "exports" field in package.json`
47
- )
48
- }
49
- const exportedName = $specifier.get('exported').node.name
50
- return buildExport({
51
- name: exportedName,
52
- source: `${MAGIC_MODULE_NAME}/${originalName}`
53
- })
54
- })
55
-
56
- $this.replaceWithMultiple(theExports)
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.60.0-canary.7",
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": "68c5c8e9757e263133c36a24f46ba35efc9b87b8"
34
+ "gitHead": "00533aa32f235351daadab676a87ca9db0252cbd"
35
35
  }