Fix IE8 for-in loops using babelHelpers.sanitizeForInObject.

Upgraded meteor-babel to 0.5.4 for sanitizeForInObject support.
This commit is contained in:
Ben Newman
2015-08-03 20:32:17 -04:00
parent 59165b9c4f
commit 5e4ed8eb28
7 changed files with 76 additions and 34 deletions

View File

@@ -1,10 +1,10 @@
{
"dependencies": {
"meteor-babel": {
"version": "0.5.2",
"version": "0.5.4",
"dependencies": {
"babel-core": {
"version": "5.8.3",
"version": "5.8.20",
"dependencies": {
"babel-plugin-constant-folding": {
"version": "1.0.1"
@@ -28,7 +28,7 @@
"version": "1.0.1"
},
"babel-plugin-proto-to-assign": {
"version": "1.0.3"
"version": "1.0.4"
},
"babel-plugin-react-constant-elements": {
"version": "1.0.3"
@@ -57,7 +57,7 @@
"version": "1.1.6"
},
"babylon": {
"version": "5.8.3"
"version": "5.8.20"
},
"bluebird": {
"version": "2.9.34"
@@ -93,7 +93,7 @@
}
},
"core-js": {
"version": "0.9.18"
"version": "1.0.1"
},
"debug": {
"version": "2.2.0",
@@ -166,6 +166,9 @@
"js-tokens": {
"version": "1.0.1"
},
"json5": {
"version": "0.4.0"
},
"line-numbers": {
"version": "0.2.0",
"dependencies": {
@@ -219,7 +222,7 @@
"version": "0.1.6"
},
"regenerator": {
"version": "0.8.34",
"version": "0.8.35",
"dependencies": {
"commoner": {
"version": "0.10.3",
@@ -325,16 +328,13 @@
}
},
"esprima-fb": {
"version": "13001.1.0-dev-harmony-fb"
"version": "15001.1.0-dev-harmony-fb"
},
"recast": {
"version": "0.10.18",
"version": "0.10.24",
"dependencies": {
"esprima-fb": {
"version": "14001.1.0-dev-harmony-fb"
},
"ast-types": {
"version": "0.8.2"
"version": "0.8.5"
}
}
},
@@ -347,13 +347,13 @@
"version": "1.2.0",
"dependencies": {
"recast": {
"version": "0.10.21",
"version": "0.10.26",
"dependencies": {
"esprima-fb": {
"version": "15001.1.0-dev-harmony-fb"
},
"ast-types": {
"version": "0.8.3"
"version": "0.8.7"
}
}
},
@@ -416,14 +416,14 @@
}
}
},
"strip-json-comments": {
"version": "1.0.2"
},
"to-fast-properties": {
"version": "1.0.1"
},
"trim-right": {
"version": "1.0.1"
},
"try-resolve": {
"version": "1.0.1"
}
}
},

View File

@@ -11,7 +11,9 @@ function getDefaultOptions(extraFeatures) {
// Modify options to enable async/await syntax powered by Fibers.
meteorAsyncAwait: Match.Optional(Boolean),
// Modify options to enable React/JSX syntax.
react: Match.Optional(Boolean)
react: Match.Optional(Boolean),
// Improve compatibility in older versions of Internet Explorer.
jscript: Match.Optional(Boolean)
});
}

View File

@@ -3,11 +3,11 @@ Package.describe({
summary: "Parser/transpiler for ECMAScript 2015+ syntax",
// Tracks the npm version below. Use wrap numbers to increment
// without incrementing the npm version.
version: '5.8.3-plugins.0_5'
version: '5.8.20-plugins.0'
});
Npm.depends({
'meteor-babel': '0.5.2'
'meteor-babel': '0.5.4'
});
Package.onUse(function (api) {

View File

@@ -1,8 +1,50 @@
var hasOwn = Object.prototype.hasOwnProperty;
function canDefineNonEnumerableProperties() {
var testObj = {};
var testPropName = "t";
try {
Object.defineProperty(testObj, testPropName, {
enumerable: false,
value: testObj
});
for (var k in testObj) {
if (k === testPropName) {
return false;
}
}
} catch (e) {
return false;
}
return testObj[testPropName] === testObj;
}
// The name `babelHelpers` is hard-coded in Babel. Otherwise we would make it
// something capitalized and more descriptive, like `BabelRuntime`.
babelHelpers = {
// Meteor-specific runtime helper for wrapping the object of for-in
// loops, so that inherited Array methods defined by es5-shim can be
// ignored in browsers where they cannot be defined as non-enumerable.
sanitizeForInObject: canDefineNonEnumerableProperties()
? function (value) { return value; }
: function (obj) {
if (Array.isArray(obj)) {
var newObj = {};
var keys = Object.keys(obj);
var keyCount = keys.length;
for (var i = 0; i < keyCount; ++i) {
var key = keys[i];
newObj[key] = obj[key];
}
return newObj;
}
return obj;
},
// es6.templateLiterals
// Constructs the object passed to the tag function in a tagged
// template literal.

View File

@@ -1,7 +1,7 @@
Package.describe({
name: "babel-runtime",
summary: "Runtime support for output of Babel transpiler",
version: '0.1.2',
version: '0.1.3',
documentation: 'README.md'
});

View File

@@ -1,6 +1,6 @@
Package.describe({
name: 'ecmascript',
version: '0.1.3-plugins.1',
version: '0.1.3-plugins.2',
summary: 'Compiler plugin that supports ES2015+ in all .js files',
documentation: 'README.md'
});
@@ -13,7 +13,7 @@ Package.registerBuildPlugin({
Package.onUse(function (api) {
api.use('isobuild:compiler-plugin@1.0.0');
api.imply('babel-runtime@0.1.2');
api.imply('babel-runtime@0.1.3');
api.imply('promise@0.4.1');
});

View File

@@ -18,23 +18,21 @@ BCp.processFilesForTarget = function (inputFiles) {
};
if (fileOptions.transpile !== false) {
var babelOptions = Babel.getDefaultOptions();
var targetCouldBeInternetExplorer8 =
inputFile.getArch() === "web.browser";
var babelOptions = Babel.getDefaultOptions({
// Perform some additional transformations to improve
// compatibility in older browsers (e.g. wrapping named function
// expressions, per http://kiro.me/blog/nfe_dilemma.html).
jscript: targetCouldBeInternetExplorer8
});
babelOptions.sourceMap = true;
babelOptions.filename = inputFilePath;
babelOptions.sourceFileName = "/" + inputFilePath;
babelOptions.sourceMapName = "/" + outputFilePath + ".map";
var targetCouldBeInternetExplorer8 =
inputFile.getArch() === "web.browser";
if (targetCouldBeInternetExplorer8) {
// Perform some additional transformations to improve
// compatibility in older browsers (e.g. wrapping named function
// expressions, per http://kiro.me/blog/nfe_dilemma.html).
babelOptions.whitelist.push("jscript");
}
try {
var result = Babel.compile(source, babelOptions);
} catch (e) {