@swc/plugin-styled-jsx 1.5.84 → 1.5.86
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/swc_plugin_styled_jsx.wasm +0 -0
- package/transform/Cargo.toml +0 -39
- package/transform/src/lib.rs +0 -7
- package/transform/src/lifetime.rs +0 -408
- package/transform/src/style.rs +0 -25
- package/transform/src/transform_css_lightningcss.rs +0 -589
- package/transform/src/transform_css_swc.rs +0 -392
- package/transform/src/utils.rs +0 -371
- package/transform/src/visitor.rs +0 -963
- package/transform/tests/errors/nested-style-tags/input.js +0 -31
- package/transform/tests/errors/nested-style-tags/output-lightningcss.js +0 -58
- package/transform/tests/errors/nested-style-tags/output-lightningcss.stderr +0 -27
- package/transform/tests/errors/nested-style-tags/output-swc.js +0 -58
- package/transform/tests/errors/nested-style-tags/output-swc.stderr +0 -27
- package/transform/tests/errors/nested-style-tags/output.js +0 -58
- package/transform/tests/errors/no-child/input.js +0 -6
- package/transform/tests/errors/no-child/output-lightningcss.js +0 -8
- package/transform/tests/errors/no-child/output-lightningcss.stderr +0 -9
- package/transform/tests/errors/no-child/output-swc.js +0 -8
- package/transform/tests/errors/no-child/output-swc.stderr +0 -9
- package/transform/tests/errors/no-child/output.js +0 -8
- package/transform/tests/errors/ts-with-css-resolve/input.js +0 -10
- package/transform/tests/errors/ts-with-css-resolve/output-lightningcss.js +0 -5
- package/transform/tests/errors/ts-with-css-resolve/output-lightningcss.stderr +0 -2
- package/transform/tests/errors/ts-with-css-resolve/output-swc.js +0 -5
- package/transform/tests/errors/ts-with-css-resolve/output-swc.stderr +0 -2
- package/transform/tests/errors/ts-with-css-resolve/output.js +0 -5
- package/transform/tests/errors/two-children/input.js +0 -8
- package/transform/tests/errors/two-children/output-lightningcss.js +0 -12
- package/transform/tests/errors/two-children/output-lightningcss.stderr +0 -11
- package/transform/tests/errors/two-children/output-swc.js +0 -12
- package/transform/tests/errors/two-children/output-swc.stderr +0 -11
- package/transform/tests/errors/two-children/output.js +0 -12
- package/transform/tests/errors/wrong-child-type/input.js +0 -7
- package/transform/tests/errors/wrong-child-type/output-lightningcss.js +0 -10
- package/transform/tests/errors/wrong-child-type/output-lightningcss.stderr +0 -10
- package/transform/tests/errors/wrong-child-type/output-swc.js +0 -10
- package/transform/tests/errors/wrong-child-type/output-swc.stderr +0 -10
- package/transform/tests/errors/wrong-child-type/output.js +0 -10
- package/transform/tests/errors/wrong-jsx-expression-type/input.js +0 -7
- package/transform/tests/errors/wrong-jsx-expression-type/output-lightningcss.js +0 -10
- package/transform/tests/errors/wrong-jsx-expression-type/output-lightningcss.stderr +0 -10
- package/transform/tests/errors/wrong-jsx-expression-type/output-swc.js +0 -10
- package/transform/tests/errors/wrong-jsx-expression-type/output-swc.stderr +0 -10
- package/transform/tests/errors/wrong-jsx-expression-type/output.js +0 -10
- package/transform/tests/fixture/.expressions/input.js +0 -90
- package/transform/tests/fixture/absent/input.js +0 -6
- package/transform/tests/fixture/absent/output.lightningcss.js +0 -7
- package/transform/tests/fixture/absent/output.swc.js +0 -7
- package/transform/tests/fixture/attribute-generation-classname-rewriting/input.js +0 -55
- package/transform/tests/fixture/attribute-generation-classname-rewriting/output.lightningcss.js +0 -112
- package/transform/tests/fixture/attribute-generation-classname-rewriting/output.swc.js +0 -112
- package/transform/tests/fixture/attribute-generation-modes/input.js +0 -166
- package/transform/tests/fixture/attribute-generation-modes/output.lightningcss.js +0 -228
- package/transform/tests/fixture/attribute-generation-modes/output.swc.js +0 -228
- package/transform/tests/fixture/class/input.js +0 -14
- package/transform/tests/fixture/class/output.lightningcss.js +0 -12
- package/transform/tests/fixture/class/output.swc.js +0 -12
- package/transform/tests/fixture/comments/input.js +0 -18
- package/transform/tests/fixture/comments/output.lightningcss.js +0 -12
- package/transform/tests/fixture/comments/output.swc.js +0 -12
- package/transform/tests/fixture/component-attribute/input.js +0 -11
- package/transform/tests/fixture/component-attribute/output.lightningcss.js +0 -10
- package/transform/tests/fixture/component-attribute/output.swc.js +0 -10
- package/transform/tests/fixture/conflicts/input.js +0 -16
- package/transform/tests/fixture/conflicts/output.lightningcss.js +0 -14
- package/transform/tests/fixture/conflicts/output.swc.js +0 -14
- package/transform/tests/fixture/css-selector-after-pseudo/input.js +0 -18
- package/transform/tests/fixture/css-selector-after-pseudo/output.lightningcss.js +0 -11
- package/transform/tests/fixture/css-selector-after-pseudo/output.swc.js +0 -11
- package/transform/tests/fixture/css-tag-same-file/input.js +0 -25
- package/transform/tests/fixture/css-tag-same-file/output.lightningcss.js +0 -21
- package/transform/tests/fixture/css-tag-same-file/output.swc.js +0 -21
- package/transform/tests/fixture/different-jsx-ids/input.js +0 -23
- package/transform/tests/fixture/different-jsx-ids/output.lightningcss.js +0 -24
- package/transform/tests/fixture/different-jsx-ids/output.swc.js +0 -24
- package/transform/tests/fixture/dynamic-element/input.js +0 -56
- package/transform/tests/fixture/dynamic-element/output.lightningcss.js +0 -40
- package/transform/tests/fixture/dynamic-element/output.swc.js +0 -40
- package/transform/tests/fixture/dynamic-element-class/input.js +0 -32
- package/transform/tests/fixture/dynamic-element-class/output.lightningcss.js +0 -25
- package/transform/tests/fixture/dynamic-element-class/output.swc.js +0 -25
- package/transform/tests/fixture/dynamic-element-external/input.js +0 -12
- package/transform/tests/fixture/dynamic-element-external/output.lightningcss.js +0 -12
- package/transform/tests/fixture/dynamic-element-external/output.swc.js +0 -12
- package/transform/tests/fixture/dynamic-this-in-arrow/input.js +0 -41
- package/transform/tests/fixture/dynamic-this-in-arrow/output.lightningcss.js +0 -39
- package/transform/tests/fixture/dynamic-this-in-arrow/output.swc.js +0 -39
- package/transform/tests/fixture/exported-jsx-style/input.js +0 -1
- package/transform/tests/fixture/exported-jsx-style/output.lightningcss.js +0 -1
- package/transform/tests/fixture/exported-jsx-style/output.swc.js +0 -1
- package/transform/tests/fixture/exported-non-jsx-style/input.js +0 -1
- package/transform/tests/fixture/exported-non-jsx-style/output.lightningcss.js +0 -1
- package/transform/tests/fixture/exported-non-jsx-style/output.swc.js +0 -1
- package/transform/tests/fixture/external-nested-scope/input.js +0 -5
- package/transform/tests/fixture/external-nested-scope/output.lightningcss.js +0 -7
- package/transform/tests/fixture/external-nested-scope/output.swc.js +0 -7
- package/transform/tests/fixture/external-stylesheet/input.js +0 -41
- package/transform/tests/fixture/external-stylesheet/output.lightningcss.js +0 -34
- package/transform/tests/fixture/external-stylesheet/output.swc.js +0 -34
- package/transform/tests/fixture/external-stylesheet-global/input.js +0 -19
- package/transform/tests/fixture/external-stylesheet-global/output.lightningcss.js +0 -18
- package/transform/tests/fixture/external-stylesheet-global/output.swc.js +0 -18
- package/transform/tests/fixture/external-stylesheet-multi-line/input.js +0 -9
- package/transform/tests/fixture/external-stylesheet-multi-line/output.lightningcss.js +0 -9
- package/transform/tests/fixture/external-stylesheet-multi-line/output.swc.js +0 -9
- package/transform/tests/fixture/fragment/input.js +0 -51
- package/transform/tests/fixture/fragment/output.lightningcss.js +0 -47
- package/transform/tests/fixture/fragment/output.swc.js +0 -47
- package/transform/tests/fixture/global/input.js +0 -22
- package/transform/tests/fixture/global/output.lightningcss.js +0 -7
- package/transform/tests/fixture/global/output.swc.js +0 -7
- package/transform/tests/fixture/global-child-selector/input.js +0 -10
- package/transform/tests/fixture/global-child-selector/output.lightningcss.js +0 -8
- package/transform/tests/fixture/global-child-selector/output.swc.js +0 -8
- package/transform/tests/fixture/global-redundant/input.js +0 -12
- package/transform/tests/fixture/global-redundant/output.lightningcss.js +0 -10
- package/transform/tests/fixture/global-redundant/output.swc.js +0 -10
- package/transform/tests/fixture/issue-30480/input.js +0 -11
- package/transform/tests/fixture/issue-30480/output.lightningcss.js +0 -15
- package/transform/tests/fixture/issue-30480/output.swc.js +0 -15
- package/transform/tests/fixture/issue-30570/input.js +0 -15
- package/transform/tests/fixture/issue-30570/output.lightningcss.js +0 -12
- package/transform/tests/fixture/issue-30570/output.swc.js +0 -12
- package/transform/tests/fixture/issue-31562-interpolation-in-mdea/input.js +0 -30
- package/transform/tests/fixture/issue-31562-interpolation-in-mdea/output.lightningcss.js +0 -43
- package/transform/tests/fixture/issue-31562-interpolation-in-mdea/output.swc.js +0 -43
- package/transform/tests/fixture/mixed-global-scoped/input.js +0 -9
- package/transform/tests/fixture/mixed-global-scoped/output.lightningcss.js +0 -11
- package/transform/tests/fixture/mixed-global-scoped/output.swc.js +0 -11
- package/transform/tests/fixture/multiple-jsx/input.js +0 -43
- package/transform/tests/fixture/multiple-jsx/output.lightningcss.js +0 -32
- package/transform/tests/fixture/multiple-jsx/output.swc.js +0 -32
- package/transform/tests/fixture/nested-style-tags/index.js +0 -0
- package/transform/tests/fixture/next-54653/input.js +0 -10
- package/transform/tests/fixture/next-54653/output.lightningcss.js +0 -3
- package/transform/tests/fixture/next-54653/output.swc.js +0 -3
- package/transform/tests/fixture/non-styled-jsx-style/input.js +0 -7
- package/transform/tests/fixture/non-styled-jsx-style/output.lightningcss.js +0 -12
- package/transform/tests/fixture/non-styled-jsx-style/output.swc.js +0 -12
- package/transform/tests/fixture/not-styled-jsx-tagged-templates/input.js +0 -30
- package/transform/tests/fixture/not-styled-jsx-tagged-templates/output.lightningcss.js +0 -23
- package/transform/tests/fixture/not-styled-jsx-tagged-templates/output.swc.js +0 -23
- package/transform/tests/fixture/number-after-placeholder/input.js +0 -17
- package/transform/tests/fixture/number-after-placeholder/output.lightningcss.js +0 -17
- package/transform/tests/fixture/number-after-placeholder/output.swc.js +0 -17
- package/transform/tests/fixture/one-off-global-selectors/input.js +0 -10
- package/transform/tests/fixture/one-off-global-selectors/output.lightningcss.js +0 -8
- package/transform/tests/fixture/one-off-global-selectors/output.swc.js +0 -8
- package/transform/tests/fixture/source-maps/input.js +0 -8
- package/transform/tests/fixture/source-maps/output.lightningcss.js +0 -8
- package/transform/tests/fixture/source-maps/output.swc.js +0 -8
- package/transform/tests/fixture/stateless/input.js +0 -8
- package/transform/tests/fixture/stateless/output.lightningcss.js +0 -12
- package/transform/tests/fixture/stateless/output.swc.js +0 -12
- package/transform/tests/fixture/styles/input.js +0 -57
- package/transform/tests/fixture/styles/output.lightningcss.js +0 -39
- package/transform/tests/fixture/styles/output.swc.js +0 -39
- package/transform/tests/fixture/styles-external-invalid/input.js +0 -13
- package/transform/tests/fixture/styles-external-invalid/output.lightningcss.js +0 -9
- package/transform/tests/fixture/styles-external-invalid/output.swc.js +0 -9
- package/transform/tests/fixture/styles-external-invalid2/input.js +0 -11
- package/transform/tests/fixture/styles-external-invalid2/output.lightningcss.js +0 -8
- package/transform/tests/fixture/styles-external-invalid2/output.swc.js +0 -8
- package/transform/tests/fixture/styles2/input.js +0 -6
- package/transform/tests/fixture/styles2/output.lightningcss.js +0 -5
- package/transform/tests/fixture/styles2/output.swc.js +0 -5
- package/transform/tests/fixture/too-many/input.js +0 -35
- package/transform/tests/fixture/too-many/output.lightningcss.js +0 -49
- package/transform/tests/fixture/too-many/output.swc.js +0 -49
- package/transform/tests/fixture/tpl-escape-1/input.js +0 -14
- package/transform/tests/fixture/tpl-escape-1/output.lightningcss.js +0 -12
- package/transform/tests/fixture/tpl-escape-1/output.swc.js +0 -12
- package/transform/tests/fixture/tpl-escape-2/input.js +0 -17
- package/transform/tests/fixture/tpl-escape-2/output.lightningcss.js +0 -17
- package/transform/tests/fixture/tpl-escape-2/output.swc.js +0 -17
- package/transform/tests/fixture/tpl-placeholder-1-as-property/input.js +0 -17
- package/transform/tests/fixture/tpl-placeholder-1-as-property/output.lightningcss.js +0 -28
- package/transform/tests/fixture/tpl-placeholder-1-as-property/output.swc.js +0 -28
- package/transform/tests/fixture/tpl-placeholder-2-as-part-of-value/input.js +0 -21
- package/transform/tests/fixture/tpl-placeholder-2-as-part-of-value/output.lightningcss.js +0 -34
- package/transform/tests/fixture/tpl-placeholder-2-as-part-of-value/output.swc.js +0 -34
- package/transform/tests/fixture/tpl-placeholder-3-as-value/input.js +0 -17
- package/transform/tests/fixture/tpl-placeholder-3-as-value/output.lightningcss.js +0 -28
- package/transform/tests/fixture/tpl-placeholder-3-as-value/output.swc.js +0 -28
- package/transform/tests/fixture/tpl-placeholder-4-as-part-of-value-in-multiple/input.js +0 -17
- package/transform/tests/fixture/tpl-placeholder-4-as-part-of-value-in-multiple/output.lightningcss.js +0 -31
- package/transform/tests/fixture/tpl-placeholder-4-as-part-of-value-in-multiple/output.swc.js +0 -31
- package/transform/tests/fixture/tpl-placeholder-5-values-of-multiple-properties/input.js +0 -16
- package/transform/tests/fixture/tpl-placeholder-5-values-of-multiple-properties/output.lightningcss.js +0 -31
- package/transform/tests/fixture/tpl-placeholder-5-values-of-multiple-properties/output.swc.js +0 -31
- package/transform/tests/fixture/transform-css/input.js +0 -176
- package/transform/tests/fixture/transform-css/output.lightningcss.js +0 -8
- package/transform/tests/fixture/transform-css/output.swc.js +0 -8
- package/transform/tests/fixture/transform-css-complex-selector/input.js +0 -116
- package/transform/tests/fixture/transform-css-complex-selector/output.lightningcss.js +0 -8
- package/transform/tests/fixture/transform-css-complex-selector/output.swc.js +0 -8
- package/transform/tests/fixture/transform-css-complex-selector-2/input.js +0 -12
- package/transform/tests/fixture/transform-css-complex-selector-2/output.lightningcss.js +0 -8
- package/transform/tests/fixture/transform-css-complex-selector-2/output.swc.js +0 -8
- package/transform/tests/fixture/transform-css-global/input.js +0 -32
- package/transform/tests/fixture/transform-css-global/output.lightningcss.js +0 -8
- package/transform/tests/fixture/transform-css-global/output.swc.js +0 -8
- package/transform/tests/fixture/transform-css-media-query/input.js +0 -24
- package/transform/tests/fixture/transform-css-media-query/output.lightningcss.js +0 -8
- package/transform/tests/fixture/transform-css-media-query/output.swc.js +0 -8
- package/transform/tests/fixture/transform-css-normal/input.js +0 -22
- package/transform/tests/fixture/transform-css-normal/output.lightningcss.js +0 -8
- package/transform/tests/fixture/transform-css-normal/output.swc.js +0 -8
- package/transform/tests/fixture/transform-css-nth-1/input.js +0 -10
- package/transform/tests/fixture/transform-css-nth-1/output.lightningcss.js +0 -8
- package/transform/tests/fixture/transform-css-nth-1/output.swc.js +0 -8
- package/transform/tests/fixture/whitespace/input.js +0 -12
- package/transform/tests/fixture/whitespace/output.lightningcss.js +0 -12
- package/transform/tests/fixture/whitespace/output.swc.js +0 -12
- package/transform/tests/fixture.rs +0 -129
package/transform/src/utils.rs
DELETED
|
@@ -1,371 +0,0 @@
|
|
|
1
|
-
use std::{collections::hash_map::DefaultHasher, hash::Hasher};
|
|
2
|
-
|
|
3
|
-
use swc_common::DUMMY_SP;
|
|
4
|
-
use swc_ecma_ast::*;
|
|
5
|
-
|
|
6
|
-
use crate::style::{ExternalStyle, JSXStyle, LocalStyle};
|
|
7
|
-
|
|
8
|
-
fn tpl_element(value: &str) -> TplElement {
|
|
9
|
-
TplElement {
|
|
10
|
-
raw: value.into(),
|
|
11
|
-
cooked: None,
|
|
12
|
-
span: DUMMY_SP,
|
|
13
|
-
tail: false,
|
|
14
|
-
}
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
pub fn compute_class_names(
|
|
18
|
-
styles: &[JSXStyle],
|
|
19
|
-
style_import_name: &str,
|
|
20
|
-
) -> (Option<String>, Option<Expr>) {
|
|
21
|
-
let mut static_class_name = None;
|
|
22
|
-
let mut external_jsx_id = None;
|
|
23
|
-
let mut static_hashes = vec![];
|
|
24
|
-
let mut dynamic_styles = vec![];
|
|
25
|
-
let mut external_styles = vec![];
|
|
26
|
-
for style_info in styles {
|
|
27
|
-
match style_info {
|
|
28
|
-
JSXStyle::Local(style_info) => {
|
|
29
|
-
if !style_info.is_dynamic {
|
|
30
|
-
static_hashes.push(style_info.hash.clone());
|
|
31
|
-
} else {
|
|
32
|
-
dynamic_styles.push(style_info);
|
|
33
|
-
}
|
|
34
|
-
}
|
|
35
|
-
JSXStyle::External(external) => {
|
|
36
|
-
if !external.is_global {
|
|
37
|
-
external_styles.push(external.expr.clone());
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
|
-
}
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
if !external_styles.is_empty() {
|
|
44
|
-
let mut quasis = vec![tpl_element("jsx-")];
|
|
45
|
-
for _i in 1..external_styles.len() {
|
|
46
|
-
quasis.push(tpl_element(" jsx-"))
|
|
47
|
-
}
|
|
48
|
-
quasis.push(tpl_element(""));
|
|
49
|
-
external_jsx_id = Some(Expr::Tpl(Tpl {
|
|
50
|
-
quasis,
|
|
51
|
-
exprs: external_styles
|
|
52
|
-
.iter()
|
|
53
|
-
.map(|external| Box::new(external.clone()))
|
|
54
|
-
.collect(),
|
|
55
|
-
span: DUMMY_SP,
|
|
56
|
-
}));
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
if !static_hashes.is_empty() {
|
|
60
|
-
static_class_name = Some(format!("jsx-{}", hash_string(&static_hashes.join(","))));
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
let dynamic_class_name = match dynamic_styles.len() {
|
|
64
|
-
0 => None,
|
|
65
|
-
_ => Some(Expr::Call(CallExpr {
|
|
66
|
-
callee: Callee::Expr(Box::new(Expr::Member(MemberExpr {
|
|
67
|
-
obj: Box::new(Expr::Ident(Ident {
|
|
68
|
-
sym: style_import_name.into(),
|
|
69
|
-
span: DUMMY_SP,
|
|
70
|
-
optional: false,
|
|
71
|
-
})),
|
|
72
|
-
prop: MemberProp::Ident(Ident {
|
|
73
|
-
sym: "dynamic".into(),
|
|
74
|
-
span: DUMMY_SP,
|
|
75
|
-
optional: false,
|
|
76
|
-
}),
|
|
77
|
-
span: DUMMY_SP,
|
|
78
|
-
}))),
|
|
79
|
-
args: vec![ExprOrSpread {
|
|
80
|
-
expr: Box::new(Expr::Array(ArrayLit {
|
|
81
|
-
elems: dynamic_styles
|
|
82
|
-
.iter()
|
|
83
|
-
.map(|style_info| {
|
|
84
|
-
let hash_input = match &static_class_name {
|
|
85
|
-
Some(class_name) => format!("{}{}", style_info.hash, class_name),
|
|
86
|
-
None => style_info.hash.clone(),
|
|
87
|
-
};
|
|
88
|
-
Some(ExprOrSpread {
|
|
89
|
-
expr: Box::new(Expr::Array(ArrayLit {
|
|
90
|
-
elems: vec![
|
|
91
|
-
Some(ExprOrSpread {
|
|
92
|
-
expr: Box::new(string_literal_expr(&hash_string(
|
|
93
|
-
&hash_input,
|
|
94
|
-
))),
|
|
95
|
-
spread: None,
|
|
96
|
-
}),
|
|
97
|
-
Some(ExprOrSpread {
|
|
98
|
-
expr: Box::new(Expr::Array(ArrayLit {
|
|
99
|
-
elems: style_info
|
|
100
|
-
.expressions
|
|
101
|
-
.iter()
|
|
102
|
-
.map(|expression| {
|
|
103
|
-
Some(ExprOrSpread {
|
|
104
|
-
expr: expression.clone(),
|
|
105
|
-
spread: None,
|
|
106
|
-
})
|
|
107
|
-
})
|
|
108
|
-
.collect(),
|
|
109
|
-
span: DUMMY_SP,
|
|
110
|
-
})),
|
|
111
|
-
spread: None,
|
|
112
|
-
}),
|
|
113
|
-
],
|
|
114
|
-
span: DUMMY_SP,
|
|
115
|
-
})),
|
|
116
|
-
spread: None,
|
|
117
|
-
})
|
|
118
|
-
})
|
|
119
|
-
.collect(),
|
|
120
|
-
span: DUMMY_SP,
|
|
121
|
-
})),
|
|
122
|
-
spread: None,
|
|
123
|
-
}],
|
|
124
|
-
span: DUMMY_SP,
|
|
125
|
-
type_args: None,
|
|
126
|
-
})),
|
|
127
|
-
};
|
|
128
|
-
|
|
129
|
-
let class_name_expr = match (
|
|
130
|
-
static_class_name.clone(),
|
|
131
|
-
dynamic_class_name,
|
|
132
|
-
external_jsx_id,
|
|
133
|
-
) {
|
|
134
|
-
(Some(static_class_name), Some(dynamic_class_name), Some(external_jsx_id)) => Some(add(
|
|
135
|
-
add(
|
|
136
|
-
external_jsx_id,
|
|
137
|
-
string_literal_expr(&format!(" {} ", static_class_name)),
|
|
138
|
-
),
|
|
139
|
-
dynamic_class_name,
|
|
140
|
-
)),
|
|
141
|
-
(Some(static_class_name), Some(dynamic_class_name), None) => Some(add(
|
|
142
|
-
string_literal_expr(&format!("{} ", static_class_name)),
|
|
143
|
-
dynamic_class_name,
|
|
144
|
-
)),
|
|
145
|
-
(Some(static_class_name), None, Some(external_jsx_id)) => Some(add(
|
|
146
|
-
string_literal_expr(&format!("{} ", static_class_name)),
|
|
147
|
-
external_jsx_id,
|
|
148
|
-
)),
|
|
149
|
-
(None, Some(dynamic_class_name), Some(external_jsx_id)) => Some(add(
|
|
150
|
-
add(external_jsx_id, string_literal_expr(" ")),
|
|
151
|
-
dynamic_class_name,
|
|
152
|
-
)),
|
|
153
|
-
(Some(static_class_name), None, None) => Some(string_literal_expr(&static_class_name)),
|
|
154
|
-
(None, Some(dynamic_class_name), None) => Some(dynamic_class_name),
|
|
155
|
-
(None, None, Some(external_jsx_id)) => Some(external_jsx_id),
|
|
156
|
-
_ => None,
|
|
157
|
-
};
|
|
158
|
-
|
|
159
|
-
(static_class_name, class_name_expr)
|
|
160
|
-
}
|
|
161
|
-
|
|
162
|
-
pub fn make_external_styled_jsx_el(style: &ExternalStyle, style_import_name: &str) -> JSXElement {
|
|
163
|
-
let attrs = vec![JSXAttrOrSpread::JSXAttr(JSXAttr {
|
|
164
|
-
name: JSXAttrName::Ident(Ident {
|
|
165
|
-
sym: "id".into(),
|
|
166
|
-
span: DUMMY_SP,
|
|
167
|
-
optional: false,
|
|
168
|
-
}),
|
|
169
|
-
value: Some(JSXAttrValue::JSXExprContainer(JSXExprContainer {
|
|
170
|
-
expr: JSXExpr::Expr(Box::new(style.expr.clone())),
|
|
171
|
-
span: DUMMY_SP,
|
|
172
|
-
})),
|
|
173
|
-
span: DUMMY_SP,
|
|
174
|
-
})];
|
|
175
|
-
let opening = JSXOpeningElement {
|
|
176
|
-
name: JSXElementName::Ident(Ident {
|
|
177
|
-
sym: style_import_name.into(),
|
|
178
|
-
span: DUMMY_SP,
|
|
179
|
-
optional: false,
|
|
180
|
-
}),
|
|
181
|
-
attrs,
|
|
182
|
-
span: DUMMY_SP,
|
|
183
|
-
self_closing: false,
|
|
184
|
-
type_args: None,
|
|
185
|
-
};
|
|
186
|
-
|
|
187
|
-
let closing = Some(JSXClosingElement {
|
|
188
|
-
name: JSXElementName::Ident(Ident {
|
|
189
|
-
sym: style_import_name.into(),
|
|
190
|
-
span: DUMMY_SP,
|
|
191
|
-
optional: false,
|
|
192
|
-
}),
|
|
193
|
-
span: DUMMY_SP,
|
|
194
|
-
});
|
|
195
|
-
|
|
196
|
-
let children = vec![JSXElementChild::JSXExprContainer(JSXExprContainer {
|
|
197
|
-
expr: JSXExpr::Expr(Box::new(Expr::Ident(style.identifier.clone()))),
|
|
198
|
-
span: DUMMY_SP,
|
|
199
|
-
})];
|
|
200
|
-
JSXElement {
|
|
201
|
-
opening,
|
|
202
|
-
closing,
|
|
203
|
-
children,
|
|
204
|
-
span: DUMMY_SP,
|
|
205
|
-
}
|
|
206
|
-
}
|
|
207
|
-
|
|
208
|
-
pub fn make_local_styled_jsx_el(
|
|
209
|
-
style_info: &LocalStyle,
|
|
210
|
-
css_expr: Expr,
|
|
211
|
-
style_import_name: &str,
|
|
212
|
-
static_class_name: Option<&String>,
|
|
213
|
-
) -> JSXElement {
|
|
214
|
-
let hash_input = match (&style_info.is_dynamic, &static_class_name) {
|
|
215
|
-
(true, Some(class_name)) => format!("{}{}", style_info.hash, class_name),
|
|
216
|
-
_ => style_info.hash.clone(),
|
|
217
|
-
};
|
|
218
|
-
let mut attrs = vec![JSXAttrOrSpread::JSXAttr(JSXAttr {
|
|
219
|
-
name: JSXAttrName::Ident(Ident {
|
|
220
|
-
sym: "id".into(),
|
|
221
|
-
span: DUMMY_SP,
|
|
222
|
-
optional: false,
|
|
223
|
-
}),
|
|
224
|
-
value: Some(JSXAttrValue::JSXExprContainer(JSXExprContainer {
|
|
225
|
-
expr: JSXExpr::Expr(Box::new(string_literal_expr(
|
|
226
|
-
hash_string(&hash_input).as_str(),
|
|
227
|
-
))),
|
|
228
|
-
span: DUMMY_SP,
|
|
229
|
-
})),
|
|
230
|
-
span: DUMMY_SP,
|
|
231
|
-
})];
|
|
232
|
-
|
|
233
|
-
if style_info.is_dynamic {
|
|
234
|
-
attrs.push(JSXAttrOrSpread::JSXAttr(JSXAttr {
|
|
235
|
-
name: JSXAttrName::Ident(Ident {
|
|
236
|
-
sym: "dynamic".into(),
|
|
237
|
-
span: DUMMY_SP,
|
|
238
|
-
optional: false,
|
|
239
|
-
}),
|
|
240
|
-
value: Some(JSXAttrValue::JSXExprContainer(JSXExprContainer {
|
|
241
|
-
expr: JSXExpr::Expr(Box::new(Expr::Array(ArrayLit {
|
|
242
|
-
elems: style_info
|
|
243
|
-
.expressions
|
|
244
|
-
.iter()
|
|
245
|
-
.map(|expression| {
|
|
246
|
-
Some(ExprOrSpread {
|
|
247
|
-
expr: expression.clone(),
|
|
248
|
-
spread: None,
|
|
249
|
-
})
|
|
250
|
-
})
|
|
251
|
-
.collect(),
|
|
252
|
-
span: DUMMY_SP,
|
|
253
|
-
}))),
|
|
254
|
-
span: DUMMY_SP,
|
|
255
|
-
})),
|
|
256
|
-
span: DUMMY_SP,
|
|
257
|
-
}));
|
|
258
|
-
}
|
|
259
|
-
|
|
260
|
-
let opening = JSXOpeningElement {
|
|
261
|
-
name: JSXElementName::Ident(Ident {
|
|
262
|
-
sym: style_import_name.into(),
|
|
263
|
-
span: DUMMY_SP,
|
|
264
|
-
optional: false,
|
|
265
|
-
}),
|
|
266
|
-
attrs,
|
|
267
|
-
span: DUMMY_SP,
|
|
268
|
-
self_closing: false,
|
|
269
|
-
type_args: None,
|
|
270
|
-
};
|
|
271
|
-
|
|
272
|
-
let closing = Some(JSXClosingElement {
|
|
273
|
-
name: JSXElementName::Ident(Ident {
|
|
274
|
-
sym: style_import_name.into(),
|
|
275
|
-
span: DUMMY_SP,
|
|
276
|
-
optional: false,
|
|
277
|
-
}),
|
|
278
|
-
span: DUMMY_SP,
|
|
279
|
-
});
|
|
280
|
-
|
|
281
|
-
let children = vec![JSXElementChild::JSXExprContainer(JSXExprContainer {
|
|
282
|
-
expr: JSXExpr::Expr(Box::new(css_expr)),
|
|
283
|
-
span: DUMMY_SP,
|
|
284
|
-
})];
|
|
285
|
-
JSXElement {
|
|
286
|
-
opening,
|
|
287
|
-
closing,
|
|
288
|
-
children,
|
|
289
|
-
span: DUMMY_SP,
|
|
290
|
-
}
|
|
291
|
-
}
|
|
292
|
-
|
|
293
|
-
pub fn get_usable_import_specifier(_items: &[ModuleItem]) -> String {
|
|
294
|
-
// TODO
|
|
295
|
-
String::from("_JSXStyle")
|
|
296
|
-
}
|
|
297
|
-
|
|
298
|
-
pub fn styled_jsx_import_decl(style_import_name: &str) -> ModuleItem {
|
|
299
|
-
ModuleItem::ModuleDecl(ModuleDecl::Import(ImportDecl {
|
|
300
|
-
with: None,
|
|
301
|
-
span: DUMMY_SP,
|
|
302
|
-
type_only: false,
|
|
303
|
-
specifiers: vec![ImportSpecifier::Default(ImportDefaultSpecifier {
|
|
304
|
-
local: Ident {
|
|
305
|
-
sym: style_import_name.into(),
|
|
306
|
-
span: DUMMY_SP,
|
|
307
|
-
optional: false,
|
|
308
|
-
},
|
|
309
|
-
span: DUMMY_SP,
|
|
310
|
-
})],
|
|
311
|
-
src: Box::new(Str {
|
|
312
|
-
span: DUMMY_SP,
|
|
313
|
-
value: "styled-jsx/style".into(),
|
|
314
|
-
raw: None,
|
|
315
|
-
}),
|
|
316
|
-
}))
|
|
317
|
-
}
|
|
318
|
-
|
|
319
|
-
// TODO: maybe use DJBHasher (need to implement)
|
|
320
|
-
pub fn hash_string(str: &str) -> String {
|
|
321
|
-
let mut hasher = DefaultHasher::new();
|
|
322
|
-
hasher.write(str.as_bytes());
|
|
323
|
-
let hash_result = hasher.finish();
|
|
324
|
-
format!("{:x}", hash_result)
|
|
325
|
-
}
|
|
326
|
-
|
|
327
|
-
pub fn string_literal_expr(str: &str) -> Expr {
|
|
328
|
-
let str = str.replace("\\`", "`");
|
|
329
|
-
Expr::Lit(Lit::Str(Str {
|
|
330
|
-
value: str.into(),
|
|
331
|
-
span: DUMMY_SP,
|
|
332
|
-
raw: None,
|
|
333
|
-
}))
|
|
334
|
-
}
|
|
335
|
-
|
|
336
|
-
pub fn ident(str: &str) -> Ident {
|
|
337
|
-
Ident {
|
|
338
|
-
sym: str.into(),
|
|
339
|
-
span: DUMMY_SP,
|
|
340
|
-
optional: false,
|
|
341
|
-
}
|
|
342
|
-
}
|
|
343
|
-
|
|
344
|
-
pub fn is_capitalized(word: &str) -> bool {
|
|
345
|
-
word.chars().next().unwrap().is_uppercase()
|
|
346
|
-
}
|
|
347
|
-
|
|
348
|
-
pub fn add(left: Expr, right: Expr) -> Expr {
|
|
349
|
-
binary_expr(BinaryOp::Add, left, right)
|
|
350
|
-
}
|
|
351
|
-
|
|
352
|
-
pub fn and(left: Expr, right: Expr) -> Expr {
|
|
353
|
-
binary_expr(BinaryOp::LogicalAnd, left, right)
|
|
354
|
-
}
|
|
355
|
-
|
|
356
|
-
pub fn or(left: Expr, right: Expr) -> Expr {
|
|
357
|
-
binary_expr(BinaryOp::LogicalOr, left, right)
|
|
358
|
-
}
|
|
359
|
-
|
|
360
|
-
pub fn not_eq(left: Expr, right: Expr) -> Expr {
|
|
361
|
-
binary_expr(BinaryOp::NotEq, left, right)
|
|
362
|
-
}
|
|
363
|
-
|
|
364
|
-
pub fn binary_expr(op: BinaryOp, left: Expr, right: Expr) -> Expr {
|
|
365
|
-
Expr::Bin(BinExpr {
|
|
366
|
-
op,
|
|
367
|
-
left: Box::new(left),
|
|
368
|
-
right: Box::new(right),
|
|
369
|
-
span: DUMMY_SP,
|
|
370
|
-
})
|
|
371
|
-
}
|