Backtestshugorun-20261024-162305#15307
js.Build should support es2025 as target
Our patch was judged better than the merged fix.
In this judgment, Patch B = our agent, Patch A = the merged fix.
Both patches make the identical one-line root-cause fix: adding the "es2025" key mapping to api.ES2025 in the target lookup map in internal/js/esbuild/options.go. Both pass the independent tests equally. Both add the same unit-table entries in options_test.go (es2024 and es2025 cases), which would fail before and pass after. Patch B additionally adds an integration test (TestBuildTargetES2025) reproducing the issue's exact scenario (TypeScript asset, minify, sourceMap none, target es2025) and asserting the built output, which exercises the real js.Build template path rather than only the option-conversion function. Patch B also updates the user-facing docs list of valid targets, which was stale and is directly relevant since the issue complains the target is neither supported nor listed, and refreshes a stale code comment that still said es2015-es2020. None of B's extra changes add risk or obscure the fix. The integration test's exact-output assertion is somewhat brittle against future esbuild minifier changes, but that is a minor concern. B is the better patch on tests and scope completeness.
Four judges ruled on this ticket in parallel, and the verdict comes from counting their votes. Each saw the issue and the two patches, labelled A and B in random order (two of them saw ours as A), with issue links and version numbers removed. Where tests could check the fix, they also saw the results of tests a separate agent wrote for the issue, run on both patches. None was told which patch was ours. The reasoning above is one judge's, shown verbatim.
Solve
21m 11s
Wall-clock time in the container
Full test suite
No new failures
771 passed · 1 skipped · 781 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..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..a3e69107f 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)+ 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}, } {