mirror of
https://github.com/github/codeql.git
synced 2026-04-25 16:55:19 +02:00
JS: Fix value of numeric literals containing underscores
This commit is contained in:
@@ -482,6 +482,7 @@ public class ESNextParser extends JSXParser {
|
||||
|
||||
if (code == '_') {
|
||||
if (underscoreAllowed) {
|
||||
seenUnderscoreNumericSeparator = true;
|
||||
// no adjacent underscores
|
||||
underscoreAllowed = false;
|
||||
++this.pos;
|
||||
|
||||
@@ -145,6 +145,11 @@ public class Parser {
|
||||
private Stack<LabelInfo> labels;
|
||||
protected int yieldPos, awaitPos;
|
||||
|
||||
/**
|
||||
* Set to true by {@link ESNextParser#readInt} if the parsed integer contains an underscore.
|
||||
*/
|
||||
protected boolean seenUnderscoreNumericSeparator = false;
|
||||
|
||||
/**
|
||||
* For readability purposes, we pass this instead of false as the argument to the
|
||||
* hasDeclareKeyword parameter (which only exists in TypeScript).
|
||||
@@ -654,7 +659,7 @@ public class Parser {
|
||||
case 58:
|
||||
++this.pos;
|
||||
return this.finishToken(TokenType.colon);
|
||||
case 35:
|
||||
case 35:
|
||||
++this.pos;
|
||||
return this.finishToken(TokenType.pound);
|
||||
case 63:
|
||||
@@ -847,6 +852,10 @@ public class Parser {
|
||||
}
|
||||
|
||||
String str = inputSubstring(start, this.pos);
|
||||
if (seenUnderscoreNumericSeparator) {
|
||||
str = str.replace("_", "");
|
||||
seenUnderscoreNumericSeparator = false;
|
||||
}
|
||||
Number val = null;
|
||||
if (isFloat) val = parseFloat(str);
|
||||
else if (!octal || str.length() == 1) val = parseInt(str, 10);
|
||||
|
||||
Reference in New Issue
Block a user