@plumeria/compiler 4.2.0 → 4.2.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/dist/index.js +44 -7
- package/package.json +2 -2
package/dist/index.js
CHANGED
|
@@ -28,8 +28,45 @@ function compileCSS(options) {
|
|
|
28
28
|
console.warn(`Failed to parse ${filePath}:`, err);
|
|
29
29
|
return [];
|
|
30
30
|
}
|
|
31
|
-
const localConsts = (0, utils_1.collectLocalConsts)(ast
|
|
32
|
-
|
|
31
|
+
const localConsts = (0, utils_1.collectLocalConsts)(ast);
|
|
32
|
+
const resourcePath = filePath;
|
|
33
|
+
const importMap = {};
|
|
34
|
+
(0, utils_1.traverse)(ast, {
|
|
35
|
+
ImportDeclaration({ node }) {
|
|
36
|
+
const sourcePath = node.source.value;
|
|
37
|
+
const actualPath = (0, utils_1.resolveImportPath)(sourcePath, resourcePath);
|
|
38
|
+
if (actualPath && fs_1.default.existsSync(actualPath)) {
|
|
39
|
+
if (fs_1.default.existsSync(actualPath)) {
|
|
40
|
+
node.specifiers.forEach((specifier) => {
|
|
41
|
+
if (specifier.type === 'ImportSpecifier') {
|
|
42
|
+
const importedName = specifier.imported
|
|
43
|
+
? specifier.imported.value
|
|
44
|
+
: specifier.local.value;
|
|
45
|
+
const localName = specifier.local.value;
|
|
46
|
+
const uniqueKey = `${actualPath}-${importedName}`;
|
|
47
|
+
if (utils_1.tables.staticTable[uniqueKey]) {
|
|
48
|
+
importMap[localName] = utils_1.tables.staticTable[uniqueKey];
|
|
49
|
+
}
|
|
50
|
+
if (utils_1.tables.keyframesHashTable[uniqueKey]) {
|
|
51
|
+
importMap[localName] = utils_1.tables.keyframesHashTable[uniqueKey];
|
|
52
|
+
}
|
|
53
|
+
if (utils_1.tables.viewTransitionHashTable[uniqueKey]) {
|
|
54
|
+
importMap[localName] =
|
|
55
|
+
utils_1.tables.viewTransitionHashTable[uniqueKey];
|
|
56
|
+
}
|
|
57
|
+
if (utils_1.tables.themeTable[uniqueKey]) {
|
|
58
|
+
importMap[localName] = utils_1.tables.themeTable[uniqueKey];
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
});
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
},
|
|
65
|
+
});
|
|
66
|
+
const mergedStaticTable = Object.assign(Object.create(utils_1.tables.staticTable), localConsts, importMap);
|
|
67
|
+
const mergedKeyframesTable = Object.assign(Object.create(utils_1.tables.keyframesHashTable), importMap);
|
|
68
|
+
const mergedViewTransitionTable = Object.assign(Object.create(utils_1.tables.viewTransitionHashTable), importMap);
|
|
69
|
+
const mergedThemeTable = Object.assign(Object.create(utils_1.tables.themeTable), importMap);
|
|
33
70
|
const localCreateStyles = {};
|
|
34
71
|
(0, utils_1.traverse)(ast, {
|
|
35
72
|
VariableDeclarator({ node }) {
|
|
@@ -41,7 +78,7 @@ function compileCSS(options) {
|
|
|
41
78
|
utils_1.t.isIdentifier(node.init.callee.property, { name: 'create' }) &&
|
|
42
79
|
node.init.arguments.length === 1 &&
|
|
43
80
|
utils_1.t.isObjectExpression(node.init.arguments[0].expression)) {
|
|
44
|
-
const obj = (0, utils_1.objectExpressionToObject)(node.init.arguments[0].expression,
|
|
81
|
+
const obj = (0, utils_1.objectExpressionToObject)(node.init.arguments[0].expression, mergedStaticTable, mergedKeyframesTable, mergedViewTransitionTable, mergedThemeTable);
|
|
45
82
|
if (obj) {
|
|
46
83
|
localCreateStyles[node.id.value] = obj;
|
|
47
84
|
Object.entries(obj).forEach(([key, style]) => {
|
|
@@ -63,7 +100,7 @@ function compileCSS(options) {
|
|
|
63
100
|
const extractStylesFromExpression = (expr) => {
|
|
64
101
|
const results = [];
|
|
65
102
|
if (utils_1.t.isObjectExpression(expr)) {
|
|
66
|
-
const obj = (0, utils_1.objectExpressionToObject)(expr,
|
|
103
|
+
const obj = (0, utils_1.objectExpressionToObject)(expr, mergedStaticTable, mergedKeyframesTable, mergedViewTransitionTable, mergedThemeTable);
|
|
67
104
|
if (obj)
|
|
68
105
|
results.push(obj);
|
|
69
106
|
}
|
|
@@ -133,14 +170,14 @@ function compileCSS(options) {
|
|
|
133
170
|
else if (callee.property.value === 'keyframes' &&
|
|
134
171
|
args.length > 0 &&
|
|
135
172
|
utils_1.t.isObjectExpression(args[0].expression)) {
|
|
136
|
-
const obj = (0, utils_1.objectExpressionToObject)(args[0].expression,
|
|
173
|
+
const obj = (0, utils_1.objectExpressionToObject)(args[0].expression, mergedStaticTable, mergedKeyframesTable, mergedViewTransitionTable, mergedThemeTable);
|
|
137
174
|
const hash = (0, zss_engine_1.genBase36Hash)(obj, 1, 8);
|
|
138
175
|
utils_1.tables.keyframesObjectTable[hash] = obj;
|
|
139
176
|
}
|
|
140
177
|
else if (callee.property.value === 'viewTransition' &&
|
|
141
178
|
args.length > 0 &&
|
|
142
179
|
utils_1.t.isObjectExpression(args[0].expression)) {
|
|
143
|
-
const obj = (0, utils_1.objectExpressionToObject)(args[0].expression,
|
|
180
|
+
const obj = (0, utils_1.objectExpressionToObject)(args[0].expression, mergedStaticTable, mergedKeyframesTable, mergedViewTransitionTable, mergedThemeTable);
|
|
144
181
|
const hash = (0, zss_engine_1.genBase36Hash)(obj, 1, 8);
|
|
145
182
|
utils_1.tables.viewTransitionObjectTable[hash] = obj;
|
|
146
183
|
(0, utils_1.extractOndemandStyles)(obj, extractedSheets);
|
|
@@ -149,7 +186,7 @@ function compileCSS(options) {
|
|
|
149
186
|
else if (callee.property.value === 'createTheme' &&
|
|
150
187
|
args.length > 0 &&
|
|
151
188
|
utils_1.t.isObjectExpression(args[0].expression)) {
|
|
152
|
-
const obj = (0, utils_1.objectExpressionToObject)(args[0].expression,
|
|
189
|
+
const obj = (0, utils_1.objectExpressionToObject)(args[0].expression, mergedStaticTable, mergedKeyframesTable, mergedViewTransitionTable, mergedThemeTable);
|
|
153
190
|
const themeHash = (0, zss_engine_1.genBase36Hash)(obj, 1, 8);
|
|
154
191
|
utils_1.tables.createThemeObjectTable[themeHash] = obj;
|
|
155
192
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@plumeria/compiler",
|
|
3
|
-
"version": "4.2.
|
|
3
|
+
"version": "4.2.1",
|
|
4
4
|
"description": "Plumeria swc based compiler for statically extracting css",
|
|
5
5
|
"author": "Refirst 11",
|
|
6
6
|
"license": "MIT",
|
|
@@ -21,7 +21,7 @@
|
|
|
21
21
|
"dist/"
|
|
22
22
|
],
|
|
23
23
|
"dependencies": {
|
|
24
|
-
"@plumeria/utils": "^4.2.
|
|
24
|
+
"@plumeria/utils": "^4.2.1"
|
|
25
25
|
},
|
|
26
26
|
"devDependencies": {
|
|
27
27
|
"@swc/core": "1.15.8",
|