evanw / esbuild

An extremely fast bundler for the web
https://esbuild.github.io/
MIT License
37.99k stars 1.14k forks source link

directives doesn't have mappings in source map #3548

Open sapphi-red opened 9 months ago

sapphi-red commented 9 months ago

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

esbuild try (sourcemap visualization)

babel (sourcemap visualization) swc (sourcemap visualization)

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

evanw commented 9 months ago

This isn't trivial to fix because the directives are separated from the rest of the file in the output (e.g. they must come outside the enclosing IIFE, if any). The easiest way to do this would be to treat it like a separate file but that would result in a duplicate source in the source map (including a duplicate of the source contents) which is undesirable. I'm not saying it can't be fixed, but that the potential complexity of this fix is why I'm not including the fix for this in the release going out today.

sergei-lobanov commented 1 week ago

Any updates on this issue?