Skip to content

Commit

Permalink
support for RN >= 0.56
Browse files Browse the repository at this point in the history
  • Loading branch information
Jesús Carrera committed Oct 6, 2018
1 parent 94bd5ae commit 904334d
Show file tree
Hide file tree
Showing 3 changed files with 3,675 additions and 1,626 deletions.
12 changes: 6 additions & 6 deletions package.json
Expand Up @@ -13,7 +13,7 @@
"@types/node": "^9.3.0",
"@types/semver": "^5.4.0",
"app-root-path": "^2.0.1",
"babel-generator": "^6.26.0",
"babel-generator": "^6.26.1",
"javascript-obfuscator": "^0.13.0",
"jju": "^1.3.0",
"semver": "^5.4.1",
Expand All @@ -30,7 +30,7 @@
"typings": "dist/index.d.ts",
"lint-staged": {
"**/*.ts": [
"prettier --list-different --no-semi --trailing-comma all"
"prettier --no-semi --trailing-comma all"
]
},
"devDependencies": {
Expand All @@ -39,11 +39,11 @@
"husky": "^0.13.3",
"jest": "^22.0.6",
"lint-staged": "^3.4.1",
"metro": "^0.24.3",
"metro-bundler": "^0.9.0",
"metro": "^0.45.6",
"metro-bundler": "^0.22.1",
"np": "^2.18.3",
"prettier": "^1.10.2",
"react-native": "^0.45.1",
"react-native": "^0.57.1",
"ts-jest": "^22.0.1",
"ts-node": "^4.1.0",
"typescript": "^2.6.2"
Expand All @@ -66,4 +66,4 @@
"json"
]
}
}
}
30 changes: 16 additions & 14 deletions src/getMetroTransformer.ts
Expand Up @@ -44,7 +44,9 @@ function getReactNativeMinorVersion(): number {
export function getMetroTransformer(
reactNativeMinorVersion: number = getReactNativeMinorVersion(),
): MetroTransformer {
if (reactNativeMinorVersion >= 52) {
if (reactNativeMinorVersion >= 56) {
return require("metro/src/reactNativeTransformer")
} else if (reactNativeMinorVersion >= 52) {
return require("metro/src/transformer")
} else if (reactNativeMinorVersion >= 0.47) {
return require("metro-bundler/src/transformer")
Expand Down Expand Up @@ -74,20 +76,20 @@ export function maybeTransformMetroResult(
})

const mapConsumer = new SourceMapConsumer(map as any) // upstream types are wrong
;(traverse as any).cheap(ast, (node: Node) => {
if (node.loc) {
const originalStart = mapConsumer.originalPositionFor(node.loc.start)
if (originalStart.line) {
node.loc.start.line = originalStart.line
node.loc.start.column = originalStart.column
}
const originalEnd = mapConsumer.originalPositionFor(node.loc.end)
if (originalEnd.line) {
node.loc.end.line = originalEnd.line
node.loc.end.column = originalEnd.column
; (traverse as any).cheap(ast, (node: Node) => {
if (node.loc) {
const originalStart = mapConsumer.originalPositionFor(node.loc.start)
if (originalStart.line) {
node.loc.start.line = originalStart.line
node.loc.start.column = originalStart.column
}
const originalEnd = mapConsumer.originalPositionFor(node.loc.end)
if (originalEnd.line) {
node.loc.end.line = originalEnd.line
node.loc.end.column = originalEnd.column
}
}
}
})
})

return { ast }
} else if (Array.isArray(upstreamResult.map)) {
Expand Down

0 comments on commit 904334d

Please sign in to comment.