@sprlab/wccompiler 0.16.14 → 0.16.15
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 +42 -3
- package/package.json +1 -1
package/lib/codegen.js
CHANGED
|
@@ -125,13 +125,47 @@ export function transformExpr(expr, signalNames, computedNames, propsObjectName
|
|
|
125
125
|
const stringPlaceholders = new Map();
|
|
126
126
|
let stringPlaceholderIndex = 0;
|
|
127
127
|
|
|
128
|
-
// Match
|
|
129
|
-
|
|
130
|
-
result = result.replace(/(['"`])(.*?)(?<!\\)\1/g, (match, quote, content) => {
|
|
128
|
+
// Step 1: Match simple string literals only (single quotes and double quotes)
|
|
129
|
+
result = result.replace(/(['"])(.*?)(?<!\\)\1/g, (match, quote, content) => {
|
|
131
130
|
const placeholder = `__STRING_PLACEHOLDER_${stringPlaceholderIndex++}__`;
|
|
132
131
|
stringPlaceholders.set(placeholder, match);
|
|
133
132
|
return placeholder;
|
|
134
133
|
});
|
|
134
|
+
|
|
135
|
+
// Step 2: For template literals, protect the static parts (text between ${...})
|
|
136
|
+
// We need to extract template literal static parts and protect them
|
|
137
|
+
// Pattern: `static${expr}static${expr}static`
|
|
138
|
+
// We'll protect each static part separately
|
|
139
|
+
let templateLiteralIndex = 0;
|
|
140
|
+
const templateLiteralParts = new Map();
|
|
141
|
+
|
|
142
|
+
// Match template literals and protect their static parts
|
|
143
|
+
result = result.replace(/`([^`]*)`/g, (match, content) => {
|
|
144
|
+
// Split by ${...} expressions
|
|
145
|
+
const parts = content.split(/\$\{[^}]*\}/);
|
|
146
|
+
|
|
147
|
+
// Replace this template literal with a version where static parts are protected
|
|
148
|
+
let result = '`';
|
|
149
|
+
let exprIndex = 0;
|
|
150
|
+
const exprs = content.match(/\$\{[^}]*\}/g) || [];
|
|
151
|
+
|
|
152
|
+
for (let i = 0; i < parts.length; i++) {
|
|
153
|
+
// Protect static part if it's not empty
|
|
154
|
+
if (parts[i].length > 0) {
|
|
155
|
+
const placeholder = `__TL_STATIC_${templateLiteralIndex++}__`;
|
|
156
|
+
templateLiteralParts.set(placeholder, parts[i]);
|
|
157
|
+
result += placeholder;
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
// Add back the expression
|
|
161
|
+
if (exprIndex < exprs.length) {
|
|
162
|
+
result += exprs[exprIndex++];
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
result += '`';
|
|
167
|
+
return result;
|
|
168
|
+
});
|
|
135
169
|
|
|
136
170
|
// BUG-0009 FIX: Protect object literal keys from transformation
|
|
137
171
|
// Store original keys and replace with placeholders to prevent them from being transformed
|
|
@@ -243,6 +277,11 @@ export function transformExpr(expr, signalNames, computedNames, propsObjectName
|
|
|
243
277
|
result = result.replace(placeholder, originalString);
|
|
244
278
|
}
|
|
245
279
|
|
|
280
|
+
// BUG-0011 FIX: Restore template literal static parts
|
|
281
|
+
for (const [placeholder, originalPart] of templateLiteralParts) {
|
|
282
|
+
result = result.replace(placeholder, originalPart);
|
|
283
|
+
}
|
|
284
|
+
|
|
246
285
|
return result;
|
|
247
286
|
}
|
|
248
287
|
|
package/package.json
CHANGED