]> git.ipfire.org Git - thirdparty/vuejs/core.git/commitdiff
build: stricter conditions for UnaryExpression in const enum plugin
authorEvan You <yyx990803@gmail.com>
Fri, 3 Feb 2023 10:29:17 +0000 (18:29 +0800)
committerEvan You <yyx990803@gmail.com>
Fri, 3 Feb 2023 10:29:17 +0000 (18:29 +0800)
scripts/const-enum.js

index 133b6da1803cdd1fb02575a8184bec0535a2cf74..b4dbc1770b9733ac83a37890dfcc5f5763643b2b 100644 (file)
@@ -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) {