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

[Bug]: sourceFileName vs. sourceFilename scattered differently over project, sometimes typed wrong #13170

Closed
1 task
wooorm opened this issue Apr 18, 2021 · 5 comments · Fixed by #13532
Closed
1 task
Assignees
Labels
i: enhancement outdated A closed issue/PR that is archived due to age. Recommended to make a new issue pkg: cli

Comments

@wooorm
Copy link

wooorm commented Apr 18, 2021

  • Would you like to work on a fix?

How are you using Babel?

Programmatic API (babel.transform, babel.parse)

Input code

n/a

Configuration file name

No response

Configuration

n/a

Current and expected behavior

  function myFancyBabelPlugin() {
    return {
      parserOverride(contents, options) {
        if (
          options.sourceFileName &&

^-- type error “Did you mean 'sourceFilename'”, but sourceFilename is undefined and sourceFileName is set.
A bit of searching shows differently cased values: https://github.com/babel/babel/search?q=sourceFilename+path%3Apackages.

Environment

$ npx envinfo --preset
Need to install the following packages:
  envinfo
Ok to proceed? (y) y

No "true" preset found.

Possible solution

picking either

Additional context

Actual code is here: https://github.com/wooorm/xdm/blob/main/test/babel.js#L37-L41.

@babel-bot
Copy link
Collaborator

Hey @wooorm! 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."

@fedeci
Copy link
Member

fedeci commented May 16, 2021

That's because different packages are now using different option name. We may align the syntax in Babel 8 because it is a breaking change. I would prefer to replace fileName with filename in @babel/cli instead of the opposite.

@wooorm
Copy link
Author

wooorm commented May 16, 2021

I can understand differently cases due to history, and would welcome a single case. But it remains that the types are incorrect, and fixing that doesn’t have to be a major

@nicolo-ribaudo
Copy link
Member

We can start by allowing both the current "mixed" versions and the consistent versions in the next minor; then in Babel 8 we can remove the "mixed" versions (and yes, we should fix the type definitions).

@fedeci fedeci self-assigned this May 17, 2021
@fedeci
Copy link
Member

fedeci commented Jun 27, 2021

I did some research while changing all occurrences of sourceFileName with sourceFilename and discovered that the error of the issue is caused by the following lines

parserOpts: {
sourceType:
path.extname(filenameRelative) === ".mjs" ? "module" : sourceType,
sourceFileName: filename,

We are setting the unused sourceFileName parser option and, in fact, commenting line 33 results in no tests failing, because there is "nothing to break".

@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 Nov 19, 2021
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Nov 19, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
i: enhancement outdated A closed issue/PR that is archived due to age. Recommended to make a new issue pkg: cli
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants