Skip to content

Commit

Permalink
fix(compartment-mapper): add support for alternatives in exports defn…
Browse files Browse the repository at this point in the history
…itions (#1134)

* fix(compartment-mapper): add support for alternatives in exports definitions

* nicer looking search for non-empty export alternative
  • Loading branch information
naugtur committed Apr 5, 2022
1 parent 1d9c17b commit 6663f25
Show file tree
Hide file tree
Showing 13 changed files with 57 additions and 2 deletions.
10 changes: 10 additions & 0 deletions packages/compartment-mapper/src/infer-exports.js
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,15 @@ function* interpretBrowserExports(name, exports) {
* @yields {[string, string]}
*/
function* interpretExports(name, exports, tags) {
if (isArray(exports)) {
for (const section of exports) {
const results = [...interpretExports(name, section, tags)];
if (results.length > 0) {
yield* results;
break;
}
}
}
if (typeof exports === 'string') {
yield [name, relativize(exports)];
return;
Expand Down
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
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 6663f25

Please sign in to comment.