Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
function findOriginalPos(
frame: StackFrameInput,
module: ExplodedSourceMapModule,
): ?Position {
if (
module.map == null ||
frame.lineNumber == null ||
frame.column == null
) {
return null;
}
const generatedPosInModule = {
line1Based: frame.lineNumber - module.firstLine1Based + 1,
column0Based: frame.column,
};
const mappingIndex = greatestLowerBound(
module.map,
generatedPosInModule,
(target, candidate) => {
if (target.line1Based === candidate[0]) {
return target.column0Based - candidate[1];
}
return target.line1Based - candidate[0];
},
);
if (mappingIndex == null) {
return null;
}
const mapping = module.map[mappingIndex];
if (
mapping[0] !== generatedPosInModule.line1Based ||
mapping.length < 4 /* no source line/column info */
: process.env.BABEL_ENV || 'production';
try {
const babelConfig = {
// ES modules require sourceType='module' but OSS may not always want that
sourceType: 'unambiguous',
...buildBabelConfig(filename, options, plugins),
caller: {name: 'metro', platform: options.platform},
ast: true,
};
const sourceAst = parseSync(src, babelConfig);
/* $FlowFixMe(>=0.111.0 site=react_native_fb) This comment suppresses an
* error found when Flow v0.111 was deployed. To see the error, delete this
* comment and run Flow. */
const result = transformFromAstSync(sourceAst, src, babelConfig);
const functionMap = generateFunctionMap(sourceAst, {filename});
// The result from `transformFromAstSync` can be null (if the file is ignored)
if (!result) {
return {ast: null, functionMap};
}
return {ast: result.ast, functionMap};
} finally {
if (OLD_BABEL_ENV) {
process.env.BABEL_ENV = OLD_BABEL_ENV;
}
}
}
const inlineRequiresPlugin = require("babel-preset-fbjs/plugins/inline-requires");
const normalizePseudoglobals = require("./worker/normalizePseudoglobals");
const _require = require("@babel/core"),
transformFromAstSync = _require.transformFromAstSync;
const _require2 = require("metro-cache"),
stableHash = _require2.stableHash;
const types = require("@babel/types");
const _require3 = require("metro-source-map"),
fromRawMappings = _require3.fromRawMappings,
toBabelSegments = _require3.toBabelSegments,
toSegmentTuple = _require3.toSegmentTuple;
function getDynamicDepsBehavior(inPackages, filename) {
switch (inPackages) {
case "reject":
return "reject";
case "throwAtRuntime":
const isPackage = /(?:^|[/\\])node_modules[/\\]/.test(filename);
return isPackage ? inPackages : "reject";
default:
inPackages;
throw new Error(
`invalid value for dynamic deps behavior: \`${inPackages}\``
);
}
const ramModules = modules.map(module => ({
id: module.id,
code: module.code,
map: fromRawMappings([module]).toMap(module.path, {
excludeSource: options.excludeSource,
}),
name: module.name,
sourcePath: module.path,
source: module.source,
type: module.type,
}));
async function fullSourceMap(
deltaBundler: DeltaBundler,
options: BundleOptions,
): Promise {
const {modules} = await _getAllModules(deltaBundler, options);
return fromRawMappings(modules).toString(undefined, {
excludeSource: options.excludeSource,
});
}
async _minifyCode(
filename: string,
code: string,
source: string,
map: Array,
reserved?: $ReadOnlyArray = [],
): Promise<{
code: string,
map: Array,
...
}> {
const sourceMap = fromRawMappings([
{code, source, map, functionMap: null, path: filename},
]).toMap(undefined, {});
const minify = getMinifier(this._config.minifierPath);
try {
const minified = minify({
code,
map: sourceMap,
filename,
reserved,
config: this._config.minifierConfig,
});
return {
code: minified.code,
async function fullSourceMapObject(
deltaBundler: DeltaBundler,
options: BundleOptions,
): Promise {
const {modules} = await _getAllModules(deltaBundler, options);
return fromRawMappings(modules).toMap(undefined, {
excludeSource: options.excludeSource,
});
}
): ReturnType {
let sourceMapInfos;
getSourceMapInfosImpl(
true,
infos => {
sourceMapInfos = infos;
},
modules,
options,
);
if (sourceMapInfos == null) {
throw new Error(
'Expected getSourceMapInfosImpl() to finish synchronously.',
);
}
return fromRawMappings(sourceMapInfos);
}
async minifyModule(
path: string,
code: string,
map: CompactRawMappings,
): Promise<{code: string, map: CompactRawMappings}> {
const sourceMap = fromRawMappings([{code, source: code, map, path}]).toMap(
undefined,
{},
);
const minified = await this._minifyCode(path, code, sourceMap);
const result = await this._postMinifyProcess({...minified});
return {
code: result.code,
map: result.map ? toRawMappings(result.map).map(compactMapping) : [],
};
}
function findModule(frame: StackFrameInput): ?ExplodedSourceMapModule {
const map = mapsByUrl.get(frame.file);
if (!map || frame.lineNumber == null) {
return null;
}
const moduleIndex = greatestLowerBound(
map,
frame.lineNumber,
(target, candidate) => target - candidate.firstLine1Based,
);
if (moduleIndex == null) {
return null;
}
return map[moduleIndex];
}