Skip to content

Commit bef4fe6

Browse files
committed
make sure the new identifiers have end-locations
1 parent b8187ed commit bef4fe6

File tree

3 files changed

+146
-2
lines changed

3 files changed

+146
-2
lines changed

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3555,7 +3555,7 @@ protected List<ExportSpecifier> parseExportSpecifiers(Set<String> exports) {
35553555
// e.g. `export { Foo_new as "Foo::new" }`
35563556
Expression string = this.parseExprAtom(null);
35573557
String str = ((Literal)string).getStringValue();
3558-
exported = new Identifier(loc, str);
3558+
exported = this.finishNode(new Identifier(loc, str));
35593559
} else {
35603560
exported = this.parseIdent(true);
35613561
}
@@ -3648,7 +3648,7 @@ protected ImportSpecifier parseImportSpecifier() {
36483648
// e.g. `import { "Foo::new" as Foo_new } from "./foo.wasm"`
36493649
Expression string = this.parseExprAtom(null);
36503650
String str = ((Literal)string).getStringValue();
3651-
imported = new Identifier(loc, str);
3651+
imported = this.finishNode(new Identifier(loc, str));
36523652
// only makes sense if there is a local identifier
36533653
if (!this.isContextual("as")) {
36543654
this.raiseRecoverable(this.start, "Unexpected string");
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
import { "foo" } from "foo"; // syntax-error, but it shouldn't crash the extractor
Lines changed: 143 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,143 @@
1+
#10000=@"/arbitaryModuleSpecifier.js;sourcefile"
2+
files(#10000,"/arbitaryModuleSpecifier.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+
comments(#20002,0,#20001," syntax-error, but it shouldn't crash the extractor","// synt ... tractor")
14+
#20003=@"loc,{#10000},1,30,1,82"
15+
locations_default(#20003,#10000,1,30,1,82)
16+
hasLocation(#20002,#20003)
17+
#20004=*
18+
lines(#20004,#20001,"import { ""foo"" } from ""foo""; // syntax-error, but it shouldn't crash the extractor","
19+
")
20+
#20005=@"loc,{#10000},1,1,1,82"
21+
locations_default(#20005,#10000,1,1,1,82)
22+
hasLocation(#20004,#20005)
23+
numlines(#20001,1,1,1)
24+
#20006=*
25+
tokeninfo(#20006,7,#20001,0,"import")
26+
#20007=@"loc,{#10000},1,1,1,6"
27+
locations_default(#20007,#10000,1,1,1,6)
28+
hasLocation(#20006,#20007)
29+
#20008=*
30+
tokeninfo(#20008,8,#20001,1,"{")
31+
#20009=@"loc,{#10000},1,8,1,8"
32+
locations_default(#20009,#10000,1,8,1,8)
33+
hasLocation(#20008,#20009)
34+
#20010=*
35+
tokeninfo(#20010,4,#20001,2,"""foo""")
36+
#20011=@"loc,{#10000},1,10,1,14"
37+
locations_default(#20011,#10000,1,10,1,14)
38+
hasLocation(#20010,#20011)
39+
#20012=*
40+
tokeninfo(#20012,8,#20001,3,"}")
41+
#20013=@"loc,{#10000},1,16,1,16"
42+
locations_default(#20013,#10000,1,16,1,16)
43+
hasLocation(#20012,#20013)
44+
#20014=*
45+
tokeninfo(#20014,6,#20001,4,"from")
46+
#20015=@"loc,{#10000},1,18,1,21"
47+
locations_default(#20015,#10000,1,18,1,21)
48+
hasLocation(#20014,#20015)
49+
#20016=*
50+
tokeninfo(#20016,4,#20001,5,"""foo""")
51+
#20017=@"loc,{#10000},1,23,1,27"
52+
locations_default(#20017,#10000,1,23,1,27)
53+
hasLocation(#20016,#20017)
54+
#20018=*
55+
tokeninfo(#20018,8,#20001,6,";")
56+
#20019=@"loc,{#10000},1,28,1,28"
57+
locations_default(#20019,#10000,1,28,1,28)
58+
hasLocation(#20018,#20019)
59+
#20020=*
60+
tokeninfo(#20020,0,#20001,7,"")
61+
#20021=@"loc,{#10000},2,1,2,0"
62+
locations_default(#20021,#10000,2,1,2,0)
63+
hasLocation(#20020,#20021)
64+
next_token(#20002,#20020)
65+
toplevels(#20001,0)
66+
#20022=@"loc,{#10000},1,1,2,0"
67+
locations_default(#20022,#10000,1,1,2,0)
68+
hasLocation(#20001,#20022)
69+
#20023=@"module;{#10000},1,1"
70+
scopes(#20023,3)
71+
scopenodes(#20001,#20023)
72+
scopenesting(#20023,#20000)
73+
is_module(#20001)
74+
is_es2015_module(#20001)
75+
#20024=@"var;{foo};{#20023}"
76+
variables(#20024,"foo",#20023)
77+
#20025=@"local_type_name;{foo};{#20023}"
78+
local_type_names(#20025,"foo",#20023)
79+
#20026=@"local_namespace_name;{foo};{#20023}"
80+
local_namespace_names(#20026,"foo",#20023)
81+
variables(#20024,"foo",#20023)
82+
local_type_names(#20025,"foo",#20023)
83+
local_namespace_names(#20026,"foo",#20023)
84+
#20027=*
85+
stmts(#20027,27,#20001,0,"import ... ""foo"";")
86+
#20028=@"loc,{#10000},1,1,1,28"
87+
locations_default(#20028,#10000,1,1,1,28)
88+
hasLocation(#20027,#20028)
89+
stmt_containers(#20027,#20001)
90+
#20029=*
91+
exprs(#20029,4,#20027,-1,"""foo""")
92+
hasLocation(#20029,#20017)
93+
enclosing_stmt(#20029,#20027)
94+
expr_containers(#20029,#20001)
95+
literals("foo","""foo""",#20029)
96+
#20030=*
97+
regexpterm(#20030,14,#20029,0,"foo")
98+
#20031=@"loc,{#10000},1,24,1,26"
99+
locations_default(#20031,#10000,1,24,1,26)
100+
hasLocation(#20030,#20031)
101+
regexp_const_value(#20030,"foo")
102+
#20032=*
103+
exprs(#20032,83,#20027,0,"""foo""")
104+
hasLocation(#20032,#20011)
105+
enclosing_stmt(#20032,#20027)
106+
expr_containers(#20032,#20001)
107+
#20033=*
108+
exprs(#20033,0,#20032,0,"""foo""")
109+
hasLocation(#20033,#20011)
110+
enclosing_stmt(#20033,#20027)
111+
expr_containers(#20033,#20001)
112+
literals("foo","foo",#20033)
113+
#20034=*
114+
exprs(#20034,78,#20032,1,"""foo""")
115+
hasLocation(#20034,#20011)
116+
enclosing_stmt(#20034,#20027)
117+
expr_containers(#20034,#20001)
118+
literals("foo","foo",#20034)
119+
decl(#20034,#20024)
120+
typedecl(#20034,#20025)
121+
namespacedecl(#20034,#20026)
122+
#20035=*
123+
entry_cfg_node(#20035,#20001)
124+
#20036=@"loc,{#10000},1,1,1,0"
125+
locations_default(#20036,#10000,1,1,1,0)
126+
hasLocation(#20035,#20036)
127+
#20037=*
128+
exit_cfg_node(#20037,#20001)
129+
hasLocation(#20037,#20021)
130+
successor(#20027,#20037)
131+
successor(#20032,#20027)
132+
successor(#20035,#20032)
133+
#20038=*
134+
js_parse_errors(#20038,#20001,"Error: Unexpected string","import { ""foo"" } from ""foo""; // syntax-error, but it shouldn't crash the extractor
135+
")
136+
hasLocation(#20038,#20013)
137+
#20039=*
138+
lines(#20039,#20001,"import { ""foo"" } from ""foo""; // syntax-error, but it shouldn't crash the extractor","
139+
")
140+
hasLocation(#20039,#20005)
141+
numlines(#20001,1,0,0)
142+
numlines(#10000,1,1,1)
143+
filetype(#10000,"javascript")

0 commit comments

Comments
 (0)