Skip to content

Commit

Permalink
Allow negative enum ids even if super inefficient (encodes as 10 byte…
Browse files Browse the repository at this point in the history
…s), fixes #499, fixes #500 [ci skip]
  • Loading branch information
dcodeIO committed Nov 29, 2016
1 parent 6376983 commit 4012a00
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions src/parse.js
Original file line number Diff line number Diff line change
Expand Up @@ -150,18 +150,20 @@ function parse(source, root) {
throw illegal(token, 'number');
}

function parseId(token) {
function parseId(token, acceptNegative) {
var tokenLower = lower(token);
switch (tokenLower) {
case "min": return 1;
case "max": return 0x1FFFFFFF;
case "0": return 0;
}
if (/^[1-9][0-9]*$/.test(token))
if (token.charAt(0) === '-' && !acceptNegative)
throw illegal(token, "id");
if (/^\-?[1-9][0-9]*$/.test(token))
return parseInt(token, 10);
if (/^0[x][0-9a-f]+$/.test(tokenLower))
if (/^\-?0[x][0-9a-f]+$/.test(tokenLower))
return parseInt(token, 16);
if (/^0[0-7]+$/.test(token))
if (/^\-?0[0-7]+$/.test(token))
return parseInt(token, 8);
throw illegal(token, "id");
}
Expand Down Expand Up @@ -357,7 +359,7 @@ function parse(source, root) {
throw illegal(token, s_name);
var name = token;
skip("=");
var value = parseId(next());
var value = parseId(next(), true);
parseInlineOptions(parent.values[name] = new Number(value)); // eslint-disable-line no-new-wrappers
}

Expand Down

0 comments on commit 4012a00

Please sign in to comment.