diff --git a/compiler/CodeGenerator.js b/compiler/CodeGenerator.js index 6aaaac1ec..840e9012a 100644 --- a/compiler/CodeGenerator.js +++ b/compiler/CodeGenerator.js @@ -288,7 +288,11 @@ class Generator { let startPos = this._code.length; - this.generateCode(node); + if (Array.isArray(node) || (node instanceof Container)) { + this.generateStatements(node); + } else { + this.generateCode(node); + } if (this._code.length === startPos) { // No code was generated. Remove any code that was previously added diff --git a/compiler/CompileError.js b/compiler/CompileError.js index a609c3d73..b722b8128 100644 --- a/compiler/CompileError.js +++ b/compiler/CompileError.js @@ -38,7 +38,7 @@ class CompileError { pos = ''; } var str = pos + this.message; - if (this.node) { + if (pos == null && this.node) { str += ' (' + this.node.toString() + ')'; } return str; diff --git a/compiler/HtmlJsParser.js b/compiler/HtmlJsParser.js index 7a20b444b..3ff331d40 100644 --- a/compiler/HtmlJsParser.js +++ b/compiler/HtmlJsParser.js @@ -20,9 +20,9 @@ class HtmlJsParser { onattributeplaceholder(event) { // placeholder within attribute if (event.escape) { - event.expression = 'escapeXml(' + event.expression + ')'; + event.expression = '$escapeXml(' + event.expression + ')'; } else { - event.expression = 'noEscapeXml(' + event.expression + ')'; + event.expression = '$noEscapeXml(' + event.expression + ')'; } }, diff --git a/compiler/ast/CustomTag.js b/compiler/ast/CustomTag.js index 10d7c34e9..6b40679ba 100644 --- a/compiler/ast/CustomTag.js +++ b/compiler/ast/CustomTag.js @@ -3,6 +3,7 @@ var HtmlElement = require('./HtmlElement'); var path = require('path'); var removeDashes = require('../util/removeDashes'); +var removeEscapeFunctions = require('../util/removeEscapeFunctions'); function removeExt(filename) { var ext = path.extname(filename); @@ -20,6 +21,11 @@ function buildInputProps(node, context) { var attrName = attr.name; var attrDef = attr.def || context.taglibLookup.getAttribute(node.tagName, attr.name); + var attrValue = removeEscapeFunctions(attr.value); + + if (!attrDef) { + return; // Skip over attributes that are not supported + } var propName; var parentPropName; @@ -52,9 +58,9 @@ function buildInputProps(node, context) { if (parentPropName) { let parent = inputProps[parentPropName] = (inputProps[parentPropName] = {}); - parent[propName] = attr.value; + parent[propName] = attrValue; } else { - inputProps[propName] = attr.value; + inputProps[propName] = attrValue; } }); diff --git a/compiler/ast/FunctionCall.js b/compiler/ast/FunctionCall.js index 8153155e8..5724d2a47 100644 --- a/compiler/ast/FunctionCall.js +++ b/compiler/ast/FunctionCall.js @@ -9,7 +9,7 @@ class FunctionCall extends Node { this.callee = def.callee; ok(this.callee, '"callee" is required'); - + this.args = def.args; if (this.args && !Array.isArray(this.args)) { diff --git a/compiler/ast/HtmlAttribute.js b/compiler/ast/HtmlAttribute.js index 5d45ccfd1..ad692cac9 100644 --- a/compiler/ast/HtmlAttribute.js +++ b/compiler/ast/HtmlAttribute.js @@ -3,8 +3,8 @@ var Node = require('./Node'); var Literal = require('./Literal'); var ok = require('assert').ok; var escapeXmlAttr = require('raptor-util/escapeXml').attr; -var compiler = require('../'); var parseExpression = require('../util/parseExpression'); +var removeEscapeFunctions = require('../util/removeEscapeFunctions'); function isStringLiteral(node) { return node.type === 'Literal' && typeof node.value === 'string'; @@ -13,18 +13,12 @@ function isStringLiteral(node) { function isNoEscapeXml(node) { return node.type === 'FunctionCall' && node.callee.type === 'Identifier' && - node.callee.name === 'noEscapeXml'; -} - -function isEscapeXml(node) { - return node.type === 'FunctionCall' && - node.callee.type === 'Identifier' && - node.callee.name === 'escapeXml'; + node.callee.name === '$noEscapeXml'; } function isStringExpression(node) { return node.type === 'FunctionCall' && node.callee.type === 'Identifier' && - (node.callee.name === 'noEscapeXml' || node.callee.name === 'escapeXml'); + (node.callee.name === '$noEscapeXml' || node.callee.name === '$escapeXml'); } function flattenAttrConcats(node) { @@ -61,33 +55,6 @@ function flattenAttrConcats(node) { return final.concats; } -// function handleEscaping(node) { -// -// function handleEscapingHelper(node, escaping) { -// if (node.type === 'Literal') { -// } else if (isEscapeXml(node)) { -// return handleEscapingHelper(node.arguments[0], true); -// } else if (isNoEscapeXml(node)) { -// return handleEscapingHelper(node.arguments[0], escaping false); -// } -// } -// -// var finalNode = handleEscapingHelper(node, true /* default to escaping */); -// return finalNode; -// } - -function removeEscapeFunctions(node) { - var walker = compiler.createWalker({ - enter: function(node, parent) { - if (isNoEscapeXml(node) || isEscapeXml(node)) { - return node.args[0]; - } - } - }); - - return walker.walk(node); -} - function generateCodeForExpressionAttr(name, value, codegen) { var flattenedConcats = flattenAttrConcats(value); var hasLiteral = false; diff --git a/compiler/ast/HtmlElement.js b/compiler/ast/HtmlElement.js index 83ab85a68..71d65dd5a 100644 --- a/compiler/ast/HtmlElement.js +++ b/compiler/ast/HtmlElement.js @@ -157,9 +157,11 @@ class HtmlElement extends Node { if (openTagOnly) { codegen.generateCode(startTag); } else { - codegen.generateCode(startTag); - codegen.generateCode(body); - codegen.generateCode(endTag); + return [ + startTag, + body, + endTag + ]; } } } diff --git a/compiler/util/removeEscapeFunctions.js b/compiler/util/removeEscapeFunctions.js new file mode 100644 index 000000000..3a57df804 --- /dev/null +++ b/compiler/util/removeEscapeFunctions.js @@ -0,0 +1,17 @@ +var compiler = require('../'); + +function removeEscapeFunctions(node) { + var walker = compiler.createWalker({ + enter: function(node, parent) { + if (node.type === 'FunctionCall' && + node.callee.type === 'Identifier' && + (node.callee.name === '$noEscapeXml' || node.callee.name === '$escapeXml')) { + return node.args[0]; + } + } + }); + + return walker.walk(node); +} + +module.exports = removeEscapeFunctions; \ No newline at end of file diff --git a/test/fixtures/render/autotest-pending/simple-handlers/expected.html b/test/fixtures/render/autotest-pending/simple-handlers/expected.html deleted file mode 100644 index 7e8e1fe33..000000000 --- a/test/fixtures/render/autotest-pending/simple-handlers/expected.html +++ /dev/null @@ -1 +0,0 @@ -