File tree Expand file tree Collapse file tree 1 file changed +23
-2
lines changed Expand file tree Collapse file tree 1 file changed +23
-2
lines changed Original file line number Diff line number Diff line change @@ -85,8 +85,29 @@ export async function constEnum() {
85
85
86
86
// e.g. 1 << 2
87
87
if ( init . type === 'BinaryExpression' ) {
88
- // @ts -ignore assume all operands are literals
89
- const exp = `${ init . left . value } ${ init . operator } ${ init . right . value } `
88
+ const resolveValue = node => {
89
+ if (
90
+ node . type === 'NumericLiteral' ||
91
+ node . type === 'StringLiteral'
92
+ ) {
93
+ return node . value
94
+ } else if ( node . type === 'MemberExpression' ) {
95
+ const exp = content . slice ( node . start , node . end )
96
+ if ( ! ( exp in enumData . defines ) ) {
97
+ throw new Error (
98
+ `unhandled enum initialization expression ${ exp } in ${ file } `
99
+ )
100
+ }
101
+ return enumData . defines [ exp ]
102
+ } else {
103
+ throw new Error (
104
+ `unhandled BinaryExpression operand type ${ node . type } in ${ file } `
105
+ )
106
+ }
107
+ }
108
+ const exp = `${ resolveValue ( init . left ) } ${
109
+ init . operator
110
+ } ${ resolveValue ( init . right ) } `
90
111
value = evaluate ( exp )
91
112
}
92
113
You can’t perform that action at this time.
0 commit comments