@sprlab/wccompiler 0.16.12 → 0.16.13
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/lib/codegen.js +27 -1
- package/package.json +1 -1
package/lib/codegen.js
CHANGED
|
@@ -120,6 +120,27 @@ function wrapTernaryExpr(expr) {
|
|
|
120
120
|
export function transformExpr(expr, signalNames, computedNames, propsObjectName = null, propNames = new Set(), emitsObjectName = null, constantNames = [], methodNames = [], modelVarMap = new Map()) {
|
|
121
121
|
let result = expr;
|
|
122
122
|
|
|
123
|
+
// BUG-0009 FIX: Protect object literal keys from transformation
|
|
124
|
+
// Store original keys and replace with placeholders to prevent them from being transformed
|
|
125
|
+
const keyPlaceholders = new Map();
|
|
126
|
+
let placeholderIndex = 0;
|
|
127
|
+
|
|
128
|
+
// Match ALL object literal keys (identifier or string before colon)
|
|
129
|
+
// We need to loop because replace with /g only replaces non-overlapping matches
|
|
130
|
+
let prevResult;
|
|
131
|
+
do {
|
|
132
|
+
prevResult = result;
|
|
133
|
+
result = result.replace(/(\{|,|;)\s*(?:([a-zA-Z_$][\w$]*)|(['"])([^'"\\]*(?:\\.[^'"\\]*)*?)\3)\s*:/g, (match, prefix, identifierKey, quote, stringKey) => {
|
|
134
|
+
const key = identifierKey || stringKey;
|
|
135
|
+
if (key && !key.startsWith('__KEY_PLACEHOLDER_')) {
|
|
136
|
+
const placeholder = `__KEY_PLACEHOLDER_${placeholderIndex++}__`;
|
|
137
|
+
keyPlaceholders.set(placeholder, identifierKey ? key : `${quote}${key}${quote}`);
|
|
138
|
+
return `${prefix} ${placeholder}:`;
|
|
139
|
+
}
|
|
140
|
+
return match;
|
|
141
|
+
});
|
|
142
|
+
} while (result !== prevResult);
|
|
143
|
+
|
|
123
144
|
// Transform emit calls: emitsObjectName( → this._emit(
|
|
124
145
|
if (emitsObjectName) {
|
|
125
146
|
const emitsRe = new RegExp(`\\b${escapeRegex(emitsObjectName)}\\(`, 'g');
|
|
@@ -198,7 +219,12 @@ export function transformExpr(expr, signalNames, computedNames, propsObjectName
|
|
|
198
219
|
const bareRe = new RegExp(`\\b(${name})\\b(?!\\.set\\()(?!\\()`, 'g');
|
|
199
220
|
result = result.replace(bareRe, `this._const_${name}`);
|
|
200
221
|
}
|
|
201
|
-
|
|
222
|
+
|
|
223
|
+
// BUG-0009 FIX: Restore original object literal keys from placeholders
|
|
224
|
+
for (const [placeholder, originalKey] of keyPlaceholders) {
|
|
225
|
+
result = result.replace(placeholder, originalKey);
|
|
226
|
+
}
|
|
227
|
+
|
|
202
228
|
return result;
|
|
203
229
|
}
|
|
204
230
|
|
package/package.json
CHANGED