@expo/html-elements 0.4.1 → 0.4.2

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/CHANGELOG.md CHANGED
@@ -8,6 +8,9 @@
8
8
 
9
9
  ### 🐛 Bug fixes
10
10
 
11
+ - Prevent babel plugin from running on node_modules. ([#21594](https://github.com/expo/expo/pull/21594) by [@EvanBacon](https://github.com/EvanBacon))
12
+ - Prevent babel plugin from transforming `html` and `body` on web. ([#21594](https://github.com/expo/expo/pull/21594) by [@EvanBacon](https://github.com/EvanBacon))
13
+
11
14
  ### 💡 Others
12
15
 
13
16
  ## 0.4.1 — 2023-02-09
@@ -15,6 +15,10 @@ const options = {
15
15
  },
16
16
  ],
17
17
  ],
18
+ caller: {
19
+ name: 'metro',
20
+ platform: 'ios',
21
+ },
18
22
  minified: false,
19
23
  plugins: [plugin],
20
24
  compact: false,
@@ -36,6 +40,35 @@ function App() {
36
40
  expect(code).not.toMatch(`@expo/html-elements`);
37
41
  });
38
42
 
43
+ it(`Skips html and body on web`, () => {
44
+ const sourceCode = `
45
+ function App() {
46
+ return <html><body>Test</body></html>;
47
+ }`;
48
+ const { code } = babel.transform(sourceCode, {
49
+ ...options,
50
+ caller: {
51
+ ...options.caller,
52
+ platform: 'web',
53
+ },
54
+ });
55
+ expect(code).toMatch(`_jsx("html", { children: _jsx("body", { children: "Test" }) });`);
56
+ const { code: nativeCode } = babel.transform(sourceCode, options);
57
+ expect(nativeCode).toMatch(`_jsx(Div, { children: _jsx(Div, { children: "Test" }) });`);
58
+ });
59
+
60
+ it(`Skips conversion in node modules`, () => {
61
+ const sourceCode = `
62
+ function App() {
63
+ return <a href="#">Link</a>;
64
+ }`;
65
+ const { code } = babel.transform(sourceCode, {
66
+ ...options,
67
+ filename: '/node_modules/foo/bar.js',
68
+ });
69
+ expect(code).not.toMatch(`import { A } from "@expo/html-elements";`);
70
+ });
71
+
39
72
  it(`Converts basic link`, () => {
40
73
  const sourceCode = `
41
74
  function App() {
package/babel.js CHANGED
@@ -50,10 +50,26 @@ const elementToComponent = {
50
50
  // NOTE: head, meta, link should use some special component in the future.
51
51
  };
52
52
 
53
- module.exports = ({ types: t }, { expo }) => {
53
+ function getPlatform(caller) {
54
+ return caller && caller.platform;
55
+ }
56
+
57
+ module.exports = ({ types: t, ...api }, { expo }) => {
58
+ const platform = api.caller(getPlatform);
59
+
54
60
  function replaceElement(path, state) {
61
+ // Not supported in node modules
62
+ if (/\/node_modules\//.test(state.filename)) {
63
+ return;
64
+ }
65
+
55
66
  const { name } = path.node.openingElement.name;
56
67
 
68
+ if (platform === 'web') {
69
+ if (['html', 'body'].includes(name)) {
70
+ return;
71
+ }
72
+ }
57
73
  // Replace element with @expo/html-elements
58
74
  const component = elementToComponent[name];
59
75
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@expo/html-elements",
3
- "version": "0.4.1",
3
+ "version": "0.4.2",
4
4
  "description": "Universal semantic HTML React components for iOS, Android, web, and desktop",
5
5
  "main": "build/Elements.js",
6
6
  "types": "build/Elements.d.ts",
@@ -58,6 +58,5 @@
58
58
  },
59
59
  "devDependencies": {
60
60
  "expo-module-scripts": "^3.0.0"
61
- },
62
- "gitHead": "1f8a6a09570fd451378565ca34933018ce48454e"
61
+ }
63
62
  }