trickle-observe 0.2.79 → 0.2.81
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/dist/observe-register.js +8 -14
- package/dist/vite-plugin.d.ts +7 -0
- package/dist/vite-plugin.js +1 -0
- package/dist-esm/vite-plugin.js +1 -1
- package/package.json +1 -1
- package/src/observe-register.ts +9 -16
- package/src/vite-plugin.ts +1 -1
package/dist/observe-register.js
CHANGED
|
@@ -396,9 +396,10 @@ function transformCjsSource(source, filename, moduleName, env) {
|
|
|
396
396
|
// Skip common false positives
|
|
397
397
|
if (name === 'require' || name === 'exports' || name === 'module')
|
|
398
398
|
continue;
|
|
399
|
-
// Find the opening brace of the function body
|
|
399
|
+
// Find the opening brace of the function body, correctly skipping
|
|
400
|
+
// default parameter values like `headers = {}` which contain braces
|
|
400
401
|
const afterMatch = match.index + match[0].length;
|
|
401
|
-
const openBrace =
|
|
402
|
+
const openBrace = (0, vite_plugin_1.findFunctionBodyBrace)(source, afterMatch);
|
|
402
403
|
if (openBrace === -1)
|
|
403
404
|
continue;
|
|
404
405
|
// Extract parameter names from the source between ( and {
|
|
@@ -539,12 +540,13 @@ function transformCjsSource(source, filename, moduleName, env) {
|
|
|
539
540
|
destructInsertions = findDestructuredDeclarations(source);
|
|
540
541
|
}
|
|
541
542
|
}
|
|
542
|
-
// Additional variable patterns: reassignments, for-loops, catch clauses
|
|
543
|
+
// Additional variable patterns: reassignments, for-loops, catch clauses
|
|
544
|
+
// Note: function params are NOT traced here because observe-register already
|
|
545
|
+
// wraps functions with __trickle_wrap which captures param types via wrapFunction.
|
|
543
546
|
const reassignInsertions = (0, vite_plugin_1.findReassignments)(source);
|
|
544
547
|
const forLoopInsertions = (0, vite_plugin_1.findForLoopVars)(source);
|
|
545
548
|
const catchInsertions = (0, vite_plugin_1.findCatchVars)(source);
|
|
546
|
-
|
|
547
|
-
if (insertions.length === 0 && varInsertions.length === 0 && destructInsertions.length === 0 && reassignInsertions.length === 0 && forLoopInsertions.length === 0 && catchInsertions.length === 0 && funcParamInsertions.length === 0 && classInsertions.length === 0)
|
|
549
|
+
if (insertions.length === 0 && varInsertions.length === 0 && destructInsertions.length === 0 && reassignInsertions.length === 0 && forLoopInsertions.length === 0 && catchInsertions.length === 0 && classInsertions.length === 0)
|
|
548
550
|
return source;
|
|
549
551
|
// Resolve the path to the wrap helper (compiled JS)
|
|
550
552
|
const wrapHelperPath = path_1.default.join(__dirname, 'wrap.js');
|
|
@@ -567,7 +569,7 @@ function transformCjsSource(source, filename, moduleName, env) {
|
|
|
567
569
|
`};`,
|
|
568
570
|
];
|
|
569
571
|
// Add variable tracing helper if we have var insertions
|
|
570
|
-
if (varInsertions.length > 0 || destructInsertions.length > 0 || reassignInsertions.length > 0 || forLoopInsertions.length > 0 || catchInsertions.length > 0
|
|
572
|
+
if (varInsertions.length > 0 || destructInsertions.length > 0 || reassignInsertions.length > 0 || forLoopInsertions.length > 0 || catchInsertions.length > 0) {
|
|
571
573
|
const traceVarPath = path_1.default.join(__dirname, 'trace-var.js');
|
|
572
574
|
prefixLines.push(`var __trickle_tv_mod = require(${JSON.stringify(traceVarPath)});`, `var __trickle_tv = function(v, n, l) { try { __trickle_tv_mod.traceVar(v, n, l, ${JSON.stringify(moduleName)}, ${JSON.stringify(filename)}); } catch(e){} };`);
|
|
573
575
|
}
|
|
@@ -617,14 +619,6 @@ function transformCjsSource(source, filename, moduleName, env) {
|
|
|
617
619
|
code: `\ntry{${calls}}catch(__e2){}\n`,
|
|
618
620
|
});
|
|
619
621
|
}
|
|
620
|
-
// Function parameter insertions
|
|
621
|
-
for (const { bodyStart, paramNames, lineNo } of funcParamInsertions) {
|
|
622
|
-
const calls = paramNames.map(n => `__trickle_tv(${n},${JSON.stringify(n)},${lineNo})`).join(';');
|
|
623
|
-
allInsertions.push({
|
|
624
|
-
position: bodyStart,
|
|
625
|
-
code: `\ntry{${calls}}catch(__e){}\n`,
|
|
626
|
-
});
|
|
627
|
-
}
|
|
628
622
|
// Add class method wrappings
|
|
629
623
|
for (const ci of classInsertions) {
|
|
630
624
|
allInsertions.push(ci);
|
package/dist/vite-plugin.d.ts
CHANGED
|
@@ -40,6 +40,13 @@ export declare function tricklePlugin(options?: TricklePluginOptions): {
|
|
|
40
40
|
map: null;
|
|
41
41
|
} | null;
|
|
42
42
|
};
|
|
43
|
+
/**
|
|
44
|
+
* Find the opening brace of a function body, skipping the parameter list.
|
|
45
|
+
* Starting from the character right after the opening `(` of the parameter list,
|
|
46
|
+
* scans forward matching parens to find the closing `)`, then finds the `{` after it.
|
|
47
|
+
* Returns -1 if not found.
|
|
48
|
+
*/
|
|
49
|
+
export declare function findFunctionBodyBrace(source: string, afterOpenParen: number): number;
|
|
43
50
|
/**
|
|
44
51
|
* Find variable reassignments (not declarations) and return insertions for tracing.
|
|
45
52
|
* Handles: x = newValue; x += 1; x ||= fallback; etc.
|
package/dist/vite-plugin.js
CHANGED
|
@@ -23,6 +23,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
23
23
|
};
|
|
24
24
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
25
25
|
exports.tricklePlugin = tricklePlugin;
|
|
26
|
+
exports.findFunctionBodyBrace = findFunctionBodyBrace;
|
|
26
27
|
exports.findReassignments = findReassignments;
|
|
27
28
|
exports.findCatchVars = findCatchVars;
|
|
28
29
|
exports.findForLoopVars = findForLoopVars;
|
package/dist-esm/vite-plugin.js
CHANGED
|
@@ -114,7 +114,7 @@ export function tricklePlugin(options = {}) {
|
|
|
114
114
|
* scans forward matching parens to find the closing `)`, then finds the `{` after it.
|
|
115
115
|
* Returns -1 if not found.
|
|
116
116
|
*/
|
|
117
|
-
function findFunctionBodyBrace(source, afterOpenParen) {
|
|
117
|
+
export function findFunctionBodyBrace(source, afterOpenParen) {
|
|
118
118
|
let depth = 1;
|
|
119
119
|
let pos = afterOpenParen;
|
|
120
120
|
// Skip the parameter list (matching parens)
|
package/package.json
CHANGED
package/src/observe-register.ts
CHANGED
|
@@ -40,7 +40,7 @@ import {
|
|
|
40
40
|
findReassignments,
|
|
41
41
|
findForLoopVars,
|
|
42
42
|
findCatchVars,
|
|
43
|
-
|
|
43
|
+
findFunctionBodyBrace,
|
|
44
44
|
} from './vite-plugin';
|
|
45
45
|
|
|
46
46
|
const M = Module as any;
|
|
@@ -371,9 +371,10 @@ function transformCjsSource(source: string, filename: string, moduleName: string
|
|
|
371
371
|
// Skip common false positives
|
|
372
372
|
if (name === 'require' || name === 'exports' || name === 'module') continue;
|
|
373
373
|
|
|
374
|
-
// Find the opening brace of the function body
|
|
374
|
+
// Find the opening brace of the function body, correctly skipping
|
|
375
|
+
// default parameter values like `headers = {}` which contain braces
|
|
375
376
|
const afterMatch = match.index + match[0].length;
|
|
376
|
-
const openBrace = source
|
|
377
|
+
const openBrace = findFunctionBodyBrace(source, afterMatch);
|
|
377
378
|
if (openBrace === -1) continue;
|
|
378
379
|
|
|
379
380
|
// Extract parameter names from the source between ( and {
|
|
@@ -514,13 +515,14 @@ function transformCjsSource(source: string, filename: string, moduleName: string
|
|
|
514
515
|
}
|
|
515
516
|
}
|
|
516
517
|
|
|
517
|
-
// Additional variable patterns: reassignments, for-loops, catch clauses
|
|
518
|
+
// Additional variable patterns: reassignments, for-loops, catch clauses
|
|
519
|
+
// Note: function params are NOT traced here because observe-register already
|
|
520
|
+
// wraps functions with __trickle_wrap which captures param types via wrapFunction.
|
|
518
521
|
const reassignInsertions = findReassignments(source);
|
|
519
522
|
const forLoopInsertions = findForLoopVars(source);
|
|
520
523
|
const catchInsertions = findCatchVars(source);
|
|
521
|
-
const funcParamInsertions = findFunctionParams(source, false);
|
|
522
524
|
|
|
523
|
-
if (insertions.length === 0 && varInsertions.length === 0 && destructInsertions.length === 0 && reassignInsertions.length === 0 && forLoopInsertions.length === 0 && catchInsertions.length === 0 &&
|
|
525
|
+
if (insertions.length === 0 && varInsertions.length === 0 && destructInsertions.length === 0 && reassignInsertions.length === 0 && forLoopInsertions.length === 0 && catchInsertions.length === 0 && classInsertions.length === 0) return source;
|
|
524
526
|
|
|
525
527
|
// Resolve the path to the wrap helper (compiled JS)
|
|
526
528
|
const wrapHelperPath = path.join(__dirname, 'wrap.js');
|
|
@@ -545,7 +547,7 @@ function transformCjsSource(source: string, filename: string, moduleName: string
|
|
|
545
547
|
];
|
|
546
548
|
|
|
547
549
|
// Add variable tracing helper if we have var insertions
|
|
548
|
-
if (varInsertions.length > 0 || destructInsertions.length > 0 || reassignInsertions.length > 0 || forLoopInsertions.length > 0 || catchInsertions.length > 0
|
|
550
|
+
if (varInsertions.length > 0 || destructInsertions.length > 0 || reassignInsertions.length > 0 || forLoopInsertions.length > 0 || catchInsertions.length > 0) {
|
|
549
551
|
const traceVarPath = path.join(__dirname, 'trace-var.js');
|
|
550
552
|
prefixLines.push(
|
|
551
553
|
`var __trickle_tv_mod = require(${JSON.stringify(traceVarPath)});`,
|
|
@@ -609,15 +611,6 @@ function transformCjsSource(source: string, filename: string, moduleName: string
|
|
|
609
611
|
});
|
|
610
612
|
}
|
|
611
613
|
|
|
612
|
-
// Function parameter insertions
|
|
613
|
-
for (const { bodyStart, paramNames, lineNo } of funcParamInsertions) {
|
|
614
|
-
const calls = paramNames.map(n => `__trickle_tv(${n},${JSON.stringify(n)},${lineNo})`).join(';');
|
|
615
|
-
allInsertions.push({
|
|
616
|
-
position: bodyStart,
|
|
617
|
-
code: `\ntry{${calls}}catch(__e){}\n`,
|
|
618
|
-
});
|
|
619
|
-
}
|
|
620
|
-
|
|
621
614
|
// Add class method wrappings
|
|
622
615
|
for (const ci of classInsertions) {
|
|
623
616
|
allInsertions.push(ci);
|
package/src/vite-plugin.ts
CHANGED
|
@@ -134,7 +134,7 @@ export function tricklePlugin(options: TricklePluginOptions = {}) {
|
|
|
134
134
|
* scans forward matching parens to find the closing `)`, then finds the `{` after it.
|
|
135
135
|
* Returns -1 if not found.
|
|
136
136
|
*/
|
|
137
|
-
function findFunctionBodyBrace(source: string, afterOpenParen: number): number {
|
|
137
|
+
export function findFunctionBodyBrace(source: string, afterOpenParen: number): number {
|
|
138
138
|
let depth = 1;
|
|
139
139
|
let pos = afterOpenParen;
|
|
140
140
|
// Skip the parameter list (matching parens)
|