From e89c93f4f76bcd2030b30750a08dfec2cb2b3f02 Mon Sep 17 00:00:00 2001 From: Simen Bekkhus Date: Thu, 7 Apr 2022 08:23:50 -0700 Subject: [PATCH] fix(preprocessor): return object, not just code (#33576) Summary: Jest 28 will error if only a string is returned from a transfomer, it needs to be an object of `{code: string, map?: object}`. Returning an object has been supported since https://github.com/facebook/jest/pull/2290, released in Jest v20. ## Changelog [Internal] [Fixed] - Return object from Jest preprocessor Pull Request resolved: https://github.com/facebook/react-native/pull/33576 Test Plan: Green CI? Reviewed By: motiz88 Differential Revision: D35426748 Pulled By: robhogan fbshipit-source-id: 3edb79b62b2d34274be192061817d3fcd8a7ba17 --- jest/preprocessor_DO_NOT_USE.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/jest/preprocessor_DO_NOT_USE.js b/jest/preprocessor_DO_NOT_USE.js index b4fae006b41fd5..09c0140f033f39 100644 --- a/jest/preprocessor_DO_NOT_USE.js +++ b/jest/preprocessor_DO_NOT_USE.js @@ -30,7 +30,7 @@ babelRegisterOnly([]); const transformer = require('metro-react-native-babel-transformer'); module.exports = { - process(src /*: string */, file /*: string */) /*: string */ { + process(src /*: string */, file /*: string */) /*: {code: string, ...} */ { if (nodeFiles.test(file)) { // node specific transforms only return babelTransformSync(src, { @@ -38,7 +38,7 @@ module.exports = { sourceType: 'script', ...nodeOptions, ast: false, - }).code; + }); } const {ast} = transformer.transform({ @@ -111,7 +111,7 @@ module.exports = { sourceMaps: true, }, src, - ).code; + ); }, getCacheKey: (createCacheKeyFunction([