Merged
Conversation
🦋 Changeset detectedLatest commit: 86bd203 The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
jasikpark
reviewed
Dec 19, 2022
natemoo-re
commented
Dec 19, 2022
Comment on lines
15
to
+19
| type HoistedScripts struct { | ||
| Hoisted [][]byte | ||
| Body []byte | ||
| Hoisted [][]byte | ||
| HoistedLocs []loc.Loc | ||
| Body [][]byte | ||
| BodyLocs []loc.Loc |
Member
Author
There was a problem hiding this comment.
Previously we were throwing away all location info when hoisting imports/exports, which was obviously unhelpful!
Comment on lines
+162
to
+190
| exports := make([][]byte, 0) | ||
| exportLocs := make([]loc.Loc, 0) | ||
| bodies := make([][]byte, 0) | ||
| bodiesLocs := make([]loc.Loc, 0) | ||
|
|
||
| if len(render.Body) > 0 { | ||
| for i, innerBody := range render.Body { | ||
| innerStart := render.BodyLocs[i].Start | ||
| if len(bytes.TrimSpace(innerBody)) == 0 { | ||
| continue | ||
| } | ||
|
|
||
| // Extract exports | ||
| preprocessed := js_scanner.HoistExports(append(innerBody, '\n')) | ||
| if len(preprocessed.Hoisted) > 0 { | ||
| for j, exported := range preprocessed.Hoisted { | ||
| exportedLoc := preprocessed.HoistedLocs[j] | ||
| exportLocs = append(exportLocs, loc.Loc{Start: start + innerStart + exportedLoc.Start}) | ||
| exports = append(exports, exported) | ||
| } | ||
| } | ||
|
|
||
| if len(preprocessed.Body) > 0 { | ||
| for j, body := range preprocessed.Body { | ||
| bodyLoc := preprocessed.BodyLocs[j] | ||
| bodiesLocs = append(bodiesLocs, loc.Loc{Start: start + innerStart + bodyLoc.Start}) | ||
| bodies = append(bodies, body) | ||
| } | ||
| } |
Member
Author
There was a problem hiding this comment.
This is interleaving import hoisting with export hoisting, which gets kinda hard to follow, but the main point is that we're preserving the location of each statement.
| if len(bytes.TrimSpace(body)) == 0 { | ||
| continue | ||
| } | ||
| p.printTextWithSourcemap(string(body), bodyLoc) |
Member
Author
There was a problem hiding this comment.
Now we can print these with intact location info!
* Add internal/js_scanner/js_scanner_test.go#FuzzHoistImport Runnable via `go test ./internal/js_scanner -fuzz=FuzzHoistImports` * Update internal/js_scanner/js_scanner_test.go Co-authored-by: Nate Moore <natemoo-re@users.noreply.github.com> * fix(js_scanner): assert that i < len(source) when scanning Co-authored-by: Nate Moore <natemoo-re@users.noreply.github.com> Co-authored-by: Nate Moore <nate@astro.build>
Contributor
|
woot 🥳 |
natemoo-re
added a commit
that referenced
this pull request
Dec 20, 2022
This reverts commit 20497f4.
Merged
natemoo-re
added a commit
that referenced
this pull request
Dec 20, 2022
Merged
natemoo-re
added a commit
that referenced
this pull request
Dec 20, 2022
natemoo-re
added a commit
that referenced
this pull request
Jan 4, 2023
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Changes
Testing
Tested manually using https://evanw.github.io/source-map-visualization/
CleanShot.2022-12-19.at.14.08.16.mp4
Docs
N/A