@sprlab/wccompiler 0.16.13 → 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.
Files changed (2) hide show
  1. package/lib/codegen.js +57 -0
  2. package/package.json +1 -1
package/lib/codegen.js CHANGED
@@ -120,6 +120,53 @@ 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-0011 FIX: Protect string literals from transformation
124
+ // Store original strings and replace with placeholders to prevent signal names inside strings from being transformed
125
+ const stringPlaceholders = new Map();
126
+ let stringPlaceholderIndex = 0;
127
+
128
+ // Step 1: Match simple string literals only (single quotes and double quotes)
129
+ result = result.replace(/(['"])(.*?)(?<!\\)\1/g, (match, quote, content) => {
130
+ const placeholder = `__STRING_PLACEHOLDER_${stringPlaceholderIndex++}__`;
131
+ stringPlaceholders.set(placeholder, match);
132
+ return placeholder;
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
+ });
169
+
123
170
  // BUG-0009 FIX: Protect object literal keys from transformation
124
171
  // Store original keys and replace with placeholders to prevent them from being transformed
125
172
  const keyPlaceholders = new Map();
@@ -225,6 +272,16 @@ export function transformExpr(expr, signalNames, computedNames, propsObjectName
225
272
  result = result.replace(placeholder, originalKey);
226
273
  }
227
274
 
275
+ // BUG-0011 FIX: Restore original string literals from placeholders
276
+ for (const [placeholder, originalString] of stringPlaceholders) {
277
+ result = result.replace(placeholder, originalString);
278
+ }
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
+
228
285
  return result;
229
286
  }
230
287
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sprlab/wccompiler",
3
- "version": "0.16.13",
3
+ "version": "0.16.15",
4
4
  "description": "Zero-runtime compiler that transforms .wcc single-file components into native web components with signals-based reactivity",
5
5
  "type": "module",
6
6
  "exports": {