From 6ecdb0edd57c69be72cee6b9fa1b1e9098f9b8f4 Mon Sep 17 00:00:00 2001 From: Max Schaefer Date: Wed, 27 Feb 2019 08:53:01 +0000 Subject: [PATCH] JavaScript: Allow first expression in array literal to be an `in` expression. --- .../src/com/semmle/jcorn/CustomParser.java | 2 +- .../src/com/semmle/js/extractor/Main.java | 2 +- .../extractor/tests/e4x/input/regress.js | 1 + .../tests/e4x/output/trap/regress.js.trap | 103 ++++++++++++++++++ 4 files changed, 106 insertions(+), 2 deletions(-) create mode 100644 javascript/extractor/tests/e4x/input/regress.js create mode 100644 javascript/extractor/tests/e4x/output/trap/regress.js.trap diff --git a/javascript/extractor/src/com/semmle/jcorn/CustomParser.java b/javascript/extractor/src/com/semmle/jcorn/CustomParser.java index 32704af783d..188a6183af7 100644 --- a/javascript/extractor/src/com/semmle/jcorn/CustomParser.java +++ b/javascript/extractor/src/com/semmle/jcorn/CustomParser.java @@ -147,7 +147,7 @@ public class CustomParser extends FlowParser { this.type == TokenType.ellipsis) { elements = this.parseExprList(TokenType.bracketR, true, true, refDestructuringErrors); } else { - Expression firstExpr = this.parseMaybeAssign(true, refDestructuringErrors, null); + Expression firstExpr = this.parseMaybeAssign(false, refDestructuringErrors, null); // check whether this is a postfix array comprehension if (this.type == TokenType._for || this.type == TokenType._if) { ComprehensionExpression c = this.parseComprehension(startLoc, false, firstExpr); diff --git a/javascript/extractor/src/com/semmle/js/extractor/Main.java b/javascript/extractor/src/com/semmle/js/extractor/Main.java index 45bf81fb1f2..8688f6744ea 100644 --- a/javascript/extractor/src/com/semmle/js/extractor/Main.java +++ b/javascript/extractor/src/com/semmle/js/extractor/Main.java @@ -41,7 +41,7 @@ public class Main { * such a way that it may produce different tuples for the same file under the same * {@link ExtractorConfig}. */ - public static final String EXTRACTOR_VERSION = "2019-02-04"; + public static final String EXTRACTOR_VERSION = "2019-02-27"; public static final Pattern NEWLINE = Pattern.compile("\n"); diff --git a/javascript/extractor/tests/e4x/input/regress.js b/javascript/extractor/tests/e4x/input/regress.js new file mode 100644 index 00000000000..58c99875beb --- /dev/null +++ b/javascript/extractor/tests/e4x/input/regress.js @@ -0,0 +1 @@ +[ x in y ] diff --git a/javascript/extractor/tests/e4x/output/trap/regress.js.trap b/javascript/extractor/tests/e4x/output/trap/regress.js.trap new file mode 100644 index 00000000000..39a8c3867fc --- /dev/null +++ b/javascript/extractor/tests/e4x/output/trap/regress.js.trap @@ -0,0 +1,103 @@ +#10000=@"/regress.js;sourcefile" +files(#10000,"/regress.js","regress","js",0) +#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=* +lines(#20002,#20001,"[ x in y ]"," +") +#20003=@"loc,{#10000},1,1,1,10" +locations_default(#20003,#10000,1,1,1,10) +hasLocation(#20002,#20003) +numlines(#20001,1,1,0) +#20004=* +tokeninfo(#20004,8,#20001,0,"[") +#20005=@"loc,{#10000},1,1,1,1" +locations_default(#20005,#10000,1,1,1,1) +hasLocation(#20004,#20005) +#20006=* +tokeninfo(#20006,6,#20001,1,"x") +#20007=@"loc,{#10000},1,3,1,3" +locations_default(#20007,#10000,1,3,1,3) +hasLocation(#20006,#20007) +#20008=* +tokeninfo(#20008,7,#20001,2,"in") +#20009=@"loc,{#10000},1,5,1,6" +locations_default(#20009,#10000,1,5,1,6) +hasLocation(#20008,#20009) +#20010=* +tokeninfo(#20010,6,#20001,3,"y") +#20011=@"loc,{#10000},1,8,1,8" +locations_default(#20011,#10000,1,8,1,8) +hasLocation(#20010,#20011) +#20012=* +tokeninfo(#20012,8,#20001,4,"]") +#20013=@"loc,{#10000},1,10,1,10" +locations_default(#20013,#10000,1,10,1,10) +hasLocation(#20012,#20013) +#20014=* +tokeninfo(#20014,0,#20001,5,"") +#20015=@"loc,{#10000},2,1,2,0" +locations_default(#20015,#10000,2,1,2,0) +hasLocation(#20014,#20015) +toplevels(#20001,0) +#20016=@"loc,{#10000},1,1,2,0" +locations_default(#20016,#10000,1,1,2,0) +hasLocation(#20001,#20016) +#20017=* +stmts(#20017,2,#20001,0,"[ x in y ]") +hasLocation(#20017,#20003) +stmtContainers(#20017,#20001) +#20018=* +exprs(#20018,7,#20017,0,"[ x in y ]") +hasLocation(#20018,#20003) +enclosingStmt(#20018,#20017) +exprContainers(#20018,#20001) +#20019=* +exprs(#20019,42,#20018,0,"x in y") +#20020=@"loc,{#10000},1,3,1,8" +locations_default(#20020,#10000,1,3,1,8) +hasLocation(#20019,#20020) +enclosingStmt(#20019,#20017) +exprContainers(#20019,#20001) +#20021=* +exprs(#20021,79,#20019,0,"x") +hasLocation(#20021,#20007) +enclosingStmt(#20021,#20017) +exprContainers(#20021,#20001) +literals("x","x",#20021) +#20022=@"var;{x};{#20000}" +variables(#20022,"x",#20000) +bind(#20021,#20022) +#20023=* +exprs(#20023,79,#20019,1,"y") +hasLocation(#20023,#20011) +enclosingStmt(#20023,#20017) +exprContainers(#20023,#20001) +literals("y","y",#20023) +#20024=@"var;{y};{#20000}" +variables(#20024,"y",#20000) +bind(#20023,#20024) +arraySize(#20018,1) +#20025=* +entry_cfg_node(#20025,#20001) +#20026=@"loc,{#10000},1,1,1,0" +locations_default(#20026,#10000,1,1,1,0) +hasLocation(#20025,#20026) +#20027=* +exit_cfg_node(#20027,#20001) +hasLocation(#20027,#20015) +successor(#20017,#20018) +successor(#20018,#20021) +successor(#20023,#20019) +successor(#20021,#20023) +successor(#20019,#20027) +successor(#20025,#20017) +numlines(#10000,1,1,0) +filetype(#10000,"javascript")