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
19 changes: 17 additions & 2 deletions packages/commonjs/src/ast-utils.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,19 @@
export { default as isReference } from 'is-reference';

function triStateAnd(a, b) {
if (a === false) return false;
if (b === false) return false;
if (a === true && b === true) return true;
return null;
}

function triStateOr(a, b) {
if (a === true) return true;
if (b === true) return true;
if (a === false && b === false) return false;
return null;
}

const operators = {
'==': (x) => equals(x.left, x.right, false),

Expand All @@ -11,9 +25,9 @@ const operators = {

'!': (x) => isFalsy(x.argument),

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

'||': (x) => isTruthy(x.left) || isTruthy(x.right)
'||': (x) => triStateOr(isTruthy(x.left), isTruthy(x.right))
};

function not(value) {
Expand Down Expand Up @@ -126,3 +140,4 @@ export function hasDefineEsmProperty(node) {
return false;
});
}

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 {
exports.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 };