Skip to content

Commit 0cfc455

Browse files
committed
fix(transformer/styled-components): should use source path to generate file hash when the path is absoulte path
1 parent facd3cd commit 0cfc455

File tree

11 files changed

+43
-43
lines changed

11 files changed

+43
-43
lines changed

crates/oxc_transformer/src/plugins/styled_components.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -681,7 +681,7 @@ impl<'a> StyledComponents<'a, '_> {
681681
}
682682

683683
let mut hasher = FxHasher::default();
684-
if self.ctx.source_path.is_relative() {
684+
if self.ctx.source_path.is_absolute() {
685685
self.ctx.source_path.hash(&mut hasher);
686686
} else {
687687
self.ctx.source_text.hash(&mut hasher);

napi/transform/test/transform.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -438,7 +438,7 @@ describe('styled-components', () => {
438438
"import styled, { css } from "styled-components";
439439
styled.div.withConfig({
440440
displayName: "test",
441-
componentId: "sc-ziiqn7-0"
441+
componentId: "sc-3q0sbi-0"
442442
})(["color:red;"]);
443443
const v = /* @__PURE__ */ css(["color: red;"]);
444444
"
Original file line numberDiff line numberDiff line change
@@ -1,65 +1,65 @@
11
import styled from 'styled-components';
22
const Test = styled.div.withConfig({
33
displayName: "Test",
4-
componentId: "sc-mkpq9u-0"
4+
componentId: "sc-68njp2-0"
55
})`width:100%;`;
66
const Test2 = true ? styled.div.withConfig({
77
displayName: "Test2",
8-
componentId: "sc-mkpq9u-1"
8+
componentId: "sc-68njp2-1"
99
})`` : styled.div.withConfig({
1010
displayName: "Test2",
11-
componentId: "sc-mkpq9u-2"
11+
componentId: "sc-68njp2-2"
1212
})``;
1313
const styles = {
1414
One: styled.div.withConfig({
1515
displayName: "One",
16-
componentId: "sc-mkpq9u-3"
16+
componentId: "sc-68njp2-3"
1717
})``
1818
};
1919
let Component;
2020
Component = styled.div.withConfig({
2121
displayName: "Component",
22-
componentId: "sc-mkpq9u-4"
22+
componentId: "sc-68njp2-4"
2323
})``;
2424
const WrappedComponent = styled(Inner).withConfig({
2525
displayName: "WrappedComponent",
26-
componentId: "sc-mkpq9u-5"
26+
componentId: "sc-68njp2-5"
2727
})``;
2828
const WrappedComponent2 = styled.div.withConfig({
2929
displayName: "WrappedComponent2",
30-
componentId: "sc-mkpq9u-6"
30+
componentId: "sc-68njp2-6"
3131
})({});
3232
const WrappedComponent3 = styled(Inner).withConfig({
3333
displayName: "WrappedComponent3",
34-
componentId: "sc-mkpq9u-7"
34+
componentId: "sc-68njp2-7"
3535
})({});
3636
const WrappedComponent4 = styled(Inner).attrs(() => ({
3737
something: 'else'
3838
})).withConfig({
3939
displayName: "WrappedComponent4",
40-
componentId: "sc-mkpq9u-8"
40+
componentId: "sc-68njp2-8"
4141
})({});
4242
const WrappedComponent5 = styled.div.attrs(() => ({
4343
something: 'else'
4444
})).withConfig({
4545
displayName: "WrappedComponent5",
46-
componentId: "sc-mkpq9u-9"
46+
componentId: "sc-68njp2-9"
4747
})({});
4848
const WrappedComponent6 = styled.div.attrs(() => ({
4949
something: 'else'
5050
})).withConfig({
5151
displayName: "WrappedComponent6",
52-
componentId: "sc-mkpq9u-10"
52+
componentId: "sc-68njp2-10"
5353
})``;
5454
const WrappedComponent7 = styled.div.withConfig({
5555
shouldForwardProp: () => { },
5656
displayName: "WrappedComponent7",
57-
componentId: "sc-mkpq9u-11"
57+
componentId: "sc-68njp2-11"
5858
})({});
5959
const WrappedComponent8 = styled.div.withConfig({
6060
shouldForwardProp: () => { },
6161
displayName: "WrappedComponent8",
62-
componentId: "sc-mkpq9u-12"
62+
componentId: "sc-68njp2-12"
6363
}).attrs(() => ({
6464
something: 'else'
6565
}))({});
@@ -68,5 +68,5 @@ const WrappedComponent9 = styled.div.attrs(() => ({
6868
})).withConfig({
6969
shouldForwardProp: () => { },
7070
displayName: "WrappedComponent9",
71-
componentId: "sc-mkpq9u-13"
71+
componentId: "sc-68njp2-13"
7272
})({});
Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,21 @@
11
import styled from 'styled-components';
22
const Test = styled.div.withConfig({
3-
componentId: "sc-80sor8-0"
3+
componentId: "sc-yv1qfe-0"
44
})`width:100%;`;
55
const Test2 = true ? styled.div.withConfig({
6-
componentId: "sc-80sor8-1"
6+
componentId: "sc-yv1qfe-1"
77
})`` : styled.div.withConfig({
8-
componentId: "sc-80sor8-2"
8+
componentId: "sc-yv1qfe-2"
99
})``;
1010
const styles = {
1111
One: styled.div.withConfig({
12-
componentId: "sc-80sor8-3"
12+
componentId: "sc-yv1qfe-3"
1313
})``
1414
};
1515
let Component;
1616
Component = styled.div.withConfig({
17-
componentId: "sc-80sor8-4"
17+
componentId: "sc-yv1qfe-4"
1818
})``;
1919
const WrappedComponent = styled(Inner).withConfig({
20-
componentId: "sc-80sor8-5"
20+
componentId: "sc-yv1qfe-5"
2121
})``;

tasks/transform_conformance/tests/plugin-styled-components/test/fixtures/styled-components/ignore-external-styled-import/output.jsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { styled } from '@material/ui';
22
import s from 'styled-components';
33
const Paragraph = s.p.withConfig({
44
displayName: "input__Paragraph",
5-
componentId: "sc-33emk6-0"
5+
componentId: "sc-g689do-0"
66
})(["color:green;"]);
77
const Foo = p => <Paragraph {...p} />;
88
const TestNormal = styled(Foo)({

tasks/transform_conformance/tests/plugin-styled-components/test/fixtures/styled-components/minify-single-line-comments-with-interpolations/output.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,4 @@ const Test7 = styled.div.withConfig({ displayName: "input__Test7", componentId:
1414
p => p.props.width,
1515
'green',
1616
p => p.props.height,
17-
);
17+
);
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,27 @@
11
import s from "styled-components";
22
const Test = s.div.withConfig({
33
displayName: "Test",
4-
componentId: "sc-4ndp5k-0"
4+
componentId: "sc-etvu4p-0"
55
})`width:100%;`;
66
const Test2 = true ? s.div.withConfig({
77
displayName: "Test2",
8-
componentId: "sc-4ndp5k-1"
8+
componentId: "sc-etvu4p-1"
99
})`` : s.div.withConfig({
1010
displayName: "Test2",
11-
componentId: "sc-4ndp5k-2"
11+
componentId: "sc-etvu4p-2"
1212
})``;
1313
const styles = {
1414
One: s.div.withConfig({
1515
displayName: "One",
16-
componentId: "sc-4ndp5k-3"
16+
componentId: "sc-etvu4p-3"
1717
})``
1818
};
1919
let Component;
2020
Component = s.div.withConfig({
2121
displayName: "Component",
22-
componentId: "sc-4ndp5k-4"
22+
componentId: "sc-etvu4p-4"
2323
})``;
2424
const WrappedComponent = s(Inner).withConfig({
2525
displayName: "WrappedComponent",
26-
componentId: "sc-4ndp5k-5"
26+
componentId: "sc-etvu4p-5"
2727
})``;
Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
11
import styled from "styled-components";
22
const Test = styled.div.withConfig({
33
displayName: "use-directory-name__Test",
4-
componentId: "sc-885txi-0"
4+
componentId: "sc-bccdtg-0"
55
})`color:red;`;
66
const before = styled.div.withConfig({
77
displayName: "use-directory-name__before",
8-
componentId: "sc-885txi-1"
8+
componentId: "sc-bccdtg-1"
99
})`color:blue;`;
1010
styled.div.withConfig({
1111
displayName: "use-directory-name",
12-
componentId: "sc-885txi-2"
12+
componentId: "sc-bccdtg-2"
1313
})``;
1414
export default styled.button.withConfig({
1515
displayName: "use-directory-name",
16-
componentId: "sc-885txi-3"
16+
componentId: "sc-bccdtg-3"
1717
})``;
Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
11
import styled from "styled-components";
22
const Test = styled.div.withConfig({
33
displayName: "input__Test",
4-
componentId: "sc-3maeg5-0"
4+
componentId: "sc-bccdtg-0"
55
})`color:red;`;
66
const before = styled.div.withConfig({
77
displayName: "input__before",
8-
componentId: "sc-3maeg5-1"
8+
componentId: "sc-bccdtg-1"
99
})`color:blue;`;
1010
styled.div.withConfig({
1111
displayName: "input",
12-
componentId: "sc-3maeg5-2"
12+
componentId: "sc-bccdtg-2"
1313
})``;
1414
export default styled.button.withConfig({
1515
displayName: "input",
16-
componentId: "sc-3maeg5-3"
16+
componentId: "sc-bccdtg-3"
1717
})``;

tasks/transform_conformance/tests/plugin-styled-components/test/fixtures/styled-components/use-namespace/output.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,17 +9,17 @@ const GlobalStyle = styled.createGlobalStyle`
99
`;
1010
const Test = styled.default.div.withConfig({
1111
displayName: "input__Test",
12-
componentId: "test-namespace__sc-ko2l8q-0"
12+
componentId: "test-namespace__sc-zljhv7-0"
1313
})`color:red;`;
1414
const before = styled.default.div.withConfig({
1515
displayName: "input__before",
16-
componentId: "test-namespace__sc-ko2l8q-1"
16+
componentId: "test-namespace__sc-zljhv7-1"
1717
})`color:blue;`;
1818
styled.default.div.withConfig({
1919
displayName: "input",
20-
componentId: "test-namespace__sc-ko2l8q-2"
20+
componentId: "test-namespace__sc-zljhv7-2"
2121
})``;
2222
export default styled.default.button.withConfig({
2323
displayName: "input",
24-
componentId: "test-namespace__sc-ko2l8q-3"
24+
componentId: "test-namespace__sc-zljhv7-3"
2525
})``;

0 commit comments

Comments
 (0)