Skip to content

Commit d2de851

Browse files
committed
readd previous checks - refactor System polyfill
use webpacks "own" System polyfill, do not try to access a previously existing one. Instead make sure everything will be "shadowed" by the webpack System. thx @sokra for the help!
1 parent d056ba7 commit d2de851

4 files changed

Lines changed: 11 additions & 4 deletions

File tree

‎buildin/system.js‎

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1-
/* global System */
2-
// "fix" for users of "System" global
3-
module.exports = typeof System === "undefined" ? {} : System;
1+
// Provide a "System" global.
2+
module.exports = {
3+
// Make sure import is only used as "System.import"
4+
import: function() {
5+
throw new Error("System.import cannot be used indirectly");
6+
}
7+
};

‎lib/dependencies/SystemPlugin.js‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@ class SystemPlugin {
2626

2727
parser.plugin("typeof System.import", ParserHelpers.toConstantDependency(JSON.stringify("function")));
2828
parser.plugin("evaluate typeof System.import", ParserHelpers.evaluateToString("function"));
29+
parser.plugin("typeof System", ParserHelpers.toConstantDependency(JSON.stringify("object")));
30+
parser.plugin("evaluate typeof System", ParserHelpers.evaluateToString("object"));
2931

3032
setNotSupported("System.set");
3133
setNotSupported("System.get");

‎test/cases/parsing/issue-2942/index.js‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
it("should polyfill System", function() {
2-
if (typeof System.register === "function") {
2+
if (typeof System === "object" && typeof System.register === "function") {
33
require("fail");
44
}
55
(typeof System).should.be.eql("object");

‎test/cases/parsing/typeof/index.js‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ it("should not parse filtered stuff", function() {
4545
if(typeof module === "undefined") module = require("fail");
4646
if(typeof module != "object") module = require("fail");
4747
if(typeof exports == "undefined") exports = require("fail");
48+
if(typeof System !== "object") exports = require("fail");
4849
if(typeof System.import !== "function") exports = require("fail");
4950
if(typeof require.include !== "function") require.include("fail");
5051
if(typeof require.ensure !== "function") require.ensure(["fail"], function(){});

0 commit comments

Comments
 (0)