Skip to content

Commit

Permalink
update babel and fix tests accordingly (#1343)
Browse files Browse the repository at this point in the history
Summary:
X-link: facebook/react-native#46295

Pull Request resolved: #1343

Updated all **babel** packages in all `package.json` across the repo and ran `npx yarn-deduplicate yarn.lock --scopes babel`. Afterwards, fixed the following issues appearing as a result of that (squashed the following initially separate diffs to make this packages update work atomically):
### (D61336392) updated jest snapshot tests failing
### (D61336393) updated babel types and corrected typings accordingly
The latest babel 7 introduces the following features we need to adjust our types to:
* `JSXNamespacedName` is removed from valid `CallExpression` args ([PR](babel/babel#16421))
  * `JSXNamespacedName` is used for namespaced XML properties in things like `<div namespace:name="value">`, but `fn(namespace:name)` doesn't make any sense.
* Dynamic imports are enabled behind a new flag `createImportExpressions` ([PR](babel/babel#15682)), introducing calls such as `import(foo, options)`. These complicate the expected values passed to `import` to be more than just strings.
  * Since these are behind a flag that is not expected to be enabled, we can throw an error for now and whoever uses it can add a support to it if needed later.

### Added a new metro ENV ignore
`BROWSERSLIST_ROOT_PATH` is set to `""` explicitly in `xplat/js/BUCK`
and then ignored in
`js/tools/metro-buck-transform-worker/src/EnvVarAllowList.js`

Reviewed By: robhogan

Differential Revision: D61543660

fbshipit-source-id: abbcab72642cf6dc03eed5142eb78dbcc7f63a86
  • Loading branch information
vzaidman authored and facebook-github-bot committed Sep 5, 2024
1 parent 71c6bb5 commit 2c3a22a
Show file tree
Hide file tree
Showing 19 changed files with 801 additions and 1,042 deletions.
9 changes: 9 additions & 0 deletions flow-typed/npm/babel-traverse_v7.x.x.js
Original file line number Diff line number Diff line change
Expand Up @@ -900,7 +900,9 @@ declare module '@babel/traverse' {
isImportAttribute(opts?: Opts): boolean;
isImportDeclaration(opts?: Opts): boolean;
isImportDefaultSpecifier(opts?: Opts): boolean;
isImportExpression(opts?: Opts): boolean;
isImportNamespaceSpecifier(opts?: Opts): boolean;
isImportOrExportDeclaration(opts?: Opts): boolean;
isImportSpecifier(opts?: Opts): boolean;
isIndexedAccessType(opts?: Opts): boolean;
isInferredPredicate(opts?: Opts): boolean;
Expand Down Expand Up @@ -1215,7 +1217,9 @@ declare module '@babel/traverse' {
assertImportAttribute(opts?: Opts): void;
assertImportDeclaration(opts?: Opts): void;
assertImportDefaultSpecifier(opts?: Opts): void;
assertImportExpression(opts?: Opts): void;
assertImportNamespaceSpecifier(opts?: Opts): void;
assertImportOrExportDeclaration(opts?: Opts): void;
assertImportSpecifier(opts?: Opts): void;
assertIndexedAccessType(opts?: Opts): void;
assertInferredPredicate(opts?: Opts): void;
Expand Down Expand Up @@ -1571,10 +1575,15 @@ declare module '@babel/traverse' {
ImportAttribute?: VisitNode<BabelNodeImportAttribute, TState>,
ImportDeclaration?: VisitNode<BabelNodeImportDeclaration, TState>,
ImportDefaultSpecifier?: VisitNode<BabelNodeImportDefaultSpecifier, TState>,
ImportExpression?: VisitNode<BabelNodeImportExpression, TState>,
ImportNamespaceSpecifier?: VisitNode<
BabelNodeImportNamespaceSpecifier,
TState,
>,
ImportOrExportDeclaration?: VisitNode<
BabelNodeImportOrExportDeclaration,
TState,
>,
ImportSpecifier?: VisitNode<BabelNodeImportSpecifier, TState>,
IndexedAccessType?: VisitNode<BabelNodeIndexedAccessType, TState>,
InferredPredicate?: VisitNode<BabelNodeInferredPredicate, TState>,
Expand Down
95 changes: 58 additions & 37 deletions flow-typed/npm/babel-types_v7.x.x.js

Large diffs are not rendered by default.

11 changes: 6 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
{
"private": true,
"devDependencies": {
"@babel/core": "^7.20.0",
"@babel/plugin-syntax-class-properties": "^7.0.0",
"@babel/plugin-transform-flow-strip-types": "^7.20.0",
"@babel/plugin-transform-modules-commonjs": "^7.0.0",
"@babel/plugin-transform-react-jsx": "^7.0.0",
"@babel/core": "^7.25.2",
"@babel/plugin-syntax-class-properties": "^7.12.13",
"@babel/plugin-transform-flow-strip-types": "^7.25.2",
"@babel/plugin-transform-modules-commonjs": "^7.24.8",
"@babel/plugin-transform-react-jsx": "^7.25.2",
"@babel/types": "^7.25.2",
"@tsconfig/node18": "1.0.1",
"@typescript-eslint/eslint-plugin": "^7.1.1",
"@typescript-eslint/parser": "^7.1.1",
Expand Down
10 changes: 5 additions & 5 deletions packages/metro-babel-register/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@
"url": "git@github.com:facebook/metro.git"
},
"dependencies": {
"@babel/core": "^7.20.0",
"@babel/core": "^7.25.2",
"@babel/plugin-proposal-export-namespace-from": "^7.18.9",
"@babel/plugin-transform-flow-strip-types": "^7.20.0",
"@babel/plugin-transform-modules-commonjs": "^7.0.0",
"@babel/preset-typescript": "^7.18.0",
"@babel/register": "^7.0.0",
"@babel/plugin-transform-flow-strip-types": "^7.25.2",
"@babel/plugin-transform-modules-commonjs": "^7.24.8",
"@babel/preset-typescript": "^7.24.7",
"@babel/register": "^7.24.6",
"babel-plugin-replace-ts-export-assignment": "^0.0.2",
"babel-plugin-syntax-hermes-parser": "0.23.1",
"babel-plugin-transform-flow-enums": "^0.0.2",
Expand Down
2 changes: 1 addition & 1 deletion packages/metro-babel-transformer/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
],
"license": "MIT",
"dependencies": {
"@babel/core": "^7.20.0",
"@babel/core": "^7.25.2",
"flow-enums-runtime": "^0.0.6",
"hermes-parser": "0.23.1",
"nullthrows": "^1.1.1"
Expand Down
2 changes: 1 addition & 1 deletion packages/metro-runtime/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
"flow-enums-runtime": "^0.0.6"
},
"devDependencies": {
"@babel/core": "^7.20.0",
"@babel/core": "^7.25.2",
"react": "19.0.0-rc-fb9a90fa48-20240614",
"react-refresh": "^0.14.0",
"react-test-renderer": "19.0.0-rc-fb9a90fa48-20240614"
Expand Down
10 changes: 5 additions & 5 deletions packages/metro-source-map/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@
"cleanup-release": "test ! -e build && mv src build && mv src.real src"
},
"dependencies": {
"@babel/traverse": "^7.20.0",
"@babel/traverse--for-generate-function-map": "npm:@babel/traverse@^7.20.0",
"@babel/types": "^7.20.0",
"@babel/traverse": "^7.25.3",
"@babel/traverse--for-generate-function-map": "npm:@babel/traverse@^7.25.3",
"@babel/types": "^7.25.2",
"flow-enums-runtime": "^0.0.6",
"invariant": "^2.2.4",
"metro-symbolicate": "0.80.11",
Expand All @@ -25,8 +25,8 @@
},
"license": "MIT",
"devDependencies": {
"@babel/core": "^7.20.0",
"@babel/parser": "^7.20.0",
"@babel/core": "^7.25.2",
"@babel/parser": "^7.25.3",
"terser": "^5.15.0"
},
"engines": {
Expand Down
18 changes: 9 additions & 9 deletions packages/metro-transform-plugins/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,19 +13,19 @@
},
"license": "MIT",
"dependencies": {
"@babel/core": "^7.20.0",
"@babel/generator": "^7.20.0",
"@babel/template": "^7.0.0",
"@babel/traverse": "^7.20.0",
"@babel/core": "^7.25.2",
"@babel/generator": "^7.25.0",
"@babel/template": "^7.25.0",
"@babel/traverse": "^7.25.3",
"flow-enums-runtime": "^0.0.6",
"nullthrows": "^1.1.1"
},
"devDependencies": {
"@babel/code-frame": "^7.0.0",
"@babel/plugin-syntax-nullish-coalescing-operator": "^7.0.0",
"@babel/plugin-transform-flow-strip-types": "^7.20.0",
"@babel/plugin-transform-modules-commonjs": "^7.0.0",
"@babel/types": "^7.20.0",
"@babel/code-frame": "^7.24.7",
"@babel/plugin-syntax-nullish-coalescing-operator": "^7.8.3",
"@babel/plugin-transform-flow-strip-types": "^7.25.2",
"@babel/plugin-transform-modules-commonjs": "^7.24.8",
"@babel/types": "^7.25.2",
"babel-plugin-tester": "^6.0.1",
"metro": "0.80.11"
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,7 @@ describe('inline-requires', () => {
['import Imported from "foo";', 'console.log(Imported);'],
[
'var _foo = _interopRequireDefault(require("foo"));',
'function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }',
'function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }',
'console.log(_foo.default);',
],
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,6 @@ function createInlinePlatformChecks(
args: Array<
| BabelNodeExpression
| BabelNodeSpreadElement
| BabelNodeJSXNamespacedName
| BabelNodeArgumentPlaceholder,
>,
dependencyId: string,
Expand Down
8 changes: 4 additions & 4 deletions packages/metro-transform-worker/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@
},
"license": "MIT",
"dependencies": {
"@babel/core": "^7.20.0",
"@babel/generator": "^7.20.0",
"@babel/parser": "^7.20.0",
"@babel/types": "^7.20.0",
"@babel/core": "^7.25.2",
"@babel/generator": "^7.25.0",
"@babel/parser": "^7.25.3",
"@babel/types": "^7.25.2",
"flow-enums-runtime": "^0.0.6",
"metro": "0.80.11",
"metro-babel-transformer": "0.80.11",
Expand Down
Loading

0 comments on commit 2c3a22a

Please sign in to comment.