@plumeria/utils 19.1.9 → 19.2.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/parser.js CHANGED
@@ -996,6 +996,7 @@ function resolveFileError(actualPath, importedName) {
996
996
  return undefined;
997
997
  }
998
998
  const fileCache = {};
999
+ const receiverKeysByFile = new Map();
999
1000
  const dependentsMap = new Map();
1000
1001
  let knownFiles = new Set();
1001
1002
  function updateDependencyEdges(filePath, oldDeps, newDeps) {
@@ -1031,6 +1032,7 @@ const globalAgregatedTables = {
1031
1032
  createStaticHashTable: {},
1032
1033
  createStaticObjectTable: {},
1033
1034
  componentPropsTable: {},
1035
+ styleReceiverTable: {},
1034
1036
  };
1035
1037
  let hasComputedOnce = false;
1036
1038
  let resolutionConfigStamp;
@@ -1040,7 +1042,7 @@ const fileObjectContributions = new Map();
1040
1042
  function snapshotTables() {
1041
1043
  return Object.fromEntries(Object.entries(globalAgregatedTables).map(([key, value]) => [
1042
1044
  key,
1043
- { ...value },
1045
+ key === 'styleReceiverTable' ? value : { ...value },
1044
1046
  ]));
1045
1047
  }
1046
1048
  function releaseFileObjects(filePath) {
@@ -1082,11 +1084,18 @@ function releaseObjectOwner(tableName, hash, filePath, table) {
1082
1084
  }
1083
1085
  function stripFileContributions(filePath, cached) {
1084
1086
  releaseFileObjects(filePath);
1087
+ const receiverKeys = receiverKeysByFile.get(filePath);
1088
+ if (receiverKeys) {
1089
+ for (const key of receiverKeys)
1090
+ delete globalAgregatedTables.styleReceiverTable[key];
1091
+ receiverKeysByFile.delete(filePath);
1092
+ }
1085
1093
  for (const [name, table] of Object.entries(globalAgregatedTables)) {
1086
1094
  if (name.endsWith('ObjectTable') ||
1087
1095
  name === 'createAtomicMapTable' ||
1088
1096
  name === 'createThemeSelectorTable' ||
1089
- name === 'componentPropsTable')
1097
+ name === 'componentPropsTable' ||
1098
+ name === 'styleReceiverTable')
1090
1099
  continue;
1091
1100
  for (const key of Object.keys(table))
1092
1101
  if (key.startsWith(`${filePath}-`))
@@ -2006,6 +2015,57 @@ function scanAll(scanCwd = process.cwd()) {
2006
2015
  list.push(entry);
2007
2016
  }
2008
2017
  };
2018
+ const receiverTable = localTables.styleReceiverTable;
2019
+ const registerReceiver = (name, fn) => {
2020
+ if (name[0] !== name[0].toUpperCase())
2021
+ return;
2022
+ const first = fn?.params?.[0];
2023
+ const pattern = first?.pat ?? first;
2024
+ const inner = pattern?.type === 'AssignmentPattern' ? pattern.left : pattern;
2025
+ if (inner?.type !== 'ObjectPattern')
2026
+ return;
2027
+ for (const property of inner.properties ?? []) {
2028
+ const key = property.type === 'AssignmentPatternProperty'
2029
+ ? property.key
2030
+ : property.type === 'KeyValuePatternProperty'
2031
+ ? property.key
2032
+ : undefined;
2033
+ if (!exports.t.isIdentifier(key))
2034
+ continue;
2035
+ const compKey = `${filePath}-${name}`;
2036
+ if (!receiverTable[compKey]) {
2037
+ receiverTable[compKey] = [];
2038
+ const owned = receiverKeysByFile.get(filePath);
2039
+ if (owned)
2040
+ owned.push(compKey);
2041
+ else
2042
+ receiverKeysByFile.set(filePath, [compKey]);
2043
+ }
2044
+ const props = receiverTable[compKey];
2045
+ if (!props.includes(key.value))
2046
+ props.push(key.value);
2047
+ }
2048
+ };
2049
+ for (const statement of ast.body) {
2050
+ const declaration = statement.type === 'ExportDeclaration'
2051
+ ? statement.declaration
2052
+ : statement;
2053
+ if (declaration.type === 'FunctionDeclaration') {
2054
+ if (declaration.identifier)
2055
+ registerReceiver(declaration.identifier.value, declaration);
2056
+ continue;
2057
+ }
2058
+ if (declaration.type !== 'VariableDeclaration')
2059
+ continue;
2060
+ for (const declarator of declaration.declarations) {
2061
+ const init = declarator.init;
2062
+ if (!exports.t.isIdentifier(declarator.id) || !init)
2063
+ continue;
2064
+ if (init.type === 'ArrowFunctionExpression' ||
2065
+ init.type === 'FunctionExpression')
2066
+ registerReceiver(declarator.id.value, init);
2067
+ }
2068
+ }
2009
2069
  traverse(ast, {
2010
2070
  JSXOpeningElement({ node }) {
2011
2071
  const compKey = resolveComponentKey(node.name, filePath, localImports);
package/dist/transform.js CHANGED
@@ -2020,14 +2020,14 @@ const transformSource = async (env) => {
2020
2020
  break;
2021
2021
  }
2022
2022
  }
2023
- const relayed = compKey
2024
- ? scannedTables.componentPropsTable?.[compKey]?.[attrName]
2025
- : undefined;
2026
- if (attrName !== styleProp || relayed) {
2023
+ const receivesStyleProp = Boolean(compKey &&
2024
+ scannedTables.styleReceiverTable?.[compKey]?.includes(attrName));
2025
+ let relayed = false;
2026
+ if (attrName !== styleProp || receivesStyleProp) {
2027
2027
  if (compKey) {
2028
2028
  if (node.value?.type === 'JSXExpressionContainer')
2029
2029
  assertNoStyleArraySpread(node.value.expression);
2030
- const list = relayed;
2030
+ const list = scannedTables.componentPropsTable?.[compKey]?.[attrName];
2031
2031
  if (list &&
2032
2032
  node.value &&
2033
2033
  node.value.type === 'JSXExpressionContainer') {
@@ -2084,23 +2084,27 @@ const transformSource = async (env) => {
2084
2084
  (0, parser_1.traverse)(expr, {
2085
2085
  MemberExpression({ node: subNode }) {
2086
2086
  if (replaceWithKey(subNode)) {
2087
+ relayed = true;
2087
2088
  excludeSubtreeSpans(subNode);
2088
2089
  }
2089
2090
  },
2090
2091
  ArrayExpression({ node: subNode }) {
2091
2092
  if (replaceWithKey(subNode)) {
2093
+ relayed = true;
2092
2094
  excludeSubtreeSpans(subNode);
2093
2095
  }
2094
2096
  },
2095
2097
  CallExpression({ node: subNode }) {
2096
2098
  if (replaceWithKey(subNode)) {
2099
+ relayed = true;
2097
2100
  excludeSubtreeSpans(subNode);
2098
2101
  }
2099
2102
  },
2100
2103
  });
2101
2104
  }
2102
2105
  }
2103
- return;
2106
+ if (attrName !== styleProp || relayed)
2107
+ return;
2104
2108
  }
2105
2109
  if (!node.value || node.value.type !== 'JSXExpressionContainer')
2106
2110
  return;
package/dist/types.d.ts CHANGED
@@ -48,6 +48,7 @@ export interface Tables {
48
48
  createStaticHashTable: CreateStaticHashTable;
49
49
  createStaticObjectTable: CreateStaticObjectTable;
50
50
  componentPropsTable?: Record<string, Record<string, TableEntry[]>>;
51
+ styleReceiverTable?: Record<string, string[]>;
51
52
  }
52
53
  export type CreateTheme = {
53
54
  [key: string]: {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@plumeria/utils",
3
- "version": "19.1.9",
3
+ "version": "19.2.0",
4
4
  "description": "Plumeria Utils",
5
5
  "author": "Refirst 11",
6
6
  "license": "MIT",