MCPcopy
hub / github.com/webpack/webpack / evaluate

Method evaluate

lib/javascript/JavascriptParser.js:5072–5082  ·  view source on GitHub ↗

* Returns evaluation result. * @param {string} source source code * @returns {BasicEvaluatedExpression} evaluation result

(source)

Source from the content-addressed store, hash-verified

5070 * @returns {BasicEvaluatedExpression} evaluation result
5071 */
5072 evaluate(source) {
5073 const { ast } = JavascriptParser._parse(
5074 `(${source})`,
5075 { sourceType: this.sourceType },
5076 this.options.parse
5077 );
5078 if (ast.body.length !== 1 || ast.body[0].type !== "ExpressionStatement") {
5079 throw new Error("evaluate: Source is not a expression");
5080 }
5081 return this.evaluateExpression(ast.body[0].expression);
5082 }
5083
5084 /**
5085 * Checks whether this javascript parser is pure.

Callers 5

applyDefineMethod · 0.80
runModuleFunction · 0.80
runMethod · 0.80
asModule.jsFile · 0.80

Calls 2

evaluateExpressionMethod · 0.95
_parseMethod · 0.80

Tested by

no test coverage detected