mirror of
https://github.com/github/codeql.git
synced 2025-12-16 16:53:25 +01:00
JS: Parse with proper locations
This commit is contained in:
@@ -114,7 +114,7 @@ public class JSDocParser {
|
||||
}
|
||||
|
||||
private static boolean isTypeName(char ch) {
|
||||
return "><(){}[],:*|?!=".indexOf(ch) == -1 && !isWhiteSpace(ch) && !isLineTerminator(ch);
|
||||
return "><(){}[],:*|?!=.".indexOf(ch) == -1 && !isWhiteSpace(ch) && !isLineTerminator(ch);
|
||||
}
|
||||
|
||||
private static boolean isParamTitle(String title) {
|
||||
@@ -536,20 +536,9 @@ public class JSDocParser {
|
||||
}
|
||||
|
||||
private Token scanTypeName() {
|
||||
char ch, ch2;
|
||||
|
||||
StringBuilder sb = new StringBuilder();
|
||||
sb.append((char)advance());
|
||||
while (index < endIndex && isTypeName(source.charAt(index))) {
|
||||
ch = source.charAt(index);
|
||||
if (ch == '.') {
|
||||
if ((index + 1) < endIndex) {
|
||||
ch2 = source.charAt(index + 1);
|
||||
if (ch2 == '<') {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
sb.append((char)advance());
|
||||
}
|
||||
value = sb.toString();
|
||||
@@ -827,15 +816,21 @@ public class JSDocParser {
|
||||
return finishNode(new RecordType(loc, fields));
|
||||
}
|
||||
|
||||
private JSDocTypeExpression parseNameExpression() throws ParseError {
|
||||
private Identifier parseIdentifier() throws ParseError {
|
||||
SourceLocation loc = loc();
|
||||
Object value = this.value; // save the value of the current token
|
||||
expect(Token.NAME);
|
||||
// Hacky initial implementation with wrong locations
|
||||
String[] parts = value.toString().split("\\.");
|
||||
JSDocTypeExpression node = finishNode(new Identifier(loc, parts[0]));
|
||||
for (int i = 1; i < parts.length; i++) {
|
||||
Identifier memberName = finishNode(new Identifier(loc, parts[i]));
|
||||
return finishNode(new Identifier(loc, value.toString()));
|
||||
}
|
||||
|
||||
private JSDocTypeExpression parseNameExpression() throws ParseError {
|
||||
JSDocTypeExpression node = parseIdentifier();
|
||||
while (token == Token.DOT) {
|
||||
consume(Token.DOT);
|
||||
Identifier memberName = parseIdentifier();
|
||||
// Create a SourceLocation object with the correct start location.
|
||||
// The call to finishNode() will set the end location.
|
||||
SourceLocation loc = new SourceLocation(node.getLoc());
|
||||
node = finishNode(new QualifiedNameExpression(loc, node, memberName));
|
||||
}
|
||||
return node;
|
||||
|
||||
@@ -523,156 +523,164 @@ locations_default(#20160,#10000,11,26,11,37)
|
||||
hasLocation(#20159,#20160)
|
||||
#20161=*
|
||||
jsdoc_type_exprs(#20161,15,#20159,0,"goog.ui")
|
||||
hasLocation(#20161,#20160)
|
||||
#20162=*
|
||||
jsdoc_type_exprs(#20162,5,#20161,0,"goog")
|
||||
hasLocation(#20162,#20160)
|
||||
#20162=@"loc,{#10000},11,26,11,32"
|
||||
locations_default(#20162,#10000,11,26,11,32)
|
||||
hasLocation(#20161,#20162)
|
||||
#20163=*
|
||||
jsdoc_type_exprs(#20163,5,#20161,1,"ui")
|
||||
hasLocation(#20163,#20160)
|
||||
#20164=*
|
||||
jsdoc_type_exprs(#20164,5,#20159,1,"Menu")
|
||||
hasLocation(#20164,#20160)
|
||||
jsdoc_has_new_parameter(#20145)
|
||||
jsdoc_type_exprs(#20163,5,#20161,0,"goog")
|
||||
#20164=@"loc,{#10000},11,26,11,29"
|
||||
locations_default(#20164,#10000,11,26,11,29)
|
||||
hasLocation(#20163,#20164)
|
||||
#20165=*
|
||||
jsdoc_tags(#20165,"param",#20117,4,"@param")
|
||||
#20166=@"loc,{#10000},12,5,12,10"
|
||||
locations_default(#20166,#10000,12,5,12,10)
|
||||
jsdoc_type_exprs(#20165,5,#20161,1,"ui")
|
||||
#20166=@"loc,{#10000},11,31,11,32"
|
||||
locations_default(#20166,#10000,11,31,11,32)
|
||||
hasLocation(#20165,#20166)
|
||||
jsdoc_tag_names(#20165,"var_args")
|
||||
#20167=*
|
||||
jsdoc_type_exprs(#20167,14,#20165,0,"...number")
|
||||
#20168=@"loc,{#10000},12,13,12,21"
|
||||
locations_default(#20168,#10000,12,13,12,21)
|
||||
jsdoc_type_exprs(#20167,5,#20159,1,"Menu")
|
||||
#20168=@"loc,{#10000},11,34,11,37"
|
||||
locations_default(#20168,#10000,11,34,11,37)
|
||||
hasLocation(#20167,#20168)
|
||||
jsdoc_has_new_parameter(#20145)
|
||||
#20169=*
|
||||
jsdoc_type_exprs(#20169,5,#20167,0,"number")
|
||||
#20170=@"loc,{#10000},12,16,12,21"
|
||||
locations_default(#20170,#10000,12,16,12,21)
|
||||
jsdoc_tags(#20169,"param",#20117,4,"@param")
|
||||
#20170=@"loc,{#10000},12,5,12,10"
|
||||
locations_default(#20170,#10000,12,5,12,10)
|
||||
hasLocation(#20169,#20170)
|
||||
jsdoc_tag_names(#20169,"var_args")
|
||||
#20171=*
|
||||
jsdoc(#20171,"",#20010)
|
||||
hasLocation(#20171,#20011)
|
||||
#20172=*
|
||||
jsdoc_tags(#20172,"param",#20171,0,"@param")
|
||||
#20173=@"loc,{#10000},15,4,15,9"
|
||||
locations_default(#20173,#10000,15,4,15,9)
|
||||
hasLocation(#20172,#20173)
|
||||
#20174=*
|
||||
jsdoc_errors(#20174,#20172,"Missing or invalid tag name","Missing ... ag name")
|
||||
jsdoc_type_exprs(#20171,14,#20169,0,"...number")
|
||||
#20172=@"loc,{#10000},12,13,12,21"
|
||||
locations_default(#20172,#10000,12,13,12,21)
|
||||
hasLocation(#20171,#20172)
|
||||
#20173=*
|
||||
jsdoc_type_exprs(#20173,5,#20171,0,"number")
|
||||
#20174=@"loc,{#10000},12,16,12,21"
|
||||
locations_default(#20174,#10000,12,16,12,21)
|
||||
hasLocation(#20173,#20174)
|
||||
#20175=*
|
||||
jsdoc_tags(#20175,"param",#20171,1,"@param")
|
||||
#20176=@"loc,{#10000},16,4,16,9"
|
||||
locations_default(#20176,#10000,16,4,16,9)
|
||||
hasLocation(#20175,#20176)
|
||||
jsdoc_tag_names(#20175,"x")
|
||||
#20177=*
|
||||
jsdoc(#20177,"",#20012)
|
||||
hasLocation(#20177,#20013)
|
||||
jsdoc(#20175,"",#20010)
|
||||
hasLocation(#20175,#20011)
|
||||
#20176=*
|
||||
jsdoc_tags(#20176,"param",#20175,0,"@param")
|
||||
#20177=@"loc,{#10000},15,4,15,9"
|
||||
locations_default(#20177,#10000,15,4,15,9)
|
||||
hasLocation(#20176,#20177)
|
||||
#20178=*
|
||||
jsdoc_tags(#20178,"",#20177,0,"@")
|
||||
#20179=@"loc,{#10000},20,4,20,4"
|
||||
locations_default(#20179,#10000,20,4,20,4)
|
||||
hasLocation(#20178,#20179)
|
||||
jsdoc_tag_descriptions(#20178,"{link a}")
|
||||
#20180=*
|
||||
jsdoc_errors(#20180,#20178,"Missing or invalid title","Missing ... d title")
|
||||
jsdoc_errors(#20178,#20176,"Missing or invalid tag name","Missing ... ag name")
|
||||
#20179=*
|
||||
jsdoc_tags(#20179,"param",#20175,1,"@param")
|
||||
#20180=@"loc,{#10000},16,4,16,9"
|
||||
locations_default(#20180,#10000,16,4,16,9)
|
||||
hasLocation(#20179,#20180)
|
||||
jsdoc_tag_names(#20179,"x")
|
||||
#20181=*
|
||||
jsdoc(#20181,"",#20014)
|
||||
hasLocation(#20181,#20015)
|
||||
jsdoc(#20181,"",#20012)
|
||||
hasLocation(#20181,#20013)
|
||||
#20182=*
|
||||
jsdoc_tags(#20182,"typedef",#20181,0,"@typedef")
|
||||
#20183=@"loc,{#10000},24,4,24,11"
|
||||
locations_default(#20183,#10000,24,4,24,11)
|
||||
jsdoc_tags(#20182,"",#20181,0,"@")
|
||||
#20183=@"loc,{#10000},20,4,20,4"
|
||||
locations_default(#20183,#10000,20,4,20,4)
|
||||
hasLocation(#20182,#20183)
|
||||
jsdoc_tag_descriptions(#20182,"{a}")
|
||||
jsdoc_tag_descriptions(#20182,"{link a}")
|
||||
#20184=*
|
||||
jsdoc_errors(#20184,#20182,"Missing or invalid tag type","Missing ... ag type")
|
||||
jsdoc_errors(#20184,#20182,"Missing or invalid title","Missing ... d title")
|
||||
#20185=*
|
||||
jsdoc(#20185,"[resize description]",#20016)
|
||||
hasLocation(#20185,#20017)
|
||||
jsdoc(#20185,"",#20014)
|
||||
hasLocation(#20185,#20015)
|
||||
#20186=*
|
||||
jsdoc_tags(#20186,"param",#20185,0,"@param")
|
||||
#20187=@"loc,{#10000},30,4,30,9"
|
||||
locations_default(#20187,#10000,30,4,30,9)
|
||||
jsdoc_tags(#20186,"typedef",#20185,0,"@typedef")
|
||||
#20187=@"loc,{#10000},24,4,24,11"
|
||||
locations_default(#20187,#10000,24,4,24,11)
|
||||
hasLocation(#20186,#20187)
|
||||
jsdoc_tag_descriptions(#20186,"[description]
|
||||
")
|
||||
jsdoc_tag_names(#20186,"w")
|
||||
jsdoc_tag_descriptions(#20186,"{a}")
|
||||
#20188=*
|
||||
jsdoc_type_exprs(#20188,10,#20186,0,"[type]")
|
||||
#20189=@"loc,{#10000},30,13,30,18"
|
||||
locations_default(#20189,#10000,30,13,30,18)
|
||||
hasLocation(#20188,#20189)
|
||||
jsdoc_errors(#20188,#20186,"Missing or invalid tag type","Missing ... ag type")
|
||||
#20189=*
|
||||
jsdoc(#20189,"[resize description]",#20016)
|
||||
hasLocation(#20189,#20017)
|
||||
#20190=*
|
||||
jsdoc_type_exprs(#20190,5,#20188,0,"type")
|
||||
#20191=@"loc,{#10000},30,14,30,17"
|
||||
locations_default(#20191,#10000,30,14,30,17)
|
||||
jsdoc_tags(#20190,"param",#20189,0,"@param")
|
||||
#20191=@"loc,{#10000},30,4,30,9"
|
||||
locations_default(#20191,#10000,30,4,30,9)
|
||||
hasLocation(#20190,#20191)
|
||||
jsdoc_tag_descriptions(#20190,"[description]
|
||||
")
|
||||
jsdoc_tag_names(#20190,"w")
|
||||
#20192=*
|
||||
jsdoc_tags(#20192,"param",#20185,1,"@param")
|
||||
#20193=@"loc,{#10000},31,4,31,9"
|
||||
locations_default(#20193,#10000,31,4,31,9)
|
||||
jsdoc_type_exprs(#20192,10,#20190,0,"[type]")
|
||||
#20193=@"loc,{#10000},30,13,30,18"
|
||||
locations_default(#20193,#10000,30,13,30,18)
|
||||
hasLocation(#20192,#20193)
|
||||
jsdoc_tag_descriptions(#20192,"[description]
|
||||
")
|
||||
#20194=*
|
||||
jsdoc_tags(#20194,"return",#20185,2,"@return")
|
||||
#20195=@"loc,{#10000},32,4,32,10"
|
||||
locations_default(#20195,#10000,32,4,32,10)
|
||||
jsdoc_type_exprs(#20194,5,#20192,0,"type")
|
||||
#20195=@"loc,{#10000},30,14,30,17"
|
||||
locations_default(#20195,#10000,30,14,30,17)
|
||||
hasLocation(#20194,#20195)
|
||||
jsdoc_tag_descriptions(#20194,"[description]")
|
||||
#20196=*
|
||||
jsdoc_type_exprs(#20196,10,#20194,0,"[type]")
|
||||
#20197=@"loc,{#10000},32,13,32,18"
|
||||
locations_default(#20197,#10000,32,13,32,18)
|
||||
jsdoc_tags(#20196,"param",#20189,1,"@param")
|
||||
#20197=@"loc,{#10000},31,4,31,9"
|
||||
locations_default(#20197,#10000,31,4,31,9)
|
||||
hasLocation(#20196,#20197)
|
||||
#20198=*
|
||||
jsdoc_type_exprs(#20198,5,#20196,0,"type")
|
||||
#20199=@"loc,{#10000},32,14,32,17"
|
||||
locations_default(#20199,#10000,32,14,32,17)
|
||||
hasLocation(#20198,#20199)
|
||||
#20200=*
|
||||
jsdoc(#20200,"",#20018)
|
||||
hasLocation(#20200,#20019)
|
||||
#20201=*
|
||||
jsdoc_tags(#20201,"exports",#20200,0,"@exports")
|
||||
#20202=@"loc,{#10000},36,3,36,10"
|
||||
locations_default(#20202,#10000,36,3,36,10)
|
||||
hasLocation(#20201,#20202)
|
||||
jsdoc_tag_descriptions(#20201,"R
|
||||
jsdoc_tag_descriptions(#20196,"[description]
|
||||
")
|
||||
#20203=*
|
||||
jsdoc(#20203,"",#20020)
|
||||
hasLocation(#20203,#20021)
|
||||
#20198=*
|
||||
jsdoc_tags(#20198,"return",#20189,2,"@return")
|
||||
#20199=@"loc,{#10000},32,4,32,10"
|
||||
locations_default(#20199,#10000,32,4,32,10)
|
||||
hasLocation(#20198,#20199)
|
||||
jsdoc_tag_descriptions(#20198,"[description]")
|
||||
#20200=*
|
||||
jsdoc_type_exprs(#20200,10,#20198,0,"[type]")
|
||||
#20201=@"loc,{#10000},32,13,32,18"
|
||||
locations_default(#20201,#10000,32,13,32,18)
|
||||
hasLocation(#20200,#20201)
|
||||
#20202=*
|
||||
jsdoc_type_exprs(#20202,5,#20200,0,"type")
|
||||
#20203=@"loc,{#10000},32,14,32,17"
|
||||
locations_default(#20203,#10000,32,14,32,17)
|
||||
hasLocation(#20202,#20203)
|
||||
#20204=*
|
||||
jsdoc_tags(#20204,"typedef",#20203,0,"@typedef")
|
||||
#20205=@"loc,{#10000},41,4,41,11"
|
||||
locations_default(#20205,#10000,41,4,41,11)
|
||||
hasLocation(#20204,#20205)
|
||||
#20206=*
|
||||
jsdoc_type_exprs(#20206,9,#20204,0,"{0: number}")
|
||||
#20207=@"loc,{#10000},41,14,41,24"
|
||||
locations_default(#20207,#10000,41,14,41,24)
|
||||
hasLocation(#20206,#20207)
|
||||
jsdoc_record_field_name(#20206,0,"0")
|
||||
jsdoc(#20204,"",#20018)
|
||||
hasLocation(#20204,#20019)
|
||||
#20205=*
|
||||
jsdoc_tags(#20205,"exports",#20204,0,"@exports")
|
||||
#20206=@"loc,{#10000},36,3,36,10"
|
||||
locations_default(#20206,#10000,36,3,36,10)
|
||||
hasLocation(#20205,#20206)
|
||||
jsdoc_tag_descriptions(#20205,"R
|
||||
")
|
||||
#20207=*
|
||||
jsdoc(#20207,"",#20020)
|
||||
hasLocation(#20207,#20021)
|
||||
#20208=*
|
||||
jsdoc_type_exprs(#20208,5,#20206,0,"number")
|
||||
#20209=@"loc,{#10000},41,18,41,23"
|
||||
locations_default(#20209,#10000,41,18,41,23)
|
||||
jsdoc_tags(#20208,"typedef",#20207,0,"@typedef")
|
||||
#20209=@"loc,{#10000},41,4,41,11"
|
||||
locations_default(#20209,#10000,41,4,41,11)
|
||||
hasLocation(#20208,#20209)
|
||||
#20210=*
|
||||
jsdoc_type_exprs(#20210,9,#20208,0,"{0: number}")
|
||||
#20211=@"loc,{#10000},41,14,41,24"
|
||||
locations_default(#20211,#10000,41,14,41,24)
|
||||
hasLocation(#20210,#20211)
|
||||
jsdoc_record_field_name(#20210,0,"0")
|
||||
#20212=*
|
||||
jsdoc_type_exprs(#20212,5,#20210,0,"number")
|
||||
#20213=@"loc,{#10000},41,18,41,23"
|
||||
locations_default(#20213,#10000,41,18,41,23)
|
||||
hasLocation(#20212,#20213)
|
||||
toplevels(#20001,0)
|
||||
#20210=@"loc,{#10000},1,1,43,0"
|
||||
locations_default(#20210,#10000,1,1,43,0)
|
||||
hasLocation(#20001,#20210)
|
||||
#20211=*
|
||||
entry_cfg_node(#20211,#20001)
|
||||
#20212=@"loc,{#10000},1,1,1,0"
|
||||
locations_default(#20212,#10000,1,1,1,0)
|
||||
hasLocation(#20211,#20212)
|
||||
#20213=*
|
||||
exit_cfg_node(#20213,#20001)
|
||||
hasLocation(#20213,#20105)
|
||||
successor(#20211,#20213)
|
||||
#20214=@"loc,{#10000},1,1,43,0"
|
||||
locations_default(#20214,#10000,1,1,43,0)
|
||||
hasLocation(#20001,#20214)
|
||||
#20215=*
|
||||
entry_cfg_node(#20215,#20001)
|
||||
#20216=@"loc,{#10000},1,1,1,0"
|
||||
locations_default(#20216,#10000,1,1,1,0)
|
||||
hasLocation(#20215,#20216)
|
||||
#20217=*
|
||||
exit_cfg_node(#20217,#20001)
|
||||
hasLocation(#20217,#20105)
|
||||
successor(#20215,#20217)
|
||||
numlines(#10000,42,0,37)
|
||||
filetype(#10000,"javascript")
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
| bar.js:5:14:5:18 | x | x |
|
||||
| bar.js:5:14:5:14 | x | x |
|
||||
| bar.js:5:14:5:18 | x.Foo | ns.very.long.namespace.Foo |
|
||||
| bar.js:12:14:12:21 | iife | iife |
|
||||
| bar.js:12:14:12:17 | iife | iife |
|
||||
| bar.js:12:14:12:21 | iife.Foo | IIFE.Foo |
|
||||
| closure.js:8:12:8:28 | goog | goog |
|
||||
| closure.js:8:12:8:28 | goog.net | goog.net |
|
||||
| closure.js:8:12:8:15 | goog | goog |
|
||||
| closure.js:8:12:8:19 | goog.net | goog.net |
|
||||
| closure.js:8:12:8:28 | goog.net.SomeType | goog.net.SomeType |
|
||||
| closure.js:9:12:9:23 | net | net |
|
||||
| closure.js:9:12:9:14 | net | net |
|
||||
| closure.js:9:12:9:23 | net.SomeType | goog.net.SomeType |
|
||||
| closure.js:10:12:10:19 | SomeType | goog.net.SomeType |
|
||||
|
||||
Reference in New Issue
Block a user