Skip to content

Commit

Permalink
use __cjsModule
Browse files Browse the repository at this point in the history
  • Loading branch information
guybedford committed Jul 6, 2024
1 parent 92a2241 commit e7bd13a
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 8 deletions.
6 changes: 3 additions & 3 deletions test/fixtures/requireesm-brand-nowrap/expected.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import * as _nobinding2 from "nobinding";
var _nobinding = _nobinding2.__cjs ? _nobinding2.default : "default" in _nobinding2 && !_nobinding2.__esModule ? new Proxy(_nobinding2, {
var _nobinding = _nobinding2.__cjsModule ? _nobinding2.default : "default" in _nobinding2 && !_nobinding2.__esModule ? new Proxy(_nobinding2, {
get: (t, k, r) => k === "__esModule" || Reflect.get(t, k, r),
has: (t, k) => k === "__esModule" || Reflect.has(t, k)
}) : _nobinding2;
import * as _fs2 from "fs";
var _fs = _fs2.__cjs ? _fs2.default : "default" in _fs2 && !_fs2.__esModule ? new Proxy(_fs2, {
var _fs = _fs2.__cjsModule ? _fs2.default : "default" in _fs2 && !_fs2.__esModule ? new Proxy(_fs2, {
get: (t, k, r) => k === "__esModule" || Reflect.get(t, k, r),
has: (t, k) => k === "__esModule" || Reflect.has(t, k)
}) : _fs2;
Expand All @@ -18,4 +18,4 @@ const {
} = _thing;
readFileSync("asdf");
export default {};
export const __cjs = true;
export const __cjsModule = true;
4 changes: 2 additions & 2 deletions test/fixtures/requireesm-brand/expected.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@ var exports = {},
export function dew() {
if (_dewExec) return exports;
_dewExec = true;
var _nobinding = _nobinding2.__cjs ? _nobinding2.default : "default" in _nobinding2 && !_nobinding2.__esModule ? new Proxy(_nobinding2, {
var _nobinding = _nobinding2.__cjsModule ? _nobinding2.default : "default" in _nobinding2 && !_nobinding2.__esModule ? new Proxy(_nobinding2, {
get: (t, k, r) => k === "__esModule" || Reflect.get(t, k, r),
has: (t, k) => k === "__esModule" || Reflect.has(t, k)
}) : _nobinding2;
var _fs = _fs2.__cjs ? _fs2.default : "default" in _fs2 && !_fs2.__esModule ? new Proxy(_fs2, {
var _fs = _fs2.__cjsModule ? _fs2.default : "default" in _fs2 && !_fs2.__esModule ? new Proxy(_fs2, {
get: (t, k, r) => k === "__esModule" || Reflect.get(t, k, r),
has: (t, k) => k === "__esModule" || Reflect.has(t, k)
}) : _fs2;
Expand Down
6 changes: 3 additions & 3 deletions transform-cjs-dew.js
Original file line number Diff line number Diff line change
Expand Up @@ -792,7 +792,7 @@ module.exports = function ({ types: t }) {
if (dep.ns && dep.mid.name !== dep.id.name) {
unshiftBody(path, t.variableDeclaration('var', [
t.variableDeclarator(dep.id, t.conditionalExpression(
t.memberExpression(dep.mid, t.identifier('__cjs')),
t.memberExpression(dep.mid, t.identifier('__cjsModule')),
t.memberExpression(dep.mid, t.identifier('default')),
t.conditionalExpression(
t.logicalExpression('&&', t.binaryExpression('in', t.stringLiteral('default'), dep.mid), t.unaryExpression('!', t.memberExpression(dep.mid, t.identifier('__esModule')))),
Expand Down Expand Up @@ -852,7 +852,7 @@ module.exports = function ({ types: t }) {
}

if (state.opts.cjsMarker) {
exportDeclarations.push(t.variableDeclarator(t.identifier('__cjs'), t.booleanLiteral(true)));
exportDeclarations.push(t.variableDeclarator(t.identifier('__cjsModule'), t.booleanLiteral(true)));
}

if (exportDeclarations.length)
Expand All @@ -879,7 +879,7 @@ module.exports = function ({ types: t }) {
innerWrapper.push(
t.variableDeclaration('var', [
t.variableDeclarator(dep.id, t.conditionalExpression(
t.memberExpression(dep.mid, t.identifier('__cjs')),
t.memberExpression(dep.mid, t.identifier('__cjsModule')),
t.memberExpression(dep.mid, t.identifier('default')),
t.conditionalExpression(
t.logicalExpression('&&', t.binaryExpression('in', t.stringLiteral('default'), dep.mid), t.unaryExpression('!', t.memberExpression(dep.mid, t.identifier('__esModule')))),
Expand Down

0 comments on commit e7bd13a

Please sign in to comment.