pugjs/pug

Alternative syntax for `&attributes`

Open

#1.744 aberto em 20 de nov. de 2014

Ver no GitHub
 (7 comments) (0 reactions) (0 assignees)JavaScript (1.955 forks)batch import
Good First Issue

Métricas do repositório

Stars
 (21.509 stars)
Métricas de merge de PR
 (Nenhuma PRs mesclada em 30d)

Description

I tend to use the &attributes syntax quite often, and think it is kind of verbose. The & token does not seem to be used for anything else right now, so would not it be possible to use an alternative syntax such as

h1.foo(data-a="b")&({'data-b': 'c'})

A small change to the lexer should be sufficient. Modifying attributesBlock as follow works and passes all the tests.

  attributesBlock: function () {
    var captures;
    if (captures = (/^&attributes/.exec(this.input) || /^&/.exec(this.input))) {
      this.consume(captures[0].length);
      var args = this.bracketExpression();
      this.consume(args.end + 1);
      return this.tok('&attributes', args.src);
    }
  }

If you have any interest in this proposition, I'm up for testing this feature and sending a PR.

Thanks.

Guia do colaborador