mirror of
https://github.com/marko-js/marko.git
synced 2025-12-08 19:26:05 +00:00
Marko v3: allow more than two args for builder.concat(...)
This commit is contained in:
parent
410bb80ede
commit
90317b899f
@ -103,11 +103,23 @@ class Builder {
|
||||
return new Code({value});
|
||||
}
|
||||
|
||||
concat(left, right) {
|
||||
left = makeNode(left);
|
||||
right = makeNode(right);
|
||||
concat(args) {
|
||||
var prev;
|
||||
let operator = '+';
|
||||
return new BinaryExpression({left, operator, right});
|
||||
|
||||
for (var i=1; i<arguments.length; i++) {
|
||||
var left;
|
||||
var right = makeNode(arguments[i]);
|
||||
if (i === 1) {
|
||||
left = makeNode(arguments[i-1]);
|
||||
} else {
|
||||
left = prev;
|
||||
}
|
||||
|
||||
prev = new BinaryExpression({left, operator, right});
|
||||
}
|
||||
|
||||
return prev;
|
||||
}
|
||||
|
||||
conditionalExpression(test, consequent, alternate) {
|
||||
|
||||
1
test/fixtures/codegen/autotest/concat-four/expected.js
vendored
Normal file
1
test/fixtures/codegen/autotest/concat-four/expected.js
vendored
Normal file
@ -0,0 +1 @@
|
||||
((a + b) + c) + d
|
||||
9
test/fixtures/codegen/autotest/concat-four/index.js
vendored
Normal file
9
test/fixtures/codegen/autotest/concat-four/index.js
vendored
Normal file
@ -0,0 +1,9 @@
|
||||
'use strict';
|
||||
|
||||
module.exports = function(builder) {
|
||||
return builder.concat(
|
||||
builder.identifier('a'),
|
||||
builder.identifier('b'),
|
||||
builder.identifier('c'),
|
||||
builder.identifier('d'));
|
||||
};
|
||||
1
test/fixtures/codegen/autotest/concat-three/expected.js
vendored
Normal file
1
test/fixtures/codegen/autotest/concat-three/expected.js
vendored
Normal file
@ -0,0 +1 @@
|
||||
(a + b) + c
|
||||
8
test/fixtures/codegen/autotest/concat-three/index.js
vendored
Normal file
8
test/fixtures/codegen/autotest/concat-three/index.js
vendored
Normal file
@ -0,0 +1,8 @@
|
||||
'use strict';
|
||||
|
||||
module.exports = function(builder) {
|
||||
return builder.concat(
|
||||
builder.identifier('a'),
|
||||
builder.identifier('b'),
|
||||
builder.identifier('c'));
|
||||
};
|
||||
1
test/fixtures/codegen/autotest/concat/expected.js
vendored
Normal file
1
test/fixtures/codegen/autotest/concat/expected.js
vendored
Normal file
@ -0,0 +1 @@
|
||||
a + b
|
||||
7
test/fixtures/codegen/autotest/concat/index.js
vendored
Normal file
7
test/fixtures/codegen/autotest/concat/index.js
vendored
Normal file
@ -0,0 +1,7 @@
|
||||
'use strict';
|
||||
|
||||
module.exports = function(builder) {
|
||||
return builder.concat(
|
||||
builder.identifier('a'),
|
||||
builder.identifier('b'));
|
||||
};
|
||||
Loading…
x
Reference in New Issue
Block a user