-
-
Notifications
You must be signed in to change notification settings - Fork 57
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(styled-components): handle
topLevelIdent[localIdent]
in templat…
…e literal (#233) This fixes local identifiers are not handled properly in styled-components tagged literal. ## Input code ```jsx const id = (x) => x const colorMap = { orange: '#E3750E', blue: '#38699F', green: '#3F9348', } const Colored = (color, text) => { return ( <div css={css` /* ${color} */ color: ${colorMap[color]}; background-color: ${id(color)}; `} > {text} </div> ) } ``` ## Previous output Local variable `color` is referenced outside the function. ```jsx import _styled from "styled-components"; const id = (x)=>x; const colorMap = { orange: '#E3750E', blue: '#38699F', green: '#3F9348' }; const Colored = (color, text)=>{ return <_StyledDiv $_css={color} $_css2={id(color)}> {text} </_StyledDiv>; }; var _StyledDiv = _styled("div")` /* ${(p)=>p.$_css} */ color: ${colorMap[color]}; background-color: ${(p)=>p.$_css2}; `; ``` ## Fixed output ```jsx import _styled from "styled-components"; const id = (x)=>x; const colorMap = { orange: '#E3750E', blue: '#38699F', green: '#3F9348' }; const Colored = (color, text)=>{ return <_StyledDiv $_css={color} $_css2={colorMap[color]} $_css3={id(color)}> {text} </_StyledDiv>; }; var _StyledDiv = _styled("div")` /* ${(p)=>p.$_css} */ color: ${(p)=>p.$_css2}; background-color: ${(p)=>p.$_css3}; `; ``` fixes #194 related to #100
- Loading branch information
Showing
3 changed files
with
155 additions
and
9 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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