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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bug]: Source-map name mappings #15647

Closed
1 task
lNikolayl opened this issue May 24, 2023 · 3 comments
Closed
1 task

[Bug]: Source-map name mappings #15647

lNikolayl opened this issue May 24, 2023 · 3 comments

Comments

@lNikolayl
Copy link

lNikolayl commented May 24, 2023

馃捇

  • Would you like to work on a fix?

How are you using Babel?

Other (Next.js, Gatsby, vue-cli, ...)

Input code

Possible way to reproduce:

import * as babel from '@babel/core';

babel.transform('function someFunctionName(arg1, arg2) {}', { sourceMap: true });

Configuration file name

No response

Configuration

No response

Current and expected behavior

Current source map:

{
    "version": 3,
    "names": [
        "someFunctionName",
        "arg1",
        "arg2"
    ],
    "sources": [
        "unknown"
    ],
    "sourcesContent": [
        "function someFunctionName(arg1, arg2) {}"
    ],
    "mappings": "AAAA,SAASA,gBAAgBA,CAACC,IAAI,EAAEC,IAAI,EAAE,CAAC"
}

After mappings decoding:

[
  [0, 0, 0, 0],
  [9, 0, 0, 9, 0],
  [25, 0, 0, 25, 0],
  [26, 0, 0, 26, 1],
  [30, 0, 0, 30],
  [32, 0, 0, 32, 2],
  [36, 0, 0, 36],
  [38, 0, 0, 38],
  [39, 0, 0, 39],
]

On the previous version of babel (@babel/core: 7.20.12; @babel/generator: 7.20.14) mappings decoding is:

[
  [0, 0, 0, 0],
  [9, 0, 0, 9, 0],
  [25, 0, 0, 25],
  [26, 0, 0, 26, 1],
  [30, 0, 0, 30],
  [32, 0, 0, 32, 2],
  [36, 0, 0, 36],
  [38, 0, 0, 38],
  [39, 0, 0, 39],
]

Environment

npmPackages:
@babel/core: 7.21.5
@babel/generator: 7.21.5

Possible solution

On #15022 I've observed this change in methods.ts file:

const nameInfo = _getFuncIdName.call(this, idNode, parentNode);
if (nameInfo) {
  this.sourceIdentifierName(nameInfo.name, nameInfo.pos);
}

I suppose it should be moved to parameters function under arguments length check.

However I'm not in the context of this change in #15022 PR.

Additional context

We are using babel as part of ember-cli build. So, in the updated version we have an issue with source map validation. I was able to localize the issue to source map generation, specially to extra name field in the decoded mappings property of source map. If you will check the current and old behaviour you will find an extra element in the decoded mappings. This element represents the name index in the names array.

Note: Not really sure that it's an issue. However anyway it's breaking change of source map validation.

@babel-bot
Copy link
Collaborator

Hey @lNikolayl! We really appreciate you taking the time to report an issue. The collaborators on this project attempt to help as many people as possible, but we're a limited number of volunteers, so it's possible this won't be addressed swiftly.

If you need any help, or just have general Babel or JavaScript questions, we have a vibrant Slack community that typically always has someone willing to help. You can sign-up here for an invite.

@lNikolayl lNikolayl changed the title [Bug]: [Bug]: Source-map name mappings May 24, 2023
@liuxingbaoyu
Copy link
Member

I suppose it should be moved to parameters function under arguments length check.

However I'm not in the context of this change in #15022 PR.

Sorry I didn't understand what you mean, can you explain?

We append the identifier name to ( on purpose.
Because in many of the methods below, it is more desirable to append the identifier name to ( than to "fn"]:function(.

var a = {
   fn() {},
   fn:function() {},
   [fn]:function() {},
   ["fn"]:function() {},
   [function() {}]: function() {},
   [()=> {}]: function() {},
   [fn]() { },
   ["fn"]() { },
   [function() {}]() { },
   [()=> {}]() { }
}

More context here #14907

@lNikolayl
Copy link
Author

Oh, thank you, I got it. Inside Ember pipeline there is sourcemap validation stage and with the new version of babel all sourcemaps marked as invalid due to this change. In this case it's breaking change. Seems it should be addressed to the validator side. The issue is described here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants