Skip to content

Commit 9a30686

Browse files
authored
Merge pull request #4282 from erik-krogh/es2021
Approved by esbena
2 parents 47506a8 + 4571ba3 commit 9a30686

File tree

28 files changed

+1167
-45
lines changed

28 files changed

+1167
-45
lines changed

change-notes/1.26/analysis-javascript.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
- [underscore](https://www.npmjs.com/package/underscore)
2121

2222
* Analyzing files with the ".cjs" extension is now supported.
23+
* ES2021 features are now supported.
2324

2425
## New queries
2526

javascript/extractor/src/com/semmle/jcorn/Parser.java

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -531,9 +531,14 @@ private Token readToken_question() { // '?'
531531
int next2 = charAt(this.pos + 2);
532532
if (this.options.esnext()) {
533533
if (next == '.' && !('0' <= next2 && next2 <= '9')) // '?.', but not '?.X' where X is a digit
534-
return this.finishOp(TokenType.questiondot, 2);
535-
if (next == '?') // '??'
536-
return this.finishOp(TokenType.questionquestion, 2);
534+
return this.finishOp(TokenType.questiondot, 2);
535+
if (next == '?') { // '??'
536+
if (next2 == '=') { // ??=
537+
return this.finishOp(TokenType.assign, 3);
538+
}
539+
return this.finishOp(TokenType.questionquestion, 2);
540+
}
541+
537542
}
538543
return this.finishOp(TokenType.question, 1);
539544
}
@@ -566,8 +571,11 @@ private Token readToken_mult_modulo_exp(int code) { // '%*'
566571

567572
private Token readToken_pipe_amp(int code) { // '|&'
568573
int next = charAt(this.pos + 1);
569-
if (next == code)
574+
int next2 = charAt(this.pos + 2);
575+
if (next == code) { // && ||
576+
if (next2 == 61) return this.finishOp(TokenType.assign, 3); // &&= ||=
570577
return this.finishOp(code == 124 ? TokenType.logicalOR : TokenType.logicalAND, 2);
578+
}
571579
if (next == 61) return this.finishOp(TokenType.assign, 2);
572580
return this.finishOp(code == 124 ? TokenType.bitwiseOR : TokenType.bitwiseAND, 1);
573581
}
@@ -709,8 +717,8 @@ protected Token getTokenFromCode(int code) {
709717
case 42: // '%*'
710718
return this.readToken_mult_modulo_exp(code);
711719

712-
case 124:
713-
case 38: // '|&'
720+
case 124: // '|'
721+
case 38: // '&'
714722
return this.readToken_pipe_amp(code);
715723

716724
case 94: // '^'

javascript/extractor/src/com/semmle/js/extractor/Main.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ public class Main {
4343
* A version identifier that should be updated every time the extractor changes in such a way that
4444
* it may produce different tuples for the same file under the same {@link ExtractorConfig}.
4545
*/
46-
public static final String EXTRACTOR_VERSION = "2020-09-12";
46+
public static final String EXTRACTOR_VERSION = "2020-09-17";
4747

4848
public static final Pattern NEWLINE = Pattern.compile("\n");
4949

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
var x = 1;
2+
var y = 2;
3+
var foo = x && y;
4+
var bar = x &&= y;
5+
console.log(x); // 2
6+
7+
x &&= y;
8+
x ||= y;
9+
x ??= y;
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
1_000_000_000 // Ah, so a billion
2+
101_475_938.38 // And this is hundreds of millions
3+
4+
let fee = 123_00; // $123 (12300 cents, apparently)
5+
let fee = 12_300; // $12,300 (woah, that fee!)
6+
let amount = 12345_00; // 12,345 (1234500 cents, apparently)
7+
let amount = 123_4500; // 123.45 (4-fixed financial)
8+
let amount = 1_234_500; // 1,234,500
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"experimental": true
3+
}

0 commit comments

Comments
 (0)