Skip to content

Commit 1bf3484

Browse files
committed
work
1 parent 981909b commit 1bf3484

16 files changed

Lines changed: 2995 additions & 2615 deletions

File tree

dist/build/build.js

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8360,6 +8360,12 @@ const jsenvPluginImportMetaCss = () => {
83608360
return null;
83618361
}
83628362
if (urlInfo.context.build) {
8363+
if (hasModuleScopeAssignment(urlInfo.contentAst)) {
8364+
urlInfo.contentSideEffects.push({
8365+
has: true,
8366+
reason: "import.meta.css assigned at module scope",
8367+
});
8368+
}
83638369
const packageName = urlInfo.packageName;
83648370
const packageDirectoryUrl =
83658371
urlInfo.packageDirectoryUrl || urlInfo.context.rootDirectoryUrl;
@@ -8403,6 +8409,28 @@ const jsenvPluginImportMetaCss = () => {
84038409
};
84048410
};
84058411

8412+
// A stylesheet assigned at module scope is adopted when the module runs: that
8413+
// assignment IS the module's side effect. It has to be told, because a
8414+
// package.json "sideEffects" list is authoritative once it exists — a module
8415+
// it does not name is dropped whole when it is imported for nothing else, and
8416+
// its css silently leaves the build.
8417+
const hasModuleScopeAssignment = (ast) => {
8418+
for (const node of ast.body) {
8419+
if (node.type !== "ExpressionStatement") {
8420+
continue;
8421+
}
8422+
const { expression } = node;
8423+
if (
8424+
expression.type === "AssignmentExpression" &&
8425+
expression.operator === "=" &&
8426+
getImportMetaPropertyName(expression.left) === "css"
8427+
) {
8428+
return true;
8429+
}
8430+
}
8431+
return false;
8432+
};
8433+
84068434
const babelPluginRewriteImportMetaCssAssignment = (
84078435
{ types: t },
84088436
{ relativeUrl },

dist/start_dev_server/start_dev_server.js

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6179,6 +6179,12 @@ const jsenvPluginImportMetaCss = () => {
61796179
return null;
61806180
}
61816181
if (urlInfo.context.build) {
6182+
if (hasModuleScopeAssignment(urlInfo.contentAst)) {
6183+
urlInfo.contentSideEffects.push({
6184+
has: true,
6185+
reason: "import.meta.css assigned at module scope",
6186+
});
6187+
}
61826188
const packageName = urlInfo.packageName;
61836189
const packageDirectoryUrl =
61846190
urlInfo.packageDirectoryUrl || urlInfo.context.rootDirectoryUrl;
@@ -6222,6 +6228,28 @@ const jsenvPluginImportMetaCss = () => {
62226228
};
62236229
};
62246230

6231+
// A stylesheet assigned at module scope is adopted when the module runs: that
6232+
// assignment IS the module's side effect. It has to be told, because a
6233+
// package.json "sideEffects" list is authoritative once it exists — a module
6234+
// it does not name is dropped whole when it is imported for nothing else, and
6235+
// its css silently leaves the build.
6236+
const hasModuleScopeAssignment = (ast) => {
6237+
for (const node of ast.body) {
6238+
if (node.type !== "ExpressionStatement") {
6239+
continue;
6240+
}
6241+
const { expression } = node;
6242+
if (
6243+
expression.type === "AssignmentExpression" &&
6244+
expression.operator === "=" &&
6245+
getImportMetaPropertyName(expression.left) === "css"
6246+
) {
6247+
return true;
6248+
}
6249+
}
6250+
return false;
6251+
};
6252+
62256253
const babelPluginRewriteImportMetaCssAssignment = (
62266254
{ types: t },
62276255
{ relativeUrl },

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@jsenv/core",
3-
"version": "41.4.26",
3+
"version": "41.4.27",
44
"type": "module",
55
"description": "Tool to develop, test and build js projects",
66
"repository": {

0 commit comments

Comments
 (0)