Skip to content

Square brackets are not included in attribute key #200

@dagi12

Description

@dagi12

Square brackets are not included in attribute key. When trying to access below

<input [(ngModel)]="foo">

Attribute key is parsed as (ngmodel) same goes for output from outerHTML
I'm trying to parse and refactor some angular templates. I'm unable to do that with parser working like that.

I think problem lies in below regular expression

 /**
   * Get escaped (as-is) attributes
   * @return {Object} parsed attributes
   */
  get: function () {
    if (this._rawAttrs) {
      return this._rawAttrs;
    }

    var attrs = {};

    if (this.rawAttrs) {
      var re = /([a-zA-Z()#][a-zA-Z0-9-_:()#]*)(?:\s*=\s*((?:'[^']*')|(?:"[^"]*")|\S+))?/g;
      var match = void 0;

      while (match = re.exec(this.rawAttrs)) {
        var key = match[1];
        var val = match[2] || null;
        if (val && (val[0] === "'" || val[0] === "\"")) val = val.slice(1, val.length - 1);
        attrs[key] = val;
      }
    }

    this._rawAttrs = attrs;
    return attrs;
  }

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions