@plumeria/utils 6.0.1 → 6.1.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.
Files changed (2) hide show
  1. package/dist/parser.js +98 -53
  2. package/package.json +1 -1
package/dist/parser.js CHANGED
@@ -473,7 +473,7 @@ function scanAll() {
473
473
  continue;
474
474
  }
475
475
  const source = fs_1.default.readFileSync(filePath, 'utf8');
476
- if (!source.includes('css.')) {
476
+ if (!source.includes('@plumeria/core')) {
477
477
  fileCache[filePath] = {
478
478
  mtimeMs: stats.mtimeMs,
479
479
  staticTable: {},
@@ -507,6 +507,33 @@ function scanAll() {
507
507
  const localCreateObjectTable = {};
508
508
  const localVariantsHashTable = {};
509
509
  const localVariantsObjectTable = {};
510
+ const plumeriaAliases = {};
511
+ for (const node of ast.body) {
512
+ if (node.type === 'ImportDeclaration') {
513
+ const sourceValue = node.source.value;
514
+ if (sourceValue === '@plumeria/core') {
515
+ node.specifiers.forEach((specifier) => {
516
+ if (specifier.type === 'ImportNamespaceSpecifier') {
517
+ if (specifier.local) {
518
+ plumeriaAliases[specifier.local.value] = 'NAMESPACE';
519
+ }
520
+ }
521
+ else if (specifier.type === 'ImportSpecifier') {
522
+ const importedName = specifier.imported
523
+ ? specifier.imported.value
524
+ : specifier.local.value;
525
+ const localName = specifier.local.value;
526
+ plumeriaAliases[localName] = importedName;
527
+ }
528
+ else if (specifier.type === 'ImportDefaultSpecifier') {
529
+ if (specifier.local) {
530
+ plumeriaAliases[specifier.local.value] = 'NAMESPACE';
531
+ }
532
+ }
533
+ });
534
+ }
535
+ }
536
+ }
510
537
  for (const node of ast.body) {
511
538
  let declarations = [];
512
539
  if (exports.t.isVariableDeclaration(node)) {
@@ -521,61 +548,79 @@ function scanAll() {
521
548
  exports.t.isIdentifier(decl.id) &&
522
549
  decl.init &&
523
550
  exports.t.isCallExpression(decl.init) &&
524
- exports.t.isMemberExpression(decl.init.callee) &&
525
- exports.t.isIdentifier(decl.init.callee.object, { name: 'css' }) &&
526
- exports.t.isIdentifier(decl.init.callee.property) &&
527
- decl.init.arguments.length > 0 &&
528
- exports.t.isObjectExpression(decl.init.arguments[0].expression)) {
529
- const method = decl.init.callee.property.value;
530
- const name = decl.id.value;
531
- const init = decl.init;
532
- const resolveVariable = (name) => {
533
- const hash = localCreateHashTable[name];
534
- if (hash && localCreateObjectTable[hash]) {
535
- return localCreateObjectTable[hash];
551
+ exports.t.isCallExpression(decl.init)) {
552
+ const callee = decl.init.callee;
553
+ let method;
554
+ if (exports.t.isMemberExpression(callee) &&
555
+ exports.t.isIdentifier(callee.object) &&
556
+ exports.t.isIdentifier(callee.property)) {
557
+ const objectName = callee.object.value;
558
+ const propertyName = callee.property.value;
559
+ const alias = plumeriaAliases[objectName];
560
+ if (alias === 'NAMESPACE' || objectName === 'css') {
561
+ method = propertyName;
536
562
  }
537
- return undefined;
538
- };
539
- const obj = objectExpressionToObject(init.arguments[0].expression, localStaticTable, localKeyframesHashTable, localViewTransitionHashTable, localThemeTable, localCreateHashTable, localVariantsHashTable, resolveVariable);
540
- const uniqueKey = `${filePath}-${name}`;
541
- if (method === 'createStatic') {
542
- localStaticTable[name] = obj;
543
- localTables.staticTable[uniqueKey] = obj;
544
- }
545
- else if (method === 'keyframes') {
546
- const hash = (0, zss_engine_1.genBase36Hash)(obj, 1, 8);
547
- localKeyframesHashTable[name] = hash;
548
- localTables.keyframesHashTable[uniqueKey] = hash;
549
- localTables.keyframesObjectTable[hash] = obj;
550
- localKeyframesObjectTable[hash] = obj;
551
- }
552
- else if (method === 'viewTransition') {
553
- const hash = (0, zss_engine_1.genBase36Hash)(obj, 1, 8);
554
- localViewTransitionHashTable[name] = hash;
555
- localTables.viewTransitionHashTable[uniqueKey] = hash;
556
- localTables.viewTransitionObjectTable[hash] = obj;
557
- localViewTransitionObjectTable[hash] = obj;
558
563
  }
559
- else if (method === 'createTheme') {
560
- const hash = (0, zss_engine_1.genBase36Hash)(obj, 1, 8);
561
- localThemeTable[name] = obj;
562
- localTables.themeTable[uniqueKey] = obj;
563
- localTables.createThemeObjectTable[hash] = obj;
564
- localCreateThemeObjectTable[hash] = obj;
565
- }
566
- else if (method === 'create') {
567
- const hash = (0, zss_engine_1.genBase36Hash)(obj, 1, 8);
568
- localCreateHashTable[name] = hash;
569
- localTables.createHashTable[uniqueKey] = hash;
570
- localTables.createObjectTable[hash] = obj;
571
- localCreateObjectTable[hash] = obj;
564
+ else if (exports.t.isIdentifier(callee)) {
565
+ const calleeName = callee.value;
566
+ const originalName = plumeriaAliases[calleeName];
567
+ if (originalName) {
568
+ method = originalName;
569
+ }
572
570
  }
573
- else if (method === 'variants') {
574
- const hash = (0, zss_engine_1.genBase36Hash)(obj, 1, 8);
575
- localVariantsHashTable[name] = hash;
576
- localTables.variantsHashTable[uniqueKey] = hash;
577
- localTables.variantsObjectTable[hash] = obj;
578
- localVariantsObjectTable[hash] = obj;
571
+ if (method &&
572
+ decl.init.arguments.length > 0 &&
573
+ exports.t.isObjectExpression(decl.init.arguments[0].expression)) {
574
+ const name = decl.id.value;
575
+ const init = decl.init;
576
+ const resolveVariable = (name) => {
577
+ const hash = localCreateHashTable[name];
578
+ if (hash && localCreateObjectTable[hash]) {
579
+ return localCreateObjectTable[hash];
580
+ }
581
+ return undefined;
582
+ };
583
+ const obj = objectExpressionToObject(init.arguments[0].expression, localStaticTable, localKeyframesHashTable, localViewTransitionHashTable, localThemeTable, localCreateHashTable, localVariantsHashTable, resolveVariable);
584
+ const uniqueKey = `${filePath}-${name}`;
585
+ if (method === 'createStatic') {
586
+ localStaticTable[name] = obj;
587
+ localTables.staticTable[uniqueKey] = obj;
588
+ }
589
+ else if (method === 'keyframes') {
590
+ const hash = (0, zss_engine_1.genBase36Hash)(obj, 1, 8);
591
+ localKeyframesHashTable[name] = hash;
592
+ localTables.keyframesHashTable[uniqueKey] = hash;
593
+ localTables.keyframesObjectTable[hash] = obj;
594
+ localKeyframesObjectTable[hash] = obj;
595
+ }
596
+ else if (method === 'viewTransition') {
597
+ const hash = (0, zss_engine_1.genBase36Hash)(obj, 1, 8);
598
+ localViewTransitionHashTable[name] = hash;
599
+ localTables.viewTransitionHashTable[uniqueKey] = hash;
600
+ localTables.viewTransitionObjectTable[hash] = obj;
601
+ localViewTransitionObjectTable[hash] = obj;
602
+ }
603
+ else if (method === 'createTheme') {
604
+ const hash = (0, zss_engine_1.genBase36Hash)(obj, 1, 8);
605
+ localThemeTable[name] = obj;
606
+ localTables.themeTable[uniqueKey] = obj;
607
+ localTables.createThemeObjectTable[hash] = obj;
608
+ localCreateThemeObjectTable[hash] = obj;
609
+ }
610
+ else if (method === 'create') {
611
+ const hash = (0, zss_engine_1.genBase36Hash)(obj, 1, 8);
612
+ localCreateHashTable[name] = hash;
613
+ localTables.createHashTable[uniqueKey] = hash;
614
+ localTables.createObjectTable[hash] = obj;
615
+ localCreateObjectTable[hash] = obj;
616
+ }
617
+ else if (method === 'variants') {
618
+ const hash = (0, zss_engine_1.genBase36Hash)(obj, 1, 8);
619
+ localVariantsHashTable[name] = hash;
620
+ localTables.variantsHashTable[uniqueKey] = hash;
621
+ localTables.variantsObjectTable[hash] = obj;
622
+ localVariantsObjectTable[hash] = obj;
623
+ }
579
624
  }
580
625
  }
581
626
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@plumeria/utils",
3
- "version": "6.0.1",
3
+ "version": "6.1.0",
4
4
  "description": "Plumeria Utils",
5
5
  "author": "Refirst 11",
6
6
  "license": "MIT",