Skip to content

js.raw doesn't accept import.meta #4931

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

Closed
cometkim opened this issue Feb 2, 2021 · 5 comments
Closed

js.raw doesn't accept import.meta #4931

cometkim opened this issue Feb 2, 2021 · 5 comments

Comments

@cometkim
Copy link
Member

cometkim commented Feb 2, 2021

The import.meta is a widely supported standard by modern browsers.

I recently tried to use it for HMR on Snowpack, but the ReScript compiler ([email protected]) didn't seem to support it.

   8 │
   9 │ %%raw(`
  10 │ if (import.meta.hot) {
  11 │   import.meta.hot.accept();
  12 │ }

  Unexpected token `.`, expected the token `(`

FAILED: cannot make progress due to previous errors.
>>>> Finish compiling(exit: 1)

It seems that this is still not implemented on the Flow side. facebook/flow#6913

Can we add support for this separately?

@bobzhang
Copy link
Member

bobzhang commented Feb 3, 2021

we will have a flag to loosen the checks

@bobzhang
Copy link
Member

bobzhang commented Feb 3, 2021

we turned flow parse error into a warning 103 which you can turned off:

@@config({
  flags: ["-w", "-103"],
})

%%raw(`
if (import.meta.hot){
  console.log('es6')
}
`)

@bobzhang
Copy link
Member

bobzhang commented Feb 3, 2021

fixed in #4932

@TheSpyder
Copy link
Contributor

I can't get this to work in reasonml syntax? I've tried both [@config {flags: ["-w", "-103"]}] at the top of the file and [@warning "-103"] next to the raw definition.

The code generating the warning is:

  let currentDir: string =
    [%raw "import.meta.url"]->Path.dirname->String.sliceToEnd(~from="file://"->String.length);

(where Path comes from reason-nodejs and String is Js.String2)

@cometkim
Copy link
Member Author

cometkim commented Sep 2, 2021

at least the parsing error is now resolved: facebook/flow@0851b3e

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

No branches or pull requests

3 participants