Backtestshugorun-20261005-133023#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 root-cause fix: they add "es2025": api.ES2025 to the target map in internal/js/esbuild/options.go, so the 'unsupported target: [es2025]' error goes away. Both also extend the TestToBuildOptionsTarget unit table with es2024 and es2025, and that test would fail before the change. Patch A goes further in ways the issue directly asks for. The issue says Hugo doesn't 'support and/or list es2025', and A updates the user-facing docs (options.md) to list es2025. A also fixes the outdated Target field comment. In addition, A adds an integration test that reproduces the exact scenario from the issue: js.Build on a TypeScript file with minify, sourceMap none and target es2025. That test exercises the full template-to-esbuild path, not just the map lookup. Its expected exact minified output is slightly brittle, but it is still a valid end-to-end regression test. Neither patch adds risk. Correctness is equal, A has stronger tests and covers the 'list' part of the request, so A 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
1h
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
24vs 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..0a61b05c1 100644@@ -402,6 +402,23 @@ class A {} b.AssertFileContent("public/js/main.js", "__decorateClass") } +func TestBuildTargetES2025(t *testing.T) {+ t.Parallel()++ files := `+-- hugo.toml --+disableKinds = ['RSS','sitemap','taxonomy','term','page','section']+-- assets/ts/main.ts --+const greeting: string = "hello";+console.log(greeting);+-- layouts/home.html --+{{ $opts := dict "minify" true "sourceMap" "none" "target" "es2025" "targetPath" "js/main.js" }}+{{ with resources.Get "ts/main.ts" | js.Build $opts }}<script>{{ .Content | safeJS }}</script>{{ end }}+`+ b := hugolib.Test(t, files)+ b.AssertFileContent("public/index.html", `<script>(()=>{var o="hello";console.log(o);})();`)+}+ // 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}, } {