diff --git a/lib/6to5/to-fast-properties.js b/lib/6to5/to-fast-properties.js new file mode 100644 index 0000000000..341a451d03 --- /dev/null +++ b/lib/6to5/to-fast-properties.js @@ -0,0 +1,14 @@ +/** + * A trick from Bluebird to force V8 to use fast properties for an object. + * Read more: http://stackoverflow.com/questions/24987896/ + * + * Use %HasFastProperties(obj) and --allow-natives-syntax to check whether + * a particular object already has fast properties. + */ +module.exports = function toFastProperties(obj) { + /*jshint -W027*/ + function f() {} + f.prototype = obj; + return f; + eval(obj); +}; diff --git a/lib/6to5/types/index.js b/lib/6to5/types/index.js index 2891d2df82..7984bcfba8 100644 --- a/lib/6to5/types/index.js +++ b/lib/6to5/types/index.js @@ -1,5 +1,6 @@ -var esutils = require("esutils"); -var _ = require("lodash"); +var esutils = require("esutils"); +var _ = require("lodash"); +var toFastProperties = require("../to-fast-properties"); var t = exports; @@ -573,3 +574,5 @@ t.getSpecifierName = function (specifier) { t.isSpecifierDefault = function (specifier) { return t.isIdentifier(specifier.id) && specifier.id.name === "default"; }; + +toFastProperties(t); \ No newline at end of file