ds300 / react-native-typescript-transformer

Seamlessly use TypeScript with React Native
MIT License
657 stars 50 forks source link

Fix source mapping in react-native 0.52 #39

Closed ds300 closed 6 years ago

ds300 commented 6 years ago

following discussion from from #37

dluksza commented 6 years ago

Configuration for running jest tests described in https://github.com/ds300/react-native-typescript-transformer/issues/21#issuecomment-330148700 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 6 years ago

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

ds300 commented 6 years ago

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

dluksza commented 6 years ago

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

ds300 commented 6 years ago

Ah yes. I should have made another issue for that

ds300 commented 6 years ago

@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.

dluksza commented 6 years ago

@ds300 thank you that works! :D