From b2ab0dbedced957140622702cd66e58766e01616 Mon Sep 17 00:00:00 2001 From: Sebastian McKenzie Date: Mon, 10 Nov 2014 08:16:38 +1100 Subject: [PATCH] add self-global template to runtime generation --- lib/6to5/runtime.js | 11 +---------- lib/6to5/templates/self-global.js | 1 + 2 files changed, 2 insertions(+), 10 deletions(-) create mode 100644 lib/6to5/templates/self-global.js diff --git a/lib/6to5/runtime.js b/lib/6to5/runtime.js index 3a2675b3ee..39ac7ba908 100644 --- a/lib/6to5/runtime.js +++ b/lib/6to5/runtime.js @@ -11,16 +11,7 @@ module.exports = function (namespace) { var container = t.functionExpression(null, [], t.blockStatement(body)); var tree = t.program([t.expressionStatement(t.callExpression(container, []))]); - body.push(t.variableDeclaration("var", [ - t.variableDeclarator(t.identifier("self"), t.conditionalExpression( - t.binaryExpression("===", - t.unaryExpression("typeof", t.identifier("global"), true), - t.literal("undefined") - ), - t.identifier("window"), - t.identifier("global")) - ) - ])); + body.push(util.template("self-global", true)); body.push(t.variableDeclaration("var", [ t.variableDeclarator( diff --git a/lib/6to5/templates/self-global.js b/lib/6to5/templates/self-global.js new file mode 100644 index 0000000000..72f256e1f7 --- /dev/null +++ b/lib/6to5/templates/self-global.js @@ -0,0 +1 @@ +var self = typeof global === "undefined" ? window : global;