wasm-idle 1.1.0 → 1.2.0
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 +267 -112
- package/dist/container/bash-profile.d.ts +80 -0
- package/dist/container/bash-profile.js +328 -0
- package/dist/container/binding.d.ts +39 -0
- package/dist/container/binding.js +331 -0
- package/dist/container/clang-runtime.d.ts +42 -0
- package/dist/container/clang-runtime.js +561 -0
- package/dist/container/client.d.ts +14 -0
- package/dist/container/client.js +185 -0
- package/dist/container/explorer.d.ts +31 -0
- package/dist/container/explorer.js +112 -0
- package/dist/container/index.d.ts +11 -0
- package/dist/container/index.js +11 -0
- package/dist/container/owner-worker.d.ts +19 -0
- package/dist/container/owner-worker.js +464 -0
- package/dist/container/protocol.d.ts +84 -0
- package/dist/container/protocol.js +28 -0
- package/dist/container/runtime-adapter.d.ts +75 -0
- package/dist/container/runtime-adapter.js +537 -0
- package/dist/container/shell-control.d.ts +49 -0
- package/dist/container/shell-control.js +360 -0
- package/dist/container/workspace.d.ts +12 -0
- package/dist/container/workspace.js +29 -0
- package/dist/index.d.ts +1 -1
- package/dist/playground/assetBridge.js +111 -33
- package/dist/playground/assets.d.ts +10 -2
- package/dist/playground/c3.js +22 -0
- package/dist/playground/c3Memory.d.ts +19 -0
- package/dist/playground/c3Memory.js +117 -0
- package/dist/playground/cachedClang.js +143 -34
- package/dist/playground/clang.d.ts +5 -1
- package/dist/playground/clang.js +61 -5
- package/dist/playground/clangAssetIntegrity.js +6 -6
- package/dist/playground/clangWorkerProtocol.d.ts +12 -1
- package/dist/playground/cobol.d.ts +3 -0
- package/dist/playground/cobol.js +10 -1
- package/dist/playground/commonlispAssets.d.ts +2 -2
- package/dist/playground/compiledArtifactCache.d.ts +3 -1
- package/dist/playground/compiledArtifactCache.js +31 -5
- package/dist/playground/compiledLldb.d.ts +41 -0
- package/dist/playground/compiledLldb.js +167 -0
- package/dist/playground/d.d.ts +10 -2
- package/dist/playground/d.js +161 -14
- package/dist/playground/debugDeadline.d.ts +12 -0
- package/dist/playground/debugDeadline.js +34 -0
- package/dist/playground/debugMailbox.d.ts +12 -0
- package/dist/playground/debugMailbox.js +77 -0
- package/dist/playground/dotnet.js +6 -8
- package/dist/playground/fortran.d.ts +3 -0
- package/dist/playground/fortran.js +10 -1
- package/dist/playground/go.js +23 -7
- package/dist/playground/goDebugInstrumentation.js +207 -97
- package/dist/playground/java-debug-FMHDKUN6.js +124 -0
- package/dist/playground/java-debug-notices.txt +492 -0
- package/dist/playground/java.d.ts +17 -1
- package/dist/playground/java.js +162 -5
- package/dist/playground/javaDebug.d.ts +62 -0
- package/dist/playground/javaDebug.js +305 -0
- package/dist/playground/javaDebugBridge.d.ts +6 -0
- package/dist/playground/javaDebugBridge.js +250 -0
- package/dist/playground/javaDebugSource.d.ts +9 -0
- package/dist/playground/javaDebugSource.js +4 -0
- package/dist/playground/javaRuntimeErrors.d.ts +9 -0
- package/dist/playground/javaRuntimeErrors.js +93 -0
- package/dist/playground/lean4Assets.d.ts +1 -25
- package/dist/playground/lean4Assets.js +2 -123
- package/dist/playground/lfortran.js +10 -0
- package/dist/playground/lfortranAssets.d.ts +2 -2
- package/dist/playground/lldbSession.d.ts +23 -2
- package/dist/playground/lldbSession.js +278 -58
- package/dist/playground/lldbSourcePath.d.ts +2 -0
- package/dist/playground/lldbSourcePath.js +9 -0
- package/dist/playground/lua.d.ts +20 -1
- package/dist/playground/lua.js +190 -8
- package/dist/playground/luaDebug.d.ts +1 -0
- package/dist/playground/luaDebug.js +1 -0
- package/dist/playground/nim.d.ts +1 -0
- package/dist/playground/nim.js +30 -0
- package/dist/playground/objectivec.d.ts +10 -6
- package/dist/playground/objectivec.js +85 -10
- package/dist/playground/options.d.ts +12 -4
- package/dist/playground/python.d.ts +8 -1
- package/dist/playground/python.js +89 -6
- package/dist/playground/ruby.d.ts +10 -1
- package/dist/playground/ruby.js +66 -1
- package/dist/playground/rubyDebug.d.ts +21 -0
- package/dist/playground/rubyDebug.js +128 -0
- package/dist/playground/runtimeAssetCache.d.ts +1 -32
- package/dist/playground/runtimeAssetCache.js +1 -193
- package/dist/playground/runtimeSession.d.ts +2 -2
- package/dist/playground/runtimeSession.js +11 -11
- package/dist/playground/rust.d.ts +10 -0
- package/dist/playground/rust.js +230 -51
- package/dist/playground/sandbox.d.ts +8 -1
- package/dist/playground/staticStdinRing.d.ts +2 -1
- package/dist/playground/staticStdinRing.js +21 -10
- package/dist/playground/staticWorkerRuntime.d.ts +15 -1
- package/dist/playground/staticWorkerRuntime.js +127 -19
- package/dist/playground/stdinBuffer.d.ts +1 -1
- package/dist/playground/stdinBuffer.js +19 -2
- package/dist/playground/tinygo.d.ts +3 -0
- package/dist/playground/tinygo.js +88 -6
- package/dist/playground/typescript.js +8 -0
- package/dist/playground/v.d.ts +6 -2
- package/dist/playground/v.js +76 -13
- package/dist/playground/wasmAwkVersion.d.ts +13 -13
- package/dist/playground/wasmAwkVersion.js +4 -4
- package/dist/playground/wasmBqnVersion.d.ts +2 -2
- package/dist/playground/wasmBqnVersion.js +2 -2
- package/dist/playground/wasmC3Version.d.ts +2 -2
- package/dist/playground/wasmC3Version.js +2 -2
- package/dist/playground/wasmClojureScriptVersion.d.ts +2 -2
- package/dist/playground/wasmClojureScriptVersion.js +2 -2
- package/dist/playground/wasmCommonLispVersion.d.ts +2 -2
- package/dist/playground/wasmCommonLispVersion.js +2 -2
- package/dist/playground/wasmDIntegrity.d.ts +5 -5
- package/dist/playground/wasmDIntegrity.js +5 -5
- package/dist/playground/wasmDVersion.d.ts +16 -1
- package/dist/playground/wasmDVersion.js +16 -1
- package/dist/playground/wasmDebugVersion.d.ts +1 -1
- package/dist/playground/wasmDebugVersion.js +1 -1
- package/dist/playground/wasmForthVersion.d.ts +2 -2
- package/dist/playground/wasmForthVersion.js +2 -2
- package/dist/playground/wasmGleamVersion.d.ts +2 -2
- package/dist/playground/wasmGleamVersion.js +2 -2
- package/dist/playground/wasmGrainVersion.d.ts +2 -2
- package/dist/playground/wasmGrainVersion.js +2 -2
- package/dist/playground/wasmJVersion.d.ts +2 -2
- package/dist/playground/wasmJVersion.js +2 -2
- package/dist/playground/wasmJanetVersion.js +2 -2
- package/dist/playground/wasmJuliaVersion.js +2 -2
- package/dist/playground/wasmLean4Version.d.ts +1 -110
- package/dist/playground/wasmLean4Version.js +2 -111
- package/dist/playground/wasmLfortranVersion.d.ts +2 -2
- package/dist/playground/wasmLfortranVersion.js +2 -2
- package/dist/playground/wasmLuaVersion.d.ts +1 -1
- package/dist/playground/wasmLuaVersion.js +1 -1
- package/dist/playground/wasmNimVersion.d.ts +9 -9
- package/dist/playground/wasmNimVersion.js +6 -6
- package/dist/playground/wasmOcamlVersion.d.ts +2 -2
- package/dist/playground/wasmOcamlVersion.js +1 -1
- package/dist/playground/wasmPascalVersion.js +2 -2
- package/dist/playground/wasmPerlVersion.js +2 -2
- package/dist/playground/wasmPrologVersion.d.ts +2 -2
- package/dist/playground/wasmPrologVersion.js +2 -2
- package/dist/playground/wasmReScriptVersion.d.ts +2 -2
- package/dist/playground/wasmReScriptVersion.js +2 -2
- package/dist/playground/wasmRustVersion.d.ts +26 -38
- package/dist/playground/wasmRustVersion.js +25 -40
- package/dist/playground/wasmTclVersion.d.ts +4 -4
- package/dist/playground/wasmTclVersion.js +2 -2
- package/dist/playground/wasmTinyGoVersion.d.ts +14 -14
- package/dist/playground/wasmTinyGoVersion.js +14 -14
- package/dist/playground/wasmTypeScriptVersion.d.ts +5 -5
- package/dist/playground/wasmTypeScriptVersion.js +5 -5
- package/dist/playground/worker/cachedClangCompile.js +52 -4
- package/dist/playground/worker/cachedClangExecute.js +6 -5
- package/dist/playground/worker/clang.js +33 -11
- package/dist/playground/worker/cobol.js +3 -3
- package/dist/playground/worker/d.js +63 -7
- package/dist/playground/worker/fortran.js +3 -3
- package/dist/playground/worker/go.js +16 -5
- package/dist/playground/worker/haskell.js +10 -7
- package/dist/playground/worker/java.js +263 -45
- package/dist/playground/worker/javaDebugEvaluator.d.ts +16 -0
- package/dist/playground/worker/javaDebugEvaluator.js +44 -0
- package/dist/playground/worker/javaDebugRuntime.d.ts +24 -0
- package/dist/playground/worker/javaDebugRuntime.js +315 -0
- package/dist/playground/worker/javaOutput.d.ts +11 -0
- package/dist/playground/worker/javaOutput.js +54 -0
- package/dist/playground/worker/lua.js +15 -3
- package/dist/playground/worker/php.js +15 -9
- package/dist/playground/worker/python.js +102 -30
- package/dist/playground/worker/pythonExecution.js +17 -1
- package/dist/playground/worker/pythonWorkspaceFiles.d.ts +6 -0
- package/dist/playground/worker/pythonWorkspaceFiles.js +26 -0
- package/dist/playground/worker/pythonWorkspaceImports.d.ts +4 -0
- package/dist/playground/worker/pythonWorkspaceImports.js +129 -0
- package/dist/playground/worker/r.js +13 -6
- package/dist/playground/worker/ruby.js +13 -0
- package/dist/playground/worker/rubyDebugPreview.d.ts +2 -0
- package/dist/playground/worker/rubyDebugPreview.js +80 -0
- package/dist/playground/worker/rubyTracepoint.d.ts +16 -0
- package/dist/playground/worker/rubyTracepoint.js +162 -0
- package/dist/playground/worker/rust.js +38 -3
- package/dist/playground/worker/sqlite.js +4 -3
- package/dist/playground/worker/tinygo.js +11 -3
- package/dist/playground/worker/typescript.js +2 -3
- package/dist/playground/worker/v.js +32 -7
- package/dist/playground/worker/wat.js +2 -3
- package/dist/playground/worker/zig.js +20 -6
- package/dist/playground/workerSession.d.ts +1 -28
- package/dist/playground/workerSession.js +1 -164
- package/dist/playground/zig.js +4 -0
- package/package.json +66 -15
- package/dist/playground/worker/python.runtime.cases.d.ts +0 -1
- package/dist/playground/worker/python.runtime.cases.js +0 -374
|
@@ -69,59 +69,113 @@ function stripLineComment(line) {
|
|
|
69
69
|
const commentStart = lineCommentStart(line);
|
|
70
70
|
return commentStart === -1 ? line : line.slice(0, commentStart);
|
|
71
71
|
}
|
|
72
|
-
|
|
73
|
-
const
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
72
|
+
const goKeywords = new Set([
|
|
73
|
+
...'break case chan const continue default defer else fallthrough for func go'.split(' '),
|
|
74
|
+
...'goto if import interface map package range return select struct switch type var'.split(' ')
|
|
75
|
+
]);
|
|
76
|
+
// Final tokens after which Go inserts a semicolon at a line break. Literals are tokenized as
|
|
77
|
+
// '0' (number), '"' (string), "'" (rune) and '`' (raw string).
|
|
78
|
+
const statementEndTokens = new Set([
|
|
79
|
+
...'break continue fallthrough return ++ -- ) ] }'.split(' '),
|
|
80
|
+
...['0', '"', "'", '`']
|
|
81
|
+
]);
|
|
82
|
+
function isIdentifier(token) {
|
|
83
|
+
return token !== undefined && /^[\p{L}_]/u.test(token) && !goKeywords.has(token);
|
|
84
|
+
}
|
|
85
|
+
function endsStatement(token) {
|
|
86
|
+
return statementEndTokens.has(token) || isIdentifier(token);
|
|
87
|
+
}
|
|
88
|
+
// Inside an if/for/switch header Go reads `T{` as the block, but `[]T{`, `[N]*pkg.T{`,
|
|
89
|
+
// `map[K]V{` and `struct{...}{` still open composite literals.
|
|
90
|
+
function followsLiteralType(tokens, braceIndex, closedFrame) {
|
|
91
|
+
let index = braceIndex - 1;
|
|
92
|
+
if (tokens[index] === '}')
|
|
93
|
+
return closedFrame === 'type';
|
|
94
|
+
if (!isIdentifier(tokens[index]))
|
|
95
|
+
return false;
|
|
96
|
+
index -= 1;
|
|
97
|
+
if (tokens[index] === '.' && isIdentifier(tokens[index - 1]))
|
|
98
|
+
index -= 2;
|
|
99
|
+
const pointer = tokens[index] === '*';
|
|
100
|
+
while (tokens[index] === '*')
|
|
101
|
+
index -= 1;
|
|
102
|
+
if (tokens[index] !== ']')
|
|
103
|
+
return false;
|
|
104
|
+
if (!pointer)
|
|
105
|
+
return true;
|
|
106
|
+
// `a[i] * b {` multiplies; only `[]*T` and `map[K]*V` are element types.
|
|
107
|
+
let open = index - 1;
|
|
108
|
+
for (let depth = 1; open >= 0; open -= 1) {
|
|
109
|
+
if (tokens[open] === ']')
|
|
110
|
+
depth += 1;
|
|
111
|
+
else if (tokens[open] === '[' && --depth === 0)
|
|
112
|
+
break;
|
|
113
|
+
}
|
|
114
|
+
return open === index - 1 || tokens[open - 1] === 'map';
|
|
115
|
+
}
|
|
116
|
+
function lineTokens(line, state, onWord) {
|
|
117
|
+
const tokens = [];
|
|
118
|
+
const wordPattern = /[\p{L}_][\p{L}\p{N}_]*|\.?\d[\p{L}\p{N}_.]*/uy;
|
|
119
|
+
let index = 0;
|
|
120
|
+
while (index < line.length) {
|
|
121
|
+
if (state.rawString || state.blockComment) {
|
|
122
|
+
const end = line.indexOf(state.rawString ? '`' : '*/', index);
|
|
123
|
+
if (end === -1)
|
|
124
|
+
break;
|
|
125
|
+
if (state.rawString)
|
|
126
|
+
tokens.push('`');
|
|
127
|
+
index = end + (state.rawString ? 1 : 2);
|
|
128
|
+
state.rawString = false;
|
|
129
|
+
state.blockComment = false;
|
|
130
|
+
continue;
|
|
131
|
+
}
|
|
132
|
+
const character = line[index] || '';
|
|
133
|
+
if (/\s/.test(character)) {
|
|
134
|
+
index += 1;
|
|
135
|
+
continue;
|
|
136
|
+
}
|
|
137
|
+
if (line.startsWith('//', index))
|
|
138
|
+
break;
|
|
139
|
+
if (line.startsWith('/*', index)) {
|
|
140
|
+
state.blockComment = true;
|
|
141
|
+
index += 2;
|
|
142
|
+
continue;
|
|
143
|
+
}
|
|
144
|
+
if (character === '`') {
|
|
145
|
+
state.rawString = true;
|
|
146
|
+
index += 1;
|
|
147
|
+
continue;
|
|
148
|
+
}
|
|
149
|
+
if (character === '"' || character === "'") {
|
|
150
|
+
index += 1;
|
|
151
|
+
while (index < line.length && line[index] !== character) {
|
|
152
|
+
index += line[index] === '\\' ? 2 : 1;
|
|
93
153
|
}
|
|
94
|
-
|
|
95
|
-
|
|
154
|
+
tokens.push(character);
|
|
155
|
+
index += 1;
|
|
96
156
|
continue;
|
|
97
157
|
}
|
|
98
|
-
|
|
99
|
-
|
|
158
|
+
wordPattern.lastIndex = index;
|
|
159
|
+
const word = wordPattern.exec(line)?.[0];
|
|
160
|
+
if (word) {
|
|
161
|
+
tokens.push(/^[\p{L}_]/u.test(word) ? word : '0');
|
|
162
|
+
index += word.length;
|
|
163
|
+
onWord?.(word, index);
|
|
100
164
|
continue;
|
|
101
165
|
}
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
else if (character === '(')
|
|
107
|
-
parens += 1;
|
|
108
|
-
else if (character === ')')
|
|
109
|
-
parens -= 1;
|
|
110
|
-
else if (character === '[')
|
|
111
|
-
brackets += 1;
|
|
112
|
-
else if (character === ']')
|
|
113
|
-
brackets -= 1;
|
|
166
|
+
const operator = ['++', '--', ':=', '...'].find((candidate) => line.startsWith(candidate, index)) ||
|
|
167
|
+
character;
|
|
168
|
+
tokens.push(operator);
|
|
169
|
+
index += operator.length;
|
|
114
170
|
}
|
|
115
|
-
return
|
|
171
|
+
return tokens;
|
|
116
172
|
}
|
|
117
173
|
function functionNameFromLine(line) {
|
|
118
174
|
const source = stripLineComment(line).trim();
|
|
119
175
|
const match = source.match(/^func\s+(?:\([^)]*\)\s*)?([A-Za-z_]\w*)\s*\(/);
|
|
120
176
|
return match?.[1] || null;
|
|
121
177
|
}
|
|
122
|
-
function shouldInstrumentLine(line
|
|
123
|
-
if (parenDepth > 0 || bracketDepth > 0)
|
|
124
|
-
return false;
|
|
178
|
+
function shouldInstrumentLine(line) {
|
|
125
179
|
const trimmed = stripLineComment(line).trim();
|
|
126
180
|
if (!trimmed)
|
|
127
181
|
return false;
|
|
@@ -141,80 +195,134 @@ function shouldInstrumentLine(line, parenDepth, bracketDepth) {
|
|
|
141
195
|
}
|
|
142
196
|
function insertDebugImports(source) {
|
|
143
197
|
const lines = source.split('\n');
|
|
144
|
-
const
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
198
|
+
const state = { rawString: false, blockComment: false };
|
|
199
|
+
let packageKeyword = false;
|
|
200
|
+
for (let index = 0; index < lines.length; index += 1) {
|
|
201
|
+
const line = lines[index];
|
|
202
|
+
let packageNameEnd;
|
|
203
|
+
lineTokens(line, state, (word, end) => {
|
|
204
|
+
if (packageNameEnd !== undefined)
|
|
205
|
+
return;
|
|
206
|
+
if (packageKeyword)
|
|
207
|
+
packageNameEnd = end;
|
|
208
|
+
else if (word === 'package')
|
|
209
|
+
packageKeyword = true;
|
|
210
|
+
});
|
|
211
|
+
if (packageNameEnd === undefined)
|
|
212
|
+
continue;
|
|
213
|
+
// Insert before trailing comments, which may span lines or end beside an import.
|
|
214
|
+
// Keep the suffix on ')' so an explicit package semicolon still terminates a declaration.
|
|
215
|
+
lines.splice(index, 1, line.slice(0, packageNameEnd), '', 'import (', ...debugImports.map((entry) => `\t${entry}`), ')' + line.slice(packageNameEnd));
|
|
160
216
|
return lines.join('\n');
|
|
161
217
|
}
|
|
162
|
-
|
|
163
|
-
lines.splice(importStart, 1, 'import (', `\t${singleImport}`, ...debugImports.map((entry) => `\t${entry}`), ')');
|
|
164
|
-
return lines.join('\n');
|
|
165
|
-
}
|
|
166
|
-
function insertDebugSupport(source) {
|
|
167
|
-
const lines = source.split('\n');
|
|
168
|
-
let insertIndex = lines.findIndex((line) => /^\s*import\b/.test(line));
|
|
169
|
-
if (insertIndex === -1) {
|
|
170
|
-
insertIndex = lines.findIndex((line) => /^\s*package\s+\w+/.test(line));
|
|
171
|
-
if (insertIndex === -1)
|
|
172
|
-
return source;
|
|
173
|
-
insertIndex += 1;
|
|
174
|
-
}
|
|
175
|
-
else if (/^\s*import\s*\(/.test(lines[insertIndex] || '')) {
|
|
176
|
-
for (; insertIndex < lines.length; insertIndex += 1) {
|
|
177
|
-
if (/^\s*\)/.test(lines[insertIndex] || '')) {
|
|
178
|
-
insertIndex += 1;
|
|
179
|
-
break;
|
|
180
|
-
}
|
|
181
|
-
}
|
|
182
|
-
}
|
|
183
|
-
else {
|
|
184
|
-
insertIndex += 1;
|
|
185
|
-
}
|
|
186
|
-
lines.splice(insertIndex, 0, debugSupportSource.trim());
|
|
187
|
-
return lines.join('\n');
|
|
218
|
+
return source;
|
|
188
219
|
}
|
|
189
220
|
function instrumentFunctionLines(source) {
|
|
190
221
|
const lines = source.split('\n');
|
|
191
222
|
const instrumented = [];
|
|
192
223
|
const functionStack = [];
|
|
224
|
+
const lexState = { rawString: false, blockComment: false };
|
|
225
|
+
const frames = [];
|
|
226
|
+
// Frame depths where a `func` signature still awaits its body, and where an if/for/switch
|
|
227
|
+
// header still awaits its block.
|
|
228
|
+
let pendingFunctionDepths = [];
|
|
229
|
+
let headerDepth = -1;
|
|
230
|
+
let closedFrame;
|
|
231
|
+
let previousToken = ';';
|
|
232
|
+
let continuesStatement = false;
|
|
233
|
+
let followsLabel = false;
|
|
193
234
|
let braceDepth = 0;
|
|
194
|
-
let parenDepth = 0;
|
|
195
|
-
let bracketDepth = 0;
|
|
196
235
|
for (let index = 0; index < lines.length; index += 1) {
|
|
197
236
|
const line = lines[index] || '';
|
|
198
237
|
const lineNumber = index + 1;
|
|
199
|
-
const
|
|
238
|
+
const startsInCode = !lexState.rawString && !lexState.blockComment;
|
|
239
|
+
const functionName = startsInCode ? functionNameFromLine(line) : null;
|
|
200
240
|
const inFunction = functionStack.length > 0;
|
|
201
241
|
const indent = line.match(/^\s*/)?.[0] || '';
|
|
202
|
-
|
|
242
|
+
// Only hook lines that start a statement directly inside a block: not inside a raw
|
|
243
|
+
// string, comment, composite literal, call or index, and not continuing the previous line.
|
|
244
|
+
if (inFunction &&
|
|
245
|
+
startsInCode &&
|
|
246
|
+
frames.at(-1) === 'block' &&
|
|
247
|
+
!frames.includes('(') &&
|
|
248
|
+
!frames.includes('[') &&
|
|
249
|
+
!continuesStatement &&
|
|
250
|
+
!followsLabel &&
|
|
251
|
+
shouldInstrumentLine(line)) {
|
|
203
252
|
instrumented.push(`${indent}__wasmIdleDebugLine(${lineNumber})`);
|
|
204
253
|
}
|
|
205
254
|
instrumented.push(line);
|
|
206
|
-
const
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
255
|
+
const tokens = lineTokens(line, lexState);
|
|
256
|
+
let braces = 0;
|
|
257
|
+
for (let tokenIndex = 0; tokenIndex < tokens.length; tokenIndex += 1) {
|
|
258
|
+
const token = tokens[tokenIndex] || '';
|
|
259
|
+
const depth = frames.length;
|
|
260
|
+
if (token === '(' || token === '[') {
|
|
261
|
+
frames.push(token);
|
|
262
|
+
}
|
|
263
|
+
else if (token === ')' || token === ']' || token === '}') {
|
|
264
|
+
closedFrame = frames.pop();
|
|
265
|
+
if (token === '}')
|
|
266
|
+
braces -= 1;
|
|
267
|
+
pendingFunctionDepths = pendingFunctionDepths.filter((pending) => pending <= frames.length);
|
|
268
|
+
if (headerDepth > frames.length)
|
|
269
|
+
headerDepth = -1;
|
|
270
|
+
}
|
|
271
|
+
else if (token === '{') {
|
|
272
|
+
let frame = '{';
|
|
273
|
+
if (pendingFunctionDepths.includes(depth)) {
|
|
274
|
+
frame = 'block';
|
|
275
|
+
pendingFunctionDepths = pendingFunctionDepths.filter((pending) => pending !== depth);
|
|
276
|
+
}
|
|
277
|
+
else if (previousToken === 'struct' || previousToken === 'interface') {
|
|
278
|
+
frame = 'type';
|
|
279
|
+
}
|
|
280
|
+
else if (['else', 'for', 'switch', 'select'].includes(previousToken) ||
|
|
281
|
+
(headerDepth === depth &&
|
|
282
|
+
tokenIndex === tokens.length - 1 &&
|
|
283
|
+
!followsLiteralType(tokens, tokenIndex, closedFrame)) ||
|
|
284
|
+
([';', '{', ':'].includes(previousToken) &&
|
|
285
|
+
(frames.at(-1) ?? 'block') === 'block')) {
|
|
286
|
+
// Go ends an if/for/switch header at the `{` that closes its line; any other
|
|
287
|
+
// `{` after an operand (`P{`, `[]int{`) opens a literal.
|
|
288
|
+
frame = 'block';
|
|
289
|
+
if (headerDepth === depth)
|
|
290
|
+
headerDepth = -1;
|
|
291
|
+
}
|
|
292
|
+
frames.push(frame);
|
|
293
|
+
braces += 1;
|
|
294
|
+
}
|
|
295
|
+
else if (token === 'func' && previousToken !== ']' && previousToken !== 'chan') {
|
|
296
|
+
pendingFunctionDepths.push(depth);
|
|
297
|
+
}
|
|
298
|
+
else if (['if', 'for', 'switch', 'select'].includes(token)) {
|
|
299
|
+
headerDepth = depth;
|
|
300
|
+
}
|
|
301
|
+
else if ([',', ';', '=', ':='].includes(token)) {
|
|
302
|
+
pendingFunctionDepths = pendingFunctionDepths.filter((pending) => pending !== depth);
|
|
303
|
+
}
|
|
304
|
+
previousToken = token;
|
|
305
|
+
}
|
|
306
|
+
const lastToken = tokens.at(-1);
|
|
307
|
+
if (lastToken !== undefined) {
|
|
308
|
+
const trimmed = stripLineComment(line).trim();
|
|
309
|
+
continuesStatement = !endsStatement(lastToken) && !['{', ':', ';'].includes(lastToken);
|
|
310
|
+
followsLabel = /^[A-Za-z_]\w*:$/.test(trimmed) && trimmed !== 'default:';
|
|
311
|
+
if (endsStatement(lastToken)) {
|
|
312
|
+
previousToken = ';';
|
|
313
|
+
pendingFunctionDepths = pendingFunctionDepths.filter((pending) => pending < frames.length);
|
|
314
|
+
if (headerDepth >= frames.length)
|
|
315
|
+
headerDepth = -1;
|
|
316
|
+
}
|
|
317
|
+
}
|
|
318
|
+
// A signature line that ends inside a raw string or block comment has no place for the
|
|
319
|
+
// entry hook; leave that function uninstrumented rather than edit the literal.
|
|
320
|
+
if (functionName && braces > 0 && !lexState.rawString && !lexState.blockComment) {
|
|
211
321
|
const bodyIndent = `${indent}\t`;
|
|
212
322
|
instrumented.push(`${bodyIndent}__wasmIdleDebugEnter(${JSON.stringify(functionName)}, ${lineNumber})`, `${bodyIndent}defer __wasmIdleDebugLeave()`);
|
|
213
|
-
functionStack.push({ depth:
|
|
323
|
+
functionStack.push({ depth: braceDepth + braces, name: functionName });
|
|
214
324
|
}
|
|
215
|
-
braceDepth
|
|
216
|
-
parenDepth = nextParenDepth;
|
|
217
|
-
bracketDepth = nextBracketDepth;
|
|
325
|
+
braceDepth += braces;
|
|
218
326
|
while (functionStack.length &&
|
|
219
327
|
braceDepth < functionStack[functionStack.length - 1].depth) {
|
|
220
328
|
functionStack.pop();
|
|
@@ -225,5 +333,7 @@ function instrumentFunctionLines(source) {
|
|
|
225
333
|
export function instrumentGoDebugSource(source) {
|
|
226
334
|
if (source.includes('__wasmIdleDebugLine'))
|
|
227
335
|
return source;
|
|
228
|
-
|
|
336
|
+
// Declarations may follow user code; placing them here keeps every user import
|
|
337
|
+
// ahead of declarations, including a second import block.
|
|
338
|
+
return `${insertDebugImports(instrumentFunctionLines(source))}\n\n${debugSupportSource.trim()}\n`;
|
|
229
339
|
}
|