summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorkpdecker <kpdecker@gmail.com>2014-11-02 11:55:52 -0600
committerkpdecker <kpdecker@gmail.com>2014-11-02 11:55:52 -0600
commitf30b3ea3293ad28bad8167e40b8372c48cb2419e (patch)
treef668b1950bc532b35cbbab3e78ea0e50f9e9577e /src
parent9fbf7aa753f5d48951c3f373c40f787739489962 (diff)
downloadhandlebars.js-f30b3ea3293ad28bad8167e40b8372c48cb2419e.zip
handlebars.js-f30b3ea3293ad28bad8167e40b8372c48cb2419e.tar.gz
handlebars.js-f30b3ea3293ad28bad8167e40b8372c48cb2419e.tar.bz2
Allow whitespace control on comments
This changes the call signature for the CommentNode constructor, which is a potentially breaking change for AST users. Fixes #866
Diffstat (limited to 'src')
-rw-r--r--src/handlebars.l16
-rw-r--r--src/handlebars.yy2
2 files changed, 14 insertions, 4 deletions
diff --git a/src/handlebars.l b/src/handlebars.l
index 0f420e7..fbeec34 100644
--- a/src/handlebars.l
+++ b/src/handlebars.l
@@ -56,7 +56,10 @@ ID [^\s!"#%-,\.\/;->@\[-\^`\{-~]+/{LOOKAHEAD}
}
<raw>[^\x00]*?/("{{{{/") { return 'CONTENT'; }
-<com>[\s\S]*?"--}}" strip(0,4); this.popState(); return 'COMMENT';
+<com>[\s\S]*?"--"{RIGHT_STRIP}?"}}" {
+ this.popState();
+ return 'COMMENT';
+}
<mu>"(" return 'OPEN_SEXPR';
<mu>")" return 'CLOSE_SEXPR';
@@ -76,8 +79,15 @@ ID [^\s!"#%-,\.\/;->@\[-\^`\{-~]+/{LOOKAHEAD}
<mu>"{{"{LEFT_STRIP}?\s*"else" return 'OPEN_INVERSE';
<mu>"{{"{LEFT_STRIP}?"{" return 'OPEN_UNESCAPED';
<mu>"{{"{LEFT_STRIP}?"&" return 'OPEN';
-<mu>"{{!--" this.popState(); this.begin('com');
-<mu>"{{!"[\s\S]*?"}}" strip(3,5); this.popState(); return 'COMMENT';
+<mu>"{{"{LEFT_STRIP}?"!--" {
+ this.unput(yytext);
+ this.popState();
+ this.begin('com');
+}
+<mu>"{{"{LEFT_STRIP}?"!"[\s\S]*?"}}" {
+ this.popState();
+ return 'COMMENT';
+}
<mu>"{{"{LEFT_STRIP}? return 'OPEN';
<mu>"=" return 'EQUALS';
diff --git a/src/handlebars.yy b/src/handlebars.yy
index a8d288f..ccc0d22 100644
--- a/src/handlebars.yy
+++ b/src/handlebars.yy
@@ -18,7 +18,7 @@ statement
| rawBlock -> $1
| partial -> $1
| CONTENT -> new yy.ContentNode($1, @$)
- | COMMENT -> new yy.CommentNode($1, @$)
+ | COMMENT -> new yy.CommentNode(yy.stripComment($1), yy.stripFlags($1, $1), @$)
;
rawBlock