"use strict"; function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); } function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; } function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; } function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; } function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : i + ""; } function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); } var _require = require("lodash"), assign = _require.assign; var expressionParser = require("../../expressions.js"); var angularParserIE11 = require("../../expressions-ie11.js"); var Errors = require("../../errors.js"); var _require2 = require("../utils.js"), wrapMultiError = _require2.wrapMultiError; var nbsp = String.fromCharCode(160); expressionParser.filters.upper = function (str) { if (!str) { return str; } return str.toUpperCase(); }; expressionParser.filters.sum = function (num1, num2) { return num1 + num2; }; var noInternals = { lexed: null, parsed: null, postparsed: null }; var xmlSpacePreserveTag = { type: "tag", position: "start", value: '', text: true, tag: "w:t" }; var startText = { type: "tag", position: "start", value: "", text: true, tag: "w:t" }; var endText = { type: "tag", value: "", text: true, position: "end", tag: "w:t" }; var startParagraph = { type: "tag", value: "", text: false, position: "start", tag: "w:p" }; var endParagraph = { type: "tag", value: "", text: false, position: "end", tag: "w:p" }; var tableRowStart = { type: "tag", position: "start", text: false, value: "", tag: "w:tr" }; var tableRowEnd = { type: "tag", value: "", text: false, position: "end", tag: "w:tr" }; var delimiters = { start: { type: "delimiter", position: "start" }, end: { type: "delimiter", position: "end" } }; function content(value) { return { type: "content", value: value, position: "insidetag" }; } function externalContent(value) { return { type: "content", value: value, position: "outsidetag" }; } var fixtures = [{ it: "should handle {user} with tag", content: "Hi {user}", scope: { user: "Foo" }, result: 'Hi Foo', xmllexed: [{ position: "start", tag: "w:t", text: true, type: "tag", value: "" }, { type: "content", value: "Hi {user}" }, { position: "end", tag: "w:t", text: true, type: "tag", value: "" }], lexed: [startText, content("Hi "), delimiters.start, content("user"), delimiters.end, endText], parsed: [startText, content("Hi "), { type: "placeholder", value: "user" }, endText], postparsed: [xmlSpacePreserveTag, content("Hi "), { type: "placeholder", value: "user" }, endText] }, { it: "should handle {.} with tag", content: "Hi {.}", scope: "Foo", result: 'Hi Foo', lexed: [startText, content("Hi "), delimiters.start, content("."), delimiters.end, endText], parsed: [startText, content("Hi "), { type: "placeholder", value: "." }, endText], postparsed: [xmlSpacePreserveTag, content("Hi "), { type: "placeholder", value: "." }, endText] }, _objectSpread(_objectSpread({ it: "should handle {userGreeting} with lambda function", content: "{#users}{userGreeting}{/}" }, noInternals), {}, { scope: { userGreeting: function userGreeting(scope, sm) { return "How is it going, " + scope.name + " ? " + sm.scopeLindex.length; }, users: [{ name: "John" }, { name: "Mary" }] }, result: 'How is it going, John ? 1How is it going, Mary ? 1' }), _objectSpread(_objectSpread({ it: "should handle non breaking space in tag", result: 'Hey Ho' }, noInternals), {}, { content: "{:foo".concat(nbsp).concat(nbsp, "bar").concat(nbsp, "bar} {:zing").concat(nbsp).concat(nbsp).concat(nbsp, "bang}"), options: { modules: function modules() { return [{ name: "FooModule", parse: function parse(placeHolderContent, options) { if (options.match(":foo ", placeHolderContent)) { return { type: "placeholder", value: options.getValue(":foo ", placeHolderContent) }; } if (options.match(/^:zing +(.*)/, placeHolderContent)) { return { type: "placeholder", value: options.getValue(/^:zing +(.*)/, placeHolderContent) }; } } }]; }, parser: function parser(tag) { return { get: function get() { if (tag === "bar bar") { return "Hey"; } if (tag === "bang") { return "Ho"; } return "Bad"; } }; } } }), _objectSpread(_objectSpread({ it: "should be possible to add nullGetter to module", result: 'foo' }, noInternals), {}, { content: "{foo}", options: { modules: function modules() { return [{ name: "MyModule", nullGetter: function nullGetter() { return "foo"; } }, { name: "MyModule2", nullGetter: function nullGetter() { return "bar"; } }]; } } }), _objectSpread(_objectSpread({ it: "should handle {#userGet} with lambda function", content: "{#userGet}- {name}{/}" }, noInternals), {}, { scope: { userGet: function userGet() { return [{ name: "John" }, { name: "Mary" }]; } }, result: '- John- Mary' }), _objectSpread(_objectSpread({ it: "should allow to call a function up one scope with angular expressions", content: "{#users}{hi(.)}{/}" }, noInternals), {}, { options: { parser: expressionParser }, scope: { hi: function hi(user) { return "What's up, ".concat(user, " ?"); }, users: ["John", "Jackie"] }, result: 'What's up, John ?What's up, Jackie ?' }), { it: "should xmlparse strange tags", content: "{name} {FOOageBAR}", scope: { name: "Foo", age: 12 }, result: 'Foo 12FOOBAR', xmllexed: [startText, { type: "content", value: "{name} {" }, endText, { type: "content", value: "FOO" }, startText, { type: "content", value: "age" }, endText, { type: "content", value: "BAR" }, startText, { type: "content", value: "}" }, endText], lexed: [startText, delimiters.start, content("name"), delimiters.end, content(" "), delimiters.start, endText, externalContent("FOO"), startText, content("age"), endText, externalContent("BAR"), startText, delimiters.end, endText], parsed: [startText, { type: "placeholder", value: "name" }, content(" "), { type: "placeholder", value: "age" }, endText, externalContent("FOO"), startText, endText, externalContent("BAR"), startText, endText], postparsed: null }, { it: "should work with custom delimiters", content: "Hello [[[name]]", scope: { name: "John Doe" }, result: 'Hello John Doe', delimiters: { start: "[[[", end: "]]" }, lexed: [startText, content("Hello "), delimiters.start, content("name"), delimiters.end, endText], parsed: [startText, content("Hello "), { type: "placeholder", value: "name" }, endText], postparsed: null }, { it: "should work with custom delimiters splitted", content: 'Hello {name}}, how is it ?', scope: { name: "John Doe" }, result: 'Hello John Doe, how is it ?', delimiters: { start: "{", end: "}}" }, lexed: [startText, content("Hello "), delimiters.start, content("name"), delimiters.end, endText, { type: "tag", value: '', text: true, position: "start", tag: "w:t" }, content(", how is it ?"), endText], parsed: [startText, content("Hello "), { type: "placeholder", value: "name" }, endText, { type: "tag", value: '', text: true, position: "start", tag: "w:t" }, content(", how is it ?"), endText], postparsed: null }, { it: "should work with custom delimiters splitted over > 2 tags", content: "Hello {name}}TAG}}}foobar", scope: { name: "John Doe" }, result: 'Hello John DoeTAGfoobar', delimiters: { start: "{", end: "}}}}}" }, lexed: [startText, content("Hello "), delimiters.start, content("name"), delimiters.end, endText, startText, endText, externalContent("TAG"), startText, endText, startText, content("foobar"), endText], parsed: [startText, content("Hello "), { type: "placeholder", value: "name" }, endText, startText, endText, externalContent("TAG"), startText, endText, startText, content("foobar"), endText], postparsed: null }, _objectSpread(_objectSpread({ it: "should work when having equal sign after closing tag", content: "{foo}====", scope: { foo: "FOO" } }, noInternals), {}, { result: 'FOO====' }), _objectSpread(_objectSpread({ it: "should fail when having two open text tags", content: "xxx" }, noInternals), {}, { error: { message: "Malformed xml", name: "InternalError", properties: { id: "malformed_xml", explanation: "The template contains malformed xml" } }, errorType: Errors.XTInternalError }), _objectSpread(_objectSpread({ it: "should fail when having two close text tags", content: "xxx" }, noInternals), {}, { error: { message: "Malformed xml", name: "InternalError", properties: { id: "malformed_xml", explanation: "The template contains malformed xml" } }, errorType: Errors.XTInternalError }), _objectSpread(_objectSpread({ it: "should show multierror with loops", content: "{#a}{b}{/a}" }, noInternals), {}, { options: { parser: function parser() { return { get: function get() { throw new Error("Foobar"); } }; } }, error: wrapMultiError({ name: "ScopeParserError", message: "Scope parser execution failed", properties: { explanation: "The scope parser for the tag a failed to execute", rootError: { message: "Foobar" }, file: "word/document.xml", id: "scopeparser_execution_failed", xtag: "a", offset: 0 } }), errorType: Errors.XTTemplateError }), _objectSpread(_objectSpread({ it: "should show multierror with loops", content: "{#a}{b}{/a}" }, noInternals), {}, { options: { parser: function parser(tag) { return { get: function get(scope) { if (tag === "a") { return scope[tag]; } throw new Error("Foobar"); } }; } }, scope: { a: [1] }, error: wrapMultiError({ name: "ScopeParserError", message: "Scope parser execution failed", properties: { explanation: "The scope parser for the tag b failed to execute", rootError: { message: "Foobar" }, file: "word/document.xml", id: "scopeparser_execution_failed", scope: 1, xtag: "b", offset: 4 } }), errorType: Errors.XTTemplateError }), { it: "should work with loops", content: "Hello {#users}{name}, {/users}", scope: { users: [{ name: "John Doe" }, { name: "Jane Doe" }, { name: "Wane Doe" }] }, result: 'Hello John Doe, Jane Doe, Wane Doe, ', lexed: [startText, content("Hello "), delimiters.start, content("#users"), delimiters.end, delimiters.start, content("name"), delimiters.end, content(", "), delimiters.start, content("/users"), delimiters.end, endText], parsed: [startText, content("Hello "), { type: "placeholder", value: "users", location: "start", module: "loop", inverted: false, expandTo: "auto" }, { type: "placeholder", value: "name" }, content(", "), { type: "placeholder", value: "users", location: "end", module: "loop" }, endText], postparsed: [xmlSpacePreserveTag, content("Hello "), { type: "placeholder", value: "users", module: "loop", inverted: false, sectPrCount: 0, subparsed: [{ type: "placeholder", value: "name" }, content(", ")] }, endText] }, { it: "should work with paragraph loops", content: "Hello {#users}User {.}{/users}", options: { paragraphLoop: true }, scope: { users: ["John Doe", "Jane Doe", "Wane Doe"] }, result: 'Hello User John DoeUser Jane DoeUser Wane Doe', lexed: [startParagraph, startText, content("Hello "), endText, endParagraph, startParagraph, startText, delimiters.start, content("#users"), delimiters.end, endText, endParagraph, startParagraph, startText, content("User "), delimiters.start, content("."), delimiters.end, endText, endParagraph, startParagraph, startText, delimiters.start, content("/users"), delimiters.end, endText, endParagraph], parsed: [startParagraph, startText, content("Hello "), endText, endParagraph, startParagraph, startText, { type: "placeholder", value: "users", location: "start", module: "loop", inverted: false, expandTo: "auto" }, endText, endParagraph, startParagraph, startText, content("User "), { type: "placeholder", value: "." }, endText, endParagraph, startParagraph, startText, { type: "placeholder", value: "users", location: "end", module: "loop" }, endText, endParagraph], postparsed: [startParagraph, startText, content("Hello "), endText, endParagraph, { type: "placeholder", value: "users", module: "loop", paragraphLoop: true, sectPrCount: 0, hasPageBreak: false, hasPageBreakBeginning: false, inverted: false, subparsed: [startParagraph, xmlSpacePreserveTag, content("User "), { type: "placeholder", value: "." }, endText, endParagraph] }] }, { it: "should work with paragraph loops and selfclosing paragraphs", content: "{#foo}{/}", options: { paragraphLoop: true }, scope: { foo: true }, result: "", lexed: null, parsed: null, postparsed: null }, _objectSpread(_objectSpread({ it: "should not fail with nested loops if using paragraphLoop", content: "{#users} {#pets}Pet {.}{/pets}{/users}" }, noInternals), {}, { options: { paragraphLoop: true }, scope: { users: [{ pets: ["Cat", "Dog"] }, { pets: ["Cat", "Dog"] }] }, result: ' Pet CatPet Dog Pet CatPet Dog' }), { it: "should work with spacing loops", content: "{#condition} hello{/condition}", scope: { condition: true }, result: ' hello', lexed: [startText, delimiters.start, content("#condition"), endText, startText, delimiters.end, content(" hello"), delimiters.start, content("/"), endText, startText, content("condition"), delimiters.end, endText], parsed: [startText, { type: "placeholder", value: "condition", location: "start", module: "loop", inverted: false, expandTo: "auto" }, endText, startText, content(" hello"), { type: "placeholder", value: "condition", location: "end", module: "loop" }, endText, startText, endText], postparsed: null }, _objectSpread(_objectSpread({ it: "should work with spacing loops 2" }, noInternals), {}, { content: "{#condition}{text}{/condition}", scope: { condition: [{ text: " hello " }] }, result: ' hello ' }), _objectSpread(_objectSpread({ it: "should work with empty condition" }, noInternals), {}, { content: "{#a}A{/a}{^b}{/b}", scope: { a: true }, result: 'A' }), _objectSpread(_objectSpread({ it: "should work with spacing loops 3" }, noInternals), {}, { content: "{#condition}{/condition} foo", scope: { condition: false }, result: ' foo' }), _objectSpread(_objectSpread({ it: "should work with spacing loops 4" }, noInternals), {}, { content: "{#condition}foo{/condition}", scope: { condition: false }, result: "" }), { it: "should work with dashloops", content: "Hello {-w:p users}{name}, {/users}", scope: { users: [{ name: "John Doe" }, { name: "Jane Doe" }, { name: "Wane Doe" }] }, result: 'Hello John Doe, Hello Jane Doe, Hello Wane Doe, ', lexed: [startParagraph, startText, content("Hello "), delimiters.start, content("-w:p users"), delimiters.end, delimiters.start, content("name"), delimiters.end, content(", "), delimiters.start, content("/users"), delimiters.end, endText, endParagraph], parsed: [startParagraph, startText, content("Hello "), { type: "placeholder", value: "users", location: "start", module: "loop", inverted: false, expandTo: "w:p" }, { type: "placeholder", value: "name" }, content(", "), { type: "placeholder", value: "users", location: "end", module: "loop" }, endText, endParagraph], postparsed: [{ type: "placeholder", value: "users", module: "loop", inverted: false, sectPrCount: 0, subparsed: [startParagraph, xmlSpacePreserveTag, content("Hello "), { type: "placeholder", value: "name" }, content(", "), endText, endParagraph] }] }, { it: "should work with dashloops nested", content: "{-w:tr columns} Hello {-w:p users}{name}, {/users}{/columns}", scope: { columns: [{ users: [{ name: "John Doe" }, { name: "Jane Doe" }, { name: "Wane Doe" }] }] }, result: ' Hello John Doe, Hello Jane Doe, Hello Wane Doe, ', lexed: [tableRowStart, startParagraph, startText, delimiters.start, content("-w:tr columns"), delimiters.end, content(" Hello "), delimiters.start, content("-w:p users"), delimiters.end, delimiters.start, content("name"), delimiters.end, content(", "), delimiters.start, content("/users"), delimiters.end, endText, startText, delimiters.start, content("/columns"), delimiters.end, endText, endParagraph, tableRowEnd], parsed: [tableRowStart, startParagraph, startText, { type: "placeholder", value: "columns", location: "start", module: "loop", inverted: false, expandTo: "w:tr" }, content(" Hello "), { type: "placeholder", value: "users", location: "start", module: "loop", inverted: false, expandTo: "w:p" }, { type: "placeholder", value: "name" }, content(", "), { type: "placeholder", value: "users", location: "end", module: "loop" }, endText, startText, { type: "placeholder", value: "columns", location: "end", module: "loop" }, endText, endParagraph, tableRowEnd], postparsed: null }, { it: "should handle selfclose tag", content: "", scope: { user: "Foo" }, result: "", lexed: [{ type: "tag", value: "", text: true, position: "selfclosing", tag: "w:t" }], parsed: [{ type: "tag", position: "selfclosing", value: "", text: true, tag: "w:t" }], postparsed: [{ type: "tag", position: "selfclosing", value: "", text: true, tag: "w:t" }] }, { it: "should handle {user} with tag with selfclosing", content: "Hi {user}", scope: { user: "Foo" }, result: 'Hi Foo', lexed: [{ type: "tag", value: "", text: true, position: "selfclosing", tag: "w:t" }, startText, content("Hi "), delimiters.start, content("user"), delimiters.end, endText], parsed: [{ type: "tag", position: "selfclosing", value: "", text: true, tag: "w:t" }, startText, content("Hi "), { type: "placeholder", value: "user" }, endText], postparsed: [{ type: "tag", position: "selfclosing", value: "", text: true, tag: "w:t" }, xmlSpacePreserveTag, content("Hi "), { type: "placeholder", value: "user" }, endText] }, { it: "should be possible to change the delimiters", content: "Hi {=[[ ]]=}[[user]][[={ }=]] and {user2}", scope: { user: "John", user2: "Jane" }, result: 'Hi John and Jane', lexed: [startText, content("Hi "), delimiters.start, content("user"), delimiters.end, content(" and "), delimiters.start, content("user2"), delimiters.end, endText], parsed: [startText, content("Hi "), { type: "placeholder", value: "user" }, content(" and "), { type: "placeholder", value: "user2" }, endText], postparsed: [xmlSpacePreserveTag, content("Hi "), { type: "placeholder", value: "user" }, content(" and "), { type: "placeholder", value: "user2" }, endText] }, { it: "should be possible to change the delimiters", content: "Hi {=a b c=}", error: { name: "TemplateError", message: "New Delimiters cannot be parsed", properties: { id: "change_delimiters_invalid" } }, errorType: Errors.XTTemplateError }, { it: "should throw error if delimiters invalid", content: "Hi {= =}", error: { name: "TemplateError", message: "New Delimiters cannot be parsed", properties: { id: "change_delimiters_invalid" } }, errorType: Errors.XTTemplateError }, { it: "should throw error if delimiters invalid (2)", content: "Hi {=[ =}", error: { name: "TemplateError", message: "New Delimiters cannot be parsed", properties: { id: "change_delimiters_invalid" } }, errorType: Errors.XTTemplateError }, { it: "should throw error if delimiters invalid (3)", content: "Hi {= ]=}", error: { name: "TemplateError", message: "New Delimiters cannot be parsed", properties: { id: "change_delimiters_invalid" } }, errorType: Errors.XTTemplateError }, { it: "should be possible to change the delimiters with complex example", content: "Hi {={{[ ]}}=}{{[user]}}{{[={{ ]=]}} and {{user2]", scope: { user: "John", user2: "Jane" }, result: 'Hi John and Jane', lexed: [startText, content("Hi "), delimiters.start, content("user"), delimiters.end, content(" and "), delimiters.start, content("user2"), delimiters.end, endText], parsed: [startText, content("Hi "), { type: "placeholder", value: "user" }, content(" and "), { type: "placeholder", value: "user2" }, endText], postparsed: [xmlSpacePreserveTag, content("Hi "), { type: "placeholder", value: "user" }, content(" and "), { type: "placeholder", value: "user2" }, endText] }, _objectSpread(_objectSpread({ it: "should resolve the data correctly" }, noInternals), {}, { content: "{test}{#test}{label}{/test}{test}", scope: { label: "T1", test: true }, resolved: [{ tag: "test", lIndex: 3, value: true }, { tag: "test", lIndex: 15, value: true }, { tag: "test", lIndex: 6, value: [[{ tag: "label", lIndex: 9, value: "T1" }]] }], result: 'trueT1true' }), _objectSpread(_objectSpread({ it: "should resolve 2 the data correctly" }, noInternals), {}, { content: "{^a}{label}{/a}", scope: { a: true }, resolved: [{ tag: "a", lIndex: 3, value: [] }], result: "" }), _objectSpread(_objectSpread({ it: "should resolve 3 the data correctly" }, noInternals), {}, { content: "{#frames}{#true}{label}{#false}{label}{/false}{/true}{#false}{label}{/false}{/frames}", scope: { frames: [{ label: "T1", "true": true }] }, resolved: [{ tag: "frames", lIndex: 3, value: [[{ tag: "false", lIndex: 24, value: [] }, { tag: "true", lIndex: 6, value: [[{ tag: "label", lIndex: 9, value: "T1" }, { tag: "false", lIndex: 12, value: [] }]] }]] }], result: 'T1' }), _objectSpread(_objectSpread({ it: "should resolve truthy data correctly", content: "{#loop}L{#cond2}{label}{/cond2}{#cond3}{label}{/cond3}{/loop}" }, noInternals), {}, { scope: { label: "outer", loop: [{ cond2: true, label: "inner" }] }, resolved: null, result: 'Linner' }), _objectSpread(_objectSpread({ it: "should resolve truthy multi data correctly", content: "{#loop}L{#cond2}{label}{/cond2}{#cond3}{label}{/cond3}{/loop}" }, noInternals), {}, { scope: { label: "outer", loop: [{ cond2: true, label: "inner" }, { cond2: true, label: "inner" }, { cond3: true, label: "inner" }, { cond2: true, cond3: true }] }, resolved: null, result: 'LinnerLinnerLinnerLouterouter' }), _objectSpread(_objectSpread({ it: "should resolve async loop", content: "{#loop}{#cond1}{label}{/}{#cond2}{label}{/}{/loop}" }, noInternals), {}, { scope: { label: "outer", loop: [{ cond1: true, label: "inner" }, { cond1: true, cond2: true }] }, resolved: null, result: 'innerouterouter' }), _objectSpread(_objectSpread({ it: "should work well with inversed loop simple", content: "{^b}{label}{/}" }, noInternals), {}, { scope: { b: false, label: "hi" }, resolved: null, result: 'hi' }), _objectSpread(_objectSpread({ it: "should work well with nested inversed loop", content: "{#a}{^b}{label}{/}{/}" }, noInternals), {}, { scope: { a: [{ b: false, label: "hi" }] }, resolved: null, result: 'hi' }), _objectSpread(_objectSpread({ it: "should work well with deeply nested inversed loop nested", content: "{#a}{^b}{^c}{label}{/}{/}{/}" }, noInternals), {}, { scope: { a: [{ b: false, label: "hi" }] }, resolved: null, result: 'hi' }), _objectSpread(_objectSpread({ it: "should work well with true value for condition", content: "{#cond}{#product.price > 10}high{/}{#product.price <= 10}low{/}{/cond}" }, noInternals), {}, { options: { parser: expressionParser }, scope: { cond: true, product: { price: 2 } }, resolved: null, result: 'low' }), _objectSpread(_objectSpread({ it: "should handle {this+this+this} tag", scope: "Foo" }, noInternals), {}, { content: "Hi {this+this+this}", options: { parser: expressionParser }, result: 'Hi FooFooFoo' }), _objectSpread(_objectSpread({ it: "should handle {((.+.+.)*.*0.5)|sum:.} tag", scope: 2 }, noInternals), {}, { content: "Hi {((((.+.+.)*.*0.5)|sum:.)-.)/.}", // = (((2 + 2 + 2)*2 * 0.5 | sum:2)-2)/2 // = (((6)*2 * 0.5 | sum:2)-2)/2 // = ((6 | sum:2)-2)/2 // = ((8)-2)/2 // = (6)/2 // = 3 options: { parser: expressionParser }, result: 'Hi 3' }), _objectSpread(_objectSpread({ it: "should handle {.['user-name']} tag", scope: { "user-name": "John" } }, noInternals), {}, { content: "Hi {.['user-name']}", options: { parser: expressionParser }, result: 'Hi John' }), _objectSpread(_objectSpread({ it: 'should handle {this["a b"]} tag', scope: { "a b": "John" } }, noInternals), {}, { content: 'Hi {this["a b"]}', options: { parser: expressionParser }, result: 'Hi John' }), _objectSpread(_objectSpread({ it: 'should handle {this["length"]} tag', scope: "John" }, noInternals), {}, { content: 'Hi { this["length"]}', options: { parser: expressionParser }, result: 'Hi 4' }), _objectSpread(_objectSpread({ it: 'should handle {this["split"]} tag', scope: "John" }, noInternals), {}, { content: 'Hi {this["split"]}', options: { parser: expressionParser }, result: 'Hi undefined' }), _objectSpread(_objectSpread({ it: "should handle {this.split} tag", scope: "John" }, noInternals), {}, { content: "Hi {this.split}", options: { parser: expressionParser }, result: 'Hi undefined' }), _objectSpread(_objectSpread({ it: "should handle {(this+this+this)*this} tag", scope: 1 }, noInternals), {}, { content: "Hi {(this+this+this)*(this+this)}", options: { parser: expressionParser }, result: 'Hi 6' }), _objectSpread(_objectSpread({ it: "should handle {(this+this+this)*(this+this)}, this=0 tag", scope: 0 }, noInternals), {}, { content: "Hi {( this + this + this)*(this+this)}", options: { parser: expressionParser }, result: 'Hi 0' }), _objectSpread(_objectSpread({ it: "should handle {#products}{# . }-{ . }-{/}{/}", scope: { products: [[1, 2, 3, 4], [4, 5, 6, 7]] } }, noInternals), {}, { // The space inside {# . } is important. // It tests a regression that was fixed in version 3.37.12 content: "Hi {#products}{# . }-{ . }-{/}{/}", options: { parser: expressionParser }, result: 'Hi -1--2--3--4--4--5--6--7-' }), _objectSpread(_objectSpread({ it: "should work well with int value for condition", content: "{#cond}{#product.price > 10}high{/}{#product.price <= 10}low{/}{/cond}" }, noInternals), {}, { options: { parser: expressionParser }, scope: { cond: 10, product: { price: 2 } }, resolved: null, result: 'low' }), _objectSpread(_objectSpread({ it: "should work well with empty string as result", content: "{foo}" }, noInternals), {}, { options: { parser: expressionParser }, scope: { foo: "" }, resolved: null, result: "" }), _objectSpread(_objectSpread({ it: "should work well with str value for condition", content: "{#cond}{#product.price > 10}high{/}{#product.price <= 10}low{/}{/cond}" }, noInternals), {}, { options: { parser: expressionParser }, scope: { cond: "cond", product: { price: 2 } }, resolved: null, result: 'low' }), _objectSpread(_objectSpread({ it: "should work well with false value for condition", content: "{^cond}{#product.price > 10}high{/}{#product.price <= 10}low{/}{/cond}" }, noInternals), {}, { options: { parser: expressionParser }, scope: { cond: false, product: { price: 2 } }, resolved: null, result: 'low' }), _objectSpread(_objectSpread({ it: "should work well with multi level angular parser", // This tag was designed to match /-([^\s]+)\s(.+)$/ which is the prefix of the dash loop content: "{#users}{name} {date-age+ offset} {/}" }, noInternals), {}, { options: { parser: expressionParser }, scope: { date: 2019, offset: 1, users: [{ name: "John", age: 44 }, { name: "Mary", age: 22 }, { date: 2100, age: 22, name: "Walt" }] }, resolved: null, result: 'John 1976 Mary 1998 Walt 2079 ' }), _objectSpread(_objectSpread({ it: "should work well with $index angular parser", content: "{#todos}{#$index==0}FIRST {/}{text} {/todos}" }, noInternals), {}, { options: { parser: expressionParser }, scope: { todos: [{ text: "Hello" }, { text: "Other todo" }] }, result: 'FIRST Hello Other todo ' }), _objectSpread(_objectSpread({ it: "should work well with $index inside condition angular parser", content: "{#todos}{#important}!!{$index+1}{text}{/}{^important}?{$index+1}{text}{/}{/}" }, noInternals), {}, { options: { parser: expressionParser }, scope: { todos: [{ important: true, text: "Hello" }, { text: "Other todo" }, { important: true, text: "Bye" }] }, result: '!!1Hello?2Other todo!!3Bye' }), _objectSpread(_objectSpread({ it: "should work well with $index inside condition angular parser", content: "{#todos}{#important}!!{$index+1}{text}{/}{^important}?{$index+1}{text}{/}{/}" }, noInternals), {}, { options: { parser: angularParserIE11 }, scope: { todos: [{ important: true, text: "Hello" }, { text: "Other todo" }, { important: true, text: "Bye" }] }, result: '!!1Hello?2Other todo!!3Bye' }), _objectSpread(_objectSpread({ it: "should work well with -w:tr conditions inside table inside paragraphLoop condition" }, noInternals), {}, { content: "{#cond}{-w:tc cond}{val}{/}{/}", options: { paragraphLoop: true }, scope: { cond: true, val: "yep" }, resolved: null, result: 'yep' }), _objectSpread(_objectSpread({ it: "should work well with nested angular expressions", content: "{v}{#c1}{v}{#c2}{v}{#c3}{v}{/}{/}{/}" }, noInternals), {}, { options: { parser: expressionParser }, scope: { v: "0", c1: { v: "1", c2: { v: "2", c3: { v: "3" } } } }, resolved: null, result: '0123' }), _objectSpread(_objectSpread({ it: "should work with this with angular expressions", content: "{#hello}{this}{/hello}" }, noInternals), {}, { options: { parser: expressionParser }, scope: { hello: ["world"] }, resolved: null, result: 'world' }), _objectSpread(_objectSpread({ it: "should be possible to close loops with {/}", content: "{#products}Product {name}{/}" }, noInternals), {}, { scope: { products: [{ name: "Bread" }] }, result: 'Product Bread' }), _objectSpread(_objectSpread({ it: "should get parent prop if child is null", content: "{#c}{label}{/c}" }, noInternals), {}, { options: { parser: expressionParser }, scope: { c: { label: null }, label: "hello" }, resolved: null, result: 'hello' }), _objectSpread(_objectSpread({ it: "should work when using double nested arrays", content: "{#a}{this}{/}" }, noInternals), {}, { options: { parser: expressionParser }, scope: { a: [["first-part", "other-part"]] }, resolved: null, result: 'first-part,other-part' }), _objectSpread(_objectSpread({ it: "should work when using accents or numbers in variable names, ...", content: "{êtreîöò12áeêëẽ}" }, noInternals), {}, { options: { parser: expressionParser }, scope: {}, resolved: null, result: 'undefined' }), _objectSpread(_objectSpread({ it: "should fail when using € sign", content: "{hello€}" }, noInternals), {}, { options: { parser: expressionParser }, scope: {}, error: wrapMultiError({ name: "ScopeParserError", message: "Scope parser compilation failed", properties: { explanation: 'The scope parser for the tag "hello€" failed to compile', rootError: { message: "[$parse:lexerr] Lexer Error: Unexpected next character at columns 5-5 [\u20AC] in expression [hello\u20AC].\nhttp://errors.angularjs.org/\"NG_VERSION_FULL\"/$parse/lexerr?p0=Unexpected%20next%20character%20&p1=s%205-5%20%5B%E2%82%AC%5D&p2=hello%E2%82%AC" }, file: "word/document.xml", id: "scopeparser_compilation_failed", xtag: "hello€", offset: 0 } }), errorType: Errors.XTTemplateError, resolved: null, result: 'undefined' }), _objectSpread(_objectSpread({ it: "should disallow access to internal property", content: '{"".split.toString()}' }, noInternals), {}, { options: { parser: expressionParser }, scope: {}, resolved: null, result: 'undefined' }), _objectSpread(_objectSpread({ it: "should allow filters like | upper", content: "{name | upper}" }, noInternals), {}, { options: { parser: expressionParser }, scope: { name: "john" }, resolved: null, result: 'JOHN' }), _objectSpread(_objectSpread({ it: "should work when using angular assignment that is already in the scope", content: "{b=a}{b}" }, noInternals), {}, { options: { parser: expressionParser }, scope: { a: 10, b: 5 }, resolved: null, result: '10' }), _objectSpread(_objectSpread({ it: "should work with linebreaks", content: "{b}" }, noInternals), {}, { options: { linebreaks: true, parser: expressionParser }, scope: { b: "Hello\n\nFoo\n\nBar\n\n" }, result: 'HelloFooBar' }), _objectSpread(_objectSpread({ it: "should not fail with no scope on expressionParser", content: "{b}" }, noInternals), {}, { options: { linebreaks: true, parser: expressionParser }, result: 'undefined' }), _objectSpread(_objectSpread({ it: "should be possible to add filter for one instance of the expressionParser", content: "{b|foo}" }, noInternals), {}, { options: { linebreaks: true, parser: expressionParser.configure({ filters: { foo: function foo() { return "FOO"; } } }) }, result: 'FOO' }), _objectSpread(_objectSpread({ it: "should be possible to add filter for one instance of the ie11 parser", content: "{b|foo}" }, noInternals), {}, { options: { linebreaks: true, parser: angularParserIE11.configure({ csp: true, filters: { foo: function foo() { return "FOO"; } } }) }, result: 'FOO' }), _objectSpread(_objectSpread({ it: "should not fail with no scope on ie11 parser", content: "{b}" }, noInternals), {}, { options: { linebreaks: true, parser: angularParserIE11 }, result: 'undefined' }), { it: "should work for table with nested loops", content: "\n\t\t{#c1}A\n\t\t{/}{#c2}B{/}\n", error: wrapMultiError({ name: "TemplateError", message: "Unbalanced loop tag", properties: { explanation: "Unbalanced loop tags {#c1}{/}{#c2}{/}", file: "word/document.xml", id: "unbalanced_loop_tags", lastPair: { left: "c1", right: "" }, offset: [0, 15], pair: { left: "c2", right: "" } } }), errorType: Errors.XTTemplateError }, { it: "should not escape explanation for unclosed tag with &&", content: "Unclosed tag : {Hi&&Ho", error: wrapMultiError({ name: "TemplateError", message: "Unclosed tag", properties: { explanation: 'The tag beginning with "{Hi&&Ho" is unclosed', context: "{Hi&&Ho", xtag: "Hi&&Ho", file: "word/document.xml", id: "unclosed_tag", offset: 15 } }), errorType: Errors.XTTemplateError }, { it: "should not escape explanation for unopened tag with &&", content: "&&foo}", error: wrapMultiError({ name: "TemplateError", message: "Unopened tag", properties: { explanation: 'The tag beginning with "&&foo" is unopened', context: "&&foo", xtag: "&&foo", file: "word/document.xml", id: "unopened_tag", offset: null } }), errorType: Errors.XTTemplateError }, { it: "should not escape explanation for unclosed loop with &&", content: "Unclosed tag : {#Hi&&Ho}{/%%><&&bar}", error: wrapMultiError({ name: "TemplateError", message: "Closing tag does not match opening tag", properties: { explanation: 'The tag "Hi&&Ho" is closed by the tag "%%><&&bar"', file: "word/document.xml", openingtag: "Hi&&Ho", closingtag: "%%><&&bar", id: "closing_tag_does_not_match_opening_tag", offset: [15, 32] } }), errorType: Errors.XTTemplateError }, { it: "should not escape explanation for duplicate opening with &&", content: "Unclosed tag : {Hi&&{foo", error: { message: "Multi error", name: "TemplateError", properties: { id: "multi_error", errors: [{ name: "TemplateError", message: "Unclosed tag", properties: { context: "{Hi&&", xtag: "Hi&&", explanation: 'The tag beginning with "{Hi&&" is unclosed', file: "word/document.xml", id: "unclosed_tag", offset: null } }, { name: "TemplateError", message: "Unclosed tag", properties: { context: "{foo", xtag: "foo", explanation: 'The tag beginning with "{foo" is unclosed', file: "word/document.xml", id: "unclosed_tag", offset: null } }] } }, errorType: Errors.XTTemplateError }, _objectSpread(_objectSpread({ it: "should add space=preserve to last tag" }, noInternals), {}, { content: "\n \n Hello {firstName} {\n \n \n lastName\n \n \n } world\n \n ", result: "\n \n Hello undefined undefined\n \n \n \n \n \n world\n \n " }), _objectSpread(_objectSpread({ it: "should not fail on SPACED unopened tag if allowUnopenedTag is true" }, noInternals), {}, { content: "\n \n Hello firstName} {\n \n \n lastName\n \n \n } } world} } }\n \n ", options: { syntax: { allowUnopenedTag: true } }, scope: { firstName: "John", lastName: "Doe" }, result: "\n \n Hello firstName} Doe\n \n \n \n \n \n } world} } }\n \n " }), _objectSpread(_objectSpread({ it: "should not fail on unopened tag if allowUnopenedTag is true" }, noInternals), {}, { content: "\n \n Hello firstName} {\n \n \n lastName\n \n \n }} world}}}\n \n }", options: { syntax: { allowUnopenedTag: true } }, scope: { firstName: "John", lastName: "Doe" }, result: "\n \n Hello firstName} Doe\n \n \n \n \n \n } world}}}\n \n }" }), _objectSpread(_objectSpread({ it: "should add space=preserve to last tag when having middle tag" }, noInternals), {}, { content: "\n\t\t\n\t\t\tHello {\n\t\t\n\t\t\n\t\t\tlast_name\n\t\t\n\t\t\n\t\t\t} {\n\t\t\n\t\t\n\t\t\tfirst_name\n\t\t\n\t\t\n\t\t\t} what's up ?\n\t\t\n ", result: "\n\t\t\n\t\t\tHello undefined\n\t\t\n\t\t\n\t\t\t\n\t\t\n\t\t\n\t\t\t undefined\n\t\t\n\t\t\n\t\t\t\n\t\t\n\t\t\n\t\t\t what's up ?\n\t\t\n " }), _objectSpread(_objectSpread({ it: "should parse self closing tags", content: '' }, noInternals), {}, { result: null, xmllexed: [{ position: "start", tag: "w:pPr", type: "tag", text: false, value: "" }, { position: "selfclosing", tag: "w:spacing", type: "tag", text: false, value: '' }, { position: "end", tag: "w:pPr", type: "tag", text: false, value: "" }] }), _objectSpread(_objectSpread({ it: "should not fail with empty loop inside loop", content: "A{#a}\n\t\t{#c}{/}{/}" }, noInternals), {}, { result: 'A' }), _objectSpread(_objectSpread({ // The specificity of this input is that it contains : // So in the algorithm that updates the height of the table, those tags should be ignored it: "should work with table pptx nested and empty 'ext' element" }, noInternals), {}, { content: "\n\n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n ABC\n \n \n \n \n \n \n \n \n \n \n \n DEF\n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n {#loop1}{#loop2}\n \n \n {name}\n \n \n {/}{#loop3}\n \n \n TTT\n \n \n {/}\n \n \n \n \n \n \n \n \n \n \n \n {#loop3}\n \n \n {name}\n \n \n {/}{#loop4}\n \n \n DEF\n \n \n {/}{/loop1}\n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n", scope: { loop1: [1, 2, 3], loop2: [1, 2, 3] }, result: "\n\n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n ABC\n \n \n \n \n \n \n \n \n \n \n \n DEF\n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n undefined\n \n \n \n \n \n undefined\n \n \n \n \n \n undefined\n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n undefined\n \n \n \n \n \n undefined\n \n \n \n \n \n undefined\n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n undefined\n \n \n \n \n \n undefined\n \n \n \n \n \n undefined\n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n", pptx: true })]; var rawXmlTest = { it: "should work with rawxml", content: "BEFORE{@rawxml}AFTER", scope: { rawxml: 'My customXML' }, result: 'BEFOREMy customXMLAFTER', lexed: [externalContent("BEFORE"), startParagraph, startText, delimiters.start, content("@rawxml"), delimiters.end, endText, endParagraph, externalContent("AFTER")], parsed: [externalContent("BEFORE"), startParagraph, startText, { type: "placeholder", value: "rawxml", module: "rawxml" }, endText, endParagraph, externalContent("AFTER")], postparsed: [externalContent("BEFORE"), { type: "placeholder", value: "rawxml", module: "rawxml", expanded: [[startParagraph, xmlSpacePreserveTag], [endText, endParagraph]] }, externalContent("AFTER")] }; fixtures.push(rawXmlTest); fixtures.push(_objectSpread(_objectSpread({}, rawXmlTest), {}, { it: "should work with rawxml with undefined tags", scope: {}, result: "BEFOREAFTER" })); fixtures.push(_objectSpread(_objectSpread({}, rawXmlTest), {}, { it: "should throw error with rawxml with scope that is an integer", scope: { rawxml: 11 }, error: wrapMultiError({ name: "RenderingError", message: "Non string values are not allowed for rawXML tags", properties: { explanation: "The value of the raw tag : 'rawxml' is not a string", file: "word/document.xml", id: "invalid_raw_xml_value", value: 11, xtag: "rawxml", offset: 0 } }), errorType: Errors.XTTemplateError })); fixtures.forEach(function (fixture) { var delimiters = { delimiters: fixture.delimiters || { start: "{", end: "}" } }; fixture.options = assign({}, fixture.options, delimiters); }); module.exports = fixtures;