Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(emotion): Port label tests and fix label generation #245

Merged
merged 28 commits into from
Jan 18, 2024
Merged
Show file tree
Hide file tree
Changes from 15 commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
f62b71f
fix(emotion): Fix local labels not using keys of objects
Codex- Jan 12, 2024
8751307
chore: move label related fixtures into labels sub-dir
Codex- Jan 12, 2024
72059b3
test: port label tests with expected output from the emotion/babel-pl…
Codex- Jan 12, 2024
6456299
fix: label generation for object prop methods
Codex- Jan 12, 2024
64efe26
fix: label generation for named functions on var assignments
Codex- Jan 12, 2024
d98210a
fix: label generation for string keys on objects
Codex- Jan 12, 2024
39a5bce
chore: move label tests up one level to prevent test fixture pattern …
Codex- Jan 12, 2024
0ebfab3
fix: label generation for functions that return calls to emotion
Codex- Jan 12, 2024
cd81fb3
fix: label should be empty if no context is available
Codex- Jan 12, 2024
51f3f2e
test: port more emotion tests
Codex- Jan 12, 2024
25d9a3c
fix: functions on classes use the class name, but properties use the …
Codex- Jan 12, 2024
a91ac18
fix: computed properties should not have a label
Codex- Jan 12, 2024
9af519b
test: port remaining emotion tests
Codex- Jan 12, 2024
7601c2e
test: add examples from #180
Codex- Jan 12, 2024
5b63029
Merge branch 'main' into fix_emotion_label_bugs
kdy1 Jan 18, 2024
2c3e0ba
Bump crates
kdy1 Jan 18, 2024
03e9261
Bump npm package: ./packages/constify
kdy1 Jan 18, 2024
d3e7d2a
Bump npm package: ./packages/emotion
kdy1 Jan 18, 2024
629d0b0
Bump npm package: ./packages/jest
kdy1 Jan 18, 2024
506ac5d
Bump npm package: ./packages/loadable-components
kdy1 Jan 18, 2024
6b512de
Bump npm package: ./packages/noop
kdy1 Jan 18, 2024
edd2bc4
Bump npm package: ./packages/react-remove-properties
kdy1 Jan 18, 2024
a2d5997
Bump npm package: ./packages/relay
kdy1 Jan 18, 2024
2e45764
Bump npm package: ./packages/remove-console
kdy1 Jan 18, 2024
f76d97b
Bump npm package: ./packages/styled-components
kdy1 Jan 18, 2024
4ead2ae
Bump npm package: ./packages/styled-jsx
kdy1 Jan 18, 2024
95720b3
Bump npm package: ./packages/swc-magic
kdy1 Jan 18, 2024
9874eeb
Bump npm package: ./packages/transform-imports
kdy1 Jan 18, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
90 changes: 84 additions & 6 deletions packages/emotion/transform/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,11 @@ use sourcemap::{RawToken, SourceMap as RawSourcemap};
use swc_atoms::JsWord;
use swc_common::{comments::Comments, util::take::Take, BytePos, SourceMapperDyn, DUMMY_SP};
use swc_ecma_ast::{
ArrayLit, CallExpr, Callee, Expr, ExprOrSpread, Id, Ident, ImportDecl, ImportSpecifier,
JSXAttr, JSXAttrName, JSXAttrOrSpread, JSXAttrValue, JSXElement, JSXElementName, JSXExpr,
JSXExprContainer, JSXObject, KeyValueProp, MemberProp, ModuleExportName, ObjectLit, Pat, Prop,
PropName, PropOrSpread, SourceMapperExt, SpreadElement, Tpl, VarDeclarator,
ArrayLit, CallExpr, Callee, ClassDecl, ClassMethod, ClassProp, Expr, ExprOrSpread, FnDecl, Id,
Ident, ImportDecl, ImportSpecifier, JSXAttr, JSXAttrName, JSXAttrOrSpread, JSXAttrValue,
JSXElement, JSXElementName, JSXExpr, JSXExprContainer, JSXObject, KeyValueProp, MemberProp,
MethodProp, ModuleExportName, ObjectLit, Pat, Prop, PropName, PropOrSpread, SourceMapperExt,
SpreadElement, Tpl, VarDeclarator,
};
use swc_ecma_utils::ExprFactory;
use swc_ecma_visit::{Fold, FoldWith};
Expand Down Expand Up @@ -76,6 +77,9 @@ static EMOTION_OFFICIAL_LIBRARIES: Lazy<Vec<EmotionModuleConfig>> = Lazy::new(||
]
});

static INVALID_LABEL_SPACES: Lazy<Regex> =
Lazy::new(|| RegexBuilder::new(r#"\s+"#).build().unwrap());

static INVALID_CSS_CLASS_NAME_CHARACTERS: Lazy<Regex> = Lazy::new(|| {
RegexBuilder::new(r##"[!"#$%&'()*+,./:;<=>?@\[\]^`|}~{]"##)
.build()
Expand Down Expand Up @@ -178,6 +182,7 @@ pub struct EmotionTransformer<C: Comments> {
import_packages: FxHashMap<Id, PackageMeta>,
emotion_target_class_name_count: usize,
current_context: Option<String>,
current_class: Option<String>,
// skip `css` transformation if it in JSX Element/Attribute
in_jsx_element: bool,

Expand Down Expand Up @@ -217,13 +222,19 @@ impl<C: Comments> EmotionTransformer<C> {
import_packages: FxHashMap::default(),
emotion_target_class_name_count: 0,
current_context: None,
current_class: None,
in_jsx_element: false,
registered_imports,
}
}

fn sanitize_label_part<'t>(&self, label_part: &'t str) -> Cow<'t, str> {
INVALID_CSS_CLASS_NAME_CHARACTERS.replace_all(label_part, "-")
fn sanitize_label_part<'t>(&self, label_part: &'t str) -> String {
// Existing @emotion/babel-plugin behaviour is to replace all spaces
// with a single hyphen
let without_spaces = INVALID_LABEL_SPACES.replace_all(label_part, "-");
INVALID_CSS_CLASS_NAME_CHARACTERS
.replace_all(&without_spaces, "-")
.to_string()
}

fn create_label(&self, with_prefix: bool) -> String {
Expand All @@ -244,6 +255,10 @@ impl<C: Comments> EmotionTransformer<C> {
if let Some(dirname) = self.dirname.as_ref() {
label = label.replace("[dirname]", &self.sanitize_label_part(dirname));
};
} else {
// Existing @emotion/babel-plugin behaviour is to
// not provide a label if there is no available identifier
return "".to_string();
}
label
}
Expand Down Expand Up @@ -430,9 +445,72 @@ impl<C: Comments> Fold for EmotionTransformer<C> {
if let Pat::Ident(i) = &dec.name {
self.current_context = Some(i.id.as_ref().to_owned());
}
// If we encounter a named function expression
if let Expr::Fn(f) = *dec.init.clone().unwrap() {
if let Some(i) = &f.ident {
self.current_context = Some(i.sym.as_ref().to_owned());
}
}
dec.fold_children_with(self)
}

fn fold_key_value_prop(&mut self, kv: KeyValueProp) -> KeyValueProp {
match &kv.key {
PropName::Ident(k) => {
self.current_context = Some(k.sym.as_ref().to_owned());
}
PropName::Str(k) => {
self.current_context = Some(k.value.as_ref().to_owned());
}
_ => (),
}
kv.fold_children_with(self)
}

fn fold_method_prop(&mut self, mp: MethodProp) -> MethodProp {
if let PropName::Ident(p) = &mp.key {
self.current_context = Some(p.sym.as_ref().to_owned());
}
mp.fold_children_with(self)
}

fn fold_fn_decl(&mut self, fn_dec: FnDecl) -> FnDecl {
self.current_context = Some(fn_dec.ident.sym.as_ref().to_owned());
fn_dec.fold_children_with(self)
}

fn fold_class_decl(&mut self, cd: ClassDecl) -> ClassDecl {
self.current_class = Some(cd.ident.sym.as_ref().to_owned());
self.current_context = self.current_class.clone();
cd.fold_children_with(self)
}

fn fold_class_method(&mut self, cm: ClassMethod) -> ClassMethod {
// class methods use the class name for the context
if self.current_class.is_some() {
self.current_context = self.current_class.clone();
}
cm.fold_children_with(self)
}

fn fold_class_prop(&mut self, cp: ClassProp) -> ClassProp {
if let PropName::Ident(p) = &cp.key {
self.current_context = Some(p.sym.as_ref().to_owned());
}
cp.fold_children_with(self)
}

fn fold_computed_prop_name(
&mut self,
n: swc_ecma_ast::ComputedPropName,
) -> swc_ecma_ast::ComputedPropName {
// Existing @emotion/babel-plugin behaviour is that computed
// properties do not have a label. We reset the label here as
// an unset label is reduced to an empty string in `create_label`.
self.current_context = None;
n.fold_children_with(self)
}

fn fold_call_expr(&mut self, mut expr: CallExpr) -> CallExpr {
// If no package that we care about is imported, skip the following
// transformation logic.
Expand Down
17 changes: 13 additions & 4 deletions packages/emotion/transform/tests/fixture.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,8 @@ fn next_emotion_fixture(input: PathBuf) {
// "/labels/filename" -> "[filename]"
// "/labels/filename-local" -> "[filename]-[local]"
// "/labels/local" -> "[local]"
#[fixture("tests/labels/**/output.js")]
fn emotion_label_fixture(output: PathBuf) {
#[fixture("tests/labels/options/**/output.js")]
fn emotion_label_option_fixture(output: PathBuf) {
let output_folder = output.parent().unwrap();
let output_folder_name = output_folder.file_name().unwrap().to_str().unwrap();
let input = output_folder.parent().unwrap().join("input.tsx");
Expand Down Expand Up @@ -136,8 +136,17 @@ fn emotion_label_fixture(output: PathBuf) {
);
}

#[fixture("tests/label-sanitisation/**/*.ts")]
#[fixture("tests/labels/emotion-js/**/*.ts")]
fn emotion_label_original(input: PathBuf) {
emotion_label(input, "[local]".to_string())
}

#[fixture("tests/labels/sanitisation/**/*.ts")]
fn emotion_label_sanitisation(input: PathBuf) {
emotion_label(input, "[dirname]-[filename]-[local]".to_string())
}

fn emotion_label(input: PathBuf, label: String) {
let output_folder_name = input
.parent()
.unwrap()
Expand Down Expand Up @@ -174,7 +183,7 @@ fn emotion_label_sanitisation(input: PathBuf) {
enabled: Some(true),
sourcemap: Some(true),
auto_label: Some(true),
label_format: Some("[dirname]-[filename]-[local]".to_string()),
label_format: Some(label.to_owned()),
..Default::default()
},
&PathBuf::from(format!("{output_folder_name}/{input_file_name}")),
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import styled from "@emotion/styled";
export default /*#__PURE__*/ styled("div", {
target: "e1h8m75k0",
label: "[local]",
label: "",
})(
"color:red;.foo{color:blue;}width:10px;",
"/*# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiaW5wdXQudHMiLCJzb3VyY2VzIjpbImlucHV0LnRzIl0sInNvdXJjZXNDb250ZW50IjpbImltcG9ydCBzdHlsZWQgZnJvbSBcIkBlbW90aW9uL3N0eWxlZFwiO1xuXG5leHBvcnQgZGVmYXVsdCBzdHlsZWQuZGl2YFxuICBjb2xvcjogcmVkO1xuICAuZm9vIHtcbiAgICBjb2xvcjogYmx1ZTtcbiAgICAvKipcbiAgICAgIG11bHRpIGxpbmUgY29tbWVudHNcbiAgICAqL1xuICB9XG4gIC8qIC8qICovXG4gIHdpZHRoOiAxMHB4O1xuYDtcbiJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiQUFFZSJ9 */"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ const Container2 = /*#__PURE__*/ styled("div", {
export class SimpleComponent extends PureComponent {
render() {
return /*#__PURE__*/ _jsxs(Container, {
css: /*#__PURE__*/ css("color:hotpink;", "Container2", "/*# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiaW5wdXQudHMiLCJzb3VyY2VzIjpbImlucHV0LnRzIl0sInNvdXJjZXNDb250ZW50IjpbImltcG9ydCB7IGNzcywgR2xvYmFsIH0gZnJvbSAnQGVtb3Rpb24vcmVhY3QnXG5pbXBvcnQgc3R5bGVkIGZyb20gJ0BlbW90aW9uL3N0eWxlZCdcbmltcG9ydCB7IFB1cmVDb21wb25lbnQgfSBmcm9tICdyZWFjdCdcbmltcG9ydCBSZWFjdERPTSBmcm9tICdyZWFjdC1kb20nXG5cbmNvbnN0IHN0eWxlc0luQ2FsbGJhY2sgPSAocHJvcHM6IGFueSkgPT5cbiAgY3NzKHtcbiAgICBjb2xvcjogJ3JlZCcsXG4gICAgYmFja2dyb3VuZDogJ3llbGxvdycsXG4gICAgd2lkdGg6IGAke3Byb3BzLnNjYWxlICogMTAwfXB4YCxcbiAgfSlcblxuY29uc3Qgc3R5bGVzID0gY3NzKHtcbiAgY29sb3I6ICdyZWQnLFxuICB3aWR0aDogJzIwcHgnLFxufSlcblxuY29uc3Qgc3R5bGVzMiA9IGNzc2BcbiAgY29sb3I6IHJlZDtcbiAgd2lkdGg6IDIwcHg7XG5gXG5cbmNvbnN0IERpdkNvbnRhaW5lciA9IHN0eWxlZC5kaXYoe1xuICBiYWNrZ3JvdW5kOiAncmVkJyxcbn0pXG5cbmNvbnN0IERpdkNvbnRhaW5lcjIgPSBzdHlsZWQuZGl2YFxuICBiYWNrZ3JvdW5kOiBy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ICAgICAgICBib2R5IHtcbiAgICAgICAgICAgICAgcGFkZGluZzogM3JlbSAxcmVtO1xuICAgICAgICAgICAgICBtYXJnaW46IDA7XG4gICAgICAgICAgICAgIGJhY2tncm91bmQ6IHBhcGF5YXdoaXA7XG4gICAgICAgICAgICAgIG1pbi1oZWlnaHQ6IDEwMCU7XG4gICAgICAgICAgICAgIGZvbnQtZmFtaWx5OiBIZWx2ZXRpY2EsIEFyaWFsLCBzYW5zLXNlcmlmO1xuICAgICAgICAgICAgICBmb250LXNpemU6IDI0cHg7XG4gICAgICAgICAgICB9XG4gICAgICAgICAgYH1cbiAgICAgICAgLz5cbiAgICAgICAgPHNwYW4+aGVsbG88L3NwYW4+XG4gICAgICA8L0NvbnRhaW5lcj5cbiAgICApXG4gIH1cbn1cblxuUmVhY3RET00ucmVuZGVyKDxTaW1wbGVDb21wb25lbnQgLz4sIGRvY3VtZW50LnF1ZXJ5U2VsZWN0b3IoJyNhcHAnKSlcbiJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiQUE4RGEifQ== */"),
css: /*#__PURE__*/ css("color:hotpink;", "SimpleComponent", "/*# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiaW5wdXQudHMiLCJzb3VyY2VzIjpbImlucHV0LnRzIl0sInNvdXJjZXNDb250ZW50IjpbImltcG9ydCB7IGNzcywgR2xvYmFsIH0gZnJvbSAnQGVtb3Rpb24vcmVhY3QnXG5pbXBvcnQgc3R5bGVkIGZyb20gJ0BlbW90aW9uL3N0eWxlZCdcbmltcG9ydCB7IFB1cmVDb21wb25lbnQgfSBmcm9tICdyZWFjdCdcbmltcG9ydCBSZWFjdERPTSBmcm9tICdyZWFjdC1kb20nXG5cbmNvbnN0IHN0eWxlc0luQ2FsbGJhY2sgPSAocHJvcHM6IGFueSkgPT5cbiAgY3NzKHtcbiAgICBjb2xvcjogJ3JlZCcsXG4gICAgYmFja2dyb3VuZDogJ3llbGxvdycsXG4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cbmBcblxuY29uc3QgQ29udGFpbmVyMiA9IHN0eWxlZC5kaXZgXG4gIGJhY2tncm91bmQ6IHJlZDtcbmBcblxuZXhwb3J0IGNsYXNzIFNpbXBsZUNvbXBvbmVudCBleHRlbmRzIFB1cmVDb21wb25lbnQge1xuICByZW5kZXIoKSB7XG4gICAgcmV0dXJuIChcbiAgICAgIDxDb250YWluZXJcbiAgICAgICAgY3NzPXtjc3NgXG4gICAgICAgICAgY29sb3I6IGhvdHBpbms7XG4gICAgICAgIGB9XG4gICAgICA+XG4gICAgICAgIDxHbG9iYWxcbiAgICAgICAgICBzdHlsZXM9e2Nzc2BcbiAgICAgICAgICAgIGh0bWwsXG4gICAgICAgICAgICBib2R5IHtcbiAgICAgICAgICAgICAgcGFkZGluZzogM3JlbSAxcmVtO1xuICAgICAgICAgICAgICBtYXJnaW46IDA7XG4gICAgICAgICAgICAgIGJhY2tncm91bmQ6IHBhcGF5YXdoaXA7XG4gICAgICAgICAgICAgIG1pbi1oZWlnaHQ6IDEwMCU7XG4gICAgICAgICAgICAgIGZvbnQtZmFtaWx5OiBIZWx2ZXRpY2EsIEFyaWFsLCBzYW5zLXNlcmlmO1xuICAgICAgICAgICAgICBmb250LXNpemU6IDI0cHg7XG4gICAgICAgICAgICB9XG4gICAgICAgICAgYH1cbiAgICAgICAgLz5cbiAgICAgICAgPHNwYW4+aGVsbG88L3NwYW4+XG4gICAgICA8L0NvbnRhaW5lcj5cbiAgICApXG4gIH1cbn1cblxuUmVhY3RET00ucmVuZGVyKDxTaW1wbGVDb21wb25lbnQgLz4sIGRvY3VtZW50LnF1ZXJ5U2VsZWN0b3IoJyNhcHAnKSlcbiJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiQUE4RGEifQ== */"),
children: [
/*#__PURE__*/ _jsx(Global, {
styles: [
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { something } from 'package-three';
/*#__PURE__*/ something({
color: 'green'
}, "label:[local]", "/*# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiaW5wdXQudHMiLCJzb3VyY2VzIjpbImlucHV0LnRzIl0sInNvdXJjZXNDb250ZW50IjpbImltcG9ydCB7IHNvbWV0aGluZyB9IGZyb20gJ3BhY2thZ2UtdGhyZWUnXG5cbnNvbWV0aGluZyh7IGNvbG9yOiAnZ3JlZW4nIH0pXG4iXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IkFBRUEifQ== */");
}, "", "/*# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiaW5wdXQudHMiLCJzb3VyY2VzIjpbImlucHV0LnRzIl0sInNvdXJjZXNDb250ZW50IjpbImltcG9ydCB7IHNvbWV0aGluZyB9IGZyb20gJ3BhY2thZ2UtdGhyZWUnXG5cbnNvbWV0aGluZyh7IGNvbG9yOiAnZ3JlZW4nIH0pXG4iXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IkFBRUEifQ== */");
39 changes: 39 additions & 0 deletions packages/emotion/transform/tests/fixture/issues/180/input.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import { css } from "@emotion/react";
import styled from "@emotion/styled";

// Example 1
function myStyled(Component) {
return styled(Component)`
background-color: red;
`;
}

function myCss(color) {
return css`
background-color: ${color};
`;
}

const myStyles = myCss("red");

const Div = myStyled("div");

function App() {
return (
<>
<Div>one</Div>
<div css={myStyles}>two</div>
</>
);
}

// Example 2
const styles = {
keyA: css({
padding: 0,
}),
keyB: css({
margin: 0,
}),
};
const App2 = () => <div classname={styles.keyA}>hello world</div>;
Loading
Loading