Skip to content

Commit b49b9ef

Browse files
committed
build: stricter conditions for UnaryExpression in const enum plugin
1 parent a871fd0 commit b49b9ef

File tree

1 file changed

+11
-3
lines changed

1 file changed

+11
-3
lines changed

scripts/const-enum.js

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -112,9 +112,17 @@ export async function constEnum() {
112112
}
113113

114114
if (init.type === 'UnaryExpression') {
115-
// @ts-ignore assume all operands are literals
116-
const exp = `${init.operator}${init.argument.value}`
117-
value = evaluate(exp)
115+
if (
116+
init.argument.type === 'StringLiteral' ||
117+
init.argument.type === 'NumericLiteral'
118+
) {
119+
const exp = `${init.operator}${init.argument.value}`
120+
value = evaluate(exp)
121+
} else {
122+
throw new Error(
123+
`unhandled UnaryExpression argument type ${init.argument.type} in ${file}`
124+
)
125+
}
118126
}
119127

120128
if (value === undefined) {

0 commit comments

Comments
 (0)