This repository has been archived by the owner on Feb 18, 2019. It is now read-only.
forked from facebook/react-native
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Summary:This rev adds support for production sourcemaps on RAM. When we inject a module into JSC we use the original `sourceURL` and specify the `startingLineNumber` of the module relative to a "regular" bundle. By doing so, when an error is thrown, JSC will include the provided `sourceURL` as the filename and will use the indicated `startingLineNumber` to figure out on which line the error actually occurred. To make things a bit simpler and avoid having to deal with columns, we tweak the generated bundle so that each module starts on a new line. Since we cannot assure that each module's code will be on a single line as the minifier might break it on multiple (UglifyJS does so due to a bug on old versions of Chrome), we include on the index the line number that should be used when invoking `JSEvaluateScript`. Since the module length was not being used we replaced the placeholder we have there for the line number. Reviewed By: javache Differential Revision: D2997520 fb-gh-sync-id: 3243a489cbb5b48a963f4ccdd98ba63b30f53f3f shipit-source-id: 3243a489cbb5b48a963f4ccdd98ba63b30f53f3f
- Loading branch information
1 parent
7338c57
commit f99468d
Showing
10 changed files
with
175 additions
and
54 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
59 changes: 59 additions & 0 deletions
59
local-cli/bundle/output/unbundle/buildUnbundleSourcemap.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
/** | ||
* Copyright (c) 2015-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. | ||
*/ | ||
'use strict'; | ||
|
||
const sourceMap = require('source-map'); | ||
const SourceMapConsumer = sourceMap.SourceMapConsumer; | ||
|
||
/** | ||
* Builds the sourcemaps for any type of unbundle provided the Bundle that | ||
* contains the modules reachable from the entry point. | ||
* | ||
* The generated sourcemaps correspond to a regular bundle on which each module | ||
* starts on a new line. Depending on the type of unbundle you're using, you | ||
* will have to pipe the line number to native and use it when injecting the | ||
* module's code into JSC. This way, we'll trick JSC to believe all the code is | ||
* on a single big regular bundle where as it could be on an indexed bundle or | ||
* as sparsed assets. | ||
*/ | ||
function buildUnbundleSourcemap(bundle) { | ||
const generator = new sourceMap.SourceMapGenerator({}); | ||
const nonPolyfillModules = bundle.getModules().filter(module => | ||
!module.polyfill | ||
); | ||
|
||
let offset = 1; | ||
nonPolyfillModules.forEach(module => { | ||
if (module.map) { // assets have no sourcemap | ||
const consumer = new SourceMapConsumer(module.map); | ||
consumer.eachMapping(mapping => { | ||
generator.addMapping({ | ||
original: { | ||
line: mapping.originalLine, | ||
column: mapping.originalColumn, | ||
}, | ||
generated: { | ||
line: mapping.generatedLine + offset, | ||
column: mapping.generatedColumn, | ||
}, | ||
source: module.sourcePath, | ||
}); | ||
}); | ||
|
||
generator.setSourceContent(module.sourcePath, module.sourceCode); | ||
} | ||
|
||
// some modules span more than 1 line | ||
offset += module.code.split('\n').length; | ||
}); | ||
|
||
return generator.toString(); | ||
} | ||
|
||
module.exports = buildUnbundleSourcemap; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.