nodejs / nodejs/cjs-module-lexer

Can't export when enumerable is "!0"

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

Nobody has claimed this yet.

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

Description

Input File:

Object.defineProperty(exports, 'a', {
  enumerable: true,
  value: 'a'
});

Object.defineProperty(exports, 'b', {
  enumerable: !0,
  value: 'b'
});

Expected Result: ["a", "b"]
Actual Result: ["a"]

We can get this case when we use uglifyjs to minify our source code.
image

The Error is occured in https://github.com/guybedford/cjs-module-lexer/blob/a96e7b52b99d39fee25d69f356905161d14a15ed/lexer.js#L370

Here is a simple solution:

          if (source.startsWith('true', pos)) {
            pos += 4;
          } else if (source.startsWith('!0', pos)) {
            pos += 2;
          } else {
            break;
          }

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 at lexer.js around line 370, where enumerable values are recognized during CommonJS export analysis. Reproduce the provided input containing enumerable: true and enumerable: !0, then verify that both "a" and "b" are reported as named exports.

Written by the indexing model from the issue text.

Assessment

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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.