MCPcopy
hub / github.com/webpack/webpack / walkNewExpression

Method walkNewExpression

lib/javascript/JavascriptParser.js:3952–3995  ·  view source on GitHub ↗

* Walk new expression. * @param {NewExpression} expression new expression

(expression)

Source from the content-addressed store, hash-verified

3950 * @param {NewExpression} expression new expression
3951 */
3952 walkNewExpression(expression) {
3953 // TODO acorn-import-phases bug: it omits acorn's `!forNew` guard, so
3954 // `import.defer(...)`/`import.source(...)` are wrongly accepted as `new`
3955 // operands; drop once fixed. Parenthesized forms stay valid (check `(`).
3956 if (typeof this.state.source === "string") {
3957 let base = expression.callee;
3958 while (
3959 base.type === "MemberExpression" ||
3960 base.type === "CallExpression"
3961 ) {
3962 base = base.type === "MemberExpression" ? base.object : base.callee;
3963 }
3964 if (base.type === "ImportExpression") {
3965 const newStart = /** @type {Range} */ (expression.range)[0];
3966 const importStart = /** @type {Range} */ (base.range)[0];
3967 const between = this.state.source
3968 .slice(newStart, importStart)
3969 .replace(/\/\*[\s\S]*?\*\//g, "")
3970 .replace(/\/\/[^\n]*/g, "");
3971 if (!between.includes("(")) {
3972 const err =
3973 /** @type {SyntaxError & { loc?: { line: number, column: number } }} */
3974 (new SyntaxError("import call cannot be the target of `new`"));
3975 if (expression.loc) {
3976 err.loc = {
3977 line: expression.loc.start.line,
3978 column: expression.loc.start.column
3979 };
3980 }
3981 throw err;
3982 }
3983 }
3984 }
3985 const result = this.callHooksForExpression(
3986 this.hooks.new,
3987 expression.callee,
3988 expression
3989 );
3990 if (result === true) return;
3991 this.walkExpression(expression.callee);
3992 if (expression.arguments) {
3993 this.walkExpressions(expression.arguments);
3994 }
3995 }
3996
3997 /**
3998 * Walk yield expression.

Callers 1

walkExpressionMethod · 0.95

Calls 5

walkExpressionMethod · 0.95
walkExpressionsMethod · 0.95
sliceMethod · 0.80
replaceMethod · 0.45

Tested by

no test coverage detected