Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
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
13 changes: 12 additions & 1 deletion packages/commonjs/src/ast-utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,18 @@ const operators = {

'&&': (x) => isTruthy(x.left) && isTruthy(x.right),

'||': (x) => isTruthy(x.left) || isTruthy(x.right)
'||': (x) => {
const leftTruthy = isTruthy(x.left);
const rightTruthy = isTruthy(x.right);
// If left is definitely truthy, the whole expression is truthy
if (leftTruthy === true) return true;
// If both are definitely falsy, the whole expression is falsy
if (leftTruthy === false && rightTruthy === false) return false;
// If left is falsy but right is truthy, the whole expression is truthy
if (leftTruthy === false && rightTruthy === true) return true;
// Otherwise it's conditional
return null;
}
};

function not(value) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
var condition1 = typeof global !== 'undefined' && global.env && global.env.USE_FEATURE_A;
var condition2 = typeof global !== 'undefined' && global.env && global.env.USE_FEATURE_B;

function featureHandler() { return 'feature'; }
function defaultHandler() { return 'default'; }

if (condition1 || condition2) {
exports.handler = featureHandler;
} else {
exports.handler = defaultHandler;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import * as commonjsHelpers from "_commonjsHelpers.js";
import { __exports as input } from "\u0000fixtures/form/conditional-exports-or-conditional/input.js?commonjs-exports";

var hasRequiredInput;

function requireInput () {
if (hasRequiredInput) return input;
hasRequiredInput = 1;
var condition1 = typeof commonjsHelpers.commonjsGlobal !== 'undefined' && commonjsHelpers.commonjsGlobal.env && commonjsHelpers.commonjsGlobal.env.USE_FEATURE_A;
var condition2 = typeof commonjsHelpers.commonjsGlobal !== 'undefined' && commonjsHelpers.commonjsGlobal.env && commonjsHelpers.commonjsGlobal.env.USE_FEATURE_B;

function featureHandler() { return 'feature'; }
function defaultHandler() { return 'default'; }

if (condition1 || condition2) {
input.handler = featureHandler;
} else {
input.handler = defaultHandler;
}
return input;
}

export { requireInput as __require };
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
var crypto = (typeof global !== 'undefined' && global.crypto) || null;

function randomFill() { return 'randomFill'; }
function randomFillSync() { return 'randomFillSync'; }
function oldBrowser() { throw new Error('not supported'); }

if ((crypto && crypto.getRandomValues) || false) {
exports.randomFill = randomFill;
exports.randomFillSync = randomFillSync;
} else {
exports.randomFill = oldBrowser;
exports.randomFillSync = oldBrowser;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import * as commonjsHelpers from "_commonjsHelpers.js";
import { __exports as input } from "\u0000fixtures/form/conditional-exports-or-false/input.js?commonjs-exports";

var hasRequiredInput;

function requireInput () {
if (hasRequiredInput) return input;
hasRequiredInput = 1;
var crypto = (typeof commonjsHelpers.commonjsGlobal !== 'undefined' && commonjsHelpers.commonjsGlobal.crypto) || null;

function randomFill() { return 'randomFill'; }
function randomFillSync() { return 'randomFillSync'; }
function oldBrowser() { throw new Error('not supported'); }

if ((crypto && crypto.getRandomValues) || false) {
input.randomFill = randomFill;
input.randomFillSync = randomFillSync;
} else {
input.randomFill = oldBrowser;
input.randomFillSync = oldBrowser;
}
return input;
}

export { requireInput as __require };
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
var crypto = (typeof global !== 'undefined' && global.crypto) || null;

function secureHandler() { return 'secure'; }
function fallbackHandler() { return 'fallback'; }

if ((crypto && crypto.getRandomValues) || null) {
exports.handler = secureHandler;
} else {
exports.handler = fallbackHandler;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import * as commonjsHelpers from "_commonjsHelpers.js";
import { __exports as input } from "\u0000fixtures/form/conditional-exports-or-null/input.js?commonjs-exports";

var hasRequiredInput;

function requireInput () {
if (hasRequiredInput) return input;
hasRequiredInput = 1;
var crypto = (typeof commonjsHelpers.commonjsGlobal !== 'undefined' && commonjsHelpers.commonjsGlobal.crypto) || null;

function secureHandler() { return 'secure'; }
function fallbackHandler() { return 'fallback'; }

if ((crypto && crypto.getRandomValues) || null) {
input.handler = secureHandler;
} else {
input.handler = fallbackHandler;
}
return input;
}

export { requireInput as __require };
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
var condition = typeof global !== 'undefined' && global.env && global.env.NODE_ENV;

function prodHandler() { return 'production'; }
function defaultHandler() { return 'default'; }

if (condition || true) {
exports.handler = prodHandler;
} else {
exports.handler = defaultHandler;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import * as commonjsHelpers from "_commonjsHelpers.js";
import { __exports as input } from "\u0000fixtures/form/conditional-exports-or-true/input.js?commonjs-exports";

var hasRequiredInput;

function requireInput () {
if (hasRequiredInput) return input;
hasRequiredInput = 1;
var condition = typeof commonjsHelpers.commonjsGlobal !== 'undefined' && commonjsHelpers.commonjsGlobal.env && commonjsHelpers.commonjsGlobal.env.NODE_ENV;

function prodHandler() { return 'production'; }
function defaultHandler() { return 'default'; }

if (condition || true) {
input.handler = prodHandler;
} else {
input.handler = defaultHandler;
}
return input;
}

export { requireInput as __require };
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
var condition = typeof global !== 'undefined' && global.env && global.env.DEBUG;

function enabledHandler() { return 'enabled'; }
function disabledHandler() { return 'disabled'; }

if (true || condition) {
exports.handler = enabledHandler;
} else {
exports.handler = disabledHandler;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import * as commonjsHelpers from "_commonjsHelpers.js";
import { __exports as input } from "\u0000fixtures/form/conditional-exports-true-or-conditional/input.js?commonjs-exports";

var hasRequiredInput;

function requireInput () {
if (hasRequiredInput) return input;
hasRequiredInput = 1;
var condition = typeof commonjsHelpers.commonjsGlobal !== 'undefined' && commonjsHelpers.commonjsGlobal.env && commonjsHelpers.commonjsGlobal.env.DEBUG;

function enabledHandler() { return 'enabled'; }
function disabledHandler() { return 'disabled'; }

if (true || condition) {
input.handler = enabledHandler;
} else {
exports.handler = disabledHandler;
}
return input;
}

export { requireInput as __require };