/** * Copyright (c) Meta Platforms, Inc. and affiliates. * * This source code is licensed under the MIT license found in the * LICENSE file in the root directory of this source tree. * * @flow strict-local * @format */ 'use strict'; const {ParserError} = require('./errors'); const path = require('path'); export type TypeDeclarationMap = {[declarationName: string]: $FlowFixMe}; export type TypeAliasResolutionStatus = | $ReadOnly<{ successful: true, aliasName: string, }> | $ReadOnly<{ successful: false, }>; function extractNativeModuleName(filename: string): string { // this should drop everything after the file name. For Example it will drop: // .android.js, .android.ts, .android.tsx, .ios.js, .ios.ts, .ios.tsx, .js, .ts, .tsx return path.basename(filename).split('.')[0]; } export type ParserErrorCapturer = (fn: () => T) => ?T; function createParserErrorCapturer(): [ Array, ParserErrorCapturer, ] { const errors = []; function guard(fn: () => T): ?T { try { return fn(); } catch (error) { if (!(error instanceof ParserError)) { throw error; } errors.push(error); return null; } } return [errors, guard]; } module.exports = { extractNativeModuleName, createParserErrorCapturer, };