From 38194c6ae7095ac981b2af1abe5e35c50fd05dd4 Mon Sep 17 00:00:00 2001 From: Asger F Date: Fri, 3 Mar 2023 11:35:24 +0100 Subject: [PATCH] JS: Extract import assertions to DB --- .../com/semmle/js/extractor/ASTExtractor.java | 4 + .../output/trap/import-assertion.js.trap | 792 ++++++++++++------ .../ts/output/trap/import-assertion.ts.trap | 735 ++++++++-------- .../lib/semmle/javascript/ES2015Modules.qll | 23 + javascript/ql/lib/semmle/javascript/Expr.qll | 11 + .../ImportAssertions/js-import-assertions.js | 13 + .../TypeScript/ImportAssertions/test.expected | 20 + .../TypeScript/ImportAssertions/test.ql | 13 + .../ImportAssertions/ts-import-assertions.ts | 15 + 9 files changed, 1025 insertions(+), 601 deletions(-) create mode 100644 javascript/ql/test/library-tests/TypeScript/ImportAssertions/js-import-assertions.js create mode 100644 javascript/ql/test/library-tests/TypeScript/ImportAssertions/test.expected create mode 100644 javascript/ql/test/library-tests/TypeScript/ImportAssertions/test.ql create mode 100644 javascript/ql/test/library-tests/TypeScript/ImportAssertions/ts-import-assertions.ts diff --git a/javascript/extractor/src/com/semmle/js/extractor/ASTExtractor.java b/javascript/extractor/src/com/semmle/js/extractor/ASTExtractor.java index 0a85e1e87f0..b0b88854239 100644 --- a/javascript/extractor/src/com/semmle/js/extractor/ASTExtractor.java +++ b/javascript/extractor/src/com/semmle/js/extractor/ASTExtractor.java @@ -1759,6 +1759,7 @@ public class ASTExtractor { public Label visit(ExportAllDeclaration nd, Context c) { Label lbl = super.visit(nd, c); visit(nd.getSource(), lbl, 0); + visit(nd.getAssertion(), lbl, -10); return lbl; } @@ -1774,6 +1775,7 @@ public class ASTExtractor { Label lbl = super.visit(nd, c); visit(nd.getDeclaration(), lbl, -1); visit(nd.getSource(), lbl, -2); + visit(nd.getAssertion(), lbl, -10); IdContext childContext = nd.hasSource() ? IdContext.LABEL @@ -1797,6 +1799,7 @@ public class ASTExtractor { public Label visit(ImportDeclaration nd, Context c) { Label lbl = super.visit(nd, c); visit(nd.getSource(), lbl, -1); + visit(nd.getAssertion(), lbl, -10); IdContext childContext = nd.hasTypeKeyword() ? IdContext.TYPE_ONLY_IMPORT @@ -1972,6 +1975,7 @@ public class ASTExtractor { public Label visit(DynamicImport nd, Context c) { Label key = super.visit(nd, c); visit(nd.getSource(), key, 0); + visit(nd.getAttributes(), key, 1); return key; } diff --git a/javascript/extractor/tests/esnext/output/trap/import-assertion.js.trap b/javascript/extractor/tests/esnext/output/trap/import-assertion.js.trap index 4ab0cc54f6d..88f32abcfbf 100644 --- a/javascript/extractor/tests/esnext/output/trap/import-assertion.js.trap +++ b/javascript/extractor/tests/esnext/output/trap/import-assertion.js.trap @@ -721,327 +721,585 @@ locations_default(#20273,#10000,1,9,1,14) hasLocation(#20272,#20273) regexp_const_value(#20272,"module") #20274=* -stmts(#20274,27,#20001,1,"import ... son"" };") -hasLocation(#20274,#20009) -stmt_containers(#20274,#20001) -#20275=* -exprs(#20275,4,#20274,-1,"""module""") -hasLocation(#20275,#20061) -enclosing_stmt(#20275,#20274) -expr_containers(#20275,#20001) -literals("module","""module""",#20275) +exprs(#20274,8,#20270,-10,"{ type: ""json"" }") +#20275=@"loc,{#10000},1,24,1,39" +locations_default(#20275,#10000,1,24,1,39) +hasLocation(#20274,#20275) +enclosing_stmt(#20274,#20270) +expr_containers(#20274,#20001) #20276=* -regexpterm(#20276,14,#20275,0,"module") -#20277=@"loc,{#10000},2,22,2,27" -locations_default(#20277,#10000,2,22,2,27) +properties(#20276,#20274,0,0,"type: ""json""") +#20277=@"loc,{#10000},1,26,1,37" +locations_default(#20277,#10000,1,26,1,37) hasLocation(#20276,#20277) -regexp_const_value(#20276,"module") #20278=* -exprs(#20278,85,#20274,0,"* as v1") -#20279=@"loc,{#10000},2,8,2,14" -locations_default(#20279,#10000,2,8,2,14) -hasLocation(#20278,#20279) -enclosing_stmt(#20278,#20274) +exprs(#20278,0,#20276,0,"type") +hasLocation(#20278,#20041) +enclosing_stmt(#20278,#20270) expr_containers(#20278,#20001) +literals("type","type",#20278) +#20279=* +exprs(#20279,4,#20276,1,"""json""") +hasLocation(#20279,#20045) +enclosing_stmt(#20279,#20270) +expr_containers(#20279,#20001) +literals("json","""json""",#20279) #20280=* -exprs(#20280,78,#20278,1,"v1") -hasLocation(#20280,#20057) -enclosing_stmt(#20280,#20274) -expr_containers(#20280,#20001) -literals("v1","v1",#20280) -decl(#20280,#20260) -typedecl(#20280,#20263) -namespacedecl(#20280,#20266) -#20281=* -stmts(#20281,27,#20001,2,"import ... son"" };") -hasLocation(#20281,#20011) -stmt_containers(#20281,#20001) +regexpterm(#20280,14,#20279,0,"json") +#20281=@"loc,{#10000},1,33,1,36" +locations_default(#20281,#10000,1,33,1,36) +hasLocation(#20280,#20281) +regexp_const_value(#20280,"json") #20282=* -exprs(#20282,4,#20281,-1,"""module""") -hasLocation(#20282,#20087) -enclosing_stmt(#20282,#20281) -expr_containers(#20282,#20001) -literals("module","""module""",#20282) +stmts(#20282,27,#20001,1,"import ... son"" };") +hasLocation(#20282,#20009) +stmt_containers(#20282,#20001) #20283=* -regexpterm(#20283,14,#20282,0,"module") -#20284=@"loc,{#10000},3,21,3,26" -locations_default(#20284,#10000,3,21,3,26) -hasLocation(#20283,#20284) -regexp_const_value(#20283,"module") -#20285=* -exprs(#20285,83,#20281,0,"v2") -hasLocation(#20285,#20081) -enclosing_stmt(#20285,#20281) -expr_containers(#20285,#20001) +exprs(#20283,4,#20282,-1,"""module""") +hasLocation(#20283,#20061) +enclosing_stmt(#20283,#20282) +expr_containers(#20283,#20001) +literals("module","""module""",#20283) +#20284=* +regexpterm(#20284,14,#20283,0,"module") +#20285=@"loc,{#10000},2,22,2,27" +locations_default(#20285,#10000,2,22,2,27) +hasLocation(#20284,#20285) +regexp_const_value(#20284,"module") #20286=* -exprs(#20286,0,#20285,0,"v2") -hasLocation(#20286,#20081) -enclosing_stmt(#20286,#20281) +exprs(#20286,8,#20282,-10,"{ type: ""json"" }") +#20287=@"loc,{#10000},2,37,2,52" +locations_default(#20287,#10000,2,37,2,52) +hasLocation(#20286,#20287) +enclosing_stmt(#20286,#20282) expr_containers(#20286,#20001) -literals("v2","v2",#20286) -#20287=* -exprs(#20287,78,#20285,1,"v2") -hasLocation(#20287,#20081) -enclosing_stmt(#20287,#20281) -expr_containers(#20287,#20001) -literals("v2","v2",#20287) -decl(#20287,#20261) -typedecl(#20287,#20264) -namespacedecl(#20287,#20267) #20288=* -stmts(#20288,27,#20001,3,"import ... son"" };") -hasLocation(#20288,#20013) -stmt_containers(#20288,#20001) -#20289=* -exprs(#20289,4,#20288,-1,"""module""") -hasLocation(#20289,#20109) -enclosing_stmt(#20289,#20288) -expr_containers(#20289,#20001) -literals("module","""module""",#20289) +properties(#20288,#20286,0,0,"type: ""json""") +#20289=@"loc,{#10000},2,39,2,50" +locations_default(#20289,#10000,2,39,2,50) +hasLocation(#20288,#20289) #20290=* -regexpterm(#20290,14,#20289,0,"module") -#20291=@"loc,{#10000},4,17,4,22" -locations_default(#20291,#10000,4,17,4,22) -hasLocation(#20290,#20291) -regexp_const_value(#20290,"module") +exprs(#20290,0,#20288,0,"type") +hasLocation(#20290,#20067) +enclosing_stmt(#20290,#20282) +expr_containers(#20290,#20001) +literals("type","type",#20290) +#20291=* +exprs(#20291,4,#20288,1,"""json""") +hasLocation(#20291,#20071) +enclosing_stmt(#20291,#20282) +expr_containers(#20291,#20001) +literals("json","""json""",#20291) #20292=* -exprs(#20292,84,#20288,0,"v3") -hasLocation(#20292,#20105) -enclosing_stmt(#20292,#20288) -expr_containers(#20292,#20001) -#20293=* -exprs(#20293,78,#20292,1,"v3") -hasLocation(#20293,#20105) -enclosing_stmt(#20293,#20288) -expr_containers(#20293,#20001) -literals("v3","v3",#20293) -decl(#20293,#20262) -typedecl(#20293,#20265) -namespacedecl(#20293,#20268) +regexpterm(#20292,14,#20291,0,"json") +#20293=@"loc,{#10000},2,46,2,49" +locations_default(#20293,#10000,2,46,2,49) +hasLocation(#20292,#20293) +regexp_const_value(#20292,"json") #20294=* -stmts(#20294,30,#20001,4,"export ... son"" };") -hasLocation(#20294,#20017) -stmt_containers(#20294,#20001) -#20295=* -exprs(#20295,4,#20294,-2,"""module""") -hasLocation(#20295,#20135) -enclosing_stmt(#20295,#20294) -expr_containers(#20295,#20001) -literals("module","""module""",#20295) +exprs(#20294,85,#20282,0,"* as v1") +#20295=@"loc,{#10000},2,8,2,14" +locations_default(#20295,#10000,2,8,2,14) +hasLocation(#20294,#20295) +enclosing_stmt(#20294,#20282) +expr_containers(#20294,#20001) #20296=* -regexpterm(#20296,14,#20295,0,"module") -#20297=@"loc,{#10000},6,21,6,26" -locations_default(#20297,#10000,6,21,6,26) -hasLocation(#20296,#20297) -regexp_const_value(#20296,"module") +exprs(#20296,78,#20294,1,"v1") +hasLocation(#20296,#20057) +enclosing_stmt(#20296,#20282) +expr_containers(#20296,#20001) +literals("v1","v1",#20296) +decl(#20296,#20260) +typedecl(#20296,#20263) +namespacedecl(#20296,#20266) +#20297=* +stmts(#20297,27,#20001,2,"import ... son"" };") +hasLocation(#20297,#20011) +stmt_containers(#20297,#20001) #20298=* -exprs(#20298,86,#20294,0,"v4") -hasLocation(#20298,#20129) -enclosing_stmt(#20298,#20294) +exprs(#20298,4,#20297,-1,"""module""") +hasLocation(#20298,#20087) +enclosing_stmt(#20298,#20297) expr_containers(#20298,#20001) +literals("module","""module""",#20298) #20299=* -exprs(#20299,0,#20298,0,"v4") -hasLocation(#20299,#20129) -enclosing_stmt(#20299,#20294) -expr_containers(#20299,#20001) -literals("v4","v4",#20299) -#20300=* -exprs(#20300,0,#20298,1,"v4") -hasLocation(#20300,#20129) -enclosing_stmt(#20300,#20294) -expr_containers(#20300,#20001) -literals("v4","v4",#20300) +regexpterm(#20299,14,#20298,0,"module") +#20300=@"loc,{#10000},3,21,3,26" +locations_default(#20300,#10000,3,21,3,26) +hasLocation(#20299,#20300) +regexp_const_value(#20299,"module") #20301=* -stmts(#20301,28,#20001,5,"export ... son"" };") -hasLocation(#20301,#20019) -stmt_containers(#20301,#20001) -#20302=* -exprs(#20302,4,#20301,0,"""module""") -hasLocation(#20302,#20157) -enclosing_stmt(#20302,#20301) -expr_containers(#20302,#20001) -literals("module","""module""",#20302) +exprs(#20301,8,#20297,-10,"{ type: ""json"" }") +#20302=@"loc,{#10000},3,36,3,51" +locations_default(#20302,#10000,3,36,3,51) +hasLocation(#20301,#20302) +enclosing_stmt(#20301,#20297) +expr_containers(#20301,#20001) #20303=* -regexpterm(#20303,14,#20302,0,"module") -#20304=@"loc,{#10000},7,16,7,21" -locations_default(#20304,#10000,7,16,7,21) +properties(#20303,#20301,0,0,"type: ""json""") +#20304=@"loc,{#10000},3,38,3,49" +locations_default(#20304,#10000,3,38,3,49) hasLocation(#20303,#20304) -regexp_const_value(#20303,"module") #20305=* -stmts(#20305,30,#20001,6,"export ... son"" };") -hasLocation(#20305,#20021) -stmt_containers(#20305,#20001) +exprs(#20305,0,#20303,0,"type") +hasLocation(#20305,#20093) +enclosing_stmt(#20305,#20297) +expr_containers(#20305,#20001) +literals("type","type",#20305) #20306=* -exprs(#20306,4,#20305,-2,"""module""") -hasLocation(#20306,#20183) -enclosing_stmt(#20306,#20305) +exprs(#20306,4,#20303,1,"""json""") +hasLocation(#20306,#20097) +enclosing_stmt(#20306,#20297) expr_containers(#20306,#20001) -literals("module","""module""",#20306) +literals("json","""json""",#20306) #20307=* -regexpterm(#20307,14,#20306,0,"module") -#20308=@"loc,{#10000},8,22,8,27" -locations_default(#20308,#10000,8,22,8,27) +regexpterm(#20307,14,#20306,0,"json") +#20308=@"loc,{#10000},3,45,3,48" +locations_default(#20308,#10000,3,45,3,48) hasLocation(#20307,#20308) -regexp_const_value(#20307,"module") +regexp_const_value(#20307,"json") #20309=* -exprs(#20309,96,#20305,0,"* as v5") -#20310=@"loc,{#10000},8,8,8,14" -locations_default(#20310,#10000,8,8,8,14) -hasLocation(#20309,#20310) -enclosing_stmt(#20309,#20305) +exprs(#20309,83,#20297,0,"v2") +hasLocation(#20309,#20081) +enclosing_stmt(#20309,#20297) expr_containers(#20309,#20001) +#20310=* +exprs(#20310,0,#20309,0,"v2") +hasLocation(#20310,#20081) +enclosing_stmt(#20310,#20297) +expr_containers(#20310,#20001) +literals("v2","v2",#20310) #20311=* -exprs(#20311,0,#20309,1,"v5") -hasLocation(#20311,#20179) -enclosing_stmt(#20311,#20305) +exprs(#20311,78,#20309,1,"v2") +hasLocation(#20311,#20081) +enclosing_stmt(#20311,#20297) expr_containers(#20311,#20001) -literals("v5","v5",#20311) +literals("v2","v2",#20311) +decl(#20311,#20261) +typedecl(#20311,#20264) +namespacedecl(#20311,#20267) #20312=* -stmts(#20312,22,#20001,7,"const v ... "" } });") -hasLocation(#20312,#20025) +stmts(#20312,27,#20001,3,"import ... son"" };") +hasLocation(#20312,#20013) stmt_containers(#20312,#20001) #20313=* -exprs(#20313,64,#20312,0,"v6 = im ... n"" } })") -#20314=@"loc,{#10000},10,7,10,57" -locations_default(#20314,#10000,10,7,10,57) -hasLocation(#20313,#20314) +exprs(#20313,4,#20312,-1,"""module""") +hasLocation(#20313,#20109) enclosing_stmt(#20313,#20312) expr_containers(#20313,#20001) -#20315=* -exprs(#20315,78,#20313,0,"v6") -hasLocation(#20315,#20201) -enclosing_stmt(#20315,#20312) -expr_containers(#20315,#20001) -literals("v6","v6",#20315) -decl(#20315,#20269) +literals("module","""module""",#20313) +#20314=* +regexpterm(#20314,14,#20313,0,"module") +#20315=@"loc,{#10000},4,17,4,22" +locations_default(#20315,#10000,4,17,4,22) +hasLocation(#20314,#20315) +regexp_const_value(#20314,"module") #20316=* -exprs(#20316,99,#20313,1,"import( ... n"" } })") -#20317=@"loc,{#10000},10,12,10,57" -locations_default(#20317,#10000,10,12,10,57) +exprs(#20316,8,#20312,-10,"{ type: ""json"" }") +#20317=@"loc,{#10000},4,32,4,47" +locations_default(#20317,#10000,4,32,4,47) hasLocation(#20316,#20317) enclosing_stmt(#20316,#20312) expr_containers(#20316,#20001) #20318=* -exprs(#20318,4,#20316,0,"""module""") -hasLocation(#20318,#20209) -enclosing_stmt(#20318,#20312) -expr_containers(#20318,#20001) -literals("module","""module""",#20318) -#20319=* -regexpterm(#20319,14,#20318,0,"module") -#20320=@"loc,{#10000},10,20,10,25" -locations_default(#20320,#10000,10,20,10,25) -hasLocation(#20319,#20320) -regexp_const_value(#20319,"module") +properties(#20318,#20316,0,0,"type: ""json""") +#20319=@"loc,{#10000},4,34,4,45" +locations_default(#20319,#10000,4,34,4,45) +hasLocation(#20318,#20319) +#20320=* +exprs(#20320,0,#20318,0,"type") +hasLocation(#20320,#20115) +enclosing_stmt(#20320,#20312) +expr_containers(#20320,#20001) +literals("type","type",#20320) #20321=* -stmts(#20321,27,#20001,8,"import ""module""") -#20322=@"loc,{#10000},12,1,12,15" -locations_default(#20322,#10000,12,1,12,15) -hasLocation(#20321,#20322) -stmt_containers(#20321,#20001) -#20323=* -exprs(#20323,4,#20321,-1,"""module""") -hasLocation(#20323,#20237) -enclosing_stmt(#20323,#20321) -expr_containers(#20323,#20001) -literals("module","""module""",#20323) +exprs(#20321,4,#20318,1,"""json""") +hasLocation(#20321,#20119) +enclosing_stmt(#20321,#20312) +expr_containers(#20321,#20001) +literals("json","""json""",#20321) +#20322=* +regexpterm(#20322,14,#20321,0,"json") +#20323=@"loc,{#10000},4,41,4,44" +locations_default(#20323,#10000,4,41,4,44) +hasLocation(#20322,#20323) +regexp_const_value(#20322,"json") #20324=* -regexpterm(#20324,14,#20323,0,"module") -#20325=@"loc,{#10000},12,9,12,14" -locations_default(#20325,#10000,12,9,12,14) -hasLocation(#20324,#20325) -regexp_const_value(#20324,"module") +exprs(#20324,84,#20312,0,"v3") +hasLocation(#20324,#20105) +enclosing_stmt(#20324,#20312) +expr_containers(#20324,#20001) +#20325=* +exprs(#20325,78,#20324,1,"v3") +hasLocation(#20325,#20105) +enclosing_stmt(#20325,#20312) +expr_containers(#20325,#20001) +literals("v3","v3",#20325) +decl(#20325,#20262) +typedecl(#20325,#20265) +namespacedecl(#20325,#20268) #20326=* -stmts(#20326,2,#20001,9,"assert( ... son""});") -#20327=@"loc,{#10000},13,1,13,23" -locations_default(#20327,#10000,13,1,13,23) -hasLocation(#20326,#20327) +stmts(#20326,30,#20001,4,"export ... son"" };") +hasLocation(#20326,#20017) stmt_containers(#20326,#20001) +#20327=* +exprs(#20327,4,#20326,-2,"""module""") +hasLocation(#20327,#20135) +enclosing_stmt(#20327,#20326) +expr_containers(#20327,#20001) +literals("module","""module""",#20327) #20328=* -exprs(#20328,13,#20326,0,"assert( ... json""})") -#20329=@"loc,{#10000},13,1,13,22" -locations_default(#20329,#10000,13,1,13,22) +regexpterm(#20328,14,#20327,0,"module") +#20329=@"loc,{#10000},6,21,6,26" +locations_default(#20329,#10000,6,21,6,26) hasLocation(#20328,#20329) -enclosing_stmt(#20328,#20326) -expr_containers(#20328,#20001) +regexp_const_value(#20328,"module") #20330=* -exprs(#20330,79,#20328,-1,"assert") -hasLocation(#20330,#20239) +exprs(#20330,8,#20326,-10,"{ type: ""json"" }") +#20331=@"loc,{#10000},6,36,6,51" +locations_default(#20331,#10000,6,36,6,51) +hasLocation(#20330,#20331) enclosing_stmt(#20330,#20326) expr_containers(#20330,#20001) -literals("assert","assert",#20330) -#20331=@"var;{assert};{#20000}" -variables(#20331,"assert",#20000) -bind(#20330,#20331) #20332=* -exprs(#20332,8,#20328,0,"{type: ""json""}") -#20333=@"loc,{#10000},13,8,13,21" -locations_default(#20333,#10000,13,8,13,21) +properties(#20332,#20330,0,0,"type: ""json""") +#20333=@"loc,{#10000},6,38,6,49" +locations_default(#20333,#10000,6,38,6,49) hasLocation(#20332,#20333) -enclosing_stmt(#20332,#20326) -expr_containers(#20332,#20001) #20334=* -properties(#20334,#20332,0,0,"type: ""json""") -#20335=@"loc,{#10000},13,9,13,20" -locations_default(#20335,#10000,13,9,13,20) -hasLocation(#20334,#20335) +exprs(#20334,0,#20332,0,"type") +hasLocation(#20334,#20141) +enclosing_stmt(#20334,#20326) +expr_containers(#20334,#20001) +literals("type","type",#20334) +#20335=* +exprs(#20335,4,#20332,1,"""json""") +hasLocation(#20335,#20145) +enclosing_stmt(#20335,#20326) +expr_containers(#20335,#20001) +literals("json","""json""",#20335) #20336=* -exprs(#20336,0,#20334,0,"type") -hasLocation(#20336,#20245) -enclosing_stmt(#20336,#20326) -expr_containers(#20336,#20001) -literals("type","type",#20336) -#20337=* -exprs(#20337,4,#20334,1,"""json""") -hasLocation(#20337,#20249) -enclosing_stmt(#20337,#20326) -expr_containers(#20337,#20001) -literals("json","""json""",#20337) +regexpterm(#20336,14,#20335,0,"json") +#20337=@"loc,{#10000},6,45,6,48" +locations_default(#20337,#10000,6,45,6,48) +hasLocation(#20336,#20337) +regexp_const_value(#20336,"json") #20338=* -regexpterm(#20338,14,#20337,0,"json") -#20339=@"loc,{#10000},13,16,13,19" -locations_default(#20339,#10000,13,16,13,19) -hasLocation(#20338,#20339) -regexp_const_value(#20338,"json") +exprs(#20338,86,#20326,0,"v4") +hasLocation(#20338,#20129) +enclosing_stmt(#20338,#20326) +expr_containers(#20338,#20001) +#20339=* +exprs(#20339,0,#20338,0,"v4") +hasLocation(#20339,#20129) +enclosing_stmt(#20339,#20326) +expr_containers(#20339,#20001) +literals("v4","v4",#20339) #20340=* -entry_cfg_node(#20340,#20001) -#20341=@"loc,{#10000},1,1,1,0" -locations_default(#20341,#10000,1,1,1,0) -hasLocation(#20340,#20341) +exprs(#20340,0,#20338,1,"v4") +hasLocation(#20340,#20129) +enclosing_stmt(#20340,#20326) +expr_containers(#20340,#20001) +literals("v4","v4",#20340) +#20341=* +stmts(#20341,28,#20001,5,"export ... son"" };") +hasLocation(#20341,#20019) +stmt_containers(#20341,#20001) #20342=* -exit_cfg_node(#20342,#20001) -hasLocation(#20342,#20257) -successor(#20326,#20330) -successor(#20332,#20336) -successor(#20337,#20334) -successor(#20336,#20337) -successor(#20334,#20328) -successor(#20330,#20332) -successor(#20328,#20342) -successor(#20321,#20326) -successor(#20312,#20315) -successor(#20318,#20316) -successor(#20316,#20313) -successor(#20315,#20318) -successor(#20313,#20321) -successor(#20305,#20306) -successor(#20309,#20311) -successor(#20311,#20312) -successor(#20306,#20309) -successor(#20301,#20302) -successor(#20302,#20305) -successor(#20294,#20295) -successor(#20298,#20299) -successor(#20300,#20301) -successor(#20299,#20300) -successor(#20295,#20298) -successor(#20288,#20294) -successor(#20281,#20288) -successor(#20274,#20281) -successor(#20270,#20274) -successor(#20292,#20270) -successor(#20285,#20292) -successor(#20278,#20285) -successor(#20340,#20278) +exprs(#20342,4,#20341,0,"""module""") +hasLocation(#20342,#20157) +enclosing_stmt(#20342,#20341) +expr_containers(#20342,#20001) +literals("module","""module""",#20342) +#20343=* +regexpterm(#20343,14,#20342,0,"module") +#20344=@"loc,{#10000},7,16,7,21" +locations_default(#20344,#10000,7,16,7,21) +hasLocation(#20343,#20344) +regexp_const_value(#20343,"module") +#20345=* +exprs(#20345,8,#20341,-10,"{ type: ""json"" }") +#20346=@"loc,{#10000},7,31,7,46" +locations_default(#20346,#10000,7,31,7,46) +hasLocation(#20345,#20346) +enclosing_stmt(#20345,#20341) +expr_containers(#20345,#20001) +#20347=* +properties(#20347,#20345,0,0,"type: ""json""") +#20348=@"loc,{#10000},7,33,7,44" +locations_default(#20348,#10000,7,33,7,44) +hasLocation(#20347,#20348) +#20349=* +exprs(#20349,0,#20347,0,"type") +hasLocation(#20349,#20163) +enclosing_stmt(#20349,#20341) +expr_containers(#20349,#20001) +literals("type","type",#20349) +#20350=* +exprs(#20350,4,#20347,1,"""json""") +hasLocation(#20350,#20167) +enclosing_stmt(#20350,#20341) +expr_containers(#20350,#20001) +literals("json","""json""",#20350) +#20351=* +regexpterm(#20351,14,#20350,0,"json") +#20352=@"loc,{#10000},7,40,7,43" +locations_default(#20352,#10000,7,40,7,43) +hasLocation(#20351,#20352) +regexp_const_value(#20351,"json") +#20353=* +stmts(#20353,30,#20001,6,"export ... son"" };") +hasLocation(#20353,#20021) +stmt_containers(#20353,#20001) +#20354=* +exprs(#20354,4,#20353,-2,"""module""") +hasLocation(#20354,#20183) +enclosing_stmt(#20354,#20353) +expr_containers(#20354,#20001) +literals("module","""module""",#20354) +#20355=* +regexpterm(#20355,14,#20354,0,"module") +#20356=@"loc,{#10000},8,22,8,27" +locations_default(#20356,#10000,8,22,8,27) +hasLocation(#20355,#20356) +regexp_const_value(#20355,"module") +#20357=* +exprs(#20357,8,#20353,-10,"{ type: ""json"" }") +#20358=@"loc,{#10000},8,37,8,52" +locations_default(#20358,#10000,8,37,8,52) +hasLocation(#20357,#20358) +enclosing_stmt(#20357,#20353) +expr_containers(#20357,#20001) +#20359=* +properties(#20359,#20357,0,0,"type: ""json""") +#20360=@"loc,{#10000},8,39,8,50" +locations_default(#20360,#10000,8,39,8,50) +hasLocation(#20359,#20360) +#20361=* +exprs(#20361,0,#20359,0,"type") +hasLocation(#20361,#20189) +enclosing_stmt(#20361,#20353) +expr_containers(#20361,#20001) +literals("type","type",#20361) +#20362=* +exprs(#20362,4,#20359,1,"""json""") +hasLocation(#20362,#20193) +enclosing_stmt(#20362,#20353) +expr_containers(#20362,#20001) +literals("json","""json""",#20362) +#20363=* +regexpterm(#20363,14,#20362,0,"json") +#20364=@"loc,{#10000},8,46,8,49" +locations_default(#20364,#10000,8,46,8,49) +hasLocation(#20363,#20364) +regexp_const_value(#20363,"json") +#20365=* +exprs(#20365,96,#20353,0,"* as v5") +#20366=@"loc,{#10000},8,8,8,14" +locations_default(#20366,#10000,8,8,8,14) +hasLocation(#20365,#20366) +enclosing_stmt(#20365,#20353) +expr_containers(#20365,#20001) +#20367=* +exprs(#20367,0,#20365,1,"v5") +hasLocation(#20367,#20179) +enclosing_stmt(#20367,#20353) +expr_containers(#20367,#20001) +literals("v5","v5",#20367) +#20368=* +stmts(#20368,22,#20001,7,"const v ... "" } });") +hasLocation(#20368,#20025) +stmt_containers(#20368,#20001) +#20369=* +exprs(#20369,64,#20368,0,"v6 = im ... n"" } })") +#20370=@"loc,{#10000},10,7,10,57" +locations_default(#20370,#10000,10,7,10,57) +hasLocation(#20369,#20370) +enclosing_stmt(#20369,#20368) +expr_containers(#20369,#20001) +#20371=* +exprs(#20371,78,#20369,0,"v6") +hasLocation(#20371,#20201) +enclosing_stmt(#20371,#20368) +expr_containers(#20371,#20001) +literals("v6","v6",#20371) +decl(#20371,#20269) +#20372=* +exprs(#20372,99,#20369,1,"import( ... n"" } })") +#20373=@"loc,{#10000},10,12,10,57" +locations_default(#20373,#10000,10,12,10,57) +hasLocation(#20372,#20373) +enclosing_stmt(#20372,#20368) +expr_containers(#20372,#20001) +#20374=* +exprs(#20374,4,#20372,0,"""module""") +hasLocation(#20374,#20209) +enclosing_stmt(#20374,#20368) +expr_containers(#20374,#20001) +literals("module","""module""",#20374) +#20375=* +regexpterm(#20375,14,#20374,0,"module") +#20376=@"loc,{#10000},10,20,10,25" +locations_default(#20376,#10000,10,20,10,25) +hasLocation(#20375,#20376) +regexp_const_value(#20375,"module") +#20377=* +exprs(#20377,8,#20372,1,"{ asser ... on"" } }") +#20378=@"loc,{#10000},10,29,10,56" +locations_default(#20378,#10000,10,29,10,56) +hasLocation(#20377,#20378) +enclosing_stmt(#20377,#20368) +expr_containers(#20377,#20001) +#20379=* +properties(#20379,#20377,0,0,"assert: ... json"" }") +#20380=@"loc,{#10000},10,31,10,54" +locations_default(#20380,#10000,10,31,10,54) +hasLocation(#20379,#20380) +#20381=* +exprs(#20381,0,#20379,0,"assert") +hasLocation(#20381,#20215) +enclosing_stmt(#20381,#20368) +expr_containers(#20381,#20001) +literals("assert","assert",#20381) +#20382=* +exprs(#20382,8,#20379,1,"{ type: ""json"" }") +#20383=@"loc,{#10000},10,39,10,54" +locations_default(#20383,#10000,10,39,10,54) +hasLocation(#20382,#20383) +enclosing_stmt(#20382,#20368) +expr_containers(#20382,#20001) +#20384=* +properties(#20384,#20382,0,0,"type: ""json""") +#20385=@"loc,{#10000},10,41,10,52" +locations_default(#20385,#10000,10,41,10,52) +hasLocation(#20384,#20385) +#20386=* +exprs(#20386,0,#20384,0,"type") +hasLocation(#20386,#20221) +enclosing_stmt(#20386,#20368) +expr_containers(#20386,#20001) +literals("type","type",#20386) +#20387=* +exprs(#20387,4,#20384,1,"""json""") +hasLocation(#20387,#20225) +enclosing_stmt(#20387,#20368) +expr_containers(#20387,#20001) +literals("json","""json""",#20387) +#20388=* +regexpterm(#20388,14,#20387,0,"json") +#20389=@"loc,{#10000},10,48,10,51" +locations_default(#20389,#10000,10,48,10,51) +hasLocation(#20388,#20389) +regexp_const_value(#20388,"json") +#20390=* +stmts(#20390,27,#20001,8,"import ""module""") +#20391=@"loc,{#10000},12,1,12,15" +locations_default(#20391,#10000,12,1,12,15) +hasLocation(#20390,#20391) +stmt_containers(#20390,#20001) +#20392=* +exprs(#20392,4,#20390,-1,"""module""") +hasLocation(#20392,#20237) +enclosing_stmt(#20392,#20390) +expr_containers(#20392,#20001) +literals("module","""module""",#20392) +#20393=* +regexpterm(#20393,14,#20392,0,"module") +#20394=@"loc,{#10000},12,9,12,14" +locations_default(#20394,#10000,12,9,12,14) +hasLocation(#20393,#20394) +regexp_const_value(#20393,"module") +#20395=* +stmts(#20395,2,#20001,9,"assert( ... son""});") +#20396=@"loc,{#10000},13,1,13,23" +locations_default(#20396,#10000,13,1,13,23) +hasLocation(#20395,#20396) +stmt_containers(#20395,#20001) +#20397=* +exprs(#20397,13,#20395,0,"assert( ... json""})") +#20398=@"loc,{#10000},13,1,13,22" +locations_default(#20398,#10000,13,1,13,22) +hasLocation(#20397,#20398) +enclosing_stmt(#20397,#20395) +expr_containers(#20397,#20001) +#20399=* +exprs(#20399,79,#20397,-1,"assert") +hasLocation(#20399,#20239) +enclosing_stmt(#20399,#20395) +expr_containers(#20399,#20001) +literals("assert","assert",#20399) +#20400=@"var;{assert};{#20000}" +variables(#20400,"assert",#20000) +bind(#20399,#20400) +#20401=* +exprs(#20401,8,#20397,0,"{type: ""json""}") +#20402=@"loc,{#10000},13,8,13,21" +locations_default(#20402,#10000,13,8,13,21) +hasLocation(#20401,#20402) +enclosing_stmt(#20401,#20395) +expr_containers(#20401,#20001) +#20403=* +properties(#20403,#20401,0,0,"type: ""json""") +#20404=@"loc,{#10000},13,9,13,20" +locations_default(#20404,#10000,13,9,13,20) +hasLocation(#20403,#20404) +#20405=* +exprs(#20405,0,#20403,0,"type") +hasLocation(#20405,#20245) +enclosing_stmt(#20405,#20395) +expr_containers(#20405,#20001) +literals("type","type",#20405) +#20406=* +exprs(#20406,4,#20403,1,"""json""") +hasLocation(#20406,#20249) +enclosing_stmt(#20406,#20395) +expr_containers(#20406,#20001) +literals("json","""json""",#20406) +#20407=* +regexpterm(#20407,14,#20406,0,"json") +#20408=@"loc,{#10000},13,16,13,19" +locations_default(#20408,#10000,13,16,13,19) +hasLocation(#20407,#20408) +regexp_const_value(#20407,"json") +#20409=* +entry_cfg_node(#20409,#20001) +#20410=@"loc,{#10000},1,1,1,0" +locations_default(#20410,#10000,1,1,1,0) +hasLocation(#20409,#20410) +#20411=* +exit_cfg_node(#20411,#20001) +hasLocation(#20411,#20257) +successor(#20395,#20399) +successor(#20401,#20405) +successor(#20406,#20403) +successor(#20405,#20406) +successor(#20403,#20397) +successor(#20399,#20401) +successor(#20397,#20411) +successor(#20390,#20395) +successor(#20368,#20371) +successor(#20374,#20372) +successor(#20372,#20369) +successor(#20371,#20374) +successor(#20369,#20390) +successor(#20353,#20354) +successor(#20365,#20367) +successor(#20367,#20368) +successor(#20354,#20365) +successor(#20341,#20342) +successor(#20342,#20353) +successor(#20326,#20327) +successor(#20338,#20339) +successor(#20340,#20341) +successor(#20339,#20340) +successor(#20327,#20338) +successor(#20312,#20326) +successor(#20297,#20312) +successor(#20282,#20297) +successor(#20270,#20282) +successor(#20324,#20270) +successor(#20309,#20324) +successor(#20294,#20309) +successor(#20409,#20294) numlines(#10000,13,10,2) filetype(#10000,"javascript") diff --git a/javascript/extractor/tests/ts/output/trap/import-assertion.ts.trap b/javascript/extractor/tests/ts/output/trap/import-assertion.ts.trap index d82dca7dee7..82d6671b171 100644 --- a/javascript/extractor/tests/ts/output/trap/import-assertion.ts.trap +++ b/javascript/extractor/tests/ts/output/trap/import-assertion.ts.trap @@ -726,392 +726,459 @@ locations_default(#20275,#10000,1,9,1,14) hasLocation(#20274,#20275) regexp_const_value(#20274,"module") #20276=* -stmts(#20276,27,#20001,1,"import ... son"" };") -hasLocation(#20276,#20009) -stmt_containers(#20276,#20001) -#20277=* -exprs(#20277,4,#20276,-1,"""module""") -hasLocation(#20277,#20061) -enclosing_stmt(#20277,#20276) -expr_containers(#20277,#20001) -literals("module","""module""",#20277) +exprs(#20276,8,#20272,-10,"assert ... json"" }") +#20277=@"loc,{#10000},1,17,1,39" +locations_default(#20277,#10000,1,17,1,39) +hasLocation(#20276,#20277) +enclosing_stmt(#20276,#20272) +expr_containers(#20276,#20001) #20278=* -regexpterm(#20278,14,#20277,0,"module") -#20279=@"loc,{#10000},2,22,2,27" -locations_default(#20279,#10000,2,22,2,27) +properties(#20278,#20276,0,0,"type: ""json""") +#20279=@"loc,{#10000},1,26,1,37" +locations_default(#20279,#10000,1,26,1,37) hasLocation(#20278,#20279) -regexp_const_value(#20278,"module") #20280=* -exprs(#20280,85,#20276,0,"* as v1") -#20281=@"loc,{#10000},2,8,2,14" -locations_default(#20281,#10000,2,8,2,14) -hasLocation(#20280,#20281) -enclosing_stmt(#20280,#20276) -expr_containers(#20280,#20001) +stmts(#20280,27,#20001,1,"import ... son"" };") +hasLocation(#20280,#20009) +stmt_containers(#20280,#20001) +#20281=* +exprs(#20281,4,#20280,-1,"""module""") +hasLocation(#20281,#20061) +enclosing_stmt(#20281,#20280) +expr_containers(#20281,#20001) +literals("module","""module""",#20281) #20282=* -exprs(#20282,78,#20280,1,"v1") -hasLocation(#20282,#20057) -enclosing_stmt(#20282,#20276) -expr_containers(#20282,#20001) -literals("v1","v1",#20282) -decl(#20282,#20262) -typedecl(#20282,#20265) -namespacedecl(#20282,#20268) -#20283=* -stmts(#20283,27,#20001,2,"import ... son"" };") -hasLocation(#20283,#20011) -stmt_containers(#20283,#20001) +regexpterm(#20282,14,#20281,0,"module") +#20283=@"loc,{#10000},2,22,2,27" +locations_default(#20283,#10000,2,22,2,27) +hasLocation(#20282,#20283) +regexp_const_value(#20282,"module") #20284=* -exprs(#20284,4,#20283,-1,"""module""") -hasLocation(#20284,#20087) -enclosing_stmt(#20284,#20283) +exprs(#20284,8,#20280,-10,"assert ... json"" }") +#20285=@"loc,{#10000},2,30,2,52" +locations_default(#20285,#10000,2,30,2,52) +hasLocation(#20284,#20285) +enclosing_stmt(#20284,#20280) expr_containers(#20284,#20001) -literals("module","""module""",#20284) -#20285=* -regexpterm(#20285,14,#20284,0,"module") -#20286=@"loc,{#10000},3,21,3,26" -locations_default(#20286,#10000,3,21,3,26) -hasLocation(#20285,#20286) -regexp_const_value(#20285,"module") -#20287=* -exprs(#20287,83,#20283,0,"v2") -hasLocation(#20287,#20081) -enclosing_stmt(#20287,#20283) -expr_containers(#20287,#20001) +#20286=* +properties(#20286,#20284,0,0,"type: ""json""") +#20287=@"loc,{#10000},2,39,2,50" +locations_default(#20287,#10000,2,39,2,50) +hasLocation(#20286,#20287) #20288=* -exprs(#20288,0,#20287,0,"v2") -hasLocation(#20288,#20081) -enclosing_stmt(#20288,#20283) +exprs(#20288,85,#20280,0,"* as v1") +#20289=@"loc,{#10000},2,8,2,14" +locations_default(#20289,#10000,2,8,2,14) +hasLocation(#20288,#20289) +enclosing_stmt(#20288,#20280) expr_containers(#20288,#20001) -literals("v2","v2",#20288) -#20289=* -exprs(#20289,78,#20287,1,"v2") -hasLocation(#20289,#20081) -enclosing_stmt(#20289,#20283) -expr_containers(#20289,#20001) -literals("v2","v2",#20289) -decl(#20289,#20263) -typedecl(#20289,#20266) -namespacedecl(#20289,#20269) #20290=* -stmts(#20290,27,#20001,3,"import ... son"" };") -hasLocation(#20290,#20013) -stmt_containers(#20290,#20001) +exprs(#20290,78,#20288,1,"v1") +hasLocation(#20290,#20057) +enclosing_stmt(#20290,#20280) +expr_containers(#20290,#20001) +literals("v1","v1",#20290) +decl(#20290,#20262) +typedecl(#20290,#20265) +namespacedecl(#20290,#20268) #20291=* -exprs(#20291,4,#20290,-1,"""module""") -hasLocation(#20291,#20109) -enclosing_stmt(#20291,#20290) -expr_containers(#20291,#20001) -literals("module","""module""",#20291) +stmts(#20291,27,#20001,2,"import ... son"" };") +hasLocation(#20291,#20011) +stmt_containers(#20291,#20001) #20292=* -regexpterm(#20292,14,#20291,0,"module") -#20293=@"loc,{#10000},4,17,4,22" -locations_default(#20293,#10000,4,17,4,22) -hasLocation(#20292,#20293) -regexp_const_value(#20292,"module") -#20294=* -exprs(#20294,84,#20290,0,"v3") -hasLocation(#20294,#20105) -enclosing_stmt(#20294,#20290) -expr_containers(#20294,#20001) +exprs(#20292,4,#20291,-1,"""module""") +hasLocation(#20292,#20087) +enclosing_stmt(#20292,#20291) +expr_containers(#20292,#20001) +literals("module","""module""",#20292) +#20293=* +regexpterm(#20293,14,#20292,0,"module") +#20294=@"loc,{#10000},3,21,3,26" +locations_default(#20294,#10000,3,21,3,26) +hasLocation(#20293,#20294) +regexp_const_value(#20293,"module") #20295=* -exprs(#20295,78,#20294,1,"v3") -hasLocation(#20295,#20105) -enclosing_stmt(#20295,#20290) +exprs(#20295,8,#20291,-10,"assert ... json"" }") +#20296=@"loc,{#10000},3,29,3,51" +locations_default(#20296,#10000,3,29,3,51) +hasLocation(#20295,#20296) +enclosing_stmt(#20295,#20291) expr_containers(#20295,#20001) -literals("v3","v3",#20295) -decl(#20295,#20264) -typedecl(#20295,#20267) -namespacedecl(#20295,#20270) -#20296=* -stmts(#20296,30,#20001,4,"export ... son"" };") -hasLocation(#20296,#20017) -stmt_containers(#20296,#20001) #20297=* -exprs(#20297,4,#20296,-2,"""module""") -hasLocation(#20297,#20135) -enclosing_stmt(#20297,#20296) -expr_containers(#20297,#20001) -literals("module","""module""",#20297) -#20298=* -regexpterm(#20298,14,#20297,0,"module") -#20299=@"loc,{#10000},6,21,6,26" -locations_default(#20299,#10000,6,21,6,26) -hasLocation(#20298,#20299) -regexp_const_value(#20298,"module") +properties(#20297,#20295,0,0,"type: ""json""") +#20298=@"loc,{#10000},3,38,3,49" +locations_default(#20298,#10000,3,38,3,49) +hasLocation(#20297,#20298) +#20299=* +exprs(#20299,83,#20291,0,"v2") +hasLocation(#20299,#20081) +enclosing_stmt(#20299,#20291) +expr_containers(#20299,#20001) #20300=* -exprs(#20300,86,#20296,0,"v4") -hasLocation(#20300,#20129) -enclosing_stmt(#20300,#20296) +exprs(#20300,0,#20299,0,"v2") +hasLocation(#20300,#20081) +enclosing_stmt(#20300,#20291) expr_containers(#20300,#20001) +literals("v2","v2",#20300) #20301=* -exprs(#20301,0,#20300,0,"v4") -hasLocation(#20301,#20129) -enclosing_stmt(#20301,#20296) +exprs(#20301,78,#20299,1,"v2") +hasLocation(#20301,#20081) +enclosing_stmt(#20301,#20291) expr_containers(#20301,#20001) -literals("v4","v4",#20301) +literals("v2","v2",#20301) +decl(#20301,#20263) +typedecl(#20301,#20266) +namespacedecl(#20301,#20269) #20302=* -exprs(#20302,0,#20300,1,"v4") -hasLocation(#20302,#20129) -enclosing_stmt(#20302,#20296) -expr_containers(#20302,#20001) -literals("v4","v4",#20302) +stmts(#20302,27,#20001,3,"import ... son"" };") +hasLocation(#20302,#20013) +stmt_containers(#20302,#20001) #20303=* -stmts(#20303,28,#20001,5,"export ... son"" };") -hasLocation(#20303,#20019) -stmt_containers(#20303,#20001) +exprs(#20303,4,#20302,-1,"""module""") +hasLocation(#20303,#20109) +enclosing_stmt(#20303,#20302) +expr_containers(#20303,#20001) +literals("module","""module""",#20303) #20304=* -exprs(#20304,4,#20303,0,"""module""") -hasLocation(#20304,#20157) -enclosing_stmt(#20304,#20303) -expr_containers(#20304,#20001) -literals("module","""module""",#20304) -#20305=* -regexpterm(#20305,14,#20304,0,"module") -#20306=@"loc,{#10000},7,16,7,21" -locations_default(#20306,#10000,7,16,7,21) -hasLocation(#20305,#20306) -regexp_const_value(#20305,"module") -#20307=* -stmts(#20307,30,#20001,6,"export ... son"" };") -hasLocation(#20307,#20021) -stmt_containers(#20307,#20001) +regexpterm(#20304,14,#20303,0,"module") +#20305=@"loc,{#10000},4,17,4,22" +locations_default(#20305,#10000,4,17,4,22) +hasLocation(#20304,#20305) +regexp_const_value(#20304,"module") +#20306=* +exprs(#20306,8,#20302,-10,"assert ... json"" }") +#20307=@"loc,{#10000},4,25,4,47" +locations_default(#20307,#10000,4,25,4,47) +hasLocation(#20306,#20307) +enclosing_stmt(#20306,#20302) +expr_containers(#20306,#20001) #20308=* -exprs(#20308,4,#20307,-2,"""module""") -hasLocation(#20308,#20183) -enclosing_stmt(#20308,#20307) -expr_containers(#20308,#20001) -literals("module","""module""",#20308) -#20309=* -regexpterm(#20309,14,#20308,0,"module") -#20310=@"loc,{#10000},8,22,8,27" -locations_default(#20310,#10000,8,22,8,27) -hasLocation(#20309,#20310) -regexp_const_value(#20309,"module") +properties(#20308,#20306,0,0,"type: ""json""") +#20309=@"loc,{#10000},4,34,4,45" +locations_default(#20309,#10000,4,34,4,45) +hasLocation(#20308,#20309) +#20310=* +exprs(#20310,84,#20302,0,"v3") +hasLocation(#20310,#20105) +enclosing_stmt(#20310,#20302) +expr_containers(#20310,#20001) #20311=* -exprs(#20311,96,#20307,0,"* as v5") -#20312=@"loc,{#10000},8,8,8,14" -locations_default(#20312,#10000,8,8,8,14) -hasLocation(#20311,#20312) -enclosing_stmt(#20311,#20307) +exprs(#20311,78,#20310,1,"v3") +hasLocation(#20311,#20105) +enclosing_stmt(#20311,#20302) expr_containers(#20311,#20001) +literals("v3","v3",#20311) +decl(#20311,#20264) +typedecl(#20311,#20267) +namespacedecl(#20311,#20270) +#20312=* +stmts(#20312,30,#20001,4,"export ... son"" };") +hasLocation(#20312,#20017) +stmt_containers(#20312,#20001) #20313=* -exprs(#20313,0,#20311,1,"v5") -hasLocation(#20313,#20179) -enclosing_stmt(#20313,#20307) +exprs(#20313,4,#20312,-2,"""module""") +hasLocation(#20313,#20135) +enclosing_stmt(#20313,#20312) expr_containers(#20313,#20001) -literals("v5","v5",#20313) +literals("module","""module""",#20313) #20314=* -stmts(#20314,22,#20001,7,"const v ... "" } });") -hasLocation(#20314,#20025) -stmt_containers(#20314,#20001) -#20315=* -exprs(#20315,64,#20314,0,"v6 = im ... n"" } })") -#20316=@"loc,{#10000},10,7,10,57" -locations_default(#20316,#10000,10,7,10,57) -hasLocation(#20315,#20316) -enclosing_stmt(#20315,#20314) -expr_containers(#20315,#20001) -#20317=* -exprs(#20317,78,#20315,0,"v6") -hasLocation(#20317,#20201) -enclosing_stmt(#20317,#20314) -expr_containers(#20317,#20001) -literals("v6","v6",#20317) -decl(#20317,#20271) +regexpterm(#20314,14,#20313,0,"module") +#20315=@"loc,{#10000},6,21,6,26" +locations_default(#20315,#10000,6,21,6,26) +hasLocation(#20314,#20315) +regexp_const_value(#20314,"module") +#20316=* +exprs(#20316,8,#20312,-10,"assert ... json"" }") +#20317=@"loc,{#10000},6,29,6,51" +locations_default(#20317,#10000,6,29,6,51) +hasLocation(#20316,#20317) +enclosing_stmt(#20316,#20312) +expr_containers(#20316,#20001) #20318=* -exprs(#20318,13,#20315,1,"import( ... n"" } })") -#20319=@"loc,{#10000},10,12,10,57" -locations_default(#20319,#10000,10,12,10,57) +properties(#20318,#20316,0,0,"type: ""json""") +#20319=@"loc,{#10000},6,38,6,49" +locations_default(#20319,#10000,6,38,6,49) hasLocation(#20318,#20319) -enclosing_stmt(#20318,#20314) -expr_containers(#20318,#20001) #20320=* -exprs(#20320,79,#20318,-1,"import") -hasLocation(#20320,#20205) -enclosing_stmt(#20320,#20314) +exprs(#20320,86,#20312,0,"v4") +hasLocation(#20320,#20129) +enclosing_stmt(#20320,#20312) expr_containers(#20320,#20001) -literals("import","import",#20320) -#20321=@"var;{import};{#20000}" -variables(#20321,"import",#20000) -bind(#20320,#20321) +#20321=* +exprs(#20321,0,#20320,0,"v4") +hasLocation(#20321,#20129) +enclosing_stmt(#20321,#20312) +expr_containers(#20321,#20001) +literals("v4","v4",#20321) #20322=* -exprs(#20322,4,#20318,0,"""module""") -hasLocation(#20322,#20209) -enclosing_stmt(#20322,#20314) +exprs(#20322,0,#20320,1,"v4") +hasLocation(#20322,#20129) +enclosing_stmt(#20322,#20312) expr_containers(#20322,#20001) -literals("module","""module""",#20322) +literals("v4","v4",#20322) #20323=* -regexpterm(#20323,14,#20322,0,"module") -#20324=@"loc,{#10000},10,20,10,25" -locations_default(#20324,#10000,10,20,10,25) -hasLocation(#20323,#20324) -regexp_const_value(#20323,"module") +stmts(#20323,28,#20001,5,"export ... son"" };") +hasLocation(#20323,#20019) +stmt_containers(#20323,#20001) +#20324=* +exprs(#20324,4,#20323,0,"""module""") +hasLocation(#20324,#20157) +enclosing_stmt(#20324,#20323) +expr_containers(#20324,#20001) +literals("module","""module""",#20324) #20325=* -exprs(#20325,8,#20318,1,"{ asser ... on"" } }") -#20326=@"loc,{#10000},10,29,10,56" -locations_default(#20326,#10000,10,29,10,56) +regexpterm(#20325,14,#20324,0,"module") +#20326=@"loc,{#10000},7,16,7,21" +locations_default(#20326,#10000,7,16,7,21) hasLocation(#20325,#20326) -enclosing_stmt(#20325,#20314) -expr_containers(#20325,#20001) +regexp_const_value(#20325,"module") #20327=* -properties(#20327,#20325,0,0,"assert: ... json"" }") -#20328=@"loc,{#10000},10,31,10,54" -locations_default(#20328,#10000,10,31,10,54) +exprs(#20327,8,#20323,-10,"assert ... json"" }") +#20328=@"loc,{#10000},7,24,7,46" +locations_default(#20328,#10000,7,24,7,46) hasLocation(#20327,#20328) +enclosing_stmt(#20327,#20323) +expr_containers(#20327,#20001) #20329=* -exprs(#20329,0,#20327,0,"assert") -hasLocation(#20329,#20215) -enclosing_stmt(#20329,#20314) -expr_containers(#20329,#20001) -literals("assert","assert",#20329) -#20330=* -exprs(#20330,8,#20327,1,"{ type: ""json"" }") -#20331=@"loc,{#10000},10,39,10,54" -locations_default(#20331,#10000,10,39,10,54) -hasLocation(#20330,#20331) -enclosing_stmt(#20330,#20314) -expr_containers(#20330,#20001) +properties(#20329,#20327,0,0,"type: ""json""") +#20330=@"loc,{#10000},7,33,7,44" +locations_default(#20330,#10000,7,33,7,44) +hasLocation(#20329,#20330) +#20331=* +stmts(#20331,30,#20001,6,"export ... son"" };") +hasLocation(#20331,#20021) +stmt_containers(#20331,#20001) #20332=* -properties(#20332,#20330,0,0,"type: ""json""") -#20333=@"loc,{#10000},10,41,10,52" -locations_default(#20333,#10000,10,41,10,52) -hasLocation(#20332,#20333) -#20334=* -exprs(#20334,0,#20332,0,"type") -hasLocation(#20334,#20221) -enclosing_stmt(#20334,#20314) -expr_containers(#20334,#20001) -literals("type","type",#20334) +exprs(#20332,4,#20331,-2,"""module""") +hasLocation(#20332,#20183) +enclosing_stmt(#20332,#20331) +expr_containers(#20332,#20001) +literals("module","""module""",#20332) +#20333=* +regexpterm(#20333,14,#20332,0,"module") +#20334=@"loc,{#10000},8,22,8,27" +locations_default(#20334,#10000,8,22,8,27) +hasLocation(#20333,#20334) +regexp_const_value(#20333,"module") #20335=* -exprs(#20335,4,#20332,1,"""json""") -hasLocation(#20335,#20225) -enclosing_stmt(#20335,#20314) +exprs(#20335,8,#20331,-10,"assert ... json"" }") +#20336=@"loc,{#10000},8,30,8,52" +locations_default(#20336,#10000,8,30,8,52) +hasLocation(#20335,#20336) +enclosing_stmt(#20335,#20331) expr_containers(#20335,#20001) -literals("json","""json""",#20335) -#20336=* -regexpterm(#20336,14,#20335,0,"json") -#20337=@"loc,{#10000},10,48,10,51" -locations_default(#20337,#10000,10,48,10,51) -hasLocation(#20336,#20337) -regexp_const_value(#20336,"json") -#20338=* -stmts(#20338,27,#20001,8,"import ""module"";") -#20339=@"loc,{#10000},12,1,12,16" -locations_default(#20339,#10000,12,1,12,16) -hasLocation(#20338,#20339) -stmt_containers(#20338,#20001) -#20340=* -exprs(#20340,4,#20338,-1,"""module""") -hasLocation(#20340,#20237) -enclosing_stmt(#20340,#20338) -expr_containers(#20340,#20001) -literals("module","""module""",#20340) +#20337=* +properties(#20337,#20335,0,0,"type: ""json""") +#20338=@"loc,{#10000},8,39,8,50" +locations_default(#20338,#10000,8,39,8,50) +hasLocation(#20337,#20338) +#20339=* +exprs(#20339,96,#20331,0,"* as v5") +#20340=@"loc,{#10000},8,8,8,14" +locations_default(#20340,#10000,8,8,8,14) +hasLocation(#20339,#20340) +enclosing_stmt(#20339,#20331) +expr_containers(#20339,#20001) #20341=* -regexpterm(#20341,14,#20340,0,"module") -#20342=@"loc,{#10000},12,9,12,14" -locations_default(#20342,#10000,12,9,12,14) -hasLocation(#20341,#20342) -regexp_const_value(#20341,"module") +exprs(#20341,0,#20339,1,"v5") +hasLocation(#20341,#20179) +enclosing_stmt(#20341,#20331) +expr_containers(#20341,#20001) +literals("v5","v5",#20341) +#20342=* +stmts(#20342,22,#20001,7,"const v ... "" } });") +hasLocation(#20342,#20025) +stmt_containers(#20342,#20001) #20343=* -stmts(#20343,2,#20001,9,"assert( ... on"" });") -#20344=@"loc,{#10000},13,1,13,25" -locations_default(#20344,#10000,13,1,13,25) +exprs(#20343,64,#20342,0,"v6 = im ... n"" } })") +#20344=@"loc,{#10000},10,7,10,57" +locations_default(#20344,#10000,10,7,10,57) hasLocation(#20343,#20344) -stmt_containers(#20343,#20001) +enclosing_stmt(#20343,#20342) +expr_containers(#20343,#20001) #20345=* -exprs(#20345,13,#20343,0,"assert( ... son"" })") -#20346=@"loc,{#10000},13,1,13,24" -locations_default(#20346,#10000,13,1,13,24) -hasLocation(#20345,#20346) -enclosing_stmt(#20345,#20343) +exprs(#20345,78,#20343,0,"v6") +hasLocation(#20345,#20201) +enclosing_stmt(#20345,#20342) expr_containers(#20345,#20001) -#20347=* -exprs(#20347,79,#20345,-1,"assert") -hasLocation(#20347,#20241) -enclosing_stmt(#20347,#20343) -expr_containers(#20347,#20001) -literals("assert","assert",#20347) -#20348=@"var;{assert};{#20000}" -variables(#20348,"assert",#20000) -bind(#20347,#20348) +literals("v6","v6",#20345) +decl(#20345,#20271) +#20346=* +exprs(#20346,99,#20343,1,"import( ... n"" } })") +#20347=@"loc,{#10000},10,12,10,57" +locations_default(#20347,#10000,10,12,10,57) +hasLocation(#20346,#20347) +enclosing_stmt(#20346,#20342) +expr_containers(#20346,#20001) +#20348=* +exprs(#20348,4,#20346,0,"""module""") +hasLocation(#20348,#20209) +enclosing_stmt(#20348,#20342) +expr_containers(#20348,#20001) +literals("module","""module""",#20348) #20349=* -exprs(#20349,8,#20345,0,"{ type: ""json"" }") -#20350=@"loc,{#10000},13,8,13,23" -locations_default(#20350,#10000,13,8,13,23) +regexpterm(#20349,14,#20348,0,"module") +#20350=@"loc,{#10000},10,20,10,25" +locations_default(#20350,#10000,10,20,10,25) hasLocation(#20349,#20350) -enclosing_stmt(#20349,#20343) -expr_containers(#20349,#20001) +regexp_const_value(#20349,"module") #20351=* -properties(#20351,#20349,0,0,"type: ""json""") -#20352=@"loc,{#10000},13,10,13,21" -locations_default(#20352,#10000,13,10,13,21) +exprs(#20351,8,#20346,1,"{ asser ... on"" } }") +#20352=@"loc,{#10000},10,29,10,56" +locations_default(#20352,#10000,10,29,10,56) hasLocation(#20351,#20352) +enclosing_stmt(#20351,#20342) +expr_containers(#20351,#20001) #20353=* -exprs(#20353,0,#20351,0,"type") -hasLocation(#20353,#20247) -enclosing_stmt(#20353,#20343) -expr_containers(#20353,#20001) -literals("type","type",#20353) -#20354=* -exprs(#20354,4,#20351,1,"""json""") -hasLocation(#20354,#20251) -enclosing_stmt(#20354,#20343) -expr_containers(#20354,#20001) -literals("json","""json""",#20354) +properties(#20353,#20351,0,0,"assert: ... json"" }") +#20354=@"loc,{#10000},10,31,10,54" +locations_default(#20354,#10000,10,31,10,54) +hasLocation(#20353,#20354) #20355=* -regexpterm(#20355,14,#20354,0,"json") -#20356=@"loc,{#10000},13,17,13,20" -locations_default(#20356,#10000,13,17,13,20) -hasLocation(#20355,#20356) -regexp_const_value(#20355,"json") -#20357=* -entry_cfg_node(#20357,#20001) -#20358=@"loc,{#10000},1,1,1,0" -locations_default(#20358,#10000,1,1,1,0) -hasLocation(#20357,#20358) -#20359=* -exit_cfg_node(#20359,#20001) -hasLocation(#20359,#20259) -successor(#20343,#20347) -successor(#20349,#20353) -successor(#20354,#20351) -successor(#20353,#20354) -successor(#20351,#20345) -successor(#20347,#20349) -successor(#20345,#20359) -successor(#20338,#20343) -successor(#20314,#20317) -successor(#20325,#20329) -successor(#20330,#20334) -successor(#20335,#20332) -successor(#20334,#20335) -successor(#20332,#20327) -successor(#20329,#20330) -successor(#20327,#20318) -successor(#20322,#20325) -successor(#20320,#20322) -successor(#20318,#20315) -successor(#20317,#20320) -successor(#20315,#20338) -successor(#20307,#20308) -successor(#20311,#20313) -successor(#20313,#20314) -successor(#20308,#20311) -successor(#20303,#20304) -successor(#20304,#20307) -successor(#20296,#20297) -successor(#20300,#20301) -successor(#20302,#20303) -successor(#20301,#20302) -successor(#20297,#20300) -successor(#20290,#20296) -successor(#20283,#20290) -successor(#20276,#20283) -successor(#20272,#20276) -successor(#20294,#20272) -successor(#20287,#20294) -successor(#20280,#20287) -successor(#20357,#20280) +exprs(#20355,0,#20353,0,"assert") +hasLocation(#20355,#20215) +enclosing_stmt(#20355,#20342) +expr_containers(#20355,#20001) +literals("assert","assert",#20355) +#20356=* +exprs(#20356,8,#20353,1,"{ type: ""json"" }") +#20357=@"loc,{#10000},10,39,10,54" +locations_default(#20357,#10000,10,39,10,54) +hasLocation(#20356,#20357) +enclosing_stmt(#20356,#20342) +expr_containers(#20356,#20001) +#20358=* +properties(#20358,#20356,0,0,"type: ""json""") +#20359=@"loc,{#10000},10,41,10,52" +locations_default(#20359,#10000,10,41,10,52) +hasLocation(#20358,#20359) +#20360=* +exprs(#20360,0,#20358,0,"type") +hasLocation(#20360,#20221) +enclosing_stmt(#20360,#20342) +expr_containers(#20360,#20001) +literals("type","type",#20360) +#20361=* +exprs(#20361,4,#20358,1,"""json""") +hasLocation(#20361,#20225) +enclosing_stmt(#20361,#20342) +expr_containers(#20361,#20001) +literals("json","""json""",#20361) +#20362=* +regexpterm(#20362,14,#20361,0,"json") +#20363=@"loc,{#10000},10,48,10,51" +locations_default(#20363,#10000,10,48,10,51) +hasLocation(#20362,#20363) +regexp_const_value(#20362,"json") +#20364=* +stmts(#20364,27,#20001,8,"import ""module"";") +#20365=@"loc,{#10000},12,1,12,16" +locations_default(#20365,#10000,12,1,12,16) +hasLocation(#20364,#20365) +stmt_containers(#20364,#20001) +#20366=* +exprs(#20366,4,#20364,-1,"""module""") +hasLocation(#20366,#20237) +enclosing_stmt(#20366,#20364) +expr_containers(#20366,#20001) +literals("module","""module""",#20366) +#20367=* +regexpterm(#20367,14,#20366,0,"module") +#20368=@"loc,{#10000},12,9,12,14" +locations_default(#20368,#10000,12,9,12,14) +hasLocation(#20367,#20368) +regexp_const_value(#20367,"module") +#20369=* +stmts(#20369,2,#20001,9,"assert( ... on"" });") +#20370=@"loc,{#10000},13,1,13,25" +locations_default(#20370,#10000,13,1,13,25) +hasLocation(#20369,#20370) +stmt_containers(#20369,#20001) +#20371=* +exprs(#20371,13,#20369,0,"assert( ... son"" })") +#20372=@"loc,{#10000},13,1,13,24" +locations_default(#20372,#10000,13,1,13,24) +hasLocation(#20371,#20372) +enclosing_stmt(#20371,#20369) +expr_containers(#20371,#20001) +#20373=* +exprs(#20373,79,#20371,-1,"assert") +hasLocation(#20373,#20241) +enclosing_stmt(#20373,#20369) +expr_containers(#20373,#20001) +literals("assert","assert",#20373) +#20374=@"var;{assert};{#20000}" +variables(#20374,"assert",#20000) +bind(#20373,#20374) +#20375=* +exprs(#20375,8,#20371,0,"{ type: ""json"" }") +#20376=@"loc,{#10000},13,8,13,23" +locations_default(#20376,#10000,13,8,13,23) +hasLocation(#20375,#20376) +enclosing_stmt(#20375,#20369) +expr_containers(#20375,#20001) +#20377=* +properties(#20377,#20375,0,0,"type: ""json""") +#20378=@"loc,{#10000},13,10,13,21" +locations_default(#20378,#10000,13,10,13,21) +hasLocation(#20377,#20378) +#20379=* +exprs(#20379,0,#20377,0,"type") +hasLocation(#20379,#20247) +enclosing_stmt(#20379,#20369) +expr_containers(#20379,#20001) +literals("type","type",#20379) +#20380=* +exprs(#20380,4,#20377,1,"""json""") +hasLocation(#20380,#20251) +enclosing_stmt(#20380,#20369) +expr_containers(#20380,#20001) +literals("json","""json""",#20380) +#20381=* +regexpterm(#20381,14,#20380,0,"json") +#20382=@"loc,{#10000},13,17,13,20" +locations_default(#20382,#10000,13,17,13,20) +hasLocation(#20381,#20382) +regexp_const_value(#20381,"json") +#20383=* +entry_cfg_node(#20383,#20001) +#20384=@"loc,{#10000},1,1,1,0" +locations_default(#20384,#10000,1,1,1,0) +hasLocation(#20383,#20384) +#20385=* +exit_cfg_node(#20385,#20001) +hasLocation(#20385,#20259) +successor(#20369,#20373) +successor(#20375,#20379) +successor(#20380,#20377) +successor(#20379,#20380) +successor(#20377,#20371) +successor(#20373,#20375) +successor(#20371,#20385) +successor(#20364,#20369) +successor(#20342,#20345) +successor(#20348,#20346) +successor(#20346,#20343) +successor(#20345,#20348) +successor(#20343,#20364) +successor(#20331,#20332) +successor(#20339,#20341) +successor(#20341,#20342) +successor(#20332,#20339) +successor(#20323,#20324) +successor(#20324,#20331) +successor(#20312,#20313) +successor(#20320,#20321) +successor(#20322,#20323) +successor(#20321,#20322) +successor(#20313,#20320) +successor(#20302,#20312) +successor(#20291,#20302) +successor(#20280,#20291) +successor(#20272,#20280) +successor(#20310,#20272) +successor(#20299,#20310) +successor(#20288,#20299) +successor(#20383,#20288) numlines(#10000,13,10,2) filetype(#10000,"typescript") diff --git a/javascript/ql/lib/semmle/javascript/ES2015Modules.qll b/javascript/ql/lib/semmle/javascript/ES2015Modules.qll index f6e759b87e7..535d2317aa3 100644 --- a/javascript/ql/lib/semmle/javascript/ES2015Modules.qll +++ b/javascript/ql/lib/semmle/javascript/ES2015Modules.qll @@ -90,6 +90,16 @@ class ImportDeclaration extends Stmt, Import, @import_declaration { override PathExpr getImportedPath() { result = getChildExpr(-1) } + /** + * Gets the object literal passed as part of the `assert` clause in this import declaration. + * + * For example, this gets the `{ type: "json" }` object literal in the following: + * ```js + * import foo from "foo" assert { type: "json" }; + * ``` + */ + ObjectExpr getImportAssertion() { result = getChildExpr(-10) } + /** Gets the `i`th import specifier of this import declaration. */ ImportSpecifier getSpecifier(int i) { result = getChildExpr(i) } @@ -310,6 +320,19 @@ abstract class ExportDeclaration extends Stmt, @export_declaration { predicate isTypeOnly() { has_type_keyword(this) } override string getAPrimaryQlClass() { result = "ExportDeclaration" } + + /** + * Gets the object literal passed as part of the `assert` clause, if this is + * a re-export declaration. + * + * For example, this gets the `{ type: "json" }` expression in each of the following: + * ```js + * export { x } from 'foo' assert { type: "json" }; + * export * from 'foo' assert { type: "json" }; + * export * as x from 'foo' assert { type: "json" }; + * ``` + */ + ObjectExpr getImportAssertion() { result = this.getChildExpr(-10) } } /** diff --git a/javascript/ql/lib/semmle/javascript/Expr.qll b/javascript/ql/lib/semmle/javascript/Expr.qll index 925352cacad..aa1b19e0ab9 100644 --- a/javascript/ql/lib/semmle/javascript/Expr.qll +++ b/javascript/ql/lib/semmle/javascript/Expr.qll @@ -2807,6 +2807,7 @@ class FunctionBindExpr extends @bind_expr, Expr { * * ``` * import("fs") + * import("foo", { assert: { type: "json" }}) * ``` */ class DynamicImportExpr extends @dynamic_import, Expr, Import { @@ -2819,6 +2820,16 @@ class DynamicImportExpr extends @dynamic_import, Expr, Import { override PathExpr getImportedPath() { result = this.getSource() } + /** + * Gets the second "argument" to the import expression, that is, the `Y` in `import(X, Y)`. + * + * For example, gets the `{ assert: { type: "json" }}` expression in the following: + * ```js + * import('foo', { assert: { type: "json" }}) + * ``` + */ + Expr getImportAttributes() { result = this.getChildExpr(1) } + override Module getEnclosingModule() { result = this.getTopLevel() } override DataFlow::Node getImportedModuleNode() { result = DataFlow::valueNode(this) } diff --git a/javascript/ql/test/library-tests/TypeScript/ImportAssertions/js-import-assertions.js b/javascript/ql/test/library-tests/TypeScript/ImportAssertions/js-import-assertions.js new file mode 100644 index 00000000000..23c030be511 --- /dev/null +++ b/javascript/ql/test/library-tests/TypeScript/ImportAssertions/js-import-assertions.js @@ -0,0 +1,13 @@ +import "module" assert { type: "json" }; +import * as v1 from "module" assert { type: "json" }; +import { v2 } from "module" assert { type: "json" }; +import v3 from "module" assert { type: "json" }; + +export { v4 } from "module" assert { type: "json" }; +export * from "module" assert { type: "json" }; +export * as v5 from "module" assert { type: "json" }; + +const v6 = import("module", { assert: { type: "json" } }); + +import "module" // missing semicolon +assert({type: "json"}); // function call, not import assertion diff --git a/javascript/ql/test/library-tests/TypeScript/ImportAssertions/test.expected b/javascript/ql/test/library-tests/TypeScript/ImportAssertions/test.expected new file mode 100644 index 00000000000..330f034c7c9 --- /dev/null +++ b/javascript/ql/test/library-tests/TypeScript/ImportAssertions/test.expected @@ -0,0 +1,20 @@ +getImportAssertionFromImport +| js-import-assertions.js:1:1:1:40 | import ... son" }; | js-import-assertions.js:1:24:1:39 | { type: "json" } | +| js-import-assertions.js:2:1:2:53 | import ... son" }; | js-import-assertions.js:2:37:2:52 | { type: "json" } | +| js-import-assertions.js:3:1:3:52 | import ... son" }; | js-import-assertions.js:3:36:3:51 | { type: "json" } | +| js-import-assertions.js:4:1:4:48 | import ... son" }; | js-import-assertions.js:4:32:4:47 | { type: "json" } | +| ts-import-assertions.ts:3:1:3:40 | import ... son" }; | ts-import-assertions.ts:3:17:3:39 | assert ... json" } | +| ts-import-assertions.ts:4:1:4:53 | import ... son" }; | ts-import-assertions.ts:4:30:4:52 | assert ... json" } | +| ts-import-assertions.ts:5:1:5:52 | import ... son" }; | ts-import-assertions.ts:5:29:5:51 | assert ... json" } | +| ts-import-assertions.ts:6:1:6:48 | import ... son" }; | ts-import-assertions.ts:6:25:6:47 | assert ... json" } | +getImportAssertionFromExport +| js-import-assertions.js:6:1:6:52 | export ... son" }; | js-import-assertions.js:6:36:6:51 | { type: "json" } | +| js-import-assertions.js:7:1:7:47 | export ... son" }; | js-import-assertions.js:7:31:7:46 | { type: "json" } | +| js-import-assertions.js:8:1:8:53 | export ... son" }; | js-import-assertions.js:8:37:8:52 | { type: "json" } | +| ts-import-assertions.ts:8:1:8:52 | export ... son" }; | ts-import-assertions.ts:8:29:8:51 | assert ... json" } | +| ts-import-assertions.ts:9:1:9:47 | export ... son" }; | ts-import-assertions.ts:9:24:9:46 | assert ... json" } | +| ts-import-assertions.ts:10:1:10:53 | export ... son" }; | ts-import-assertions.ts:10:30:10:52 | assert ... json" } | +getImportAttributes +| js-import-assertions.js:10:12:10:57 | import( ... n" } }) | js-import-assertions.js:10:29:10:56 | { asser ... on" } } | +| ts-import-assertions.ts:12:12:12:57 | import( ... n" } }) | ts-import-assertions.ts:12:29:12:56 | { asser ... on" } } | +errors diff --git a/javascript/ql/test/library-tests/TypeScript/ImportAssertions/test.ql b/javascript/ql/test/library-tests/TypeScript/ImportAssertions/test.ql new file mode 100644 index 00000000000..d7017a652ef --- /dev/null +++ b/javascript/ql/test/library-tests/TypeScript/ImportAssertions/test.ql @@ -0,0 +1,13 @@ +import javascript + +query Expr getImportAssertionFromImport(ImportDeclaration decl) { + result = decl.getImportAssertion() +} + +query Expr getImportAssertionFromExport(ExportDeclaration decl) { + result = decl.getImportAssertion() +} + +query Expr getImportAttributes(DynamicImportExpr imprt) { result = imprt.getImportAttributes() } + +query JSParseError errors() { any() } diff --git a/javascript/ql/test/library-tests/TypeScript/ImportAssertions/ts-import-assertions.ts b/javascript/ql/test/library-tests/TypeScript/ImportAssertions/ts-import-assertions.ts new file mode 100644 index 00000000000..5d46b200f54 --- /dev/null +++ b/javascript/ql/test/library-tests/TypeScript/ImportAssertions/ts-import-assertions.ts @@ -0,0 +1,15 @@ +// TypeScript + +import "module" assert { type: "json" }; +import * as v1 from "module" assert { type: "json" }; +import { v2 } from "module" assert { type: "json" }; +import v3 from "module" assert { type: "json" }; + +export { v4 } from "module" assert { type: "json" }; +export * from "module" assert { type: "json" }; +export * as v5 from "module" assert { type: "json" }; + +const v6 = import("module", { assert: { type: "json" } }); + +import "module" // missing semicolon +assert({ type: "json" }); // function call, not import assertion