nodejs / nodejs/cjs-module-lexer

Export not detected

Open
#20 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

⚠️ This is not real-world code. It's technically a bug, but no real program will notice it. Feel free to close this issue!

Consider this non-strict mode code: (GitHub's syntax highlighting is broken)

function fn() {
    yield / "/ //" /*
}
/*/
}

module.exports.foo = 2;

// */

The tokens are:

[function] [Identifier: fn] [paren left] [paren left] [brace left]
[Identifier: yield] [division] [String: "/ //"] [Comment: \n}\n/ ]
[brace right]

[Identifier: module] [dot] [Identifier: exports] [dot] [Identifier: foo] [equal] [Number: 2] [semicolon]

However, cjs-module-lexer returns { exports: [], reexports: [] }.

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 running the provided non-strict JavaScript snippet through cjs-module-lexer and inspect how it tokenizes the yield, regular expression, and comment sequence. Done means the lexer detects foo in module.exports rather than returning empty exports and reexports results, with regression coverage for this input.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript
Domain
tooling
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.