Backtestshugorun-20261002-200313#15307
js.Build should support es2025 as target
Our patch was judged better than the merged fix.
In this judgment, Patch A = our agent, Patch B = the merged fix.
Both patches make the same core fix: they add "es2025": api.ES2025 to the target map in internal/js/esbuild/options.go. That resolves the 'unsupported target: [es2025]' error at its root. Both also extend the TestToBuildOptionsTarget unit table with es2024 and es2025 cases, which would fail before the change and pass after it. Patch A goes further in ways that serve the issue's stated ask. The issue says Hugo doesn't 'support and/or list es2025', and A updates the user-facing docs (options.md) so es2025 appears in the list of valid targets. A also fixes the stale Go doc comment on the Target field, which only listed versions up to es2020. Finally, A adds an end-to-end integration test that mirrors the issue's reproduction: js.Build on a .ts file with minify, sourceMap none and target es2025. That test also checks that an uppercase 'ES2025' is accepted. Asserting exact minified output is somewhat brittle, but it reasonably exercises the reported scenario. The correctness is identical, so A wins on more complete coverage of the issue (documentation listing) and stronger tests, with no added risk.
The judge saw only the two patches, labelled A and B in random order, with issue links and version numbers removed. The reasoning above is shown verbatim.
Solve
45m 55s
Wall-clock time in the container
Full test suite
No new failures
3,758 passed · 100 skipped · 3,860 total
Contamination audit
Clean
No sign the agent saw the real fix
Patch size
26vs 3 merged
Changed lines, ours vs merged
The issue
View on GitHubHugo's built-in js.Build function currently doesnt support and/or list es2025 as available target parameter.
As far as i understood js.Build relies on evanw/esbuild for bundling, transforming and minifying javascript ressources.
According to hugo's own release notes esbuild was just bumped to 0.28.2.
According to esbuild's release notes, support for es2025 as target parameter exists since 0.27.5.
Hugo should therefore support es2025 as target parameter.
However when doing something like this:
{{- $buildParams := dict
"minify" true
"sourceMap" "none"
"target" "es2025"
}}
{{- with . | js.Build $buildParams }}
<script>{{ .Content | safeJS }}</script>
{{- end }}
results in the following error message:
`
... JSBUILD: failed to transform "/ts/test.ts" (text/typescript): unsupported target: [es2025] ...
`
What version of Hugo are you using (hugo version)?
hugo v0.165.0
Does this issue reproduce with the latest release?
Yes
The two patches
docs/content/en/_common/functions/js/options.mdindex ed606b0d7..4767eda6c 100644@@ -104,4 +104,4 @@ _comment: Do not remove front matter. : (`bool`) Whether to include the content of the source files in the source map. Default is `true`. `target`-: (`string`) The language target. One of: `es5`, `es2015`, `es2016`, `es2017`, `es2018`, `es2019`, `es2020`, `es2021`, `es2022`, `es2023`, `es2024`, or `esnext`. Default is `esnext`.+: (`string`) The language target. One of: `es5`, `es2015`, `es2016`, `es2017`, `es2018`, `es2019`, `es2020`, `es2021`, `es2022`, `es2023`, `es2024`, `es2025`, or `esnext`. Default is `esnext`.internal/js/esbuild/options.goindex 4176438e8..3bdf3c66d 100644@@ -49,6 +49,7 @@ var ( "es2022": api.ES2022, "es2023": api.ES2023, "es2024": api.ES2024,+ "es2025": api.ES2025, } engineName = map[string]api.EngineName{@@ -144,7 +145,7 @@ type ExternalOptions struct { SourcesContent bool // This sets the target environment for the generated JavaScript and/or CSS code.- // It can specify the JavaScript language version to target (es2015, es2016, es2017, es2018, es2019, es2020 or esnext; default is esnext),+ // It can specify the JavaScript language version to target (es5, es2015 through es2025, or esnext; default is esnext), // in addition to a set of environments to support, as slice of environment name followed by a version number. e.g. "chrome80", "firefox73", "safari13" or "edge80". // See https://esbuild.github.io/api/#target Target []stringinternal/js/esbuild/options_test.goindex b60dcbc4a..683a32db0 100644@@ -189,6 +189,8 @@ func TestToBuildOptionsTarget(t *testing.T) { {"es2021", api.ES2021}, {"es2022", api.ES2022}, {"es2023", api.ES2023},+ {"es2024", api.ES2024},+ {"es2025", api.ES2025}, {"", api.ESNext}, {"esnext", api.ESNext}, } {resources/resource_transformers/js/js_integration_test.goindex 2244e8f8e..108572848 100644@@ -402,6 +402,25 @@ class A {} b.AssertFileContent("public/js/main.js", "__decorateClass") } +func TestBuildTargetES2025(t *testing.T) {+ t.Parallel()+ files := `+-- hugo.toml --+disableKinds = ['RSS','sitemap','taxonomy','term']+-- assets/ts/test.ts --+const greeting: string = "Hello ES2025";+console.log(greeting);+-- layouts/home.html --+{{ $lower := resources.Get "ts/test.ts" | js.Build (dict "minify" true "sourceMap" "none" "target" "es2025" "targetPath" "js/lower.js") }}+{{ $upper := resources.Get "ts/test.ts" | js.Build (dict "target" "ES2025" "targetPath" "js/upper.js") }}+<script>{{ $lower.Content | safeJS }}</script>+{{ $upper.RelPermalink }}+`+ b := hugolib.Test(t, files, hugolib.TestOptOsFs())+ b.AssertFileContent("public/index.html", `<script>(()=>{var o="Hello ES2025";console.log(o);})();`, "/js/upper.js")+ b.AssertFileContent("public/js/upper.js", `Hello ES2025`)+}+ // Issue 13183. func TestExternalsInAssets(t *testing.T) { files := `
internal/js/esbuild/options.goindex 4176438e8..9248701f7 100644@@ -49,6 +49,7 @@ var ( "es2022": api.ES2022, "es2023": api.ES2023, "es2024": api.ES2024,+ "es2025": api.ES2025, } engineName = map[string]api.EngineName{internal/js/esbuild/options_test.goindex b60dcbc4a..683a32db0 100644@@ -189,6 +189,8 @@ func TestToBuildOptionsTarget(t *testing.T) { {"es2021", api.ES2021}, {"es2022", api.ES2022}, {"es2023", api.ES2023},+ {"es2024", api.ES2024},+ {"es2025", api.ES2025}, {"", api.ESNext}, {"esnext", api.ESNext}, } {