'use strict'; var ok = require('assert').ok; var AttributePlaceholder = require('./ast/AttributePlaceholder'); var COMPILER_ATTRIBUTE_HANDLERS = { 'preserve-whitespace': function(attr, context) { context.setPreserveWhitespace(true); }, 'preserve-comments': function(attr, context) { context.setPreserveComments(true); } }; var ieConditionalCommentRegExp = /^\[if [^]*?, argument will be "color in colors" if (argument) { argument = argument.value; } if (tagName === 'compiler-options') { attributes.forEach(function (attr) { let attrName = attr.name; let handler = COMPILER_ATTRIBUTE_HANDLERS[attrName]; if (!handler) { context.addError({ code: 'ERR_INVALID_COMPILER_OPTION', message: 'Invalid Marko compiler option of "' + attrName + '". Allowed: ' + Object.keys(COMPILER_ATTRIBUTE_HANDLERS).join(', '), pos: el.pos, node: el }); return; } handler(attr, context); }); return; } this.prevTextNode = null; var elDef = { tagName: tagName, argument: argument, openTagOnly: el.openTagOnly === true, selfClosed: el.selfClosed === true, pos: el.pos, attributes: attributes.map((attr) => { var attrValue; if (attr.hasOwnProperty('literalValue')) { attrValue = builder.literal(attr.literalValue); } else if (attr.value == null) { attrValue = undefined; } else { let parsedExpression = builder.parseExpression(attr.value); attrValue = replacePlaceholderEscapeFuncs(parsedExpression, context); } var attrDef = { name: attr.name, value: attrValue, rawValue: attr.value }; if (attr.argument) { // TODO Do something with the argument pos attrDef.argument = attr.argument.value; } return attrDef; }) }; var node = this.context.createNodeForEl(elDef); var tagDef = node.tagDef; if (node.tagDef) { var body = tagDef.body; if (body) { } } this.parentNode.appendChild(node); this.stack.push({ node: node, tag: null }); } handleEndElement(elementName) { if (elementName === 'compiler-options') { return; } this.prevTextNode = null; this.stack.pop(); } handleComment(comment) { this.prevTextNode = null; var builder = this.context.builder; var preserveComment = this.context.isPreserveComments() || isIEConditionalComment(comment); if (preserveComment) { var commentNode = builder.htmlComment(builder.literal(comment)); this.parentNode.appendChild(commentNode); } } handleBodyTextPlaceholder(expression, escape) { this.prevTextNode = null; var builder = this.context.builder; var parsedExpression = builder.parseExpression(expression); var preserveWhitespace = true; var text = builder.text(parsedExpression, escape, preserveWhitespace); this.parentNode.appendChild(text); } handleScriptlet(code) { this.prevTextNode = null; var builder = this.context.builder; var scriptlet = builder.scriptlet(code); this.parentNode.appendChild(scriptlet); } handleError(event) { this.context.addError({ message: event.message, code: event.code, pos: event.pos, endPos: event.endPos }); } get parentNode() { var last = this.stack[this.stack.length-1]; return last.node; } getParserStateForTag(el) { var attributes = el.attributes; for (var i=0; i