mirror of
https://github.com/marko-js/marko.git
synced 2025-12-08 19:26:05 +00:00
Use attr helper and handle attribute escaping Also improved AST and added walking capability
46 lines
1.1 KiB
JavaScript
46 lines
1.1 KiB
JavaScript
'use strict';
|
|
|
|
var Node = require('./Node');
|
|
|
|
class ConditionalExpression extends Node {
|
|
constructor(def) {
|
|
super('ConditionalExpression');
|
|
this.test = def.test;
|
|
this.consequent = def.consequent;
|
|
this.alternate = def.alternate;
|
|
}
|
|
|
|
generateCode(codegen) {
|
|
var test = this.test;
|
|
var consequent = this.consequent;
|
|
var alternate = this.alternate;
|
|
|
|
|
|
codegen.generateCode(test);
|
|
codegen.write(' ? ');
|
|
codegen.generateCode(consequent);
|
|
codegen.write(' : ');
|
|
codegen.generateCode(alternate);
|
|
}
|
|
|
|
isCompoundExpression() {
|
|
return true;
|
|
}
|
|
|
|
toJSON() {
|
|
return {
|
|
type: 'ConditionalExpression',
|
|
test: this.test,
|
|
consequent: this.consequent,
|
|
alternate: this.alternate
|
|
};
|
|
}
|
|
|
|
walk(walker) {
|
|
this.test = walker.walk(this.test);
|
|
this.consequent = walker.walk(this.consequent);
|
|
this.alternate = walker.walk(this.alternate);
|
|
}
|
|
}
|
|
|
|
module.exports = ConditionalExpression; |