mirror of
https://github.com/facebook/react-native.git
synced 2025-11-01 09:14:26 +00:00
5403946f09
Reviewed By: davidaurelio Differential Revision: D4627645 fbshipit-source-id: 3cf368c6a24a555b7d0a39045f6ba6fd92ae34e1
48 lines
1.2 KiB
JavaScript
48 lines
1.2 KiB
JavaScript
/**
|
|
* Copyright (c) 2016-present, Facebook, Inc.
|
|
* All rights reserved.
|
|
*
|
|
* This source code is licensed under the BSD-style license found in the
|
|
* LICENSE file in the root directory of this source tree. An additional grant
|
|
* of patent rights can be found in the PATENTS file in the same directory.
|
|
*
|
|
* @flow
|
|
*/
|
|
'use strict';
|
|
|
|
const {createIndexMap} = require('./source-map');
|
|
const {addModuleIdsToModuleWrapper} = require('./util');
|
|
|
|
import type {OutputFn} from '../types.flow';
|
|
|
|
module.exports = (
|
|
(modules, filename, idForPath) => {
|
|
let code = '';
|
|
let line = 0;
|
|
const sections = [];
|
|
|
|
for (const module of modules) {
|
|
const {file} = module;
|
|
const moduleCode = file.type === 'module'
|
|
? addModuleIdsToModuleWrapper(module, idForPath)
|
|
: file.code;
|
|
|
|
code += moduleCode + '\n';
|
|
if (file.map) {
|
|
sections.push({
|
|
map: file.map,
|
|
offset: {column: 0, line},
|
|
});
|
|
}
|
|
line += countLines(moduleCode);
|
|
}
|
|
|
|
return {code, map: createIndexMap({file: filename, sections})};
|
|
}: OutputFn);
|
|
|
|
const reLine = /^/gm;
|
|
function countLines(string: string): number {
|
|
//$FlowFixMe This regular expression always matches
|
|
return string.match(reLine).length;
|
|
}
|