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

Allow functions to redeclare vars and functions in function scopes #5248

Merged
merged 1 commit into from Nov 14, 2023

Conversation

lukastaegert
Copy link
Member

This PR contains:

  • bugfix
  • feature
  • refactor
  • documentation
  • other

Are tests included?

  • yes (bugfixes and features will not be merged without tests)
  • no

Breaking Changes?

  • yes (breaking changes will not be merged unless absolutely necessary)
  • no

List any relevant issue numbers:

Description

Apparently, the semantics for duplicate function names differ between function scopes and other scopes: In function scopes, function can redeclare function and var while in other scopes it is forbidden

Copy link

vercel bot commented Nov 13, 2023

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
rollup ✅ Ready (Inspect) Visit Preview 💬 Add feedback Nov 13, 2023 8:10am

Copy link

github-actions bot commented Nov 13, 2023

Thank you for your contribution! ❤️

You can try out this pull request locally by installing Rollup via

npm install rollup/rollup#gh-5247-function-redeclaration

Notice: Ensure you have installed Rust nightly. If you haven't installed it yet, please first see https://www.rust-lang.org/tools/install to learn how to download Rustup and install Rust, then see https://rust-lang.github.io/rustup/concepts/channels.html to learn how to install Rust nightly.

or load it into the REPL:
https://rollup-4877i9lit-rollup-js.vercel.app/repl/?pr=5248

Copy link

codecov bot commented Nov 13, 2023

Codecov Report

Merging #5248 (ad51fad) into master (53d6360) will increase coverage by 0.00%.
The diff coverage is 100.00%.

@@           Coverage Diff           @@
##           master    #5248   +/-   ##
=======================================
  Coverage   98.89%   98.89%           
=======================================
  Files         231      232    +1     
  Lines        8926     8936   +10     
  Branches     2332     2333    +1     
=======================================
+ Hits         8827     8837   +10     
  Misses         40       40           
  Partials       59       59           
Files Coverage Δ
src/ast/scopes/CatchBodyScope.ts 100.00% <ø> (ø)
src/ast/scopes/FunctionBodyScope.ts 100.00% <100.00%> (ø)
src/ast/scopes/ParameterScope.ts 100.00% <ø> (ø)
src/ast/scopes/Scope.ts 100.00% <100.00%> (ø)

@sapphi-red
Copy link
Contributor

It seems cases like these are not allowed. This PR allows them.

{
  var fn
  function fn () {}
}

acorn playground
rollup repl for this PR

@lukastaegert
Copy link
Member Author

Yes, please try again. So apparently the logic is still different from what I assumed: Redeclaring functions and stuff with functions is forbidden in nearly all scopes except function scopes, where apparently anything goes... Who made this up!??

@sapphi-red
Copy link
Contributor

Great! The behavior looks good to me. Yeah, it's really complicated. 🫠

@lukastaegert lukastaegert merged commit 70b7b90 into master Nov 14, 2023
27 checks passed
@lukastaegert lukastaegert deleted the gh-5247-function-redeclaration branch November 14, 2023 05:11
Copy link

This PR has been released as part of rollup@4.4.1. You can test it via npm install rollup.

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

Successfully merging this pull request may close these issues.

[!] (plugin commonjs--resolver) RollupError: Identifier "fn" has already been declared
2 participants