MCPcopy Create free account
hub / github.com/microsoft/vscode-js-debug / statementToFunction

Function statementToFunction

src/common/sourceCodeManipulations.ts:204–224  ·  view source on GitHub ↗

* statement => function () { catchAndReturnErrors(return statement); } * statement; statement => function () { catchAndReturnErrors(statement; return statement); }

(
  parameterNames: ReadonlyArray<string>,
  statements: ReadonlyArray<Statement>,
  preserveThis: boolean,
  catchAndReturnErrors: boolean,
)

Source from the content-addressed store, hash-verified

202 * statement; statement => function () { catchAndReturnErrors(statement; return statement); }
203 */
204function statementToFunction(
205 parameterNames: ReadonlyArray<string>,
206 statements: ReadonlyArray<Statement>,
207 preserveThis: boolean,
208 catchAndReturnErrors: boolean,
209) {
210 const last = statements[statements.length - 1];
211 if (last.type !== 'ReturnStatement') {
212 const expr = statementToExpression(last);
213 if (expr) {
214 statements = [...statements.slice(0, -1), { type: 'ReturnStatement', argument: expr }];
215 }
216 }
217
218 return codeToFunctionExecutingCode(
219 parameterNames,
220 statements,
221 preserveThis,
222 catchAndReturnErrors,
223 );
224}
225
226export function statementToExpression(stmt: Statement): Expression | undefined {
227 switch (stmt.type) {

Callers 2

statementsToFunctionFunction · 0.85

Calls 2

statementToExpressionFunction · 0.85

Tested by

no test coverage detected