@plumeria/utils 19.1.10 → 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
@@ -2010,17 +2010,20 @@ const transformSource = async (env) => {
2010
2010
  if (node.name.type !== 'Identifier')
2011
2011
  return;
2012
2012
  const attrName = node.name.value;
2013
- if (attrName !== styleProp) {
2014
- let compKey = null;
2015
- for (const [, val] of jsxOpeningElementMap) {
2016
- const found = val.attributes
2017
- .filter((a) => a.type === 'JSXAttribute')
2018
- .find((a) => a.span.start === node.span.start);
2019
- if (found) {
2020
- compKey = val.compKey;
2021
- break;
2022
- }
2013
+ let compKey = null;
2014
+ for (const [, val] of jsxOpeningElementMap) {
2015
+ const found = val.attributes
2016
+ .filter((a) => a.type === 'JSXAttribute')
2017
+ .find((a) => a.span.start === node.span.start);
2018
+ if (found) {
2019
+ compKey = val.compKey;
2020
+ break;
2023
2021
  }
2022
+ }
2023
+ const receivesStyleProp = Boolean(compKey &&
2024
+ scannedTables.styleReceiverTable?.[compKey]?.includes(attrName));
2025
+ let relayed = false;
2026
+ if (attrName !== styleProp || receivesStyleProp) {
2024
2027
  if (compKey) {
2025
2028
  if (node.value?.type === 'JSXExpressionContainer')
2026
2029
  assertNoStyleArraySpread(node.value.expression);
@@ -2081,23 +2084,27 @@ const transformSource = async (env) => {
2081
2084
  (0, parser_1.traverse)(expr, {
2082
2085
  MemberExpression({ node: subNode }) {
2083
2086
  if (replaceWithKey(subNode)) {
2087
+ relayed = true;
2084
2088
  excludeSubtreeSpans(subNode);
2085
2089
  }
2086
2090
  },
2087
2091
  ArrayExpression({ node: subNode }) {
2088
2092
  if (replaceWithKey(subNode)) {
2093
+ relayed = true;
2089
2094
  excludeSubtreeSpans(subNode);
2090
2095
  }
2091
2096
  },
2092
2097
  CallExpression({ node: subNode }) {
2093
2098
  if (replaceWithKey(subNode)) {
2099
+ relayed = true;
2094
2100
  excludeSubtreeSpans(subNode);
2095
2101
  }
2096
2102
  },
2097
2103
  });
2098
2104
  }
2099
2105
  }
2100
- return;
2106
+ if (attrName !== styleProp || relayed)
2107
+ return;
2101
2108
  }
2102
2109
  if (!node.value || node.value.type !== 'JSXExpressionContainer')
2103
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.10",
3
+ "version": "19.2.0",
4
4
  "description": "Plumeria Utils",
5
5
  "author": "Refirst 11",
6
6
  "license": "MIT",