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

Function statementsToFunction

src/common/sourceCodeManipulations.ts:61–99  ·  view source on GitHub ↗
(
  parameterNames: ReadonlyArray<string>,
  statements: ReadonlyArray<Statement>,
  catchAndReturnErrors: boolean,
)

Source from the content-addressed store, hash-verified

59 * statement; statement => function () { catchAndReturnErrors?(statement; return statement;) }
60 */
61export function statementsToFunction(
62 parameterNames: ReadonlyArray<string>,
63 statements: ReadonlyArray<Statement>,
64 catchAndReturnErrors: boolean,
65): AnyFunctionExpression {
66 if (statements.length > 1 || statements[0].type !== 'FunctionDeclaration') {
67 return statementToFunction(parameterNames, statements, true, catchAndReturnErrors);
68 }
69
70 return codeToFunctionExecutingCode(
71 parameterNames,
72 [
73 {
74 type: 'ReturnStatement',
75 argument: {
76 type: 'CallExpression',
77 optional: false,
78 arguments: [
79 { type: 'ThisExpression' },
80 ...parameterNames.map(name => ({ type: 'Identifier' as const, name })),
81 ],
82 callee: {
83 type: 'MemberExpression',
84 property: { type: 'Identifier', name: 'call' },
85 computed: false,
86 optional: false,
87 object: {
88 type: 'FunctionExpression',
89 params: statements[0].params,
90 body: statements[0].body,
91 },
92 },
93 },
94 },
95 ],
96 true,
97 catchAndReturnErrors,
98 );
99}
100
101/**
102 * code => (parameterNames) => return catchAndReturnErrors?(code)

Calls 3

statementToFunctionFunction · 0.85
mapMethod · 0.80

Tested by

no test coverage detected