@jsenv/core 27.0.0-alpha.29 → 27.0.0-alpha.31
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,9 +1,3 @@
|
|
|
1
|
-
/*
|
|
2
|
-
* TODO:
|
|
3
|
-
* - code should also inject helper when code uses new keyword on "CSSStyleSheet"
|
|
4
|
-
* - code should also inject helper when code uses "document.adoptedStylesheets"
|
|
5
|
-
*/
|
|
6
|
-
|
|
7
1
|
import { pathToFileURL } from "node:url"
|
|
8
2
|
|
|
9
3
|
import { injectImport } from "@jsenv/utils/js_ast/babel_utils.js"
|
|
@@ -27,6 +21,18 @@ export const babelPluginNewStylesheetAsJsenvImport = (
|
|
|
27
21
|
}
|
|
28
22
|
let usesNewStylesheet = false
|
|
29
23
|
programPath.traverse({
|
|
24
|
+
NewExpression: (path) => {
|
|
25
|
+
usesNewStylesheet = isNewCssStyleSheetCall(path.node)
|
|
26
|
+
if (usesNewStylesheet) {
|
|
27
|
+
path.stop()
|
|
28
|
+
}
|
|
29
|
+
},
|
|
30
|
+
MemberExpression: (path) => {
|
|
31
|
+
usesNewStylesheet = isDocumentAdoptedStyleSheets(path.node)
|
|
32
|
+
if (usesNewStylesheet) {
|
|
33
|
+
path.stop()
|
|
34
|
+
}
|
|
35
|
+
},
|
|
30
36
|
CallExpression: (path) => {
|
|
31
37
|
if (path.node.callee.type !== "Import") {
|
|
32
38
|
// Some other function call, not import();
|
|
@@ -90,6 +96,24 @@ export const babelPluginNewStylesheetAsJsenvImport = (
|
|
|
90
96
|
}
|
|
91
97
|
}
|
|
92
98
|
|
|
99
|
+
const isNewCssStyleSheetCall = (node) => {
|
|
100
|
+
return (
|
|
101
|
+
node.type === "NewExpression" &&
|
|
102
|
+
node.callee.type === "Identifier" &&
|
|
103
|
+
node.callee.name === "CSSStyleSheet"
|
|
104
|
+
)
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
const isDocumentAdoptedStyleSheets = (node) => {
|
|
108
|
+
return (
|
|
109
|
+
node.type === "MemberExpression" &&
|
|
110
|
+
node.object.type === "Identifier" &&
|
|
111
|
+
node.object.name === "document" &&
|
|
112
|
+
node.property.type === "Identifier" &&
|
|
113
|
+
node.property.name === "adoptedStyleSheets"
|
|
114
|
+
)
|
|
115
|
+
}
|
|
116
|
+
|
|
93
117
|
const hasCssModuleQueryParam = (path) => {
|
|
94
118
|
const { node } = path
|
|
95
119
|
return (
|