Skip to content

Commit

Permalink
v2.3.21
Browse files Browse the repository at this point in the history
- Refactorization, now `tmpl` and `brackets` are ~5% faster.
- Removed unused `tmpl.isRaw` function (internal).
- Changes to comments.
- Files to preprocess are moved from the "lib" to the "src" directory, "lib" was removed.
  • Loading branch information
amarcruz committed Jan 29, 2016
1 parent 240f23b commit 622c16d
Show file tree
Hide file tree
Showing 9 changed files with 103 additions and 80 deletions.
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
# riot-tmpl Changes

### v2.3.21
- Refactorization of `brackets`, now is ~8% faster.
- Refactorization, now `tmpl` and `brackets` are ~5% faster.
- Removed unused `tmpl.isRaw` function (internal).
- Changes to comments.
- Files to preprocess are moved from the "lib" to the "src" directory, "lib" was removed.

### v2.3.20
- Fixed lint issues with new .eslintrc.yml, almost compatible with [JavaScript Standard Style](http://standardjs.com/)
Expand Down
8 changes: 4 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,13 @@ test: build test-mocha test-karma
build: eslint
# rebuild all
@ mkdir -p $(DIST)
@ $(JSPP) $(JSPP_RIOT_FLAGS) lib/index.js > $(DIST)riot.tmpl.js
@ $(JSPP) $(JSPP_ES6_FLAGS) lib/index.js > $(DIST)es6.tmpl.js
@ $(JSPP) $(JSPP_NODE_FLAGS) lib/index.js > $(DIST)tmpl.js
@ $(JSPP) $(JSPP_RIOT_FLAGS) src/index.js > $(DIST)riot.tmpl.js
@ $(JSPP) $(JSPP_ES6_FLAGS) src/index.js > $(DIST)es6.tmpl.js
@ $(JSPP) $(JSPP_NODE_FLAGS) src/index.js > $(DIST)tmpl.js

eslint:
# check code style
@ $(ESLINT) -c ./.eslintrc.yml lib
@ $(ESLINT) -c ./.eslintrc.yml src

test-karma:
@ $(KARMA) start test/karma.conf.js
Expand Down
26 changes: 13 additions & 13 deletions dist/es6.tmpl.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ var brackets = (function (UNDEF) {
arr = arr.concat(pair.replace(/(?=[[\]()*+?.^$|])/g, '\\').split(' '))

arr[4] = _rewrite(arr[1].length > 1 ? /{[\S\s]*?}/ : _pairs[4], arr)
arr[5] = _rewrite(/\\({|})/g, arr)
arr[5] = _rewrite(pair.length > 3 ? /\\({|})/g : _pairs[5], arr)
arr[6] = _rewrite(_pairs[6], arr)
arr[7] = RegExp('\\\\(' + arr[3] + ')|([[({])|(' + arr[3] + ')|' + S_QBLOCKS, REGLOB)
arr[8] = pair
Expand Down Expand Up @@ -107,7 +107,7 @@ var brackets = (function (UNDEF) {
if (isexpr) {

if (match[2]) {
re.lastIndex = skipBraces(match[2], re.lastIndex)
re.lastIndex = skipBraces(str, match[2], re.lastIndex)
continue
}
if (!match[3])
Expand All @@ -128,25 +128,25 @@ var brackets = (function (UNDEF) {

return parts

function unescapeStr (str) {
function unescapeStr (s) {
if (tmpl || isexpr)
parts.push(str && str.replace(_bp[5], '$1'))
parts.push(s && s.replace(_bp[5], '$1'))
else
parts.push(str)
parts.push(s)
}

function skipBraces (ch, pos) {
function skipBraces (s, ch, ix) {
var
match,
recch = FINDBRACES[ch]

recch.lastIndex = pos
pos = 1
while (match = recch.exec(str)) {
recch.lastIndex = ix
ix = 1
while (match = recch.exec(s)) {
if (match[1] &&
!(match[1] === ch ? ++pos : --pos)) break
!(match[1] === ch ? ++ix : --ix)) break
}
return pos ? str.length : recch.lastIndex
return ix ? s.length : recch.lastIndex
}
}

Expand All @@ -166,7 +166,7 @@ var brackets = (function (UNDEF) {
}

_brackets.array = function array (pair) {
return pair ? _create(pair) : _pairs
return pair ? _create(pair) : _cache
}

function _reset (pair) {
Expand Down Expand Up @@ -197,7 +197,7 @@ var brackets = (function (UNDEF) {
get: function () { return _settings }
})

/* istanbul ignore next: in the node version riot is not in the scope */
/* istanbul ignore next: in the browser riot is always in the scope */
_brackets.settings = typeof riot !== 'undefined' && riot.settings || {}
_brackets.set = _reset

Expand Down
26 changes: 13 additions & 13 deletions dist/riot.tmpl.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ var brackets = (function (UNDEF) {
arr = arr.concat(pair.replace(/(?=[[\]()*+?.^$|])/g, '\\').split(' '))

arr[4] = _rewrite(arr[1].length > 1 ? /{[\S\s]*?}/ : _pairs[4], arr)
arr[5] = _rewrite(/\\({|})/g, arr)
arr[5] = _rewrite(pair.length > 3 ? /\\({|})/g : _pairs[5], arr)
arr[6] = _rewrite(_pairs[6], arr)
arr[7] = RegExp('\\\\(' + arr[3] + ')|([[({])|(' + arr[3] + ')|' + S_QBLOCKS, REGLOB)
arr[8] = pair
Expand Down Expand Up @@ -104,7 +104,7 @@ var brackets = (function (UNDEF) {
if (isexpr) {

if (match[2]) {
re.lastIndex = skipBraces(match[2], re.lastIndex)
re.lastIndex = skipBraces(str, match[2], re.lastIndex)
continue
}
if (!match[3])
Expand All @@ -125,25 +125,25 @@ var brackets = (function (UNDEF) {

return parts

function unescapeStr (str) {
function unescapeStr (s) {
if (tmpl || isexpr)
parts.push(str && str.replace(_bp[5], '$1'))
parts.push(s && s.replace(_bp[5], '$1'))
else
parts.push(str)
parts.push(s)
}

function skipBraces (ch, pos) {
function skipBraces (s, ch, ix) {
var
match,
recch = FINDBRACES[ch]

recch.lastIndex = pos
pos = 1
while (match = recch.exec(str)) {
recch.lastIndex = ix
ix = 1
while (match = recch.exec(s)) {
if (match[1] &&
!(match[1] === ch ? ++pos : --pos)) break
!(match[1] === ch ? ++ix : --ix)) break
}
return pos ? str.length : recch.lastIndex
return ix ? s.length : recch.lastIndex
}
}

Expand All @@ -163,7 +163,7 @@ var brackets = (function (UNDEF) {
}

_brackets.array = function array (pair) {
return pair ? _create(pair) : _pairs
return pair ? _create(pair) : _cache
}

function _reset (pair) {
Expand Down Expand Up @@ -194,7 +194,7 @@ var brackets = (function (UNDEF) {
get: function () { return _settings }
})

/* istanbul ignore next: in the node version riot is not in the scope */
/* istanbul ignore next: in the browser riot is always in the scope */
_brackets.settings = typeof riot !== 'undefined' && riot.settings || {}
_brackets.set = _reset

Expand Down
26 changes: 13 additions & 13 deletions dist/tmpl.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@
arr = arr.concat(pair.replace(/(?=[[\]()*+?.^$|])/g, '\\').split(' '))

arr[4] = _rewrite(arr[1].length > 1 ? /{[\S\s]*?}/ : _pairs[4], arr)
arr[5] = _rewrite(/\\({|})/g, arr)
arr[5] = _rewrite(pair.length > 3 ? /\\({|})/g : _pairs[5], arr)
arr[6] = _rewrite(_pairs[6], arr)
arr[7] = RegExp('\\\\(' + arr[3] + ')|([[({])|(' + arr[3] + ')|' + S_QBLOCKS, REGLOB)
arr[8] = pair
Expand Down Expand Up @@ -103,7 +103,7 @@
if (isexpr) {

if (match[2]) {
re.lastIndex = skipBraces(match[2], re.lastIndex)
re.lastIndex = skipBraces(str, match[2], re.lastIndex)
continue
}
if (!match[3])
Expand All @@ -124,25 +124,25 @@

return parts

function unescapeStr (str) {
function unescapeStr (s) {
if (tmpl || isexpr)
parts.push(str && str.replace(_bp[5], '$1'))
parts.push(s && s.replace(_bp[5], '$1'))
else
parts.push(str)
parts.push(s)
}

function skipBraces (ch, pos) {
function skipBraces (s, ch, ix) {
var
match,
recch = FINDBRACES[ch]

recch.lastIndex = pos
pos = 1
while (match = recch.exec(str)) {
recch.lastIndex = ix
ix = 1
while (match = recch.exec(s)) {
if (match[1] &&
!(match[1] === ch ? ++pos : --pos)) break
!(match[1] === ch ? ++ix : --ix)) break
}
return pos ? str.length : recch.lastIndex
return ix ? s.length : recch.lastIndex
}
}

Expand All @@ -162,7 +162,7 @@
}

_brackets.array = function array (pair) {
return pair ? _create(pair) : _pairs
return pair ? _create(pair) : _cache
}

function _reset (pair) {
Expand Down Expand Up @@ -193,7 +193,7 @@
get: function () { return _settings }
})

/* istanbul ignore next: in the node version riot is not in the scope */
/* istanbul ignore next: in the browser riot is always in the scope */
_brackets.settings = typeof riot !== 'undefined' && riot.settings || {}
_brackets.set = _reset

Expand Down
15 changes: 7 additions & 8 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,10 @@
"main": "dist/tmpl.js",
"jsnext:main": "dist/es6.tmpl.js",
"directories": {
"lib": "lib",
"doc": "doc"
},
"files": [
"lib",
"src",
"doc",
"dist/*.js",
"test/**"
Expand All @@ -29,18 +28,18 @@
"engine"
],
"devDependencies": {
"coveralls": "^2.11.4",
"coveralls": "^2.11.6",
"eslint": "^1.10.3",
"expect.js": "^0.3.1",
"istanbul": "^0.4.1",
"istanbul": "^0.4.2",
"jspreproc": "^0.2.7",
"karma": "^0.13.15",
"karma": "^0.13.19",
"karma-browserstack-launcher": "^0.1.6",
"karma-coverage": "^0.5.3",
"karma-mocha": "^0.2.1",
"karma-phantomjs-launcher": "^0.2.1",
"mocha": "^2.3.4",
"phantomjs": "^1.9.19",
"karma-phantomjs-launcher": "^0.2.3",
"mocha": "^2.4.4",
"phantomjs": "^2.1.2",
"riot-bump": "^1.0.0"
},
"author": "Muut, Inc. and other contributors",
Expand Down
8 changes: 5 additions & 3 deletions lib/brackets.js → src/brackets.js
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ var brackets = (function (UNDEF) {
arr = arr.concat(pair.replace(/(?=[[\]()*+?.^$|])/g, '\\').split(' '))

arr[$_RIX_TEST] = _rewrite(arr[1].length > 1 ? /{[\S\s]*?}/ : _pairs[$_RIX_TEST], arr)
arr[$_RIX_ESC] = _rewrite(/\\({|})/g, arr)
arr[$_RIX_ESC] = _rewrite(pair.length > 3 ? /\\({|})/g : _pairs[$_RIX_ESC], arr)
arr[$_RIX_OPEN] = _rewrite(_pairs[$_RIX_OPEN], arr) // for _split()
arr[$_RIX_CLOSE] = RegExp('\\\\(' + arr[3] + ')|([[({])|(' + arr[3] + ')|' + S_QBLOCKS, REGLOB)
arr[$_RIX_PAIR] = pair
Expand Down Expand Up @@ -314,14 +314,16 @@ var brackets = (function (UNDEF) {

/**
* Returns an array with brackets information, defaults to the current brackets.
* (the `brackets` module in the node version of the compiler allways defaults
* to the predefined riot brackets `{ }`).
*
* _This function is for internal use._
* @param {string} [pair] - If used, returns info for this brackets
* @returns {Array} Brackets array in internal format.
* @private
*/
_brackets.array = function array (pair) {
return pair ? _create(pair) : _pairs
return pair ? _create(pair) : _cache
}

/**
Expand Down Expand Up @@ -366,7 +368,7 @@ var brackets = (function (UNDEF) {
get: function () { return _settings }
})

/* istanbul ignore next: in the node version riot is not in the scope */
/* istanbul ignore next: in the browser riot is always in the scope */
_brackets.settings = typeof riot !== 'undefined' && riot.settings || {}
_brackets.set = _reset

Expand Down
File renamed without changes.
Loading

0 comments on commit 622c16d

Please sign in to comment.