1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51
|
Description: Avoid emitting __proto__ in generated output
Replace {__proto__: null, ...} with Object.setPrototypeOf({...}, null)
in generated code. The __proto__ property in object literals does not
work when Node.js runs with --disable-proto, which is used in Debian
autopkgtests. Object.setPrototypeOf is a proper API that works in all
environments and preserves getter semantics for live bindings.
Author: Yadd <yadd@debian.org>
Bug-Debian: https://bugs.debian.org/1093290
Forwarded: no
Last-Update: 2026-03-22
--- a/src/ast/variables/NamespaceVariable.ts
+++ b/src/ast/variables/NamespaceVariable.ts
@@ -145,9 +145,7 @@
return [name, variable.getName(getPropertyAccess)];
});
- members.unshift([null, `__proto__:${_}null`]);
-
- let output = getObject(members, { lineBreakIndent: { base: '', t } });
+ let output = `/*#__PURE__*/Object.setPrototypeOf(${getObject(members, { lineBreakIndent: { base: '', t } })},${_}null)`;
if (this.mergedNamespaces.length > 0) {
const assignmentArguments = this.mergedNamespaces.map(variable =>
variable.getName(getPropertyAccess)
--- a/src/utils/interopHelpers.ts
+++ b/src/utils/interopHelpers.ts
@@ -141,7 +141,7 @@
freeze: boolean,
namespaceToStringTag: boolean
) {
- const { getDirectReturnFunction, getObject, n } = snippets;
+ const { _, getDirectReturnFunction, getObject, n } = snippets;
const [left, right] = getDirectReturnFunction(['e'], {
functionReturn: true,
lineBreakIndent: null,
@@ -151,13 +151,10 @@
freeze,
getWithToStringTag(
namespaceToStringTag,
- getObject(
- [
- ['__proto__', 'null'],
- ['default', 'e']
- ],
+ `/*#__PURE__*/Object.setPrototypeOf(${getObject(
+ [['default', 'e']],
{ lineBreakIndent: null }
- ),
+ )},${_}null)`,
snippets
)
)}${right}${n}${n}`;
|