mirror of
https://github.com/marko-js/marko.git
synced 2025-12-08 19:26:05 +00:00
76 lines
1.7 KiB
JavaScript
76 lines
1.7 KiB
JavaScript
'use strict';
|
|
|
|
var Node = require('./Node');
|
|
|
|
class Vars extends Node {
|
|
constructor(def) {
|
|
super('Vars');
|
|
this.kind = def.kind || 'var';
|
|
this.declarations = def.declarations;
|
|
this.body = this.makeContainer(def.body);
|
|
}
|
|
|
|
generateCode(codegen) {
|
|
var declarations = this.declarations;
|
|
|
|
if (!declarations || !declarations.length) {
|
|
return null;
|
|
}
|
|
|
|
if (this.body && this.body.length) {
|
|
var scopedBody = [this].concat(this.body);
|
|
this.body = null;
|
|
return codegen.builder.selfInvokingFunction(scopedBody);
|
|
}
|
|
|
|
return this;
|
|
}
|
|
|
|
writeCode(writer) {
|
|
var declarations = this.declarations;
|
|
var kind = this.kind;
|
|
var isStatement = this.statement;
|
|
|
|
|
|
if (!declarations || !declarations.length) {
|
|
return;
|
|
}
|
|
|
|
writer.incIndent(4);
|
|
|
|
for (let i=0; i<declarations.length; i++) {
|
|
var declarator = declarations[i];
|
|
|
|
if (i === 0) {
|
|
writer.write(kind + ' ');
|
|
} else {
|
|
writer.writeLineIndent();
|
|
}
|
|
|
|
writer.write(declarator);
|
|
|
|
if (i < declarations.length - 1) {
|
|
writer.write(',\n');
|
|
} else {
|
|
if (isStatement) {
|
|
writer.write(';\n');
|
|
}
|
|
}
|
|
}
|
|
|
|
writer.decIndent(4);
|
|
}
|
|
|
|
walk(walker) {
|
|
this.argument = walker.walk(this.argument);
|
|
}
|
|
|
|
/**
|
|
* "noOutput" should be true if the Node.js does not result in any HTML or Text output
|
|
*/
|
|
get noOutput() {
|
|
return !(this.body && this.body.length);
|
|
}
|
|
}
|
|
|
|
module.exports = Vars; |