@jsenv/plugin-transpilation 1.3.16 → 1.4.1
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/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@jsenv/plugin-transpilation",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.4.1",
|
|
4
4
|
"description": "TODO",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": {
|
|
@@ -51,8 +51,8 @@
|
|
|
51
51
|
"@babel/plugin-transform-template-literals": "7.24.7",
|
|
52
52
|
"@babel/plugin-transform-typeof-symbol": "7.24.7",
|
|
53
53
|
"@babel/plugin-transform-unicode-regex": "7.24.7",
|
|
54
|
-
"@jsenv/ast": "6.
|
|
55
|
-
"@jsenv/js-module-fallback": "1.3.
|
|
54
|
+
"@jsenv/ast": "6.1.1",
|
|
55
|
+
"@jsenv/js-module-fallback": "1.3.18",
|
|
56
56
|
"@jsenv/runtime-compat": "1.3.0",
|
|
57
57
|
"babel-plugin-transform-async-to-promises": "0.8.18",
|
|
58
58
|
"construct-style-sheets-polyfill": "3.1.0",
|
|
@@ -20,7 +20,7 @@ export const analyzeConstructableStyleSheetUsage = (urlInfo) => {
|
|
|
20
20
|
// import('./' + moduleName)
|
|
21
21
|
return false;
|
|
22
22
|
}
|
|
23
|
-
if (
|
|
23
|
+
if (hasImportTypeCssAttribute(node)) {
|
|
24
24
|
return node;
|
|
25
25
|
}
|
|
26
26
|
if (hasCssModuleQueryParam(source)) {
|
|
@@ -33,7 +33,7 @@ export const analyzeConstructableStyleSheetUsage = (urlInfo) => {
|
|
|
33
33
|
if (hasCssModuleQueryParam(source)) {
|
|
34
34
|
return source;
|
|
35
35
|
}
|
|
36
|
-
if (
|
|
36
|
+
if (hasImportTypeCssAttribute(node)) {
|
|
37
37
|
return node;
|
|
38
38
|
}
|
|
39
39
|
return false;
|
|
@@ -95,20 +95,18 @@ const hasCssModuleQueryParam = (node) => {
|
|
|
95
95
|
);
|
|
96
96
|
};
|
|
97
97
|
|
|
98
|
-
const
|
|
99
|
-
const
|
|
100
|
-
|
|
101
|
-
);
|
|
102
|
-
return Boolean(importAssertionsDescriptor.type === "css");
|
|
98
|
+
const hasImportTypeCssAttribute = (node) => {
|
|
99
|
+
const importAttributes = getImportAttributes(node);
|
|
100
|
+
return Boolean(importAttributes.type === "css");
|
|
103
101
|
};
|
|
104
102
|
|
|
105
|
-
const
|
|
106
|
-
const
|
|
107
|
-
if (
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
103
|
+
const getImportAttributes = (importNode) => {
|
|
104
|
+
const importAttributes = {};
|
|
105
|
+
if (importNode.attributes) {
|
|
106
|
+
importNode.attributes.forEach((importAttributeNode) => {
|
|
107
|
+
importAttributes[importAttributeNode.key.name] =
|
|
108
|
+
importAttributeNode.value.value;
|
|
111
109
|
});
|
|
112
110
|
}
|
|
113
|
-
return
|
|
111
|
+
return importAttributes;
|
|
114
112
|
};
|
|
@@ -3,17 +3,17 @@
|
|
|
3
3
|
* ```js
|
|
4
4
|
* const file = "./style.css"
|
|
5
5
|
* const type = "css"
|
|
6
|
-
* import(file, {
|
|
6
|
+
* import(file, { with: { type }})
|
|
7
7
|
* ```
|
|
8
8
|
* Jsenv could throw an error when it knows some browsers in runtimeCompat
|
|
9
|
-
* do not support import
|
|
9
|
+
* do not support import attributes
|
|
10
10
|
* But for now (as it is simpler) we let the browser throw the error
|
|
11
11
|
*/
|
|
12
12
|
|
|
13
13
|
import { urlToFilename, injectQueryParams } from "@jsenv/urls";
|
|
14
14
|
import { JS_QUOTES } from "@jsenv/utils/src/string/js_quotes.js";
|
|
15
15
|
|
|
16
|
-
export const
|
|
16
|
+
export const jsenvPluginImportAttributes = ({
|
|
17
17
|
json = "auto",
|
|
18
18
|
css = "auto",
|
|
19
19
|
text = "auto",
|
|
@@ -36,17 +36,17 @@ export const jsenvPluginImportAssertions = ({
|
|
|
36
36
|
} else {
|
|
37
37
|
const { importTypeAttributeNode } = reference.astInfo;
|
|
38
38
|
const content = reference.ownerUrlInfo.content;
|
|
39
|
-
const
|
|
40
|
-
"
|
|
41
|
-
importTypeAttributeNode.start - "
|
|
39
|
+
const withKeywordStart = content.indexOf(
|
|
40
|
+
"with",
|
|
41
|
+
importTypeAttributeNode.start - " with { ".length,
|
|
42
42
|
);
|
|
43
|
-
const
|
|
43
|
+
const withKeywordEnd = content.indexOf(
|
|
44
44
|
"}",
|
|
45
45
|
importTypeAttributeNode.end,
|
|
46
46
|
);
|
|
47
47
|
magicSource.remove({
|
|
48
|
-
start:
|
|
49
|
-
end:
|
|
48
|
+
start: withKeywordStart,
|
|
49
|
+
end: withKeywordEnd + 1,
|
|
50
50
|
});
|
|
51
51
|
}
|
|
52
52
|
};
|
|
@@ -7,14 +7,14 @@
|
|
|
7
7
|
* of this plugin
|
|
8
8
|
*/
|
|
9
9
|
|
|
10
|
-
import {
|
|
10
|
+
import { jsenvPluginImportAttributes } from "./import_attributes/jsenv_plugin_import_attributes.js";
|
|
11
11
|
import { jsenvPluginBabel } from "./babel/jsenv_plugin_babel.js";
|
|
12
12
|
import { jsenvPluginJsModuleFallback } from "./js_module_fallback/jsenv_plugin_js_module_fallback.js";
|
|
13
13
|
import { jsenvPluginAsJsModule } from "./as_js_module/jsenv_plugin_as_js_module.js";
|
|
14
14
|
import { jsenvPluginCssTranspilation } from "./css/jsenv_plugin_css_transpilation.js";
|
|
15
15
|
|
|
16
16
|
export const jsenvPluginTranspilation = ({
|
|
17
|
-
|
|
17
|
+
importAttributes = true,
|
|
18
18
|
css = true, // TODO
|
|
19
19
|
// build sets jsModuleFallback: false during first step of the build
|
|
20
20
|
// and re-enable it in the second phase (when performing the bundling)
|
|
@@ -22,8 +22,8 @@ export const jsenvPluginTranspilation = ({
|
|
|
22
22
|
jsModuleFallback = true,
|
|
23
23
|
babelHelpersAsImport = true,
|
|
24
24
|
}) => {
|
|
25
|
-
if (
|
|
26
|
-
|
|
25
|
+
if (importAttributes === true) {
|
|
26
|
+
importAttributes = {};
|
|
27
27
|
}
|
|
28
28
|
if (jsModuleFallback === true) {
|
|
29
29
|
jsModuleFallback = {};
|
|
@@ -35,8 +35,8 @@ export const jsenvPluginTranspilation = ({
|
|
|
35
35
|
}),
|
|
36
36
|
jsenvPluginAsJsModule(),
|
|
37
37
|
...(jsModuleFallback ? [jsenvPluginJsModuleFallback()] : []),
|
|
38
|
-
...(
|
|
39
|
-
? [
|
|
38
|
+
...(importAttributes
|
|
39
|
+
? [jsenvPluginImportAttributes(importAttributes)]
|
|
40
40
|
: []),
|
|
41
41
|
|
|
42
42
|
...(css ? [jsenvPluginCssTranspilation()] : []),
|