fix(vite): cover more commonjs cases (#3465)

Fixes https://github.com/denoland/fresh/issues/3463
Fixes https://github.com/denoland/fresh/issues/3449
This commit is contained in:
Marvin Hagemeister
2025-09-19 18:36:51 +02:00
committed by GitHub
parent a6016fc045
commit 9b83a1e1b3
9 changed files with 349 additions and 83 deletions
@@ -34,32 +34,6 @@ export function codeEvalPlugin(
}
},
},
CallExpression: {
enter(path) {
if (
t.isMemberExpression(path.node.callee) &&
t.isIdentifier(path.node.callee.object) &&
t.isIdentifier(path.node.callee.property) &&
path.node.callee.object.name === "Object" &&
path.node.callee.property.name === "defineProperty" &&
path.node.arguments.length >= 2
) {
const args = path.node.arguments;
if (
t.isIdentifier(args[0]) && args[0].name === "exports" ||
t.isMemberExpression(args[0]) &&
t.isIdentifier(args[0].object) &&
t.isIdentifier(args[0].property) &&
args[0].object.name === "module" &&
args[0].property.name === "exports" &&
t.isStringLiteral(args[1]) && args[1].value === "native"
) {
path.remove();
}
}
},
},
},
};
};