Skip to content
This repository has been archived by the owner on Jul 13, 2020. It is now read-only.

Commit

Permalink
polyfill handling
Browse files Browse the repository at this point in the history
  • Loading branch information
guybedford committed May 15, 2015
1 parent a0ee0f4 commit 80c2119
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 9 deletions.
2 changes: 0 additions & 2 deletions Gruntfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ module.exports = function (grunt) {
dist: {
files: {
'dist/<%= pkg.name %>.src.js': [
'node_modules/when/es6-shim/Promise.js',
'src/wrapper-start.js',
'src/loader.js',
'src/dynamic-only.js',
Expand All @@ -32,7 +31,6 @@ module.exports = function (grunt) {
'src/wrapper-end.js'
],
'dist/<%= pkg.name %>-dev.src.js': [
'node_modules/when/es6-shim/Promise.js',
'src/wrapper-start.js',
'src/loader.js',
'src/declarative.js',
Expand Down
7 changes: 4 additions & 3 deletions src/url-polyfill.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// from https://gist.github.com/Yaffle/1088850
function URL(url, baseURL) {
function URLPolyfill(url, baseURL) {
if (typeof url != 'string')
throw new TypeError('URL must be a string');
var m = String(url).replace(/^\s+|\s+$/g, "").match(/^([^:\/?#]+:)?(?:\/\/(?:([^:@\/?#]*)(?::([^:@\/?#]*))?@)?(([^:\/?#]*)(?::(\d*))?))?([^?#]*)(\?[^#]*)?(#[\s\S]*)?/);
Expand All @@ -16,7 +16,7 @@ function URL(url, baseURL) {
var search = m[8] || "";
var hash = m[9] || "";
if (baseURL !== undefined) {
var base = baseURL instanceof URL ? baseURL : new URL(baseURL);
var base = baseURL instanceof URLPolyfill ? baseURL : new URLPolyfill(baseURL);
var flag = protocol === "" && host === "" && username === "";
if (flag && pathname === "" && search === "") {
search = base.search;
Expand Down Expand Up @@ -64,4 +64,5 @@ function URL(url, baseURL) {
this.pathname = pathname;
this.search = search;
this.hash = hash;
}
}
(typeof self != 'undefined' ? self : global).URLPolyfill = URLPolyfill;
2 changes: 1 addition & 1 deletion src/wrapper-end.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,4 @@

__global.System = System;

})(typeof window != 'undefined' ? window : (typeof global != 'undefined' ? global : self));
})(typeof self != 'undefined' ? self : global);
2 changes: 2 additions & 0 deletions src/wrapper-start.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,3 +55,5 @@
throw addToError(e, 'Evaluating ' + debugName);
}
}

var URL = __global.URL || URLPolyfill;
6 changes: 3 additions & 3 deletions test/system.normalize.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,11 +47,11 @@ describe('System', function () {

describe('when having two arguments', function () {

var refererAddress = '/dir/file';
var refererAddress = 'http://parent.com/dir/file';

it('should normalize relative paths against the parent address', function () {
expect(System.normalize('./d/e/f', null, refererAddress)).to.equal('/dir/d/e/f');
expect(System.normalize('../e/f', null, refererAddress)).to.equal('/e/f');
expect(System.normalize('./d/e/f', null, refererAddress)).to.equal('http://parent.com/dir/d/e/f');
expect(System.normalize('../e/f', null, refererAddress)).to.equal('http://parent.com/e/f');
});

});
Expand Down

0 comments on commit 80c2119

Please sign in to comment.