Skip to content

Commit

Permalink
feat(compartment-mapper): Precompiled ESM
Browse files Browse the repository at this point in the history
This anti-climactic change pre-compiles ESM and executes the compiled
static module records from an archive.

Refs #673
  • Loading branch information
kriskowal committed Apr 26, 2021
1 parent cb19ddc commit eb2fcc4
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 3 deletions.
2 changes: 2 additions & 0 deletions packages/compartment-mapper/NEWS.md
Expand Up @@ -4,6 +4,8 @@ User-visible changes to the compartment mapper:

* Reenables CommonJS support with a fast lexer and without a dependency on
Babel.
* The Compartment Mapper now produces archives containing SES-shim
pre-compiled StaticModuleRecords for ESM instead of the source.
* *BREAKING*: This release parallels a breaking upgrade for SES to version
0.13. This entails the removal of `StaticModuleRecord` from SES, and the
removal of the `ses/lockdown` light layering (there is no heavy layer to
Expand Down
1 change: 1 addition & 0 deletions packages/compartment-mapper/package.json
Expand Up @@ -27,6 +27,7 @@
"dependencies": {
"@endo/cjs-module-analyzer": "^0.1.0",
"@endo/static-module-record": "^0.1.0",
"@endo/syrup": "^0.1.0",
"@endo/zip": "^0.1.0",
"ses": "^0.12.7"
},
Expand Down
23 changes: 21 additions & 2 deletions packages/compartment-mapper/src/parse.js
Expand Up @@ -3,6 +3,7 @@

import { StaticModuleRecord } from '@endo/static-module-record';
import { analyzeCommonJS } from '@endo/cjs-module-analyzer';
import { encodeSyrup, decodeSyrup } from '@endo/syrup';
import { parseExtension } from './extension.js';
import * as json from './json.js';

Expand Down Expand Up @@ -33,10 +34,27 @@ export const parseMjs = async (
_packageLocation,
) => {
const source = textDecoder.decode(bytes);
const record = new StaticModuleRecord(source, location);
const pre = encodeSyrup(record);
return {
parser: 'mjs',
parser: 'pre',
bytes: pre,
record,
};
};

/** @type {ParseFn} */
export const parsePre = async (
bytes,
_specifier,
location,
_packageLocation,
) => {
const record = decodeSyrup(bytes, { name: location });
return {
parser: 'pre',
bytes,
record: new StaticModuleRecord(source, location),
record,
};
};

Expand Down Expand Up @@ -131,6 +149,7 @@ export const parseCjs = async (
export const parserForLanguage = {
mjs: parseMjs,
cjs: parseCjs,
pre: parsePre,
json: parseJson,
};

Expand Down
2 changes: 1 addition & 1 deletion packages/compartment-mapper/src/types.js
Expand Up @@ -62,7 +62,7 @@
*/

/**
* @typedef {'mjs' | 'cjs' | 'json'} ParserDescriptor
* @typedef {'mjs' | 'cjs' | 'json' | 'pre'} ParserDescriptor
*/

// /////////////////////////////////////////////////////////////////////////////
Expand Down

0 comments on commit eb2fcc4

Please sign in to comment.