make sure the new identifiers have end-locations

This commit is contained in:
erik-krogh
2024-08-07 10:25:22 +02:00
parent b8187ed294
commit bef4fe627d
3 changed files with 146 additions and 2 deletions

View File

@@ -3555,7 +3555,7 @@ public class Parser {
// e.g. `export { Foo_new as "Foo::new" }`
Expression string = this.parseExprAtom(null);
String str = ((Literal)string).getStringValue();
exported = new Identifier(loc, str);
exported = this.finishNode(new Identifier(loc, str));
} else {
exported = this.parseIdent(true);
}
@@ -3648,7 +3648,7 @@ public class Parser {
// e.g. `import { "Foo::new" as Foo_new } from "./foo.wasm"`
Expression string = this.parseExprAtom(null);
String str = ((Literal)string).getStringValue();
imported = new Identifier(loc, str);
imported = this.finishNode(new Identifier(loc, str));
// only makes sense if there is a local identifier
if (!this.isContextual("as")) {
this.raiseRecoverable(this.start, "Unexpected string");

View File

@@ -0,0 +1 @@
import { "foo" } from "foo"; // syntax-error, but it shouldn't crash the extractor

View File

@@ -0,0 +1,143 @@
#10000=@"/arbitaryModuleSpecifier.js;sourcefile"
files(#10000,"/arbitaryModuleSpecifier.js")
#10001=@"/;folder"
folders(#10001,"/")
containerparent(#10001,#10000)
#10002=@"loc,{#10000},0,0,0,0"
locations_default(#10002,#10000,0,0,0,0)
hasLocation(#10000,#10002)
#20000=@"global_scope"
scopes(#20000,0)
#20001=@"script;{#10000},1,1"
#20002=*
comments(#20002,0,#20001," syntax-error, but it shouldn't crash the extractor","// synt ... tractor")
#20003=@"loc,{#10000},1,30,1,82"
locations_default(#20003,#10000,1,30,1,82)
hasLocation(#20002,#20003)
#20004=*
lines(#20004,#20001,"import { ""foo"" } from ""foo""; // syntax-error, but it shouldn't crash the extractor","
")
#20005=@"loc,{#10000},1,1,1,82"
locations_default(#20005,#10000,1,1,1,82)
hasLocation(#20004,#20005)
numlines(#20001,1,1,1)
#20006=*
tokeninfo(#20006,7,#20001,0,"import")
#20007=@"loc,{#10000},1,1,1,6"
locations_default(#20007,#10000,1,1,1,6)
hasLocation(#20006,#20007)
#20008=*
tokeninfo(#20008,8,#20001,1,"{")
#20009=@"loc,{#10000},1,8,1,8"
locations_default(#20009,#10000,1,8,1,8)
hasLocation(#20008,#20009)
#20010=*
tokeninfo(#20010,4,#20001,2,"""foo""")
#20011=@"loc,{#10000},1,10,1,14"
locations_default(#20011,#10000,1,10,1,14)
hasLocation(#20010,#20011)
#20012=*
tokeninfo(#20012,8,#20001,3,"}")
#20013=@"loc,{#10000},1,16,1,16"
locations_default(#20013,#10000,1,16,1,16)
hasLocation(#20012,#20013)
#20014=*
tokeninfo(#20014,6,#20001,4,"from")
#20015=@"loc,{#10000},1,18,1,21"
locations_default(#20015,#10000,1,18,1,21)
hasLocation(#20014,#20015)
#20016=*
tokeninfo(#20016,4,#20001,5,"""foo""")
#20017=@"loc,{#10000},1,23,1,27"
locations_default(#20017,#10000,1,23,1,27)
hasLocation(#20016,#20017)
#20018=*
tokeninfo(#20018,8,#20001,6,";")
#20019=@"loc,{#10000},1,28,1,28"
locations_default(#20019,#10000,1,28,1,28)
hasLocation(#20018,#20019)
#20020=*
tokeninfo(#20020,0,#20001,7,"")
#20021=@"loc,{#10000},2,1,2,0"
locations_default(#20021,#10000,2,1,2,0)
hasLocation(#20020,#20021)
next_token(#20002,#20020)
toplevels(#20001,0)
#20022=@"loc,{#10000},1,1,2,0"
locations_default(#20022,#10000,1,1,2,0)
hasLocation(#20001,#20022)
#20023=@"module;{#10000},1,1"
scopes(#20023,3)
scopenodes(#20001,#20023)
scopenesting(#20023,#20000)
is_module(#20001)
is_es2015_module(#20001)
#20024=@"var;{foo};{#20023}"
variables(#20024,"foo",#20023)
#20025=@"local_type_name;{foo};{#20023}"
local_type_names(#20025,"foo",#20023)
#20026=@"local_namespace_name;{foo};{#20023}"
local_namespace_names(#20026,"foo",#20023)
variables(#20024,"foo",#20023)
local_type_names(#20025,"foo",#20023)
local_namespace_names(#20026,"foo",#20023)
#20027=*
stmts(#20027,27,#20001,0,"import ... ""foo"";")
#20028=@"loc,{#10000},1,1,1,28"
locations_default(#20028,#10000,1,1,1,28)
hasLocation(#20027,#20028)
stmt_containers(#20027,#20001)
#20029=*
exprs(#20029,4,#20027,-1,"""foo""")
hasLocation(#20029,#20017)
enclosing_stmt(#20029,#20027)
expr_containers(#20029,#20001)
literals("foo","""foo""",#20029)
#20030=*
regexpterm(#20030,14,#20029,0,"foo")
#20031=@"loc,{#10000},1,24,1,26"
locations_default(#20031,#10000,1,24,1,26)
hasLocation(#20030,#20031)
regexp_const_value(#20030,"foo")
#20032=*
exprs(#20032,83,#20027,0,"""foo""")
hasLocation(#20032,#20011)
enclosing_stmt(#20032,#20027)
expr_containers(#20032,#20001)
#20033=*
exprs(#20033,0,#20032,0,"""foo""")
hasLocation(#20033,#20011)
enclosing_stmt(#20033,#20027)
expr_containers(#20033,#20001)
literals("foo","foo",#20033)
#20034=*
exprs(#20034,78,#20032,1,"""foo""")
hasLocation(#20034,#20011)
enclosing_stmt(#20034,#20027)
expr_containers(#20034,#20001)
literals("foo","foo",#20034)
decl(#20034,#20024)
typedecl(#20034,#20025)
namespacedecl(#20034,#20026)
#20035=*
entry_cfg_node(#20035,#20001)
#20036=@"loc,{#10000},1,1,1,0"
locations_default(#20036,#10000,1,1,1,0)
hasLocation(#20035,#20036)
#20037=*
exit_cfg_node(#20037,#20001)
hasLocation(#20037,#20021)
successor(#20027,#20037)
successor(#20032,#20027)
successor(#20035,#20032)
#20038=*
js_parse_errors(#20038,#20001,"Error: Unexpected string","import { ""foo"" } from ""foo""; // syntax-error, but it shouldn't crash the extractor
")
hasLocation(#20038,#20013)
#20039=*
lines(#20039,#20001,"import { ""foo"" } from ""foo""; // syntax-error, but it shouldn't crash the extractor","
")
hasLocation(#20039,#20005)
numlines(#20001,1,0,0)
numlines(#10000,1,1,1)
filetype(#10000,"javascript")