ds300/react-native-typescript-transformer

Fix source mapping in react-native 0.52

ds300 opened this issue · 7 comments

ds300 commented

following discussion from from #37

Configuration for running jest tests described in #21 (comment) also doesn't work with 0.52

It is failing with error:

  ● Test suite failed to run

    TypeError: Jest: a transform's `process` function must return a string, or an object with `code` key containing this string.
      
      at ScriptTransformer.transformSource (node_modules/jest-runtime/build/script_transformer.js:238:15)
ds300 commented

Ah yes, that makes sense. Thanks for the heads-up! I'm going to try duplicating the old upstream transformer locally.

ds300 commented

Another thing I'm trying is traversing the ast and updating its mappings in place. Seems doable so far.

Jest tests are still failing with the same error as mentioned in my previous comment :|

ds300 commented

Ah yes. I should have made another issue for that

ds300 commented

@dluksza you can do this for now:

var tsTransformer = require('react-native-typescript-transformer')
var rnTransformer = require('react-native/jest/preprocessor')
var generate = require('babel-generator')

var preprocessor = Object.assign({}, rnTransformer, {
  process (src, file) {
    const {ast} = tsTransformer.transform({
      filename: file,
      localPath: file,
      options: {
        dev: true,
        platform: '',
        projectRoot: '',
      },
      src,
    })

    return generate.default(ast, {
      filename: file,
      retainLines: true
    }, src)
  },
})

module.exports = preprocessor

It doesn't do source mapping, but then neither did the original version.

@ds300 thank you that works! :D