Skip to content

Commit

Permalink
fixed regexes
Browse files Browse the repository at this point in the history
  • Loading branch information
amarcruz committed Dec 10, 2015
1 parent 3e98bbd commit 3459a5e
Show file tree
Hide file tree
Showing 7 changed files with 18 additions and 14 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# Changelog for riot-tmpl

### v2.3.15
- Regression of optimized regexes not working in IE9/10.
- 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`).

Expand Down
6 changes: 3 additions & 3 deletions dist/es6.tmpl.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ var brackets = (function (UNDEF) {
REGLOB = 'g',

MLCOMMS = /\/\*[^*]*\*+(?:[^*\/][^*]*\*+)*\//g,
STRINGS = /"[^"\\]*(?:\\[^][^"\\]*)*"|'[^'\\]*(?:\\[^][^'\\]*)*'/g,
STRINGS = /"[^"\\]*(?:\\[\S\s][^"\\]*)*"|'[^'\\]*(?:\\[\S\s][^'\\]*)*'/g,

S_QBSRC = STRINGS.source + '|' +
/(?:\breturn\s+|(?:[$\w\)\]]|\+\+|--)\s*(\/)(?![*\/]))/.source + '|' +
Expand Down Expand Up @@ -63,7 +63,7 @@ var brackets = (function (UNDEF) {
arr = arr.concat(pair.replace(/(?=[[\]()*+?.^$|])/g, '\\').split(' '))
cvt = _rewrite
}
arr[4] = cvt(arr[1].length > 1 ? /{[^]*?}/ : /{[^}]*}/, arr)
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)
Expand Down Expand Up @@ -208,7 +208,7 @@ var tmpl = (function () {
}

_tmpl.haveRaw = function (src) {
return brackets(/{=[^]*?}/).test(src)
return brackets(/(^|[^\\]){=[\S\s]*?}/).test(src)
}

_tmpl.hasExpr = brackets.hasExpr
Expand Down
6 changes: 3 additions & 3 deletions dist/riot.tmpl.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ var brackets = (function (UNDEF) {
REGLOB = 'g',

MLCOMMS = /\/\*[^*]*\*+(?:[^*\/][^*]*\*+)*\//g,
STRINGS = /"[^"\\]*(?:\\[^][^"\\]*)*"|'[^'\\]*(?:\\[^][^'\\]*)*'/g,
STRINGS = /"[^"\\]*(?:\\[\S\s][^"\\]*)*"|'[^'\\]*(?:\\[\S\s][^'\\]*)*'/g,

S_QBSRC = STRINGS.source + '|' +
/(?:\breturn\s+|(?:[$\w\)\]]|\+\+|--)\s*(\/)(?![*\/]))/.source + '|' +
Expand Down Expand Up @@ -63,7 +63,7 @@ var brackets = (function (UNDEF) {
arr = arr.concat(pair.replace(/(?=[[\]()*+?.^$|])/g, '\\').split(' '))
cvt = _rewrite
}
arr[4] = cvt(arr[1].length > 1 ? /{[^]*?}/ : /{[^}]*}/, arr)
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)
Expand Down Expand Up @@ -208,7 +208,7 @@ var tmpl = (function () {
}

_tmpl.haveRaw = function (src) {
return brackets(/{=[^]*?}/).test(src)
return brackets(/(^|[^\\]){=[\S\s]*?}/).test(src)
}

_tmpl.hasExpr = brackets.hasExpr
Expand Down
6 changes: 3 additions & 3 deletions dist/tmpl.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
REGLOB = 'g',

MLCOMMS = /\/\*[^*]*\*+(?:[^*\/][^*]*\*+)*\//g,
STRINGS = /"[^"\\]*(?:\\[^][^"\\]*)*"|'[^'\\]*(?:\\[^][^'\\]*)*'/g,
STRINGS = /"[^"\\]*(?:\\[\S\s][^"\\]*)*"|'[^'\\]*(?:\\[\S\s][^'\\]*)*'/g,

S_QBSRC = STRINGS.source + '|' +
/(?:\breturn\s+|(?:[$\w\)\]]|\+\+|--)\s*(\/)(?![*\/]))/.source + '|' +
Expand Down Expand Up @@ -61,7 +61,7 @@
arr = arr.concat(pair.replace(/(?=[[\]()*+?.^$|])/g, '\\').split(' '))
cvt = _rewrite
}
arr[4] = cvt(arr[1].length > 1 ? /{[^]*?}/ : /{[^}]*}/, arr)
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)
Expand Down Expand Up @@ -206,7 +206,7 @@
}

_tmpl.haveRaw = function (src) {
return brackets(/{=[^]*?}/).test(src)
return brackets(/(^|[^\\]){=[\S\s]*?}/).test(src)
}

_tmpl.hasExpr = brackets.hasExpr
Expand Down
4 changes: 2 additions & 2 deletions lib/brackets.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ var brackets = (function (UNDEF) {
// `STRINGS` - Quoted strings. Don't care about inner eols<br>

MLCOMMS = /\/\*[^*]*\*+(?:[^*\/][^*]*\*+)*\//g,
STRINGS = /"[^"\\]*(?:\\[^][^"\\]*)*"|'[^'\\]*(?:\\[^][^'\\]*)*'/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.
Expand Down Expand Up @@ -111,7 +111,7 @@ var brackets = (function (UNDEF) {
arr = arr.concat(pair.replace(/(?=[[\]()*+?.^$|])/g, '\\').split(' '))
cvt = _rewrite
}
arr[$_RIX_TEST] = cvt(arr[1].length > 1 ? /{[^]*?}/ : /{[^}]*}/, arr)
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)
Expand Down
2 changes: 1 addition & 1 deletion lib/tmpl.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ var tmpl = (function () {
}

_tmpl.haveRaw = function (src) {
return brackets(/{=[^]*?}/).test(src)
return brackets(/(^|[^\\]){=[\S\s]*?}/).test(src)
}

/**
Expand Down
7 changes: 5 additions & 2 deletions test/specs/brackets.specs.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ describe('brackets', function () {
expect(render('\\{ 1 }')).to.equal('{ 1 }')
expect(render('{ "\\}" }')).to.equal('}')
expect(render('{ "\\{" }')).to.equal('{')
expect(render('{ \\{\\} }')).to.eql({})
})

it('though escaping is optional', function () {
Expand All @@ -78,9 +79,11 @@ describe('brackets', function () {

setBrackets('{{ }}')
expect(render('a{{ "b{{c}}d" }}e {{ "{f{{f}}}" }} g')).to.equal('ab{{c}}de {f{{f}}} g')
expect(render('{{{}}}')).to.eql({})

//setBrackets('<% %>')
//expect(render('a<% "b<%c%>d" %>e <% "<%f<%f%>%>" %> g')).to.equal('ab<%c%>de <%f<%f%>%> g')
setBrackets('{^ ^}')
expect(render('{^ "x" ^}')).to.equal('x')
expect(render('{^ /{^}/ ^}').source).to.equal(/{^}/.source)

setBrackets('[[ ]]')
expect(render('a[[ "b[[c]]d" ]]e [["[[f[f]]]"]]g[[]]')).to.equal('ab[[c]]de [[f[f]]]g')
Expand Down

0 comments on commit 3459a5e

Please sign in to comment.