Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
fix: don't optimize in with syntheticNamedExports
  • Loading branch information
hi-ogawa committed Aug 2, 2025
commit a39ebadf90ee9d3248b1ec561a342c84ffbeefc1
2 changes: 2 additions & 0 deletions src/ast/nodes/BinaryExpression.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import {
import { getRenderedLiteralValue } from '../utils/renderLiteralValue';
import ExternalVariable from '../variables/ExternalVariable';
import NamespaceVariable from '../variables/NamespaceVariable';
import SyntheticNamedExportVariable from '../variables/SyntheticNamedExportVariable';
import ExpressionStatement from './ExpressionStatement';
import type { LiteralValue } from './Literal';
import type * as NodeType from './NodeType';
Expand Down Expand Up @@ -109,6 +110,7 @@ export default class BinaryExpression extends NodeBase implements DeoptimizableE
if (this.operator === 'in' && this.right.variable instanceof NamespaceVariable) {
const [variable] = this.right.variable.context.traceExport(String(leftValue));
if (variable instanceof ExternalVariable) return UnknownValue;
if (variable instanceof SyntheticNamedExportVariable) return UnknownValue;
return !!variable;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
module.exports = defineTest({
description: 'disables optimization for synthetic named exports when using the in operator',
options: {
plugins: [
{
name: 'virtual-synthatic',
resolveId(id) {
if (id === 'virtual:synthetic') {
return '\0' + id;
}
},
load(id) {
if (id === '\0virtual:synthetic') {
const code = `
export const __moduleExports = { a: true };
`;
return {
code,
syntheticNamedExports: '__moduleExports'
};
}
}
}
]
},
solo: true
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
function _mergeNamespaces(n, m) {
m.forEach(function (e) {
e && typeof e !== 'string' && !Array.isArray(e) && Object.keys(e).forEach(function (k) {
if (k !== 'default' && !(k in n)) {
var d = Object.getOwnPropertyDescriptor(e, k);
Object.defineProperty(n, k, d.get ? d : {
enumerable: true,
get: function () { return e[k]; }
});
}
});
});
return Object.freeze(n);
}

const __moduleExports = { a: true };

var mod = /*#__PURE__*/_mergeNamespaces({
__proto__: null
}, [__moduleExports]);

if ('a' in mod) console.log(`'a' in mod`);
if ('b' in mod) console.log(`'b' in mod`);
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import * as mod from 'virtual:synthetic';

if ('a' in mod) console.log(`'a' in mod`)
if ('b' in mod) console.log(`'b' in mod`)
Loading