nodejs / nodejs/cjs-module-lexer

Regexp/division after `]}` not properly disambiguated

Open
#22 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug
Dominant language
JavaScript
Stars
262
Forks
31
Avg merge
9d 2h
Merged PRs (30d)
5

Description

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 😅)

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reproducing the two JavaScript inputs from the issue and comparing the lexer’s named-export result with the stated distinction between division and a regular expression. Then trace how the lexer handles ]} followed by /; done means the two examples are no longer treated identically.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript
Domain
tooling
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.