diff --git a/packages/ses/README.md b/packages/ses/README.md index eafa752ae6..474750b072 100644 --- a/packages/ses/README.md +++ b/packages/ses/README.md @@ -419,7 +419,9 @@ A compiled static module record has the following shape: 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)` + - `importMeta` is a null-prototype object with keys transferred from `meta` + property in the envelope returned by importHook and/or mutated by + calling `importMetaHook(moduleSpecifier, 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. diff --git a/packages/ses/src/module-instance.js b/packages/ses/src/module-instance.js index 697f8dbf09..0e8caf26e6 100644 --- a/packages/ses/src/module-instance.js +++ b/packages/ses/src/module-instance.js @@ -127,14 +127,14 @@ export const makeModuleInstance = ( compartment, moduleSpecifier, staticModuleRecord, - meta: moduleRecordMeta, + importMeta: moduleRecordMeta, } = moduleRecord; const { reexports: exportAlls = [], __syncModuleProgram__: functorSource, __fixedExportMap__: fixedExportMap = {}, __liveExportMap__: liveExportMap = {}, - __usesImportMeta__: usesImportMeta = false, + __needsImportMeta__: needsImportMeta = false, } = staticModuleRecord; const compartmentFields = weakmapGet(privateFields, compartment); @@ -169,8 +169,8 @@ export const makeModuleInstance = ( if (moduleRecordMeta) { assign(importMeta, moduleRecordMeta); } - if (usesImportMeta && importMetaHook) { - importMetaHook(importMeta); + if (needsImportMeta && importMetaHook) { + importMetaHook(moduleSpecifier, importMeta); } // {_localName_: [{get, set, notify}]} used to merge all the export updaters. diff --git a/packages/ses/src/module-load.js b/packages/ses/src/module-load.js index aafd37f83e..625b087c94 100644 --- a/packages/ses/src/module-load.js +++ b/packages/ses/src/module-load.js @@ -63,7 +63,7 @@ const loadRecord = async ( pendingJobs, moduleLoads, errors, - meta, + importMeta, ) => { const { resolveHook, moduleRecords } = weakmapGet( compartmentPrivateFields, @@ -81,7 +81,7 @@ const loadRecord = async ( staticModuleRecord, moduleSpecifier, resolvedImports, - meta, + importMeta, }); // Enqueue jobs to load this module's shallow dependencies. @@ -183,7 +183,7 @@ const loadWithoutErrorAnnotation = async ( compartment: aliasCompartment = compartment, specifier: aliasSpecifier = moduleSpecifier, record: aliasModuleRecord, - meta, + importMeta, } = staticModuleRecord; const aliasRecord = await loadRecord( @@ -195,7 +195,7 @@ const loadWithoutErrorAnnotation = async ( pendingJobs, moduleLoads, errors, - meta, + importMeta, ); mapSet(moduleRecords, moduleSpecifier, aliasRecord); return aliasRecord; diff --git a/packages/ses/test/node.js b/packages/ses/test/node.js index 67b82b46d3..10583ba378 100644 --- a/packages/ses/test/node.js +++ b/packages/ses/test/node.js @@ -63,9 +63,9 @@ export const makeLocator = root => { }; }; -const wrapImporterWithMeta = (importer, meta) => async specifier => { +const wrapImporterWithMeta = (importer, importMeta) => async specifier => { const moduleRecord = await importer(specifier); - return { record: moduleRecord, meta }; + return { record: moduleRecord, importMeta }; }; // makeNodeImporter conveniently curries makeImporter with a Node.js style diff --git a/packages/ses/test/test-import.js b/packages/ses/test/test-import.js index 93cd7f3b5c..c46a630045 100644 --- a/packages/ses/test/test-import.js +++ b/packages/ses/test/test-import.js @@ -602,7 +602,7 @@ test('importMetaHook', async t => { name: 'https://example.com', resolveHook: resolveNode, importHook: makeImportHook('https://example.com'), - importMetaHook: meta => { + importMetaHook: (_moduleSpecifier, meta) => { meta.url = 'https://example.com/index.js'; }, }, @@ -632,7 +632,7 @@ test('importMetaHook and meta from record', async t => { importHook: makeImportHook('https://example.com', { meta: { url: 'https://example.com/index.js' }, }), - importMetaHook: meta => { + importMetaHook: (_moduleSpecifier, meta) => { meta.url += '?foo'; meta.isStillMutableHopefully = 1; }, diff --git a/packages/static-module-record/src/babelPlugin.js b/packages/static-module-record/src/babelPlugin.js index 1ece31f27f..1f7ce62b92 100644 --- a/packages/static-module-record/src/babelPlugin.js +++ b/packages/static-module-record/src/babelPlugin.js @@ -300,7 +300,7 @@ function makeModulePlugins(options) { path.node.meta.name === 'import' && path.node.property.name === 'meta' ) { - importMeta.uttered = true; + importMeta.present = true; path.replaceWithMultiple([ replace(path.node, hiddenIdentifier(h.HIDDEN_META)), ]); diff --git a/packages/static-module-record/src/hidden.js b/packages/static-module-record/src/hidden.js index a8208b64c0..8a08920613 100644 --- a/packages/static-module-record/src/hidden.js +++ b/packages/static-module-record/src/hidden.js @@ -5,7 +5,9 @@ export const HIDDEN_IMPORT = `${HIDDEN_PREFIX}import`; export const HIDDEN_IMPORT_SELF = `${HIDDEN_PREFIX}importSelf`; export const HIDDEN_IMPORTS = `${HIDDEN_PREFIX}imports`; export const HIDDEN_ONCE = `${HIDDEN_PREFIX}once`; -export const HIDDEN_META = `${HIDDEN_PREFIX}import_meta`; +// HIDDEN_META is used to replace `import.meta`. The value fits the original +// length so it doesn’t displace the column number of following text +export const HIDDEN_META = `${HIDDEN_PREFIX}___meta`; export const HIDDEN_LIVE = `${HIDDEN_PREFIX}live`; export const HIDDEN_IDENTIFIERS = [ HIDDEN_A, diff --git a/packages/static-module-record/src/static-module-record.js b/packages/static-module-record/src/static-module-record.js index 138cf604e9..40d1463b94 100644 --- a/packages/static-module-record/src/static-module-record.js +++ b/packages/static-module-record/src/static-module-record.js @@ -51,7 +51,7 @@ export function StaticModuleRecord(source, url) { liveExportMap, fixedExportMap, exportAlls, - importMetaUttered, + needsImportMeta, } = analyzeModule({ string: source, url }); this.imports = freeze([...keys(imports)].sort()); this.exports = freeze( @@ -61,6 +61,6 @@ export function StaticModuleRecord(source, url) { this.__syncModuleProgram__ = functorSource; this.__liveExportMap__ = liveExportMap; this.__fixedExportMap__ = fixedExportMap; - this.__usesImportMeta__ = importMetaUttered; + this.__needsImportMeta__ = needsImportMeta; freeze(this); } diff --git a/packages/static-module-record/src/transform-analyze.js b/packages/static-module-record/src/transform-analyze.js index 8daaf3cd78..72977b3f56 100644 --- a/packages/static-module-record/src/transform-analyze.js +++ b/packages/static-module-record/src/transform-analyze.js @@ -26,7 +26,7 @@ const makeCreateStaticRecord = transformSource => importSources: Object.create(null), importDecls: [], // enables passing import.meta usage hints up. - importMeta: { uttered: false }, + importMeta: { present: false }, }; if (moduleSource.startsWith('#!')) { // Comment out the shebang lines. @@ -90,7 +90,7 @@ const makeCreateStaticRecord = transformSource => imports: freeze(sourceOptions.imports), liveExportMap: freeze(sourceOptions.liveExportMap), fixedExportMap: freeze(sourceOptions.fixedExportMap), - importMetaUttered: sourceOptions.importMeta.uttered, + needsImportMeta: sourceOptions.importMeta.present, functorSource, }); return moduleAnalysis; diff --git a/packages/static-module-record/test/benchmark-babel-plugin.js b/packages/static-module-record/test/benchmark-babel-plugin.js index f0d3d0091a..e896eccba1 100644 --- a/packages/static-module-record/test/benchmark-babel-plugin.js +++ b/packages/static-module-record/test/benchmark-babel-plugin.js @@ -33,7 +33,7 @@ const freshOptions = () => { hoistedDecls: [], importSources: Object.create(null), importDecls: [], - importMeta: { uttered: false }, + importMeta: { present: false }, }; }; diff --git a/packages/static-module-record/test/fixtures/large.js b/packages/static-module-record/test/fixtures/large.js index 17946914a8..769ef77fb7 100644 --- a/packages/static-module-record/test/fixtures/large.js +++ b/packages/static-module-record/test/fixtures/large.js @@ -338,7 +338,7 @@ function makeModulePlugins(options) { path.node.property.name === 'meta' ) { if (doAnalyze) { - importMeta.uttered = true; + importMeta.present = true; } if (doTransform) { console.error('at least I tried') diff --git a/packages/static-module-record/test/test-static-module-record.js b/packages/static-module-record/test/test-static-module-record.js index 29848dc3d3..1684b76c08 100644 --- a/packages/static-module-record/test/test-static-module-record.js +++ b/packages/static-module-record/test/test-static-module-record.js @@ -570,13 +570,13 @@ test('import meta in export', t => { }); t.is(namespace.a, 'ok file://meta.url'); }); -test('import meta member uttered', t => { +test('import meta member present', t => { const record = new StaticModuleRecord(`const a = import.meta.url`); - t.is(record.__usesImportMeta__, true); + t.is(record.__needsImportMeta__, true); }); -test('import meta uttered', t => { +test('import meta present', t => { const record = new StaticModuleRecord(`const a = import.meta`); - t.is(record.__usesImportMeta__, true); + t.is(record.__needsImportMeta__, true); }); test('export names', t => { diff --git a/yarn.lock b/yarn.lock index c390735bab..df0681798b 100644 --- a/yarn.lock +++ b/yarn.lock @@ -9644,13 +9644,6 @@ pkg-dir@^4.2.0: dependencies: find-up "^4.0.0" -pkg-up@^2.0.0: - version "2.0.0" - resolved "https://registry.yarnpkg.com/pkg-up/-/pkg-up-2.0.0.tgz#c819ac728059a461cab1c3889a2be3c49a004d7f" - integrity sha1-yBmscoBZpGHKscOImivjxJoATX8= - dependencies: - find-up "^2.1.0" - platform@^1.3.3: version "1.3.6" resolved "https://registry.yarnpkg.com/platform/-/platform-1.3.6.tgz#48b4ce983164b209c2d45a107adb31f473a6e7a7"