1
0
mirror of https://github.com/Jermolene/TiddlyWiki5 synced 2024-11-27 12:07:19 +00:00

Added verification of macro type compatibility

This commit is contained in:
Jeremy Ruston 2012-01-07 18:33:57 +00:00
parent 7a0f94343a
commit 3a98cc5389

View File

@ -80,61 +80,57 @@ WikiTextParseTree.prototype.compileMacroCall = function(type,name,params) {
var macro = this.store.macros[name], var macro = this.store.macros[name],
p, p,
n; n;
if(macro) { if(!macro) {
var macroCall = { this.pushString("{{** Unknown macro '" + name + "' **}}");
type: "FunctionCall", return;
name: { }
if(macro.types.indexOf(type) === -1) {
this.pushString("{{** Macro '" + name + "' cannot render to MIME type '" + type + "'**}}");
return;
}
var macroCall = {
type: "FunctionCall",
name: {
"base": {
"base": { "base": {
"base": { "base": {
"base": { "name": "store",
"name": "store", "type": "Variable"},
"type": "Variable" "name": "macros",
}, "type": "PropertyAccess"},
"name": "macros", "name": {
"type": "PropertyAccess" "type": "StringLiteral",
}, "value": name},
"name": { "type": "PropertyAccess"},
"type": "StringLiteral", "name": "code",
"value": name "type": "PropertyAccess"},
}, "arguments": [ {
"type": "PropertyAccess" "type": "StringLiteral",
}, "value": type
"name": "code", },{
"type": "PropertyAccess" "type": "Variable",
}, "name": "tiddler"
"arguments": [ { },{
"type": "StringLiteral", "type": "Variable",
"value": type "name": "store"
}, },{
{ type: "ObjectLiteral",
"type": "Variable", properties: []
"name": "tiddler" }]
}, };
{ for(p in params) {
"type": "Variable", if(params[p].type === "string") {
"name": "store" n = {type: "StringLiteral", value: params[p].value};
}, } else {
{ n = this.store.jsParser.parse(params[p].value).tree.elements[0];
type: "ObjectLiteral",
properties: []
}]
};
for(p in params) {
if(params[p].type === "string") {
n = {type: "StringLiteral", value: params[p].value};
} else {
n = this.store.jsParser.parse(params[p].value).tree.elements[0];
}
macroCall["arguments"][3].properties.push({
type: "PropertyAssignment",
name: p,
value: n
});
} }
this.output.push(macroCall); macroCall["arguments"][3].properties.push({
} else { type: "PropertyAssignment",
this.pushString("{{** Unknown macro '" + name + "' **}}"); name: p,
value: n
});
} }
this.output.push(macroCall);
}; };
WikiTextParseTree.prototype.compileElementHtml = function(element, options) { WikiTextParseTree.prototype.compileElementHtml = function(element, options) {