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!
This commit is contained in:
Tim Sebastian 2017-03-01 00:32:35 +11:00
parent d056ba7d40
commit d2de851b83
4 changed files with 11 additions and 4 deletions

View File

@ -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");
}
};

View File

@ -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");

View File

@ -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");

View File

@ -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(){});