davidbonnet / astring

🌳 Tiny and fast JavaScript code generator from an ESTree-compliant AST.

Home Page:https://david.bonnet.cc/astring/demo/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Fails to generate SpreadOperator

nchanged opened this issue · comments

Motivation

Generated AST code with acorn from this source

var target = {foo : "bar"}
target = {...target, ...{}};

fails

Property: function Property(node, state) {
      
      if (node.method || node.kind[0] !== 'i') {
        // Either a method or of kind `set` or `get` (not `init`)
        this.MethodDefinition(node, state);
      } else {

with node.kind being undefined. I guess it should have never got in there.

Thanks!

UPD.

kind of fixed it with the following, but I am 99% percent sure that it's NOT the right place

Property: function Property(node, state) {
      if ( node.type === "SpreadElement"){
         this.RestElement(node, state)
      } else {
        if (node.method || node.kind[0] !== 'i') {
          // Either a method or of kind `set` or `get` (not `init`)
          this.MethodDefinition(node, state);
        } else {
          if (!node.shorthand) {
            if (node.computed) {
              state.write('[');
              this[node.key.type](node.key, state);
              state.write(']');
            } else {
              this[node.key.type](node.key, state);
            }
            state.write(': ');
          }
          this[node.value.type](node.value, state);
        }
      }
    }

Fixed, thanks for reporting this.

Thanks!! I was losing hope already! I am planning to use it with fuse-box (a bundler) hopefully it will all work since I am expecting a lot of new users after v4 is released :)