MCPcopy Create free account
hub / github.com/Snapchat/Valdi / generatePositions

Function generatePositions

valdi/vscode_debugger/src/common/sourceUtils.ts:47–73  ·  view source on GitHub ↗
(text: string)

Source from the content-addressed store, hash-verified

45}
46
47function generatePositions(text: string) {
48 const sourceFile = ts.createSourceFile(
49 'file.js',
50 text,
51 ts.ScriptTarget.ESNext,
52 /*setParentNodes */ false,
53 );
54
55 const result: number[] = [];
56 let index = 0;
57 let line = 0;
58 let column = 0;
59 function traverse(node: ts.Node) {
60 for (; index < node.pos; ++index) {
61 if (text[index] === '\n') {
62 ++line;
63 column = 0;
64 continue;
65 }
66 ++column;
67 }
68 result.push(line + 1, column);
69 ts.forEachChild(node, traverse);
70 }
71 traverse(sourceFile);
72 return result;
73}
74
75export function rewriteTopLevelAwait(code: string): string | undefined {
76 // Basic idea is to wrap code in async function, which

Callers 1

prettyPrintAsSourceMapFunction · 0.85

Calls 2

traverseFunction · 0.70
createSourceFileMethod · 0.45

Tested by

no test coverage detected