diff --git a/lib/utils/html-tag.html b/lib/utils/html-tag.html index 6745e2cce4..e6189cde7c 100644 --- a/lib/utils/html-tag.html +++ b/lib/utils/html-tag.html @@ -12,28 +12,68 @@ (function() { 'use strict'; + /** + * Class representing a static string value which can be used to filter + * strings by asseting that they have been created via this class. The + * `value` property returns the string passed to the constructor. + */ + class LiteralString { + constructor(string) { + /** @type {string} */ + this.value = string.toString(); + } + /** + * @return {string} LiteralString string value + */ + toString() { + return this.value; + } + } + + /** + * @param {*} value Object to stringify into HTML + * @return {string} HTML stringified form of `obj` + */ + function literalValue(value) { + if (value instanceof LiteralString) { + return /** @type {!LiteralString} */(value).value; + } else { + throw new Error(`non-literal value passed to Polymer.htmlLiteral: ${value}`); + } + } + /** * @param {*} value Object to stringify into HTML * @return {string} HTML stringified form of `obj` */ function htmlValue(value) { if (value instanceof HTMLTemplateElement) { - return /** @type {!HTMLTemplateElement} */(value).innerHTML; + return /** @type {!HTMLTemplateElement } */(value).innerHTML; + } else if (value instanceof LiteralString) { + return literalValue(value); } else { - return String(value); + throw new Error(`non-template value passed to Polymer.html: ${value}`); } } /** - * A template literal tag that creates an HTML