@jsenv/core 23.8.2 → 23.8.7
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/dist/jsenv_browser_system.js +46 -39
- package/dist/jsenv_browser_system.js.map +14 -14
- package/dist/jsenv_compile_proxy.js.map +6 -6
- package/dist/jsenv_exploring_index.js.map +5 -5
- package/dist/jsenv_exploring_redirector.js.map +12 -12
- package/dist/jsenv_toolbar.js.map +7 -7
- package/dist/jsenv_toolbar_injector.js.map +5 -5
- package/helpers/babel/.eslintrc.cjs +24 -24
- package/helpers/babel/AsyncGenerator/AsyncGenerator.js +81 -81
- package/helpers/babel/AwaitValue/AwaitValue.js +3 -3
- package/helpers/babel/applyDecoratorDescriptor/applyDecoratorDescriptor.js +33 -33
- package/helpers/babel/arrayLikeToArray/arrayLikeToArray.js +7 -7
- package/helpers/babel/arrayWithHoles/arrayWithHoles.js +4 -4
- package/helpers/babel/arrayWithoutHoles/arrayWithoutHoles.js +6 -6
- package/helpers/babel/assertThisInitialized/assertThisInitialized.js +7 -7
- package/helpers/babel/asyncGeneratorDelegate/asyncGeneratorDelegate.js +40 -40
- package/helpers/babel/asyncIterator/asyncIterator.js +12 -12
- package/helpers/babel/asyncToGenerator/asyncToGenerator.js +34 -34
- package/helpers/babel/awaitAsyncGenerator/awaitAsyncGenerator.js +5 -5
- package/helpers/babel/classApplyDescriptorDestructureSet/classApplyDescriptorDestructureSet.js +20 -20
- package/helpers/babel/classApplyDescriptorGet/classApplyDescriptorGet.js +6 -6
- package/helpers/babel/classApplyDescriptorSet/classApplyDescriptorSet.js +13 -13
- package/helpers/babel/classCallCheck/classCallCheck.js +5 -5
- package/helpers/babel/classCheckPrivateStaticAccess/classCheckPrivateStaticAccess.js +5 -5
- package/helpers/babel/classCheckPrivateStaticFieldDescriptor/classCheckPrivateStaticFieldDescriptor.js +6 -6
- package/helpers/babel/classExtractFieldDescriptor/classExtractFieldDescriptor.js +7 -7
- package/helpers/babel/classNameTDZError/classNameTDZError.js +4 -4
- package/helpers/babel/classPrivateFieldDestructureSet/classPrivateFieldDestructureSet.js +7 -7
- package/helpers/babel/classPrivateFieldGet/classPrivateFieldGet.js +7 -7
- package/helpers/babel/classPrivateFieldLooseBase/classPrivateFieldLooseBase.js +6 -6
- package/helpers/babel/classPrivateFieldLooseKey/classPrivateFieldLooseKey.js +5 -5
- package/helpers/babel/classPrivateFieldSet/classPrivateFieldSet.js +8 -8
- package/helpers/babel/classPrivateMethodGet/classPrivateMethodGet.js +6 -6
- package/helpers/babel/classPrivateMethodSet/classPrivateMethodSet.js +3 -3
- package/helpers/babel/classStaticPrivateFieldSpecGet/classStaticPrivateFieldSpecGet.js +9 -9
- package/helpers/babel/classStaticPrivateFieldSpecSet/classStaticPrivateFieldSpecSet.js +15 -15
- package/helpers/babel/classStaticPrivateMethodGet/classStaticPrivateMethodGet.js +6 -6
- package/helpers/babel/classStaticPrivateMethodSet/classStaticPrivateMethodSet.js +3 -3
- package/helpers/babel/construct/construct.js +16 -16
- package/helpers/babel/createClass/createClass.js +15 -15
- package/helpers/babel/createForOfIteratorHelper/createForOfIteratorHelper.js +60 -60
- package/helpers/babel/createForOfIteratorHelperLoose/createForOfIteratorHelperLoose.js +23 -23
- package/helpers/babel/createRawReactElement/createRawReactElement.js +50 -50
- package/helpers/babel/createSuper/createSuper.js +22 -22
- package/helpers/babel/decorate/decorate.js +403 -403
- package/helpers/babel/defaults/defaults.js +11 -11
- package/helpers/babel/defineEnumerableProperties/defineEnumerableProperties.js +23 -23
- package/helpers/babel/defineProperty/defineProperty.js +18 -18
- package/helpers/babel/extends/extends.js +14 -14
- package/helpers/babel/get/get.js +13 -13
- package/helpers/babel/getPrototypeOf/getPrototypeOf.js +4 -4
- package/helpers/babel/inherits/inherits.js +15 -15
- package/helpers/babel/inheritsLoose/inheritsLoose.js +7 -7
- package/helpers/babel/initializerDefineProperty/initializerDefineProperty.js +10 -10
- package/helpers/babel/initializerWarningHelper/initializerWarningHelper.js +6 -6
- package/helpers/babel/instanceof/instanceof.js +6 -6
- package/helpers/babel/interopRequireDefault/interopRequireDefault.js +3 -3
- package/helpers/babel/interopRequireWildcard/interopRequireWildcard.js +37 -37
- package/helpers/babel/isNativeFunction/isNativeFunction.js +4 -4
- package/helpers/babel/isNativeReflectConstruct/isNativeReflectConstruct.js +21 -21
- package/helpers/babel/iterableToArray/iterableToArray.js +7 -7
- package/helpers/babel/iterableToArrayLimit/iterableToArrayLimit.js +36 -36
- package/helpers/babel/iterableToArrayLimitLoose/iterableToArrayLimitLoose.js +10 -10
- package/helpers/babel/jsx/jsx.js +45 -45
- package/helpers/babel/maybeArrayLike/maybeArrayLike.js +10 -10
- package/helpers/babel/newArrowCheck/newArrowCheck.js +5 -5
- package/helpers/babel/nonIterableRest/nonIterableRest.js +5 -5
- package/helpers/babel/nonIterableSpread/nonIterableSpread.js +5 -5
- package/helpers/babel/objectDestructuringEmpty/objectDestructuringEmpty.js +3 -3
- package/helpers/babel/objectSpread/objectSpread.js +23 -23
- package/helpers/babel/objectSpread2/objectSpread2.js +33 -33
- package/helpers/babel/objectWithoutProperties/objectWithoutProperties.js +19 -19
- package/helpers/babel/objectWithoutPropertiesLoose/objectWithoutPropertiesLoose.js +13 -13
- package/helpers/babel/possibleConstructorReturn/possibleConstructorReturn.js +10 -10
- package/helpers/babel/readOnlyError/readOnlyError.js +4 -4
- package/helpers/babel/readme.md +9 -9
- package/helpers/babel/set/set.js +44 -44
- package/helpers/babel/setPrototypeOf/setPrototypeOf.js +6 -6
- package/helpers/babel/skipFirstGeneratorNext/skipFirstGeneratorNext.js +8 -8
- package/helpers/babel/slicedToArray/slicedToArray.js +10 -10
- package/helpers/babel/slicedToArrayLoose/slicedToArrayLoose.js +13 -13
- package/helpers/babel/superPropBase/superPropBase.js +10 -10
- package/helpers/babel/taggedTemplateLiteral/taggedTemplateLiteral.js +10 -10
- package/helpers/babel/taggedTemplateLiteralLoose/taggedTemplateLiteralLoose.js +7 -7
- package/helpers/babel/tdz/tdz.js +4 -4
- package/helpers/babel/temporalRef/temporalRef.js +6 -6
- package/helpers/babel/temporalUndefined/temporalUndefined.js +3 -3
- package/helpers/babel/toArray/toArray.js +10 -10
- package/helpers/babel/toConsumableArray/toConsumableArray.js +10 -10
- package/helpers/babel/toPrimitive/toPrimitive.js +10 -10
- package/helpers/babel/toPropertyKey/toPropertyKey.js +6 -6
- package/helpers/babel/typeof/typeof.js +14 -14
- package/helpers/babel/unsupportedIterableToArray/unsupportedIterableToArray.js +12 -12
- package/helpers/babel/wrapAsyncGenerator/wrapAsyncGenerator.js +8 -8
- package/helpers/babel/wrapNativeSuper/wrapNativeSuper.js +30 -30
- package/helpers/babel/wrapRegExp/wrapRegExp.js +63 -63
- package/helpers/babel/writeOnlyError/writeOnlyError.js +4 -4
- package/helpers/regenerator-runtime/regenerator-runtime.js +748 -748
- package/{LICENSE → license} +21 -21
- package/package.json +2 -2
- package/src/buildProject.js +300 -300
- package/src/execute.js +184 -184
- package/src/internal/browser-launcher/jsenv-browser-system.js +203 -199
- package/src/internal/building/buildUsingRollup.js +2 -10
- package/src/internal/compiling/babel_plugin_import_assertions.js +121 -121
- package/src/internal/compiling/babel_plugin_import_metadata.js +22 -22
- package/src/internal/compiling/babel_plugin_import_visitor.js +84 -84
- package/src/internal/compiling/compile-directory/getOrGenerateCompiledFile.js +268 -268
- package/src/internal/compiling/compile-directory/updateMeta.js +154 -154
- package/src/internal/compiling/compile-directory/validateCache.js +265 -265
- package/src/internal/compiling/compileFile.js +233 -224
- package/src/internal/compiling/compileHtml.js +550 -550
- package/src/internal/compiling/createCompiledFileService.js +291 -291
- package/src/internal/compiling/html_source_file_service.js +403 -404
- package/src/internal/compiling/js-compilation-service/jsenvTransform.js +272 -270
- package/src/internal/compiling/jsenvCompilerForHtml.js +374 -308
- package/src/internal/compiling/jsenvCompilerForJavaScript.js +2 -0
- package/src/internal/compiling/startCompileServer.js +1086 -1048
- package/src/internal/compiling/transformResultToCompilationResult.js +220 -220
- package/src/internal/executing/coverage/babel_plugin_instrument.js +90 -90
- package/src/internal/executing/coverage/reportToCoverage.js +193 -187
- package/src/internal/executing/executePlan.js +183 -183
- package/src/internal/executing/launchAndExecute.js +458 -458
- package/src/internal/generateGroupMap/featuresCompatMap.js +29 -0
- package/src/internal/generateGroupMap/jsenvBabelPluginCompatMap.js +1 -8
- package/src/internal/runtime/createBrowserRuntime/scanBrowserRuntimeFeatures.js +246 -246
- package/src/internal/runtime/createNodeRuntime/scanNodeRuntimeFeatures.js +112 -112
- package/src/internal/runtime/s.js +727 -727
- package/src/internal/toolbar/jsenv-logo.svg +144 -144
- package/src/internal/toolbar/toolbar.main.css +196 -196
- package/src/internal/toolbar/toolbar.main.js +227 -227
- package/src/internal/url_conversion.js +317 -317
- package/src/startExploring.js +309 -309
|
@@ -1,121 +1,121 @@
|
|
|
1
|
-
import { urlToRelativeUrl } from "@jsenv/filesystem"
|
|
2
|
-
|
|
3
|
-
import { setUrlSearchParamsDescriptor } from "@jsenv/core/src/internal/url_utils.js"
|
|
4
|
-
import { babelPluginImportVisitor } from "./babel_plugin_import_visitor.js"
|
|
5
|
-
|
|
6
|
-
export const babelPluginImportAssertions = (
|
|
7
|
-
babel,
|
|
8
|
-
{ transformJson = true, transformCss = true },
|
|
9
|
-
) => {
|
|
10
|
-
return {
|
|
11
|
-
...babelPluginImportVisitor(
|
|
12
|
-
babel,
|
|
13
|
-
// During the build we throw when for import call expression where
|
|
14
|
-
// sepcifier or type is dynamic.
|
|
15
|
-
// Here there is no strong need to throw because keeping the source code intact
|
|
16
|
-
// will throw an error when browser will execute the code
|
|
17
|
-
({ importPath, specifierPath }) => {
|
|
18
|
-
const importNode = importPath.node
|
|
19
|
-
let assertionsDescriptor
|
|
20
|
-
if (importNode.type === "CallExpression") {
|
|
21
|
-
const args = importNode.arguments
|
|
22
|
-
const secondArg = args[1]
|
|
23
|
-
if (!secondArg) {
|
|
24
|
-
return
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
const { properties } = secondArg
|
|
28
|
-
const assertProperty = properties.find((property) => {
|
|
29
|
-
return property.key.name === "assert"
|
|
30
|
-
})
|
|
31
|
-
if (!assertProperty) {
|
|
32
|
-
return
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
const assertProperties = assertProperty.value.properties
|
|
36
|
-
const typePropertyNode = assertProperties.find((property) => {
|
|
37
|
-
return property.key.name === "type"
|
|
38
|
-
})
|
|
39
|
-
if (!typePropertyNode) {
|
|
40
|
-
return
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
const typePropertyValue = typePropertyNode.value
|
|
44
|
-
if (typePropertyValue.type !== "StringLiteral") {
|
|
45
|
-
return
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
assertionsDescriptor = {
|
|
49
|
-
type: typePropertyValue.value,
|
|
50
|
-
}
|
|
51
|
-
} else {
|
|
52
|
-
assertionsDescriptor = getImportAssertionsDescriptor(
|
|
53
|
-
importPath.node.assertions,
|
|
54
|
-
)
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
const { type } = assertionsDescriptor
|
|
58
|
-
if (type === "json" && transformJson) {
|
|
59
|
-
forceImportTypeOnSpecifier({
|
|
60
|
-
specifierPath,
|
|
61
|
-
babel,
|
|
62
|
-
importType: "json",
|
|
63
|
-
})
|
|
64
|
-
return
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
if (type === "css" && transformCss) {
|
|
68
|
-
forceImportTypeOnSpecifier({
|
|
69
|
-
specifierPath,
|
|
70
|
-
babel,
|
|
71
|
-
importType: "css",
|
|
72
|
-
})
|
|
73
|
-
return
|
|
74
|
-
}
|
|
75
|
-
},
|
|
76
|
-
),
|
|
77
|
-
name: "transform-import-assertions",
|
|
78
|
-
}
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
const getImportAssertionsDescriptor = (importAssertions) => {
|
|
82
|
-
const importAssertionsDescriptor = {}
|
|
83
|
-
if (importAssertions) {
|
|
84
|
-
importAssertions.forEach((importAssertion) => {
|
|
85
|
-
importAssertionsDescriptor[importAssertion.key.name] =
|
|
86
|
-
importAssertion.value.value
|
|
87
|
-
})
|
|
88
|
-
}
|
|
89
|
-
return importAssertionsDescriptor
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
const forceImportTypeOnSpecifier = ({ specifierPath, babel, importType }) => {
|
|
93
|
-
const specifier = specifierPath.node.value
|
|
94
|
-
const fakeOrigin = "http://jsenv.com"
|
|
95
|
-
const url = new URL(specifier, fakeOrigin)
|
|
96
|
-
const urlWithImportType = setUrlSearchParamsDescriptor(url, {
|
|
97
|
-
import_type: importType,
|
|
98
|
-
})
|
|
99
|
-
if (urlWithImportType.startsWith(fakeOrigin)) {
|
|
100
|
-
// specifier was relative
|
|
101
|
-
const specifierWithImportType = urlToRelativeUrl(
|
|
102
|
-
urlWithImportType,
|
|
103
|
-
fakeOrigin,
|
|
104
|
-
)
|
|
105
|
-
|
|
106
|
-
replaceSpecifierUsingBabel(`./${specifierWithImportType}`, {
|
|
107
|
-
specifierPath,
|
|
108
|
-
babel,
|
|
109
|
-
})
|
|
110
|
-
return
|
|
111
|
-
}
|
|
112
|
-
|
|
113
|
-
replaceSpecifierUsingBabel(urlWithImportType, {
|
|
114
|
-
specifierPath,
|
|
115
|
-
babel,
|
|
116
|
-
})
|
|
117
|
-
}
|
|
118
|
-
|
|
119
|
-
const replaceSpecifierUsingBabel = (value, { specifierPath, babel }) => {
|
|
120
|
-
specifierPath.replaceWith(babel.types.stringLiteral(value))
|
|
121
|
-
}
|
|
1
|
+
import { urlToRelativeUrl } from "@jsenv/filesystem"
|
|
2
|
+
|
|
3
|
+
import { setUrlSearchParamsDescriptor } from "@jsenv/core/src/internal/url_utils.js"
|
|
4
|
+
import { babelPluginImportVisitor } from "./babel_plugin_import_visitor.js"
|
|
5
|
+
|
|
6
|
+
export const babelPluginImportAssertions = (
|
|
7
|
+
babel,
|
|
8
|
+
{ transformJson = true, transformCss = true },
|
|
9
|
+
) => {
|
|
10
|
+
return {
|
|
11
|
+
...babelPluginImportVisitor(
|
|
12
|
+
babel,
|
|
13
|
+
// During the build we throw when for import call expression where
|
|
14
|
+
// sepcifier or type is dynamic.
|
|
15
|
+
// Here there is no strong need to throw because keeping the source code intact
|
|
16
|
+
// will throw an error when browser will execute the code
|
|
17
|
+
({ importPath, specifierPath }) => {
|
|
18
|
+
const importNode = importPath.node
|
|
19
|
+
let assertionsDescriptor
|
|
20
|
+
if (importNode.type === "CallExpression") {
|
|
21
|
+
const args = importNode.arguments
|
|
22
|
+
const secondArg = args[1]
|
|
23
|
+
if (!secondArg) {
|
|
24
|
+
return
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
const { properties } = secondArg
|
|
28
|
+
const assertProperty = properties.find((property) => {
|
|
29
|
+
return property.key.name === "assert"
|
|
30
|
+
})
|
|
31
|
+
if (!assertProperty) {
|
|
32
|
+
return
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
const assertProperties = assertProperty.value.properties
|
|
36
|
+
const typePropertyNode = assertProperties.find((property) => {
|
|
37
|
+
return property.key.name === "type"
|
|
38
|
+
})
|
|
39
|
+
if (!typePropertyNode) {
|
|
40
|
+
return
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
const typePropertyValue = typePropertyNode.value
|
|
44
|
+
if (typePropertyValue.type !== "StringLiteral") {
|
|
45
|
+
return
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
assertionsDescriptor = {
|
|
49
|
+
type: typePropertyValue.value,
|
|
50
|
+
}
|
|
51
|
+
} else {
|
|
52
|
+
assertionsDescriptor = getImportAssertionsDescriptor(
|
|
53
|
+
importPath.node.assertions,
|
|
54
|
+
)
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
const { type } = assertionsDescriptor
|
|
58
|
+
if (type === "json" && transformJson) {
|
|
59
|
+
forceImportTypeOnSpecifier({
|
|
60
|
+
specifierPath,
|
|
61
|
+
babel,
|
|
62
|
+
importType: "json",
|
|
63
|
+
})
|
|
64
|
+
return
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
if (type === "css" && transformCss) {
|
|
68
|
+
forceImportTypeOnSpecifier({
|
|
69
|
+
specifierPath,
|
|
70
|
+
babel,
|
|
71
|
+
importType: "css",
|
|
72
|
+
})
|
|
73
|
+
return
|
|
74
|
+
}
|
|
75
|
+
},
|
|
76
|
+
),
|
|
77
|
+
name: "transform-import-assertions",
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
const getImportAssertionsDescriptor = (importAssertions) => {
|
|
82
|
+
const importAssertionsDescriptor = {}
|
|
83
|
+
if (importAssertions) {
|
|
84
|
+
importAssertions.forEach((importAssertion) => {
|
|
85
|
+
importAssertionsDescriptor[importAssertion.key.name] =
|
|
86
|
+
importAssertion.value.value
|
|
87
|
+
})
|
|
88
|
+
}
|
|
89
|
+
return importAssertionsDescriptor
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
const forceImportTypeOnSpecifier = ({ specifierPath, babel, importType }) => {
|
|
93
|
+
const specifier = specifierPath.node.value
|
|
94
|
+
const fakeOrigin = "http://jsenv.com"
|
|
95
|
+
const url = new URL(specifier, fakeOrigin)
|
|
96
|
+
const urlWithImportType = setUrlSearchParamsDescriptor(url, {
|
|
97
|
+
import_type: importType,
|
|
98
|
+
})
|
|
99
|
+
if (urlWithImportType.startsWith(fakeOrigin)) {
|
|
100
|
+
// specifier was relative
|
|
101
|
+
const specifierWithImportType = urlToRelativeUrl(
|
|
102
|
+
urlWithImportType,
|
|
103
|
+
fakeOrigin,
|
|
104
|
+
)
|
|
105
|
+
|
|
106
|
+
replaceSpecifierUsingBabel(`./${specifierWithImportType}`, {
|
|
107
|
+
specifierPath,
|
|
108
|
+
babel,
|
|
109
|
+
})
|
|
110
|
+
return
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
replaceSpecifierUsingBabel(urlWithImportType, {
|
|
114
|
+
specifierPath,
|
|
115
|
+
babel,
|
|
116
|
+
})
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
const replaceSpecifierUsingBabel = (value, { specifierPath, babel }) => {
|
|
120
|
+
specifierPath.replaceWith(babel.types.stringLiteral(value))
|
|
121
|
+
}
|
|
@@ -1,22 +1,22 @@
|
|
|
1
|
-
import { babelPluginImportVisitor } from "./babel_plugin_import_visitor.js"
|
|
2
|
-
|
|
3
|
-
export const babelPluginImportMetadata = (babel) => {
|
|
4
|
-
return {
|
|
5
|
-
...babelPluginImportVisitor(
|
|
6
|
-
babel,
|
|
7
|
-
// During the build we throw when for import call expression where
|
|
8
|
-
// sepcifier or type is dynamic.
|
|
9
|
-
// Here there is no strong need to throw because keeping the source code intact
|
|
10
|
-
// will throw an error when browser will execute the code
|
|
11
|
-
({ state, specifierPath }) => {
|
|
12
|
-
const { metadata } = state.file
|
|
13
|
-
|
|
14
|
-
metadata.dependencies = [
|
|
15
|
-
...(metadata.dependencies ? metadata.dependencies : []),
|
|
16
|
-
specifierPath.node.value,
|
|
17
|
-
]
|
|
18
|
-
},
|
|
19
|
-
),
|
|
20
|
-
name: "import-metadata",
|
|
21
|
-
}
|
|
22
|
-
}
|
|
1
|
+
import { babelPluginImportVisitor } from "./babel_plugin_import_visitor.js"
|
|
2
|
+
|
|
3
|
+
export const babelPluginImportMetadata = (babel) => {
|
|
4
|
+
return {
|
|
5
|
+
...babelPluginImportVisitor(
|
|
6
|
+
babel,
|
|
7
|
+
// During the build we throw when for import call expression where
|
|
8
|
+
// sepcifier or type is dynamic.
|
|
9
|
+
// Here there is no strong need to throw because keeping the source code intact
|
|
10
|
+
// will throw an error when browser will execute the code
|
|
11
|
+
({ state, specifierPath }) => {
|
|
12
|
+
const { metadata } = state.file
|
|
13
|
+
|
|
14
|
+
metadata.dependencies = [
|
|
15
|
+
...(metadata.dependencies ? metadata.dependencies : []),
|
|
16
|
+
specifierPath.node.value,
|
|
17
|
+
]
|
|
18
|
+
},
|
|
19
|
+
),
|
|
20
|
+
name: "import-metadata",
|
|
21
|
+
}
|
|
22
|
+
}
|
|
@@ -1,84 +1,84 @@
|
|
|
1
|
-
/*
|
|
2
|
-
* Not meant to be used directly
|
|
3
|
-
* Will be used either to put import specifier in metadata
|
|
4
|
-
* or to transform import specifiers
|
|
5
|
-
*
|
|
6
|
-
* see also
|
|
7
|
-
* https://github.com/jamiebuilds/babel-handbook/blob/master/translations/en/plugin-handbook.md
|
|
8
|
-
* https://github.com/mjackson/babel-plugin-import-visitor
|
|
9
|
-
*
|
|
10
|
-
*/
|
|
11
|
-
|
|
12
|
-
export const babelPluginImportVisitor = (babel, importVisitor = () => {}) => {
|
|
13
|
-
return {
|
|
14
|
-
name: "import-visitor",
|
|
15
|
-
|
|
16
|
-
// manipulateOptions(opts, parserOpts) {
|
|
17
|
-
// parserOpts.plugins.push(
|
|
18
|
-
// "dynamicImport",
|
|
19
|
-
// "exportDefaultFrom",
|
|
20
|
-
// "exportNamespaceFrom",
|
|
21
|
-
// "importMeta",
|
|
22
|
-
// )
|
|
23
|
-
// },
|
|
24
|
-
|
|
25
|
-
visitor: {
|
|
26
|
-
CallExpression: (path, state) => {
|
|
27
|
-
if (path.node.callee.type !== "Import") {
|
|
28
|
-
// Some other function call, not import();
|
|
29
|
-
return
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
if (path.node.arguments[0].type !== "StringLiteral") {
|
|
33
|
-
// Non-string argument, probably a variable or expression, e.g.
|
|
34
|
-
// import(moduleId)
|
|
35
|
-
// import('./' + moduleName)
|
|
36
|
-
return
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
importVisitor({
|
|
40
|
-
importPath: path,
|
|
41
|
-
specifierPath: path.get("arguments")[0],
|
|
42
|
-
state,
|
|
43
|
-
babel,
|
|
44
|
-
})
|
|
45
|
-
},
|
|
46
|
-
|
|
47
|
-
ExportAllDeclaration: (path, state) => {
|
|
48
|
-
importVisitor({
|
|
49
|
-
importPath: path,
|
|
50
|
-
specifierPath: path.get("source"),
|
|
51
|
-
state,
|
|
52
|
-
babel,
|
|
53
|
-
})
|
|
54
|
-
},
|
|
55
|
-
|
|
56
|
-
ExportNamedDeclaration: (path, state) => {
|
|
57
|
-
if (!path.node.source) {
|
|
58
|
-
// This export has no "source", so it's probably
|
|
59
|
-
// a local variable or function, e.g.
|
|
60
|
-
// export { varName }
|
|
61
|
-
// export const constName = ...
|
|
62
|
-
// export function funcName() {}
|
|
63
|
-
return
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
importVisitor({
|
|
67
|
-
importPath: path,
|
|
68
|
-
specifierPath: path.get("source"),
|
|
69
|
-
state,
|
|
70
|
-
babel,
|
|
71
|
-
})
|
|
72
|
-
},
|
|
73
|
-
|
|
74
|
-
ImportDeclaration: (path, state) => {
|
|
75
|
-
importVisitor({
|
|
76
|
-
importPath: path,
|
|
77
|
-
specifierPath: path.get("source"),
|
|
78
|
-
state,
|
|
79
|
-
babel,
|
|
80
|
-
})
|
|
81
|
-
},
|
|
82
|
-
},
|
|
83
|
-
}
|
|
84
|
-
}
|
|
1
|
+
/*
|
|
2
|
+
* Not meant to be used directly
|
|
3
|
+
* Will be used either to put import specifier in metadata
|
|
4
|
+
* or to transform import specifiers
|
|
5
|
+
*
|
|
6
|
+
* see also
|
|
7
|
+
* https://github.com/jamiebuilds/babel-handbook/blob/master/translations/en/plugin-handbook.md
|
|
8
|
+
* https://github.com/mjackson/babel-plugin-import-visitor
|
|
9
|
+
*
|
|
10
|
+
*/
|
|
11
|
+
|
|
12
|
+
export const babelPluginImportVisitor = (babel, importVisitor = () => {}) => {
|
|
13
|
+
return {
|
|
14
|
+
name: "import-visitor",
|
|
15
|
+
|
|
16
|
+
// manipulateOptions(opts, parserOpts) {
|
|
17
|
+
// parserOpts.plugins.push(
|
|
18
|
+
// "dynamicImport",
|
|
19
|
+
// "exportDefaultFrom",
|
|
20
|
+
// "exportNamespaceFrom",
|
|
21
|
+
// "importMeta",
|
|
22
|
+
// )
|
|
23
|
+
// },
|
|
24
|
+
|
|
25
|
+
visitor: {
|
|
26
|
+
CallExpression: (path, state) => {
|
|
27
|
+
if (path.node.callee.type !== "Import") {
|
|
28
|
+
// Some other function call, not import();
|
|
29
|
+
return
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
if (path.node.arguments[0].type !== "StringLiteral") {
|
|
33
|
+
// Non-string argument, probably a variable or expression, e.g.
|
|
34
|
+
// import(moduleId)
|
|
35
|
+
// import('./' + moduleName)
|
|
36
|
+
return
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
importVisitor({
|
|
40
|
+
importPath: path,
|
|
41
|
+
specifierPath: path.get("arguments")[0],
|
|
42
|
+
state,
|
|
43
|
+
babel,
|
|
44
|
+
})
|
|
45
|
+
},
|
|
46
|
+
|
|
47
|
+
ExportAllDeclaration: (path, state) => {
|
|
48
|
+
importVisitor({
|
|
49
|
+
importPath: path,
|
|
50
|
+
specifierPath: path.get("source"),
|
|
51
|
+
state,
|
|
52
|
+
babel,
|
|
53
|
+
})
|
|
54
|
+
},
|
|
55
|
+
|
|
56
|
+
ExportNamedDeclaration: (path, state) => {
|
|
57
|
+
if (!path.node.source) {
|
|
58
|
+
// This export has no "source", so it's probably
|
|
59
|
+
// a local variable or function, e.g.
|
|
60
|
+
// export { varName }
|
|
61
|
+
// export const constName = ...
|
|
62
|
+
// export function funcName() {}
|
|
63
|
+
return
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
importVisitor({
|
|
67
|
+
importPath: path,
|
|
68
|
+
specifierPath: path.get("source"),
|
|
69
|
+
state,
|
|
70
|
+
babel,
|
|
71
|
+
})
|
|
72
|
+
},
|
|
73
|
+
|
|
74
|
+
ImportDeclaration: (path, state) => {
|
|
75
|
+
importVisitor({
|
|
76
|
+
importPath: path,
|
|
77
|
+
specifierPath: path.get("source"),
|
|
78
|
+
state,
|
|
79
|
+
babel,
|
|
80
|
+
})
|
|
81
|
+
},
|
|
82
|
+
},
|
|
83
|
+
}
|
|
84
|
+
}
|