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 line numbers in case of commonJS file with no sourcemap #3687

Merged
merged 2 commits into from
Apr 12, 2024

Conversation

mstoykov
Copy link
Collaborator

What?

Fix line numbers in case of commonJS file with no sourcemap:

exports.something = "something"
throw "b"; // this was line 3 

Why?

Previously if someone imports or runs a commonJS file (one that won't
need to go through babel) we still need to wrap it in some code to run
it. But we don't have a sourcemap to update, unless it already had
one(internal babel adds it). This leads to all lines being off by 1.

This is fixed by updating the sourcemap in the other case.

Unfortunately short of generating an "identity" sourcemap and then
shifting it by 1 with adding ; to the first mapping, this can't be
done.

The sourcemap implementation specifically wants to find each mapping, so
unless it can do that it will not do anything.

The remaining hack (adjusting any available sourcemap) still stands as
it also fixes the columns on the first line of the file. As well as
actually being better.

Also found that while fixing linter issue I broke the tc39 error generation :(.

Checklist

  • I have performed a self-review of my code.
  • I have added tests for my changes.
  • I have run linter locally (make lint) and all checks pass.
  • I have run tests locally (make tests) and all tests pass.
  • I have commented on my code, particularly in hard-to-understand areas.

Related PR(s)/Issue(s)

@mstoykov mstoykov added the bug label Apr 11, 2024
@mstoykov mstoykov added this to the v0.51.0 milestone Apr 11, 2024
@mstoykov mstoykov requested a review from a team as a code owner April 11, 2024 16:16
@mstoykov mstoykov requested review from oleiade and olegbespalov and removed request for a team April 11, 2024 16:16
@codecov-commenter
Copy link

codecov-commenter commented Apr 11, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 73.33%. Comparing base (a62140c) to head (98da449).
Report is 1 commits behind head on master.

❗ Current head 98da449 differs from pull request most recent head e371e6d. Consider uploading reports for the commit e371e6d to get more accurate results

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #3687      +/-   ##
==========================================
- Coverage   73.33%   73.33%   -0.01%     
==========================================
  Files         278      278              
  Lines       20329    20332       +3     
==========================================
+ Hits        14908    14910       +2     
- Misses       4477     4478       +1     
  Partials      944      944              
Flag Coverage Δ
macos ?
ubuntu 73.25% <100.00%> (-0.02%) ⬇️
windows 73.17% <100.00%> (+<0.01%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

oleiade
oleiade previously approved these changes Apr 12, 2024
Copy link
Member

@oleiade oleiade left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚀 🚀

js/compiler/compiler.go Outdated Show resolved Hide resolved
olegbespalov
olegbespalov previously approved these changes Apr 12, 2024
Previously if someone imports or runs a commonJS file (one that won't
need to go through babel) we still need to wrap it in some code to run
it. But we don't have a sourcemap to update, unless it already had
one(internal babel adds it). This leads to all lines being off by 1.

This is fixed by updating the sourcemap in the other case.

Unfortunately short of generating an "identity" sourcemap and then
shifting it by 1 with adding `;` to the first mapping, this can't be
done.

The sourcemap implementation specifically wants to find each mapping, so
unless it can do that it will not do anything.

The remaining hack (adjusting any available sourcemap) still stands as
it also fixes the columns on the *first* line of the file. As well as
actually being better.
@mstoykov mstoykov merged commit e201243 into master Apr 12, 2024
23 of 25 checks passed
@mstoykov mstoykov deleted the sourceMapFix branch April 12, 2024 13:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants