Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 5a89024

Browse files
author
Max Schaefer
committed
JavaScript: Be more lenient about keywords used as identifiers.
1 parent dbbb961 commit 5a89024

3 files changed

Lines changed: 109 additions & 6 deletions

File tree

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

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2106,8 +2106,10 @@ protected Identifier parseIdent(boolean liberal) {
21062106
if (this.inAsync && this.value.equals("await"))
21072107
this.raiseRecoverable(this.start, "Can not use 'await' as identifier inside an async function");
21082108
name = String.valueOf(this.value);
2109-
} else if (liberal && this.type.keyword != null) {
2109+
} else if (this.type.keyword != null) {
21102110
name = this.type.keyword;
2111+
if (!liberal)
2112+
raiseRecoverable(this.start, "Cannot use keyword '" + name + "' as an identifier.");
21112113
} else {
21122114
this.unexpected();
21132115
}
@@ -2264,9 +2266,6 @@ protected Expression parseBindingAtom() {
22642266
if (this.options.ecmaVersion() < 6)
22652267
return this.parseIdent(false);
22662268

2267-
if (this.type == TokenType.name)
2268-
return this.parseIdent(false);
2269-
22702269
if (this.type == TokenType.bracketL) {
22712270
Position start = this.startLoc;
22722271
this.next();
@@ -2278,8 +2277,7 @@ protected Expression parseBindingAtom() {
22782277
if (this.type == TokenType.braceL)
22792278
return this.parseObj(true, null);
22802279

2281-
this.unexpected();
2282-
return null;
2280+
return this.parseIdent(false);
22832281
}
22842282

22852283
protected List<Expression> parseBindingList(TokenType close, boolean allowEmpty, boolean allowTrailingComma, boolean allowNonIdent) {
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
var class = 23;
Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
#10000=@"/kwident.js;sourcefile"
2+
files(#10000,"/kwident.js","kwident","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 class = 23;","
14+
")
15+
#20003=@"loc,{#10000},1,1,1,15"
16+
locations_default(#20003,#10000,1,1,1,15)
17+
hasLocation(#20002,#20003)
18+
numlines(#20001,1,1,0)
19+
#20004=*
20+
tokeninfo(#20004,7,#20001,0,"var")
21+
#20005=@"loc,{#10000},1,1,1,3"
22+
locations_default(#20005,#10000,1,1,1,3)
23+
hasLocation(#20004,#20005)
24+
#20006=*
25+
tokeninfo(#20006,7,#20001,1,"class")
26+
#20007=@"loc,{#10000},1,5,1,9"
27+
locations_default(#20007,#10000,1,5,1,9)
28+
hasLocation(#20006,#20007)
29+
#20008=*
30+
tokeninfo(#20008,8,#20001,2,"=")
31+
#20009=@"loc,{#10000},1,11,1,11"
32+
locations_default(#20009,#10000,1,11,1,11)
33+
hasLocation(#20008,#20009)
34+
#20010=*
35+
tokeninfo(#20010,3,#20001,3,"23")
36+
#20011=@"loc,{#10000},1,13,1,14"
37+
locations_default(#20011,#10000,1,13,1,14)
38+
hasLocation(#20010,#20011)
39+
#20012=*
40+
tokeninfo(#20012,8,#20001,4,";")
41+
#20013=@"loc,{#10000},1,15,1,15"
42+
locations_default(#20013,#10000,1,15,1,15)
43+
hasLocation(#20012,#20013)
44+
#20014=*
45+
tokeninfo(#20014,0,#20001,5,"")
46+
#20015=@"loc,{#10000},2,1,2,0"
47+
locations_default(#20015,#10000,2,1,2,0)
48+
hasLocation(#20014,#20015)
49+
toplevels(#20001,0)
50+
#20016=@"loc,{#10000},1,1,2,0"
51+
locations_default(#20016,#10000,1,1,2,0)
52+
hasLocation(#20001,#20016)
53+
#20017=@"var;{class};{#20000}"
54+
variables(#20017,"class",#20000)
55+
#20018=*
56+
stmts(#20018,18,#20001,0,"var class = 23;")
57+
hasLocation(#20018,#20003)
58+
stmtContainers(#20018,#20001)
59+
#20019=*
60+
exprs(#20019,64,#20018,0,"class = 23")
61+
#20020=@"loc,{#10000},1,5,1,14"
62+
locations_default(#20020,#10000,1,5,1,14)
63+
hasLocation(#20019,#20020)
64+
enclosingStmt(#20019,#20018)
65+
exprContainers(#20019,#20001)
66+
#20021=*
67+
exprs(#20021,78,#20019,0,"class")
68+
hasLocation(#20021,#20007)
69+
enclosingStmt(#20021,#20018)
70+
exprContainers(#20021,#20001)
71+
literals("class","class",#20021)
72+
decl(#20021,#20017)
73+
#20022=*
74+
exprs(#20022,3,#20019,1,"23")
75+
hasLocation(#20022,#20011)
76+
enclosingStmt(#20022,#20018)
77+
exprContainers(#20022,#20001)
78+
literals("23","23",#20022)
79+
#20023=*
80+
entry_cfg_node(#20023,#20001)
81+
#20024=@"loc,{#10000},1,1,1,0"
82+
locations_default(#20024,#10000,1,1,1,0)
83+
hasLocation(#20023,#20024)
84+
#20025=*
85+
exit_cfg_node(#20025,#20001)
86+
hasLocation(#20025,#20015)
87+
successor(#20018,#20021)
88+
successor(#20022,#20019)
89+
successor(#20021,#20022)
90+
successor(#20019,#20025)
91+
successor(#20023,#20018)
92+
#20026=*
93+
jsParseErrors(#20026,#20001,"Error: Cannot use keyword 'class' as an identifier.","var class = 23;
94+
")
95+
#20027=@"loc,{#10000},1,5,1,5"
96+
locations_default(#20027,#10000,1,5,1,5)
97+
hasLocation(#20026,#20027)
98+
#20028=*
99+
lines(#20028,#20001,"var class = 23;","
100+
")
101+
hasLocation(#20028,#20003)
102+
numlines(#20001,1,0,0)
103+
numlines(#10000,1,1,0)
104+
filetype(#10000,"javascript")

0 commit comments

Comments
 (0)