@@ -6,6 +6,8 @@ const os = require('os')
6
6
const path = require ( 'path' )
7
7
const process = require ( 'process' )
8
8
const semver = require ( 'semver' )
9
+ const traverse = require ( 'babel-traverse' )
10
+
9
11
const TSCONFIG_PATH = process . env . TSCONFIG_PATH
10
12
11
13
let upstreamTransformer = null
@@ -47,6 +49,25 @@ function loadJsonFile(jsonFilename) {
47
49
}
48
50
}
49
51
52
+ // only used with RN >= 52
53
+ function sourceMapAstInPlace ( tsMap , babelAst ) {
54
+ const tsConsumer = new SourceMapConsumer ( tsMap )
55
+ traverse . default . cheap ( babelAst , node => {
56
+ if ( node . loc ) {
57
+ const originalStart = tsConsumer . originalPositionFor ( node . loc . start )
58
+ if ( originalStart . line ) {
59
+ node . loc . start . line = originalStart . line
60
+ node . loc . start . column = originalStart . column
61
+ }
62
+ const originalEnd = tsConsumer . originalPositionFor ( node . loc . end )
63
+ if ( originalEnd . line ) {
64
+ node . loc . start . line = originalEnd . line
65
+ node . loc . start . column = originalEnd . column
66
+ }
67
+ }
68
+ } )
69
+ }
70
+
50
71
function composeRawSourceMap ( tsMap , babelMap ) {
51
72
const tsConsumer = new SourceMapConsumer ( tsMap )
52
73
const composedMap = [ ]
@@ -192,6 +213,7 @@ module.exports.transform = function(src, filename, options) {
192
213
} )
193
214
194
215
if ( reactNativeMinorVersion >= 52 ) {
216
+ sourceMapAstInPlace ( tsCompileResult . sourceMapText , babelCompileResult . ast )
195
217
return babelCompileResult
196
218
}
197
219
0 commit comments