trickle-observe 0.2.88 → 0.2.89
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/observe-esm-hooks.mjs +32 -0
- package/package.json +1 -1
package/observe-esm-hooks.mjs
CHANGED
|
@@ -236,6 +236,10 @@ function findVarDeclarationsESM(source) {
|
|
|
236
236
|
const restOfLine = source.slice(match.index + match[0].length - 1, match.index + match[0].length + 200);
|
|
237
237
|
if (/^\s*require\s*\(/.test(restOfLine)) continue;
|
|
238
238
|
|
|
239
|
+
// Skip variable declarations inside for-loop headers
|
|
240
|
+
const beforeDecl = source.slice(Math.max(0, match.index - 50), match.index);
|
|
241
|
+
if (/\bfor\s*\(\s*$/.test(beforeDecl)) continue;
|
|
242
|
+
|
|
239
243
|
// Calculate line number where the declaration starts
|
|
240
244
|
let lineNo = 1;
|
|
241
245
|
for (let i = 0; i < match.index; i++) {
|
|
@@ -260,6 +264,19 @@ function findVarDeclarationsESM(source) {
|
|
|
260
264
|
} else if (ch === '\n' && depth === 0) {
|
|
261
265
|
const nextNonWs = source.slice(pos + 1).match(/^\s*(\S)/);
|
|
262
266
|
if (nextNonWs && !'.+=-|&?:,'.includes(nextNonWs[1])) {
|
|
267
|
+
// Check if a recent non-empty line ends with an operator (continuation across empty lines)
|
|
268
|
+
let checkPos = pos;
|
|
269
|
+
let lastCh = '';
|
|
270
|
+
for (let back = 0; back < 5; back++) {
|
|
271
|
+
const prevNL = source.lastIndexOf('\n', checkPos - 1);
|
|
272
|
+
const prevLine = source.slice(prevNL + 1, checkPos).trimEnd();
|
|
273
|
+
if (prevLine.length > 0) { lastCh = prevLine[prevLine.length - 1]; break; }
|
|
274
|
+
checkPos = prevNL;
|
|
275
|
+
if (prevNL <= 0) break;
|
|
276
|
+
}
|
|
277
|
+
if (lastCh && '=+-*/%&|^~<>?:,({['.includes(lastCh)) {
|
|
278
|
+
pos++; continue;
|
|
279
|
+
}
|
|
263
280
|
foundEnd = pos;
|
|
264
281
|
break;
|
|
265
282
|
}
|
|
@@ -270,6 +287,21 @@ function findVarDeclarationsESM(source) {
|
|
|
270
287
|
else if (source[pos] === quote) break;
|
|
271
288
|
pos++;
|
|
272
289
|
}
|
|
290
|
+
} else if (ch === '/' && pos + 1 < source.length && source[pos + 1] !== '/' && source[pos + 1] !== '*') {
|
|
291
|
+
// Possible regex literal
|
|
292
|
+
let rp = pos - 1;
|
|
293
|
+
while (rp >= 0 && (source[rp] === ' ' || source[rp] === '\t')) rp--;
|
|
294
|
+
const rpCh = rp >= 0 ? source[rp] : '';
|
|
295
|
+
if ('=(!,;:?[{&|^~+-><%'.includes(rpCh) || source.slice(Math.max(0, rp - 5), rp + 1).match(/\b(return|typeof|instanceof|in|of|void|delete|throw|new|case)\s*$/)) {
|
|
296
|
+
pos++;
|
|
297
|
+
while (pos < source.length) {
|
|
298
|
+
if (source[pos] === '\\') pos++;
|
|
299
|
+
else if (source[pos] === '[') { pos++; while (pos < source.length && source[pos] !== ']') { if (source[pos] === '\\') pos++; pos++; } }
|
|
300
|
+
else if (source[pos] === '/') break;
|
|
301
|
+
pos++;
|
|
302
|
+
}
|
|
303
|
+
while (pos + 1 < source.length && /[gimsuy]/.test(source[pos + 1])) pos++;
|
|
304
|
+
}
|
|
273
305
|
} else if (ch === '/' && pos + 1 < source.length && source[pos + 1] === '/') {
|
|
274
306
|
while (pos < source.length && source[pos] !== '\n') pos++;
|
|
275
307
|
continue;
|