babel-preset-expo 0.0.1-canary-20240405-cdfd9c1 → 0.0.1-canary-20240411-33a7dc1

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.
@@ -55,8 +55,17 @@ function environmentRestrictedReactAPIsPlugin(api) {
55
55
  // Check for both named and namespace imports
56
56
  const isForbidden = forbiddenList.includes(importName);
57
57
  if (isForbidden) {
58
- // Add special handling for `Component` since it is different to a function API.
59
- throw path.buildCodeFrameError(`Client-only "${sourceValue}" API "${importName}" cannot be imported in a React server component. Add the "use client" directive to the top of this file or one of the parent files to enable running this stateful code on a user's device.`);
58
+ if (['Component', 'PureComponent'].includes(importName)) {
59
+ // Add special handling for `Component` since it is different to a function API.
60
+ throw path.buildCodeFrameError(`Client-only "${sourceValue}" API "${importName}" cannot be imported in a React server component. Add the "use client" directive to the top of this file or one of the parent files to enable running this stateful code on a user's device.`);
61
+ }
62
+ else {
63
+ const forbiddenImports = path.scope.getData('forbiddenImports') ?? new Map();
64
+ if (!forbiddenImports.has(sourceValue))
65
+ forbiddenImports.set(sourceValue, new Set());
66
+ forbiddenImports.get(sourceValue).add(importName);
67
+ path.scope.setData('forbiddenImports', forbiddenImports);
68
+ }
60
69
  }
61
70
  }
62
71
  else {
@@ -69,6 +78,19 @@ function environmentRestrictedReactAPIsPlugin(api) {
69
78
  });
70
79
  }
71
80
  },
81
+ // Match against `var _useState = useState(0),`
82
+ VariableDeclarator(path) {
83
+ const importedSpecifiers = path.scope.getData('forbiddenImports');
84
+ if (!importedSpecifiers)
85
+ return;
86
+ importedSpecifiers.forEach((forbiddenApis, importName) => {
87
+ if (t.isCallExpression(path.node.init) && t.isIdentifier(path.node.init.callee)) {
88
+ if (forbiddenApis.has(path.node.init.callee.name)) {
89
+ throw path.buildCodeFrameError(`Client-only "useState" API cannot be used in a React server component. Add the "use client" directive to the top of this file or one of the parent files to enable running this stateful code on a user's device.`);
90
+ }
91
+ }
92
+ });
93
+ },
72
94
  MemberExpression(path) {
73
95
  const importedNamespaces = path.scope.getData('importedNamespace') || {};
74
96
  Object.keys(importedNamespaces).forEach((namespace) => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "babel-preset-expo",
3
- "version": "0.0.1-canary-20240405-cdfd9c1",
3
+ "version": "0.0.1-canary-20240411-33a7dc1",
4
4
  "description": "The Babel preset for Expo projects",
5
5
  "main": "build/index.js",
6
6
  "files": [
@@ -47,14 +47,14 @@
47
47
  "@babel/plugin-transform-parameters": "^7.22.15",
48
48
  "@babel/preset-typescript": "^7.23.0",
49
49
  "@babel/preset-react": "^7.22.15",
50
- "@react-native/babel-preset": "~0.74.77",
50
+ "@react-native/babel-preset": "~0.74.79",
51
51
  "babel-plugin-react-native-web": "~0.19.10",
52
52
  "react-refresh": "0.14.0"
53
53
  },
54
54
  "devDependencies": {
55
55
  "@babel/core": "^7.20.0",
56
- "expo-module-scripts": "0.0.1-canary-20240405-cdfd9c1",
56
+ "expo-module-scripts": "0.0.1-canary-20240411-33a7dc1",
57
57
  "jest": "^29.2.1"
58
58
  },
59
- "gitHead": "cdfd9c1a0b8d8860b542edea45cb452f3eea5269"
59
+ "gitHead": "33a7dc1ce3283426fd553cd6675d0540214ab902"
60
60
  }