From: Evan You Date: Fri, 3 Feb 2023 10:29:17 +0000 (+0800) Subject: build: stricter conditions for UnaryExpression in const enum plugin X-Git-Tag: v3.3.0-alpha.1~4 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=b49b9eff20e7b77896d6a1cc811eb5e2e5fea8f4;p=thirdparty%2Fvuejs%2Fcore.git build: stricter conditions for UnaryExpression in const enum plugin --- diff --git a/scripts/const-enum.js b/scripts/const-enum.js index 133b6da180..b4dbc1770b 100644 --- a/scripts/const-enum.js +++ b/scripts/const-enum.js @@ -112,9 +112,17 @@ export async function constEnum() { } if (init.type === 'UnaryExpression') { - // @ts-ignore assume all operands are literals - const exp = `${init.operator}${init.argument.value}` - value = evaluate(exp) + if ( + init.argument.type === 'StringLiteral' || + init.argument.type === 'NumericLiteral' + ) { + const exp = `${init.operator}${init.argument.value}` + value = evaluate(exp) + } else { + throw new Error( + `unhandled UnaryExpression argument type ${init.argument.type} in ${file}` + ) + } } if (value === undefined) {