@plumeria/utils 21.2.1 → 21.2.2

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/compile.js CHANGED
@@ -828,6 +828,7 @@ function compileCSS(options) {
828
828
  ...argExpr,
829
829
  properties: argExpr.properties.filter((prop) => prop.type === 'Identifier' ||
830
830
  (prop.type === 'KeyValueProperty' &&
831
+ prop.key.type !== 'Computed' &&
831
832
  isStaticArgValue(prop.value))),
832
833
  }, ctx.mergedStaticTable, ctx.mergedKeyframesTable, ctx.mergedViewTransitionTable, ctx.mergedCreateThemeHashTable, ctx.scannedTables.createThemeObjectTable, ctx.mergedCreateTable, ctx.mergedCreateStaticHashTable, ctx.scannedTables.createStaticObjectTable, undefined, ctx.mergedVarTypeTable, ctx.mergedPositionTryTable);
833
834
  if (func.named) {
package/dist/parser.js CHANGED
@@ -287,6 +287,10 @@ function objectExpressionToObject(node, staticTable, keyframesHashTable, viewTra
287
287
  if (typeof spreadVal === 'object' && spreadVal !== null) {
288
288
  Object.assign(obj, spreadVal);
289
289
  }
290
+ else if (spreadVal === null &&
291
+ !exports.t.isNullLiteral(unwrapExpression(arg))) {
292
+ throw new Error(`[plumeria] Cannot spread ${(0, exports.expressionLabel)(arg)} at build time. Spread a const object, or pass a runtime value through the function form, css.create({ name: (value) => ({ ... }) }).`);
293
+ }
290
294
  return;
291
295
  }
292
296
  if (exports.t.isIdentifier(prop) && !exports.t.isObjectProperty(prop)) {
@@ -298,13 +302,16 @@ function objectExpressionToObject(node, staticTable, keyframesHashTable, viewTra
298
302
  return;
299
303
  }
300
304
  }
301
- if (staticTable[key] !== undefined) {
302
- obj[key] = staticTable[key];
305
+ try {
306
+ obj[key] = evaluateExpression(prop, staticTable, keyframesHashTable, viewTransitionHashTable, varTypeHashTable, positionTryHashTable, createThemeHashTable, createThemeObjectTable, createStaticHashTable, createStaticObjectTable);
307
+ }
308
+ catch {
303
309
  }
304
310
  return;
305
311
  }
306
- if (!exports.t.isObjectProperty(prop))
307
- return;
312
+ if (!exports.t.isObjectProperty(prop)) {
313
+ throw new Error(`[plumeria] Cannot read the method or accessor "${prop.key?.value ?? ''}" at build time. Write it as a plain property.`);
314
+ }
308
315
  const rawKey = getPropertyKey(prop.key, staticTable, keyframesHashTable, viewTransitionHashTable, varTypeHashTable, positionTryHashTable, createThemeHashTable, createThemeObjectTable, createStaticHashTable, createStaticObjectTable);
309
316
  if (!rawKey)
310
317
  return;
@@ -732,7 +739,7 @@ function getPropertyKey(node, staticTable, keyframesHashTable, viewTransitionHas
732
739
  if (exports.t.isBinaryExpression(expr)) {
733
740
  return evaluateBinaryExpression(expr, staticTable, keyframesHashTable, viewTransitionHashTable, varTypeHashTable, positionTryHashTable, createThemeHashTable, createThemeObjectTable, createStaticHashTable, createStaticObjectTable);
734
741
  }
735
- return '';
742
+ throw new Error(`[plumeria] Cannot inline the computed key [${(0, exports.expressionLabel)(expr)}] at build time. Declare it with css.createStatic, such as const breakpoints = css.createStatic({ sm: '...' }), and read it as [breakpoints.sm]. A definition in a package needs a plumeria export condition.`);
736
743
  }
737
744
  if (exports.t.isTemplateLiteral(node)) {
738
745
  return evaluateTemplateLiteral(node, staticTable, keyframesHashTable, viewTransitionHashTable, varTypeHashTable, positionTryHashTable, createThemeHashTable, createThemeObjectTable, createStaticHashTable, createStaticObjectTable);
package/dist/transform.js CHANGED
@@ -1268,6 +1268,7 @@ const transformExpanded = async (env, scannedTables, namespaces) => {
1268
1268
  ...argExpr,
1269
1269
  properties: argExpr.properties.filter((prop) => prop.type === 'Identifier' ||
1270
1270
  (prop.type === 'KeyValueProperty' &&
1271
+ prop.key.type !== 'Computed' &&
1271
1272
  isStaticArgValue(prop.value))),
1272
1273
  }, mergedStaticTable, mergedKeyframesTable, mergedViewTransitionTable, mergedCreateThemeHashTable, scannedTables.createThemeObjectTable, mergedCreateTable, mergedCreateStaticHashTable, scannedTables.createStaticObjectTable, undefined, mergedVarTypeTable, mergedPositionTryTable);
1273
1274
  if (func.named) {
@@ -9,6 +9,11 @@ const keyValue = (key) => {
9
9
  ? value
10
10
  : undefined;
11
11
  };
12
+ const asKeyValue = (prop) => prop.type === 'Identifier'
13
+ ? { key: prop, value: prop }
14
+ : prop.type === 'KeyValueProperty'
15
+ ? prop
16
+ : null;
12
17
  const unresolvableValue = (key, node, context) => new Error(`[plumeria] Cannot resolve the value of "${key}" at build time (${context?.sourceOf?.(node) ?? node.type}). ` +
13
18
  `Values in css.create must be statically known; pass a runtime value through the ` +
14
19
  `function form, css.create({ name: (value) => ({ ... }) }).`);
@@ -23,7 +28,8 @@ const overwrittenLater = (properties, index, key, context) => {
23
28
  return true;
24
29
  continue;
25
30
  }
26
- if (later.type === 'KeyValueProperty' && keyValue(later.key) === key)
31
+ const entry = asKeyValue(later);
32
+ if (entry && keyValue(entry.key) === key)
27
33
  return true;
28
34
  }
29
35
  return false;
@@ -86,14 +92,14 @@ const assertStyleFunction = (func, context) => {
86
92
  const walk = (object) => {
87
93
  const properties = object.properties ?? [];
88
94
  for (let index = 0; index < properties.length; index++) {
89
- const prop = properties[index];
90
- if (prop.type !== 'KeyValueProperty')
95
+ const entry = asKeyValue(properties[index]);
96
+ if (!entry)
91
97
  continue;
92
- const key = keyValue(prop.key);
98
+ const key = keyValue(entry.key);
93
99
  if ((typeof key === 'string' || typeof key === 'number') &&
94
100
  overwrittenLater(properties, index, key, context))
95
101
  continue;
96
- const value = prop.value;
102
+ const value = entry.value;
97
103
  if (!value)
98
104
  continue;
99
105
  if (value.type === 'ObjectExpression') {
@@ -123,9 +129,10 @@ const keysSuppliedAfter = (properties, index, context) => {
123
129
  keys.add(name);
124
130
  continue;
125
131
  }
126
- if (later.type !== 'KeyValueProperty')
132
+ const entry = asKeyValue(later);
133
+ if (!entry)
127
134
  continue;
128
- const key = keyValue(later.key);
135
+ const key = keyValue(entry.key);
129
136
  if (typeof key !== 'string' && typeof key !== 'number')
130
137
  return null;
131
138
  keys.add(String(key));
@@ -146,16 +153,17 @@ const assertNoDroppedValues = (node, resolved, context, ignore) => {
146
153
  (0, exports.assertNoDroppedValues)(provided.source, provided.values, context, replaced);
147
154
  continue;
148
155
  }
149
- if (prop.type !== 'KeyValueProperty')
156
+ const entry = asKeyValue(prop);
157
+ if (!entry)
150
158
  continue;
151
- const key = keyValue(prop.key);
159
+ const key = keyValue(entry.key);
152
160
  if (typeof key !== 'string' && typeof key !== 'number')
153
161
  continue;
154
162
  if (ignore?.has(String(key)))
155
163
  continue;
156
164
  if (overwrittenLater(node.properties, index, key, context))
157
165
  continue;
158
- const value = prop.value;
166
+ const value = entry.value;
159
167
  if (!value)
160
168
  continue;
161
169
  if (value.type === 'ArrowFunctionExpression' ||
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@plumeria/utils",
3
- "version": "21.2.1",
3
+ "version": "21.2.2",
4
4
  "description": "Plumeria Utils",
5
5
  "author": "Refirst 11",
6
6
  "license": "MIT",