Skip to content
This repository has been archived by the owner on Mar 3, 2023. It is now read-only.

Constructor serialization #27

Open
wizzard0 opened this issue Nov 1, 2016 · 0 comments
Open

Constructor serialization #27

wizzard0 opened this issue Nov 1, 2016 · 0 comments

Comments

@wizzard0
Copy link
Contributor

wizzard0 commented Nov 1, 2016

Serializing constructor like this:

  var generate = require('escodegen').generate
  var lave = require('lave')
  var fs = require('fs')

    function Greeter(message) {
        this.greeting = message;
    }
    Greeter.prototype.greet = function () {
        return "Hello, " + this.greeting;
    };
var greeter = new Greeter("world");
  var js = lave(greeter, {generate, format: 'module'})
console.log(js);

outputs

var a = {
        'constructor': function Greeter(message) {
        this.greeting = message;
    },
        'greet': function () {
        return "Hello, " + this.greeting;
    }
    }, b = Object.create(a);
function Greeter(message) {
        this.greeting = message;
    }.prototype = a;
b.greeting = 'world';
export default b;

instead of something like

var a = {
        'constructor': function Greeter(message) {
        this.greeting = message;
    },
        'greet': function () {
        return "Hello, " + this.greeting;
    }
    }, b = Object.create(a);
function Greeter(message) {
        this.greeting = message;
    };
Greeter.prototype = a;
b.greeting = 'world';
export default b;

which results in

    }.prototype = a;
     ^
SyntaxError: Unexpected token .
    at Object.exports.runInThisContext (vm.js:76:16)
    at Module._compile (module.js:542:28)
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant