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

Commit e4676b1

Browse files
committed
Polyfill document.currentScript as document._currentScript.
1 parent 79fec83 commit e4676b1

2 files changed

Lines changed: 15 additions & 0 deletions

File tree

src/HTMLImports.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -441,6 +441,19 @@ xhr = xhr || {
441441

442442
var forEach = Array.prototype.forEach.call.bind(Array.prototype.forEach);
443443

444+
// expose _currentScript
445+
Object.defineProperty(document, '_currentScript', {
446+
get: function() {
447+
return HTMLImports.currentScript || document.currentScript;
448+
},
449+
set: function(script) {
450+
HTMLImports.currentScript = script;
451+
},
452+
writeable: true,
453+
configurable: true
454+
});
455+
456+
444457
// exports
445458

446459
scope.path = path;

src/Parser.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,9 @@ var importParser = {
8383
// source map hint
8484
code += "\n//# sourceURL=" + moniker + "\n";
8585
// evaluate the code
86+
scope.currentScript = scriptElt;
8687
eval.call(window, code);
88+
scope.currentScript = null;
8789
}
8890
}
8991
}

0 commit comments

Comments
 (0)