@plumeria/utils 19.2.10 → 19.2.11

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/transform.js +36 -40
  2. package/package.json +1 -1
package/dist/transform.js CHANGED
@@ -402,9 +402,8 @@ const transformSource = async (env) => {
402
402
  for (const key of Object.keys(importMap)) {
403
403
  mergedStaticTable[key] = importMap[key];
404
404
  }
405
- const mergedKeyframesTable = {};
405
+ const mergedKeyframesTable = Object.create(scannedTables.keyframesHashTable);
406
406
  for (const key of Object.keys(scannedTables.keyframesHashTable)) {
407
- mergedKeyframesTable[key] = scannedTables.keyframesHashTable[key];
408
407
  if (key.startsWith(`${resourcePath}-`)) {
409
408
  const varName = key.slice(resourcePath.length + 1);
410
409
  mergedKeyframesTable[varName] = scannedTables.keyframesHashTable[key];
@@ -413,9 +412,8 @@ const transformSource = async (env) => {
413
412
  for (const key of Object.keys(keyframesImportMap)) {
414
413
  mergedKeyframesTable[key] = keyframesImportMap[key];
415
414
  }
416
- const mergedViewTransitionTable = {};
415
+ const mergedViewTransitionTable = Object.create(scannedTables.viewTransitionHashTable);
417
416
  for (const key of Object.keys(scannedTables.viewTransitionHashTable)) {
418
- mergedViewTransitionTable[key] = scannedTables.viewTransitionHashTable[key];
419
417
  if (key.startsWith(`${resourcePath}-`)) {
420
418
  const varName = key.slice(resourcePath.length + 1);
421
419
  mergedViewTransitionTable[varName] =
@@ -425,9 +423,8 @@ const transformSource = async (env) => {
425
423
  for (const key of Object.keys(viewTransitionImportMap)) {
426
424
  mergedViewTransitionTable[key] = viewTransitionImportMap[key];
427
425
  }
428
- const mergedCreateTable = {};
426
+ const mergedCreateTable = Object.create(scannedTables.createHashTable);
429
427
  for (const key of Object.keys(scannedTables.createHashTable)) {
430
- mergedCreateTable[key] = scannedTables.createHashTable[key];
431
428
  if (key.startsWith(`${resourcePath}-`)) {
432
429
  const varName = key.slice(resourcePath.length + 1);
433
430
  mergedCreateTable[varName] = scannedTables.createHashTable[key];
@@ -436,9 +433,8 @@ const transformSource = async (env) => {
436
433
  for (const key of Object.keys(createImportMap)) {
437
434
  mergedCreateTable[key] = createImportMap[key];
438
435
  }
439
- const mergedCreateThemeHashTable = {};
436
+ const mergedCreateThemeHashTable = Object.create(scannedTables.createThemeHashTable);
440
437
  for (const key of Object.keys(scannedTables.createThemeHashTable)) {
441
- mergedCreateThemeHashTable[key] = scannedTables.createThemeHashTable[key];
442
438
  if (key.startsWith(`${resourcePath}-`)) {
443
439
  const varName = key.slice(resourcePath.length + 1);
444
440
  mergedCreateThemeHashTable[varName] =
@@ -448,9 +444,8 @@ const transformSource = async (env) => {
448
444
  for (const key of Object.keys(createThemeImportMap)) {
449
445
  mergedCreateThemeHashTable[key] = createThemeImportMap[key];
450
446
  }
451
- const mergedCreateStaticHashTable = {};
447
+ const mergedCreateStaticHashTable = Object.create(scannedTables.createStaticHashTable);
452
448
  for (const key of Object.keys(scannedTables.createStaticHashTable)) {
453
- mergedCreateStaticHashTable[key] = scannedTables.createStaticHashTable[key];
454
449
  if (key.startsWith(`${resourcePath}-`)) {
455
450
  const varName = key.slice(resourcePath.length + 1);
456
451
  mergedCreateStaticHashTable[varName] =
@@ -856,7 +851,25 @@ const transformSource = async (env) => {
856
851
  }
857
852
  },
858
853
  });
859
- const jsxOpeningElementMap = new Map();
854
+ const jsxAttributeOwnerMap = new Map();
855
+ const propEntryIndexes = new Map();
856
+ const localPropEntries = (list, spanStart) => {
857
+ let index = propEntryIndexes.get(list);
858
+ if (!index) {
859
+ index = new Map();
860
+ for (const entry of list) {
861
+ if (entry.filePath !== resourcePath)
862
+ continue;
863
+ const bucket = index.get(entry.spanStart);
864
+ if (bucket)
865
+ bucket.push(entry);
866
+ else
867
+ index.set(entry.spanStart, [entry]);
868
+ }
869
+ propEntryIndexes.set(list, index);
870
+ }
871
+ return index.get(spanStart);
872
+ };
860
873
  const componentParamNames = new Set();
861
874
  const addFirstParamName = (fn) => {
862
875
  const first = fn.params[0];
@@ -1839,10 +1852,13 @@ const transformSource = async (env) => {
1839
1852
  };
1840
1853
  (0, parser_1.traverse)(ast, {
1841
1854
  JSXOpeningElement({ node }) {
1842
- jsxOpeningElementMap.set(node.span.start, {
1855
+ const owner = {
1843
1856
  compKey: (0, parser_1.resolveComponentKey)(node.name, resourcePath, localImports),
1844
1857
  attributes: node.attributes,
1845
- });
1858
+ };
1859
+ for (const attribute of node.attributes)
1860
+ if (attribute.type === 'JSXAttribute')
1861
+ jsxAttributeOwnerMap.set(attribute.span.start, owner);
1846
1862
  },
1847
1863
  MemberExpression({ node }) {
1848
1864
  if (!isVisibleReference(node))
@@ -2021,16 +2037,7 @@ const transformSource = async (env) => {
2021
2037
  if (node.name.type !== 'Identifier')
2022
2038
  return;
2023
2039
  const attrName = node.name.value;
2024
- let compKey = null;
2025
- for (const [, val] of jsxOpeningElementMap) {
2026
- const found = val.attributes
2027
- .filter((a) => a.type === 'JSXAttribute')
2028
- .find((a) => a.span.start === node.span.start);
2029
- if (found) {
2030
- compKey = val.compKey;
2031
- break;
2032
- }
2033
- }
2040
+ const compKey = jsxAttributeOwnerMap.get(node.span.start)?.compKey ?? null;
2034
2041
  const receivesStyleProp = Boolean(compKey &&
2035
2042
  scannedTables.styleReceiverTable?.[compKey]?.includes(attrName));
2036
2043
  let relayed = false;
@@ -2064,9 +2071,8 @@ const transformSource = async (env) => {
2064
2071
  return `{ ${foldDynamicVars(vars).join(', ')} }`;
2065
2072
  };
2066
2073
  const replaceWithKey = (subNode) => {
2067
- const entries = list.filter((entry) => entry.spanStart === subNode.span.start &&
2068
- entry.filePath === resourcePath);
2069
- if (!entries.length)
2074
+ const entries = localPropEntries(list, subNode.span.start);
2075
+ if (!entries)
2070
2076
  return false;
2071
2077
  let content = '""';
2072
2078
  for (const entry of [...entries].reverse()) {
@@ -2131,16 +2137,7 @@ const transformSource = async (env) => {
2131
2137
  : [{ expression: expr }];
2132
2138
  const dynamicClassParts = [];
2133
2139
  const existingStyleParts = [];
2134
- let attributes = [];
2135
- for (const [, val] of jsxOpeningElementMap) {
2136
- const found = val.attributes
2137
- .filter((a) => a.type === 'JSXAttribute')
2138
- .find((a) => a.span.start === node.span.start);
2139
- if (found) {
2140
- attributes = val.attributes;
2141
- break;
2142
- }
2143
- }
2140
+ const attributes = jsxAttributeOwnerMap.get(node.span.start)?.attributes ?? [];
2144
2141
  const classNameAttr = attributes.find((attr) => attr.type === 'JSXAttribute' &&
2145
2142
  attr.name.type === 'Identifier' &&
2146
2143
  attr.name.value === 'className');
@@ -2323,10 +2320,11 @@ const transformSource = async (env) => {
2323
2320
  `so it cannot be passed through another prop or read as a value.`, call);
2324
2321
  }
2325
2322
  });
2323
+ replacements.sort((a, b) => a.start - b.start || b.end - a.end);
2326
2324
  for (const deferred of deferredSources) {
2327
2325
  let cursor = deferred.start;
2328
2326
  const pieces = [];
2329
- for (const replacement of [...replacements].sort((a, b) => a.start - b.start || b.end - a.end)) {
2327
+ for (const replacement of replacements) {
2330
2328
  if (replacement.start < cursor || replacement.end > deferred.end)
2331
2329
  continue;
2332
2330
  pieces.push(sourceBuffer.subarray(cursor, replacement.start).toString('utf-8'), replacement.content);
@@ -2340,9 +2338,7 @@ const transformSource = async (env) => {
2340
2338
  const buffer = Buffer.from(source);
2341
2339
  let offset = 0;
2342
2340
  const parts = [];
2343
- replacements
2344
- .sort((a, b) => a.start - b.start || b.end - a.end)
2345
- .forEach((r) => {
2341
+ replacements.forEach((r) => {
2346
2342
  if (r.start < offset)
2347
2343
  return;
2348
2344
  parts.push(buffer.subarray(offset, r.start));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@plumeria/utils",
3
- "version": "19.2.10",
3
+ "version": "19.2.11",
4
4
  "description": "Plumeria Utils",
5
5
  "author": "Refirst 11",
6
6
  "license": "MIT",