js: Add avoidTDZ option
authorBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>
Tue, 3 Nov 2020 08:05:09 +0000 (09:05 +0100)
committerBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>
Tue, 3 Nov 2020 12:04:37 +0000 (13:04 +0100)
Fixes #7865

docs/content/en/hugo-pipes/js.md
go.sum
resources/resource_transformers/js/options.go
resources/resource_transformers/js/options_test.go

index 5e9c027d577d8898b1b31d7f8b0888078eb1b12c..07ee560f689b4fb094e328a450a07d85b2ec0e02 100644 (file)
@@ -40,6 +40,9 @@ Note that this is meant for small data sets, e.g. config settings. For larger da
 minify [bool]
 : Let `js.Build` handle the minification.
 
+avoidTDZ {{< new-in "0.78.0" >}}
+: There is/was a bug in WebKit with severe performance issue with the tracking of TDZ checks in JavaScriptCore. Enabling this flag removes the TDZ and `const` assignment checks and may improve performance of larger JS codebases until the WebKit fix is in widespread use. See https://bugs.webkit.org/show_bug.cgi?id=199866
+
 target [string]
 : The language target.
   One of: `es5`, `es2015`, `es2016`, `es2017`, `es2018`, `es2019`, `es2020` or `esnext`.
diff --git a/go.sum b/go.sum
index b240a8a77ba34d03f9c0d3b30b9ce8f435d81ab2..8470f4778443905adf4d9dd993adcc2b5a129b9b 100644 (file)
--- a/go.sum
+++ b/go.sum
@@ -459,6 +459,8 @@ github.com/spf13/afero v1.2.2 h1:5jhuqJyZCZf2JRofRvN/nIFgIWNzPa3/Vz8mYylgbWc=
 github.com/spf13/afero v1.2.2/go.mod h1:9ZxEEn6pIJ8Rxe320qSDBk6AsU0r9pR7Q4OcevTdifk=
 github.com/spf13/afero v1.4.0 h1:jsLTaI1zwYO3vjrzHalkVcIHXTNmdQFepW4OI8H3+x8=
 github.com/spf13/afero v1.4.0/go.mod h1:Ai8FlHk4v/PARR026UzYexafAt9roJ7LcLMAmO6Z93I=
+github.com/spf13/afero v1.4.1 h1:asw9sl74539yqavKaglDM5hFpdJVK0Y5Dr/JOgQ89nQ=
+github.com/spf13/afero v1.4.1/go.mod h1:Ai8FlHk4v/PARR026UzYexafAt9roJ7LcLMAmO6Z93I=
 github.com/spf13/cast v1.3.0 h1:oget//CVOEoFewqQxwr0Ej5yjygnqGkvggSE/gB35Q8=
 github.com/spf13/cast v1.3.0/go.mod h1:Qx5cxh0v+4UWYiBimWS+eyWzqEqokIECu5etghLkUJE=
 github.com/spf13/cast v1.3.1 h1:nFm6S0SMdyzrzcmThSipiEubIDy8WEXKNZ0UOgiRpng=
index 5e74982d38db4100acc6425085b9519e61fa3f62..84a6c1a78452125c7c8437545a5ca680a12147e1 100644 (file)
@@ -70,6 +70,16 @@ type Options struct {
        // What to use instead of React.Fragment.
        JSXFragment string
 
+       // There is/was a bug in WebKit with severe performance issue with the tracking
+       // of TDZ checks in JavaScriptCore.
+       //
+       // Enabling this flag removes the TDZ and `const` assignment checks and
+       // may improve performance of larger JS codebases until the WebKit fix
+       // is in widespread use.
+       //
+       // See https://bugs.webkit.org/show_bug.cgi?id=199866
+       AvoidTDZ bool
+
        mediaType  media.Type
        outDir     string
        contents   string
@@ -339,6 +349,8 @@ func toBuildOptions(opts Options) (buildOptions api.BuildOptions, err error) {
                JSXFactory:  opts.JSXFactory,
                JSXFragment: opts.JSXFragment,
 
+               AvoidTDZ: opts.AvoidTDZ,
+
                Tsconfig: opts.tsConfig,
 
                Stdin: &api.StdinOptions{
index 89d362ab93914a2bb9703443ac987cd9bc50640d..abc8091a9c3b115b948e30987fcc408ffc566d61 100644 (file)
@@ -54,7 +54,12 @@ func TestToBuildOptions(t *testing.T) {
        })
 
        opts, err = toBuildOptions(Options{
-               Target: "es2018", Format: "cjs", Minify: true, mediaType: media.JavascriptType})
+               Target:    "es2018",
+               Format:    "cjs",
+               Minify:    true,
+               mediaType: media.JavascriptType,
+               AvoidTDZ:  true,
+       })
        c.Assert(err, qt.IsNil)
        c.Assert(opts, qt.DeepEquals, api.BuildOptions{
                Bundle:            true,
@@ -63,6 +68,7 @@ func TestToBuildOptions(t *testing.T) {
                MinifyIdentifiers: true,
                MinifySyntax:      true,
                MinifyWhitespace:  true,
+               AvoidTDZ:          true,
                Stdin: &api.StdinOptions{
                        Loader: api.LoaderJS,
                },