From 7d47c2c620e37388d39b21db1131b8480ef71df4 Mon Sep 17 00:00:00 2001 From: Taco de Wolff Date: Sun, 14 May 2023 19:37:10 -0400 Subject: [PATCH] JS: fix parsing of string expressions at the start of statement lists that are no UseStrictDirectives --- go.mod | 2 +- go.sum | 4 ++-- js/js_test.go | 58 +++++++++++++++++++++++++-------------------------- 3 files changed, 32 insertions(+), 32 deletions(-) diff --git a/go.mod b/go.mod index ee1f164e7c..e690e105c8 100644 --- a/go.mod +++ b/go.mod @@ -9,7 +9,7 @@ require ( github.com/fsnotify/fsnotify v1.6.0 github.com/matryer/try v0.0.0-20161228173917-9ac251b645a2 github.com/spf13/pflag v1.0.5 - github.com/tdewolff/parse/v2 v2.6.5 + github.com/tdewolff/parse/v2 v2.6.6 github.com/tdewolff/test v1.0.7 golang.org/x/sys v0.6.0 // indirect ) diff --git a/go.sum b/go.sum index 439cd75e9d..6773c6fd73 100644 --- a/go.sum +++ b/go.sum @@ -10,8 +10,8 @@ github.com/matryer/try v0.0.0-20161228173917-9ac251b645a2 h1:JAEbJn3j/FrhdWA9jW8 github.com/matryer/try v0.0.0-20161228173917-9ac251b645a2/go.mod h1:0KeJpeMD6o+O4hW7qJOT7vyQPKrWmj26uf5wMc/IiIs= github.com/spf13/pflag v1.0.5 h1:iy+VFUOCP1a+8yFto/drg2CJ5u0yRoB7fZw3DKv/JXA= github.com/spf13/pflag v1.0.5/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg= -github.com/tdewolff/parse/v2 v2.6.5 h1:lYvWBk55GkqKl0JJenGpmrgu/cPHQQ6/Mm1hBGswoGQ= -github.com/tdewolff/parse/v2 v2.6.5/go.mod h1:woz0cgbLwFdtbjJu8PIKxhW05KplTFQkOdX78o+Jgrs= +github.com/tdewolff/parse/v2 v2.6.6 h1:Yld+0CrKUJaCV78DL1G2nk3C9lKrxyRTux5aaK/AkDo= +github.com/tdewolff/parse/v2 v2.6.6/go.mod h1:woz0cgbLwFdtbjJu8PIKxhW05KplTFQkOdX78o+Jgrs= github.com/tdewolff/test v1.0.7 h1:8Vs0142DmPFW/bQeHRP3MV19m1gvndjUb1sn8yy74LM= github.com/tdewolff/test v1.0.7/go.mod h1:6DAvZliBAAnD7rhVgwaM7DE5/d9NMOAJ09SqYqeK4QE= golang.org/x/sys v0.0.0-20220908164124-27713097b956/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= diff --git a/js/js_test.go b/js/js_test.go index 4ea670efea..21306911c1 100644 --- a/js/js_test.go +++ b/js/js_test.go @@ -141,35 +141,35 @@ func TestJS(t *testing.T) { {`try {a} catch(b) {c}`, `try{a}catch{c}`}, {`a=b;c=d`, `a=b,c=d`}, - // strings (prepend '0,' to avoid being a directive prologue) - {`0,""`, `0,""`}, - {`0,"\x7"`, `0,"\x7"`}, - {`0,"string\'string"`, `0,"string'string"`}, - {`0,'string\"string'`, `0,'string"string'`}, - {`0,"string\t\f\v\bstring"`, "0,\"string\t\f\v\bstring\""}, - {`0,"string\a\c\'string"`, `0,"stringac'string"`}, - {`0,"string\∀string"`, `0,"string∀string"`}, - {`0,"string\0\uFFFFstring"`, "0,\"string\x00\\uFFFFstring\""}, - {`0,"string\x00\x55\x0A\x0D\x22\x27string"`, "0,\"string\x00U\\n\\r\\\"'string\""}, - {`0,"string\000\12\015\042\47\411string"`, "0,\"string\x00\\n\\r\\\"'!1string\""}, - {"0,'string\\n\\rstring'", "0,`string\n\rstring`"}, - {"0,'string\\\r\nstring\\\nstring\\\rstring\\\u2028string\\\u2029string'", `0,"stringstringstringstringstringstring"`}, - {`0,"str1ng" + "str2ng"`, `0,"str1ngstr2ng"`}, - {`0,"str1ng" + "str2ng" + "str3ng"`, `0,"str1ngstr2ngstr3ng"`}, - {`0,"padding" + this`, `0,"padding"+this`}, - {`0,"<\/script>"`, `0,"<\/script>"`}, - {`0,""`, `0,"<\/script>"`}, - {`0,"\""`, `0,'"'`}, - {`0,'\'""'`, "0,`'\"\"`"}, - {`0,"\"\"a'"`, "0,`\"\"a'`"}, - {`0,"'" + '"'`, "0,`'\"`"}, - {`0,'"' + "'"`, "0,`\"'`"}, - {"0,`\\n\\'\\$\\$\\{`", "0,`\n'$\\${`"}, - {`0,"a"+"b"+5`, `0,"ab"+5`}, - {`0,5+"a"+"b"`, `0,5+"ab"`}, - {`0,"a"+"b"+5+"c"+"d"`, `0,"ab"+5+"cd"`}, - {`0,"a"+"b"+5+6+"d"`, `0,"ab"+5+6+"d"`}, - {"0,`$${foo}`", "0,`$${foo}`"}, + // strings + {`""`, `""`}, + {`"\x7"`, `"\x7"`}, + {`"string\'string"`, `"string'string"`}, + {`'string\"string'`, `'string"string'`}, + {`"string\t\f\v\bstring"`, "\"string\t\f\v\bstring\""}, + {`"string\a\c\'string"`, `"stringac'string"`}, + {`"string\∀string"`, `"string∀string"`}, + {`"string\0\uFFFFstring"`, "\"string\x00\\uFFFFstring\""}, + {`"string\x00\x55\x0A\x0D\x22\x27string"`, "\"string\x00U\\n\\r\\\"'string\""}, + {`"string\000\12\015\042\47\411string"`, "\"string\x00\\n\\r\\\"'!1string\""}, + {"'string\\n\\rstring'", "`string\n\rstring`"}, + {"'string\\\r\nstring\\\nstring\\\rstring\\\u2028string\\\u2029string'", `"stringstringstringstringstringstring"`}, + {`"str1ng" + "str2ng"`, `"str1ngstr2ng"`}, + {`"str1ng" + "str2ng" + "str3ng"`, `"str1ngstr2ngstr3ng"`}, + {`"padding" + this`, `"padding"+this`}, + {`"<\/script>"`, `"<\/script>"`}, + {`""`, `"<\/script>"`}, + {`"\""`, `'"'`}, + {`'\'""'`, "`'\"\"`"}, + {`"\"\"a'"`, "`\"\"a'`"}, + {`"'" + '"'`, "`'\"`"}, + {`'"' + "'"`, "`\"'`"}, + {"`\\n\\'\\$\\$\\{`", "`\n'$\\${`"}, + {`"a"+"b"+5`, `"ab"+5`}, + {`5+"a"+"b"`, `5+"ab"`}, + {`"a"+"b"+5+"c"+"d"`, `"ab"+5+"cd"`}, + {`"a"+"b"+5+6+"d"`, `"ab"+5+6+"d"`}, + {"`$${foo}`", "`$${foo}`"}, // rename true, false, undefined, Infinity {`x=true`, `x=!0`},