Skip to content

Commit 0515b12

Browse files
committed
JS: Add example of bad NodeJS detection
Notice the TRAP lines ``` is_module(github#20001) is_es2015_module(github#20001) ```
1 parent 45ce988 commit 0515b12

File tree

2 files changed

+209
-0
lines changed

2 files changed

+209
-0
lines changed
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
// the comment below (with 'import' on line starting with whitespace) caused the
2+
// extractor to think it was a es2015 module and not a commonjs module.
3+
/*
4+
import
5+
*/
6+
const fs = require('fs');
Lines changed: 203 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,203 @@
1+
#10000=@"/detection.js;sourcefile"
2+
files(#10000,"/detection.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," the comment below (with 'import' on line starting with whitespace) caused the","// the ... sed the")
14+
#20003=@"loc,{#10000},1,1,1,80"
15+
locations_default(#20003,#10000,1,1,1,80)
16+
hasLocation(#20002,#20003)
17+
#20004=*
18+
comments(#20004,0,#20001," extractor to think it was a es2015 module and not a commonjs module.","// extr ... module.")
19+
#20005=@"loc,{#10000},2,1,2,71"
20+
locations_default(#20005,#10000,2,1,2,71)
21+
hasLocation(#20004,#20005)
22+
#20006=*
23+
comments(#20006,1,#20001,"
24+
import
25+
","/*\n import\n*/")
26+
#20007=@"loc,{#10000},3,1,5,2"
27+
locations_default(#20007,#10000,3,1,5,2)
28+
hasLocation(#20006,#20007)
29+
#20008=*
30+
lines(#20008,#20001,"// the comment below (with 'import' on line starting with whitespace) caused the","
31+
")
32+
hasLocation(#20008,#20003)
33+
#20009=*
34+
lines(#20009,#20001,"// extractor to think it was a es2015 module and not a commonjs module.","
35+
")
36+
hasLocation(#20009,#20005)
37+
#20010=*
38+
lines(#20010,#20001,"/*","
39+
")
40+
#20011=@"loc,{#10000},3,1,3,2"
41+
locations_default(#20011,#10000,3,1,3,2)
42+
hasLocation(#20010,#20011)
43+
#20012=*
44+
lines(#20012,#20001," import","
45+
")
46+
#20013=@"loc,{#10000},4,1,4,8"
47+
locations_default(#20013,#10000,4,1,4,8)
48+
hasLocation(#20012,#20013)
49+
indentation(#10000,4," ",2)
50+
#20014=*
51+
lines(#20014,#20001,"*/","
52+
")
53+
#20015=@"loc,{#10000},5,1,5,2"
54+
locations_default(#20015,#10000,5,1,5,2)
55+
hasLocation(#20014,#20015)
56+
#20016=*
57+
lines(#20016,#20001,"const fs = require('fs');","
58+
")
59+
#20017=@"loc,{#10000},6,1,6,25"
60+
locations_default(#20017,#10000,6,1,6,25)
61+
hasLocation(#20016,#20017)
62+
numlines(#20001,6,1,5)
63+
#20018=*
64+
tokeninfo(#20018,7,#20001,0,"const")
65+
#20019=@"loc,{#10000},6,1,6,5"
66+
locations_default(#20019,#10000,6,1,6,5)
67+
hasLocation(#20018,#20019)
68+
next_token(#20002,#20018)
69+
next_token(#20004,#20018)
70+
next_token(#20006,#20018)
71+
#20020=*
72+
tokeninfo(#20020,6,#20001,1,"fs")
73+
#20021=@"loc,{#10000},6,7,6,8"
74+
locations_default(#20021,#10000,6,7,6,8)
75+
hasLocation(#20020,#20021)
76+
#20022=*
77+
tokeninfo(#20022,8,#20001,2,"=")
78+
#20023=@"loc,{#10000},6,10,6,10"
79+
locations_default(#20023,#10000,6,10,6,10)
80+
hasLocation(#20022,#20023)
81+
#20024=*
82+
tokeninfo(#20024,6,#20001,3,"require")
83+
#20025=@"loc,{#10000},6,12,6,18"
84+
locations_default(#20025,#10000,6,12,6,18)
85+
hasLocation(#20024,#20025)
86+
#20026=*
87+
tokeninfo(#20026,8,#20001,4,"(")
88+
#20027=@"loc,{#10000},6,19,6,19"
89+
locations_default(#20027,#10000,6,19,6,19)
90+
hasLocation(#20026,#20027)
91+
#20028=*
92+
tokeninfo(#20028,4,#20001,5,"'fs'")
93+
#20029=@"loc,{#10000},6,20,6,23"
94+
locations_default(#20029,#10000,6,20,6,23)
95+
hasLocation(#20028,#20029)
96+
#20030=*
97+
tokeninfo(#20030,8,#20001,6,")")
98+
#20031=@"loc,{#10000},6,24,6,24"
99+
locations_default(#20031,#10000,6,24,6,24)
100+
hasLocation(#20030,#20031)
101+
#20032=*
102+
tokeninfo(#20032,8,#20001,7,";")
103+
#20033=@"loc,{#10000},6,25,6,25"
104+
locations_default(#20033,#10000,6,25,6,25)
105+
hasLocation(#20032,#20033)
106+
#20034=*
107+
tokeninfo(#20034,0,#20001,8,"")
108+
#20035=@"loc,{#10000},7,1,7,0"
109+
locations_default(#20035,#10000,7,1,7,0)
110+
hasLocation(#20034,#20035)
111+
toplevels(#20001,0)
112+
#20036=@"loc,{#10000},1,1,7,0"
113+
locations_default(#20036,#10000,1,1,7,0)
114+
hasLocation(#20001,#20036)
115+
#20037=@"var;{global};{#20000}"
116+
variables(#20037,"global",#20000)
117+
#20038=@"var;{process};{#20000}"
118+
variables(#20038,"process",#20000)
119+
#20039=@"var;{console};{#20000}"
120+
variables(#20039,"console",#20000)
121+
#20040=@"var;{Buffer};{#20000}"
122+
variables(#20040,"Buffer",#20000)
123+
#20041=@"module;{#10000},1,1"
124+
scopes(#20041,3)
125+
scopenodes(#20001,#20041)
126+
scopenesting(#20041,#20000)
127+
#20042=@"var;{require};{#20041}"
128+
variables(#20042,"require",#20041)
129+
#20043=@"var;{module};{#20041}"
130+
variables(#20043,"module",#20041)
131+
#20044=@"var;{exports};{#20041}"
132+
variables(#20044,"exports",#20041)
133+
#20045=@"var;{__filename};{#20041}"
134+
variables(#20045,"__filename",#20041)
135+
#20046=@"var;{__dirname};{#20041}"
136+
variables(#20046,"__dirname",#20041)
137+
#20047=@"var;{arguments};{#20041}"
138+
variables(#20047,"arguments",#20041)
139+
is_module(#20001)
140+
is_es2015_module(#20001)
141+
#20048=@"var;{fs};{#20041}"
142+
variables(#20048,"fs",#20041)
143+
#20049=*
144+
stmts(#20049,22,#20001,0,"const f ... ('fs');")
145+
hasLocation(#20049,#20017)
146+
stmt_containers(#20049,#20001)
147+
#20050=*
148+
exprs(#20050,64,#20049,0,"fs = require('fs')")
149+
#20051=@"loc,{#10000},6,7,6,24"
150+
locations_default(#20051,#10000,6,7,6,24)
151+
hasLocation(#20050,#20051)
152+
enclosing_stmt(#20050,#20049)
153+
expr_containers(#20050,#20001)
154+
#20052=*
155+
exprs(#20052,78,#20050,0,"fs")
156+
hasLocation(#20052,#20021)
157+
enclosing_stmt(#20052,#20049)
158+
expr_containers(#20052,#20001)
159+
literals("fs","fs",#20052)
160+
decl(#20052,#20048)
161+
#20053=*
162+
exprs(#20053,13,#20050,1,"require('fs')")
163+
#20054=@"loc,{#10000},6,12,6,24"
164+
locations_default(#20054,#10000,6,12,6,24)
165+
hasLocation(#20053,#20054)
166+
enclosing_stmt(#20053,#20049)
167+
expr_containers(#20053,#20001)
168+
#20055=*
169+
exprs(#20055,79,#20053,-1,"require")
170+
hasLocation(#20055,#20025)
171+
enclosing_stmt(#20055,#20049)
172+
expr_containers(#20055,#20001)
173+
literals("require","require",#20055)
174+
bind(#20055,#20042)
175+
#20056=*
176+
exprs(#20056,4,#20053,0,"'fs'")
177+
hasLocation(#20056,#20029)
178+
enclosing_stmt(#20056,#20049)
179+
expr_containers(#20056,#20001)
180+
literals("fs","'fs'",#20056)
181+
#20057=*
182+
regexpterm(#20057,14,#20056,0,"fs")
183+
#20058=@"loc,{#10000},6,21,6,22"
184+
locations_default(#20058,#10000,6,21,6,22)
185+
hasLocation(#20057,#20058)
186+
regexp_const_value(#20057,"fs")
187+
#20059=*
188+
entry_cfg_node(#20059,#20001)
189+
#20060=@"loc,{#10000},1,1,1,0"
190+
locations_default(#20060,#10000,1,1,1,0)
191+
hasLocation(#20059,#20060)
192+
#20061=*
193+
exit_cfg_node(#20061,#20001)
194+
hasLocation(#20061,#20035)
195+
successor(#20049,#20052)
196+
successor(#20056,#20053)
197+
successor(#20055,#20056)
198+
successor(#20053,#20050)
199+
successor(#20052,#20055)
200+
successor(#20050,#20061)
201+
successor(#20059,#20049)
202+
numlines(#10000,6,1,5)
203+
filetype(#10000,"javascript")

0 commit comments

Comments
 (0)