diff options
author | kpdecker <kpdecker@gmail.com> | 2015-01-18 17:27:27 -0600 |
---|---|---|
committer | kpdecker <kpdecker@gmail.com> | 2015-01-18 17:27:27 -0600 |
commit | 884bf1553663734f22ffcd9d758c9d71d4373bf9 (patch) | |
tree | 55d078077b9c23779858282dfe42dd3a42bd7c0d /src | |
parent | 999da739a66199483ffc4d82426550aee5ac798f (diff) | |
download | handlebars.js-884bf1553663734f22ffcd9d758c9d71d4373bf9.zip handlebars.js-884bf1553663734f22ffcd9d758c9d71d4373bf9.tar.gz handlebars.js-884bf1553663734f22ffcd9d758c9d71d4373bf9.tar.bz2 |
Avoid direct references to sexpr in statements
This allows us to avoid creating unnecessary AST nodes and avoids things like isHelper.
Side effect of these changes is that @data functions can now have data parameters passed to them.
Diffstat (limited to 'src')
-rw-r--r-- | src/handlebars.yy | 37 |
1 files changed, 18 insertions, 19 deletions
diff --git a/src/handlebars.yy b/src/handlebars.yy index 6ca32d9..39f8027 100644 --- a/src/handlebars.yy +++ b/src/handlebars.yy @@ -30,7 +30,7 @@ rawBlock ; openRawBlock - : OPEN_RAW_BLOCK sexpr CLOSE_RAW_BLOCK -> { sexpr: $2 } + : OPEN_RAW_BLOCK helperName param* hash? CLOSE_RAW_BLOCK -> { path: $2, params: $3, hash: $4 } ; block @@ -39,15 +39,15 @@ block ; openBlock - : OPEN_BLOCK sexpr blockParams? CLOSE -> { sexpr: $2, blockParams: $3, strip: yy.stripFlags($1, $4) } + : OPEN_BLOCK helperName param* hash? blockParams? CLOSE -> { path: $2, params: $3, hash: $4, blockParams: $5, strip: yy.stripFlags($1, $6) } ; openInverse - : OPEN_INVERSE sexpr blockParams? CLOSE -> { sexpr: $2, blockParams: $3, strip: yy.stripFlags($1, $4) } + : OPEN_INVERSE helperName param* hash? blockParams? CLOSE -> { path: $2, params: $3, hash: $4, blockParams: $5, strip: yy.stripFlags($1, $6) } ; openInverseChain - : OPEN_INVERSE_CHAIN sexpr blockParams? CLOSE -> { sexpr: $2, blockParams: $3, strip: yy.stripFlags($1, $4) } + : OPEN_INVERSE_CHAIN helperName param* hash? blockParams? CLOSE -> { path: $2, params: $3, hash: $4, blockParams: $5, strip: yy.stripFlags($1, $6) } ; inverseAndProgram @@ -72,23 +72,12 @@ closeBlock mustache // Parsing out the '&' escape token at AST level saves ~500 bytes after min due to the removal of one parser node. // This also allows for handler unification as all mustache node instances can utilize the same handler - : OPEN sexpr CLOSE -> yy.prepareMustache($2, $1, yy.stripFlags($1, $3), @$) - | OPEN_UNESCAPED sexpr CLOSE_UNESCAPED -> yy.prepareMustache($2, $1, yy.stripFlags($1, $3), @$) + : OPEN helperName param* hash? CLOSE -> yy.prepareMustache($2, $3, $4, $1, yy.stripFlags($1, $5), @$) + | OPEN_UNESCAPED helperName param* hash? CLOSE_UNESCAPED -> yy.prepareMustache($2, $3, $4, $1, yy.stripFlags($1, $5), @$) ; partial - : OPEN_PARTIAL partial_expr CLOSE -> new yy.PartialStatement($2, yy.stripFlags($1, $3), yy.locInfo(@$)) - ; - -partial_expr - : helperName param* hash? -> new yy.PartialExpression($1, $2, $3, yy.locInfo(@$)) - | dataName -> new yy.PartialExpression($1, null, null, yy.locInfo(@$)) - | OPEN_SEXPR sexpr CLOSE_SEXPR param* hash? -> new yy.PartialExpression($2, $4, $5, yy.locInfo(@$)) - ; - -sexpr - : helperName param* hash? -> new yy.SubExpression($1, $2, $3, yy.locInfo(@$)) - | dataName -> new yy.SubExpression($1, null, null, yy.locInfo(@$)) + : OPEN_PARTIAL partialName param* hash? CLOSE -> new yy.PartialStatement($2, $3, $4, yy.stripFlags($1, $5), yy.locInfo(@$)) ; param @@ -97,7 +86,11 @@ param | NUMBER -> new yy.NumberLiteral($1, yy.locInfo(@$)) | BOOLEAN -> new yy.BooleanLiteral($1, yy.locInfo(@$)) | dataName -> $1 - | OPEN_SEXPR sexpr CLOSE_SEXPR -> $2 + | sexpr -> $1 + ; + +sexpr + : OPEN_SEXPR helperName param* hash? CLOSE_SEXPR -> new yy.SubExpression($2, $3, $4, yy.locInfo(@$)) ; hash @@ -114,10 +107,16 @@ blockParams helperName : path -> $1 + | dataName -> $1 | STRING -> new yy.StringLiteral($1, yy.locInfo(@$)), yy.locInfo(@$) | NUMBER -> new yy.NumberLiteral($1, yy.locInfo(@$)) ; +partialName + : helperName -> $1 + | sexpr -> $1 + ; + dataName : DATA pathSegments -> yy.preparePath(true, $2, @$) ; |