Marko v3: new method: builder.var(id, init, kind)

This commit is contained in:
Patrick Steele-Idem 2016-02-08 12:06:44 -07:00
parent 15fcbf63a5
commit 4b3c738a8d
7 changed files with 50 additions and 0 deletions

View File

@ -462,6 +462,21 @@ class Builder {
return new VariableDeclarator({id, init});
}
var(id, init, kind) {
if (!kind) {
kind = 'var';
}
id = makeNode(id);
init = makeNode(init);
var declarations = [
new VariableDeclarator({id, init})
];
return new Vars({declarations, kind});
}
vars(declarations, kind) {
if (declarations) {
if (Array.isArray(declarations)) {

View File

@ -0,0 +1 @@
let foo = "bar"

View File

@ -0,0 +1,8 @@
'use strict';
module.exports = function(builder) {
return builder.var(
builder.identifier('foo'),
builder.literal('bar'),
'let');
};

View File

@ -0,0 +1,2 @@
var foo = "bar",
hello = "world"

View File

@ -0,0 +1,14 @@
'use strict';
module.exports = function(builder) {
return builder.vars([
{
id: 'foo',
init: builder.literal('bar')
},
{
id: builder.identifier('hello'),
init: builder.literal('world')
}
]);
};

View File

@ -0,0 +1,2 @@
var foo = "bar",
hello = "world"

View File

@ -0,0 +1,8 @@
'use strict';
module.exports = function(builder) {
return builder.vars({
'foo': builder.literal('bar'),
'hello': builder.literal('world')
});
};