@canvasengine/compiler 2.0.0-beta.48 → 2.0.0-beta.49
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/grammar2.pegjs +31 -2
- package/package.json +1 -1
package/dist/grammar2.pegjs
CHANGED
|
@@ -44,6 +44,13 @@
|
|
|
44
44
|
'param', 'source', 'track', 'wbr'
|
|
45
45
|
]);
|
|
46
46
|
|
|
47
|
+
const eventAttributes = new Set([
|
|
48
|
+
'click', 'tap', 'pointertap', 'pointerdown', 'pointerup', 'pointermove',
|
|
49
|
+
'pointerover', 'pointerout', 'pointerupoutside', 'mousedown', 'mouseup',
|
|
50
|
+
'mousemove', 'mouseover', 'mouseout', 'touchstart', 'touchend', 'touchmove',
|
|
51
|
+
'touchcancel', 'rightclick', 'keydown', 'keyup', 'keypress'
|
|
52
|
+
]);
|
|
53
|
+
|
|
47
54
|
// DisplayObject special attributes that should not be in attrs
|
|
48
55
|
const displayObjectAttributes = new Set([
|
|
49
56
|
'x', 'y', 'scale', 'anchor', 'skew', 'tint', 'rotation', 'angle',
|
|
@@ -184,6 +191,15 @@
|
|
|
184
191
|
return /^[a-zA-Z_][a-zA-Z0-9_]*(\.[a-zA-Z_][a-zA-Z0-9_]*)*$/.test(value.trim());
|
|
185
192
|
}
|
|
186
193
|
|
|
194
|
+
function formatObjectLiteralSpacing(value) {
|
|
195
|
+
const trimmed = value.trim();
|
|
196
|
+
if (!trimmed.startsWith('{') || !trimmed.endsWith('}')) {
|
|
197
|
+
return value;
|
|
198
|
+
}
|
|
199
|
+
const inner = trimmed.slice(1, -1).trim();
|
|
200
|
+
return `{ ${inner} }`;
|
|
201
|
+
}
|
|
202
|
+
|
|
187
203
|
function transformBareIdentifiersToSignals(value) {
|
|
188
204
|
return value.replace(/\b([a-zA-Z_][a-zA-Z0-9_]*)\b/g, (match, name, offset) => {
|
|
189
205
|
if (['true', 'false', 'null'].includes(name)) {
|
|
@@ -482,6 +498,9 @@ dynamicAttribute "dynamic attribute"
|
|
|
482
498
|
const needsQuotes = /[^a-zA-Z0-9_$]/.test(attributeName);
|
|
483
499
|
const formattedName = needsQuotes ? `'${attributeName}'` : attributeName;
|
|
484
500
|
|
|
501
|
+
if (eventAttributes.has(attributeName)) {
|
|
502
|
+
return `${formattedName}: ${attributeValue}`;
|
|
503
|
+
}
|
|
485
504
|
|
|
486
505
|
// If it's a complex object with strings, preserve it as is
|
|
487
506
|
if (attributeValue.trim().startsWith('{') && attributeValue.trim().endsWith('}') &&
|
|
@@ -512,9 +531,19 @@ dynamicAttribute "dynamic attribute"
|
|
|
512
531
|
return `${formattedName}: ${attributeValue}`;
|
|
513
532
|
}
|
|
514
533
|
|
|
515
|
-
const isObjectLiteral = trimmedValue.startsWith('{
|
|
534
|
+
const isObjectLiteral = trimmedValue.startsWith('{') && trimmedValue.endsWith('}');
|
|
516
535
|
const isArrayLiteral = trimmedValue.startsWith('[') && trimmedValue.endsWith(']');
|
|
517
|
-
if (isObjectLiteral
|
|
536
|
+
if (isObjectLiteral) {
|
|
537
|
+
const formattedObject = formatObjectLiteralSpacing(attributeValue);
|
|
538
|
+
if (hasFunctionCall(trimmedValue)) {
|
|
539
|
+
return `${formattedName}: computed(() => (${formattedObject}))`;
|
|
540
|
+
}
|
|
541
|
+
return `${formattedName}: ${formattedObject}`;
|
|
542
|
+
}
|
|
543
|
+
if (isArrayLiteral) {
|
|
544
|
+
if (hasFunctionCall(trimmedValue)) {
|
|
545
|
+
return `${formattedName}: computed(() => ${attributeValue})`;
|
|
546
|
+
}
|
|
518
547
|
return `${formattedName}: ${attributeValue}`;
|
|
519
548
|
}
|
|
520
549
|
|