main
js 34 lines 826 Bytes
Raw
1 /*
2 * Copyright (c) Meta Platforms, Inc. and affiliates.
3 *
4 * This source code is licensed under the MIT license found in the
5 * LICENSE file in the root directory of this source tree.
6 *
7 * @flow strict-local
8 */
9
10 import type {
11 BasicSourceMap,
12 MixedSourceMap,
13 IndexSourceMap,
14 } from './SourceMapTypes';
15
16 export function sourceMapIncludesSource(
17 sourcemap: MixedSourceMap,
18 source: ?string,
19 ): boolean {
20 if (source == null) {
21 return false;
22 }
23 if (sourcemap.mappings === undefined) {
24 const indexSourceMap: IndexSourceMap = sourcemap;
25 return indexSourceMap.sections.some(section => {
26 return sourceMapIncludesSource(section.map, source);
27 });
28 }
29
30 const basicMap: BasicSourceMap = sourcemap;
31 return basicMap.sources.some(
32 s => s === 'Inline Babel script' || source.endsWith(s),
33 );
34 }