Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
336 changes: 114 additions & 222 deletions builtin_regexp.go

Large diffs are not rendered by default.

5 changes: 3 additions & 2 deletions compiler_expr.go
Original file line number Diff line number Diff line change
Expand Up @@ -3068,12 +3068,13 @@ func (c *compiler) compileArrayLiteral(v *ast.ArrayLiteral) compiledExpr {

func (e *compiledRegexpLiteral) emitGetter(putOnStack bool) {
if putOnStack {
pattern, err := compileRegexp(e.expr.Pattern, e.expr.Flags)
src := newStringValue(e.expr.Pattern)
pattern, err := compileRegexp(src, e.expr.Flags)
if err != nil {
e.c.throwSyntaxError(e.offset, err.Error())
}

e.c.emit(&newRegexp{pattern: pattern, src: newStringValue(e.expr.Pattern)})
e.c.emit(&newRegexp{pattern: pattern, src: src})
}
}

Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ go 1.20

require (
github.com/Masterminds/semver/v3 v3.2.1
github.com/dlclark/regexp2 v1.11.4
github.com/auvred/regonaut v0.0.1
github.com/dop251/goja_nodejs v0.0.0-20211022123610-8dd9abb0616d
github.com/go-sourcemap/sourcemap v2.1.3+incompatible
github.com/google/pprof v0.0.0-20230207041349-798e818bf904
Expand Down
6 changes: 4 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
github.com/Masterminds/semver/v3 v3.2.1 h1:RN9w6+7QoMeJVGyfmbcgs28Br8cvmnucEXnY0rYXWg0=
github.com/Masterminds/semver/v3 v3.2.1/go.mod h1:qvl/7zhW3nngYb5+80sSMF+FG2BjYrf8m9wsX0PNOMQ=
github.com/auvred/regonaut v0.0.1 h1:308+62qAZlIJ9Uq8R9KeLscLFBu/gENl1ZlgdlwWM1E=
github.com/auvred/regonaut v0.0.1/go.mod h1:XetEYtndfNYNqp0i+DZKtY37RdUp6L6kq4rFx1f+lic=
github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E=
github.com/dlclark/regexp2 v1.4.1-0.20201116162257-a2a8dda75c91/go.mod h1:2pZnwuY/m+8K6iRw6wQdMtk+rH5tNGR1i55kozfMjCc=
github.com/dlclark/regexp2 v1.11.4 h1:rPYF9/LECdNymJufQKmri9gV604RvvABwgOA8un7yAo=
github.com/dlclark/regexp2 v1.11.4/go.mod h1:DHkYz0B9wPfa6wondMfaivmHpzrQ3v9q8cnmRbL6yW8=
github.com/dop251/goja v0.0.0-20211022113120-dc8c55024d06/go.mod h1:R9ET47fwRVRPZnOGvHxxhuZcbrMCuiqOz3Rlrh4KSnk=
github.com/dop251/goja_nodejs v0.0.0-20210225215109-d91c329300e7/go.mod h1:hn7BA7c8pLvoGndExHudxTDKZ84Pyvv+90pbBjbTz0Y=
github.com/dop251/goja_nodejs v0.0.0-20211022123610-8dd9abb0616d h1:W1n4DvpzZGOISgp7wWNtraLcHtnmnTwBlJidqtMIuwQ=
github.com/dop251/goja_nodejs v0.0.0-20211022123610-8dd9abb0616d/go.mod h1:DngW8aVqWbuLRMHItjPUyqdj+HWPvnQe8V8y1nDpIbM=
github.com/go-sourcemap/sourcemap v2.1.3+incompatible h1:W1iEw64niKVGogNgBN3ePyLFfuisuzeidWPMPWmECqU=
github.com/go-sourcemap/sourcemap v2.1.3+incompatible/go.mod h1:F8jJfvm2KbVjc5NqelyYJmf/v5J0dwNLS2mL4sNA1Jg=
github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI=
github.com/google/pprof v0.0.0-20230207041349-798e818bf904 h1:4/hN5RUoecvl+RmJRE2YxKWtnnQls6rQjjW5oV7qg2U=
github.com/google/pprof v0.0.0-20230207041349-798e818bf904/go.mod h1:uglQLonpP8qtYCYyzA+8c/9qtqgA3qsXGYqCPKARAFg=
github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo=
Expand All @@ -33,3 +34,4 @@ gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c/go.mod h1:JHkPIbrfpd72SG/EV
gopkg.in/errgo.v2 v2.1.0/go.mod h1:hNsd1EY+bozCKY1Ytp96fpM3vjJbqLJn88ws8XvfDNI=
gopkg.in/yaml.v2 v2.4.0 h1:D8xgwECY7CYvx+Y2n4sBz93Jn9JRvxdiyyo8CTfuKaY=
gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ=
gotest.tools/v3 v3.5.2 h1:7koQfIKdy+I8UTetycgUqXWSDwpgv193Ka+qRsmBY8Q=
2 changes: 1 addition & 1 deletion parser/parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ import (
type Mode uint

const (
IgnoreRegExpErrors Mode = 1 << iota // Ignore RegExp compatibility errors (allow backtracking)
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IgnoreRegExpErrors was introduced in the initial commit (2577360). However, even back then it was only used in tests and nowhere else.

I'm not entirely sure about removing it completely, though. It has been part of the public API for 9 years. Nevertheless, I don't think anyone is actually relying on it in production code.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think it would be a problem.

WhitespaceChars = " \f\n\r\t\v\u00a0\u1680\u2000\u2001\u2002\u2003\u2004\u2005\u2006\u2007\u2008\u2009\u200a\u2028\u2029\u202f\u205f\u3000\ufeff"
)

type options struct {
Expand Down
13 changes: 0 additions & 13 deletions parser/parser_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,19 +43,6 @@ func testParse(src string) (parser *_parser, program *ast.Program, err error) {
return
}

func TestParseFile(t *testing.T) {
tt(t, func() {
_, err := ParseFile(nil, "", `/abc/`, 0)
is(err, nil)

_, err = ParseFile(nil, "", `/(?!def)abc/`, IgnoreRegExpErrors)
is(err, nil)

_, err = ParseFile(nil, "", `/(?!def)abc/; return`, IgnoreRegExpErrors)
is(err, "(anonymous): Line 1:15 Illegal return statement")
})
}

func TestParseFunction(t *testing.T) {
tt(t, func() {
test := func(prm, bdy string, expect interface{}) *ast.FunctionLiteral {
Expand Down
Loading