diff --git a/packages/metro-source-map/package.json b/packages/metro-source-map/package.json index 619fa4723d..fb462dcc53 100644 --- a/packages/metro-source-map/package.json +++ b/packages/metro-source-map/package.json @@ -13,6 +13,7 @@ }, "dependencies": { "@babel/traverse": "^7.20.0", + "@babel/traverse--for-generate-function-map": "npm:@babel/traverse@^7.20.0", "@babel/types": "^7.20.0", "flow-enums-runtime": "^0.0.6", "invariant": "^2.2.4", diff --git a/packages/metro-source-map/src/generateFunctionMap.js b/packages/metro-source-map/src/generateFunctionMap.js index 3e6e980bb7..d3d5444d77 100644 --- a/packages/metro-source-map/src/generateFunctionMap.js +++ b/packages/metro-source-map/src/generateFunctionMap.js @@ -17,7 +17,8 @@ import type {NodePath} from '@babel/traverse'; import type {Node} from '@babel/types'; import type {MetroBabelFileMetadata} from 'metro-babel-transformer'; -import traverse from '@babel/traverse'; +// $FlowFixMe[cannot-resolve-module] - resolves to @babel/traverse +import traverseSecondInstallation from '@babel/traverse--for-generate-function-map'; import { isAssignmentExpression, isClassBody, @@ -220,13 +221,8 @@ function forEachMapping( ) { const visitor = getFunctionMapVisitor(context, pushMapping); - // Traversing populates/pollutes the path cache (`traverse.cache.path`) with - // values missing the `hub` property needed by Babel transformation, so we - // save, clear, and restore the cache around our traversal. - // See: https://github.com/facebook/metro/pull/854#issuecomment-1336499395 - const previousCache = traverse.cache.path; - traverse.cache.clearPath(); - traverse(ast, { + // TODO: improve comment + traverseSecondInstallation(ast, { // Our visitor doesn't care about scope noScope: true, @@ -234,7 +230,6 @@ function forEachMapping( Program: visitor, Class: visitor, }); - traverse.cache.path = previousCache; } const ANONYMOUS_NAME = ''; diff --git a/yarn.lock b/yarn.lock index 4bbf47f348..852175876a 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1089,7 +1089,7 @@ "@babel/parser" "^7.22.5" "@babel/types" "^7.22.5" -"@babel/traverse@^7.19.1", "@babel/traverse@^7.20.0", "@babel/traverse@^7.20.1", "@babel/traverse@^7.20.5", "@babel/traverse@^7.4.3": +"@babel/traverse--for-generate-function-map@npm:@babel/traverse@^7.20.0", "@babel/traverse@^7.19.1", "@babel/traverse@^7.20.0", "@babel/traverse@^7.20.1", "@babel/traverse@^7.20.5", "@babel/traverse@^7.4.3": version "7.20.5" resolved "https://registry.yarnpkg.com/@babel/traverse/-/traverse-7.20.5.tgz#78eb244bea8270fdda1ef9af22a5d5e5b7e57133" integrity sha512-WM5ZNN3JITQIq9tFZaw1ojLU3WgWdtkxnhM1AegMS+PvHjkM5IXjmYEGY7yukz5XS4sJyEf2VzWjI8uAavhxBQ==