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

Repl has "Unexpected token ','" when both await and second argument to dynamic import are used #47463

Open
Jamesernator opened this issue Apr 7, 2023 · 1 comment
Labels
repl Issues and PRs related to the REPL subsystem.

Comments

@Jamesernator
Copy link

Version

v19.8.1

Platform

Linux 5.19.0-38-generic #39~22.04.1-Ubuntu SMP PREEMPT_DYNAMIC Fri Mar 17 21:16:15 UTC 2 x86_64 x86_64 x86_64 GNU/Linux

Subsystem

repl

What steps will reproduce the bug?

Try in the repl:

> let packageJSON = await import("./package.json", { assert: { type: "json" } })

Uncaught SyntaxError: 
let packageJSON = await import("./package.json", { assert: { type: "json" } })
                                               ^

Unexpected token ','

How often does it reproduce? Is there a required condition?

This happens consistently, curiously the features seem to work separately but not together:

// Both of these are fine:
> let p = import("./package.json", { assert: { type: "json" } });
> let p = await import("./package.json"); // Runtime error due to missing second arg

What is the expected behavior? Why is that the expected behavior?

This should parse as it is perfectly valid syntax (and it works without await).

What do you see instead?

The error:

Uncaught SyntaxError: 
let packageJSON = await import("./package.json", { assert: { type: "json" } })
                                               ^

Unexpected token ','

Additional information

There was recently changes to the import assertions proposal to change assert to with (along with changes to affect runtime), but even with that the parsing of the above would be the same anyway.

@VoltrexKeyva VoltrexKeyva added the repl Issues and PRs related to the REPL subsystem. label Apr 8, 2023
@aduh95
Copy link
Contributor

aduh95 commented Apr 13, 2023

This should parse as it is perfectly valid syntax

It's not valid syntax according to the current ES spec – because the Import Attributes proposal is stage 3 only.

it works without await

The reason for this lack of consistency is because when you pass a string that contains await, it goes through Acorn, and I think Acorn only supports stage 4 syntax.

Not sure what to do about that, I guess if you are using await on the REPL, you have to accept Acorn limitations, I don't think there's a way around that.

@RedYetiDev RedYetiDev mentioned this issue Jun 24, 2024
3 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
repl Issues and PRs related to the REPL subsystem.
Projects
None yet
Development

No branches or pull requests

3 participants