Skip to content

Commit

Permalink
fix(compartment-mapper): add support for alternatives in exports defi…
Browse files Browse the repository at this point in the history
…nitions
  • Loading branch information
naugtur committed Apr 5, 2022
1 parent 1d9c17b commit 8ebd5cc
Show file tree
Hide file tree
Showing 13 changed files with 56 additions and 2 deletions.
9 changes: 9 additions & 0 deletions packages/compartment-mapper/src/infer-exports.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import { join, relativize } from './node-module-specifier.js';

const { entries, fromEntries } = Object;
const { isArray } = Array;

/**
* @param {string} name - the name of the referrer package.
Expand Down Expand Up @@ -34,6 +35,14 @@ function* interpretBrowserExports(name, exports) {
* @yields {[string, string]}
*/
function* interpretExports(name, exports, tags) {
if (isArray(exports)) {
yield* interpretExports(
name,
// Find one that produces non-empty result, discard result and use again
exports.find(ex => !interpretExports(name, ex, tags).next().done),
tags,
);
}
if (typeof exports === 'string') {
yield [name, relativize(exports)];
return;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ export const wrap = (moduleEnvironmentRecord, compartment, resolvedImports) => {
// the lexer.
if (exportsHaveBeenOverwritten) {
moduleEnvironmentRecord.default = finalExports;
keys(moduleEnvironmentRecord.default).forEach(prop => {
keys(moduleEnvironmentRecord.default || {}).forEach(prop => {
if (prop !== 'default')
moduleEnvironmentRecord[prop] = moduleEnvironmentRecord.default[prop];
});
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions packages/compartment-mapper/test/test-cjs-compat.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ const assertFixture = (t, { namespace }) => {
assertions.parserStruggles();
assertions.moduleWithCycle();
assertions.defaultChangesAfterExec();
assertions.packageNestedFile();

t.pass();
};
Expand Down

0 comments on commit 8ebd5cc

Please sign in to comment.