From a5410e13bf4a435b2a7ec382587584a6269743da Mon Sep 17 00:00:00 2001 From: Mathew May Date: Wed, 12 Jun 2019 10:58:58 +0800 Subject: [PATCH] MDL-65758 library: Update mustache.js to 3.0.1 --- lib/amd/build/mustache.min.js | Bin 6290 -> 5615 bytes lib/amd/src/mustache.js | 205 +++++++++++++--------------------- lib/thirdpartylibs.xml | 2 +- 3 files changed, 77 insertions(+), 130 deletions(-) diff --git a/lib/amd/build/mustache.min.js b/lib/amd/build/mustache.min.js index e28c52846bb9a9ce9ae47f6239389753c624e104..ab7d884a978b9e61971dc75d69495ac6452f60fe 100644 GIT binary patch delta 1546 zcmZuxO>7%Q6xQa~Nt)DYnuHPp_J%q;cvw4$iqdQ+Y1&56N{Fg~R>F3rwLSZ1XLhr@ zwiDZ{9D3r~5fb7AoH%f(#DODUaY5q3n~hCVmCNj#x8Hm7=6m0p zhbw<%AB{=UJ|CAp;~i=GC{4mckGe)m&t!Df(u22J?6&WE)DI7z^(bW&84XqmZI`7? zMaN~-@oCubS;|){dc7XIogX;0;pqF)9?vIM&#{xXgq9tsO`Eoe&L1S!=3NDKVqZnCSd?_4 zsHywF;kSteki##DOIfeiK@?%1+@a>q0r2g+p(_-khBOFqKyt<191w7GjA{+o1h3?9 zQ+%^I+=}-khYw<-80GLG$t`t@_q)Yhce7jUbTeJjP3N>d{`*)S%6)14V_1*Jf07vg zWMcV@C|%SD6)^tenc|FzEzw0HoVZ5PE1JV^O)ean#EI{QEuyP|SGPk&R%L{3lGj+H zUQZJEs_>JPQ#K1iomIpfv#s)mkTv7;XBQ_a zHgE+CoJg^CRyo2Hbqv>6ME4CG6HH_oIL^cM^gdzEm712#I>;hT*RH1WaEe}VN5FAn}l$uH=6(Aw3A=Ou%cuUcJ@J0_2`tFb(|TI~^IzQ6!f%(VceuJh}Yqxn-%%|D40H zF3!I^fGOXe|0>z;(JsavPNMwWbN7%9$#&rlV$>&lU|)BcxIbZF-}CJd+%DE5r2Px{ C#PrMn delta 2114 zcmZ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nOVh|0w?QxrpnP zR7#Z(cfN!$fB)1O{@Y9}7BE03{O9HqKY4s}Cp`3utv7in=Npowy* zq1nJP|0xb64ogr$IZ2U+MjYU)$)07Z!0F=UGN#3~pbH`37bhZ0g&Y=UZvk4jXWxVM z>)GpLtMX+z%Z0gx|\{|&|=|!|\$||\{|&|=|!/; /** * Breaks up the given `template` string into a tree of tokens. If the `tags` @@ -235,7 +213,7 @@ token = [ type, value, start, scanner.pos ]; tokens.push(token); - if (type === '#' || type === '^' || type === '$' || type === '<') { + if (type === '#' || type === '^') { sections.push(token); } else if (type === '/') { // Check section nesting. @@ -304,8 +282,6 @@ token = tokens[i]; switch (token[0]) { - case '$': - case '<': case '#': case '^': collector.push(token); @@ -391,7 +367,6 @@ */ function Context (view, parentContext) { this.view = view; - this.blocks = {}; this.cache = { '.': this.view }; this.parent = parentContext; } @@ -404,42 +379,6 @@ return new Context(view, this); }; - /** - * Set a value in the current block context. - */ - Context.prototype.setBlockVar = function set (name, value) { - var blocks = this.blocks; - - blocks[name] = value; - - return value; - }; - - /** - * Clear all current block vars. - */ - Context.prototype.clearBlockVars = function clearBlockVars () { - this.blocks = {}; - }; - - /** - * Get a value only from the current block context. - */ - Context.prototype.getBlockVar = function getBlockVar (name) { - var blocks = this.blocks; - - var value; - if (blocks.hasOwnProperty(name)) { - value = blocks[name]; - } else { - if (this.parent) { - value = this.parent.getBlockVar(name); - } - } - // Can return undefined. - return value; - }; - /** * Returns the value of the given name in this context, traversing * up the context hierarchy if the value is absent in this context's view. @@ -451,11 +390,11 @@ if (cache.hasOwnProperty(name)) { value = cache[name]; } else { - var context = this, names, index, lookupHit = false; + var context = this, intermediateValue, names, index, lookupHit = false; while (context) { if (name.indexOf('.') > 0) { - value = context.view; + intermediateValue = context.view; names = name.split('.'); index = 0; @@ -469,20 +408,51 @@ * * This is specially necessary for when the value has been set to * `undefined` and we want to avoid looking up parent contexts. + * + * In the case where dot notation is used, we consider the lookup + * to be successful even if the last "object" in the path is + * not actually an object but a primitive (e.g., a string, or an + * integer), because it is sometimes useful to access a property + * of an autoboxed primitive, such as the length of a string. **/ - while (value != null && index < names.length) { + while (intermediateValue != null && index < names.length) { if (index === names.length - 1) - lookupHit = hasProperty(value, names[index]); + lookupHit = ( + hasProperty(intermediateValue, names[index]) + || primitiveHasOwnProperty(intermediateValue, names[index]) + ); - value = value[names[index++]]; + intermediateValue = intermediateValue[names[index++]]; } } else { - value = context.view[name]; + intermediateValue = context.view[name]; + + /** + * Only checking against `hasProperty`, which always returns `false` if + * `context.view` is not an object. Deliberately omitting the check + * against `primitiveHasOwnProperty` if dot notation is not used. + * + * Consider this example: + * ``` + * Mustache.render("The length of a football field is {{#length}}{{length}}{{/length}}.", {length: "100 yards"}) + * ``` + * + * If we were to check also against `primitiveHasOwnProperty`, as we do + * in the dot notation case, then render call would return: + * + * "The length of a football field is 9." + * + * rather than the expected: + * + * "The length of a football field is 100 yards." + **/ lookupHit = hasProperty(context.view, name); } - if (lookupHit) + if (lookupHit) { + value = intermediateValue; break; + } context = context.parent; } @@ -513,15 +483,17 @@ }; /** - * Parses and caches the given `template` and returns the array of tokens + * Parses and caches the given `template` according to the given `tags` or + * `mustache.tags` if `tags` is omitted, and returns the array of tokens * that is generated from the parse. */ Writer.prototype.parse = function parse (template, tags) { var cache = this.cache; - var tokens = cache[template]; + var cacheKey = template + ':' + (tags || mustache.tags).join(':'); + var tokens = cache[cacheKey]; if (tokens == null) - tokens = cache[template + ':' + (tags || mustache.tags).join(':')] = parseTemplate(template, tags); + tokens = cache[cacheKey] = parseTemplate(template, tags); return tokens; }; @@ -534,11 +506,15 @@ * names and templates of partials that are used in the template. It may * also be a function that is used to load partial templates on the fly * that takes a single argument: the name of the partial. + * + * If the optional `tags` argument is given here it must be an array with two + * string values: the opening and closing tags used in the template (e.g. + * [ "<%", "%>" ]). The default is to mustache.tags. */ - Writer.prototype.render = function render (template, view, partials) { - var tokens = this.parse(template); + Writer.prototype.render = function render (template, view, partials, tags) { + var tokens = this.parse(template, tags); var context = (view instanceof Context) ? view : new Context(view); - return this.renderTokens(tokens, context, partials, template); + return this.renderTokens(tokens, context, partials, template, tags); }; /** @@ -550,7 +526,7 @@ * If the template doesn't use higher-order sections, this argument may * be omitted. */ - Writer.prototype.renderTokens = function renderTokens (tokens, context, partials, originalTemplate) { + Writer.prototype.renderTokens = function renderTokens (tokens, context, partials, originalTemplate, tags) { var buffer = ''; var token, symbol, value; @@ -561,9 +537,7 @@ if (symbol === '#') value = this.renderSection(token, context, partials, originalTemplate); else if (symbol === '^') value = this.renderInverted(token, context, partials, originalTemplate); - else if (symbol === '>') value = this.renderPartial(token, context, partials, originalTemplate); - else if (symbol === '<') value = this.renderBlock(token, context, partials, originalTemplate); - else if (symbol === '$') value = this.renderBlockVariable(token, context, partials, originalTemplate); + else if (symbol === '>') value = this.renderPartial(token, context, partials, tags); else if (symbol === '&') value = this.unescapedValue(token, context); else if (symbol === 'name') value = this.escapedValue(token, context); else if (symbol === 'text') value = this.rawValue(token); @@ -618,40 +592,12 @@ return this.renderTokens(token[4], context, partials, originalTemplate); }; - Writer.prototype.renderPartial = function renderPartial (token, context, partials) { + Writer.prototype.renderPartial = function renderPartial (token, context, partials, tags) { if (!partials) return; var value = isFunction(partials) ? partials(token[1]) : partials[token[1]]; if (value != null) - return this.renderTokens(this.parse(value), context, partials, value); - }; - - Writer.prototype.renderBlock = function renderBlock (token, context, partials, originalTemplate) { - if (!partials) return; - - var value = isFunction(partials) ? partials(token[1]) : partials[token[1]]; - if (value != null) - // Ignore any wrongly set block vars before we started. - context.clearBlockVars(); - // We are only rendering to record the default block variables. - this.renderTokens(token[4], context, partials, originalTemplate); - // Now we render and return the result. - var result = this.renderTokens(this.parse(value), context, partials, value); - // Don't leak the block variables outside this include. - context.clearBlockVars(); - return result; - }; - - Writer.prototype.renderBlockVariable = function renderBlockVariable (token, context, partials, originalTemplate) { - var value = token[1]; - - var exists = context.getBlockVar(value); - if (!exists) { - context.setBlockVar(value, originalTemplate.slice(token[3], token[5])); - return this.renderTokens(token[4], context, partials, originalTemplate); - } else { - return this.renderTokens(this.parse(exists), context, partials, exists); - } + return this.renderTokens(this.parse(value, tags), context, partials, value); }; Writer.prototype.unescapedValue = function unescapedValue (token, context) { @@ -671,7 +617,7 @@ }; mustache.name = 'mustache.js'; - mustache.version = '2.3.0'; + mustache.version = '3.0.1'; mustache.tags = [ '{{', '}}' ]; // All high-level mustache.* functions use this writer. @@ -695,16 +641,18 @@ /** * Renders the `template` with the given `view` and `partials` using the - * default writer. + * default writer. If the optional `tags` argument is given here it must be an + * array with two string values: the opening and closing tags used in the + * template (e.g. [ "<%", "%>" ]). The default is to mustache.tags. */ - mustache.render = function render (template, view, partials) { + mustache.render = function render (template, view, partials, tags) { if (typeof template !== 'string') { throw new TypeError('Invalid template! Template should be a "string" ' + 'but "' + typeStr(template) + '" was given as the first ' + 'argument for mustache#render(template, view, partials)'); } - return defaultWriter.render(template, view, partials); + return defaultWriter.render(template, view, partials, tags); }; // This is here for backwards compatibility with 0.4.x., @@ -732,4 +680,3 @@ return mustache; })); -/* jshint ignore:end */ diff --git a/lib/thirdpartylibs.xml b/lib/thirdpartylibs.xml index 85d046baea2..7a677cf1c31 100644 --- a/lib/thirdpartylibs.xml +++ b/lib/thirdpartylibs.xml @@ -226,7 +226,7 @@ amd/src/mustache.js Mustache.js MIT - 2.3.0 + 3.0.1 graphlib.php -- 2.43.0