Skip to content

Commit 4012a00

Browse files
committed
Allow negative enum ids even if super inefficient (encodes as 10 bytes), fixes #499, fixes #500 [ci skip]
1 parent 6376983 commit 4012a00

File tree

1 file changed

+7
-5
lines changed

1 file changed

+7
-5
lines changed

src/parse.js

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -150,18 +150,20 @@ function parse(source, root) {
150150
throw illegal(token, 'number');
151151
}
152152

153-
function parseId(token) {
153+
function parseId(token, acceptNegative) {
154154
var tokenLower = lower(token);
155155
switch (tokenLower) {
156156
case "min": return 1;
157157
case "max": return 0x1FFFFFFF;
158158
case "0": return 0;
159159
}
160-
if (/^[1-9][0-9]*$/.test(token))
160+
if (token.charAt(0) === '-' && !acceptNegative)
161+
throw illegal(token, "id");
162+
if (/^\-?[1-9][0-9]*$/.test(token))
161163
return parseInt(token, 10);
162-
if (/^0[x][0-9a-f]+$/.test(tokenLower))
164+
if (/^\-?0[x][0-9a-f]+$/.test(tokenLower))
163165
return parseInt(token, 16);
164-
if (/^0[0-7]+$/.test(token))
166+
if (/^\-?0[0-7]+$/.test(token))
165167
return parseInt(token, 8);
166168
throw illegal(token, "id");
167169
}
@@ -357,7 +359,7 @@ function parse(source, root) {
357359
throw illegal(token, s_name);
358360
var name = token;
359361
skip("=");
360-
var value = parseId(next());
362+
var value = parseId(next(), true);
361363
parseInlineOptions(parent.values[name] = new Number(value)); // eslint-disable-line no-new-wrappers
362364
}
363365

0 commit comments

Comments
 (0)