Skip to content

Commit

Permalink
JS: fix parsing of string expressions at the start of statement lists…
Browse files Browse the repository at this point in the history
… that are no UseStrictDirectives
  • Loading branch information
tdewolff committed May 14, 2023
1 parent 9145984 commit 7d47c2c
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 32 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -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
)
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -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=
Expand Down
58 changes: 29 additions & 29 deletions js/js_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,"</scr"+"ipt>"`, `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>"`},
{`"</scr"+"ipt>"`, `"<\/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`},
Expand Down

0 comments on commit 7d47c2c

Please sign in to comment.