-
Notifications
You must be signed in to change notification settings - Fork 624
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
Handle "simple" (missing origin) source mappings in minifier output #928
Closed
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
facebook-github-bot
added
CLA Signed
This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed.
fb-exported
labels
Feb 16, 2023
This pull request was exported from Phabricator. Differential Revision: D43351987 |
…acebook#928) Summary: Pull Request resolved: facebook#928 Fixes facebook#927 Terser, unlike the previous default minifier UglifyES, produces source maps whose entries may contain "simple mappings" - that is entries with a generated line+col but no original location. When Metro processes minified output ahead of serialization, it doesn't correctly handle these entries. Instead it incorrectly detects them as complete mappings and produces a merged source map with `-1` origin line numbers in place of simple mappings. Some tools will reject the whole source map (which is otherwise correct) based on the appearance of a negative line number. The issue comes down to the conversion of raw mappings to `BabelSourceMapSegments` in `toBabelSegments`, which currently generates entries for simple mappings with `null` `origin` *properties*, such as: ``` { generated: { column: 2, line: 1 }, origin: { column: null, line: null }, // ... } ``` According to the Flow type for `BabelSourceMapSegments`, that's incorrect. `origin` itself is optional and should be missing - the properties of `origin` are not nullable. Based on the presence of the `origin` property in that object, `toSegmentTuple` generates a 4-tuple and we go on to add a "source mapping" rather than a "simple mapping". This fixes `toBabelSegments` to omit `origin` unless `line` and `column` are both populated. The final source map output is then correct. Changelog: [Fix] Source maps may have invalid entries when using Terser minification. Reviewed By: motiz88 Differential Revision: D43351987 fbshipit-source-id: 706cf2e90cb33ebc8223b449b2c280156512c9a4
robhogan
force-pushed
the
export-D43351987
branch
from
February 16, 2023 15:27
66914bf
to
ed4a813
Compare
This pull request was exported from Phabricator. Differential Revision: D43351987 |
This pull request has been merged in 1a9c719. |
robhogan
added a commit
that referenced
this pull request
Feb 18, 2023
…928) Summary: Pull Request resolved: #928 Fixes #927 Terser, unlike the previous default minifier UglifyES, produces source maps whose entries may contain "simple mappings" - that is entries with a generated line+col but no original location. When Metro processes minified output ahead of serialization, it doesn't correctly handle these entries. Instead it incorrectly detects them as complete mappings and produces a merged source map with `-1` origin line numbers in place of simple mappings. Some tools will reject the whole source map (which is otherwise correct) based on the appearance of a negative line number. The issue comes down to the conversion of raw mappings to `BabelSourceMapSegments` in `toBabelSegments`, which currently generates entries for simple mappings with `null` `origin` *properties*, such as: ``` { generated: { column: 2, line: 1 }, origin: { column: null, line: null }, // ... } ``` According to the Flow type for `BabelSourceMapSegments`, that's incorrect. `origin` itself is optional and should be missing - the properties of `origin` are not nullable. Based on the presence of the `origin` property in that object, `toSegmentTuple` generates a 4-tuple and we go on to add a "source mapping" rather than a "simple mapping". This fixes `toBabelSegments` to omit `origin` unless `line` and `column` are both populated. The final source map output is then correct. Changelog: [Fix] Source maps may have invalid entries when using Terser minification. Reviewed By: motiz88 Differential Revision: D43351987 fbshipit-source-id: 5cd46fdd001f3c3a3599ada44f525bec467854e1
robhogan
added a commit
that referenced
this pull request
Feb 19, 2023
…928) Summary: Pull Request resolved: #928 Fixes #927 Terser, unlike the previous default minifier UglifyES, produces source maps whose entries may contain "simple mappings" - that is entries with a generated line+col but no original location. When Metro processes minified output ahead of serialization, it doesn't correctly handle these entries. Instead it incorrectly detects them as complete mappings and produces a merged source map with `-1` origin line numbers in place of simple mappings. Some tools will reject the whole source map (which is otherwise correct) based on the appearance of a negative line number. The issue comes down to the conversion of raw mappings to `BabelSourceMapSegments` in `toBabelSegments`, which currently generates entries for simple mappings with `null` `origin` *properties*, such as: ``` { generated: { column: 2, line: 1 }, origin: { column: null, line: null }, // ... } ``` According to the Flow type for `BabelSourceMapSegments`, that's incorrect. `origin` itself is optional and should be missing - the properties of `origin` are not nullable. Based on the presence of the `origin` property in that object, `toSegmentTuple` generates a 4-tuple and we go on to add a "source mapping" rather than a "simple mapping". This fixes `toBabelSegments` to omit `origin` unless `line` and `column` are both populated. The final source map output is then correct. Changelog: [Fix] Source maps may have invalid entries when using Terser minification. Reviewed By: motiz88 Differential Revision: D43351987 fbshipit-source-id: 5cd46fdd001f3c3a3599ada44f525bec467854e1
This was referenced Mar 9, 2023
This was referenced Jul 30, 2023
This was referenced Aug 7, 2023
This was referenced Sep 26, 2023
This was referenced Jun 12, 2024
This was referenced Jun 22, 2024
This was referenced Aug 25, 2024
This was referenced Oct 10, 2024
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Labels
CLA Signed
This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed.
fb-exported
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Summary:
Fixes #927
Terser, unlike the previous default minifier UglifyES, produces source maps whose entries may contain "simple mappings" - that is entries with a generated line+col but no original location.
When Metro merges source maps to serialize minified output, it doesn't correctly handle these entries. Instead it incorrectly detects them as complete mappings and produces a merged source map with
-1
origin line numbers in place of simple mappings.Some tools will reject the whole source map (which is otherwise correct) based on the appearance of a negative line number.
The issue comes down to the conversion of raw mappings to
BabelSourceMapSegments
intoBabelSegments
, which currently generates entries for simple mappings withnull
origin
properties, such as:According to the Flow type for
BabelSourceMapSegments
, that's incorrect.origin
itself is optional and should be missing - the properties oforigin
are not nullable.Based on the presence of the
origin
property in that object,toSegmentTuple
generates a 4-tuple and we go on to add a "source mapping" rather than a "simple mapping".This fixes
toBabelSegments
to omitorigin
unlessline
andcolumn
are both populated. The final source map output is then correct.Differential Revision: D43351987