Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ language: node_js
node_js:
- "stable"
- "lts/*"
- 6
- 10
cache:
directories:
- node_modules
Expand Down
16 changes: 16 additions & 0 deletions INDEX.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@
<dt><a href="#executeScope">executeScope(scope, locals, node)</a> ⇒ <code>function</code></dt>
<dd><p>Runs walk function with arbitrary set of local variables</p>
</dd>
<dt><a href="#getLoopMeta">getLoopMeta(index, target)</a> ⇒ <code>Object</code></dt>
<dd><p>Returns an object containing loop metadata</p>
</dd>
<dt><a href="#parseLoopStatement">parseLoopStatement(input)</a> ⇒ <code>Object</code></dt>
<dd><p>Given a &quot;loop&quot; parameter from an &quot;each&quot; tag, parses out the param names and expression to be looped.</p>
</dd>
Expand Down Expand Up @@ -158,6 +161,19 @@ Runs walk function with arbitrary set of local variables
| locals | <code>Object</code> | Locals |
| node | <code>Object</code> | Node |

<a name="getLoopMeta"></a>

## getLoopMeta(index, target) ⇒ <code>Object</code>
Returns an object containing loop metadata

**Kind**: global function
**Returns**: <code>Object</code> - Object containing loop metadata

| Param | Type | Description |
| --- | --- | --- |
| index | <code>Integer</code> \| <code>Object</code> | Current iteration |
| target | <code>Object</code> | Object being iterated |

<a name="parseLoopStatement"></a>

## parseLoopStatement(input) ⇒ <code>Object</code>
Expand Down
6 changes: 3 additions & 3 deletions lib/backup.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,11 @@ const cloneDeep = require('fclone')
* @return {Object} backup Backup Locals
*/
function makeLocalsBackup (keys, locals) {
let backup = {}
const backup = {}

for (let i = 0; i < keys.length; i++) {
const key = keys[i]
if (locals.hasOwnProperty(key)) backup[key] = cloneDeep(locals[key])
if (Object.prototype.hasOwnProperty.call(locals, key)) backup[key] = cloneDeep(locals[key])
}

return backup
Expand All @@ -41,7 +41,7 @@ function revertBackupedLocals (keys, locals, backup) {
delete locals[key]

// revert copied key value
if (backup.hasOwnProperty(key)) locals[key] = backup[key]
if (Object.prototype.hasOwnProperty.call(backup, key)) locals[key] = backup[key]
}

return locals
Expand Down
12 changes: 6 additions & 6 deletions lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ const makeLocalsBackup = require('./backup').make
const revertBackupedLocals = require('./backup').revert
const placeholders = require('./placeholders')

let delimitersSettings = []
const delimitersSettings = []
let conditionals, switches, loops, scopes, ignored

/**
Expand Down Expand Up @@ -73,7 +73,7 @@ function getLoopMeta (index, target) {
index: index,
remaining: arr.length - index - 1,
first: arr.indexOf(arr[index]) === 0,
last: index + 1 == arr.length,
last: index + 1 === arr.length,
length: arr.length
}
}
Expand Down Expand Up @@ -177,8 +177,8 @@ function walk (opts, nodes) {
// if we have a string, match and replace it
if (typeof node === 'string') {
// if node contains ignored expression delimiter, output as-is
let before = delimitersSettings[1].text[0]
let after = delimitersSettings[1].text[1]
const before = delimitersSettings[1].text[0]
const after = delimitersSettings[1].text[1]
const ignoredDelimiter = new RegExp(`@${before}(.+?)${after}`, 'g')

if (ignoredDelimiter.test(node)) {
Expand All @@ -198,7 +198,7 @@ function walk (opts, nodes) {

// if not, we have an object, so we need to run the attributes and contents
if (node.attrs) {
for (let key in node.attrs) {
for (const key in node.attrs) {
node.attrs[key] = placeholders(node.attrs[key], ctx, delimitersSettings)
}
}
Expand Down Expand Up @@ -351,7 +351,7 @@ function walk (opts, nodes) {
m.push(executeLoop(keys, target[index], index, opts.locals, treeString))
}
} else {
for (let key in target) {
for (const key in target) {
opts.locals.loop = getLoopMeta(key, target)
m.push(executeLoop(keys, target[key], key, opts.locals, treeString))
}
Expand Down
2 changes: 1 addition & 1 deletion lib/placeholders.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ function placeholders (input, ctx, settings) {

if (/\W+/.test(expression)) {
value = vm.runInContext(expression, ctx)
} else if (ctx.hasOwnProperty(expression)) {
} else if (Object.prototype.hasOwnProperty.call(ctx, expression)) {
value = ctx[expression]
}

Expand Down
2 changes: 1 addition & 1 deletion lib/tags.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ function getNextTag (nodes, i) {
}
}

return [ i, { tag: undefined } ]
return [i, { tag: undefined }]
}

/**
Expand Down
Loading