diff options
author | Bjørn Erik Pedersen <[email protected]> | 2024-06-08 10:52:16 +0200 |
---|---|---|
committer | Bjørn Erik Pedersen <[email protected]> | 2024-06-08 11:40:19 +0200 |
commit | 1cdd3d0a9e4a988fb505a1bcbb3e7692b64bef55 (patch) | |
tree | d782941e9b12b0819ed326d922bd7d367b6dce81 /resources | |
parent | b57306d61b79b2193f6abd8a577b53bd84d0ae2b (diff) | |
download | hugo-1cdd3d0a9e4a988fb505a1bcbb3e7692b64bef55.tar.gz hugo-1cdd3d0a9e4a988fb505a1bcbb3e7692b64bef55.zip |
js: Support more recent targets with js.Build / esbuild
Closes #12575
Diffstat (limited to 'resources')
-rw-r--r-- | resources/resource_transformers/js/options.go | 6 | ||||
-rw-r--r-- | resources/resource_transformers/js/options_test.go | 36 |
2 files changed, 40 insertions, 2 deletions
diff --git a/resources/resource_transformers/js/options.go b/resources/resource_transformers/js/options.go index 7de88638c..8c271d032 100644 --- a/resources/resource_transformers/js/options.go +++ b/resources/resource_transformers/js/options.go @@ -342,6 +342,12 @@ func toBuildOptions(opts Options) (buildOptions api.BuildOptions, err error) { target = api.ES2019 case "es2020": target = api.ES2020 + case "es2021": + target = api.ES2021 + case "es2022": + target = api.ES2022 + case "es2023": + target = api.ES2023 default: err = fmt.Errorf("invalid target: %q", opts.Target) return diff --git a/resources/resource_transformers/js/options_test.go b/resources/resource_transformers/js/options_test.go index a49b174ae..de20cbd05 100644 --- a/resources/resource_transformers/js/options_test.go +++ b/resources/resource_transformers/js/options_test.go @@ -136,8 +136,10 @@ func TestToBuildOptions(t *testing.T) { }, }) - opts, err = toBuildOptions(Options{mediaType: media.Builtin.JavascriptType, - JSX: "automatic", JSXImportSource: "preact"}) + opts, err = toBuildOptions(Options{ + mediaType: media.Builtin.JavascriptType, + JSX: "automatic", JSXImportSource: "preact", + }) c.Assert(err, qt.IsNil) c.Assert(opts, qt.DeepEquals, api.BuildOptions{ Bundle: true, @@ -151,6 +153,36 @@ func TestToBuildOptions(t *testing.T) { }) } +func TestToBuildOptionsTarget(t *testing.T) { + c := qt.New(t) + + for _, test := range []struct { + target string + expect api.Target + }{ + {"es2015", api.ES2015}, + {"es2016", api.ES2016}, + {"es2017", api.ES2017}, + {"es2018", api.ES2018}, + {"es2019", api.ES2019}, + {"es2020", api.ES2020}, + {"es2021", api.ES2021}, + {"es2022", api.ES2022}, + {"es2023", api.ES2023}, + {"", api.ESNext}, + {"esnext", api.ESNext}, + } { + c.Run(test.target, func(c *qt.C) { + opts, err := toBuildOptions(Options{ + Target: test.target, + mediaType: media.Builtin.JavascriptType, + }) + c.Assert(err, qt.IsNil) + c.Assert(opts.Target, qt.Equals, test.expect) + }) + } +} + func TestResolveComponentInAssets(t *testing.T) { c := qt.New(t) |