-
Notifications
You must be signed in to change notification settings - Fork 274
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add support for arrow functions #871
Add support for arrow functions #871
Conversation
7c375e6
to
93a1b6b
Compare
eabe55c
to
ee22d77
Compare
@@ -212,9 +214,9 @@ module.exports = function (Twig) { | |||
}, | |||
{ | |||
type: Twig.expression.type.operator.binary, | |||
// Match any of ??, ?:, +, *, /, -, %, ~, <, <=, >, >=, !=, ==, **, ?, :, and, b-and, or, b-or, b-xor, in, not in | |||
// Match any of ??, ?:, +, *, /, -, %, ~, <=>, <, <=, >, >=, !=, ==, **, ?, :, and, b-and, or, b-or, b-xor, in, not in |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove this change and submit as separate PR.
// and, or, in, not in, matches, starts with, ends with can be followed by a space or parenthesis | ||
regex: /(^\?\?|^\?:|^(b-and)|^(b-or)|^(b-xor)|^[+\-~%?]|^[:](?!\d\])|^[!=]==?|^[!<>]=?|^\*\*?|^\/\/?|^(and)[(|\s+]|^(or)[(|\s+]|^(in)[(|\s+]|^(not in)[(|\s+]|^(matches)|^(starts with)|^(ends with)|^\.\.)/, | ||
regex: /(^\?\?|^\?:|^(b-and)|^(b-or)|^(b-xor)|^[+\-~%?]|^(<=>)|^[:](?!\d\])|^[!=]==?|^[!<>]=?|^\*\*?|^\/\/?|^(and)[(|\s+]|^(or)[(|\s+]|^(in)[(|\s+]|^(not in)[(|\s+]|^(matches)|^(starts with)|^(ends with)|^\.\.)/, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove this change and submit as separate PR.
token.precidence = 9; | ||
token.associativity = Twig.expression.operator.leftToRight; | ||
break; | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove this change and submit as separate PR.
case '<=>': | ||
stack.push(a === b ? 0 : (a < b ? -1 : 1)); | ||
break; | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove this change and submit as separate PR.
const template = Twig.exports.twig({data: params.body}); | ||
return template.render(data); | ||
}, params.args || 0); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove these changes and submit as a separate PR after this is one merged.
const output = testTemplate.render(pair); | ||
output.should.equal((pair.a === pair.b ? 0 : (pair.a < pair.b ? -1 : 1)).toString()); | ||
}); | ||
}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove this change and submit as separate PR.
testTemplate.render().should.equal('18'); | ||
}); | ||
}); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove these changes and submit as a separate PR after this is one merged.
Co-authored-by: Will Rowe <[email protected]>
Co-authored-by: Will Rowe <[email protected]>
Co-authored-by: Will Rowe <[email protected]>
Co-authored-by: Will Rowe <[email protected]>
Co-authored-by: Will Rowe <[email protected]>
Co-authored-by: Will Rowe <[email protected]>
Aiming to resolve #652
I'm not (yet) quite convinced if this is the way to go; would really like to get some discussion going on how to approach this and eventually get this fixed and merged.
Implementation of arrow functions in filters:
Object manipulation is not really supported; this implementation accepts a callbackFunction (Twig syntax) which is compiled and parsed as a new (runtime) template. The return values (e.g. output) of the callBackFunctions are delegated to their respective JS functions.
As previously stated: this is merely a functional (read dirty) workaround; but for most of the use cases it will do the trick.