Skip to content

Commit 5f5964d

Browse files
committed
release notes for #4163
1 parent adb5284 commit 5f5964d

File tree

2 files changed

+17
-12
lines changed

2 files changed

+17
-12
lines changed

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,12 @@
66

77
This fixes a regression in version 0.25.0 where `sources` in source maps that form invalid URLs were not being passed through to the output. Version 0.25.0 changed the interpretation of `sources` from file paths to URLs, which means that URL parsing can now fail. Previously URLs that couldn't be parsed were replaced with the empty string. With this release, invalid URLs in `sources` should now be passed through unmodified.
88

9+
* Handle exports named `__proto__` in ES modules ([#4162](https://github.com/evanw/esbuild/issues/4162), [#4163](https://github.com/evanw/esbuild/pull/4163))
10+
11+
In JavaScript, the special property name `__proto__` sets the prototype when used inside an object literal. Previously esbuild's ESM-to-CommonJS conversion didn't special-case the property name of exports named `__proto__` so the exported getter accidentally became the prototype of the object literal. It's unclear what this affects, if anything, but it's better practice to avoid this by using a computed property name in this case.
12+
13+
This fix was contributed by [@magic-akari](https://github.com/magic-akari).
14+
915
## 0.25.3
1016

1117
* Fix lowered `async` arrow functions before `super()` ([#4141](https://github.com/evanw/esbuild/issues/4141), [#4142](https://github.com/evanw/esbuild/pull/4142))

internal/linker/linker.go

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2294,19 +2294,18 @@ func (c *linkerContext) createExportsForFile(sourceIndex uint32) {
22942294
getter = js_ast.Expr{Data: &js_ast.EArrow{PreferExpr: true, Body: body}}
22952295
}
22962296

2297-
// Special case for __proto__ property - use computed property name to avoid it being treated as the object's prototype
2298-
if alias == "__proto__" {
2299-
properties = append(properties, js_ast.Property{
2300-
Flags: js_ast.PropertyIsComputed,
2301-
Key: js_ast.Expr{Data: &js_ast.EString{Value: helpers.StringToUTF16(alias)}},
2302-
ValueOrNil: getter,
2303-
})
2304-
} else {
2305-
properties = append(properties, js_ast.Property{
2306-
Key: js_ast.Expr{Data: &js_ast.EString{Value: helpers.StringToUTF16(alias)}},
2307-
ValueOrNil: getter,
2308-
})
2297+
// Special case for __proto__ property: use a computed property
2298+
// name to avoid it being treated as the object's prototype
2299+
var flags js_ast.PropertyFlags
2300+
if alias == "__proto__" && !c.options.UnsupportedJSFeatures.Has(compat.ObjectExtensions) {
2301+
flags |= js_ast.PropertyIsComputed
23092302
}
2303+
2304+
properties = append(properties, js_ast.Property{
2305+
Flags: flags,
2306+
Key: js_ast.Expr{Data: &js_ast.EString{Value: helpers.StringToUTF16(alias)}},
2307+
ValueOrNil: getter,
2308+
})
23102309
nsExportSymbolUses[export.Ref] = js_ast.SymbolUse{CountEstimate: 1}
23112310

23122311
// Make sure the part that declares the export is included

0 commit comments

Comments
 (0)