diff --git a/buildin/system.js b/buildin/system.js index 3ae0beb3b..9ba70a384 100644 --- a/buildin/system.js +++ b/buildin/system.js @@ -1,3 +1,7 @@ -/* global System */ -// "fix" for users of "System" global -module.exports = typeof System === "undefined" ? {} : System; +// Provide a "System" global. +module.exports = { + // Make sure import is only used as "System.import" + import: function() { + throw new Error("System.import cannot be used indirectly"); + } +}; diff --git a/lib/dependencies/SystemPlugin.js b/lib/dependencies/SystemPlugin.js index d08fc1ae1..08e5fb4c1 100644 --- a/lib/dependencies/SystemPlugin.js +++ b/lib/dependencies/SystemPlugin.js @@ -26,6 +26,8 @@ class SystemPlugin { parser.plugin("typeof System.import", ParserHelpers.toConstantDependency(JSON.stringify("function"))); parser.plugin("evaluate typeof System.import", ParserHelpers.evaluateToString("function")); + parser.plugin("typeof System", ParserHelpers.toConstantDependency(JSON.stringify("object"))); + parser.plugin("evaluate typeof System", ParserHelpers.evaluateToString("object")); setNotSupported("System.set"); setNotSupported("System.get"); diff --git a/test/cases/parsing/issue-2942/index.js b/test/cases/parsing/issue-2942/index.js index 535a79923..f30332b6f 100644 --- a/test/cases/parsing/issue-2942/index.js +++ b/test/cases/parsing/issue-2942/index.js @@ -1,5 +1,5 @@ it("should polyfill System", function() { - if (typeof System.register === "function") { + if (typeof System === "object" && typeof System.register === "function") { require("fail"); } (typeof System).should.be.eql("object"); diff --git a/test/cases/parsing/typeof/index.js b/test/cases/parsing/typeof/index.js index 8f1a2d14d..15b8edbd5 100644 --- a/test/cases/parsing/typeof/index.js +++ b/test/cases/parsing/typeof/index.js @@ -45,6 +45,7 @@ it("should not parse filtered stuff", function() { if(typeof module === "undefined") module = require("fail"); if(typeof module != "object") module = require("fail"); if(typeof exports == "undefined") exports = require("fail"); + if(typeof System !== "object") exports = require("fail"); if(typeof System.import !== "function") exports = require("fail"); if(typeof require.include !== "function") require.include("fail"); if(typeof require.ensure !== "function") require.ensure(["fail"], function(){});