Skip to content

Commit

Permalink
readd previous checks - refactor System polyfill
Browse files Browse the repository at this point in the history
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!
  • Loading branch information
timse committed Feb 28, 2017
1 parent d056ba7 commit d2de851
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 4 deletions.
10 changes: 7 additions & 3 deletions buildin/system.js
Original file line number Diff line number Diff line change
@@ -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");
}
};
2 changes: 2 additions & 0 deletions lib/dependencies/SystemPlugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down
2 changes: 1 addition & 1 deletion test/cases/parsing/issue-2942/index.js
Original file line number Diff line number Diff line change
@@ -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");
Expand Down
1 change: 1 addition & 0 deletions test/cases/parsing/typeof/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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(){});
Expand Down

0 comments on commit d2de851

Please sign in to comment.