firescript
Version:
Firescript transpiler
46 lines (40 loc) • 1.05 kB
JavaScript
const FirescriptElement = require('./FirescriptElement')
/**
* FunctionDeclaration
*
* @class FunctionDeclaration
* @extends FirescriptElement
*
* interface FunctionDeclaration {
* type: 'FunctionDeclaration';
* id: Identifier | null;
* params: FunctionParameter[];
* body: BlockStatement;
* generator: boolean;
* async: boolean;
* expression: false;
* }
*/
class FunctionDeclaration extends FirescriptElement {
constructor (ast) {
super(ast)
this.id = ast.id ? this.createElement(ast.id) : null
this.params = this.createElementList(ast.params)
this.body = this.createElement(ast.body, null)
this.async = ast.async
this.generator = ast.generator
}
toFSString (ctx) {
const id = this.id ? this.id.toFSString(ctx) + ' ' : ''
const func = this.async ? 'async '
: this.generator ? 'gen ' : 'func '
return this.renderElement(
func + id +
'(' +
ctx.join(this.params, ', ') +
')' +
this.body.toFSString(ctx)
)
}
}
module.exports = FunctionDeclaration