Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix using arrow functions #36

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,12 @@

const {hasOwnProperty} = Object.prototype;

// `Function#length` should reflect the parameters of `to` not `from` since we keep its body.
// `Function#prototype` is non-writable and non-configurable so can never be modified.
const shouldSkipProperty = property => property === 'length' || property === 'prototype';

const copyProperty = (to, from, property, ignoreNonConfigurable) => {
// `Function#length` should reflect the parameters of `to` not `from` since we keep its body.
// `Function#prototype` is non-writable and non-configurable so can never be modified.
if (property === 'length' || property === 'prototype') {
if (shouldSkipProperty(property)) {
return;
}

Expand Down Expand Up @@ -42,7 +44,7 @@ const changePrototype = (to, from) => {

// If `to` has properties that `from` does not have, remove them
const removeProperty = (to, from, property, ignoreNonConfigurable) => {
if (hasOwnProperty.call(from, property)) {
if (hasOwnProperty.call(from, property) || shouldSkipProperty(property)) {
return;
}

Expand Down
8 changes: 8 additions & 0 deletions test.js
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,14 @@ test('should not copy prototypes', t => {
t.is(wrapper.prototype, prototype);
});

test('should not delete prototypes', t => {
const wrapper = function () {};
const arrowFn = () => {};
mimicFn(wrapper, arrowFn);

t.not(wrapper.prototype, arrowFn.prototype);
});

test('should allow classes to be copied', t => {
class wrapperClass {}
class fooClass {}
Expand Down