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

Regexp/division after ]} not properly disambiguated #22

Open
nicolo-ribaudo opened this issue Oct 28, 2020 · 2 comments
Open

Regexp/division after ]} not properly disambiguated #22

nicolo-ribaudo opened this issue Oct 28, 2020 · 2 comments
Labels
bug Something isn't working

Comments

@nicolo-ribaudo
Copy link
Contributor

Consider these two inputs:

void {
    x: []
} / "/ //" /*

/*/

module.exports.foo = 2;

// */
{
    x: []
} / "/ //" /*

/*/

module.exports.foo = 2;

// */

In the first one it's an object divided by the string "/ //", followed by a comment and by the expression module.exports.foo = 2;.

In the second one it's a block containing a labeled statement (x: []), then there is a regular expression (/ "/), and inline comment and a block comment.

However, it returns exports: [ 'foo' ] for both the examples.

(Sorry for those /*//// */ patterns, but I need them to write "dual mode" code to toggle between code and comments 😅)

@guybedford
Copy link
Collaborator

Thanks for finding this one! Fix added in #23.

@guybedford
Copy link
Collaborator

Looking at this more closely, it is effectively a class of ASI cases where we aren't detecting the } as a block when it should be.

Some other variations:

{}

/'/.test(myString);

module.exports.foo = 2;
var p = 5

{}

/'/.test(myString);

module.exports.foo = 2;
var p = class {}

{}

/'/.test(myString);

module.exports.foo = 2;

When it comes down to it, these are all cases that require deeper parsing context to properly manage. That is, you have found the places where the heuristic approach breaks down!

I get the feeling these are the limits of a small lexer though unfortunately.

If specific cases come up with regards to real world code we can fix them individually though.

The opt out at least is not getting any detection of course.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants