ramasilveyra / unreact

Convert React Components to EJS or Pug [Alpha][Unreleased]
MIT License
14 stars 3 forks source link

ejs attributes expressions of vars with methods #2

Closed ramasilveyra closed 6 years ago

ramasilveyra commented 6 years ago

Bug:

<button<% if (![null,undefined].includes(conn.toLowerCase())) { %> data-provider="<%= conn.toLowerCase() %>"<% } %> 

Expected:

<button<% if (![null,undefined].includes(conn) { %> data-provider="<%= conn.toLowerCase() %>"<% } %> 
ramasilveyra commented 6 years ago

This is wrong. I was making the assumption that conn is a string. It can be the instance of a class like (conn.toLowerCase() can return undefined):

class Something {
  constructor(something) {
    this.something = something;
  }

  toLowerCase() {
    if (this.something) {
      return this.something.toLowerCase();
    }
    return undefined;
  }
}

Also React just throws if conn is not defined, and we are doing the same.