Skip to content
Browse files

apply: backport applyNext behaviour fixes

  • Loading branch information...
1 parent 9e7aab3 commit 38a605fbd372560ba381305b154726cf036f4497 @indutny indutny committed Oct 1, 2013
Showing with 29 additions and 14 deletions.
  1. +1 −0 lib/xjst/helpers/serializer.js
  2. +19 −9 lib/xjst/ometa/xjst.ometajs
  3. +9 −5 test/templates/apply.xjst
View
1 lib/xjst/helpers/serializer.js
@@ -194,6 +194,7 @@ Serializer.prototype.serialize = function serialize(node, tails, _parents) {
// Compile statement or wrap it into a function
} else {
+ res.push('this.__$a=0;\n');
var body = (options.asyncify ? '"enable spoon";\n' : '') +
XJSTCompiler.match(node.stmt, 'skipBraces') + ';\n' +
'return;\n';
View
28 lib/xjst/ometa/xjst.ometajs
@@ -68,8 +68,9 @@ ometa XJSTParser <: BSJSParser {
applyNextFlag -> {
function stringify() {
- if (flagId === null) flagId = ++applyNextId;
- return '__$anflg' + flagId;
+ if (flagId === null)
+ flagId = ++applyNextId;
+ return flagId;
}
var flagId = null,
flag = {
@@ -79,8 +80,8 @@ ometa XJSTParser <: BSJSParser {
},
predicate = [
'binop', '!==',
- ['getp', ['string', flag], ['this']],
- ['get', 'true']
+ ['getp', ['string', '__$a'], ['this']],
+ ['get', flag]
];
this.predicates = this.predicates.length ? [
@@ -89,8 +90,8 @@ ometa XJSTParser <: BSJSParser {
predicate
] : predicate;
- ['set', ['getp', ['string', flag], ['this']],
- ['get', 'true']]
+ ['set', ['getp', ['string', '__$a'], ['this']],
+ ['get', flag]]
},
localStmt = [#local :a :b] -> [#localStmt, a, b],
@@ -218,7 +219,13 @@ ometa XJSTTranslator <: XJSTIdentity {
localAsmt = [#set [#parens :p] trans:v] localAsmt([#set, p, v]):r -> r
- | [#set [(#get :n | #getp :k :o)]:p trans:v]
+ | [#set [#getp [#string '__$a'] [#this]]:p trans:v] -> {
+ [
+ [[#set, p, v]],
+ [],
+ [[p, v]]
+ ]
+ } | [#set [(#get :n | #getp :k :o)]:p trans:v]
localProps(p):props -> {
var lv = this._getLocalVar(),
vars = [[#var].concat(props[1], [[lv[1], props[0]]])];
@@ -364,6 +371,9 @@ ometa XJSTLocalAndApplyCompiler <: BSJSIdentity {
}
ometa XJSTCompiler <: BSJSTranslator {
+ // Help applyNext flags
+ get :x -> x.toString(),
+
extends trans:filename -> { '"extends" + ' + filename },
superStmt trans:op -> op,
superExpr trans:op -> op,
@@ -387,10 +397,10 @@ ometa XJSTCompiler <: BSJSTranslator {
tBody = trans:e -> e,
- template = [tMatch:m tBody:b] -> ('if(' + m + ') {' + b + ';return}')
+ template = [tMatch:m tBody:b] -> ('if(' + m + ') {this.__$a=0;' + b + ';return}')
| [#var anything*]:v trans(v):r -> r,
- templates = [template*:ts] -> ('exports.apply = apply;function apply(c) {\nvar __this = this;\n' + ts.join('\n') +'\n};'),
+ templates = [template*:ts] -> ('exports.apply = apply;function apply(c) {\nvar __this = this;\n' + ts.join('\n') +'\nthis.__$a=0;};'),
other = [trans*:o] -> o.join(';'),
View
14 test/templates/apply.xjst
@@ -72,14 +72,18 @@ template(this.type === 'invalidating' && !this.sub) {
return apply(this.sub = { s: 'x' });
}
-template(this.type === 'apply-next' && this.subtype === '1') {
- return 'ok';
+template(this.type === 'apply-next') {
+ return 'oh noes!';
}
-template(this.type === 'apply-next' && this.subtype === '1') {
- return applyNext();
+template(this.type === 'apply-next' && this.a === 'ok') {
+ return 'ok';
}
template(this.type === 'apply-next') {
- return applyNext(this.subtype = '1');
+ return applyNext({ a: this.a === 'pre-ok' ? 'ok' : 'pre-ok' });
+}
+
+template(this.type === 'apply-next' && this.a === 'pre-ok') {
+ return applyNext();
}

0 comments on commit 38a605f

Please sign in to comment.
Something went wrong with that request. Please try again.