Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 36.4k
esm: implement import.meta.main#32223
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Uh oh!
There was an error while loading. Please reload this page.
Changes from all commits
File filter
Filter by extension
Conversations
Uh oh!
There was an error while loading. Please reload this page.
Jump to
Uh oh!
There was an error while loading. Please reload this page.
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
| @@ -3,6 +3,8 @@ | ||||||
| /* global WebAssembly */ | ||||||
| const { | ||||||
| Boolean, | ||||||
| FunctionPrototypeBind, | ||||||
| JSONParse, | ||||||
| ObjectKeys, | ||||||
| SafeMap, | ||||||
| @@ -66,11 +68,12 @@ function initializeImportMeta(meta, { url }) { | ||||||
| // Alphabetical | ||||||
| if (experimentalImportMetaResolve) | ||||||
| meta.resolve = createImportMetaResolve(url); | ||||||
| meta.main = Boolean(this?.isMain); | ||||||
Member There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
Contributor There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is there a performance merit to this? or is it for brevity / for consistency? (out of interest) Member There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Both, and it avoids a primordial. | ||||||
| meta.url = url; | ||||||
| } | ||||||
| // Strategy for loading a standard JavaScript module | ||||||
| translators.set('module', async function moduleStrategy(url) { | ||||||
| translators.set('module', async function moduleStrategy(url, isMain) { | ||||||
| let { source } = await this._getSource( | ||||||
| url, { format: 'module' }, defaultGetSource); | ||||||
| source = `${source}`; | ||||||
| @@ -80,7 +83,9 @@ translators.set('module', async function moduleStrategy(url) { | ||||||
| debug(`Translating StandardModule ${url}`); | ||||||
| const module = new ModuleWrap(url, undefined, source, 0, 0); | ||||||
| moduleWrap.callbackMap.set(module, { | ||||||
| initializeImportMeta, | ||||||
| initializeImportMeta: isMain ? | ||||||
| FunctionPrototypeBind(initializeImportMeta, { isMain }) : | ||||||
Member There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
i believe an arrow is faster than binding | ||||||
| initializeImportMeta, | ||||||
| importModuleDynamically, | ||||||
| }); | ||||||
| return module; | ||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| import { mustCall } from '../common/index.mjs'; | ||
| import fixtures from '../common/fixtures.js'; | ||
| import assert from 'assert'; | ||
| assert.strictEqual(import.meta.main, true); | ||
| import(fixtures.path('/es-modules/import-meta-main.mjs')).then( | ||
| mustCall(({ isMain }) => { | ||
| assert.strictEqual(isMain, false); | ||
| }) | ||
| ); |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| export const isMain = import.meta.main; |
Uh oh!
There was an error while loading. Please reload this page.