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

<!-- Help reviewers and the release process by writing your own changelog entry. For an example, see:
https://github.com/facebook/react-native/wiki/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
This commit is contained in:
Simen Bekkhus
2022-04-07 08:23:50 -07:00
committed by Facebook GitHub Bot
parent 8de1c9ce91
commit e89c93f4f7
+3 -3
View File
@@ -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([