@sprlab/wccompiler 0.16.12 → 0.16.14

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 +45 -1
  2. package/package.json +1 -1
package/lib/codegen.js CHANGED
@@ -120,6 +120,40 @@ 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
+ // Match all string literals (single quotes, double quotes, backticks)
129
+ // Replace them with placeholders before any transformations
130
+ result = result.replace(/(['"`])(.*?)(?<!\\)\1/g, (match, quote, content) => {
131
+ const placeholder = `__STRING_PLACEHOLDER_${stringPlaceholderIndex++}__`;
132
+ stringPlaceholders.set(placeholder, match);
133
+ return placeholder;
134
+ });
135
+
136
+ // BUG-0009 FIX: Protect object literal keys from transformation
137
+ // Store original keys and replace with placeholders to prevent them from being transformed
138
+ const keyPlaceholders = new Map();
139
+ let placeholderIndex = 0;
140
+
141
+ // Match ALL object literal keys (identifier or string before colon)
142
+ // We need to loop because replace with /g only replaces non-overlapping matches
143
+ let prevResult;
144
+ do {
145
+ prevResult = result;
146
+ result = result.replace(/(\{|,|;)\s*(?:([a-zA-Z_$][\w$]*)|(['"])([^'"\\]*(?:\\.[^'"\\]*)*?)\3)\s*:/g, (match, prefix, identifierKey, quote, stringKey) => {
147
+ const key = identifierKey || stringKey;
148
+ if (key && !key.startsWith('__KEY_PLACEHOLDER_')) {
149
+ const placeholder = `__KEY_PLACEHOLDER_${placeholderIndex++}__`;
150
+ keyPlaceholders.set(placeholder, identifierKey ? key : `${quote}${key}${quote}`);
151
+ return `${prefix} ${placeholder}:`;
152
+ }
153
+ return match;
154
+ });
155
+ } while (result !== prevResult);
156
+
123
157
  // Transform emit calls: emitsObjectName( → this._emit(
124
158
  if (emitsObjectName) {
125
159
  const emitsRe = new RegExp(`\\b${escapeRegex(emitsObjectName)}\\(`, 'g');
@@ -198,7 +232,17 @@ export function transformExpr(expr, signalNames, computedNames, propsObjectName
198
232
  const bareRe = new RegExp(`\\b(${name})\\b(?!\\.set\\()(?!\\()`, 'g');
199
233
  result = result.replace(bareRe, `this._const_${name}`);
200
234
  }
201
-
235
+
236
+ // BUG-0009 FIX: Restore original object literal keys from placeholders
237
+ for (const [placeholder, originalKey] of keyPlaceholders) {
238
+ result = result.replace(placeholder, originalKey);
239
+ }
240
+
241
+ // BUG-0011 FIX: Restore original string literals from placeholders
242
+ for (const [placeholder, originalString] of stringPlaceholders) {
243
+ result = result.replace(placeholder, originalString);
244
+ }
245
+
202
246
  return result;
203
247
  }
204
248
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sprlab/wccompiler",
3
- "version": "0.16.12",
3
+ "version": "0.16.14",
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": {