]> git.ipfire.org Git - thirdparty/vuejs/core.git/commitdiff
build: fix handling of const enum that rely on previous values
authorEvan You <yyx990803@gmail.com>
Fri, 3 Feb 2023 08:26:56 +0000 (16:26 +0800)
committerEvan You <yyx990803@gmail.com>
Fri, 3 Feb 2023 08:26:56 +0000 (16:26 +0800)
scripts/const-enum.mjs

index 5942b795c03167ed5a0277807911502079ebed2e..133b6da1803cdd1fb02575a8184bec0535a2cf74 100644 (file)
@@ -85,8 +85,29 @@ export async function constEnum() {
 
             // e.g. 1 << 2
             if (init.type === 'BinaryExpression') {
-              // @ts-ignore assume all operands are literals
-              const exp = `${init.left.value}${init.operator}${init.right.value}`
+              const resolveValue = node => {
+                if (
+                  node.type === 'NumericLiteral' ||
+                  node.type === 'StringLiteral'
+                ) {
+                  return node.value
+                } else if (node.type === 'MemberExpression') {
+                  const exp = content.slice(node.start, node.end)
+                  if (!(exp in enumData.defines)) {
+                    throw new Error(
+                      `unhandled enum initialization expression ${exp} in ${file}`
+                    )
+                  }
+                  return enumData.defines[exp]
+                } else {
+                  throw new Error(
+                    `unhandled BinaryExpression operand type ${node.type} in ${file}`
+                  )
+                }
+              }
+              const exp = `${resolveValue(init.left)}${
+                init.operator
+              }${resolveValue(init.right)}`
               value = evaluate(exp)
             }