diff --git a/jsnox.js b/jsnox.js index 17185b8..1eb37c4 100644 --- a/jsnox.js +++ b/jsnox.js @@ -4,7 +4,7 @@ var tagNameRegex = /^([a-z1-6]+)(?:\:([a-z]+))?/ // matches 'input' or 'input:text' var propsRegex = /((?:#|\.|@)[\w-]+)|(\[.*?\])/g // matches all further properties var attrRegex = /\[([\w-]+)(?:=([^\]]+))?\]/ // matches '[foo=bar]' or '[foo]' - +var autoKeyGenRegex = /\^$/ // matches 'anything^' // Error subclass to throw for parsing errors function ParseError(input) { @@ -31,19 +31,19 @@ var specCache = {} // name: 'asdf' // } // } -function parseTagSpec(specString) { +function parseTagSpec(specString, autoKeyGen) { if (!specString || !specString.match) throw new ParseError(specString) if (specCache[specString]) return specCache[specString] // Parse tagName, and optional type attribute var tagMatch = specString.match(tagNameRegex) if (!tagMatch) throw new ParseError(specString) - - // Provide the specString as a default key, which can always be overridden - // by the props hash (for when two siblings have the same specString) var tagName = tagMatch[1] - var props = { key: specString } + var props = {} var classes = [] + if (autoKeyGen || specString.match(autoKeyGenRegex)) { + props.key = specString + } if (tagMatch[2]) props.type = tagMatch[2] else if (tagName === 'button') props.type = 'button' // Saner default for