lukeed / klona

A tiny (240B to 501B) and fast utility to "deep clone" Objects, Arrays, Dates, RegExps, and more!
MIT License
1.62k stars 43 forks source link

klona/full seems discarding prototype properties from class #24

Closed otakustay closed 4 years ago

otakustay commented 4 years ago
const clone = require('clone');
const {klona} = require('klona');
const {klona: klonaFull} = require('klona/full');

function MyPlugin() {
}

MyPlugin.prototype = {
    install: function() {
        console.log('install');
    }
}

const options = {
    plugin: new MyPlugin(),
};

console.log('oringinal', options.plugin.install);
console.log('clone', clone(options).plugin.install);
console.log('klona', klona(options).plugin.install);
console.log('klona/full', klonaFull(options).plugin.install);

Output:

oringinal [Function: install]
clone [Function: install]
klona [Function: install]
klona/full undefined

Wondering its a bug or is by design, this issue makes less-loader lost less plugin methods.

lukeed commented 4 years ago

Hey, thanks for this. Good catch!

Started looking at this tonight and will hopefully have it done tomorrow. The fix is easy but trying to prevent much performance degradation

lukeed commented 4 years ago

If you're around, I'd appreciate it if you could check out the klona/full changes and verify that it works for you before I publish a new version. I think it covers this issue, but doesn't hurt to verify :D

Thanks!

otakustay commented 4 years ago

Worked in my case (less-loader with less-plugin-functions), great!

lukeed commented 4 years ago

Cool, publishing now then