@canvasengine/compiler 2.0.0-beta.51 → 2.0.0-beta.52
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 +23 -0
- package/package.json +1 -1
package/dist/grammar2.pegjs
CHANGED
|
@@ -300,7 +300,21 @@
|
|
|
300
300
|
return `{ ${inner} }`;
|
|
301
301
|
}
|
|
302
302
|
|
|
303
|
+
function collectMemberRoots(value) {
|
|
304
|
+
const roots = new Set();
|
|
305
|
+
const memberRegex = /\b([a-zA-Z_][a-zA-Z0-9_]*)\s*\./g;
|
|
306
|
+
let match;
|
|
307
|
+
|
|
308
|
+
while ((match = memberRegex.exec(value)) !== null) {
|
|
309
|
+
roots.add(match[1]);
|
|
310
|
+
}
|
|
311
|
+
|
|
312
|
+
return roots;
|
|
313
|
+
}
|
|
314
|
+
|
|
303
315
|
function transformBareIdentifiersToSignals(value) {
|
|
316
|
+
const memberRoots = collectMemberRoots(value);
|
|
317
|
+
|
|
304
318
|
return value.replace(/\b([a-zA-Z_][a-zA-Z0-9_]*)\b/g, (match, name, offset) => {
|
|
305
319
|
if (['true', 'false', 'null'].includes(name)) {
|
|
306
320
|
return match;
|
|
@@ -320,6 +334,10 @@
|
|
|
320
334
|
return match;
|
|
321
335
|
}
|
|
322
336
|
|
|
337
|
+
if (memberRoots.has(name)) {
|
|
338
|
+
return match;
|
|
339
|
+
}
|
|
340
|
+
|
|
323
341
|
const afterSlice = value.slice(offset + match.length);
|
|
324
342
|
if (/^\s*\(/.test(afterSlice)) {
|
|
325
343
|
return match;
|
|
@@ -649,6 +667,7 @@ dynamicAttribute "dynamic attribute"
|
|
|
649
667
|
|
|
650
668
|
const isObjectLiteral = trimmedValue.startsWith('{') && trimmedValue.endsWith('}');
|
|
651
669
|
const isArrayLiteral = trimmedValue.startsWith('[') && trimmedValue.endsWith(']');
|
|
670
|
+
const isTernaryExpression = trimmedValue.includes('?') && trimmedValue.includes(':');
|
|
652
671
|
if (isObjectLiteral) {
|
|
653
672
|
const formattedObject = formatObjectLiteralSpacing(attributeValue);
|
|
654
673
|
if (hasFunctionCall(trimmedValue)) {
|
|
@@ -663,6 +682,10 @@ dynamicAttribute "dynamic attribute"
|
|
|
663
682
|
return `${formattedName}: ${attributeValue}`;
|
|
664
683
|
}
|
|
665
684
|
|
|
685
|
+
if (isTernaryExpression) {
|
|
686
|
+
return `${formattedName}: computed(() => ${attributeValue})`;
|
|
687
|
+
}
|
|
688
|
+
|
|
666
689
|
if (hasFunctionCall(trimmedValue)) {
|
|
667
690
|
return `${formattedName}: computed(() => ${attributeValue})`;
|
|
668
691
|
}
|