Skip to content

Commit

Permalink
v2.3.19
Browse files Browse the repository at this point in the history
fixing double quote issues.

Removed depedency on riot-tmpl of the node build
  • Loading branch information
amarcruz committed Dec 14, 2015
1 parent 27ad6f5 commit 06a77cf
Show file tree
Hide file tree
Showing 14 changed files with 550 additions and 55 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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.
Expand Down
15 changes: 13 additions & 2 deletions bump.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'))

Expand All @@ -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)
})
203 changes: 194 additions & 9 deletions dist/compiler.js
Original file line number Diff line number Diff line change
@@ -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

/**
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -282,7 +467,7 @@ function restoreExpr(html, pcex) {
.replace(/>/g, '&gt;')
})
}
return pcex._bp[0] + expr
return pcex._bp[0] + expr.replace(/"/g, '\u2057')
})
}
return html
Expand Down Expand Up @@ -624,5 +809,5 @@ module.exports = {
style: compileCSS,
js: compileJS,
parsers: parsers,
version: 'v2.3.18'
version: 'WIP'
}
11 changes: 3 additions & 8 deletions dist/es6.compiler.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/**
* Compiler for riot custom tags
* @version v2.3.18
* @version WIP
*/

import { brackets } from 'riot-tmpl'
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -241,7 +236,7 @@ function restoreExpr(html, pcex) {
.replace(/>/g, '&gt;')
})
}
return pcex._bp[0] + expr
return pcex._bp[0] + expr.replace(/"/g, '\u2057')
})
}
return html
Expand Down Expand Up @@ -560,7 +555,7 @@ function compile(src, opts, url) {
return src
}

var version = 'v2.3.18'
var version = 'WIP'

export default {
compile,
Expand Down
11 changes: 3 additions & 8 deletions dist/riot.compiler.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -239,7 +234,7 @@ var compile = (function () {
.replace(/>/g, '&gt;')
})
}
return pcex._bp[0] + expr
return pcex._bp[0] + expr.replace(/"/g, '\u2057')
})
}
return html
Expand Down Expand Up @@ -563,7 +558,7 @@ var compile = (function () {
html: compileHTML,
style: compileCSS,
js: compileJS,
version: 'v2.3.18'
version: 'WIP'
}
return compile

Expand Down
2 changes: 1 addition & 1 deletion lib/_node.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

//#include_once parsers

var brackets = require('riot-tmpl').brackets
//#include_once brackets

/**
* @module compiler
Expand Down

0 comments on commit 06a77cf

Please sign in to comment.