@plumeria/compiler 18.3.10 → 18.3.12
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 +42 -31
- package/package.json +2 -2
package/dist/index.js
CHANGED
|
@@ -41,6 +41,18 @@ const path = __importStar(require("path"));
|
|
|
41
41
|
const rs = __importStar(require("@rust-gear/glob"));
|
|
42
42
|
const utils_1 = require("@plumeria/utils");
|
|
43
43
|
const utils_2 = require("@plumeria/utils");
|
|
44
|
+
const unwrapExport = (node) => {
|
|
45
|
+
if (node?.type === 'ExportDeclaration')
|
|
46
|
+
return node.declaration;
|
|
47
|
+
if (node?.type === 'ExportDefaultDeclaration')
|
|
48
|
+
return node.decl;
|
|
49
|
+
if (node?.type === 'ExportDefaultExpression')
|
|
50
|
+
return node.expression;
|
|
51
|
+
return node;
|
|
52
|
+
};
|
|
53
|
+
const isFunctionNode = (node) => node?.type === 'FunctionDeclaration' ||
|
|
54
|
+
node?.type === 'FunctionExpression' ||
|
|
55
|
+
node?.type === 'ArrowFunctionExpression';
|
|
44
56
|
const isStaticArgValue = (node) => node.type === 'StringLiteral' ||
|
|
45
57
|
node.type === 'NumericLiteral' ||
|
|
46
58
|
node.type === 'BooleanLiteral' ||
|
|
@@ -241,7 +253,8 @@ function compileCSS(options) {
|
|
|
241
253
|
});
|
|
242
254
|
const scannedTables = (0, utils_1.scanAll)();
|
|
243
255
|
const processFile = (filePath) => {
|
|
244
|
-
const
|
|
256
|
+
const resourcePath = path.resolve(cwd, filePath);
|
|
257
|
+
const source = fs.readFileSync(resourcePath, 'utf-8');
|
|
245
258
|
const extractedSheets = [];
|
|
246
259
|
const ast = (0, core_1.parseSync)(source, {
|
|
247
260
|
syntax: 'typescript',
|
|
@@ -253,7 +266,6 @@ function compileCSS(options) {
|
|
|
253
266
|
const leadingBytes = Buffer.byteLength(source.slice(0, leadingLen), 'utf-8');
|
|
254
267
|
const baseByteOffset = ast.span.start - leadingBytes;
|
|
255
268
|
const localConsts = (0, utils_1.collectLocalConsts)(ast);
|
|
256
|
-
const resourcePath = path.resolve(cwd, filePath);
|
|
257
269
|
const importMap = {};
|
|
258
270
|
const keyframesImportMap = {};
|
|
259
271
|
const viewTransitionImportMap = {};
|
|
@@ -426,41 +438,40 @@ function compileCSS(options) {
|
|
|
426
438
|
localStyleAliases,
|
|
427
439
|
};
|
|
428
440
|
const componentParamNames = new Set();
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
if (
|
|
432
|
-
|
|
441
|
+
const addFirstParamName = (fn) => {
|
|
442
|
+
const p = fn.params[0];
|
|
443
|
+
if (utils_1.t.isIdentifier(p)) {
|
|
444
|
+
componentParamNames.add(p.value);
|
|
433
445
|
}
|
|
434
|
-
else if (
|
|
435
|
-
|
|
436
|
-
|
|
446
|
+
else if (typeof p === 'object' &&
|
|
447
|
+
p !== null &&
|
|
448
|
+
'pat' in p &&
|
|
449
|
+
utils_1.t.isIdentifier(p.pat)) {
|
|
450
|
+
componentParamNames.add(p.pat.value);
|
|
437
451
|
}
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
else if (typeof p === 'object' &&
|
|
451
|
-
p !== null &&
|
|
452
|
-
'pat' in p &&
|
|
453
|
-
utils_1.t.isIdentifier(p.pat)) {
|
|
454
|
-
componentParamNames.add(p.pat.value);
|
|
455
|
-
}
|
|
452
|
+
};
|
|
453
|
+
for (const node of ast.body) {
|
|
454
|
+
const statement = unwrapExport(node);
|
|
455
|
+
if (isFunctionNode(statement)) {
|
|
456
|
+
addFirstParamName(statement);
|
|
457
|
+
}
|
|
458
|
+
else if (utils_1.t.isVariableDeclaration(statement)) {
|
|
459
|
+
for (const decl of statement.declarations) {
|
|
460
|
+
if (!utils_1.t.isIdentifier(decl.id) || !decl.init)
|
|
461
|
+
continue;
|
|
462
|
+
if (isFunctionNode(decl.init))
|
|
463
|
+
addFirstParamName(decl.init);
|
|
456
464
|
}
|
|
457
465
|
}
|
|
458
466
|
}
|
|
459
467
|
const components = [];
|
|
460
468
|
for (const node of ast.body) {
|
|
461
|
-
const statement =
|
|
462
|
-
if (statement
|
|
463
|
-
components.push({
|
|
469
|
+
const statement = unwrapExport(node);
|
|
470
|
+
if (isFunctionNode(statement)) {
|
|
471
|
+
components.push({
|
|
472
|
+
name: statement.identifier?.value ?? 'default',
|
|
473
|
+
node: statement,
|
|
474
|
+
});
|
|
464
475
|
}
|
|
465
476
|
else if (utils_1.t.isVariableDeclaration(statement)) {
|
|
466
477
|
for (const decl of statement.declarations) {
|
|
@@ -797,7 +808,7 @@ function compileCSS(options) {
|
|
|
797
808
|
if (entries)
|
|
798
809
|
propPossibilities.push(...entries);
|
|
799
810
|
}
|
|
800
|
-
|
|
811
|
+
if (propPossibilities.length === 0) {
|
|
801
812
|
const filePrefix = `${resourcePath}-`;
|
|
802
813
|
for (const key of Object.keys(ctx.scannedTables.componentPropsTable || {})) {
|
|
803
814
|
if (!key.startsWith(filePrefix))
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@plumeria/compiler",
|
|
3
|
-
"version": "18.3.
|
|
3
|
+
"version": "18.3.12",
|
|
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": "^18.3.
|
|
24
|
+
"@plumeria/utils": "^18.3.12"
|
|
25
25
|
},
|
|
26
26
|
"devDependencies": {
|
|
27
27
|
"@rust-gear/glob": "1.1.1",
|