Skip to content

Commit

Permalink
Fix debugging issues when some packages was installed on RN 0.61 app (#…
Browse files Browse the repository at this point in the history
…1129)

* Fix RegExp
* Add more test scenarios
  • Loading branch information
SounD120 authored Oct 9, 2019
1 parent e19e677 commit 62a3a50
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/debugger/sourceMap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ export interface IStrictUrl extends url.Url {

export class SourceMapUtil {
private static SourceMapURLRegex: RegExp = /\/\/(#|@) sourceMappingURL=((?!data:).+?)\s*$/m;
private static SourceURLRegex: RegExp = /\/\/(#|@) sourceURL=((?!data:).+?)\s*$/m;
private static SourceURLRegex: RegExp = /\/\/(#|@) sourceURL=((?!data:).+?)\s*$/;

/**
* Given a script body and URL, this method parses the body and finds the corresponding source map URL.
Expand Down
21 changes: 19 additions & 2 deletions test/debugger/sourceMap.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -111,9 +111,26 @@ suite("sourceMap", function() {
});

test("should remove sourceURL from the bundle script body correctly", function() {
const scriptBody: string = `//# sourceMappingURL=index.map
const scriptBody: string = `//# sourceURL=http://localhost:8081/index.bundle?platform=android&dev=true&minify=false
var sourceURL = '//# sourceURL=' + (hasOwnProperty.call(options, 'sourceURL') ? (options.sourceURL + '').replace(/[\\r\\n]/g, ' ') : 'lodash.templateSources[' + ++templateCounter + ']') + '\\n';
//# sourceMappingURL=index.map
//# sourceURL=http://localhost:8081/index.bundle?platform=android&dev=true&minify=false`;
const expectedScriptBody = "//# sourceMappingURL=index.map\n";
const expectedScriptBody = `//# sourceURL=http://localhost:8081/index.bundle?platform=android&dev=true&minify=false
var sourceURL = '//# sourceURL=' + (hasOwnProperty.call(options, 'sourceURL') ? (options.sourceURL + '').replace(/[\\r\\n]/g, ' ') : 'lodash.templateSources[' + ++templateCounter + ']') + '\\n';
//# sourceMappingURL=index.map\n`;
const sourceMap = new SourceMapUtil();

const result = sourceMap.removeSourceURL(scriptBody);
assert.equal(expectedScriptBody, result);
});

test("should not remove anything if sourceURL is not in the end of the bundle script", function() {
const scriptBody: string = `//# sourceURL=http://localhost:8081/index.bundle?platform=android&dev=true&minify=false
var sourceURL = '//# sourceURL=' + (hasOwnProperty.call(options, 'sourceURL') ? (options.sourceURL + '').replace(/[\\r\\n]/g, ' ') : 'lodash.templateSources[' + ++templateCounter + ']') + '\\n';
//# sourceMappingURL=index.map`;
const expectedScriptBody = `//# sourceURL=http://localhost:8081/index.bundle?platform=android&dev=true&minify=false
var sourceURL = '//# sourceURL=' + (hasOwnProperty.call(options, 'sourceURL') ? (options.sourceURL + '').replace(/[\\r\\n]/g, ' ') : 'lodash.templateSources[' + ++templateCounter + ']') + '\\n';
//# sourceMappingURL=index.map`;
const sourceMap = new SourceMapUtil();

const result = sourceMap.removeSourceURL(scriptBody);
Expand Down

0 comments on commit 62a3a50

Please sign in to comment.