janl / mustache.js

Minimal templating with {{mustaches}} in JavaScript
https://mustache.github.io
MIT License
16.47k stars 2.39k forks source link

Problem with getter/setter accessors generated from TypeScript #445

Closed wgebczyk closed 9 years ago

wgebczyk commented 9 years ago

For below HTML file, the alert output is: "[0;00]||[1;][3;]". Expected is: "[0;00]||[1;2][3;4]"

The problem lies in lines 383 & 388. The hasOwnProperty does not returns true. If additionally we could check proto.hasOwnProperty, then this should work fine.

The HTML

<!DOCTYPE html>
<html>
<head>
  <title>aaa</title>
  <script src="res/mustache.js"></script>
  <script>
    /* TypeScript src
      interface IAaa {
        x: string;
        y: string;
      }

      class Aaa implements IAaa {
        public x: string;
        private _y: string;

        constructor(x: string, y: string) {
          this.x = x;
          this._y = y;
        }

        get y(): string { return this._y; }
        set y(value: string) { this._y = value; }
      }

      class Bbb {
        item: IAaa;
        items: IAaa[];
      }
    */
    var Aaa = (function () {
      function Aaa(x, y) {
        this.x = x;
        this._y = y;
      }
      Object.defineProperty(Aaa.prototype, "y", {
        get: function () {
          return this._y;
        },
        set: function (value) {
          this._y = value;
        },
        enumerable: true,
        configurable: true
      });
      return Aaa;
    })();
    var Bbb = (function () {
      function Bbb() {
      }
      return Bbb;
    })();
  </script>
</head>
<body>
  <script>
    var b = new Bbb();
    b.item = new Aaa("0", "00");
    b.items = [];
    b.items.push({ a: new Aaa("1", "2") });
    b.items.push({ a: new Aaa("3", "4") });
    var output = Mustache.render('[{{ item.x }};{{ item.y }}]||{{#items}}[{{ a.x }};{{ a.y }}]{{/items}}', b);
    alert(output);
  </script>
</body>
</html>
dasilvacontin commented 9 years ago

I confirm this bug.

phillipj commented 9 years ago

Thanks! I'm investigating some prototype issues in the reported firefox issue also. I'll take this into consideration aswell On lør. 9. mai 2015 at 16.38 David da Silva Contín notifications@github.com wrote:

I confirm this bug.

— Reply to this email directly or view it on GitHub https://github.com/janl/mustache.js/issues/445#issuecomment-100497952.

wgebczyk commented 9 years ago

tx!