Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix compressed source-maps have non-terminated segments #342

Conversation

devversion
Copy link
Contributor

@devversion devversion commented Apr 24, 2019

Currently when terser compresses a given input file that comes
with a source-map, but the source-map does not have mappings for
all code parts in the input file. e.g. the input file has been generated
and some specific code-parts have been generated and are not
originating from any source-file (i.e. rollup boilerplate to create bundle)

In that case if real mappings before the "generated code" are collected, and
the original file location for the "generated code" is determined after previous
mappings for the same line have been recorded, Terser just ignores the fact that
there is no original location and the previous segment is not terminated. Meaning that the"generated code" incorrectly maps to the previous segment.

@devversion devversion force-pushed the fix/compressed-source-maps-incorrect-segments branch 2 times, most recently from a60ff77 to 904002f Compare April 24, 2019 18:16
@fabiosantoscode
Copy link
Collaborator

I second @filipesilva in his comment, so please do change that one thing :)

I very much appreciate the effort that went into this PR. Source map issues are pesky, hard to debug, hard to track the origin of, and just a major pain in the backside in terms of DX.

Currently when `terser` compresses a given input file that comes
with a source-map, but the source-map does not have mappings for
all code parts in the input file. e.g. the input file has been generated
and some specific code-parts have been generated which are not
originating from any source-file.

In that case if mappings before the "generated code" are collected, and
the original file location for the "generated code" comes after previous
segments for the same line, Terser just ignores the fact that there is no
original location and the previous segment is not terminated. This causes
the "generated code" incorrectly to be mapped to the previous segment/
original source location.
@devversion devversion force-pushed the fix/compressed-source-maps-incorrect-segments branch from 904002f to 4c7b61d Compare April 27, 2019 21:56
@devversion
Copy link
Contributor Author

@fabiosantoscode Sure. I just didn't have time to address that comment until now. Thanks for the feedback you all! Updated now! 😄

@devversion
Copy link
Contributor Author

Hi @fabiosantoscode, is there anything I could do to move this forward? Happy to help in case something is unclear, or if you have any concerns in regards to increased source-map size due to more mappings.

@fabiosantoscode
Copy link
Collaborator

@devversion thanks for the ping, I'm merging this. Thank you very much for your contribution!

@fabiosantoscode fabiosantoscode merged commit 7d47254 into terser:master May 24, 2019
@devversion
Copy link
Contributor Author

Thank you! @fabiosantoscode 😄

fabiosantoscode added a commit that referenced this pull request Jun 30, 2019
fabiosantoscode added a commit that referenced this pull request Jun 30, 2019
fabiosantoscode added a commit that referenced this pull request Jun 30, 2019
devversion added a commit to devversion/angular that referenced this pull request Aug 22, 2019
Currently terser is in a broken state where technically unmapped
bytes in the input file are randomly mapped back to source files.

"unmapped bytes" are bytes in the input file (that should be minified),
which cannot be mapped back to any source file. This is totally
valid as some code will be generated by rollup in order to create
bundles of multiple files. These bytes do not originate from any
source-file and therefore do not map.

In the current state of Terser where unmapped bytes are mapped to
random source-files, size tracking tools are not able to determine
accurate payload size contribution numbers of individual source-files,
nor do the broken source-maps help with debugging Angular packages
as some bytes are incorrectly mapping to a wrong file (this is not a
big deal though as the generated code is not likely to be debugged).

For context why we try to fix the terser bug on our side now: A PR
to fix this bug on the terser side has been submitted but it had to
be reverted due to a bug in the latest `mozilla/source-map` library.
Terser reverted the fix that hit the bug in `mozilla/source-map` as
they wanted to unblock consumers that use the latest `source-map`
package. Problem is that the bug in the `source-map` package is widely
spread and there doesn't seem to be a fix for it any time soon. Meaning
that source-maps needs to stay broken/incorrect as fixing them would
always cause developers to hit the `source-map` bug...

See `source-map` bug: mozilla/source-map#385
See Terser fix: terser/terser#342.
devversion added a commit to devversion/angular that referenced this pull request Sep 11, 2019
Currently terser is in a broken state where technically unmapped
bytes in the input file are randomly mapped back to source files.

"unmapped bytes" are bytes in the input file (that should be minified),
which cannot be mapped back to any source file. This is totally
valid as some code will be generated by rollup in order to create
bundles of multiple files. These bytes do not originate from any
source-file and therefore do not map.

In the current state of Terser where unmapped bytes are mapped to
random source-files, size tracking tools are not able to determine
accurate payload size contribution numbers of individual source-files,
nor do the broken source-maps help with debugging Angular packages
as some bytes are incorrectly mapping to a wrong file (this is not a
big deal though as the generated code is not likely to be debugged).

For context why we try to fix the terser bug on our side now: A PR
to fix this bug on the terser side has been submitted but it had to
be reverted due to a bug in the latest `mozilla/source-map` library.
Terser reverted the fix that hit the bug in `mozilla/source-map` as
they wanted to unblock consumers that use the latest `source-map`
package. Problem is that the bug in the `source-map` package is widely
spread and there doesn't seem to be a fix for it any time soon. Meaning
that source-maps needs to stay broken/incorrect as fixing them would
always cause developers to hit the `source-map` bug...

See `source-map` bug: mozilla/source-map#385
See Terser fix: terser/terser#342.
devversion added a commit to devversion/angular that referenced this pull request Sep 13, 2019
Currently terser is in a broken state where technically unmapped
bytes in the input file are randomly mapped back to source files.

"unmapped bytes" are bytes in the input file (that should be minified),
which cannot be mapped back to any source file. This is totally
valid as some code will be generated by rollup in order to create
bundles of multiple files. These bytes do not originate from any
source-file and therefore do not map.

In the current state of Terser where unmapped bytes are mapped to
random source-files, size tracking tools are not able to determine
accurate payload size contribution numbers of individual source-files,
nor do the broken source-maps help with debugging Angular packages
as some bytes are incorrectly mapping to a wrong file (this is not a
big deal though as the generated code is not likely to be debugged).

For context why we try to fix the terser bug on our side now: A PR
to fix this bug on the terser side has been submitted but it had to
be reverted due to a bug in the latest `mozilla/source-map` library.
Terser reverted the fix that hit the bug in `mozilla/source-map` as
they wanted to unblock consumers that use the latest `source-map`
package. Problem is that the bug in the `source-map` package is widely
spread and there doesn't seem to be a fix for it any time soon. Meaning
that source-maps needs to stay broken/incorrect as fixing them would
always cause developers to hit the `source-map` bug...

See `source-map` bug: mozilla/source-map#385
See Terser fix: terser/terser#342.
devversion added a commit to devversion/angular that referenced this pull request Oct 2, 2019
Currently terser is in a broken state where technically unmapped
bytes in the input file are randomly mapped back to source files.

"unmapped bytes" are bytes in the input file (that should be minified),
which cannot be mapped back to any source file. This is totally
valid as some code will be generated by rollup in order to create
bundles of multiple files. These bytes do not originate from any
source-file and therefore do not map.

In the current state of Terser where unmapped bytes are mapped to
random source-files, size tracking tools are not able to determine
accurate payload size contribution numbers of individual source-files,
nor do the broken source-maps help with debugging Angular packages
as some bytes are incorrectly mapping to a wrong file (this is not a
big deal though as the generated code is not likely to be debugged).

For context why we try to fix the terser bug on our side now: A PR
to fix this bug on the terser side has been submitted but it had to
be reverted due to a bug in the latest `mozilla/source-map` library.
Terser reverted the fix that hit the bug in `mozilla/source-map` as
they wanted to unblock consumers that use the latest `source-map`
package. Problem is that the bug in the `source-map` package is widely
spread and there doesn't seem to be a fix for it any time soon. Meaning
that source-maps needs to stay broken/incorrect as fixing them would
always cause developers to hit the `source-map` bug...

See `source-map` bug: mozilla/source-map#385
See Terser fix: terser/terser#342.
devversion pushed a commit to devversion/terser that referenced this pull request Oct 31, 2021
devversion added a commit to devversion/terser that referenced this pull request Oct 31, 2021
jridgewell added a commit to ampproject/remapping that referenced this pull request Nov 11, 2021
jridgewell added a commit to ampproject/remapping that referenced this pull request Nov 11, 2021
devversion added a commit to devversion/terser that referenced this pull request May 20, 2022
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.

None yet

3 participants