Skip to content

Commit

Permalink
fix: rename meta to importMeta, fix detection to detect import.meta n…
Browse files Browse the repository at this point in the history
…ot import.meta.something
  • Loading branch information
naugtur committed May 19, 2022
1 parent dfedd96 commit 8970f45
Show file tree
Hide file tree
Showing 7 changed files with 27 additions and 16 deletions.
2 changes: 1 addition & 1 deletion packages/compartment-mapper/src/bundle.js
Original file line number Diff line number Diff line change
Expand Up @@ -332,7 +332,7 @@ ${importsCellSetter(__liveExportMap__, index)}\
onceVar: {
${importsCellSetter(__fixedExportMap__, index)}\
},
meta: {
importMeta: {
url: '${packageLocation}'\
},
});
Expand Down
3 changes: 2 additions & 1 deletion packages/ses/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -412,13 +412,14 @@ A compiled static module record has the following shape:
an initialization record and initializes the module.
This property distinguishes this type of module record.
The name implies a future record type that supports top-level await.
- An initialization record has the properties `imports`, `liveVar`, and
- An initialization record has the properties `imports`, `liveVar`, `importMeta` and
`onceVar`.
- `imports` is a function that accepts a map from partial import
module specifiers to maps from names that the corresponding module
exports to notifier functions.
A notifier function accepts an update function and registers
to receive updates for the value exported by the other module.
- `importMeta` is a null-prototype object with keys transferred from `meta` property in the envelope returned by importHook and/or mutated by calling `importMetaHook(importMeta)`
- `liveVar` is a record that maps names exported by this module
to a function that may be called to initialize or update
the corresponding value in another module.
Expand Down
2 changes: 2 additions & 0 deletions packages/static-module-record/DESIGN.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ moduleFunctor({
imports(importedVariableUpdaters) { /* ... */ },
liveVar: exportedVariableUpdaters,
onceVar: exportedConstantEmitters,
importMeta: Object.create(null)
});
```

Expand Down Expand Up @@ -85,6 +86,7 @@ line numbers.
imports: $h_imports,
liveVar: $h_live,
onceVar: $h_once,
importMeta: $h_import_meta,
}) => {
let foo, bar, fizz, buzz, colour;
$h_imports(
Expand Down
12 changes: 8 additions & 4 deletions packages/static-module-record/src/babelPlugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ function makeModulePlugins(options) {
importDecls,
importSources,
liveExportMap,
importMetaProperties,
importMeta,
} = options;

if (sourceType !== 'module') {
Expand Down Expand Up @@ -311,9 +311,13 @@ function makeModulePlugins(options) {

const moduleVisitor = (doAnalyze, doTransform) => ({
MetaProperty(path) {
if (path.node.meta.name === 'import') {
if (doAnalyze && path.parentPath.isMemberExpression()) {
importMetaProperties.add(path.parentPath.node.property.name);
if (
path.node.meta &&
path.node.meta.name === 'import' &&
path.node.property.name === 'meta'
) {
if (doAnalyze) {
importMeta.uttered = true;
}
if (doTransform) {
path.replaceWithMultiple([
Expand Down
6 changes: 2 additions & 4 deletions packages/static-module-record/src/static-module-record.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ export function StaticModuleRecord(source, url) {
liveExportMap,
fixedExportMap,
exportAlls,
importMetaProperties,
importMetaUttered,
} = analyzeModule({ string: source, url });
this.imports = freeze([...keys(imports)].sort());
this.exports = freeze(
Expand All @@ -61,8 +61,6 @@ export function StaticModuleRecord(source, url) {
this.__syncModuleProgram__ = functorSource;
this.__liveExportMap__ = liveExportMap;
this.__fixedExportMap__ = fixedExportMap;
this.__usesImportMeta__ = importMetaProperties.length > 0;
// useful for knowing if resolve or any other expensive features are used
this.__usesImportMetaProperties__ = importMetaProperties;
this.__usesImportMeta__ = importMetaUttered;
freeze(this);
}
8 changes: 3 additions & 5 deletions packages/static-module-record/src/transform-analyze.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ const makeCreateStaticRecord = transformSource =>
importSources: Object.create(null),
importDecls: [],
// enables passing import.meta usage hints up.
importMetaProperties: new Set(),
importMeta: { uttered: false },
};
if (moduleSource.startsWith('#!')) {
// Comment out the shebang lines.
Expand Down Expand Up @@ -114,7 +114,7 @@ const makeCreateStaticRecord = transformSource =>
imports: ${h.HIDDEN_IMPORTS}, \
liveVar: ${h.HIDDEN_LIVE}, \
onceVar: ${h.HIDDEN_ONCE}, \
meta: ${h.HIDDEN_META}, \
importMeta: ${h.HIDDEN_META}, \
}) => { \
${preamble} \
${scriptSource}
Expand All @@ -129,9 +129,7 @@ const makeCreateStaticRecord = transformSource =>
imports: freeze(sourceOptions.imports),
liveExportMap: freeze(sourceOptions.liveExportMap),
fixedExportMap: freeze(sourceOptions.fixedExportMap),
importMetaProperties: freeze(
Array.from(sourceOptions.importMetaProperties),
),
importMetaUttered: sourceOptions.importMeta.uttered,
functorSource,
});
return moduleAnalysis;
Expand Down
10 changes: 9 additions & 1 deletion packages/static-module-record/test/test-static-module-record.js
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ function initialize(t, source, options = {}) {
imports: updateImports,
liveVar: liveUpdaters,
onceVar: onceUpdaters,
meta: { url: 'file://meta.url' },
importMeta: { url: 'file://meta.url' },
});

return { record, namespace, log, updaters };
Expand Down Expand Up @@ -568,6 +568,14 @@ test.failing('import meta in export', t => {
});
t.is(namespace.result, 'ok file://meta.url');
});
test('import meta member uttered', t => {
const record = new StaticModuleRecord(`const a = import.meta.url`);
t.is(record.__usesImportMeta__, true);
});
test('import meta uttered', t => {
const record = new StaticModuleRecord(`const a = import.meta`);
t.is(record.__usesImportMeta__, true);
});

test('export names', t => {
const { namespace } = initialize(
Expand Down

0 comments on commit 8970f45

Please sign in to comment.