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

Use maybeAddMapping to add sourcemap markings #14510

Merged
merged 4 commits into from
Apr 30, 2022

Conversation

jridgewell
Copy link
Member

@jridgewell jridgewell commented Apr 30, 2022

Q                       A
Fixed Issues?
Patch: Bug Fix?
Major: Breaking Change?
Minor: New Feature?
Tests Added + Pass? Yes
Documentation PR Link
Any Dependency Changes?
License MIT

Projects trying to create sourcemaps shouldn't have to concern themselves with whether adding a mapping is useful or just clutters the mappings. gen-mapping has newly introduced maybeAddMapping which will determine if a mapping is useful, or skip it.

This lets the generator decide whether a mapping is worth keeping, instead of implementing it in every project that wants to produce a sorucemap.
@babel-bot
Copy link
Collaborator

babel-bot commented Apr 30, 2022

Build successful! You can test your changes in the REPL here: https://babeljs.io/repl/build/51811/

@babel-bot
Copy link
Collaborator

Build successful! You can test your changes in the REPL here: https://babeljs.io/repl/build/51807/

jest.config.js Outdated
runner: supportsESMAndJestLightRunner ? "jest-light-runner" : "jest-runner",
runner:
supportsESMAndJestLightRunner && !debug
? "jest-light-runner"
Copy link
Member Author

Choose a reason for hiding this comment

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

I think light runner is running in a Worker? I'm also having troubles when using TEST_DEBUG with a test label, it only seems to work when I use a describe label.

Copy link
Member

Choose a reason for hiding this comment

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

#14488 adds --runInBand support.

@@ -1,13 +1,15 @@
{
"mappings": "AAAC;ACAD,K",
"version": 3,
"mappings": "AAAC,KCAD;ACAA,K",
Copy link
Member Author

Choose a reason for hiding this comment

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

This is actually a bug fix. We were testing:

if (
  this._lastGenLine === generatedLine &&
  this._lastSourceLine === line &&
  this._lastSourceColumn === column
) {
  return;
}

However, we forgot to check whether the filename is different! Eg, here were on the same generated line, and pointing at the same source line/column. But we're pointing at two totally separate source files. AAAC is pointing at the firs file, and KCAD is pointing at the second file.

// start of this range. We use 'force' here to explicitly start a new
// mapping range for this new token.
this.source("start", loc, true /* force */);
this.source("start", loc);
Copy link
Member Author

Choose a reason for hiding this comment

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

We no longer need to force. gen-mapping can determine that a name index has changed, and will preserve the mapping.

Eg, const foo = x => y;, we have two mappings pointing at the x variable. The first mapping is the arrow function, and it does not have a name field. The second mapping is for the identifier, and it does have a name. Because the name changed between the mappings, we'll keep both mappings instead of skipping the second. This is what force accomplished because we didn't check for identifierName changes in the lastXyz === xyz section.

Copy link
Member

@nicolo-ribaudo nicolo-ribaudo left a comment

Choose a reason for hiding this comment

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

Approving, but the jest.config.js changes can/should be reverted.

jest-light-runner update will fix this.
@jridgewell
Copy link
Member Author

Reverted changes to jest.config.js

@nicolo-ribaudo nicolo-ribaudo merged commit 4ce5740 into babel:main Apr 30, 2022
@jridgewell jridgewell deleted the sourcemap-maybeAdd branch April 30, 2022 22:13
@github-actions github-actions bot added the outdated A closed issue/PR that is archived due to age. Recommended to make a new issue label Jul 31, 2022
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jul 31, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area: sourcemaps outdated A closed issue/PR that is archived due to age. Recommended to make a new issue
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants