You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I reviewed the diff + CI + the context in #1678. Using cjs-module-lexer to augment named export detection (e.g. Object.defineProperty(exports, "foo", ...)) makes sense and matches what was discussed in the issue, but I don’t think this is merge-ready yet.
MUST fix (before merge)
CI is currently failing prettier:check (it flags packages/commonjs/src/analyze-exports-lexer.js). Please run Prettier and push the formatted result until checks are green.
Please add tests for the new named-export detection. At minimum, cover Object.defineProperty(exports, "foo", { ... }) and assert import { foo } from ./cjs works. (The PR template calls out that bugfixes/features won’t be merged without tests.)
Avoid console.warn(...) in this code path. If the lexer fails on a file, this could spam user builds. Prefer routing warnings through Rollup’s plugin context (e.g. pass this.warn into analyzeExports) or otherwise make it opt-in.
Revisit the lexer failure fallback: returning hasDefaultExport: true when parsing fails can flip meta.commonjs.hasDefaultExport and change interop semantics. Prefer returning hasDefaultExport: false/undefined on failure, and only updating commonjsMeta.hasDefaultExport when the lexer succeeded.
IMPROVEMENTS (non-blocking)
5. lexerReexports / resolveReexports(...) are parsed/stored but don’t appear to be consumed yet. Either wire this into the actual export generation logic, or drop it for now to keep the change focused.
6. Perf: this adds an additional parse pass for each CJS module (AST scan + lexer parse). If it ends up showing up in real-world graphs, consider only running the lexer when the AST analysis can’t confidently determine exports, or cache results more aggressively.
@shellscape thanks for reply
Can you continue this PR?
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Rollup Plugin Name:
@rollup/plugin-commonjsThis PR contains:
Are tests included?
Breaking Changes?
If yes, then include "BREAKING CHANGES:" in the first commit message body, followed by a description of what is breaking.
List any relevant issue numbers: #1678
Description
Add the analyze export lexer for named export that allows to recognize exports like: