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

Flow parser should support import.meta #6913

Closed
rtsao opened this issue Sep 20, 2018 · 8 comments
Closed

Flow parser should support import.meta #6913

rtsao opened this issue Sep 20, 2018 · 8 comments

Comments

@rtsao
Copy link
Contributor

rtsao commented Sep 20, 2018

import.meta is a stage 3 proposal that has shipped in Chrome, Firefox, and Node 10. Flow should be able to parse this syntax.

https://flow.org/try/#0PQKgBAAgZgNg9gdzCYAoVBLAtgBzgJwBcA6LAU0IENiBXfGAbiA

wchargin added a commit to wchargin/flow that referenced this issue Oct 2, 2018
Summary:
Resolves facebook#6913. As with `new.target`, we can parse the expression, but
we fail to typecheck it. Clients can use a suppression comment to ignore
uses of `import.meta` in an otherwise valid file.

The parse error message on inputs like `import.notMeta` was chosen to be
consistent with the message emitted by Babylon.

Test Plan:
Unit tests added, and all existing tests pass.

wchargin-branch: parse-import-meta
wchargin added a commit to wchargin/flow that referenced this issue Oct 2, 2018
Summary:
Resolves facebook#6913. As with `new.target`, we can parse the expression, but
we fail to typecheck it. Clients can use a suppression comment to ignore
uses of `import.meta` in an otherwise valid file.

The parse error message on inputs like `import.notMeta` was chosen to be
consistent with the message emitted by Babylon.

Test Plan:
Unit tests added, and all existing tests pass.

wchargin-branch: parse-import-meta
@wchargin
Copy link
Contributor

wchargin commented Oct 2, 2018

Implemented in #6958.

@wchargin
Copy link
Contributor

Friendly ping on that PR. I know some folks were interested in this and
wouldn’t want the diff to go stale.

@mgtitimoli
Copy link

We didn't get a response from your previously friendly ping @wchargin, so I'm pinging again hoping we are gonna get some response now :)

@fredericgermain
Copy link

import.meta.url is the official way to have __dirname in ESM node implementation. ES6 Module support is very strict in node.
https://nodejs.org/docs/latest/api/esm.html

We can't migrate to modules while flow is not supporting it (flow-remove-types makes an error on this syntax too). Or we have to get around the __dirname variable.

@Kapelianovych
Copy link
Contributor

It's not implemeted yet( Though import.meta is living standard already.

@unphased
Copy link

I cannot use flow because use of import.meta breaks flow parsing of the entire source file from that point forward...

Yes, I am using import.meta.url to obtain __dirname in node scripts.

@strager
Copy link

strager commented Jul 23, 2020

I use this ugly workaround to make both Flow and Node.js happy:

// $FlowFixMe
let __filename /*: string */ = url.fileURLToPath(import /*:: ("") */.meta.url);

I don't know if this works with flow-removes-types or Babel, though.

@ancms2600
Copy link

ancms2600 commented Aug 31, 2021

The above workaround didn't quite work for me but this does:

import { dirname } from 'path';
import { fileURLToPath } from 'url';
const __dirname/*:string*/ = dirname(fileURLToPath(/*::(*/import/*::('fs'):any)*/.meta.url)); // facebook/flow PR#6958

facebook-github-bot pushed a commit that referenced this issue Sep 7, 2021
Summary:
Rather than give an `unsupported-syntax` error when `new.target` or `import.meta` are used, type them as `mixed`.
This is a bit more useful (and still safe).

Fixes #1152
Reference to #6913

Changelog: [feature] Added type checking support for `new.target` and `import.meta` as `mixed`

Reviewed By: mroch

Differential Revision: D30745294

fbshipit-source-id: 1026ddde29936b7c5c8f81daf3a7b2515a514679
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

9 participants