mirror of
https://github.com/marko-js/marko.git
synced 2025-12-08 19:26:05 +00:00
Fixes #185 - Allow the <var> tag to have body content
This commit is contained in:
parent
5665fb6e29
commit
90fb80b71f
@ -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) {
|
||||
|
||||
74
test/fixtures/parser/autotest/var-body/expected.json
vendored
Normal file
74
test/fixtures/parser/autotest/var-body/expected.json
vendored
Normal 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"
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
6
test/fixtures/parser/autotest/var-body/template.marko
vendored
Normal file
6
test/fixtures/parser/autotest/var-body/template.marko
vendored
Normal file
@ -0,0 +1,6 @@
|
||||
<var x=1 y=7 z=x+10 unusedVar>
|
||||
${x}
|
||||
${y}
|
||||
${z}
|
||||
HELLO WORLD
|
||||
</var>
|
||||
@ -24,7 +24,8 @@
|
||||
"id": "notEmpty",
|
||||
"init": "__helpers.ne"
|
||||
}
|
||||
]
|
||||
],
|
||||
"body": []
|
||||
},
|
||||
{
|
||||
"type": "Return",
|
||||
|
||||
31
test/parser-test.js
Normal file
31
test/parser-test.js
Normal 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'
|
||||
});
|
||||
});
|
||||
Loading…
x
Reference in New Issue
Block a user