From 06a77cf578877500c340cdfc4b473bb9ecac72d2 Mon Sep 17 00:00:00 2001 From: amarcruz Date: Mon, 14 Dec 2015 04:01:48 -0600 Subject: [PATCH] v2.3.19 fixing double quote issues. Removed depedency on riot-tmpl of the node build --- CHANGELOG.md | 4 + bump.js | 15 +- dist/compiler.js | 203 ++++++++++++++++- dist/es6.compiler.js | 11 +- dist/riot.compiler.js | 11 +- lib/_node.js | 2 +- lib/brackets.js | 313 +++++++++++++++++++++++++++ lib/core.js | 7 +- package.json | 5 +- test/specs/expect/raw-html.js | 2 +- test/specs/expect/whitespace.js | 2 +- test/specs/html.js | 12 +- test/specs/parsers/js/raw.rawhtml.js | 12 +- test/specs/parsers/suite.js | 6 +- 14 files changed, 550 insertions(+), 55 deletions(-) create mode 100644 lib/brackets.js diff --git a/CHANGELOG.md b/CHANGELOG.md index f82378a..65dabc8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,9 @@ # Compiler Changes +### v2.3.19 +- Fixing issues with double quotes. +- Removed dependency on riot-tmpl, now we are using a local version of `brackets` for node builds. + ### v2.3.18 - Regression of optimized regexes not working in IE9/10. diff --git a/bump.js b/bump.js index 0cdc910..e7dedd7 100644 --- a/bump.js +++ b/bump.js @@ -16,6 +16,8 @@ var count = 0, re = RegExp('\\b' + repStr.replace(/(?=[[\]()*+?.^$|])/g, '\\') + '\\b', 'g') +process.exitCode = 0 + version = 'v' + version console.log('bump %s for %s', version, path.join(fpath, '*.js')) @@ -25,12 +27,21 @@ fs.readdirSync(fpath).forEach(function (name) { name = path.join(fpath, name) console.log(name) - var src = fs.readFileSync(name, 'utf8') - fs.writeFileSync(name, src.replace(re, version), 'utf8') + fs.readFile(name, 'utf8', function (err, src) { + if (err) throw err + fs.writeFile(name, src.replace(re, version), 'utf8', function (err2) { + if (err2) throw err2 + }) + }) count++ } }) if (!count) { console.error('Error: There\'s no .js files in %s', fpath) + process.exitCode = 1 } + +process.on('exit', function (code) { + if (code) process.exit(code) +}) diff --git a/dist/compiler.js b/dist/compiler.js index d7f0068..8bb01b0 100644 --- a/dist/compiler.js +++ b/dist/compiler.js @@ -1,4 +1,4 @@ -/* riot-compiler v2.3.18, @license MIT, (c) 2015 Muut Inc. + contributors */ +/* riot-compiler WIP, @license MIT, (c) 2015 Muut Inc. + contributors */ 'use strict' // eslint-disable-line /** @@ -142,17 +142,202 @@ var parsers = (function () { })() -var brackets = require('riot-tmpl').brackets +/** + * @module brackets + * + * `brackets ` Returns a string or regex based on its parameter + * `brackets.settings` Mirrors the `riot.settings` object (use brackets.set in new code) + * `brackets.set ` Change the current riot brackets + */ + +var brackets = (function (UNDEF) { + + var + REGLOB = 'g', + + MLCOMMS = /\/\*[^*]*\*+(?:[^*\/][^*]*\*+)*\//g, + STRINGS = /"[^"\\]*(?:\\[\S\s][^"\\]*)*"|'[^'\\]*(?:\\[\S\s][^'\\]*)*'/g, + + S_QBSRC = STRINGS.source + '|' + + /(?:\breturn\s+|(?:[$\w\)\]]|\+\+|--)\s*(\/)(?![*\/]))/.source + '|' + + /\/(?=[^*\/])[^[\/\\]*(?:(?:\[(?:\\.|[^\]\\]*)*\]|\\.)[^[\/\\]*)*?(\/)[gim]*/.source, + + DEFAULT = '{ }', + + FINDBRACES = { + '(': RegExp('([()])|' + S_QBSRC, REGLOB), + '[': RegExp('([[\\]])|' + S_QBSRC, REGLOB), + '{': RegExp('([{}])|' + S_QBSRC, REGLOB) + } + + var + cachedBrackets = UNDEF, + _regex, + _pairs = [] + + function _loopback(re) { return re } + + function _rewrite(re, bp) { + // istanbul ignore next + if (!bp) bp = _pairs + return new RegExp( + re.source.replace(/{/g, bp[2]).replace(/}/g, bp[3]), re.global ? REGLOB : '' + ) + } + + function _create(pair) { + var + cvt, + arr = pair.split(' ') + + if (pair === DEFAULT) { + arr[2] = arr[0] + arr[3] = arr[1] + cvt = _loopback + } + else { + // istanbul ignore next + if (arr.length !== 2 || /[\x00-\x1F<>a-zA-Z0-9'",;\\]/.test(pair)) { + throw new Error('Unsupported brackets "' + pair + '"') + } + arr = arr.concat(pair.replace(/(?=[[\]()*+?.^$|])/g, '\\').split(' ')) + cvt = _rewrite + } + // istanbul ignore next + arr[4] = cvt(arr[1].length > 1 ? /{[\S\s]*?}/ : /{[^}]*}/, arr) + arr[5] = cvt(/\\({|})/g, arr) + arr[6] = cvt(/(\\?)({)/g, arr) + arr[7] = RegExp('(\\\\?)(?:([[({])|(' + arr[3] + '))|' + S_QBSRC, REGLOB) + arr[8] = pair + return arr + } + + // istanbul ignore next + function _reset(pair) { + if (!pair) pair = DEFAULT + + if (pair !== _pairs[8]) { + _pairs = _create(pair) + _regex = pair === DEFAULT ? _loopback : _rewrite + _pairs[9] = _regex(/^\s*{\^?\s*([$\w]+)(?:\s*,\s*(\S+))?\s+in\s+(\S.*)\s*}/) + _pairs[10] = _regex(/(^|[^\\]){=[\S\s]*?}/) + _brackets._rawOffset = _pairs[0].length + } + cachedBrackets = pair + } + + // istanbul ignore next + function _brackets(reOrIdx) { + return reOrIdx instanceof RegExp ? _regex(reOrIdx) : _pairs[reOrIdx] + } + + _brackets.split = function split(str, tmpl, _bp) { + // istanbul ignore next: _bp is for the compiler + if (!_bp) _bp = _pairs + + var + parts = [], + match, + isexpr, + start, + pos, + re = _bp[6] + + isexpr = start = re.lastIndex = 0 + + while (match = re.exec(str)) { + + pos = match.index + + if (isexpr) { + + if (match[2]) { + re.lastIndex = skipBraces(match[2], re.lastIndex) + continue + } + + if (!match[3]) + continue + } + + if (!match[1]) { + unescapeStr(str.slice(start, pos)) + start = re.lastIndex + re = _bp[6 + (isexpr ^= 1)] + re.lastIndex = start + } + } + + if (str && start < str.length) { + unescapeStr(str.slice(start)) + } + + return parts + + function unescapeStr(str) { + if (tmpl || isexpr) + parts.push(str && str.replace(_bp[5], '$1')) + else + parts.push(str) + } + + function skipBraces(ch, pos) { + var + match, + recch = FINDBRACES[ch], + level = 1 + recch.lastIndex = pos + + while (match = recch.exec(str)) { + // istanbul ignore next + if (match[1] && + !(match[1] === ch ? ++level : --level)) break + } + // istanbul ignore next + return match ? recch.lastIndex : str.length + } + } + + _brackets.array = function array(pair) { + return _create(pair || cachedBrackets) + } + + var _settings + // istanbul ignore next + function _setSettings(o) { + var b + o = o || {} + b = o.brackets + Object.defineProperty(o, 'brackets', { + set: _reset, + get: function () { return cachedBrackets }, + enumerable: true + }) + _settings = o + _reset(b) + } + // istanbul ignore next + Object.defineProperty(_brackets, 'settings', { + set: _setSettings, + get: function () { return _settings } + }) + + /* istanbul ignore next: in the node version riot is not in the scope */ + _brackets.settings = typeof riot !== 'undefined' && riot.settings || {} + _brackets.set = _reset + + _brackets.R_STRINGS = STRINGS + _brackets.R_MLCOMMS = MLCOMMS + _brackets.S_QBLOCKS = S_QBSRC + + return _brackets + +})() /** * @module compiler */ -// istanbul ignore next -if (!brackets.version) { - throw new Error('This compiler version requires riot-tmpl v2.3.18 or above') -} - function _regEx(str, opt) { return new RegExp(str, opt) } var @@ -282,7 +467,7 @@ function restoreExpr(html, pcex) { .replace(/>/g, '>') }) } - return pcex._bp[0] + expr + return pcex._bp[0] + expr.replace(/"/g, '\u2057') }) } return html @@ -624,5 +809,5 @@ module.exports = { style: compileCSS, js: compileJS, parsers: parsers, - version: 'v2.3.18' + version: 'WIP' } diff --git a/dist/es6.compiler.js b/dist/es6.compiler.js index 0817dec..b669eb0 100644 --- a/dist/es6.compiler.js +++ b/dist/es6.compiler.js @@ -1,6 +1,6 @@ /** * Compiler for riot custom tags - * @version v2.3.18 + * @version WIP */ import { brackets } from 'riot-tmpl' @@ -109,11 +109,6 @@ var parsers = (function () { * @module compiler */ -// istanbul ignore next -if (!brackets.version) { - throw new Error('This compiler version requires riot-tmpl v2.3.18 or above') -} - function _regEx(str, opt) { return new RegExp(str, opt) } var @@ -241,7 +236,7 @@ function restoreExpr(html, pcex) { .replace(/>/g, '>') }) } - return pcex._bp[0] + expr + return pcex._bp[0] + expr.replace(/"/g, '\u2057') }) } return html @@ -560,7 +555,7 @@ function compile(src, opts, url) { return src } -var version = 'v2.3.18' +var version = 'WIP' export default { compile, diff --git a/dist/riot.compiler.js b/dist/riot.compiler.js index 33ff88d..4816c57 100644 --- a/dist/riot.compiler.js +++ b/dist/riot.compiler.js @@ -103,15 +103,10 @@ riot.parsers = parsers /** * Compiler for riot custom tags - * @version v2.3.18 + * @version WIP */ var compile = (function () { - // istanbul ignore next - if (!brackets.version) { - throw new Error('This compiler version requires riot-tmpl v2.3.18 or above') - } - function _regEx(str, opt) { return new RegExp(str, opt) } var @@ -239,7 +234,7 @@ var compile = (function () { .replace(/>/g, '>') }) } - return pcex._bp[0] + expr + return pcex._bp[0] + expr.replace(/"/g, '\u2057') }) } return html @@ -563,7 +558,7 @@ var compile = (function () { html: compileHTML, style: compileCSS, js: compileJS, - version: 'v2.3.18' + version: 'WIP' } return compile diff --git a/lib/_node.js b/lib/_node.js index e535566..3fe47fc 100644 --- a/lib/_node.js +++ b/lib/_node.js @@ -3,7 +3,7 @@ //#include_once parsers -var brackets = require('riot-tmpl').brackets +//#include_once brackets /** * @module compiler diff --git a/lib/brackets.js b/lib/brackets.js new file mode 100644 index 0000000..094cfa7 --- /dev/null +++ b/lib/brackets.js @@ -0,0 +1,313 @@ +/** + * @module brackets + * + * `brackets ` Returns a string or regex based on its parameter + * `brackets.settings` Mirrors the `riot.settings` object (use brackets.set in new code) + * `brackets.set ` Change the current riot brackets + */ + +//#set $_RIX_TEST = 4 +//#set $_RIX_ESC = 5 +//#set $_RIX_OPEN = 6 +//#set $_RIX_CLOSE = 7 +//#set $_RIX_PAIR = 8 +//#set $_RIX_LOOP = 9 +//#set $_RIX_RAW = 10 +//#ifndef $_RIX_TEST +var + $_RIX_TEST = 4, // DONT'T FORGET SYNC THE #set BLOCK!!! + $_RIX_ESC = 5, + $_RIX_OPEN = 6, + $_RIX_CLOSE = 7, + $_RIX_PAIR = 8, + $_RIX_LOOP = 9, + $_RIX_RAW = 10 +//#endif + +var brackets = (function (UNDEF) { + + // Closure data + // -------------------------------------------------------------------------- + var + REGLOB = 'g', + + // `MLCOMMS` - Multiline comments in almost all their forms
+ // `STRINGS` - Quoted strings. Don't care about inner eols
+ + MLCOMMS = /\/\*[^*]*\*+(?:[^*\/][^*]*\*+)*\//g, + STRINGS = /"[^"\\]*(?:\\[\S\s][^"\\]*)*"|'[^'\\]*(?:\\[\S\s][^'\\]*)*'/g, + + // `S_QBSRC` - `STRINGS` combined with regex sources matching division operators + // and literal regexes, for use with the RegExp ctor. + // The resulting regex captures in `$1` and `$2` a single slash, depending if it + // matches a division operator ($1) or a regex ($2). + + S_QBSRC = STRINGS.source + '|' + + /(?:\breturn\s+|(?:[$\w\)\]]|\+\+|--)\s*(\/)(?![*\/]))/.source + '|' + + /\/(?=[^*\/])[^[\/\\]*(?:(?:\[(?:\\.|[^\]\\]*)*\]|\\.)[^[\/\\]*)*?(\/)[gim]*/.source, + + // The predefined riot brackets + DEFAULT = '{ }', + + // Regexes for matching JavaScript brackets out of quoted strings and regexes. + // These are heavy, but their performance is acceptable. + + FINDBRACES = { + '(': RegExp('([()])|' + S_QBSRC, REGLOB), + '[': RegExp('([[\\]])|' + S_QBSRC, REGLOB), + '{': RegExp('([{}])|' + S_QBSRC, REGLOB) + } + + // Variable information about the current brackets state, initialized on first use + // and on bracket changes. + var + cachedBrackets = UNDEF, // full brackets string in use, for change detection + _regex, // for regex convertion of default brackets + _pairs = [] // pre-made string and regexes for current brackets + + // Private functions + // -------------------------------------------------------------------------- + + /** + * Dummy function, returns the same regex + * @param {RegExp} re RegExp instance + * @returns {RegExp} The same regex + */ + function _loopback(re) { return re } + + /** + * Rewrite regex with the default brackets replaced with the custom ones. + * @param {RegExp} re - RegExp with the default riot brackets + * @param {Array} bp - Custom brackets to replace with + * @returns {RegExp} - The new regex with the default brackets replaced. + * @private + */ + function _rewrite(re, bp) { + // istanbul ignore next + if (!bp) bp = _pairs + return new RegExp( + re.source.replace(/{/g, bp[2]).replace(/}/g, bp[3]), re.global ? REGLOB : '' + ) + } + + /** + * Creates an array with strings and regexes based on the received brackets. + * + * @param {string} pair - String with the brackets pair + * @returns {Array} - Array with info for the given brackets + * @private + */ + function _create(pair) { + var + cvt, + arr = pair.split(' ') + + if (pair === DEFAULT) { + arr[2] = arr[0] + arr[3] = arr[1] + cvt = _loopback + } + else { + // istanbul ignore next + if (arr.length !== 2 || /[\x00-\x1F<>a-zA-Z0-9'",;\\]/.test(pair)) { + throw new Error('Unsupported brackets "' + pair + '"') + } + arr = arr.concat(pair.replace(/(?=[[\]()*+?.^$|])/g, '\\').split(' ')) + cvt = _rewrite + } + // istanbul ignore next + arr[$_RIX_TEST] = cvt(arr[1].length > 1 ? /{[\S\s]*?}/ : /{[^}]*}/, arr) + arr[$_RIX_ESC] = cvt(/\\({|})/g, arr) + arr[$_RIX_OPEN] = cvt(/(\\?)({)/g, arr) // for _split() + arr[$_RIX_CLOSE] = RegExp('(\\\\?)(?:([[({])|(' + arr[3] + '))|' + S_QBSRC, REGLOB) + arr[$_RIX_PAIR] = pair + return arr + } + + /** + * Resets the _pairs array with strings and regexes based on its parameter. + * + * @param {string} pair - String with the brackets pair to set + * @private + */ + // istanbul ignore next + function _reset(pair) { + if (!pair) pair = DEFAULT + + if (pair !== _pairs[$_RIX_PAIR]) { + _pairs = _create(pair) + _regex = pair === DEFAULT ? _loopback : _rewrite + _pairs[$_RIX_LOOP] = _regex(/^\s*{\^?\s*([$\w]+)(?:\s*,\s*(\S+))?\s+in\s+(\S.*)\s*}/) + _pairs[$_RIX_RAW] = _regex(/(^|[^\\]){=[\S\s]*?}/) + _brackets._rawOffset = _pairs[0].length + } + cachedBrackets = pair // always set these + } + + // "Exported" functions + // -------------------------------------------------------------------------- + + /** + * The main function.
+ * With a numeric parameter, returns the current left (0) or right (1) brackets + * characters. + * With a regex, returns the original regex if the current brackets are the defaults, + * or a new one with the default brackets replaced by the current custom brackets. + * @param {RegExp|number} reOrIdx - As noted above + * @returns {RegExp|string} - Based on the received parameter + */ + // istanbul ignore next + function _brackets(reOrIdx) { + return reOrIdx instanceof RegExp ? _regex(reOrIdx) : _pairs[reOrIdx] + } + + /** + * Splits the received string in its template text and expression parts using + * balanced brackets detection to avoid require escaped brackets from users.
+ * For internal use by tmpl and the riot-compiler. + * @param {string} str - Template source to split, can be one expression + * @param {number} [tmpl] - 1 if called from tmpl() + * @param {Array} [_bp] - Info of custom brackets to use + * @returns {Array} - Array containing alternate template text and expressions. + * If str was one unique expression, returns two elements: ["", expression]. + */ + _brackets.split = function split(str, tmpl, _bp) { + // istanbul ignore next: _bp is for the compiler + if (!_bp) _bp = _pairs + + // Template text is easy: closing brackets are ignored, all we have to do is find + // the first unescaped bracket. The real work is with the expressions... + // + // Expressions are not so easy. We can already ignore opening brackets, but finding + // the correct closing bracket is tricky. + // Strings and regexes can contain almost any combination of characters and we + // can't deal with these complexity with our regexes, so let's hide and ignore + // these. From there, all we need is to detect the bracketed parts and skip + // them, as they contains most of the common characters used by riot brackets. + // With that, we have a 90% reliability in the detection, although (hope few) some + // custom brackets still requires to be escaped. + var + parts = [], // holds the resulting parts + match, // reused by both outer and nested searches + isexpr, // we are in ttext (0) or expression (1) + start, // start position of current template or expression + pos, // current position (exec() result) + re = _bp[$_RIX_OPEN] // start with *updated* opening bracket + + isexpr = start = re.lastIndex = 0 // re is reused, we must reset lastIndex + + while (match = re.exec(str)) { + + pos = match.index + + if (isexpr) { + // $1: optional escape character, + // $2: opening js bracket `{[(`, + // $3: closing riot bracket, + // $4 & $5: qblocks + + if (match[2]) { // if have a javascript opening bracket, + re.lastIndex = skipBraces(match[2], re.lastIndex) + continue // skip the bracketed block and loop + } + + if (!match[3]) // if don't have a closing bracket + continue // search again + } + + // At this point, we expect an _unescaped_ openning bracket in $2 for text, + // or a closing bracket in $3 for expression. + + if (!match[1]) { // ignore it if have an escape char + unescapeStr(str.slice(start, pos)) // push part, even if empty + start = re.lastIndex // next position is the new start + re = _bp[$_RIX_OPEN + (isexpr ^= 1)] // switch mode and swap regexp + re.lastIndex = start // update the regex pointer + } + } + + if (str && start < str.length) { // push remaining part, if we have one + unescapeStr(str.slice(start)) + } + + return parts + + // Inner Helpers for _split() ----- + + // Store the string in the array `parts`. + // Unescape escaped brackets from expressions and, if we are called from + // tmpl, from the HTML part too. + function unescapeStr(str) { + if (tmpl || isexpr) + parts.push(str && str.replace(_bp[$_RIX_ESC], '$1')) + else + parts.push(str) + } + + // Find the js closing bracket for the current block. + // Skips strings, regexes, and other inner blocks. + function skipBraces(ch, pos) { + var + match, + recch = FINDBRACES[ch], + level = 1 + recch.lastIndex = pos + + while (match = recch.exec(str)) { + // istanbul ignore next + if (match[1] && + !(match[1] === ch ? ++level : --level)) break + } + // istanbul ignore next + return match ? recch.lastIndex : str.length + } + } + + /** + * Returns an array with brackets information, defaults to the current brackets. + * WARNIG: This function is for internal use, can returns a shared array. + * + * @param {string} [pair] - If used, set the current brackets to this pair + * @param {number} [lock] - 1 to lock the brackets + * @returns {Array} - Brackets array in internal format + */ + _brackets.array = function array(pair) { + return _create(pair || cachedBrackets) // fix #1314 + } + + // Inmediate execution + // -------------------------------------------------------------------------- + + // Mirrors the `riot.settings`, you can assign this if riot is not in context + var _settings + // istanbul ignore next + function _setSettings(o) { + var b + o = o || {} + b = o.brackets + Object.defineProperty(o, 'brackets', { + set: _reset, + get: function () { return cachedBrackets }, + enumerable: true + }) + _settings = o + _reset(b) + } + // istanbul ignore next + Object.defineProperty(_brackets, 'settings', { + set: _setSettings, + get: function () { return _settings } + }) + + /* istanbul ignore next: in the node version riot is not in the scope */ + _brackets.settings = typeof riot !== 'undefined' && riot.settings || {} + _brackets.set = _reset // or better use this + + // Public properties, shared with `tmpl` and/or the riot compiler + _brackets.R_STRINGS = STRINGS + _brackets.R_MLCOMMS = MLCOMMS + _brackets.S_QBLOCKS = S_QBSRC + + return _brackets + +})() diff --git a/lib/core.js b/lib/core.js index 29a7bb3..1de5d27 100644 --- a/lib/core.js +++ b/lib/core.js @@ -1,9 +1,4 @@ -// istanbul ignore next -if (!brackets.version) { - throw new Error('This compiler version requires riot-tmpl v2.3.18 or above') -} - function _regEx(str, opt) { return new RegExp(str, opt) } // Looks like, in [jsperf tests](http://jsperf.com/riot-regexp-test-vs-array-indexof) @@ -184,7 +179,7 @@ function restoreExpr(html, pcex) { .replace(/>/g, '>') }) } - return pcex._bp[0] + expr + return pcex._bp[0] + expr.replace(/"/g, '\u2057') }) } return html diff --git a/package.json b/package.json index a45fee2..fde1806 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "riot-compiler", - "version": "2.3.18", + "version": "2.3.19-beta", "description": "Compiler for riot .tag files", "main": "dist/compiler.js", "jsnext:main": "dist/es6.compiler.js", @@ -28,9 +28,6 @@ "tag", "compiler" ], - "dependencies": { - "riot-tmpl": "^2.3.18" - }, "devDependencies": { "coveralls": "^2.11.4", "eslint": "^1.10.3", diff --git a/test/specs/expect/raw-html.js b/test/specs/expect/raw-html.js index 5bc550d..ae46056 100644 --- a/test/specs/expect/raw-html.js +++ b/test/specs/expect/raw-html.js @@ -1,5 +1,5 @@ //src: test/specs/fixtures/raw-html.tag -riot.tag2('raw-html', '

{= [address1,address2].join(\'<br>\')}

{= \'<\' + myElem + \' style="color: \' + myColor + \';">\\n Click\\n</\' + myElem + \'><br>\\n<b>me</b>\'}

', '', '', function(opts) { +riot.tag2('raw-html', '

{= [address1,address2].join(\'<br>\')}

{= \'<\' + myElem + \' style=⁗color: \' + myColor + \';⁗>\\n Click\\n</\' + myElem + \'><br>\\n<b>me</b>\'}

', '', '', function(opts) { this.address1 = '1234 Peachtree' this.address2 = 'Atlanta' diff --git a/test/specs/expect/whitespace.js b/test/specs/expect/whitespace.js index 6cf91df..d415bb2 100644 --- a/test/specs/expect/whitespace.js +++ b/test/specs/expect/whitespace.js @@ -1,5 +1,5 @@ //src: test/specs/fixtures/whitespace.tag -riot.tag2('my-tag', '

', 'p { display: none; }', 'style=" top:0; left:0" expr="{{ foo:"bar" }}"', function(opts) { +riot.tag2('my-tag', '

', 'p { display: none; }', 'style=" top:0; left:0" expr="{{ foo:⁗bar⁗ }}"', function(opts) { this.click = function(e) {}.bind(this) }, '{ }'); diff --git a/test/specs/html.js b/test/specs/html.js index 9a1c128..3fdcd9d 100644 --- a/test/specs/html.js +++ b/test/specs/html.js @@ -69,10 +69,10 @@ describe('Compile HTML', function() { }) it('nested double quotes are supported in expressions', function () { - testStr('

', '

') - testStr('

', '

') - testStr('

', '

') - testStr('

', '

') + testStr('

', '

') + testStr('

', '

') + testStr('

', '

') + testStr('

', '

') }) it('single quotes in expressions are escaped', function () { @@ -119,10 +119,10 @@ describe('Compile HTML', function() { it('raw html detection through the `=` flag', function () { testStr( '

{= \'<\' + myElem + \' style="color: \' + myColor + \';">\\n Click me\'}

', - '

{= \'<\' + myElem + \' style="color: \' + myColor + \';">\\n Click me</\' + myElem + \'>\'}

') + '

{= \'<\' + myElem + \' style=\u2057color: \' + myColor + \';\u2057>\\n Click me</\' + myElem + \'>\'}

') testStr( '', - '') + '') }) }) diff --git a/test/specs/parsers/js/raw.rawhtml.js b/test/specs/parsers/js/raw.rawhtml.js index 623a8f5..5d8ec62 100644 --- a/test/specs/parsers/js/raw.rawhtml.js +++ b/test/specs/parsers/js/raw.rawhtml.js @@ -1,10 +1,10 @@ -riot.tag2('raw-html', '

{=[address1,address2].join("<br>")}

{="<" + myElem + " style="color: " + myColor + ";">\\n Click\\n</" + myElem + "><br>\\n<b>me</b>"}

', '', '', function(opts) { +riot.tag2('raw-html', '

{=[address1,address2].join(\'<br>\')}

{=\'<\' + myElem + \' style="color: \' + myColor + \';">\\n Click\\n</\' + myElem + \'><br>\\n<b>me</b>\'}

', '', '', function(opts) { - this.address1 = "1234 Peachtree" - this.address2 = "Atlanta" - this.myElem = "span" - this.myColor = "red" + this.address1 = '1234 Peachtree' + this.address2 = 'Atlanta' + this.myElem = 'span' + this.myColor = 'red' swap() { - this.myElem = this.myElem === "span" ? "p" : "span" + this.myElem = this.myElem === 'span' ? 'p' : 'span' } }, '{ }'); diff --git a/test/specs/parsers/suite.js b/test/specs/parsers/suite.js index 3706090..a0ac04c 100644 --- a/test/specs/parsers/suite.js +++ b/test/specs/parsers/suite.js @@ -76,8 +76,8 @@ describe('HTML parsers', function () { }) it('plays with quoted values', function () { - testStr('', '', opts) - testStr('{"b"}', '{@"b"}', opts) + testStr('', '', opts) + testStr('{"b"}', '{@\u2057b\u2057}', opts) }) it('remove the last semi-colon', function () { @@ -295,7 +295,7 @@ describe('Other', function () { it('emiting raw html through the `=` flag, with parser', function () { // custom parser compiler.parsers.js.rawhtml = function(js) { - return js.replace(/"/g, '"').replace(/'/g, '"') + return js.replace(/"/g, '"') } testParser('raw', { type: 'rawhtml', expr: true }) })