Make babelHelpers.inherits even more robust against PhantomJS bugs.

This commit is contained in:
Ben Newman
2015-12-04 12:12:19 -05:00
parent ff64b73253
commit 263c45b919

View File

@@ -117,21 +117,21 @@ babelHelpers = {
// using babel-runtime is almost certainly using it because of the
// ecmascript package, which also implies ecmascript-runtime.
Object.getOwnPropertyNames(superClass).forEach(function (k) {
if (Object.getOwnPropertyDescriptor(subClass, k)) {
// If subClass already has a property by this name, then it
// would not be inherited, so it should not be copied. This
// notably excludes properties like .prototype and .name.
return;
}
// This property descriptor dance preserves getter/setter behavior
// in browsers that support accessor properties (all except
// IE8). In IE8, the superClass can't have accessor properties
// anyway, so this code is still safe.
Object.defineProperty(
subClass, k,
Object.getOwnPropertyDescriptor(superClass, k)
);
var descriptor = Object.getOwnPropertyDescriptor(superClass, k);
if (descriptor && typeof descriptor === "object") {
if (Object.getOwnPropertyDescriptor(subClass, k)) {
// If subClass already has a property by this name, then it
// would not be inherited, so it should not be copied. This
// notably excludes properties like .prototype and .name.
return;
}
Object.defineProperty(subClass, k, descriptor);
}
});
}
},