Skip to content

Commit

Permalink
fix(systemjs-angular-loader): replace w/ version that works in IE
Browse files Browse the repository at this point in the history
  • Loading branch information
wardbell committed Mar 24, 2017
1 parent e7fd753 commit 456b849
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 6 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@ Upgraders: for a fresh start, consider running these commands
* `git clean -xdf`
* `npm install`

<a name="0.4.1"></a>
# 0.4.1 (2017-03-24)
* Replace systemjs-angular-loader with version that works for IE

<a name="0.4.0"></a>
# 0.4.0 (2017-03-24)
* Update to Angular 4.0.0
Expand Down
14 changes: 8 additions & 6 deletions src/systemjs-angular-loader.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,17 @@ var stylesRegex = /styleUrls *:(\s*\[[^\]]*?\])/g;
var stringRegex = /(['`"])((?:[^\\]\\\1|.)*?)\1/g;

module.exports.translate = function(load){

var url = new URL(load.address);
var url = document.createElement('a');
url.href = load.address;

var basePathParts = url.pathname.split('/');

basePathParts.pop();
var basePath = basePathParts.join('/');

var baseHref = new URL(this.baseURL).pathname;
var baseHref = document.createElement('a');
baseHref.href = this.baseURL;
baseHref = baseHref.pathname;

basePath = basePath.replace(baseHref, '');

Expand All @@ -23,16 +25,16 @@ module.exports.translate = function(load){
resolvedUrl = basePath + url.substr(1);
}

return `templateUrl: '${resolvedUrl}'`;
return 'templateUrl: "' + resolvedUrl + '"';
})
.replace(stylesRegex, function(match, relativeUrls) {
var urls = [];

while ((match = stringRegex.exec(relativeUrls)) !== null) {
if (match[2].startsWith('.')) {
urls.push(`'${basePath}${match[2].substr(1)}'`);
urls.push('"' + basePath + match[2].substr(1) + '"');
} else {
urls.push(`'${match[2]}'`);
urls.push('"' + match[2] + '"');
}
}

Expand Down

0 comments on commit 456b849

Please sign in to comment.