@leftium/gg 0.0.31 → 0.0.34
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/README.md +117 -36
- package/dist/GgConsole.svelte +12 -0
- package/dist/GgConsole.svelte.d.ts +4 -0
- package/dist/OpenInEditorLink.svelte +8 -10
- package/dist/OpenInEditorLink.svelte.d.ts +6 -3
- package/dist/debug/browser.d.ts +10 -0
- package/dist/debug/browser.js +102 -0
- package/dist/debug/common.d.ts +41 -0
- package/dist/debug/common.js +191 -0
- package/dist/debug/index.d.ts +9 -0
- package/dist/debug/index.js +11 -0
- package/dist/debug/node.d.ts +10 -0
- package/dist/debug/node.js +137 -0
- package/dist/eruda/loader.js +0 -11
- package/dist/eruda/plugin.js +765 -25
- package/dist/eruda/types.d.ts +8 -5
- package/dist/gg-call-sites-plugin.d.ts +90 -6
- package/dist/gg-call-sites-plugin.js +700 -112
- package/dist/gg.d.ts +18 -2
- package/dist/gg.js +127 -110
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1 -0
- package/dist/open-in-editor.js +15 -2
- package/dist/vite.d.ts +37 -0
- package/dist/vite.js +46 -0
- package/package.json +20 -13
- package/dist/debug-bundled.d.ts +0 -2
- package/dist/debug-bundled.js +0 -3
- package/dist/debug.d.ts +0 -2
- package/dist/debug.js +0 -15
- package/patches/debug@4.4.3.patch +0 -35
package/dist/eruda/types.d.ts
CHANGED
|
@@ -12,11 +12,6 @@ export interface GgErudaOptions {
|
|
|
12
12
|
* @default 2000
|
|
13
13
|
*/
|
|
14
14
|
maxEntries?: number;
|
|
15
|
-
/**
|
|
16
|
-
* Auto-enable localStorage.debug = 'gg:*' if unset
|
|
17
|
-
* @default true
|
|
18
|
-
*/
|
|
19
|
-
autoEnable?: boolean;
|
|
20
15
|
/**
|
|
21
16
|
* Additional Eruda options passed to eruda.init()
|
|
22
17
|
* @default {}
|
|
@@ -39,6 +34,14 @@ export interface CapturedEntry {
|
|
|
39
34
|
args: unknown[];
|
|
40
35
|
/** Timestamp */
|
|
41
36
|
timestamp: number;
|
|
37
|
+
/** Source file path for open-in-editor (e.g., "src/routes/blog/[slug]/+page.svelte") */
|
|
38
|
+
file?: string;
|
|
39
|
+
/** Source line number */
|
|
40
|
+
line?: number;
|
|
41
|
+
/** Source column number */
|
|
42
|
+
col?: number;
|
|
43
|
+
/** Source expression text for icecream-style display (e.g., "user.name") */
|
|
44
|
+
src?: string;
|
|
42
45
|
}
|
|
43
46
|
/**
|
|
44
47
|
* Eruda plugin interface
|
|
@@ -12,13 +12,40 @@ export interface GgCallSitesPluginOptions {
|
|
|
12
12
|
srcRootPattern?: string;
|
|
13
13
|
}
|
|
14
14
|
/**
|
|
15
|
-
*
|
|
16
|
-
*
|
|
17
|
-
*
|
|
15
|
+
* A range of source code that contains JS expressions, tagged with its context.
|
|
16
|
+
* - 'script': inside a `<script>` block — use object literal `{...}` syntax
|
|
17
|
+
* - 'template': inside a template expression `{...}` or event handler — use `gg._o()` syntax
|
|
18
|
+
*/
|
|
19
|
+
export interface CodeRange {
|
|
20
|
+
start: number;
|
|
21
|
+
end: number;
|
|
22
|
+
context: 'script' | 'template';
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* A function scope range, mapping a byte range to the enclosing function name.
|
|
26
|
+
* Built from the estree AST during `collectCodeRanges()`.
|
|
27
|
+
*/
|
|
28
|
+
export interface FunctionScope {
|
|
29
|
+
start: number;
|
|
30
|
+
end: number;
|
|
31
|
+
name: string;
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Result of `collectCodeRanges()` — code ranges plus function scope info.
|
|
35
|
+
*/
|
|
36
|
+
export interface SvelteCodeInfo {
|
|
37
|
+
ranges: CodeRange[];
|
|
38
|
+
/** Function scopes extracted from the estree AST, sorted by start position. */
|
|
39
|
+
functionScopes: FunctionScope[];
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* Vite plugin that rewrites `gg(...)` and `gg.ns(...)` calls to
|
|
43
|
+
* `gg._ns({ns, file, line, col}, ...)` at build time. This gives each call
|
|
44
|
+
* site a unique namespace plus source location metadata for open-in-editor
|
|
45
|
+
* support, with zero runtime cost — no stack trace parsing needed.
|
|
18
46
|
*
|
|
19
|
-
* Works in both dev and prod.
|
|
20
|
-
*
|
|
21
|
-
* falls back to runtime stack parsing in dev and bare `gg:` in prod.
|
|
47
|
+
* Works in both dev and prod. Without the plugin, gg() falls back to runtime
|
|
48
|
+
* stack parsing in dev and bare `gg:` in prod.
|
|
22
49
|
*
|
|
23
50
|
* @example
|
|
24
51
|
* // vite.config.ts
|
|
@@ -29,3 +56,60 @@ export interface GgCallSitesPluginOptions {
|
|
|
29
56
|
* });
|
|
30
57
|
*/
|
|
31
58
|
export default function ggCallSitesPlugin(options?: GgCallSitesPluginOptions): Plugin;
|
|
59
|
+
/**
|
|
60
|
+
* Parse JavaScript/TypeScript code using acorn to extract function scopes.
|
|
61
|
+
* Returns function scope ranges for accurate function name detection in .js/.ts files.
|
|
62
|
+
* Uses @sveltejs/acorn-typescript plugin to handle TypeScript syntax.
|
|
63
|
+
*
|
|
64
|
+
* For .svelte files, use `collectCodeRanges()` instead (which uses svelte.parse()).
|
|
65
|
+
*/
|
|
66
|
+
export declare function parseJavaScript(code: string): FunctionScope[];
|
|
67
|
+
/**
|
|
68
|
+
* Use `svelte.parse()` to collect all code ranges and function scopes in a .svelte file.
|
|
69
|
+
*
|
|
70
|
+
* Code ranges identify where JS expressions live:
|
|
71
|
+
* - `<script>` blocks (context: 'script')
|
|
72
|
+
* - Template expressions: `{expr}`, `onclick={expr}`, `bind:value={expr}`,
|
|
73
|
+
* `class:name={expr}`, `{#if expr}`, `{#each expr}`, etc. (context: 'template')
|
|
74
|
+
*
|
|
75
|
+
* Function scopes are extracted from the estree AST in script blocks, mapping
|
|
76
|
+
* byte ranges to enclosing function names. This replaces regex-based function
|
|
77
|
+
* detection for .svelte files.
|
|
78
|
+
*
|
|
79
|
+
* Text nodes (prose) are NOT included, so `gg()` in `<p>text gg()</p>` is never transformed.
|
|
80
|
+
*/
|
|
81
|
+
export declare function collectCodeRanges(code: string): SvelteCodeInfo;
|
|
82
|
+
/**
|
|
83
|
+
* Find the innermost enclosing function name for a byte position
|
|
84
|
+
* using the pre-built function scope map.
|
|
85
|
+
* Returns empty string if not inside any named function.
|
|
86
|
+
*/
|
|
87
|
+
export declare function findEnclosingFunctionFromScopes(pos: number, scopes: FunctionScope[]): string;
|
|
88
|
+
/**
|
|
89
|
+
* Escape a string for embedding as a single-quoted JS string literal.
|
|
90
|
+
*/
|
|
91
|
+
export declare function escapeForString(s: string): string;
|
|
92
|
+
/**
|
|
93
|
+
* Transform gg() and gg.ns() calls in source code to gg._ns({ns, file, line, col, src}, ...) calls.
|
|
94
|
+
*
|
|
95
|
+
* Handles:
|
|
96
|
+
* - bare gg(expr) → gg._ns({ns, file, line, col, src: 'expr'}, expr)
|
|
97
|
+
* - gg.ns('label', expr) → gg._ns({ns, file, line, col, src: 'expr'}, expr)
|
|
98
|
+
* - label supports template variables: $NS, $FN, $FILE, $LINE, $COL
|
|
99
|
+
* - plain label (no variables) is used as-is (no auto @fn append)
|
|
100
|
+
* - gg.enable, gg.disable, gg.clearPersist, gg._onLog, gg._ns → left untouched
|
|
101
|
+
* - gg inside strings and comments → left untouched
|
|
102
|
+
*
|
|
103
|
+
* For .svelte files, `svelteInfo` (from `collectCodeRanges()`) determines which
|
|
104
|
+
* positions contain JS code and provides AST-based function scope detection.
|
|
105
|
+
* Script ranges use `{...}` object literal syntax; template ranges use `gg._o()`
|
|
106
|
+
* function-call syntax (no braces in Svelte markup). Positions outside any code
|
|
107
|
+
* range (e.g. prose text) are skipped.
|
|
108
|
+
*
|
|
109
|
+
* For .js/.ts files, `jsFunctionScopes` (from `parseJavaScript()`) provides
|
|
110
|
+
* AST-based function scope detection (no regex fallback).
|
|
111
|
+
*/
|
|
112
|
+
export declare function transformGgCalls(code: string, shortPath: string, filePath: string, svelteInfo?: SvelteCodeInfo, jsFunctionScopes?: FunctionScope[]): {
|
|
113
|
+
code: string;
|
|
114
|
+
map: null;
|
|
115
|
+
} | null;
|