Skip to content

src: omit unconvertible names in cjs_lexer::Parse#63943

Open
anonrig wants to merge 1 commit into
nodejs:mainfrom
anonrig:cjs-lexer-omit-followup
Open

src: omit unconvertible names in cjs_lexer::Parse#63943
anonrig wants to merge 1 commit into
nodejs:mainfrom
anonrig:cjs-lexer-omit-followup

Conversation

@anonrig

@anonrig anonrig commented Jun 16, 2026

Copy link
Copy Markdown
Member

Follow-up to #63885 (aa25a0a30c3).

That change made CreateString() return a MaybeLocal<String> and bailed out of Parse() (early return) when an export / re-export name could not be converted to a V8 string or when Set::Add() failed. Because the binding then returns undefined, the JS caller (cjsPreparseModuleExports in lib/internal/modules/esm/translators.js, which does const { 0: exportNames, 1: reexports } = cjsParse(source)) fails the entire exports preparse for that module.

This makes the conversion best-effort instead: omit any individual export / re-export name that cannot be turned into a V8 string and continue, so the remaining names are still returned and a single pathological name no longer fails the whole preparse. Set::Add() is a V8_WARN_UNUSED_RESULT, so its result is explicitly discarded with USE().

for (const auto& exp : analysis.exports) {
  Local<String> exp_str;
  if (CreateString(isolate, exp).ToLocal(&exp_str)) {
    USE(exports_set->Add(context, exp_str));
  }
}

Verified locally: node_cjs_lexer.cc builds clean, cpplint passes, the cjs_lexer binding returns the expected export/re-export names (ASCII + non-ASCII) and handles null/empty input, and test/es-module CJS-exports tests pass.

Refs: #63885
Refs: #63323

Follow-up to aa25a0a. When an export or re-export name cannot be
converted to a V8 string (e.g. on string allocation failure), omit that
individual name and continue instead of bailing out of the whole
preparse. A single pathological name no longer fails the module's
exports preparse; the remaining names are still returned.

Refs: nodejs#63885
Refs: nodejs#63323
Signed-off-by: Yagiz Nizipli <yagiz@nizipli.com>
@nodejs-github-bot nodejs-github-bot added c++ Issues and PRs that require attention from people who are familiar with C++. needs-ci PRs that need a full CI run. labels Jun 16, 2026
@anonrig anonrig added author ready PRs that have at least one approval, no pending requests for changes, and a CI started. request-ci Add this label to start a Jenkins CI on a PR. labels Jun 16, 2026
@github-actions github-actions Bot removed the request-ci Add this label to start a Jenkins CI on a PR. label Jun 16, 2026
@nodejs-github-bot

Copy link
Copy Markdown
Collaborator

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

author ready PRs that have at least one approval, no pending requests for changes, and a CI started. c++ Issues and PRs that require attention from people who are familiar with C++. needs-ci PRs that need a full CI run.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants