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

Commit 2ff7c37

Browse files
committed
fully deprecate baseURL
1 parent 4abd53b commit 2ff7c37

File tree

8 files changed

+88
-68
lines changed

8 files changed

+88
-68
lines changed

src/system-resolve.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,10 @@ SystemLoader.prototype.normalize = function(name, parentName, parentAddress) {
1010

1111
// not absolute or relative -> apply paths (what will be sites)
1212
if (!name.match(absURLRegEx) && name[0] != '.')
13-
name = new URL(applyPaths(this, name), this.baseURL).href;
13+
name = new URL(applyPaths(this, name), baseURI).href;
1414
// apply parent-relative normalization, parentAddress is already normalized
1515
else
16-
name = new URL(name, parentAddress || this.baseURL).href;
16+
name = new URL(name, parentName || baseURI).href;
1717

1818
return name;
1919
};

src/system.js

Lines changed: 0 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -14,34 +14,6 @@ var System;
1414

1515
function SystemLoader() {
1616
Loader.call(this);
17-
18-
var baseURI;
19-
// environent baseURI detection
20-
if (typeof document != 'undefined' && document.getElementsByTagName) {
21-
baseURI = document.baseURI;
22-
23-
if (!baseURI) {
24-
var bases = document.getElementsByTagName('base');
25-
baseURI = bases[0] && bases[0].href || window.location.href;
26-
}
27-
28-
// sanitize out the hash and querystring
29-
baseURI = baseURI.split('#')[0].split('?')[0];
30-
baseURI = baseURI.substr(0, baseURI.lastIndexOf('/') + 1);
31-
}
32-
else if (typeof process != 'undefined' && process.cwd) {
33-
baseURI = 'file://' + (isWindows ? '/' : '') + process.cwd() + '/';
34-
if (isWindows)
35-
baseURI = baseURI.replace(/\\/g, '/');
36-
}
37-
else if (typeof location != 'undefined') {
38-
baseURI = __global.location.href;
39-
}
40-
else {
41-
throw new TypeError('No environment baseURI');
42-
}
43-
44-
this.baseURL = baseURI;
4517
this.paths = {};
4618
}
4719

src/wrapper-start.js

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,4 +56,30 @@
5656
}
5757
}
5858

59+
var baseURI;
60+
// environent baseURI detection
61+
if (typeof document != 'undefined' && document.getElementsByTagName) {
62+
baseURI = document.baseURI;
63+
64+
if (!baseURI) {
65+
var bases = document.getElementsByTagName('base');
66+
baseURI = bases[0] && bases[0].href || window.location.href;
67+
}
68+
69+
// sanitize out the hash and querystring
70+
baseURI = baseURI.split('#')[0].split('?')[0];
71+
baseURI = baseURI.substr(0, baseURI.lastIndexOf('/') + 1);
72+
}
73+
else if (typeof process != 'undefined' && process.cwd) {
74+
baseURI = 'file://' + (isWindows ? '/' : '') + process.cwd() + '/';
75+
if (isWindows)
76+
baseURI = baseURI.replace(/\\/g, '/');
77+
}
78+
else if (typeof location != 'undefined') {
79+
baseURI = __global.location.href;
80+
}
81+
else {
82+
throw new TypeError('No environment baseURI');
83+
}
84+
5985
var URL = __global.URL || URLPolyfill;

test/_browser.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11

2-
// Change base url to the karma "base"
3-
System.baseURL += 'base/';
2+
System.paths['*'] = 'base/*';
3+
baseURL += 'base/';
44

55
System.paths.traceur = 'node_modules/traceur/bin/traceur.js';
66
System.paths.babel = 'node_modules/babel-core/browser.js';

test/_helper.js

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,39 @@
77
__global.console = { log : __global.dump || function (){} };
88
}
99

10+
var isWindows = typeof process != 'undefined' && process.platform.match(/^win/);
11+
12+
var baseURI;
13+
// environent baseURI detection
14+
if (typeof document != 'undefined' && document.getElementsByTagName) {
15+
baseURI = document.baseURI;
16+
17+
if (!baseURI) {
18+
var bases = document.getElementsByTagName('base');
19+
baseURI = bases[0] && bases[0].href || window.location.href;
20+
}
21+
22+
// sanitize out the hash and querystring
23+
baseURI = baseURI.split('#')[0].split('?')[0];
24+
baseURI = baseURI.substr(0, baseURI.lastIndexOf('/') + 1);
25+
}
26+
else if (typeof process != 'undefined' && process.cwd) {
27+
baseURI = 'file://' + (isWindows ? '/' : '') + process.cwd() + '/';
28+
if (isWindows)
29+
baseURI = baseURI.replace(/\\/g, '/');
30+
}
31+
else if (typeof location != 'undefined') {
32+
baseURI = __global.location.href;
33+
}
34+
else {
35+
throw new TypeError('No environment baseURI');
36+
}
37+
38+
// baseURI - the current path, for standard relative normalization (./x)
39+
__global.baseURI = baseURI;
40+
41+
// baseURL - the base path, for plain relative normalization (x)
42+
__global.baseURL = baseURI;
1043

1144
/**
1245
* Describe a block if the bool is true.

test/custom-loader.spec.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ describe('Custom Loader', function () {
3939
function supposeToFail() {
4040
expect(false, 'should not be successful').to.be.ok();
4141
}
42-
var base = System.baseURL + 'test/loader/';
42+
var base = baseURL + 'test/loader/';
4343

4444
it('should make the normalize throw', function (done) {
4545
customLoader.import('test/loader/error1-parent.js')

test/system.normalize.spec.js

Lines changed: 16 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -3,20 +3,6 @@
33
describe('System', function () {
44
describe('#normalize', function () {
55

6-
// Normalize tests - identical to https://github.com/google/traceur-compiler/blob/master/test/unit/runtime/System.js
7-
8-
var originalBaseUrl = System.baseURL;
9-
10-
var dummyBase = 'http://example.org/';
11-
12-
beforeEach(function () {
13-
System.baseURL = dummyBase + 'a/b.html';
14-
});
15-
16-
afterEach(function () {
17-
System.baseURL = originalBaseUrl;
18-
});
19-
206
describe('when having no argument', function () {
217

228
it('should throw with no specified name', function () {
@@ -28,19 +14,28 @@ describe('System', function () {
2814
describe('when having one argument', function () {
2915

3016
it('should allow no referer', function () {
31-
expect(System.normalize('d/e/f')).to.equal(dummyBase + 'a/d/e/f');
17+
expect(System.normalize('d/e/f')).to.equal(baseURL + 'd/e/f');
3218
});
3319

20+
var backTrack
21+
// in the browser, double backtracking goes below the hostname -> just keep at hostname
22+
if (typeof window != 'undefined')
23+
backTrack = baseURI.substr(0, baseURI.length - 1);
24+
else
25+
backTrack = baseURI.split('/').splice(0, baseURI.split('/').length - 2).join('/')
26+
27+
if (typeof window != 'undefined')
28+
3429
it('should backtracking below baseURL', function () {
35-
expect(System.normalize('../e/f')).to.equal('http://example.org/e/f');
30+
expect(System.normalize('../e/f')).to.equal(backTrack + '/e/f');
3631
});
3732

3833
it('should double dotted backtracking', function () {
39-
expect(System.normalize('./../a.js')).to.equal(dummyBase + 'a.js');
34+
expect(System.normalize('./../a.js')).to.equal(backTrack + '/a.js');
4035
});
4136

4237
it('should normalize ./ and plain names to the same base', function () {
43-
expect(System.normalize('./a.js')).to.equal(dummyBase + 'a/a.js');
38+
expect(System.normalize('./a.js')).to.equal(baseURI + 'a.js');
4439
});
4540

4641
});
@@ -49,9 +44,9 @@ describe('System', function () {
4944

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

52-
it('should normalize relative paths against the parent address', function () {
53-
expect(System.normalize('./d/e/f', null, refererAddress)).to.equal('http://parent.com/dir/d/e/f');
54-
expect(System.normalize('../e/f', null, refererAddress)).to.equal('http://parent.com/e/f');
47+
it('should normalize relative paths against the parent name', function () {
48+
expect(System.normalize('./d/e/f', refererAddress)).to.equal('http://parent.com/dir/d/e/f');
49+
expect(System.normalize('../e/f', refererAddress)).to.equal('http://parent.com/e/f');
5550
});
5651

5752
});

test/system.spec.js

Lines changed: 8 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,6 @@ var ie = typeof window != 'undefined' && window.navigator.userAgent.match(/Tride
77

88
describe('System', function () {
99

10-
var originBaseUrl = System.baseURL;
11-
12-
afterEach(function () {
13-
System.baseURL = originBaseUrl;
14-
});
15-
1610
describe('prerequisite', function () {
1711

1812
it('should be a instance of Loader', function () {
@@ -50,7 +44,7 @@ describe('System', function () {
5044

5145
it('should support set, get and delete', function(done) {
5246

53-
var testPath = System.baseURL + 'test/loader/module.js';
47+
var testPath = baseURL + 'test/loader/module.js';
5448

5549
System.import(testPath).then(function(m) {
5650
expect(m.run).to.equal('first');
@@ -217,7 +211,7 @@ describe('System', function () {
217211
.then(supposedToFail)
218212
.catch(function (e) {
219213
expect(e)
220-
.to.be.equal('dep error\n\tError evaluating ' + System.baseURL + 'test/loads/deperror.js');
214+
.to.be.equal('dep error\n\tError evaluating ' + baseURL + 'test/loads/deperror.js');
221215
})
222216
.then(done, done);
223217
});
@@ -352,7 +346,7 @@ describe('System', function () {
352346
System.import('test/loader/moduleName.js')
353347
.then(function (m) {
354348
expect(m.name).to.be.equal(m.address);
355-
expect(m.address).to.be.equal(System.baseURL + 'test/loader/moduleName.js');
349+
expect(m.address).to.be.equal(baseURL + 'test/loader/moduleName.js');
356350
})
357351
.then(done, done);
358352
});
@@ -363,7 +357,7 @@ describe('System', function () {
363357
describe('#paths', function () {
364358

365359
it('should support custom paths', function (done) {
366-
System.paths['bar'] = 'test/loader/custom-path.js';
360+
System.paths['bar'] = baseURL + 'test/loader/custom-path.js';
367361
System.import('bar')
368362
.then(function (m) {
369363
expect(m.bar).to.be.equal('bar');
@@ -374,7 +368,7 @@ describe('System', function () {
374368

375369

376370
it('should support path wildcard', function (done) {
377-
System.paths['bar/*'] = 'test/loader/custom-folder/*.js';
371+
System.paths['bar/*'] = baseURL + 'test/loader/custom-folder/*.js';
378372
System.import('bar/path')
379373
.then(function (m) {
380374
expect(m.bar).to.be.equal('baa');
@@ -384,8 +378,8 @@ describe('System', function () {
384378
});
385379

386380
it('should support most specific paths', function (done) {
387-
System.paths['bar/bar'] = 'test/loader/specific-path.js';
388-
System.paths['bar/*'] = 'test/loader/custom-folder/*.js';
381+
System.paths['bar/bar'] = baseURL + 'test/loader/specific-path.js';
382+
System.paths['bar/*'] = baseURL + 'test/loader/custom-folder/*.js';
389383
System.import('bar/bar')
390384
.then(function (m) {
391385
expect(m.path).to.be.ok();
@@ -431,7 +425,7 @@ describe('System', function () {
431425
typeof window != 'undefined' && window.Worker,
432426
'with Web Worker', function () {
433427
(ie ? it.skip : it)('should loading inside of a Web Worker', function (done) {
434-
var worker = new Worker(System.baseURL + 'test/worker/worker-' + System.transpiler + '.js');
428+
var worker = new Worker(baseURL + 'test/worker/worker-' + System.transpiler + '.js');
435429

436430
worker.onmessage = function (e) {
437431
expect(e.data).to.be.equal('p');

0 commit comments

Comments
 (0)