Skip to content

Commit

Permalink
Merge branch 'canary' into refactor/types
Browse files Browse the repository at this point in the history
  • Loading branch information
sokra committed Sep 21, 2021
2 parents 93303bd + 0976a04 commit f4683bb
Show file tree
Hide file tree
Showing 65 changed files with 3,378 additions and 2,420 deletions.
2 changes: 0 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -151,8 +151,6 @@
"seedrandom": "3.0.5",
"selenium-webdriver": "4.0.0-beta.4",
"shell-quote": "1.7.2",
"sqlite": "4.0.22",
"sqlite3": "5.0.2",
"styled-jsx-plugin-postcss": "3.0.2",
"tailwindcss": "1.1.3",
"taskr": "1.1.0",
Expand Down
84 changes: 45 additions & 39 deletions packages/next/build/swc/src/styled_jsx/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,12 @@ pub fn compute_class_names(
let mut dynamic_styles = vec![];
let mut external_styles = vec![];
for style_info in styles {
match &style_info {
match style_info {
JSXStyle::Local(style_info) => {
if !style_info.is_dynamic {
static_hashes.push(style_info.hash.clone());
} else {
dynamic_styles.push(style_info.clone());
dynamic_styles.push(style_info);
}
}
JSXStyle::External(external) => {
Expand Down Expand Up @@ -82,43 +82,49 @@ pub fn compute_class_names(
span: DUMMY_SP,
computed: false,
}))),
args: dynamic_styles
.iter()
.map(|style_info| {
let hash_input = match &static_class_name {
Some(class_name) => format!("{}{}", style_info.hash, class_name),
None => style_info.hash.clone(),
};
ExprOrSpread {
expr: Box::new(Expr::Array(ArrayLit {
elems: vec![
Some(ExprOrSpread {
expr: Box::new(string_literal_expr(&hash_string(&hash_input))),
spread: None,
}),
Some(ExprOrSpread {
expr: Box::new(Expr::Array(ArrayLit {
elems: style_info
.expressions
.iter()
.map(|expression| {
Some(ExprOrSpread {
expr: expression.clone(),
spread: None,
})
})
.collect(),
span: DUMMY_SP,
})),
spread: None,
}),
],
span: DUMMY_SP,
})),
spread: None,
}
})
.collect(),
args: vec![ExprOrSpread {
expr: Box::new(Expr::Array(ArrayLit {
elems: dynamic_styles
.iter()
.map(|style_info| {
let hash_input = match &static_class_name {
Some(class_name) => format!("{}{}", style_info.hash, class_name),
None => style_info.hash.clone(),
};
Some(ExprOrSpread {
expr: Box::new(Expr::Array(ArrayLit {
elems: vec![
Some(ExprOrSpread {
expr: Box::new(string_literal_expr(&hash_string(&hash_input))),
spread: None,
}),
Some(ExprOrSpread {
expr: Box::new(Expr::Array(ArrayLit {
elems: style_info
.expressions
.iter()
.map(|expression| {
Some(ExprOrSpread {
expr: expression.clone(),
spread: None,
})
})
.collect(),
span: DUMMY_SP,
})),
spread: None,
}),
],
span: DUMMY_SP,
})),
spread: None,
})
})
.collect(),
span: DUMMY_SP,
})),
spread: None,
}],
span: DUMMY_SP,
type_args: None,
})),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,19 @@ export const Test2 = ()=><div className={"jsx-81a68341e430a972 " + `jsx-${styles
</div>
;
export const Test3 = ({ color })=><div className={`jsx-${styles.__hash}` + " " + _JSXStyle.dynamic([
"26b457d3bc475235",
[
color
"26b457d3bc475235",
[
color
]
]
])}>
<p className={`jsx-${styles.__hash}` + " " + _JSXStyle.dynamic([
"26b457d3bc475235",
[
color
"26b457d3bc475235",
[
color
]
]
])}>external and dynamic</p>
<_JSXStyle id={"26b457d3bc475235"} dynamic={[
Expand All @@ -32,15 +36,19 @@ export const Test3 = ({ color })=><div className={`jsx-${styles.__hash}` + " "
</div>
;
export const Test4 = ({ color })=><div className={`jsx-${styles.__hash}` + " jsx-ceba8c9ce34e3d0c " + _JSXStyle.dynamic([
"e6cca97eb9ca1a15",
[
color
"e6cca97eb9ca1a15",
[
color
]
]
])}>
<p className={`jsx-${styles.__hash}` + " jsx-ceba8c9ce34e3d0c " + _JSXStyle.dynamic([
"e6cca97eb9ca1a15",
[
color
"e6cca97eb9ca1a15",
[
color
]
]
])}>external, static and dynamic</p>
<_JSXStyle id={"ceba8c9ce34e3d0c"}>{"p.jsx-ceba8c9ce34e3d0c {display:inline-block}"}</_JSXStyle>
Expand All @@ -57,15 +65,19 @@ export const Test5 = ()=><div className={"jsx-df0159ebd3f9fb6f"}>
</div>
;
export const Test6 = ({ color })=><div className={"jsx-ceba8c9ce34e3d0c " + _JSXStyle.dynamic([
"a55f0611581d64ca",
[
color
"a55f0611581d64ca",
[
color
]
]
])}>
<p className={"jsx-ceba8c9ce34e3d0c " + _JSXStyle.dynamic([
"a55f0611581d64ca",
[
color
"a55f0611581d64ca",
[
color
]
]
])}>static and dynamic</p>
<_JSXStyle id={"ceba8c9ce34e3d0c"}>{"p.jsx-ceba8c9ce34e3d0c {display:inline-block}"}</_JSXStyle>
Expand All @@ -75,15 +87,19 @@ export const Test6 = ({ color })=><div className={"jsx-ceba8c9ce34e3d0c " + _JS
</div>
;
export const Test7 = ({ color })=><div className={_JSXStyle.dynamic([
"4adc07771eb3723",
[
color
"4adc07771eb3723",
[
color
]
]
])}>
<p className={_JSXStyle.dynamic([
"4adc07771eb3723",
[
color
"4adc07771eb3723",
[
color
]
]
])}>dynamic only</p>
<_JSXStyle id={"4adc07771eb3723"} dynamic={[
Expand All @@ -97,15 +113,19 @@ export const Test8 = ({ color })=>{
color
};
return <div className={_JSXStyle.dynamic([
"a552a4a765a9ca4e",
[
innerProps.color
"a552a4a765a9ca4e",
[
innerProps.color
]
]
])}>
<p className={_JSXStyle.dynamic([
"a552a4a765a9ca4e",
[
innerProps.color
"a552a4a765a9ca4e",
[
innerProps.color
]
]
])}>dynamic with scoped compound variable</p>
<_JSXStyle id={"a552a4a765a9ca4e"} dynamic={[
Expand All @@ -119,15 +139,19 @@ export const Test9 = ({ color })=>{
color
};
return <div className={_JSXStyle.dynamic([
"7ef39e3312c80ead",
[
innerProps.color
"7ef39e3312c80ead",
[
innerProps.color
]
]
])}>
<p className={_JSXStyle.dynamic([
"7ef39e3312c80ead",
[
innerProps.color
"7ef39e3312c80ead",
[
innerProps.color
]
]
])}>dynamic with compound variable</p>
<_JSXStyle id={"7ef39e3312c80ead"} dynamic={[
Expand All @@ -145,9 +169,11 @@ export const Test11 = ({ color })=>{
const items = Array.from({
length: 5
}).map((item, i)=><li key={i} className={_JSXStyle.dynamic([
"ebe03db0369a2939",
[
color
"ebe03db0369a2939",
[
color
]
]
]) + " " + "item"}>
<_JSXStyle id={"ebe03db0369a2939"} dynamic={[
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,35 +10,43 @@ const obj = {
display: "block"
};
export default (({ display })=><div className={"jsx-802e359ee0ab20c4 " + _JSXStyle.dynamic([
"76aa3eae4e21e4ca",
[
display ? "block" : "none"
]
], [
"5ba905f763f40220",
"76aa3eae4e21e4ca",
[
display ? "block" : "none"
]
],
[
darken(color) + 2
]
], [
"c4bb394aae9bd00b",
"5ba905f763f40220",
[
darken(color) + 2
]
],
[
darken(color)
"c4bb394aae9bd00b",
[
darken(color)
]
]
])}>
<p className={"jsx-802e359ee0ab20c4 " + _JSXStyle.dynamic([
"76aa3eae4e21e4ca",
[
display ? "block" : "none"
]
], [
"5ba905f763f40220",
"76aa3eae4e21e4ca",
[
display ? "block" : "none"
]
],
[
darken(color) + 2
]
], [
"c4bb394aae9bd00b",
"5ba905f763f40220",
[
darken(color) + 2
]
],
[
darken(color)
"c4bb394aae9bd00b",
[
darken(color)
]
]
])}>test</p>
<_JSXStyle id={"f3d3af42197b4734"}>{`p.${color}.jsx-802e359ee0ab20c4 {color:${otherColor};
Expand Down
18 changes: 12 additions & 6 deletions packages/next/build/swc/tests/fixture/styled-jsx/styles/output.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,11 @@ foo.__hash = "e46da79e05d23fff";
]}>{`div.__jsx-style-dynamic-selector {color:${colors.green.light}}
a.__jsx-style-dynamic-selector {color:red}`}</_JSXStyle>,
className: _JSXStyle.dynamic([
"12e2c41a8d37fe78",
[
colors.green.light
"12e2c41a8d37fe78",
[
colors.green.light
]
]
])
});
Expand All @@ -28,9 +30,11 @@ const b = {
]}>{`div.__jsx-style-dynamic-selector {color:${colors.green.light}}
a.__jsx-style-dynamic-selector {color:red}`}</_JSXStyle>,
className: _JSXStyle.dynamic([
"d5617758481f82cd",
[
colors.green.light
"d5617758481f82cd",
[
colors.green.light
]
]
])
};
Expand All @@ -41,9 +45,11 @@ const dynamic = (colors)=>{
]}>{`div.__jsx-style-dynamic-selector {color:${colors.green.light}}
a.__jsx-style-dynamic-selector {color:red}`}</_JSXStyle>,
className: _JSXStyle.dynamic([
"a7ac579c753e9d90",
[
colors.green.light
"a7ac579c753e9d90",
[
colors.green.light
]
]
])
};
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
import _JSXStyle from "styled-jsx/style";
export default function Home({ fontFamily }) {
return <div className={_JSXStyle.dynamic([
"2566fdd7bc25c35",
[
fontFamily
"2566fdd7bc25c35",
[
fontFamily
]
]
])}>
<_JSXStyle id={"2566fdd7bc25c35"} dynamic={[
Expand Down
2 changes: 1 addition & 1 deletion packages/next/compiled/@vercel/nft/index.js

Large diffs are not rendered by default.

0 comments on commit f4683bb

Please sign in to comment.