Skip to content

Commit

Permalink
v2.3.15
Browse files Browse the repository at this point in the history
Fix: when calling the compiler with different brackets, `brackets.array` changes the global configuration (`riot.settings.brackets`)
  • Loading branch information
amarcruz committed Dec 9, 2015
1 parent 8aaac8a commit 3cedff1
Show file tree
Hide file tree
Showing 8 changed files with 187 additions and 126 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@

# v2.3.15
- Fix [riot#1416](https://github.com/riot/riot/issues/1416): Issue with space in expression of `each`
- Fix: when calling the compiler with different brackets, `brackets.array` changes the global configuration (`riot.settings.brackets`)
70 changes: 42 additions & 28 deletions dist/es6.tmpl.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,36 +39,45 @@ var brackets = (function (UNDEF) {

function _loopback(re) { return re }

function _rewrite(re) {
function _rewrite(re, bp) {
if (!bp) bp = _pairs
return new RegExp(
re.source.replace(/{/g, _pairs[2]).replace(/}/g, _pairs[3]), re.global ? REGLOB : ''
re.source.replace(/{/g, bp[2]).replace(/}/g, bp[3]), re.global ? REGLOB : ''
)
}

function _reset(pair) {
pair = pair || DEFAULT

if (pair !== _pairs[8]) {
var bp = pair.split(' ')
function _create(pair) {
var
cvt,
arr = pair.split(' ')

if (pair === DEFAULT) {
_pairs = bp.concat(bp)
_regex = _loopback
}
else {
if (bp.length !== 2 || /[\x00-\x1F<>a-zA-Z0-9'",;\\]/.test(pair)) {
throw new Error('Unsupported brackets "' + pair + '"')
}
_pairs = bp.concat(pair.replace(/(?=[[\]()*+?.^$|])/g, '\\').split(' '))
_regex = _rewrite
if (pair === DEFAULT) {
arr[2] = arr[0]
arr[3] = arr[1]
cvt = _loopback
}
else {
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
}
arr[4] = cvt(arr[1].length > 1 ? /{[^]*?}/ : /{[^}]*}/, arr)
arr[5] = cvt(/\\({|})/g, arr)
arr[6] = cvt(/(\\?)({)/g, arr)
arr[7] = RegExp('(\\\\?)(?:([[({])|(' + arr[3] + '))|' + S_QBSRC, REGLOB)
arr[8] = pair
return arr
}

_pairs[4] = _regex(_pairs[1].length > 1 ? /{[^]*?}/ : /{[^}]*}/)
_pairs[5] = _regex(/\\({|})/g)
_pairs[6] = _regex(/(\\?)({)/g)
_pairs[7] = RegExp('(\\\\?)(?:([[({])|(' + _pairs[3] + '))|' + S_QBSRC, REGLOB)
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[8] = pair
_brackets._rawOffset = _pairs[0].length
}
_brackets.settings.brackets = cachedBrackets = pair
Expand All @@ -79,15 +88,20 @@ var brackets = (function (UNDEF) {
return reOrIdx instanceof RegExp ? _regex(reOrIdx) : _pairs[reOrIdx]
}

_brackets.split = function split(str, tmpl) {
_brackets.split = function split(str, tmpl, _bp) {
// istanbul ignore next: _bp is for the compiler
if (!_bp) {
_reset(_brackets.settings.brackets)
_bp = _pairs
}

var
parts = [],
match,
isexpr,
start,
pos,
re = _brackets(6)
re = _bp[6]

isexpr = start = re.lastIndex = 0

Expand All @@ -109,7 +123,7 @@ var brackets = (function (UNDEF) {
if (!match[1]) {
unescapeStr(str.slice(start, pos))
start = re.lastIndex
re = _pairs[6 + (isexpr ^= 1)]
re = _bp[6 + (isexpr ^= 1)]
re.lastIndex = start
}
}
Expand All @@ -122,7 +136,7 @@ var brackets = (function (UNDEF) {

function unescapeStr(str) {
if (tmpl || isexpr)
parts.push(str && str.replace(_pairs[5], '$1'))
parts.push(str && str.replace(_bp[5], '$1'))
else
parts.push(str)
}
Expand Down Expand Up @@ -153,8 +167,8 @@ var brackets = (function (UNDEF) {
}

_brackets.array = function array(pair) {
_reset(pair || _brackets.settings.brackets)
return _pairs
if (!pair) pair = _brackets.settings.brackets
return _create(pair)
}

/* istanbul ignore next: in the node version riot is not in the scope */
Expand Down
70 changes: 42 additions & 28 deletions dist/riot.tmpl.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,36 +39,45 @@ var brackets = (function (UNDEF) {

function _loopback(re) { return re }

function _rewrite(re) {
function _rewrite(re, bp) {
if (!bp) bp = _pairs
return new RegExp(
re.source.replace(/{/g, _pairs[2]).replace(/}/g, _pairs[3]), re.global ? REGLOB : ''
re.source.replace(/{/g, bp[2]).replace(/}/g, bp[3]), re.global ? REGLOB : ''
)
}

function _reset(pair) {
pair = pair || DEFAULT

if (pair !== _pairs[8]) {
var bp = pair.split(' ')
function _create(pair) {
var
cvt,
arr = pair.split(' ')

if (pair === DEFAULT) {
_pairs = bp.concat(bp)
_regex = _loopback
}
else {
if (bp.length !== 2 || /[\x00-\x1F<>a-zA-Z0-9'",;\\]/.test(pair)) {
throw new Error('Unsupported brackets "' + pair + '"')
}
_pairs = bp.concat(pair.replace(/(?=[[\]()*+?.^$|])/g, '\\').split(' '))
_regex = _rewrite
if (pair === DEFAULT) {
arr[2] = arr[0]
arr[3] = arr[1]
cvt = _loopback
}
else {
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
}
arr[4] = cvt(arr[1].length > 1 ? /{[^]*?}/ : /{[^}]*}/, arr)
arr[5] = cvt(/\\({|})/g, arr)
arr[6] = cvt(/(\\?)({)/g, arr)
arr[7] = RegExp('(\\\\?)(?:([[({])|(' + arr[3] + '))|' + S_QBSRC, REGLOB)
arr[8] = pair
return arr
}

_pairs[4] = _regex(_pairs[1].length > 1 ? /{[^]*?}/ : /{[^}]*}/)
_pairs[5] = _regex(/\\({|})/g)
_pairs[6] = _regex(/(\\?)({)/g)
_pairs[7] = RegExp('(\\\\?)(?:([[({])|(' + _pairs[3] + '))|' + S_QBSRC, REGLOB)
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[8] = pair
_brackets._rawOffset = _pairs[0].length
}
_brackets.settings.brackets = cachedBrackets = pair
Expand All @@ -79,15 +88,20 @@ var brackets = (function (UNDEF) {
return reOrIdx instanceof RegExp ? _regex(reOrIdx) : _pairs[reOrIdx]
}

_brackets.split = function split(str, tmpl) {
_brackets.split = function split(str, tmpl, _bp) {
// istanbul ignore next: _bp is for the compiler
if (!_bp) {
_reset(_brackets.settings.brackets)
_bp = _pairs
}

var
parts = [],
match,
isexpr,
start,
pos,
re = _brackets(6)
re = _bp[6]

isexpr = start = re.lastIndex = 0

Expand All @@ -109,7 +123,7 @@ var brackets = (function (UNDEF) {
if (!match[1]) {
unescapeStr(str.slice(start, pos))
start = re.lastIndex
re = _pairs[6 + (isexpr ^= 1)]
re = _bp[6 + (isexpr ^= 1)]
re.lastIndex = start
}
}
Expand All @@ -122,7 +136,7 @@ var brackets = (function (UNDEF) {

function unescapeStr(str) {
if (tmpl || isexpr)
parts.push(str && str.replace(_pairs[5], '$1'))
parts.push(str && str.replace(_bp[5], '$1'))
else
parts.push(str)
}
Expand Down Expand Up @@ -153,8 +167,8 @@ var brackets = (function (UNDEF) {
}

_brackets.array = function array(pair) {
_reset(pair || _brackets.settings.brackets)
return _pairs
if (!pair) pair = _brackets.settings.brackets
return _create(pair)
}

/* istanbul ignore next: in the node version riot is not in the scope */
Expand Down
70 changes: 42 additions & 28 deletions dist/tmpl.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,36 +37,45 @@

function _loopback(re) { return re }

function _rewrite(re) {
function _rewrite(re, bp) {
if (!bp) bp = _pairs
return new RegExp(
re.source.replace(/{/g, _pairs[2]).replace(/}/g, _pairs[3]), re.global ? REGLOB : ''
re.source.replace(/{/g, bp[2]).replace(/}/g, bp[3]), re.global ? REGLOB : ''
)
}

function _reset(pair) {
pair = pair || DEFAULT

if (pair !== _pairs[8]) {
var bp = pair.split(' ')
function _create(pair) {
var
cvt,
arr = pair.split(' ')

if (pair === DEFAULT) {
_pairs = bp.concat(bp)
_regex = _loopback
}
else {
if (bp.length !== 2 || /[\x00-\x1F<>a-zA-Z0-9'",;\\]/.test(pair)) {
throw new Error('Unsupported brackets "' + pair + '"')
}
_pairs = bp.concat(pair.replace(/(?=[[\]()*+?.^$|])/g, '\\').split(' '))
_regex = _rewrite
if (pair === DEFAULT) {
arr[2] = arr[0]
arr[3] = arr[1]
cvt = _loopback
}
else {
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
}
arr[4] = cvt(arr[1].length > 1 ? /{[^]*?}/ : /{[^}]*}/, arr)
arr[5] = cvt(/\\({|})/g, arr)
arr[6] = cvt(/(\\?)({)/g, arr)
arr[7] = RegExp('(\\\\?)(?:([[({])|(' + arr[3] + '))|' + S_QBSRC, REGLOB)
arr[8] = pair
return arr
}

_pairs[4] = _regex(_pairs[1].length > 1 ? /{[^]*?}/ : /{[^}]*}/)
_pairs[5] = _regex(/\\({|})/g)
_pairs[6] = _regex(/(\\?)({)/g)
_pairs[7] = RegExp('(\\\\?)(?:([[({])|(' + _pairs[3] + '))|' + S_QBSRC, REGLOB)
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[8] = pair
_brackets._rawOffset = _pairs[0].length
}
_brackets.settings.brackets = cachedBrackets = pair
Expand All @@ -77,15 +86,20 @@
return reOrIdx instanceof RegExp ? _regex(reOrIdx) : _pairs[reOrIdx]
}

_brackets.split = function split(str, tmpl) {
_brackets.split = function split(str, tmpl, _bp) {
// istanbul ignore next: _bp is for the compiler
if (!_bp) {
_reset(_brackets.settings.brackets)
_bp = _pairs
}

var
parts = [],
match,
isexpr,
start,
pos,
re = _brackets(6)
re = _bp[6]

isexpr = start = re.lastIndex = 0

Expand All @@ -107,7 +121,7 @@
if (!match[1]) {
unescapeStr(str.slice(start, pos))
start = re.lastIndex
re = _pairs[6 + (isexpr ^= 1)]
re = _bp[6 + (isexpr ^= 1)]
re.lastIndex = start
}
}
Expand All @@ -120,7 +134,7 @@

function unescapeStr(str) {
if (tmpl || isexpr)
parts.push(str && str.replace(_pairs[5], '$1'))
parts.push(str && str.replace(_bp[5], '$1'))
else
parts.push(str)
}
Expand Down Expand Up @@ -151,8 +165,8 @@
}

_brackets.array = function array(pair) {
_reset(pair || _brackets.settings.brackets)
return _pairs
if (!pair) pair = _brackets.settings.brackets
return _create(pair)
}

/* istanbul ignore next: in the node version riot is not in the scope */
Expand Down
12 changes: 3 additions & 9 deletions doc/API.md
Original file line number Diff line number Diff line change
Expand Up @@ -93,16 +93,10 @@ This function checks their parameter and reconfigures the internal state immedia

_parameters_

* `brackets_pair` : string - new custom brackets pair. The start and end is separated with a space character.
* `brackets_pair` : string - (optional) new custom brackets pair. The start and end is separated with a space character.


### `settings` property

_Type:_ object

Mirror the `riot.settings` object or other user object where read or write the current brackets string. Unlike with `brackets.set`, reconfiguration for changes in `brackets.settings.brackets` or `riot.settings.brackets` will be applied in the next use of the `brackets` function.

**NOTE:** `riot.settings.brackets` and `brackets.settings` will be deprecated in future versions, please use brackets.set in new code.
**NOTE:**
`riot.settings.brackets` and `brackets.settings` will be deprecated in future versions, please use `brackets.set` in new code.


### `R_MLCOMMS` property
Expand Down

0 comments on commit 3cedff1

Please sign in to comment.