Skip to content

[Bug]: inline exports create syntax errors with division operator #12631

@maxdavidson

Description

@maxdavidson

System Info

System:
  OS: macOS 26.2
  CPU: (10) arm64 Apple M1 Pro
  Memory: 135.59 MB / 32.00 GB
  Shell: 5.9 - /bin/zsh
Binaries:
  Node: 24.12.0 - ~/.nvm/versions/node/v24.12.0/bin/node
  Yarn: 4.8.1 - /usr/local/bin/yarn
  npm: 11.6.2 - ~/.nvm/versions/node/v24.12.0/bin/npm
  bun: 1.0.3 - ~/.bun/bin/bun
Browsers:
  Brave Browser: 129.1.70.126
  Chrome: 143.0.7499.170
  Chrome Canary: 145.0.7616.0
  Edge: 143.0.3650.96
  Safari: 26.2
  Safari Technology Preview: 26.0

Details

The inlineExports feature generates invalid code when the replaced variable appears right after a division operator with no space in between:

// Before:
if (minutes/minutesInDay) {}

// After: syntax error! (two forward slashes turns into a single-line comment)
if (minutes//* inlined export .minutesInDay */ (1440)) {}

If the injected code is at the end of a line, it could still generate syntactically valid, but incorrect code:

// Before:
const days = minutes/minutesInDay;

// After: no error, but incorrect!
const days = minutes//* inlined export .minutesInDay */ (1440);

I noticed this because I was using Babel with compact: true, but it could also feasibly happen if importing already minified code, or if the author simply did not use spaces.

Reproduce link

https://github.com/maxdavidson/rspack-inline-exports-bug

Reproduce Steps

  1. Run npm run install && npm run build
  2. Check errors

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions