Backtestshugorun-20261013-011256#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 add identical unit test cases for es2024 and es2025 in TestToBuildOptionsTarget, and the es2025 case would fail before the change, so on correctness and unit tests they are equal. Patch A goes further in ways that matter. It adds an integration test, TestBuildTargetES2025, that reproduces the issue's exact scenario: a TypeScript asset, minify, sourceMap none, and target es2025 through js.Build. This exercises the full template-to-esbuild path and checks the output. It also updates the user-facing docs (options.md) to list es2025, which matters because the issue explicitly complains that es2025 is not listed as an available target. Finally, it corrects the outdated Go doc comment on Target so it lists all supported targets. None of these additions add risk. One small caveat: the integration test asserts exact minified output, which could break on esbuild upgrades, but it still validates the fix. Patch A addresses the full ask (support plus listing) with stronger end-to-end testing, so it is the better fix.
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
13m 58s
Wall-clock time in the container
Full test suite
No new failures
724 passed · 27 skipped · 755 total
Contamination audit
Clean
No sign the agent saw the real fix
Patch size
25vs 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..89ecb19ff 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, es2016, es2017, es2018, es2019, es2020, es2021, es2022, es2023, es2024, 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..530445806 100644@@ -402,6 +402,24 @@ 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 --+{{- $buildParams := dict "minify" true "sourceMap" "none" "target" "es2025" }}+{{- with resources.Get "ts/test.ts" | js.Build $buildParams }}+<script>{{ .Content | safeJS }}</script>+{{- end }}+`+ b := hugolib.Test(t, files, hugolib.TestOptOsFs())+ b.AssertFileContent("public/index.html", `<script>(()=>{var e="hello es2025";console.log(e);})();`)+}+ // 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}, } {