Fixes #185 - Allow the <var> tag to have body content

This commit is contained in:
Patrick Steele-Idem 2015-12-20 16:02:59 -07:00
parent 5665fb6e29
commit 90fb80b71f
5 changed files with 114 additions and 1 deletions

View File

@ -8,6 +8,7 @@ class Vars extends Node {
super('Vars');
this.kind = def.kind || 'var';
this.declarations = def.declarations;
this.body = this.makeContainer(def.body);
}
generateCode(generator) {

View File

@ -0,0 +1,74 @@
{
"type": "TemplateRoot",
"body": [
{
"type": "Vars",
"kind": "var",
"declarations": [
{
"name": "x",
"value": {
"type": "Literal",
"value": 1
}
},
{
"name": "y",
"value": {
"type": "Literal",
"value": 7
}
},
{
"name": "z",
"value": "x+10"
},
{
"name": "unusedvar"
}
],
"body": [
{
"type": "Text",
"argument": {
"type": "Literal",
"value": "\n "
}
},
{
"type": "Text",
"argument": "x"
},
{
"type": "Text",
"argument": {
"type": "Literal",
"value": "\n "
}
},
{
"type": "Text",
"argument": "y"
},
{
"type": "Text",
"argument": {
"type": "Literal",
"value": "\n "
}
},
{
"type": "Text",
"argument": "z"
},
{
"type": "Text",
"argument": {
"type": "Literal",
"value": "\nHELLO WORLD\n"
}
}
]
}
]
}

View File

@ -0,0 +1,6 @@
<var x=1 y=7 z=x+10 unusedVar>
${x}
${y}
${z}
HELLO WORLD
</var>

View File

@ -24,7 +24,8 @@
"id": "notEmpty",
"init": "__helpers.ne"
}
]
],
"body": []
},
{
"type": "Return",

31
test/parser-test.js Normal file
View File

@ -0,0 +1,31 @@
'use strict';
var chai = require('chai');
chai.config.includeStack = true;
var path = require('path');
var compiler = require('../compiler');
var builder = compiler.createBuilder();
var autotest = require('./autotest');
var fs = require('fs');
var CompileContext = require('../compiler/CompileContext');
var HtmlJsParser = require('../compiler/HtmlJsParser');
var Parser = require('../compiler/Parser');
var parser = new Parser(new HtmlJsParser());
describe('compiler/parser', function() {
var autoTestDir = path.join(__dirname, 'fixtures/parser/autotest');
autotest.scanDir(
autoTestDir,
function run(dir) {
var templatePath = path.join(dir, 'template.marko');
var src = fs.readFileSync(templatePath, {encoding: 'utf8'});
var context = new CompileContext(src, templatePath, builder);
var ast = parser.parse(src, context);
return ast;
},
{
deepEqual: true,
compareExtension: '.json'
});
});