Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: invalid display of source files in Chrome DevTool and Firefox de… #32

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Fix: invalid display of source files in Chrome DevTool and Firefox de…
…bugger because of sourceURL format
MS-elug committed Mar 6, 2018
commit 88df1df45cd8774c3656f5f4a27380453b6d882c
64 changes: 64 additions & 0 deletions spec/browser/sourceURL.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
var SourceURL = require('../../src/browser-modules/sourceURL.js');
var expect = global.expect ? global.expect : require("expect.js");

describe("SourceURL", function() {
it('should generate sourceURL Basic', function() {
var src = "util/json";
var location = {
protocol: "http:",
hostname: "test.aria.com"
};
var sourceURL = SourceURL.generateSourceURL(location, src);
expect(sourceURL).to.equal('http://test.aria.com/util/json');
});

it('should generate sourceURL Relative', function() {
var src = "./util/json";
var location = {
protocol: "http:",
pathname: "/dist",
hostname: "test.aria.com"
};
var sourceURL = SourceURL.generateSourceURL(location, src);
expect(sourceURL).to.equal('http://test.aria.com/dist/util/json');
});

it('should generate sourceURL Absolute', function() {
var src = "/util/json";
var location = {
protocol: "http:",
hostname: "test.aria.com"
};
var sourceURL = SourceURL.generateSourceURL(location, src);
expect(sourceURL).to.equal('http://test.aria.com/util/json');
});

it('should generate sourceURL With URL', function() {
var src = "http://test.aria.com/util/json";
var location = {
protocol: "http:",
pathname: "/dist",
hostname: "test.aria.com"
};
var sourceURL = SourceURL.generateSourceURL(location, src);
expect(sourceURL).to.equal('http://test.aria.com/util/json');
});

it('should generate sourceURL With Scheme', function() {
var src = "aria://util/json";
var location = {
protocol: "http:",
pathname: "/dist",
hostname: "test.aria.com"
};
var sourceURL = SourceURL.generateSourceURL(location, src);
expect(sourceURL).to.equal('aria://util/json');
});

it('should generate sourceURL NoLocation', function() {
var src = "util/json";
var sourceURL = SourceURL.generateSourceURL(undefined, src);
expect(sourceURL).to.equal('util/json');
});

});
4 changes: 3 additions & 1 deletion src/browser-modules/eval.js
Original file line number Diff line number Diff line change
@@ -12,12 +12,14 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
var location = global.location;
var SourceURL = require("../sourceURL.js");

module.exports = function(code, fileName) {
var res = {};
// Using the 'arguments[1].res = ...' trick because IE does not let eval return a function
if (fileName) {
code = ['/*\n * File: ', fileName, '\n */\narguments[1].res=', code, '\n//# sourceURL=', fileName].join('');
code = ['/*\n * File: ', fileName, '\n */\narguments[1].res=', code, '\n//# sourceURL=', SourceURL.generateSourceURL(location, fileName)].join('');
} else {
code = 'arguments[1].res=' + code;
}
33 changes: 33 additions & 0 deletions src/browser-modules/sourceURL.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
/*
* Copyright 2012 Amadeus s.a.s.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
module.exports = {
generateSourceURL: function(location, src) {
var sourceURL = src;
// Check if src match a an URL
if (typeof src === "string" && location && !(/[a-z]*:\/\//.test(src))) {
sourceURL = location.protocol + "//" + location.hostname;

if (src.length > 0 && src[0] === "/") {
sourceURL += src;
} else if (src.length > 1 && src[0] === "." && src[1] === "/") {
sourceURL += location.pathname + src.substring(1);
} else {
sourceURL += "/" + src;
}
}

return sourceURL;
}
};