[PR #2475] [MERGED] fix(javascript): parse explicit CommonJS wrapper syntax #5256

Closed
opened 2026-10-31 01:05:13 +00:00 by bsakaguchi · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/morluto/rea/pull/2475
Author: @rudycelekli
Created: 10/13/2026
Status: ✅ Merged
Merged: 10/13/2026
Merged by: @morluto

Base: main ← Head: fix/commonjs-source-parser-mode


📝 Commits (1)

  • 405f82c fix(javascript): parse explicit CommonJS wrapper syntax

📊 Changes

3 files changed (+106 additions, -17 deletions)

View changed files

📝 src/domain/javascript/javascriptSourceParser.ts (+42 -17)
📝 tests/boundary/filesystem/referenceSourceTypeScriptExtensions.test.ts (+25 -0)
➕ tests/boundary/process/javascriptSourceModes.test.ts (+39 -0)

📄 Description

Valid .cjs top-level return and new.target were reported as syntax failures in artifact analysis and reference imports. The shared parser now admits CommonJS wrapper syntax while preserving inert reconstruction of module declarations stored in .cjs assets. Reference imports retain extension-based runtime diagnostics; artifact parsing infers declaration syntax and uses CommonJS diagnostics for recovered scripts, so module-only strict errors do not contaminate valid sloppy CommonJS source.

The first published implementation forced artifact .cjs sources into CommonJS mode and caused two existing directory/ASAR reconstruction tests to become partial. This same-PR correction preserves the existing static-source contract at the producing parser; both in-process analysis and compiled analysis workers consume it without downstream patches.

Validation with pinned Node 24.18.0 and locked dependencies:

  • Existing reconstruction suite: 22 passed on frozen base; 2 failed/20 passed on the prior PR head; both formerly failing cases now pass.
  • Expanded native CommonJS wrapper/reference regressions: 5 failed/14 passed on frozen base. Node independently accepts the wrapper/sloppy examples as CommonJS and rejects them as modules without executing their source.
  • Focused reconstruction plus original CommonJS/TypeScript controls: 41 passed.
  • Full related parser/static/semantic/reconstruction and reference-source suites: 1664 passed across 86 files.
  • Required npm run check and npm run verify:test-discovery passed.

A first local repair draft exposed Babel's sticky module diagnostics on valid sloppy CommonJS scripts. Two new native controls caught that draft; the final parser obtains CommonJS diagnostics when syntax inference chose a recovered script. The failed draft and initial missing-artifact run are preserved separately. A check attempt blocked by a concurrent artifact writer was excluded; its raw log was overwritten by the successful sequential retry, and that limitation is recorded.

GitHub CI failed on the previous published revision. After correction, the GitHub CI run passed at commit 405f82c5c6e36d38906cd5b536bcf63b8c6dcd2c; the latest check rollup is successful, including the formerly failing test shard. Independent automated review also passed the same 41 consumer/wrapper/reference cases and required check. Maintainer acceptance is not established.

AI assistance: OpenAI Codex generated the implementation, tests, analysis and this description. Verification was automated; independent AI review is tracked separately. No human review or understanding is claimed.


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/morluto/rea/pull/2475 **Author:** [@rudycelekli](https://github.com/rudycelekli) **Created:** 10/13/2026 **Status:** ✅ Merged **Merged:** 10/13/2026 **Merged by:** [@morluto](https://github.com/morluto) **Base:** `main` ← **Head:** `fix/commonjs-source-parser-mode` --- ### 📝 Commits (1) - [`405f82c`](https://github.com/morluto/rea/commit/405f82c5c6e36d38906cd5b536bcf63b8c6dcd2c) fix(javascript): parse explicit CommonJS wrapper syntax ### 📊 Changes **3 files changed** (+106 additions, -17 deletions) <details> <summary>View changed files</summary> 📝 `src/domain/javascript/javascriptSourceParser.ts` (+42 -17) 📝 `tests/boundary/filesystem/referenceSourceTypeScriptExtensions.test.ts` (+25 -0) ➕ `tests/boundary/process/javascriptSourceModes.test.ts` (+39 -0) </details> ### 📄 Description Valid `.cjs` top-level `return` and `new.target` were reported as syntax failures in artifact analysis and reference imports. The shared parser now admits CommonJS wrapper syntax while preserving inert reconstruction of module declarations stored in `.cjs` assets. Reference imports retain extension-based runtime diagnostics; artifact parsing infers declaration syntax and uses CommonJS diagnostics for recovered scripts, so module-only strict errors do not contaminate valid sloppy CommonJS source. The first published implementation forced artifact `.cjs` sources into CommonJS mode and caused two existing directory/ASAR reconstruction tests to become partial. This same-PR correction preserves the existing static-source contract at the producing parser; both in-process analysis and compiled analysis workers consume it without downstream patches. Validation with pinned Node 24.18.0 and locked dependencies: - Existing reconstruction suite: 22 passed on frozen base; 2 failed/20 passed on the prior PR head; both formerly failing cases now pass. - Expanded native CommonJS wrapper/reference regressions: 5 failed/14 passed on frozen base. Node independently accepts the wrapper/sloppy examples as CommonJS and rejects them as modules without executing their source. - Focused reconstruction plus original CommonJS/TypeScript controls: 41 passed. - Full related parser/static/semantic/reconstruction and reference-source suites: 1664 passed across 86 files. - Required `npm run check` and `npm run verify:test-discovery` passed. A first local repair draft exposed Babel's sticky module diagnostics on valid sloppy CommonJS scripts. Two new native controls caught that draft; the final parser obtains CommonJS diagnostics when syntax inference chose a recovered script. The failed draft and initial missing-artifact run are preserved separately. A check attempt blocked by a concurrent artifact writer was excluded; its raw log was overwritten by the successful sequential retry, and that limitation is recorded. GitHub CI failed on the previous published revision. After correction, the [GitHub CI run](https://github.com/morluto/rea/actions/runs/38346396019) passed at commit `405f82c5c6e36d38906cd5b536bcf63b8c6dcd2c`; the latest check rollup is successful, including the formerly failing test shard. Independent automated review also passed the same 41 consumer/wrapper/reference cases and required check. Maintainer acceptance is not established. AI assistance: OpenAI Codex generated the implementation, tests, analysis and this description. Verification was automated; independent AI review is tracked separately. No human review or understanding is claimed. --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
bsakaguchi 2026-10-31 01:05:13 +00:00
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
morluto/rea#5256
No description provided.