Skip to content

Commit 56ab013

Browse files
authored
Merge pull request #1340 from xiemaisi/js/es2019
Approved by asger-semmle
2 parents 6752782 + b62be04 commit 56ab013

File tree

8 files changed

+179
-5
lines changed

8 files changed

+179
-5
lines changed

change-notes/1.21/extractor-javascript.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,6 @@
44

55
## Changes to code extraction
66

7+
* ECMAScript 2019 support is now enabled by default.
8+
79
* YAML files are now extracted by default on LGTM. You can specify exclusion filters in your `lgtm.yml` file to override this behavior.

change-notes/support/versions-compilers.csv

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,6 @@ COBOL,ANSI 85 or newer [1]_.,Not applicable,"``.cbl``, ``.CBL``, ``.cpy``, ``.CP
1111
Java,"Java 6 to 11 [2]_.","javac (OpenJDK and Oracle JDK)
1212
1313
Eclipse compiler for Java (ECJ) batch compiler",``.java``
14-
JavaScript,ECMAScript 2018 or lower,Not applicable,"``.js``, ``.jsx``, ``.mjs``, ``.es``, ``.es6``, ``.htm``, ``.html``, ``.xhm``, ``.xhtml``, ``.vue``, ``.json`` [3]_."
14+
JavaScript,ECMAScript 2019 or lower,Not applicable,"``.js``, ``.jsx``, ``.mjs``, ``.es``, ``.es6``, ``.htm``, ``.html``, ``.xhm``, ``.xhtml``, ``.vue``, ``.json``, ``.yaml``, ``.yml``, ``.raml`` [3]_."
1515
Python,"2.7, 3.5, 3.6, 3.7",Not applicable,``.py``
1616
TypeScript [4]_.,"2.6-3.4",Standard TypeScript compiler,"``.ts``, ``.tsx``"

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -385,7 +385,7 @@ protected CatchClause parseCatchClause(Position startLoc) {
385385
param = this.parseBindingAtom();
386386
this.checkLVal(param, true, null);
387387
this.expect(TokenType.parenR);
388-
} else if (!options.esnext()) {
388+
} else if (options.ecmaVersion() < 10) {
389389
this.unexpected();
390390
}
391391
BlockStatement catchBody = this.parseBlock(false);

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ public void call(
5151
private Function<SyntaxError, ?> onRecoverableError;
5252

5353
public Options() {
54-
this.ecmaVersion = 7;
54+
this.ecmaVersion = 10;
5555
this.sourceType = "script";
5656
this.onInsertedSemicolon = null;
5757
this.onTrailingComma = null;

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -890,6 +890,9 @@ protected Token readString(char quote) {
890890
out.append(inputSubstring(chunkStart, this.pos));
891891
out.append(this.readEscapedChar(false));
892892
chunkStart = this.pos;
893+
} else if (options.ecmaVersion() >= 10 && (ch == 0x2028 || ch == 0x2029)) {
894+
// ECMAScript 2019 allows Unicode newlines in string literals
895+
++this.pos;
893896
} else {
894897
if (Whitespace.isNewLine(ch)) this.raise(this.start, "Unterminated string constant");
895898
++this.pos;

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,8 @@ public static enum ECMAVersion {
3434
ECMA2016(2016, 7),
3535
ECMA2017(2017, 8),
3636
ECMA2018(2018, 9),
37-
ECMA2019(2019, 10);
37+
ECMA2019(2019, 10),
38+
ECMA2020(2020, 11);
3839

3940
private final int version;
4041
public final int legacyVersion;
@@ -236,7 +237,7 @@ public String toString() {
236237
private String defaultEncoding;
237238

238239
public ExtractorConfig(boolean experimental) {
239-
this.ecmaVersion = experimental ? ECMAVersion.ECMA2019 : ECMAVersion.ECMA2018;
240+
this.ecmaVersion = experimental ? ECMAVersion.ECMA2020 : ECMAVersion.ECMA2019;
240241
this.platform = Platform.AUTO;
241242
this.jsx = true;
242243
this.sourceType = SourceType.AUTO;
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
var s1 = "ab
c";
2+
var s2 = "ab
c";
Lines changed: 166 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,166 @@
1+
#10000=@"/json-superset.js;sourcefile"
2+
files(#10000,"/json-superset.js","json-superset","js",0)
3+
#10001=@"/;folder"
4+
folders(#10001,"/","")
5+
containerparent(#10001,#10000)
6+
#10002=@"loc,{#10000},0,0,0,0"
7+
locations_default(#10002,#10000,0,0,0,0)
8+
hasLocation(#10000,#10002)
9+
#20000=@"global_scope"
10+
scopes(#20000,0)
11+
#20001=@"script;{#10000},1,1"
12+
#20002=*
13+
lines(#20002,#20001,"var s1 = ""ab","
")
14+
#20003=@"loc,{#10000},1,1,1,12"
15+
locations_default(#20003,#10000,1,1,1,12)
16+
hasLocation(#20002,#20003)
17+
#20004=*
18+
lines(#20004,#20001,"c"";","
19+
")
20+
#20005=@"loc,{#10000},2,1,2,3"
21+
locations_default(#20005,#10000,2,1,2,3)
22+
hasLocation(#20004,#20005)
23+
#20006=*
24+
lines(#20006,#20001,"var s2 = ""ab","
")
25+
#20007=@"loc,{#10000},3,1,3,12"
26+
locations_default(#20007,#10000,3,1,3,12)
27+
hasLocation(#20006,#20007)
28+
#20008=*
29+
lines(#20008,#20001,"c"";","
30+
")
31+
#20009=@"loc,{#10000},4,1,4,3"
32+
locations_default(#20009,#10000,4,1,4,3)
33+
hasLocation(#20008,#20009)
34+
numlines(#20001,4,2,0)
35+
#20010=*
36+
tokeninfo(#20010,7,#20001,0,"var")
37+
#20011=@"loc,{#10000},1,1,1,3"
38+
locations_default(#20011,#10000,1,1,1,3)
39+
hasLocation(#20010,#20011)
40+
#20012=*
41+
tokeninfo(#20012,6,#20001,1,"s1")
42+
#20013=@"loc,{#10000},1,5,1,6"
43+
locations_default(#20013,#10000,1,5,1,6)
44+
hasLocation(#20012,#20013)
45+
#20014=*
46+
tokeninfo(#20014,8,#20001,2,"=")
47+
#20015=@"loc,{#10000},1,8,1,8"
48+
locations_default(#20015,#10000,1,8,1,8)
49+
hasLocation(#20014,#20015)
50+
#20016=*
51+
tokeninfo(#20016,4,#20001,3,"""ab
c""")
52+
#20017=@"loc,{#10000},1,10,1,15"
53+
locations_default(#20017,#10000,1,10,1,15)
54+
hasLocation(#20016,#20017)
55+
#20018=*
56+
tokeninfo(#20018,8,#20001,4,";")
57+
#20019=@"loc,{#10000},1,16,1,16"
58+
locations_default(#20019,#10000,1,16,1,16)
59+
hasLocation(#20018,#20019)
60+
#20020=*
61+
tokeninfo(#20020,7,#20001,5,"var")
62+
hasLocation(#20020,#20005)
63+
#20021=*
64+
tokeninfo(#20021,6,#20001,6,"s2")
65+
#20022=@"loc,{#10000},2,5,2,6"
66+
locations_default(#20022,#10000,2,5,2,6)
67+
hasLocation(#20021,#20022)
68+
#20023=*
69+
tokeninfo(#20023,8,#20001,7,"=")
70+
#20024=@"loc,{#10000},2,8,2,8"
71+
locations_default(#20024,#10000,2,8,2,8)
72+
hasLocation(#20023,#20024)
73+
#20025=*
74+
tokeninfo(#20025,4,#20001,8,"""ab
c""")
75+
#20026=@"loc,{#10000},2,10,2,15"
76+
locations_default(#20026,#10000,2,10,2,15)
77+
hasLocation(#20025,#20026)
78+
#20027=*
79+
tokeninfo(#20027,8,#20001,9,";")
80+
#20028=@"loc,{#10000},2,16,2,16"
81+
locations_default(#20028,#10000,2,16,2,16)
82+
hasLocation(#20027,#20028)
83+
#20029=*
84+
tokeninfo(#20029,0,#20001,10,"")
85+
#20030=@"loc,{#10000},3,1,3,0"
86+
locations_default(#20030,#10000,3,1,3,0)
87+
hasLocation(#20029,#20030)
88+
toplevels(#20001,0)
89+
#20031=@"loc,{#10000},1,1,3,0"
90+
locations_default(#20031,#10000,1,1,3,0)
91+
hasLocation(#20001,#20031)
92+
#20032=@"var;{s1};{#20000}"
93+
variables(#20032,"s1",#20000)
94+
#20033=@"var;{s2};{#20000}"
95+
variables(#20033,"s2",#20000)
96+
#20034=*
97+
stmts(#20034,18,#20001,0,"var s1 = ""ab\u2028c"";")
98+
#20035=@"loc,{#10000},1,1,1,16"
99+
locations_default(#20035,#10000,1,1,1,16)
100+
hasLocation(#20034,#20035)
101+
stmtContainers(#20034,#20001)
102+
#20036=*
103+
exprs(#20036,64,#20034,0,"s1 = ""ab\u2028c""")
104+
#20037=@"loc,{#10000},1,5,1,15"
105+
locations_default(#20037,#10000,1,5,1,15)
106+
hasLocation(#20036,#20037)
107+
enclosingStmt(#20036,#20034)
108+
exprContainers(#20036,#20001)
109+
#20038=*
110+
exprs(#20038,78,#20036,0,"s1")
111+
hasLocation(#20038,#20013)
112+
enclosingStmt(#20038,#20034)
113+
exprContainers(#20038,#20001)
114+
literals("s1","s1",#20038)
115+
decl(#20038,#20032)
116+
#20039=*
117+
exprs(#20039,4,#20036,1,"""ab\u2028c""")
118+
hasLocation(#20039,#20017)
119+
enclosingStmt(#20039,#20034)
120+
exprContainers(#20039,#20001)
121+
literals("ab
c","""ab
c""",#20039)
122+
#20040=*
123+
stmts(#20040,18,#20001,1,"var s2 = ""ab\u2029c"";")
124+
#20041=@"loc,{#10000},2,1,2,16"
125+
locations_default(#20041,#10000,2,1,2,16)
126+
hasLocation(#20040,#20041)
127+
stmtContainers(#20040,#20001)
128+
#20042=*
129+
exprs(#20042,64,#20040,0,"s2 = ""ab\u2029c""")
130+
#20043=@"loc,{#10000},2,5,2,15"
131+
locations_default(#20043,#10000,2,5,2,15)
132+
hasLocation(#20042,#20043)
133+
enclosingStmt(#20042,#20040)
134+
exprContainers(#20042,#20001)
135+
#20044=*
136+
exprs(#20044,78,#20042,0,"s2")
137+
hasLocation(#20044,#20022)
138+
enclosingStmt(#20044,#20040)
139+
exprContainers(#20044,#20001)
140+
literals("s2","s2",#20044)
141+
decl(#20044,#20033)
142+
#20045=*
143+
exprs(#20045,4,#20042,1,"""ab\u2029c""")
144+
hasLocation(#20045,#20026)
145+
enclosingStmt(#20045,#20040)
146+
exprContainers(#20045,#20001)
147+
literals("ab
c","""ab
c""",#20045)
148+
#20046=*
149+
entry_cfg_node(#20046,#20001)
150+
#20047=@"loc,{#10000},1,1,1,0"
151+
locations_default(#20047,#10000,1,1,1,0)
152+
hasLocation(#20046,#20047)
153+
#20048=*
154+
exit_cfg_node(#20048,#20001)
155+
hasLocation(#20048,#20030)
156+
successor(#20040,#20044)
157+
successor(#20045,#20042)
158+
successor(#20044,#20045)
159+
successor(#20042,#20048)
160+
successor(#20034,#20038)
161+
successor(#20039,#20036)
162+
successor(#20038,#20039)
163+
successor(#20036,#20040)
164+
successor(#20046,#20034)
165+
numlines(#10000,4,2,0)
166+
filetype(#10000,"javascript")

0 commit comments

Comments
 (0)