MCPcopy Index your code
hub / github.com/NetEase/tango / code2expression

Function code2expression

packages/core/src/helpers/ast/parse.ts:81–98  ·  view source on GitHub ↗
(code: string)

Source from the content-addressed store, hash-verified

79 * @returns
80 */
81export function code2expression(code: string) {
82 if (!code) {
83 return;
84 }
85
86 if (code.endsWith(';')) {
87 code = code.slice(0, -1);
88 }
89
90 let expNode;
91 try {
92 expNode = t.cloneNode(parseExpression(code, babelParserConfig), false, true);
93 } catch (err) {
94 logger.error('invalid code', err);
95 // expNode = t.identifier('undefined');
96 }
97 return expNode;
98}
99
100/**
101 * 表达式代码片段转为 ast 树

Callers 10

prototype2jsxElementFunction · 0.90
CallExpressionFunction · 0.90
serviceConfig2NodeFunction · 0.90
ast.test.tsFile · 0.90
helpers.test.tsFile · 0.90
expressionCode2astFunction · 0.85
value2nodeFunction · 0.85

Calls 1

errorMethod · 0.80

Tested by

no test coverage detected