evanw / evanw/esbuild

directives doesn't have mappings in source map

Open
#3,548 2 comments 29 reactions 0 assignees View on GitHub
sourcemap
Dominant language
Go
Stars
40.1k
Forks
1.3k
PR merge metrics
No merged PRs in 30d

Description

esbuild does not output source mapping for directives. babel and SWC both output them and I expect it to be output.

[esbuild try](https://esbuild.github.io/try/#dAAwLjE5LjkALS1zb3VyY2VtYXA9ImlubGluZSIAJ3VzZSBjbGllbnQnOwoKY29uc29sZS5sb2coJ2ZvbycpOwo) ([sourcemap visualization](https://evanw.github.io/source-map-visualization/#MzA2ACJ1c2UgY2xpZW50IjsNCmNvbnNvbGUubG9nKCJmb28iKTsNCi8vIyBzb3VyY2VNYXBwaW5nVVJMPWRhdGE6YXBwbGljYXRpb24vanNvbjtiYXNlNjQsZXdvZ0lDSjJaWEp6YVc5dUlqb2dNeXdLSUNBaWMyOTFjbU5sY3lJNklGc2lQSE4wWkdsdVBpSmRMQW9nSUNKemIzVnlZMlZ6UTI5dWRHVnVkQ0k2SUZzaUozVnpaU0JqYkdsbGJuUW5PMXh1WEc1amIyNXpiMnhsTG14dlp5Z25abTl2SnlrN1hHNGlYU3dLSUNBaWJXRndjR2x1WjNNaU9pQWlPMEZCUlVFc1VVRkJVU3hKUVVGSkxFdEJRVXM3SWl3S0lDQWlibUZ0WlhNaU9pQmJYUXA5Q2c9PTE2MwB7CiAgInZlcnNpb24iOiAzLAogICJzb3VyY2VzIjogWyI8c3RkaW4+Il0sCiAgInNvdXJjZXNDb250ZW50IjogWyIndXNlIGNsaWVudCc7XG5cbmNvbnNvbGUubG9nKCdmb28nKTtcbiJdLAogICJtYXBwaW5ncyI6ICI7QUFFQSxRQUFRLElBQUksS0FBSzsiLAogICJuYW1lcyI6IFtdCn0K))

[babel](https://stackblitz.com/edit/babel-sapphi-red-template-vakqym?file=package.json,build.js,input.js) ([sourcemap visualization](https://evanw.github.io/source-map-visualization/#MzU0ACd1c2UgY2xpZW50JzsNCg0KY29uc29sZS5sb2coJ2ZvbycpOw0KLy8jIHNvdXJjZU1hcHBpbmdVUkw9ZGF0YTphcHBsaWNhdGlvbi9qc29uO2NoYXJzZXQ9dXRmLTg7YmFzZTY0LGV5SjJaWEp6YVc5dUlqb3pMQ0p1WVcxbGN5STZXeUpqYjI1emIyeGxJaXdpYkc5bklsMHNJbk52ZFhKalpYTWlPbHNpZFc1cmJtOTNiaUpkTENKemIzVnlZMlZ6UTI5dWRHVnVkQ0k2V3lJbmRYTmxJR05zYVdWdWRDYzdYSEpjYmx4eVhHNWpiMjV6YjJ4bExteHZaeWduWm05dkp5azdYSEpjYmlKZExDSnRZWEJ3YVc1bmN5STZJa0ZCUVVFc1dVRkJXVHM3UVVGRldrRXNUMEZCVHl4RFFVRkRReXhIUVVGSExFTkJRVU1zUzBGQlN5eERRVUZESW4wPTE4OAB7InZlcnNpb24iOjMsIm5hbWVzIjpbImNvbnNvbGUiLCJsb2ciXSwic291cmNlcyI6WyJ1bmtub3duIl0sInNvdXJjZXNDb250ZW50IjpbIid1c2UgY2xpZW50JztcclxuXHJcbmNvbnNvbGUubG9nKCdmb28nKTtcclxuIl0sIm1hcHBpbmdzIjoiQUFBQSxZQUFZOztBQUVaQSxPQUFPLENBQUNDLEdBQUcsQ0FBQyxLQUFLLENBQUMifQ==))
[swc](https://play.swc.rs/?version=1.3.100&code=H4sIAAAAAAAAA1MvLU5VSM7JTM0rUbfm5eLlSs7PK87PSdXLyU%2FXUE%2FLz1fXBAoDANO4gEAmAAAA&config=H4sIAAAAAAAAA1WPSw6DMAxE95wCed1FxaIL7sAhrNSgoPxkB6kIcfcmkNCyi9%2FMZOytaVuYRUHfbumZhoAsxNeciKwu4icRIGVRFOsQ4VHVWbI0ohE60H4qEJEnikdKumfXlQQY74VqojCrnR7X%2F07lbWASuRuzFd1k6N7YlFaw%2Fr0cYrklroHODV7wM9Wy62PQMtRk5OVk4hdWNGDIO4B2RjuCZv8CUFCpdDEBAAA%3D) ([sourcemap visualization](https://evanw.github.io/source-map-visualization/#MzEyACd1c2UgY2xpZW50JzsNCmNvbnNvbGUubG9nKCdmb28nKTsNCg0KLy8jIHNvdXJjZU1hcHBpbmdVUkw9ZGF0YTphcHBsaWNhdGlvbi9qc29uO2Jhc2U2NCxleUoyWlhKemFXOXVJam96TENKemIzVnlZMlZ6SWpwYkltbHVjSFYwTG1weklsMHNJbk52ZFhKalpYTkRiMjUwWlc1MElqcGJJaWQxYzJVZ1kyeHBaVzUwSnp0Y2NseHVYSEpjYm1OdmJuTnZiR1V1Ykc5bktDZG1iMjhuS1R0Y2NseHVJbDBzSW01aGJXVnpJanBiSW1OdmJuTnZiR1VpTENKc2IyY2lYU3dpYldGd2NHbHVaM01pT2lKQlFVRkJPMEZCUlVGQkxGRkJRVkZETEVkQlFVY3NRMEZCUXlKOTE2OAB7InZlcnNpb24iOjMsInNvdXJjZXMiOlsiaW5wdXQuanMiXSwic291cmNlc0NvbnRlbnQiOlsiJ3VzZSBjbGllbnQnO1xyXG5cclxuY29uc29sZS5sb2coJ2ZvbycpO1xyXG4iXSwibmFtZXMiOlsiY29uc29sZSIsImxvZyJdLCJtYXBwaW5ncyI6IkFBQUE7QUFFQUEsUUFBUUMsR0FBRyxDQUFDIn0=))

#### Additional context
Rollup outputs a warning for directives other than `use strict` (e.g. `use client`) because it doesn't know about the semantics for that. Vite uses esbuild to transform a file and feeds it to Rollup with source map. Then, Rollup output the warning because the input file has `use client` and tries to map the position to the original position using the source map generated by esbuild. But because the source map doesn't contain the mapping for the directive, Rollup fails to output the warning with the original position.

original issue: https://github.com/vitejs/vite/issues/15012

Contributor guide

No contributing guide indexed for this repository

Research direction

Start with the linked esbuild try case and compare its source map with the Babel and SWC visualizations. No source files or tests are named, so trace esbuild's source-map generation for JavaScript directives and add coverage for the reported input. Done means directive positions are represented so downstream tools can recover the original location.

Written by the indexing model from the issue text.

Assessment

Tech stack
go, javascript
Domain
compilers
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
42/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.