mirror of
https://github.com/marko-js/marko.git
synced 2025-12-08 19:26:05 +00:00
Marko v3: new method: builder.var(id, init, kind)
This commit is contained in:
parent
15fcbf63a5
commit
4b3c738a8d
@ -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)) {
|
||||
|
||||
1
test/fixtures/codegen/autotest/var/expected.js
vendored
Normal file
1
test/fixtures/codegen/autotest/var/expected.js
vendored
Normal file
@ -0,0 +1 @@
|
||||
let foo = "bar"
|
||||
8
test/fixtures/codegen/autotest/var/index.js
vendored
Normal file
8
test/fixtures/codegen/autotest/var/index.js
vendored
Normal file
@ -0,0 +1,8 @@
|
||||
'use strict';
|
||||
|
||||
module.exports = function(builder) {
|
||||
return builder.var(
|
||||
builder.identifier('foo'),
|
||||
builder.literal('bar'),
|
||||
'let');
|
||||
};
|
||||
2
test/fixtures/codegen/autotest/vars-array/expected.js
vendored
Normal file
2
test/fixtures/codegen/autotest/vars-array/expected.js
vendored
Normal file
@ -0,0 +1,2 @@
|
||||
var foo = "bar",
|
||||
hello = "world"
|
||||
14
test/fixtures/codegen/autotest/vars-array/index.js
vendored
Normal file
14
test/fixtures/codegen/autotest/vars-array/index.js
vendored
Normal 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')
|
||||
}
|
||||
]);
|
||||
};
|
||||
2
test/fixtures/codegen/autotest/vars-object/expected.js
vendored
Normal file
2
test/fixtures/codegen/autotest/vars-object/expected.js
vendored
Normal file
@ -0,0 +1,2 @@
|
||||
var foo = "bar",
|
||||
hello = "world"
|
||||
8
test/fixtures/codegen/autotest/vars-object/index.js
vendored
Normal file
8
test/fixtures/codegen/autotest/vars-object/index.js
vendored
Normal file
@ -0,0 +1,8 @@
|
||||
'use strict';
|
||||
|
||||
module.exports = function(builder) {
|
||||
return builder.vars({
|
||||
'foo': builder.literal('bar'),
|
||||
'hello': builder.literal('world')
|
||||
});
|
||||
};
|
||||
Loading…
x
Reference in New Issue
Block a user