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

enable-experimental-regexp-engine v8 flag doesn't work with promises #55400

Closed
brian6932 opened this issue Oct 15, 2024 · 5 comments
Closed

enable-experimental-regexp-engine v8 flag doesn't work with promises #55400

brian6932 opened this issue Oct 15, 2024 · 5 comments
Labels
repl Issues and PRs related to the REPL subsystem.

Comments

@brian6932
Copy link

brian6932 commented Oct 15, 2024

Version

v22.9.0

Platform

Microsoft Windows NT 10.0.19044.0 x64

Subsystem

No response

What steps will reproduce the bug?

 node --enable-experimental-regexp-engine
Welcome to Node.js v22.9.0.
Type ".help" for more information.
> /foo/l
/foo/l

> (() => /foo/l)()
/foo/l

> await /foo/l
Uncaught SyntaxError:
await /foo/l
       ^

Invalid regular expression flag

> await (async () => /foo/l)()
Uncaught SyntaxError:
await (async () => /foo/l)()
                    ^

Invalid regular expression flag

> await (function() { return /foo/l })()
Uncaught SyntaxError:
await (function() { return /foo/l })()
                            ^

Invalid regular expression flag

> await new Promise(resolve => resolve(/foo/l))
Uncaught SyntaxError:
await new Promise(resolve => resolve(/foo/l))
                                      ^

Invalid regular expression flag

> await Promise.resolve(/foo/l)
Uncaught SyntaxError:
await Promise.resolve(/foo/l)
                       ^

Invalid regular expression flag

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

The linear regex must be created, and wrapped in a Promise, closures experience no such issues.

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

The linear flag should be parsed and executed as expected.

What do you see instead?

Invalid regular expression flag

Additional information

No response

@RedYetiDev RedYetiDev added the repl Issues and PRs related to the REPL subsystem. label Oct 15, 2024
@RedYetiDev
Copy link
Member

RedYetiDev commented Oct 15, 2024

This seems to be only reproducible in the REPL, and not via an actual script. It probably has to do with top-level await.

@RedYetiDev RedYetiDev added the confirmed-bug Issues with confirmed bugs. label Oct 15, 2024
@aduh95 aduh95 removed the confirmed-bug Issues with confirmed bugs. label Oct 16, 2024
@aduh95
Copy link
Contributor

aduh95 commented Oct 16, 2024

--enable-experimental-regexp-engine is not documented, therefore it's not a flag we support.

node/doc/api/cli.md

Lines 3472 to 3476 in d6175b3

V8 has its own set of CLI options. Any V8 CLI option that is provided to `node`
will be passed on to V8 to handle. V8's options have _no stability guarantee_.
The V8 team themselves don't consider them to be part of their formal API,
and reserve the right to change them at any time. Likewise, they are not
covered by the Node.js stability guarantees. Many of the V8

You would probably get better results by passing --no-experimental-repl-await, and/or using the RegExp constructor instead.
Closing as won't fix.

@aduh95 aduh95 closed this as not planned Won't fix, can't repro, duplicate, stale Oct 16, 2024
@brian6932
Copy link
Author

You would probably get better results by passing --no-experimental-repl-await

I understand, I've ran into this in more than just Node repl (in some eval sandboxes lacking top-level await), and believe there's an underlying v8 or Node bug somewhere here. I don't have enough info as to why it happens though. It's kinda interesting that it's only occurring with the primitive, and not the constructor.

@F3n67u
Copy link
Member

F3n67u commented Oct 18, 2024

This issue is caused by acorn doesn't support linear regex.

Top-level await is not handled by V8 directly, in order to support top-level await, Node use acorn to parse and preprocess top-level await code(see #15566).
When parsing linear regex expression literal, acorn throw a "SyntaxError: Invalid regular expression flag" because it doesn't understand what flag "l" is. You can use https://astexplorer.net/ to test it.

Why it doesn't happen when using Regex constructor like new RegExp("foo", "l")?
I guess acorn just handle flag param as a string, it doesn't parse it like in regex expression literal.

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

5 participants
@F3n67u @aduh95 @brian6932 @RedYetiDev and others