@plumeria/compiler 0.25.5 → 0.27.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/dist/extract.js +51 -5
- package/dist/index.js +3 -5
- package/package.json +2 -1
package/dist/extract.js
CHANGED
|
@@ -158,7 +158,42 @@ function expressionToString(expr) {
|
|
|
158
158
|
console.warn(`css.props: Argument unsupported ${expr.type}: Use css.create instead.`);
|
|
159
159
|
return '';
|
|
160
160
|
}
|
|
161
|
-
async function
|
|
161
|
+
async function extractCreatedStyleKeys(ast) {
|
|
162
|
+
const createdStylesMap = new Map();
|
|
163
|
+
await visit(ast, {
|
|
164
|
+
VariableDeclarator: (node) => {
|
|
165
|
+
if (node.id.type === 'Identifier' &&
|
|
166
|
+
node.init &&
|
|
167
|
+
node.init.type === 'CallExpression' &&
|
|
168
|
+
node.init.callee.type === 'MemberExpression' &&
|
|
169
|
+
node.init.callee.object.type === 'Identifier' &&
|
|
170
|
+
node.init.callee.object.value === 'css' &&
|
|
171
|
+
node.init.callee.property.type === 'Identifier' &&
|
|
172
|
+
node.init.callee.property.value === 'create' &&
|
|
173
|
+
node.init.arguments.length > 0) {
|
|
174
|
+
const variableName = node.id.value;
|
|
175
|
+
const createArg = node.init.arguments[0].expression;
|
|
176
|
+
if (createArg && createArg.type === 'ObjectExpression') {
|
|
177
|
+
const keys = [];
|
|
178
|
+
for (const prop of createArg.properties) {
|
|
179
|
+
if (prop.type === 'KeyValueProperty' &&
|
|
180
|
+
prop.key.type === 'Identifier') {
|
|
181
|
+
keys.push(prop.key.value);
|
|
182
|
+
}
|
|
183
|
+
else if (prop.type === 'Identifier') {
|
|
184
|
+
keys.push(prop.value);
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
if (keys.length > 0) {
|
|
188
|
+
createdStylesMap.set(variableName, keys);
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
},
|
|
193
|
+
});
|
|
194
|
+
return createdStylesMap;
|
|
195
|
+
}
|
|
196
|
+
async function extractCssProps(ast, code, createdStylesMap) {
|
|
162
197
|
const propsMatches = [];
|
|
163
198
|
if (code && !code.includes('css.props')) {
|
|
164
199
|
return propsMatches;
|
|
@@ -178,9 +213,18 @@ async function extractCssProps(ast, code) {
|
|
|
178
213
|
if (arg.expression.type === 'ConditionalExpression' ||
|
|
179
214
|
(arg.expression.type === 'BinaryExpression' &&
|
|
180
215
|
arg.expression.operator === '&&')) {
|
|
181
|
-
const styles =
|
|
216
|
+
const styles = extractStyleObjectsFromExpression(arg.expression);
|
|
182
217
|
conditionalStyleObjects.push(...styles);
|
|
183
218
|
}
|
|
219
|
+
else if (arg.expression.type === 'MemberExpression' &&
|
|
220
|
+
arg.expression.property.type === 'Computed' &&
|
|
221
|
+
arg.expression.object.type === 'Identifier') {
|
|
222
|
+
const styleVarName = arg.expression.object.value;
|
|
223
|
+
const styleKeys = createdStylesMap.get(styleVarName);
|
|
224
|
+
if (styleKeys) {
|
|
225
|
+
propsMatches.push(...styleKeys.map((key) => `css.props(${styleVarName}.${key})`));
|
|
226
|
+
}
|
|
227
|
+
}
|
|
184
228
|
else {
|
|
185
229
|
const argStr = expressionToString(arg.expression);
|
|
186
230
|
if (argStr) {
|
|
@@ -207,7 +251,7 @@ async function extractCssProps(ast, code) {
|
|
|
207
251
|
catch (e) {
|
|
208
252
|
console.error(`Failed to parse code to extract css.props: ${e}`);
|
|
209
253
|
}
|
|
210
|
-
return propsMatches;
|
|
254
|
+
return [...new Set(propsMatches)];
|
|
211
255
|
}
|
|
212
256
|
function extractStyleObjectsFromExpression(expression) {
|
|
213
257
|
switch (expression.type) {
|
|
@@ -415,7 +459,8 @@ async function extractVueAndSvelte(filePath) {
|
|
|
415
459
|
syntax: 'typescript',
|
|
416
460
|
tsx: true,
|
|
417
461
|
});
|
|
418
|
-
const
|
|
462
|
+
const createdStylesMap = await extractCreatedStyleKeys(ast);
|
|
463
|
+
const propsFromScript = await extractCssProps(ast, code, createdStylesMap);
|
|
419
464
|
const propsFromTemplate = extractCssPropsFromTemplate(code);
|
|
420
465
|
const propsMatches = [...new Set([...propsFromScript, ...propsFromTemplate])];
|
|
421
466
|
const calls = propsMatches
|
|
@@ -455,6 +500,7 @@ async function extractTSFile(filePath) {
|
|
|
455
500
|
syntax: 'typescript',
|
|
456
501
|
tsx: true,
|
|
457
502
|
});
|
|
503
|
+
const createdStylesMap = await extractCreatedStyleKeys(ast);
|
|
458
504
|
const importSection = await extractImportDeclarations(ast);
|
|
459
505
|
const staticVariableSection = await extractStaticStringLiteralVariable(ast);
|
|
460
506
|
const cssCreateSection = await extractCssMethod(ast, 'create', code);
|
|
@@ -462,7 +508,7 @@ async function extractTSFile(filePath) {
|
|
|
462
508
|
const cssViewTransitionSection = await extractCssMethod(ast, 'viewTransition', code);
|
|
463
509
|
const cssDefineConstsSection = await extractCssMethod(ast, 'defineConsts', code);
|
|
464
510
|
const cssDefineTokensSection = await extractCssMethod(ast, 'defineTokens', code);
|
|
465
|
-
const propsMatches = await extractCssProps(ast, code);
|
|
511
|
+
const propsMatches = await extractCssProps(ast, code, createdStylesMap);
|
|
466
512
|
const calls = propsMatches
|
|
467
513
|
.filter(Boolean)
|
|
468
514
|
.map((call) => `${call};`)
|
package/dist/index.js
CHANGED
|
@@ -8,6 +8,7 @@ const promises_1 = require("fs/promises");
|
|
|
8
8
|
const postcss_1 = __importDefault(require("postcss"));
|
|
9
9
|
const postcss_combine_media_query_1 = __importDefault(require("postcss-combine-media-query"));
|
|
10
10
|
const execute_1 = require("rscute/execute");
|
|
11
|
+
const glob_1 = require("@rust-gear/glob");
|
|
11
12
|
const lightningcss_1 = require("lightningcss");
|
|
12
13
|
const core_1 = require("@swc/core");
|
|
13
14
|
const find_up_1 = require("find-up");
|
|
@@ -185,8 +186,7 @@ async function main() {
|
|
|
185
186
|
const startTime = performance.now();
|
|
186
187
|
await cleanUp();
|
|
187
188
|
const scanRoot = process.cwd();
|
|
188
|
-
const files =
|
|
189
|
-
for await (const entry of (0, promises_1.glob)('**/*.{js,jsx,ts,tsx,vue,svelte}', {
|
|
189
|
+
const files = (0, glob_1.globSync)('**/*.{js,jsx,ts,tsx,vue,svelte}', {
|
|
190
190
|
cwd: scanRoot,
|
|
191
191
|
exclude: [
|
|
192
192
|
'**/node_modules/**',
|
|
@@ -194,9 +194,7 @@ async function main() {
|
|
|
194
194
|
'**/build/**',
|
|
195
195
|
'**/.next/**',
|
|
196
196
|
],
|
|
197
|
-
})
|
|
198
|
-
files.push(entry);
|
|
199
|
-
}
|
|
197
|
+
});
|
|
200
198
|
const projectName = path_1.default.basename(projectRoot);
|
|
201
199
|
const filesSupportExtensions = await Promise.all(files.map(async (file) => {
|
|
202
200
|
const ext = path_1.default.extname(file);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@plumeria/compiler",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.27.0",
|
|
4
4
|
"description": "Plumeria Rust-based compiler",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -16,6 +16,7 @@
|
|
|
16
16
|
"css": "./bin/css.js"
|
|
17
17
|
},
|
|
18
18
|
"dependencies": {
|
|
19
|
+
"@rust-gear/glob": "^0.2.4",
|
|
19
20
|
"@swc/core": "1.15.2",
|
|
20
21
|
"find-up": "^8.0.0",
|
|
21
22
|
"lightningcss": "^1.30.2",
|