Skip to content

Commit 8fd2616

Browse files
authored
Merge pull request #67 from posthtml/milestone-1.3.0
Milestone 1.3.0
2 parents bcdb13a + 38ecddc commit 8fd2616

File tree

13 files changed

+2606
-3488
lines changed

13 files changed

+2606
-3488
lines changed

.travis.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ language: node_js
22
node_js:
33
- "stable"
44
- "lts/*"
5-
- 6
5+
- 10
66
cache:
77
directories:
88
- node_modules

INDEX.md

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,9 @@
3434
<dt><a href="#executeScope">executeScope(scope, locals, node)</a> ⇒ <code>function</code></dt>
3535
<dd><p>Runs walk function with arbitrary set of local variables</p>
3636
</dd>
37+
<dt><a href="#getLoopMeta">getLoopMeta(index, target)</a> ⇒ <code>Object</code></dt>
38+
<dd><p>Returns an object containing loop metadata</p>
39+
</dd>
3740
<dt><a href="#parseLoopStatement">parseLoopStatement(input)</a> ⇒ <code>Object</code></dt>
3841
<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>
3942
</dd>
@@ -158,6 +161,19 @@ Runs walk function with arbitrary set of local variables
158161
| locals | <code>Object</code> | Locals |
159162
| node | <code>Object</code> | Node |
160163

164+
<a name="getLoopMeta"></a>
165+
166+
## getLoopMeta(index, target) ⇒ <code>Object</code>
167+
Returns an object containing loop metadata
168+
169+
**Kind**: global function
170+
**Returns**: <code>Object</code> - Object containing loop metadata
171+
172+
| Param | Type | Description |
173+
| --- | --- | --- |
174+
| index | <code>Integer</code> \| <code>Object</code> | Current iteration |
175+
| target | <code>Object</code> | Object being iterated |
176+
161177
<a name="parseLoopStatement"></a>
162178

163179
## parseLoopStatement(input) ⇒ <code>Object</code>

lib/backup.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,11 @@ const cloneDeep = require('fclone')
1313
* @return {Object} backup Backup Locals
1414
*/
1515
function makeLocalsBackup (keys, locals) {
16-
let backup = {}
16+
const backup = {}
1717

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

2323
return backup
@@ -41,7 +41,7 @@ function revertBackupedLocals (keys, locals, backup) {
4141
delete locals[key]
4242

4343
// revert copied key value
44-
if (backup.hasOwnProperty(key)) locals[key] = backup[key]
44+
if (Object.prototype.hasOwnProperty.call(backup, key)) locals[key] = backup[key]
4545
}
4646

4747
return locals

lib/index.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ const makeLocalsBackup = require('./backup').make
99
const revertBackupedLocals = require('./backup').revert
1010
const placeholders = require('./placeholders')
1111

12-
let delimitersSettings = []
12+
const delimitersSettings = []
1313
let conditionals, switches, loops, scopes, ignored
1414

1515
/**
@@ -73,7 +73,7 @@ function getLoopMeta (index, target) {
7373
index: index,
7474
remaining: arr.length - index - 1,
7575
first: arr.indexOf(arr[index]) === 0,
76-
last: index + 1 == arr.length,
76+
last: index + 1 === arr.length,
7777
length: arr.length
7878
}
7979
}
@@ -177,8 +177,8 @@ function walk (opts, nodes) {
177177
// if we have a string, match and replace it
178178
if (typeof node === 'string') {
179179
// if node contains ignored expression delimiter, output as-is
180-
let before = delimitersSettings[1].text[0]
181-
let after = delimitersSettings[1].text[1]
180+
const before = delimitersSettings[1].text[0]
181+
const after = delimitersSettings[1].text[1]
182182
const ignoredDelimiter = new RegExp(`@${before}(.+?)${after}`, 'g')
183183

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

199199
// if not, we have an object, so we need to run the attributes and contents
200200
if (node.attrs) {
201-
for (let key in node.attrs) {
201+
for (const key in node.attrs) {
202202
node.attrs[key] = placeholders(node.attrs[key], ctx, delimitersSettings)
203203
}
204204
}
@@ -351,7 +351,7 @@ function walk (opts, nodes) {
351351
m.push(executeLoop(keys, target[index], index, opts.locals, treeString))
352352
}
353353
} else {
354-
for (let key in target) {
354+
for (const key in target) {
355355
opts.locals.loop = getLoopMeta(key, target)
356356
m.push(executeLoop(keys, target[key], key, opts.locals, treeString))
357357
}

lib/placeholders.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ function placeholders (input, ctx, settings) {
5555

5656
if (/\W+/.test(expression)) {
5757
value = vm.runInContext(expression, ctx)
58-
} else if (ctx.hasOwnProperty(expression)) {
58+
} else if (Object.prototype.hasOwnProperty.call(ctx, expression)) {
5959
value = ctx[expression]
6060
}
6161

lib/tags.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ function getNextTag (nodes, i) {
2222
}
2323
}
2424

25-
return [ i, { tag: undefined } ]
25+
return [i, { tag: undefined }]
2626
}
2727

2828
/**

0 commit comments

Comments
 (0)