fix(styled-components): keep locals in nested css prop member chains - #660
Open
Mitch Follett (mitch-282) wants to merge 2 commits into
Open
Mitch Follett (mitch-282) wants to merge 2 commits into
Mitch Follett (mitch-282) wants to merge 2 commits into
Conversation
is_direct_access treated an interpolation as module-level when the chain's
root was top-level and the outermost node had no local computed key. In
`${SIZES[size].bottom}` the outermost node is `.bottom`, so the inner
`[size]` was never checked and the expression was hoisted out of the
component, where `size` is undefined.
has_only_direct_keys now checks every computed key and call argument along
the member/call chain.
Fixes swc-project#659
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
|
Codex usage limits have been reached for code reviews. Please check with the admins of this repo to increase the limits by adding credits. |
🦋 Changeset detectedLatest commit: 4ab1d16 The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
|
|
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes #659.
A
cssprop interpolation whose member chain has a local in a computed key past the first step, such as${SIZES[size].bottom}, was hoisted into the generated styled component.sizeis out of scope there, so the module threwReferenceErroron load.is_direct_accessfound the root (SIZES, top-level) and then checked only the outermost node for a computed key. InSIZES[size].bottomthat node is.bottom, so[size]was never looked at. The newhas_only_direct_keyswalks the whole member/call chain and requires every computed key and call argument to be a direct access itself. Chains that were already classified correctly are unaffected.Tests
New fixture
transpile-css-prop-nested-member:${SIZES[size].bottom}and${SIZES.get(size).bottom}now pass through as$_cssprops.${SIZES[KEY].bottom}with a module-levelKEYis still hoisted.All 38 styled-components fixture tests pass, and no existing fixture output changed.
Not addressed here: a hoisted styled component is emitted above the module-level
consts it reads (_StyledBox3aboveSIZESin the fixture output). Its template is evaluated at module load, so that throws a TDZReferenceErrorwhenever theconstis declared after the imports. That's existing behaviour for any hoisted access, and probably wants its own issue.