Skip to content
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

import.meta: (Stage 3) #10

Open
babel-bot opened this issue Jul 10, 2017 · 7 comments
Open

import.meta: (Stage 3) #10

babel-bot opened this issue Jul 10, 2017 · 7 comments

Comments

@babel-bot
Copy link

babel-bot commented Jul 10, 2017

Original issue submitted by @hzoo in babel/babel#5832

Original issue submitted by @hzoo in babel/babylon#539

import.meta for stage 2 (Domenic Denicola) (@domenic)

Info

Proposed at TC39 Meeting: May 2017
Spec Repo: https://github.com/tc39/proposal-import-meta
Spec Text: https://tc39.github.io/proposal-import-meta/
Moved to Stage 3 at the Sept 2017 meeting

Example

(async () => {
  const response = await fetch(new URL("../hamsters.jpg", import.meta.url));
  const blob = await response.blob();

  const size = import.meta.scriptElement.dataset.size || 300;

  const image = new Image();
  image.src = URL.createObjectURL(blob);
  image.width = image.height = size;

  document.body.appendChild(image);
})();

Parsing

Transform

  • Not sure, maybe webpack should handle? Or in node?
@hzoo hzoo changed the title import.meta: Stage 2 import.meta: (Stage 2) Jul 27, 2017
@hzoo hzoo mentioned this issue Sep 28, 2017
11 tasks
@hzoo hzoo changed the title import.meta: (Stage 2) import.meta: (Stage 3) Sep 28, 2017
@jkrems
Copy link

jkrems commented Oct 16, 2017

Any preferences for what this should desugar to in a babel world? A possible default implementation would just create an empty Object.create(null) object per module. I assume that anything else would be making too many assumptions (outside of webpack doing its own thing).

@ljharb
Copy link
Member

ljharb commented Oct 16, 2017

I believe ModuleRecords should be frozen as well as being null objects.

@jkrems
Copy link

jkrems commented Oct 16, 2017

The import.meta object is an arbitrary object associated with a module, not the module record itself. The only thing the spec requires is that it was created as an ordinary object with null-prototype. The host may choose to freeze it but it's not required.

@jkrems
Copy link

jkrems commented Oct 16, 2017

See also "Will this be locked down": https://github.com/tc39/proposal-import-meta#will-this-object-be-locked-down-in-any-way

@jamiebuilds
Copy link

Since it's left up to the implementation, my opinion is that Babel should freeze it until either the spec is finalized or we discover a reason it can't be for Babel's purposes. We'll see what other implementations want to do and what the committee finally accepts.

@domenic
Copy link

domenic commented Oct 17, 2017

The spec is finalized; it won't be locked down.

@justinfagnani
Copy link

Regarding the transform:

Not sure, maybe webpack should handle? Or in node?

We're in need of a simple transform to replace import.meta with an object that has a url property based on the file's location on disk. When we have something I can ping this issue again to see if it'd be useful enough for other people to contribute.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

7 participants