@jsenv/plugin-transpilation 1.0.0
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/README.md +3 -0
- package/package.json +60 -0
- package/src/as_js_module/convert_js_classic_to_js_module.js +42 -0
- package/src/as_js_module/jsenv_plugin_as_js_module.js +89 -0
- package/src/babel/apply_js_transpilation.js +74 -0
- package/src/babel/babel_helper_directory/README.md +8 -0
- package/src/babel/babel_helper_directory/babel_helper_directory.js +35 -0
- package/src/babel/babel_helper_directory/babel_helpers/AsyncGenerator/AsyncGenerator.js +112 -0
- package/src/babel/babel_helper_directory/babel_helpers/AwaitValue/AwaitValue.js +3 -0
- package/src/babel/babel_helper_directory/babel_helpers/applyDecoratedDescriptor/applyDecoratedDescriptor.js +23 -0
- package/src/babel/babel_helper_directory/babel_helpers/applyDecs/applyDecs.js +802 -0
- package/src/babel/babel_helper_directory/babel_helpers/applyDecs2203/applyDecs2203.js +635 -0
- package/src/babel/babel_helper_directory/babel_helpers/applyDecs2203R/applyDecs2203R.js +642 -0
- package/src/babel/babel_helper_directory/babel_helpers/applyDecs2301/applyDecs2301.js +691 -0
- package/src/babel/babel_helper_directory/babel_helpers/arrayLikeToArray/arrayLikeToArray.js +7 -0
- package/src/babel/babel_helper_directory/babel_helpers/arrayWithHoles/arrayWithHoles.js +4 -0
- package/src/babel/babel_helper_directory/babel_helpers/arrayWithoutHoles/arrayWithoutHoles.js +6 -0
- package/src/babel/babel_helper_directory/babel_helpers/assertThisInitialized/assertThisInitialized.js +7 -0
- package/src/babel/babel_helper_directory/babel_helpers/asyncGeneratorDelegate/asyncGeneratorDelegate.js +55 -0
- package/src/babel/babel_helper_directory/babel_helpers/asyncIterator/asyncIterator.js +65 -0
- package/src/babel/babel_helper_directory/babel_helpers/asyncToGenerator/asyncToGenerator.js +34 -0
- package/src/babel/babel_helper_directory/babel_helpers/awaitAsyncGenerator/awaitAsyncGenerator.js +5 -0
- package/src/babel/babel_helper_directory/babel_helpers/checkInRHS/checkInRHS.js +9 -0
- package/src/babel/babel_helper_directory/babel_helpers/classApplyDescriptorDestructureSet/classApplyDescriptorDestructureSet.js +20 -0
- package/src/babel/babel_helper_directory/babel_helpers/classApplyDescriptorGet/classApplyDescriptorGet.js +6 -0
- package/src/babel/babel_helper_directory/babel_helpers/classApplyDescriptorSet/classApplyDescriptorSet.js +13 -0
- package/src/babel/babel_helper_directory/babel_helpers/classCallCheck/classCallCheck.js +5 -0
- package/src/babel/babel_helper_directory/babel_helpers/classCheckPrivateStaticAccess/classCheckPrivateStaticAccess.js +5 -0
- package/src/babel/babel_helper_directory/babel_helpers/classCheckPrivateStaticFieldDescriptor/classCheckPrivateStaticFieldDescriptor.js +6 -0
- package/src/babel/babel_helper_directory/babel_helpers/classExtractFieldDescriptor/classExtractFieldDescriptor.js +7 -0
- package/src/babel/babel_helper_directory/babel_helpers/classNameTDZError/classNameTDZError.js +4 -0
- package/src/babel/babel_helper_directory/babel_helpers/classPrivateFieldDestructureSet/classPrivateFieldDestructureSet.js +7 -0
- package/src/babel/babel_helper_directory/babel_helpers/classPrivateFieldGet/classPrivateFieldGet.js +7 -0
- package/src/babel/babel_helper_directory/babel_helpers/classPrivateFieldLooseBase/classPrivateFieldLooseBase.js +6 -0
- package/src/babel/babel_helper_directory/babel_helpers/classPrivateFieldLooseKey/classPrivateFieldLooseKey.js +5 -0
- package/src/babel/babel_helper_directory/babel_helpers/classPrivateFieldSet/classPrivateFieldSet.js +8 -0
- package/src/babel/babel_helper_directory/babel_helpers/classPrivateMethodGet/classPrivateMethodGet.js +6 -0
- package/src/babel/babel_helper_directory/babel_helpers/classPrivateMethodSet/classPrivateMethodSet.js +3 -0
- package/src/babel/babel_helper_directory/babel_helpers/classStaticPrivateFieldSpecGet/classStaticPrivateFieldSpecGet.js +9 -0
- package/src/babel/babel_helper_directory/babel_helpers/classStaticPrivateFieldSpecSet/classStaticPrivateFieldSpecSet.js +15 -0
- package/src/babel/babel_helper_directory/babel_helpers/classStaticPrivateMethodGet/classStaticPrivateMethodGet.js +6 -0
- package/src/babel/babel_helper_directory/babel_helpers/classStaticPrivateMethodSet/classStaticPrivateMethodSet.js +3 -0
- package/src/babel/babel_helper_directory/babel_helpers/construct/construct.js +16 -0
- package/src/babel/babel_helper_directory/babel_helpers/createClass/createClass.js +17 -0
- package/src/babel/babel_helper_directory/babel_helpers/createForOfIteratorHelper/createForOfIteratorHelper.js +60 -0
- package/src/babel/babel_helper_directory/babel_helpers/createForOfIteratorHelperLoose/createForOfIteratorHelperLoose.js +23 -0
- package/src/babel/babel_helper_directory/babel_helpers/createRawReactElement/createRawReactElement.js +50 -0
- package/src/babel/babel_helper_directory/babel_helpers/createSuper/createSuper.js +22 -0
- package/src/babel/babel_helper_directory/babel_helpers/decorate/decorate.js +403 -0
- package/src/babel/babel_helper_directory/babel_helpers/defaults/defaults.js +11 -0
- package/src/babel/babel_helper_directory/babel_helpers/defineAccessor/defineAccessor.js +6 -0
- package/src/babel/babel_helper_directory/babel_helpers/defineEnumerableProperties/defineEnumerableProperties.js +23 -0
- package/src/babel/babel_helper_directory/babel_helpers/defineProperty/defineProperty.js +21 -0
- package/src/babel/babel_helper_directory/babel_helpers/extends/extends.js +14 -0
- package/src/babel/babel_helper_directory/babel_helpers/get/get.js +19 -0
- package/src/babel/babel_helper_directory/babel_helpers/getPrototypeOf/getPrototypeOf.js +4 -0
- package/src/babel/babel_helper_directory/babel_helpers/identity/identity.js +3 -0
- package/src/babel/babel_helper_directory/babel_helpers/inherits/inherits.js +19 -0
- package/src/babel/babel_helper_directory/babel_helpers/inheritsLoose/inheritsLoose.js +7 -0
- package/src/babel/babel_helper_directory/babel_helpers/initializerDefineProperty/initializerDefineProperty.js +10 -0
- package/src/babel/babel_helper_directory/babel_helpers/initializerWarningHelper/initializerWarningHelper.js +6 -0
- package/src/babel/babel_helper_directory/babel_helpers/instanceof/instanceof.js +6 -0
- package/src/babel/babel_helper_directory/babel_helpers/interopRequireDefault/interopRequireDefault.js +3 -0
- package/src/babel/babel_helper_directory/babel_helpers/interopRequireWildcard/interopRequireWildcard.js +37 -0
- package/src/babel/babel_helper_directory/babel_helpers/isNativeFunction/isNativeFunction.js +4 -0
- package/src/babel/babel_helper_directory/babel_helpers/isNativeReflectConstruct/isNativeReflectConstruct.js +21 -0
- package/src/babel/babel_helper_directory/babel_helpers/iterableToArray/iterableToArray.js +7 -0
- package/src/babel/babel_helper_directory/babel_helpers/iterableToArrayLimit/iterableToArrayLimit.js +54 -0
- package/src/babel/babel_helper_directory/babel_helpers/iterableToArrayLimitLoose/iterableToArrayLimitLoose.js +16 -0
- package/src/babel/babel_helper_directory/babel_helpers/jsx/jsx.js +50 -0
- package/src/babel/babel_helper_directory/babel_helpers/maybeArrayLike/maybeArrayLike.js +10 -0
- package/src/babel/babel_helper_directory/babel_helpers/newArrowCheck/newArrowCheck.js +5 -0
- package/src/babel/babel_helper_directory/babel_helpers/nonIterableRest/nonIterableRest.js +5 -0
- package/src/babel/babel_helper_directory/babel_helpers/nonIterableSpread/nonIterableSpread.js +5 -0
- package/src/babel/babel_helper_directory/babel_helpers/objectDestructuringEmpty/objectDestructuringEmpty.js +3 -0
- package/src/babel/babel_helper_directory/babel_helpers/objectSpread/objectSpread.js +23 -0
- package/src/babel/babel_helper_directory/babel_helpers/objectSpread2/objectSpread2.js +41 -0
- package/src/babel/babel_helper_directory/babel_helpers/objectWithoutProperties/objectWithoutProperties.js +19 -0
- package/src/babel/babel_helper_directory/babel_helpers/objectWithoutPropertiesLoose/objectWithoutPropertiesLoose.js +13 -0
- package/src/babel/babel_helper_directory/babel_helpers/overloadYield/overloadYield.js +11 -0
- package/src/babel/babel_helper_directory/babel_helpers/possibleConstructorReturn/possibleConstructorReturn.js +10 -0
- package/src/babel/babel_helper_directory/babel_helpers/readOnlyError/readOnlyError.js +4 -0
- package/src/babel/babel_helper_directory/babel_helpers/regeneratorRuntime/regeneratorRuntime.js +702 -0
- package/src/babel/babel_helper_directory/babel_helpers/set/set.js +44 -0
- package/src/babel/babel_helper_directory/babel_helpers/setPrototypeOf/setPrototypeOf.js +6 -0
- package/src/babel/babel_helper_directory/babel_helpers/skipFirstGeneratorNext/skipFirstGeneratorNext.js +8 -0
- package/src/babel/babel_helper_directory/babel_helpers/slicedToArray/slicedToArray.js +10 -0
- package/src/babel/babel_helper_directory/babel_helpers/slicedToArrayLoose/slicedToArrayLoose.js +13 -0
- package/src/babel/babel_helper_directory/babel_helpers/superPropBase/superPropBase.js +10 -0
- package/src/babel/babel_helper_directory/babel_helpers/taggedTemplateLiteral/taggedTemplateLiteral.js +10 -0
- package/src/babel/babel_helper_directory/babel_helpers/taggedTemplateLiteralLoose/taggedTemplateLiteralLoose.js +7 -0
- package/src/babel/babel_helper_directory/babel_helpers/tdz/tdz.js +4 -0
- package/src/babel/babel_helper_directory/babel_helpers/temporalRef/temporalRef.js +6 -0
- package/src/babel/babel_helper_directory/babel_helpers/temporalUndefined/temporalUndefined.js +3 -0
- package/src/babel/babel_helper_directory/babel_helpers/toArray/toArray.js +10 -0
- package/src/babel/babel_helper_directory/babel_helpers/toConsumableArray/toConsumableArray.js +10 -0
- package/src/babel/babel_helper_directory/babel_helpers/toPrimitive/toPrimitive.js +10 -0
- package/src/babel/babel_helper_directory/babel_helpers/toPropertyKey/toPropertyKey.js +6 -0
- package/src/babel/babel_helper_directory/babel_helpers/typeof/typeof.js +14 -0
- package/src/babel/babel_helper_directory/babel_helpers/unsupportedIterableToArray/unsupportedIterableToArray.js +12 -0
- package/src/babel/babel_helper_directory/babel_helpers/wrapAsyncGenerator/wrapAsyncGenerator.js +8 -0
- package/src/babel/babel_helper_directory/babel_helpers/wrapNativeSuper/wrapNativeSuper.js +30 -0
- package/src/babel/babel_helper_directory/babel_helpers/wrapRegExp/wrapRegExp.js +77 -0
- package/src/babel/babel_helper_directory/babel_helpers/writeOnlyError/writeOnlyError.js +4 -0
- package/src/babel/babel_plugin_babel_helpers_as_jsenv_imports.js +53 -0
- package/src/babel/babel_plugin_structure.js +176 -0
- package/src/babel/babel_plugins_compatibility.js +432 -0
- package/src/babel/global_this/babel_plugin_global_this_injector.js +56 -0
- package/src/babel/global_this/client/global_this_js_classic.js +25 -0
- package/src/babel/global_this/client/global_this_js_module.js +21 -0
- package/src/babel/jsenv_plugin_babel.js +35 -0
- package/src/babel/new_stylesheet/babel_plugin_new_stylesheet_injector.js +149 -0
- package/src/babel/new_stylesheet/client/new_stylesheet.js +381 -0
- package/src/babel/polyfill_injection_in_babel_ast.js +41 -0
- package/src/babel/regenerator_runtime/babel_plugin_regenerator_runtime_injector.js +49 -0
- package/src/babel/regenerator_runtime/client/regenerator_runtime.js +748 -0
- package/src/css/apply_css_transpilation.js +41 -0
- package/src/css/jsenv_plugin_css_transpilation.js +17 -0
- package/src/import_assertions/jsenv_plugin_import_assertions.js +244 -0
- package/src/import_meta_resolve/jsenv_plugin_import_meta_resolve.js +48 -0
- package/src/js_module_fallback/jsenv_plugin_js_module_conversion.js +136 -0
- package/src/js_module_fallback/jsenv_plugin_js_module_fallback.js +46 -0
- package/src/js_module_fallback/jsenv_plugin_js_module_fallback_inside_html.js +240 -0
- package/src/js_module_fallback/jsenv_plugin_js_module_fallback_on_workers.js +62 -0
- package/src/jsenv_plugin_transpilation.js +54 -0
- package/src/main.js +2 -0
- package/src/top_level_await/jsenv_plugin_top_level_await.js +94 -0
package/README.md
ADDED
package/package.json
ADDED
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@jsenv/plugin-transpilation",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "TODO",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"repository": {
|
|
7
|
+
"type": "git",
|
|
8
|
+
"url": "https://github.com/jsenv/core",
|
|
9
|
+
"directory": "packages/internal/plugin-transpilation"
|
|
10
|
+
},
|
|
11
|
+
"engines": {
|
|
12
|
+
"node": ">=16.13.0"
|
|
13
|
+
},
|
|
14
|
+
"publishConfig": {
|
|
15
|
+
"access": "public"
|
|
16
|
+
},
|
|
17
|
+
"type": "module",
|
|
18
|
+
"main": "./src/main.js",
|
|
19
|
+
"files": [
|
|
20
|
+
"/src/"
|
|
21
|
+
],
|
|
22
|
+
"dependencies": {
|
|
23
|
+
"@babel/plugin-proposal-json-strings": "7.18.6",
|
|
24
|
+
"@babel/plugin-proposal-numeric-separator": "7.18.6",
|
|
25
|
+
"@babel/plugin-proposal-object-rest-spread": "7.20.7",
|
|
26
|
+
"@babel/plugin-proposal-optional-catch-binding": "7.18.6",
|
|
27
|
+
"@babel/plugin-proposal-optional-chaining": "7.21.0",
|
|
28
|
+
"@babel/plugin-proposal-unicode-property-regex": "7.18.6",
|
|
29
|
+
"@babel/plugin-syntax-import-assertions": "7.20.0",
|
|
30
|
+
"@babel/plugin-syntax-object-rest-spread": "7.8.3",
|
|
31
|
+
"@babel/plugin-syntax-optional-catch-binding": "7.8.3",
|
|
32
|
+
"@babel/plugin-transform-arrow-functions": "7.21.5",
|
|
33
|
+
"@babel/plugin-transform-block-scoped-functions": "7.18.6",
|
|
34
|
+
"@babel/plugin-transform-block-scoping": "7.21.0",
|
|
35
|
+
"@babel/plugin-transform-classes": "7.21.0",
|
|
36
|
+
"@babel/plugin-transform-computed-properties": "7.21.5",
|
|
37
|
+
"@babel/plugin-transform-destructuring": "7.21.3",
|
|
38
|
+
"@babel/plugin-transform-dotall-regex": "7.18.6",
|
|
39
|
+
"@babel/plugin-transform-duplicate-keys": "7.18.9",
|
|
40
|
+
"@babel/plugin-transform-exponentiation-operator": "7.18.6",
|
|
41
|
+
"@babel/plugin-transform-for-of": "7.21.5",
|
|
42
|
+
"@babel/plugin-transform-function-name": "7.18.9",
|
|
43
|
+
"@babel/plugin-transform-literals": "7.18.9",
|
|
44
|
+
"@babel/plugin-transform-new-target": "7.22.3",
|
|
45
|
+
"@babel/plugin-transform-object-super": "7.18.6",
|
|
46
|
+
"@babel/plugin-transform-parameters": "7.22.3",
|
|
47
|
+
"@babel/plugin-transform-regenerator": "7.21.5",
|
|
48
|
+
"@babel/plugin-transform-shorthand-properties": "7.18.6",
|
|
49
|
+
"@babel/plugin-transform-spread": "7.20.7",
|
|
50
|
+
"@babel/plugin-transform-sticky-regex": "7.18.6",
|
|
51
|
+
"@babel/plugin-transform-template-literals": "7.18.9",
|
|
52
|
+
"@babel/plugin-transform-typeof-symbol": "7.18.9",
|
|
53
|
+
"@babel/plugin-transform-unicode-regex": "7.18.6",
|
|
54
|
+
"babel-plugin-transform-async-to-promises": "0.8.18",
|
|
55
|
+
"construct-style-sheets-polyfill": "3.1.0",
|
|
56
|
+
"@jsenv/ast": "4.0.3",
|
|
57
|
+
"@jsenv/runtime-compat": "1.0.0",
|
|
58
|
+
"lightningcss": "1.20.0"
|
|
59
|
+
}
|
|
60
|
+
}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { applyBabelPlugins } from "@jsenv/ast";
|
|
2
|
+
import { composeTwoSourcemaps } from "@jsenv/sourcemap";
|
|
3
|
+
|
|
4
|
+
export const convertJsClassicToJsModule = async ({
|
|
5
|
+
isWebWorker,
|
|
6
|
+
input,
|
|
7
|
+
inputSourcemap,
|
|
8
|
+
inputUrl,
|
|
9
|
+
outputUrl,
|
|
10
|
+
}) => {
|
|
11
|
+
const { code, map } = await applyBabelPlugins({
|
|
12
|
+
babelPlugins: [[babelPluginReplaceTopLevelThis, { isWebWorker }]],
|
|
13
|
+
input,
|
|
14
|
+
inputIsJsModule: false,
|
|
15
|
+
inputUrl,
|
|
16
|
+
outputUrl,
|
|
17
|
+
});
|
|
18
|
+
const sourcemap = await composeTwoSourcemaps(inputSourcemap, map);
|
|
19
|
+
return {
|
|
20
|
+
content: code,
|
|
21
|
+
sourcemap,
|
|
22
|
+
};
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
const babelPluginReplaceTopLevelThis = () => {
|
|
26
|
+
return {
|
|
27
|
+
name: "replace-top-level-this",
|
|
28
|
+
visitor: {
|
|
29
|
+
Program: (programPath, state) => {
|
|
30
|
+
const { isWebWorker } = state.opts;
|
|
31
|
+
programPath.traverse({
|
|
32
|
+
ThisExpression: (path) => {
|
|
33
|
+
const closestFunction = path.getFunctionParent();
|
|
34
|
+
if (!closestFunction) {
|
|
35
|
+
path.replaceWithSourceString(isWebWorker ? "self" : "window");
|
|
36
|
+
}
|
|
37
|
+
},
|
|
38
|
+
});
|
|
39
|
+
},
|
|
40
|
+
},
|
|
41
|
+
};
|
|
42
|
+
};
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Js modules might not be able to import js meant to be loaded by <script>
|
|
3
|
+
* Among other things this happens for a top level this:
|
|
4
|
+
* - With <script> this is window
|
|
5
|
+
* - With an import this is undefined
|
|
6
|
+
* Example of this: https://github.com/video-dev/hls.js/issues/2911
|
|
7
|
+
*
|
|
8
|
+
* This plugin fix this issue by rewriting top level this into window
|
|
9
|
+
* and can be used like this for instance import("hls?as_js_module")
|
|
10
|
+
*/
|
|
11
|
+
|
|
12
|
+
import { urlToFilename } from "@jsenv/urls";
|
|
13
|
+
|
|
14
|
+
import { convertJsClassicToJsModule } from "./convert_js_classic_to_js_module.js";
|
|
15
|
+
|
|
16
|
+
export const jsenvPluginAsJsModule = () => {
|
|
17
|
+
return {
|
|
18
|
+
name: "jsenv:as_js_module",
|
|
19
|
+
appliesDuring: "*",
|
|
20
|
+
redirectReference: (reference) => {
|
|
21
|
+
if (reference.searchParams.has("as_js_module")) {
|
|
22
|
+
reference.expectedType = "js_module";
|
|
23
|
+
const filename = urlToFilename(reference.url);
|
|
24
|
+
const [basename] = splitFileExtension(filename);
|
|
25
|
+
reference.filename = `${basename}.mjs`;
|
|
26
|
+
}
|
|
27
|
+
},
|
|
28
|
+
fetchUrlContent: async (urlInfo, context) => {
|
|
29
|
+
const [jsClassicReference, jsClassicUrlInfo] =
|
|
30
|
+
context.getWithoutSearchParam({
|
|
31
|
+
urlInfo,
|
|
32
|
+
context,
|
|
33
|
+
searchParam: "as_js_module",
|
|
34
|
+
// override the expectedType to "js_classic"
|
|
35
|
+
// because when there is ?as_js_module it means the underlying resource
|
|
36
|
+
// is js_classic
|
|
37
|
+
expectedType: "js_classic",
|
|
38
|
+
});
|
|
39
|
+
if (!jsClassicReference) {
|
|
40
|
+
return null;
|
|
41
|
+
}
|
|
42
|
+
await context.fetchUrlContent(jsClassicUrlInfo, {
|
|
43
|
+
reference: jsClassicReference,
|
|
44
|
+
});
|
|
45
|
+
if (context.dev) {
|
|
46
|
+
context.referenceUtils.found({
|
|
47
|
+
type: "js_import",
|
|
48
|
+
subtype: jsClassicReference.subtype,
|
|
49
|
+
specifier: jsClassicReference.url,
|
|
50
|
+
expectedType: "js_classic",
|
|
51
|
+
});
|
|
52
|
+
} else if (context.build && jsClassicUrlInfo.dependents.size === 0) {
|
|
53
|
+
context.urlGraph.deleteUrlInfo(jsClassicUrlInfo.url);
|
|
54
|
+
}
|
|
55
|
+
const { content, sourcemap } = await convertJsClassicToJsModule({
|
|
56
|
+
input: jsClassicUrlInfo.content,
|
|
57
|
+
inputSourcemap: jsClassicUrlInfo.sourcemap,
|
|
58
|
+
inputUrl: jsClassicUrlInfo.url,
|
|
59
|
+
outputUrl: jsClassicUrlInfo.generatedUrl,
|
|
60
|
+
isWebWorker: isWebWorkerUrlInfo(urlInfo),
|
|
61
|
+
});
|
|
62
|
+
return {
|
|
63
|
+
content,
|
|
64
|
+
contentType: "text/javascript",
|
|
65
|
+
type: "js_module",
|
|
66
|
+
originalUrl: jsClassicUrlInfo.originalUrl,
|
|
67
|
+
originalContent: jsClassicUrlInfo.originalContent,
|
|
68
|
+
sourcemap,
|
|
69
|
+
data: jsClassicUrlInfo.data,
|
|
70
|
+
};
|
|
71
|
+
},
|
|
72
|
+
};
|
|
73
|
+
};
|
|
74
|
+
|
|
75
|
+
const isWebWorkerUrlInfo = (urlInfo) => {
|
|
76
|
+
return (
|
|
77
|
+
urlInfo.subtype === "worker" ||
|
|
78
|
+
urlInfo.subtype === "service_worker" ||
|
|
79
|
+
urlInfo.subtype === "shared_worker"
|
|
80
|
+
);
|
|
81
|
+
};
|
|
82
|
+
|
|
83
|
+
const splitFileExtension = (filename) => {
|
|
84
|
+
const dotLastIndex = filename.lastIndexOf(".");
|
|
85
|
+
if (dotLastIndex === -1) {
|
|
86
|
+
return [filename, ""];
|
|
87
|
+
}
|
|
88
|
+
return [filename.slice(0, dotLastIndex), filename.slice(dotLastIndex)];
|
|
89
|
+
};
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import { applyBabelPlugins } from "@jsenv/ast";
|
|
2
|
+
import { RUNTIME_COMPAT } from "@jsenv/runtime-compat";
|
|
3
|
+
|
|
4
|
+
import { getBaseBabelPluginStructure } from "./babel_plugin_structure.js";
|
|
5
|
+
import { babelPluginBabelHelpersAsJsenvImports } from "./babel_plugin_babel_helpers_as_jsenv_imports.js";
|
|
6
|
+
import { babelPluginNewStylesheetInjector } from "./new_stylesheet/babel_plugin_new_stylesheet_injector.js";
|
|
7
|
+
import { babelPluginGlobalThisInjector } from "./global_this/babel_plugin_global_this_injector.js";
|
|
8
|
+
import { babelPluginRegeneratorRuntimeInjector } from "./regenerator_runtime/babel_plugin_regenerator_runtime_injector.js";
|
|
9
|
+
|
|
10
|
+
export const applyJsTranspilation = async ({
|
|
11
|
+
input,
|
|
12
|
+
inputIsJsModule = false,
|
|
13
|
+
inputUrl,
|
|
14
|
+
outputUrl,
|
|
15
|
+
runtimeCompat,
|
|
16
|
+
babelHelpersAsImport = true,
|
|
17
|
+
babelOptions,
|
|
18
|
+
getImportSpecifier,
|
|
19
|
+
}) => {
|
|
20
|
+
const isSupported = (feature) => {
|
|
21
|
+
return RUNTIME_COMPAT.isSupported(runtimeCompat, feature);
|
|
22
|
+
};
|
|
23
|
+
const babelPluginStructure = getBaseBabelPluginStructure({
|
|
24
|
+
url: inputUrl,
|
|
25
|
+
isSupported,
|
|
26
|
+
isJsModule: inputIsJsModule,
|
|
27
|
+
getImportSpecifier,
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
if (!isSupported("global_this")) {
|
|
31
|
+
babelPluginStructure["global-this-injector"] = [
|
|
32
|
+
babelPluginGlobalThisInjector,
|
|
33
|
+
{ babelHelpersAsImport, getImportSpecifier },
|
|
34
|
+
];
|
|
35
|
+
}
|
|
36
|
+
if (!isSupported("async_generator_function")) {
|
|
37
|
+
babelPluginStructure["regenerator-runtime-injector"] = [
|
|
38
|
+
babelPluginRegeneratorRuntimeInjector,
|
|
39
|
+
{ babelHelpersAsImport, getImportSpecifier },
|
|
40
|
+
];
|
|
41
|
+
}
|
|
42
|
+
if (!isSupported("new_stylesheet")) {
|
|
43
|
+
babelPluginStructure["new-stylesheet-injector"] = [
|
|
44
|
+
babelPluginNewStylesheetInjector,
|
|
45
|
+
{ babelHelpersAsImport, getImportSpecifier },
|
|
46
|
+
];
|
|
47
|
+
}
|
|
48
|
+
if (
|
|
49
|
+
inputIsJsModule &&
|
|
50
|
+
babelHelpersAsImport &&
|
|
51
|
+
Object.keys(babelPluginStructure).length > 0
|
|
52
|
+
) {
|
|
53
|
+
babelPluginStructure["babel-helper-as-jsenv-import"] = [
|
|
54
|
+
babelPluginBabelHelpersAsJsenvImports,
|
|
55
|
+
{ getImportSpecifier },
|
|
56
|
+
];
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
const babelPlugins = Object.keys(babelPluginStructure).map(
|
|
60
|
+
(babelPluginName) => babelPluginStructure[babelPluginName],
|
|
61
|
+
);
|
|
62
|
+
const { code, map } = await applyBabelPlugins({
|
|
63
|
+
babelPlugins,
|
|
64
|
+
options: babelOptions,
|
|
65
|
+
input,
|
|
66
|
+
inputIsJsModule,
|
|
67
|
+
inputUrl,
|
|
68
|
+
outputUrl,
|
|
69
|
+
});
|
|
70
|
+
return {
|
|
71
|
+
content: code,
|
|
72
|
+
sourcemap: map,
|
|
73
|
+
};
|
|
74
|
+
};
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
# Babel helpers
|
|
2
|
+
|
|
3
|
+
Babel helpers are copied in there to properly appear in sourcemap.
|
|
4
|
+
|
|
5
|
+
- Last sync date: 3 May 2023
|
|
6
|
+
|
|
7
|
+
- Helpers file: https://github.com/babel/babel/blob/main/packages/babel-helpers/src/helpers.ts
|
|
8
|
+
- Individual helpers: https://github.com/babel/babel/tree/main/packages/babel-helpers/src/helpers
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Generated helpers
|
|
3
|
+
* - https://github.com/babel/babel/commits/main/packages/babel-helpers/src/helpers.ts
|
|
4
|
+
* File helpers
|
|
5
|
+
* - https://github.com/babel/babel/tree/main/packages/babel-helpers/src/helpers
|
|
6
|
+
*
|
|
7
|
+
*/
|
|
8
|
+
export const babelHelperClientDirectoryUrl = new URL(
|
|
9
|
+
"./babel_helpers/",
|
|
10
|
+
import.meta.url,
|
|
11
|
+
).href;
|
|
12
|
+
|
|
13
|
+
// we cannot use "@jsenv/core/src/*" because babel helper might be injected
|
|
14
|
+
// into node_modules not depending on "@jsenv/core"
|
|
15
|
+
export const getBabelHelperFileUrl = (babelHelperName) => {
|
|
16
|
+
const babelHelperFileUrl = new URL(
|
|
17
|
+
`./${babelHelperName}/${babelHelperName}.js`,
|
|
18
|
+
babelHelperClientDirectoryUrl,
|
|
19
|
+
).href;
|
|
20
|
+
return babelHelperFileUrl;
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
export const babelHelperNameFromUrl = (url) => {
|
|
24
|
+
if (!url.startsWith(babelHelperClientDirectoryUrl)) {
|
|
25
|
+
return null;
|
|
26
|
+
}
|
|
27
|
+
const afterBabelHelperDirectory = url.slice(
|
|
28
|
+
babelHelperClientDirectoryUrl.length,
|
|
29
|
+
);
|
|
30
|
+
const babelHelperName = afterBabelHelperDirectory.slice(
|
|
31
|
+
0,
|
|
32
|
+
afterBabelHelperDirectory.indexOf("/"),
|
|
33
|
+
);
|
|
34
|
+
return babelHelperName;
|
|
35
|
+
};
|
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
/* @minVersion 7.0.0-beta.0 */
|
|
2
|
+
|
|
3
|
+
import OverloadYield from "../overloadYield/overloadYield.js";
|
|
4
|
+
|
|
5
|
+
export default function AsyncGenerator(gen) {
|
|
6
|
+
var front, back;
|
|
7
|
+
|
|
8
|
+
function send(key, arg) {
|
|
9
|
+
return new Promise(function (resolve, reject) {
|
|
10
|
+
var request = {
|
|
11
|
+
key: key,
|
|
12
|
+
arg: arg,
|
|
13
|
+
resolve: resolve,
|
|
14
|
+
reject: reject,
|
|
15
|
+
next: null,
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
if (back) {
|
|
19
|
+
back = back.next = request;
|
|
20
|
+
} else {
|
|
21
|
+
front = back = request;
|
|
22
|
+
resume(key, arg);
|
|
23
|
+
}
|
|
24
|
+
});
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
function resume(key, arg) {
|
|
28
|
+
try {
|
|
29
|
+
var result = gen[key](arg);
|
|
30
|
+
var value = result.value;
|
|
31
|
+
var overloaded = value instanceof OverloadYield;
|
|
32
|
+
|
|
33
|
+
Promise.resolve(overloaded ? value.v : value).then(
|
|
34
|
+
function (arg) {
|
|
35
|
+
if (overloaded) {
|
|
36
|
+
// Overloaded yield requires calling into the generator twice:
|
|
37
|
+
// - first we get the iterator result wrapped in a promise
|
|
38
|
+
// (the gen[key](arg) call above)
|
|
39
|
+
// - then we await it (the Promise.resolve call above)
|
|
40
|
+
// - then we give the result back to the iterator, so that it can:
|
|
41
|
+
// * if it was an await, use its result
|
|
42
|
+
// * if it was a yield*, possibly return the `done: true` signal
|
|
43
|
+
// so that yield* knows that the iterator is finished.
|
|
44
|
+
// This needs to happen in the second call, because in the
|
|
45
|
+
// first one `done: true` was hidden in the promise and thus
|
|
46
|
+
// not visible to the (sync) yield*.
|
|
47
|
+
// The other part of this implementation is in asyncGeneratorDelegate.
|
|
48
|
+
var nextKey = key === "return" ? "return" : "next";
|
|
49
|
+
if (!value.k || arg.done) {
|
|
50
|
+
// await or end of yield*
|
|
51
|
+
return resume(nextKey, arg);
|
|
52
|
+
} else {
|
|
53
|
+
// yield*, not done
|
|
54
|
+
arg = gen[nextKey](arg).value;
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
settle(result.done ? "return" : "normal", arg);
|
|
59
|
+
},
|
|
60
|
+
function (err) {
|
|
61
|
+
resume("throw", err);
|
|
62
|
+
}
|
|
63
|
+
);
|
|
64
|
+
} catch (err) {
|
|
65
|
+
settle("throw", err);
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
function settle(type, value) {
|
|
70
|
+
switch (type) {
|
|
71
|
+
case "return":
|
|
72
|
+
front.resolve({ value: value, done: true });
|
|
73
|
+
break;
|
|
74
|
+
case "throw":
|
|
75
|
+
front.reject(value);
|
|
76
|
+
break;
|
|
77
|
+
default:
|
|
78
|
+
front.resolve({ value: value, done: false });
|
|
79
|
+
break;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
front = front.next;
|
|
83
|
+
if (front) {
|
|
84
|
+
resume(front.key, front.arg);
|
|
85
|
+
} else {
|
|
86
|
+
back = null;
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
this._invoke = send;
|
|
91
|
+
|
|
92
|
+
// Hide "return" method if generator return is not supported
|
|
93
|
+
if (typeof gen.return !== "function") {
|
|
94
|
+
this.return = undefined;
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
AsyncGenerator.prototype[
|
|
99
|
+
(typeof Symbol === "function" && Symbol.asyncIterator) || "@@asyncIterator"
|
|
100
|
+
] = function () {
|
|
101
|
+
return this;
|
|
102
|
+
};
|
|
103
|
+
|
|
104
|
+
AsyncGenerator.prototype.next = function (arg) {
|
|
105
|
+
return this._invoke("next", arg);
|
|
106
|
+
};
|
|
107
|
+
AsyncGenerator.prototype.throw = function (arg) {
|
|
108
|
+
return this._invoke("throw", arg);
|
|
109
|
+
};
|
|
110
|
+
AsyncGenerator.prototype.return = function (arg) {
|
|
111
|
+
return this._invoke("return", arg);
|
|
112
|
+
};
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
export default function _applyDecoratedDescriptor(target, property, decorators, descriptor, context){
|
|
2
|
+
var desc = {};
|
|
3
|
+
Object.keys(descriptor).forEach(function(key){
|
|
4
|
+
desc[key] = descriptor[key];
|
|
5
|
+
});
|
|
6
|
+
desc.enumerable = !!desc.enumerable;
|
|
7
|
+
desc.configurable = !!desc.configurable;
|
|
8
|
+
if ('value' in desc || desc.initializer){
|
|
9
|
+
desc.writable = true;
|
|
10
|
+
}
|
|
11
|
+
desc = decorators.slice().reverse().reduce(function(desc, decorator){
|
|
12
|
+
return decorator(target, property, desc) || desc;
|
|
13
|
+
}, desc);
|
|
14
|
+
if (context && desc.initializer !== void 0){
|
|
15
|
+
desc.value = desc.initializer ? desc.initializer.call(context) : void 0;
|
|
16
|
+
desc.initializer = undefined;
|
|
17
|
+
}
|
|
18
|
+
if (desc.initializer === void 0){
|
|
19
|
+
Object.defineProperty(target, property, desc);
|
|
20
|
+
desc = null;
|
|
21
|
+
}
|
|
22
|
+
return desc;
|
|
23
|
+
}
|