Skip to content

Parse modules as the language the bundler assigned them - #125

Merged
nstepien merged 1 commit into
mainfrom
parse-as-module-type
Nov 4, 2026
Merged

nstepien merged 1 commit into
mainfrom
parse-as-module-type

Conversation

@nstepien

@nstepien nstepien commented Nov 4, 2026

Copy link
Copy Markdown
Owner

ecij parsed the module it transforms as the language its file extension implies, ignoring the module type the bundler assigned it. Rolldown parses a .js file with JSX as JSX when configured with moduleTypes: { '.js': 'jsx' }, but ecij failed to parse it and silently left its templates untransformed. The output kept the raw css call, which throws at runtime, and no CSS or warning came out.

  • transform now parses the module as meta.moduleType when that is a language the parser accepts (js, jsx, ts, or tsx), and otherwise falls back to the file extension. The modules that interpolated values come from are still read from disk and parsed by their extension.
  • A new test builds a .js fixture with JSX through plain Rolldown with moduleTypes: { '.js': 'jsx' }. On main, its output keeps the css template and no stylesheet is extracted.
  • AGENTS.md describes how the module is parsed.

Vite users see no change. Vite compiles TypeScript and JSX to JavaScript before ecij runs, and passes moduleType: 'js' along with that code, both in builds and in the dev server. A Vite build of react-data-grid's src is byte-for-byte identical to main's, source maps included. The fix is for Rolldown and tsdown users with custom moduleTypes.

This is ported from #68, which passes meta.moduleType to the parser the same way.

The uncovered lines are unchanged. The fallback for a module type that isn't a language, like json, is the one new branch the tests don't reach.

🤖 Generated with Claude Code

A .js file with JSX, assigned the jsx module type, failed to parse as
JavaScript, which left its templates untransformed.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@coderabbitai

coderabbitai Bot commented Nov 4, 2026 •

Copy link
Copy Markdown

Important

  • Trigger review

This repository does not receive automatic reviews because it has fewer than 10 stars.

Run configuration
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

@nstepien
nstepien marked this pull request as ready for review November 4, 2026 02:25
@nstepien
nstepien merged commit 8122f7e into main Nov 4, 2026
12 checks passed
@nstepien
nstepien deleted the parse-as-module-type branch November 4, 2026 02:26
nstepien added a commit that referenced this pull request Nov 4, 2026
main reshaped the code this branch builds on since the last merge, so
the merge ports the branch onto main's design again:

- The scope visitor is shared across parses (#109), so the callbacks
  for raw TypeScript bindings and `export default` join it, and the
  default export is recorded through its visit state.
- Imported modules are resolved, loaded, and parsed once per transform
  through main's loadImportedModule (#124), which now also skips
  external modules, keys modules by moduleKey, and records dependencies
  by file.
- Modules are parsed as the language the bundler assigned them through
  main's parseLangOf (#125), which this branch had too.
- extractCssFromCode keeps main's single pass (#114), and hotUpdate its
  early return, with this branch's handling of query variants.
- readModuleCode moved to module level, as consistent-function-scoping
  is on since #109.

Tests: the inline snapshots of this branch's tests follow Rolldown's new
module comments (`// path` instead of `//#region path` and
`//#endregion`), with no other change. The dev server test of virtual
modules uses main's shared getCode and getStylesheets helpers.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant