Skip to content

Commit eacc022

Browse files
committed
fix: compatibiliy checking not comparing proprety names correctly
1 parent 0168906 commit eacc022

File tree

6 files changed

+151
-5
lines changed

6 files changed

+151
-5
lines changed

packages/react-email/src/actions/email-validation/check-compatibility.ts

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -278,8 +278,8 @@ export const checkCompatibility = async (
278278

279279
if (cssEntryType === 'full property') {
280280
if (
281-
property.name === entryFullProperty?.name &&
282-
property.value === entryFullProperty.value
281+
property.name === snakeToCamel(entryFullProperty!.name) &&
282+
property.value === entryFullProperty!.value
283283
) {
284284
addToInsights(property);
285285
break;
@@ -306,7 +306,7 @@ export const checkCompatibility = async (
306306
}
307307
} else if (
308308
entryProperties.some(
309-
(propertyName) => property.name === propertyName,
309+
(propertyName) => property.name === snakeToCamel(propertyName),
310310
)
311311
) {
312312
addToInsights(property);
@@ -322,4 +322,10 @@ export const checkCompatibility = async (
322322
return readableStream;
323323
};
324324

325+
const snakeToCamel = (snakeStr: string) => {
326+
return snakeStr
327+
.toLowerCase()
328+
.replace(/-+([a-z])/g, (_match, letter) => letter.toUpperCase());
329+
};
330+
325331
export type AST = ReturnType<typeof parse>;
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html
2+
3+
exports[`getObjectVariables() 1`] = `
4+
{
5+
"buttonStyle": [
6+
Node {
7+
"computed": false,
8+
"end": 91,
9+
"key": Node {
10+
"end": 84,
11+
"loc": SourceLocation {
12+
"end": Position {
13+
"column": 14,
14+
"index": 84,
15+
"line": 5,
16+
},
17+
"filename": undefined,
18+
"identifierName": "borderRadius",
19+
"start": Position {
20+
"column": 2,
21+
"index": 72,
22+
"line": 5,
23+
},
24+
},
25+
"name": "borderRadius",
26+
"start": 72,
27+
"type": "Identifier",
28+
},
29+
"loc": SourceLocation {
30+
"end": Position {
31+
"column": 21,
32+
"index": 91,
33+
"line": 5,
34+
},
35+
"filename": undefined,
36+
"identifierName": undefined,
37+
"start": Position {
38+
"column": 2,
39+
"index": 72,
40+
"line": 5,
41+
},
42+
},
43+
"method": false,
44+
"shorthand": false,
45+
"start": 72,
46+
"type": "ObjectProperty",
47+
"value": Node {
48+
"end": 91,
49+
"extra": {
50+
"raw": "'5px'",
51+
"rawValue": "5px",
52+
},
53+
"loc": SourceLocation {
54+
"end": Position {
55+
"column": 21,
56+
"index": 91,
57+
"line": 5,
58+
},
59+
"filename": undefined,
60+
"identifierName": undefined,
61+
"start": Position {
62+
"column": 16,
63+
"index": 86,
64+
"line": 5,
65+
},
66+
},
67+
"start": 86,
68+
"type": "StringLiteral",
69+
"value": "5px",
70+
},
71+
},
72+
],
73+
}
74+
`;
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html
2+
3+
exports[`getUsedStyleProperties() 1`] = `
4+
[
5+
{
6+
"location": SourceLocation {
7+
"end": Position {
8+
"column": 21,
9+
"index": 91,
10+
"line": 5,
11+
},
12+
"filename": undefined,
13+
"identifierName": undefined,
14+
"start": Position {
15+
"column": 2,
16+
"index": 72,
17+
"line": 5,
18+
},
19+
},
20+
"name": "borderRadius",
21+
"value": "5px",
22+
},
23+
]
24+
`;
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import { parse } from "@babel/parser";
2+
import { getObjectVariables } from "./get-object-variables";
3+
4+
test('getObjectVariables()', () => {
5+
const reactCode = `
6+
<Button style={buttonStyle}>Click me</Button>
7+
8+
const buttonStyle = {
9+
borderRadius: '5px',
10+
};
11+
`;
12+
const ast = parse(reactCode, {
13+
strictMode: false,
14+
errorRecovery: true,
15+
sourceType: 'unambiguous',
16+
plugins: ['jsx', 'typescript', 'decorators'],
17+
});
18+
expect(getObjectVariables(ast)).toMatchSnapshot();
19+
});
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import { parse } from '@babel/parser';
2+
import { getObjectVariables } from './get-object-variables';
3+
import { getUsedStyleProperties } from './get-used-style-properties';
4+
5+
test('getUsedStyleProperties()', async () => {
6+
const reactCode = `
7+
<Button style={buttonStyle}>Click me</Button>
8+
9+
const buttonStyle = {
10+
borderRadius: '5px',
11+
};
12+
`;
13+
const ast = parse(reactCode, {
14+
strictMode: false,
15+
errorRecovery: true,
16+
sourceType: 'unambiguous',
17+
plugins: ['jsx', 'typescript', 'decorators'],
18+
});
19+
const objectVariables = getObjectVariables(ast);
20+
expect(
21+
await getUsedStyleProperties(ast, reactCode, '', objectVariables),
22+
).toMatchSnapshot();
23+
});

packages/react-email/src/utils/caniemail/get-css-property-with-value.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ export const getCssPropertyWithValue = (title: string) => {
66
if (match) {
77
const [_full, propertyName, propertyValue] = match;
88
return {
9-
name: propertyName,
10-
value: propertyValue,
9+
name: propertyName!,
10+
value: propertyValue!,
1111
};
1212
}
1313
return undefined;

0 commit comments

Comments
 (0)