Skip to content

Commit 82781b5

Browse files
authored
Merge pull request #22309 from MathiasVP/js-add-support-for-d-flag
JS: Add support for ES2022's `\d` flag
2 parents 91eb992 + 224ab74 commit 82781b5

5 files changed

Lines changed: 238 additions & 1 deletion

File tree

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -790,7 +790,8 @@ private Token readRegexp() {
790790
String validFlags = "gim";
791791
if (this.options.ecmaVersion() >= 6) validFlags = "gimuy";
792792
if (this.options.ecmaVersion() >= 9) validFlags = "gimsuy";
793-
if (this.options.ecmaVersion() >= 15) validFlags = "gimsuyv";
793+
if (this.options.ecmaVersion() >= 13) validFlags = "dgimsuy";
794+
if (this.options.ecmaVersion() >= 15) validFlags = "dgimsuyv";
794795
if (!mods.matches("^[" + validFlags + "]*$"))
795796
this.raise(start, "Invalid regular expression flag");
796797
if (mods.indexOf('u') >= 0) {
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
const pattern = /import/dg;
2+
3+
function target() {
4+
return pattern;
5+
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"experimental": true
3+
}
Lines changed: 224 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,224 @@
1+
#10000=@"/d-flag.js;sourcefile"
2+
files(#10000,"/d-flag.js")
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,"const pattern = /import/dg;","
14+
")
15+
#20003=@"loc,{#10000},1,1,1,27"
16+
locations_default(#20003,#10000,1,1,1,27)
17+
hasLocation(#20002,#20003)
18+
#20004=*
19+
lines(#20004,#20001,"","
20+
")
21+
#20005=@"loc,{#10000},2,1,2,0"
22+
locations_default(#20005,#10000,2,1,2,0)
23+
hasLocation(#20004,#20005)
24+
#20006=*
25+
lines(#20006,#20001,"function target() {","
26+
")
27+
#20007=@"loc,{#10000},3,1,3,19"
28+
locations_default(#20007,#10000,3,1,3,19)
29+
hasLocation(#20006,#20007)
30+
#20008=*
31+
lines(#20008,#20001," return pattern;","
32+
")
33+
#20009=@"loc,{#10000},4,1,4,17"
34+
locations_default(#20009,#10000,4,1,4,17)
35+
hasLocation(#20008,#20009)
36+
indentation(#10000,4," ",2)
37+
#20010=*
38+
lines(#20010,#20001,"}","")
39+
#20011=@"loc,{#10000},5,1,5,1"
40+
locations_default(#20011,#10000,5,1,5,1)
41+
hasLocation(#20010,#20011)
42+
numlines(#20001,5,4,0)
43+
#20012=*
44+
tokeninfo(#20012,7,#20001,0,"const")
45+
#20013=@"loc,{#10000},1,1,1,5"
46+
locations_default(#20013,#10000,1,1,1,5)
47+
hasLocation(#20012,#20013)
48+
#20014=*
49+
tokeninfo(#20014,6,#20001,1,"pattern")
50+
#20015=@"loc,{#10000},1,7,1,13"
51+
locations_default(#20015,#10000,1,7,1,13)
52+
hasLocation(#20014,#20015)
53+
#20016=*
54+
tokeninfo(#20016,8,#20001,2,"=")
55+
#20017=@"loc,{#10000},1,15,1,15"
56+
locations_default(#20017,#10000,1,15,1,15)
57+
hasLocation(#20016,#20017)
58+
#20018=*
59+
tokeninfo(#20018,5,#20001,3,"/import/dg")
60+
#20019=@"loc,{#10000},1,17,1,26"
61+
locations_default(#20019,#10000,1,17,1,26)
62+
hasLocation(#20018,#20019)
63+
#20020=*
64+
tokeninfo(#20020,8,#20001,4,";")
65+
#20021=@"loc,{#10000},1,27,1,27"
66+
locations_default(#20021,#10000,1,27,1,27)
67+
hasLocation(#20020,#20021)
68+
#20022=*
69+
tokeninfo(#20022,7,#20001,5,"function")
70+
#20023=@"loc,{#10000},3,1,3,8"
71+
locations_default(#20023,#10000,3,1,3,8)
72+
hasLocation(#20022,#20023)
73+
#20024=*
74+
tokeninfo(#20024,6,#20001,6,"target")
75+
#20025=@"loc,{#10000},3,10,3,15"
76+
locations_default(#20025,#10000,3,10,3,15)
77+
hasLocation(#20024,#20025)
78+
#20026=*
79+
tokeninfo(#20026,8,#20001,7,"(")
80+
#20027=@"loc,{#10000},3,16,3,16"
81+
locations_default(#20027,#10000,3,16,3,16)
82+
hasLocation(#20026,#20027)
83+
#20028=*
84+
tokeninfo(#20028,8,#20001,8,")")
85+
#20029=@"loc,{#10000},3,17,3,17"
86+
locations_default(#20029,#10000,3,17,3,17)
87+
hasLocation(#20028,#20029)
88+
#20030=*
89+
tokeninfo(#20030,8,#20001,9,"{")
90+
#20031=@"loc,{#10000},3,19,3,19"
91+
locations_default(#20031,#10000,3,19,3,19)
92+
hasLocation(#20030,#20031)
93+
#20032=*
94+
tokeninfo(#20032,7,#20001,10,"return")
95+
#20033=@"loc,{#10000},4,3,4,8"
96+
locations_default(#20033,#10000,4,3,4,8)
97+
hasLocation(#20032,#20033)
98+
#20034=*
99+
tokeninfo(#20034,6,#20001,11,"pattern")
100+
#20035=@"loc,{#10000},4,10,4,16"
101+
locations_default(#20035,#10000,4,10,4,16)
102+
hasLocation(#20034,#20035)
103+
#20036=*
104+
tokeninfo(#20036,8,#20001,12,";")
105+
#20037=@"loc,{#10000},4,17,4,17"
106+
locations_default(#20037,#10000,4,17,4,17)
107+
hasLocation(#20036,#20037)
108+
#20038=*
109+
tokeninfo(#20038,8,#20001,13,"}")
110+
hasLocation(#20038,#20011)
111+
#20039=*
112+
tokeninfo(#20039,0,#20001,14,"")
113+
#20040=@"loc,{#10000},5,2,5,1"
114+
locations_default(#20040,#10000,5,2,5,1)
115+
hasLocation(#20039,#20040)
116+
toplevels(#20001,0)
117+
#20041=@"loc,{#10000},1,1,5,1"
118+
locations_default(#20041,#10000,1,1,5,1)
119+
hasLocation(#20001,#20041)
120+
#20042=@"var;{target};{#20000}"
121+
variables(#20042,"target",#20000)
122+
#20043=@"var;{pattern};{#20000}"
123+
variables(#20043,"pattern",#20000)
124+
#20044=@"var;{this};{#20000}"
125+
variables(#20044,"this",#20000)
126+
#20045=*
127+
stmts(#20045,22,#20001,0,"const p ... ort/dg;")
128+
hasLocation(#20045,#20003)
129+
stmt_containers(#20045,#20001)
130+
#20046=*
131+
exprs(#20046,64,#20045,0,"pattern = /import/dg")
132+
#20047=@"loc,{#10000},1,7,1,26"
133+
locations_default(#20047,#10000,1,7,1,26)
134+
hasLocation(#20046,#20047)
135+
enclosing_stmt(#20046,#20045)
136+
expr_containers(#20046,#20001)
137+
#20048=*
138+
exprs(#20048,78,#20046,0,"pattern")
139+
hasLocation(#20048,#20015)
140+
enclosing_stmt(#20048,#20045)
141+
expr_containers(#20048,#20001)
142+
literals("pattern","pattern",#20048)
143+
decl(#20048,#20043)
144+
#20049=*
145+
exprs(#20049,5,#20046,1,"/import/dg")
146+
hasLocation(#20049,#20019)
147+
enclosing_stmt(#20049,#20045)
148+
expr_containers(#20049,#20001)
149+
literals("/import/dg","/import/dg",#20049)
150+
#20050=*
151+
regexpterm(#20050,14,#20049,0,"import")
152+
#20051=@"loc,{#10000},1,18,1,23"
153+
locations_default(#20051,#10000,1,18,1,23)
154+
hasLocation(#20050,#20051)
155+
regexp_const_value(#20050,"import")
156+
#20052=*
157+
stmts(#20052,17,#20001,1,"functio ... tern;\n}")
158+
#20053=@"loc,{#10000},3,1,5,1"
159+
locations_default(#20053,#10000,3,1,5,1)
160+
hasLocation(#20052,#20053)
161+
stmt_containers(#20052,#20001)
162+
#20054=*
163+
exprs(#20054,78,#20052,-1,"target")
164+
hasLocation(#20054,#20025)
165+
expr_containers(#20054,#20052)
166+
literals("target","target",#20054)
167+
decl(#20054,#20042)
168+
#20055=*
169+
scopes(#20055,1)
170+
scopenodes(#20052,#20055)
171+
scopenesting(#20055,#20000)
172+
#20056=@"var;{this};{#20055}"
173+
variables(#20056,"this",#20055)
174+
#20057=@"var;{arguments};{#20055}"
175+
variables(#20057,"arguments",#20055)
176+
is_arguments_object(#20057)
177+
#20058=*
178+
stmts(#20058,1,#20052,-2,"{\n ret ... tern;\n}")
179+
#20059=@"loc,{#10000},3,19,5,1"
180+
locations_default(#20059,#10000,3,19,5,1)
181+
hasLocation(#20058,#20059)
182+
stmt_containers(#20058,#20052)
183+
#20060=*
184+
stmts(#20060,9,#20058,0,"return pattern;")
185+
#20061=@"loc,{#10000},4,3,4,17"
186+
locations_default(#20061,#10000,4,3,4,17)
187+
hasLocation(#20060,#20061)
188+
stmt_containers(#20060,#20052)
189+
#20062=*
190+
exprs(#20062,79,#20060,0,"pattern")
191+
hasLocation(#20062,#20035)
192+
enclosing_stmt(#20062,#20060)
193+
expr_containers(#20062,#20052)
194+
literals("pattern","pattern",#20062)
195+
bind(#20062,#20043)
196+
#20063=*
197+
entry_cfg_node(#20063,#20001)
198+
#20064=@"loc,{#10000},1,1,1,0"
199+
locations_default(#20064,#10000,1,1,1,0)
200+
hasLocation(#20063,#20064)
201+
#20065=*
202+
exit_cfg_node(#20065,#20001)
203+
hasLocation(#20065,#20040)
204+
successor(#20052,#20065)
205+
#20066=*
206+
entry_cfg_node(#20066,#20052)
207+
#20067=@"loc,{#10000},3,1,3,0"
208+
locations_default(#20067,#10000,3,1,3,0)
209+
hasLocation(#20066,#20067)
210+
#20068=*
211+
exit_cfg_node(#20068,#20052)
212+
hasLocation(#20068,#20040)
213+
successor(#20062,#20060)
214+
successor(#20060,#20068)
215+
successor(#20058,#20062)
216+
successor(#20066,#20058)
217+
successor(#20045,#20048)
218+
successor(#20049,#20046)
219+
successor(#20048,#20049)
220+
successor(#20046,#20052)
221+
successor(#20054,#20045)
222+
successor(#20063,#20054)
223+
numlines(#10000,5,4,0)
224+
filetype(#10000,"javascript")
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
---
2+
category: minorAnalysis
3+
---
4+
* Added support for regular expressions using the `d` flag.

0 commit comments

Comments
 (0)