fix(semantic): no error in check_function_redeclaration for CommonJS files#18231
Conversation
How to use the Graphite Merge QueueAdd either label to this PR to merge it via the merge queue:
You must have a Graphite account in order to use the merge queue. Sign up using this link. An organization admin has enabled the Graphite Merge Queue in this repository. Please do not merge from GitHub as this will restart CI on PRs being processed by the merge queue. This stack of pull requests is managed by Graphite. Learn more about stacking. |
Merging this PR will not alter performance
Comparing Footnotes
|
There was a problem hiding this comment.
Pull request overview
This PR fixes a regression in check_function_redeclaration that was introduced when the commonjs source type was added. The change restores the previous behavior where CommonJS files are treated like scripts (not modules) for function redeclaration checking.
Changes:
- Updated the condition in
check_function_redeclarationfromis_script()to!is_module()to correctly identify non-module files (Script, CommonJS, and Unambiguous)
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Merge activity
|
…S files (#18231) I can't get my head around exactly what `check_function_redeclaration` is checking, so I'm not 100% sure about this change. But certainly this PR will make sure that behavior for CommonJS files is the same as it was before the introduction of `commonjs` source type. Before `commonjs` source type existed: * Module: `source_type.is_script() == false` * Script: `source_type.is_script() == true` * CommonJS: `source_type.is_script() == true` After introduction of `commonjs` source type: * Module: `source_type.is_script() == false` * Script: `source_type.is_script() == true` * CommonJS: `source_type.is_script() == false` **(CHANGED)** After this PR: * Module: `!source_type.is_module() == false` * Script: `!source_type.is_module() == true` * CommonJS: `!source_type.is_module() == true` **(CHANGED BACK)**
f5fb3a7 to
4251813
Compare
…S files (#18231) I can't get my head around exactly what `check_function_redeclaration` is checking, so I'm not 100% sure about this change. But certainly this PR will make sure that behavior for CommonJS files is the same as it was before the introduction of `commonjs` source type. Before `commonjs` source type existed: * Module: `source_type.is_script() == false` * Script: `source_type.is_script() == true` * CommonJS: `source_type.is_script() == true` After introduction of `commonjs` source type: * Module: `source_type.is_script() == false` * Script: `source_type.is_script() == true` * CommonJS: `source_type.is_script() == false` **(CHANGED)** After this PR: * Module: `!source_type.is_module() == false` * Script: `!source_type.is_module() == true` * CommonJS: `!source_type.is_module() == true` **(CHANGED BACK)**
4251813 to
f1e2dc0
Compare
### 🐛 Bug Fixes - f1e2dc0 semantic: No error in `check_function_redeclaration` for CommonJS files (#18231) (overlookmotel) - 645c3f0 transformer: Use `require` not `import` in CommonJS files (#18226) (overlookmotel) - ee9f6a4 mangler: Use `retain` instead of `truncate` to remove empty frequency slots (#18225) (Dunqing) ### ⚡ Performance - 52073d9 semantic: Use cheaper test for source type (#18235) (overlookmotel) Co-authored-by: overlookmotel <557937+overlookmotel@users.noreply.github.com>
Follow-on after #18231. Add test cases to make sure function redeclaration check works correctly in script, module, and CommonJS files.

I can't get my head around exactly what
check_function_redeclarationis checking, so I'm not 100% sure about this change. But certainly this PR will make sure that behavior for CommonJS files is the same as it was before the introduction ofcommonjssource type.Before
commonjssource type existed:source_type.is_script() == falsesource_type.is_script() == truesource_type.is_script() == trueAfter introduction of
commonjssource type:source_type.is_script() == falsesource_type.is_script() == truesource_type.is_script() == false(CHANGED)After this PR:
!source_type.is_module() == false!source_type.is_module() == true!source_type.is_module() == true(CHANGED BACK)