metro-source-map
Advanced tools
Comparing version 0.76.6 to 0.76.7
{ | ||
"name": "metro-source-map", | ||
"version": "0.76.6", | ||
"version": "0.76.7", | ||
"description": "🚇 Source map generator for Metro.", | ||
@@ -18,5 +18,5 @@ "main": "src/source-map.js", | ||
"invariant": "^2.2.4", | ||
"metro-symbolicate": "0.76.6", | ||
"metro-symbolicate": "0.76.7", | ||
"nullthrows": "^1.1.1", | ||
"ob1": "0.76.6", | ||
"ob1": "0.76.7", | ||
"source-map": "^0.5.6", | ||
@@ -23,0 +23,0 @@ "vlq": "^1.0.0" |
@@ -21,2 +21,3 @@ /** | ||
const t = require("@babel/types"); | ||
const invariant = require("invariant"); | ||
const nullthrows = require("nullthrows"); | ||
@@ -51,8 +52,47 @@ const fsPath = require("path"); | ||
} | ||
function functionMapBabelPlugin() { | ||
return { | ||
// Eagerly traverse the tree on `pre`, before any visitors have run, so | ||
// that regardless of plugin order we're dealing with the AST before any | ||
// mutations. | ||
visitor: {}, | ||
pre: ({ path, metadata, opts }) => { | ||
const { filename } = nullthrows(opts); | ||
const encoder = new MappingEncoder(); | ||
const visitor = getFunctionMapVisitor( | ||
{ | ||
filename, | ||
}, | ||
(mapping) => encoder.push(mapping) | ||
); | ||
invariant( | ||
path && t.isProgram(path.node), | ||
"path missing or not a program node" | ||
); | ||
// $FlowFixMe[prop-missing] checked above | ||
// $FlowFixMe[incompatible-type-arg] checked above | ||
const programPath = path; | ||
visitor.enter(programPath); | ||
programPath.traverse({ | ||
Function: visitor, | ||
Class: visitor, | ||
}); | ||
visitor.exit(programPath); | ||
/** | ||
* Traverses a Babel AST and calls the supplied callback with function name | ||
* mappings, one at a time. | ||
*/ | ||
function forEachMapping(ast, context, pushMapping) { | ||
// $FlowFixMe[prop-missing] Babel `File` is not generically typed | ||
const metroMetadata = metadata; | ||
const functionMap = encoder.getResult(); | ||
// Set the result on a metadata property | ||
if (!metroMetadata.metro) { | ||
metroMetadata.metro = { | ||
functionMap, | ||
}; | ||
} else { | ||
metroMetadata.metro.functionMap = functionMap; | ||
} | ||
}, | ||
}; | ||
} | ||
function getFunctionMapVisitor(context, pushMapping) { | ||
const nameStack = []; | ||
@@ -101,3 +141,3 @@ let tailPos = { | ||
: null; | ||
const visitor = { | ||
return { | ||
enter(path) { | ||
@@ -114,3 +154,11 @@ let name = getNameForPath(path); | ||
}; | ||
} | ||
/** | ||
* Traverses a Babel AST and calls the supplied callback with function name | ||
* mappings, one at a time. | ||
*/ | ||
function forEachMapping(ast, context, pushMapping) { | ||
const visitor = getFunctionMapVisitor(context, pushMapping); | ||
// Traversing populates/pollutes the path cache (`traverse.cache.path`) with | ||
@@ -447,4 +495,5 @@ // values missing the `hub` property needed by Babel transformation, so we | ||
module.exports = { | ||
functionMapBabelPlugin, | ||
generateFunctionMap, | ||
generateFunctionMappingsArray, | ||
}; |
@@ -19,3 +19,6 @@ /** | ||
const normalizeSourcePath = require("./Consumer/normalizeSourcePath"); | ||
const { generateFunctionMap } = require("./generateFunctionMap"); | ||
const { | ||
functionMapBabelPlugin, | ||
generateFunctionMap, | ||
} = require("./generateFunctionMap"); | ||
const Generator = require("./Generator"); | ||
@@ -186,2 +189,3 @@ // $FlowFixMe[untyped-import] - source-map | ||
fromRawMappingsNonBlocking, | ||
functionMapBabelPlugin, | ||
normalizeSourcePath, | ||
@@ -188,0 +192,0 @@ toBabelSegments, |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
126208
1953
+ Addedmetro-symbolicate@0.76.7(transitive)
+ Addedob1@0.76.7(transitive)
- Removedmetro-symbolicate@0.76.6(transitive)
- Removedob1@0.76.6(transitive)
Updatedmetro-symbolicate@0.76.7
Updatedob1@0.76.7