@babel/helper-plugin-utils
Advanced tools
Comparing version 7.0.0-beta.41 to 7.0.0-beta.42
@@ -9,3 +9,3 @@ "use strict"; | ||
if (!api.assertVersion) { | ||
api = Object.assign({}, api, { | ||
api = Object.assign(copyApiObject(api), { | ||
assertVersion: function assertVersion(range) { | ||
@@ -21,2 +21,20 @@ throwVersionError(range, api.version); | ||
function copyApiObject(api) { | ||
var proto = null; | ||
if (typeof api.version === "string" && /^7\./.test(api.version)) { | ||
proto = Object.getPrototypeOf(api); | ||
if (proto && (!has(proto, "version") || !has(proto, "transform") || !has(proto, "template") || !has(proto, "types"))) { | ||
proto = null; | ||
} | ||
} | ||
return Object.assign({}, proto, api); | ||
} | ||
function has(obj, key) { | ||
return Object.prototype.hasOwnProperty.call(obj, key); | ||
} | ||
function throwVersionError(range, version) { | ||
@@ -23,0 +41,0 @@ if (typeof range === "number") { |
{ | ||
"name": "@babel/helper-plugin-utils", | ||
"version": "7.0.0-beta.41", | ||
"version": "7.0.0-beta.42", | ||
"description": "General utilities for plugins to use", | ||
@@ -5,0 +5,0 @@ "author": "Logan Smyth <loganfsmyth@gmail.com>", |
@@ -6,3 +6,3 @@ export function declare(builder) { | ||
// versions of Babel 7's beta that didn't have it. | ||
api = Object.assign({}, api, { | ||
api = Object.assign(copyApiObject(api), { | ||
assertVersion(range) { | ||
@@ -18,2 +18,29 @@ throwVersionError(range, api.version); | ||
function copyApiObject(api) { | ||
// Babel >= 7 <= beta.41 passed the API as a new object that had | ||
// babel/core as the prototype. While slightly faster, it also | ||
// means that the Object.assign copy below fails. Rather than | ||
// keep complexity, the Babel 6 behavior has been reverted and this | ||
// normalizes all that for Babel 7. | ||
let proto = null; | ||
if (typeof api.version === "string" && /^7\./.test(api.version)) { | ||
proto = Object.getPrototypeOf(api); | ||
if ( | ||
proto && | ||
(!has(proto, "version") || | ||
!has(proto, "transform") || | ||
!has(proto, "template") || | ||
!has(proto, "types")) | ||
) { | ||
proto = null; | ||
} | ||
} | ||
return Object.assign({}, proto, api); | ||
} | ||
function has(obj, key) { | ||
return Object.prototype.hasOwnProperty.call(obj, key); | ||
} | ||
function throwVersionError(range, version) { | ||
@@ -20,0 +47,0 @@ if (typeof range === "number") { |
6515
139