Skip to content

Fix error when parsing ignored files with @babel/eslint-parser#13338

Merged
nicolo-ribaudo merged 1 commit intobabel:mainfrom
devfservant:fix-parsing-error
May 19, 2021
Merged

Fix error when parsing ignored files with @babel/eslint-parser#13338
nicolo-ribaudo merged 1 commit intobabel:mainfrom
devfservant:fix-parsing-error

Conversation

@devfservant
Copy link
Copy Markdown
Contributor

@devfservant devfservant commented May 19, 2021

This PR fixes several parsing errors which occurred in @babel/eslint-parser, in particular when a file was ignored.

Related issue: #13331

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

Changes

  • eslint-parser:
    • Implement fallback when normalizing config
    • Add corresponding test case

cc @JLHwung @nicolo-ribaudo @fedeci

@babel-bot
Copy link
Copy Markdown
Collaborator

babel-bot commented May 19, 2021

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

@codesandbox-ci
Copy link
Copy Markdown

codesandbox-ci bot commented May 19, 2021

This pull request is automatically built and testable in CodeSandbox.

To see build info of the built libraries, click here or the icon next to each commit SHA.

Latest deployment of this branch, based on commit 23caac0:

Sandbox Source
babel-repl-custom-plugin Configuration
babel-plugin-multi-config Configuration

@nicolo-ribaudo
Copy link
Copy Markdown
Member

I'm trying to better understand why plugins might be not set.

When the config is null because the file is ignored, || parseOptions at

return validateResolvedConfig(config, options) || parseOptions;
should replace it with our default config.

(I'll clone this PR locally and test it, but you might already have an answer 😁)

@nicolo-ribaudo
Copy link
Copy Markdown
Member

Ok, the source of the problem is that, while the result of loadPartialConfig will prevent Babel from resolving config files and ignores again, || parserOptions will still include ignore: ... and an empty plugins list.

A better fix would be to replace || parserOptions with something like || getDefaultConfig(parserOptions), which sets/deletes the necessary properties:

function getDefaultParserOptions(options) {
  return {
    plugins: [],
    ...options,
    babelrc: false,
    configFile: false,
    browserslistConfigFile: false,
    ignore: null,
    only: null
  };
}

@devfservant
Copy link
Copy Markdown
Contributor Author

Ok, of course, the best is to determine the root cause of all these errors 👍
I'll try to implement your suggestion!

@nicolo-ribaudo nicolo-ribaudo added area: eslint PR: Bug Fix 🐛 A type of pull request used for our changelog categories labels May 19, 2021
@nicolo-ribaudo
Copy link
Copy Markdown
Member

@devfservant I noticed that your commits aren't associated to your GitHub account. It doesn't matter for us, but if you want them to be linked to your account you can check https://docs.github.com/en/github/committing-changes-to-your-project/troubleshooting-commits/why-are-my-commits-linked-to-the-wrong-user#commits-are-not-linked-to-any-user

…el#13338)

* fix(babel-eslint-parser): prevent typeerror in maybeParse
* fix(babel-eslint-parser): prevent other typeerrors in convert modules
* test(babel-eslint-parser): test maybeParse when file is ignored
* refactor(babel-eslint-parser): use fallback options instead of typeerror protections

Co-authored-by: devfservant <43757707+devfservant@users.noreply.github.com>
Co-authored-by: François Servant <francois.servant.e@thalesdigital.io>
@nicolo-ribaudo
Copy link
Copy Markdown
Member

@devfservant I linked your commits both to your email (that you use in Git) and to your GitHub autogenerated email, so that they are linked to your account.

@nicolo-ribaudo nicolo-ribaudo merged commit 1219004 into babel:main May 19, 2021
@nicolo-ribaudo nicolo-ribaudo changed the title Fix multiple parsing errors in @babel/eslint-parser Fix error when parsing ignored files with @babel/eslint-parser May 19, 2021
@devfservant devfservant deleted the fix-parsing-error branch May 20, 2021 03:04
@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 Aug 19, 2021
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Aug 19, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

area: eslint outdated A closed issue/PR that is archived due to age. Recommended to make a new issue PR: Bug Fix 🐛 A type of pull request used for our changelog categories

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants