mirror of
https://github.com/marko-js/marko.git
synced 2025-12-08 19:26:05 +00:00
Fixing bug that occurs when string concatenation is being used and one of the parts is a ternary operator expression. Each part needs to be surrounded with parentheses.
This commit is contained in:
parent
0dad9a6d78
commit
e1872eeaaa
@ -162,7 +162,12 @@ CodeWriter.prototype = {
|
||||
code.append(' +\n' + this.indentStr());
|
||||
}
|
||||
|
||||
// The expression might be a ternary operator
|
||||
// so we need to surround it with parentheses.
|
||||
// Minification will remove unnecessary parentheses.
|
||||
code.append('(');
|
||||
writeArg(_this, expression);
|
||||
code.append(')');
|
||||
|
||||
if (i !== 0) {
|
||||
_this.decIndent();
|
||||
|
||||
1
test-render-rxml.sh
Executable file
1
test-render-rxml.sh
Executable file
@ -0,0 +1 @@
|
||||
node_modules/.bin/mocha --ui bdd --reporter spec ./test/render-rxml-tests.js
|
||||
@ -362,5 +362,9 @@ describe('raptor-templates/rxml' , function() {
|
||||
testRender("test-project/rxml-templates/layout-use.rxml", {}, done);
|
||||
});
|
||||
|
||||
it("should add parentheses around each expression when using string concatenation to handle ternary operator", function(done) {
|
||||
testRender("test-project/rxml-templates/string-concat-with-ternary-operator.rxml", {}, done);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
|
||||
@ -12,26 +12,26 @@ module.exports = function create(__helpers) {
|
||||
|
||||
var message=data.message;
|
||||
|
||||
context.w('<div class="hello-world ' +
|
||||
escapeXmlAttr(rootClass) +
|
||||
'">' +
|
||||
escapeXml(message) +
|
||||
'</div>');
|
||||
context.w(('<div class="hello-world ') +
|
||||
(escapeXmlAttr(rootClass)) +
|
||||
('">') +
|
||||
(escapeXml(message)) +
|
||||
('</div>'));
|
||||
|
||||
if (notEmpty(colors)) {
|
||||
context.w('<ul>');
|
||||
context.w(('<ul>'));
|
||||
|
||||
forEach(colors, function(color) {
|
||||
context.w('<li class="color">' +
|
||||
escapeXml(color) +
|
||||
'</li>');
|
||||
context.w(('<li class="color">') +
|
||||
(escapeXml(color)) +
|
||||
('</li>'));
|
||||
});
|
||||
|
||||
context.w('</ul>');
|
||||
context.w(('</ul>'));
|
||||
}
|
||||
|
||||
if (empty(colors)) {
|
||||
context.w('<div>No colors!</div>');
|
||||
context.w(('<div>No colors!</div>'));
|
||||
}
|
||||
};
|
||||
}
|
||||
@ -17,26 +17,26 @@ module.exports = function create(__helpers) {
|
||||
"name": "World"
|
||||
});
|
||||
|
||||
context.w('<div class="hello-world ' +
|
||||
escapeXmlAttr(rootClass) +
|
||||
'">' +
|
||||
escapeXml(message) +
|
||||
'</div>');
|
||||
context.w(('<div class="hello-world ') +
|
||||
(escapeXmlAttr(rootClass)) +
|
||||
('">') +
|
||||
(escapeXml(message)) +
|
||||
('</div>'));
|
||||
|
||||
if (notEmpty(colors)) {
|
||||
context.w('<ul>');
|
||||
context.w(('<ul>'));
|
||||
|
||||
forEach(colors, function(color) {
|
||||
context.w('<li class="color">' +
|
||||
escapeXml(color) +
|
||||
'</li>');
|
||||
context.w(('<li class="color">') +
|
||||
(escapeXml(color)) +
|
||||
('</li>'));
|
||||
});
|
||||
|
||||
context.w('</ul>');
|
||||
context.w(('</ul>'));
|
||||
}
|
||||
|
||||
if (empty(colors)) {
|
||||
context.w('<div>No colors!</div>');
|
||||
context.w(('<div>No colors!</div>'));
|
||||
}
|
||||
};
|
||||
}
|
||||
@ -0,0 +1,4 @@
|
||||
<c-template c-whitespace="preserve">
|
||||
A: $!{true ? 'ABC' : ''}
|
||||
B: This should be outputted as well.
|
||||
</c-template>
|
||||
@ -0,0 +1,3 @@
|
||||
|
||||
A: ABC
|
||||
B: This should be outputted as well.
|
||||
@ -0,0 +1,10 @@
|
||||
module.exports = function create(__helpers) {
|
||||
var empty = __helpers.e,
|
||||
notEmpty = __helpers.ne;
|
||||
|
||||
return function render(data, context) {
|
||||
context.w(('\nA: ') +
|
||||
(true ? 'ABC' : '') +
|
||||
('\nB: This should be outputted as well.\n'));
|
||||
};
|
||||
}
|
||||
@ -3,6 +3,6 @@ module.exports = function create(__helpers) {
|
||||
notEmpty = __helpers.ne;
|
||||
|
||||
return function render(data, context) {
|
||||
context.w('Hello John');
|
||||
context.w(('Hello John'));
|
||||
};
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user