Skip to content

Commit 5a88331

Browse files
authored
Merge pull request #105 from posthtml/milestone-1.6.1
Milestone 1.6.1
2 parents a47c11b + d18df2a commit 5a88331

File tree

8 files changed

+33
-11
lines changed

8 files changed

+33
-11
lines changed

INDEX.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@
4343
<dt><a href="#escapeHTML">escapeHTML(unescaped)</a> ⇒ <code>String</code></dt>
4444
<dd><p>Escape HTML characters with their respective entities</p>
4545
</dd>
46-
<dt><a href="#placeholders">placeholders(input, ctx, settings)</a> ⇒ <code>String</code></dt>
46+
<dt><a href="#placeholders">placeholders(input, ctx, settings, opts)</a> ⇒ <code>String</code></dt>
4747
<dd><p>Replace Expressions</p>
4848
</dd>
4949
<dt><a href="#getNextTag">getNextTag(nodes, i)</a> ⇒ <code>Array</code></dt>
@@ -200,7 +200,7 @@ Escape HTML characters with their respective entities
200200

201201
<a name="placeholders"></a>
202202

203-
## placeholders(input, ctx, settings) ⇒ <code>String</code>
203+
## placeholders(input, ctx, settings, opts) ⇒ <code>String</code>
204204
Replace Expressions
205205

206206
**Kind**: global function
@@ -211,6 +211,7 @@ Replace Expressions
211211
| input | <code>String</code> | Input |
212212
| ctx | <code>Object</code> | Context |
213213
| settings | <code>Array</code> | Settings |
214+
| opts | <code>Array</code> | Options |
214215

215216
<a name="getNextTag"></a>
216217

changelog.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,12 @@
1+
## [1.6.1](https://github.com/posthtml/posthtml-expressions/compare/v1.6.0...v1.6.1) (2020-11-09)
2+
3+
4+
### Bug Fixes
5+
6+
* check if key exists in locals as text, close [#102](https://github.com/posthtml/posthtml-expressions/issues/102) ([1d7596a](https://github.com/posthtml/posthtml-expressions/commit/1d7596a8a4d12fd29a74f03637057772a9b81d09))
7+
8+
9+
110
# [1.6.0](https://github.com/posthtml/posthtml-expressions/compare/v1.5.0...v1.6.0) (2020-10-30)
211

312

lib/index.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,7 @@ function walk (opts, nodes) {
182182

183183
// if we have a string, match and replace it
184184
if (typeof node === 'string') {
185-
node = placeholders(node, ctx, delimitersSettings)
185+
node = placeholders(node, ctx, delimitersSettings, opts)
186186
node = node
187187
.replace(unescapeDelimitersReplace, delimitersSettings[0].text[0])
188188
.replace(delimitersReplace, delimitersSettings[1].text[0])
@@ -196,14 +196,14 @@ function walk (opts, nodes) {
196196
if (node.attrs) {
197197
for (const key in node.attrs) {
198198
if (typeof node.attrs[key] === 'string') {
199-
node.attrs[key] = placeholders(node.attrs[key], ctx, delimitersSettings)
199+
node.attrs[key] = placeholders(node.attrs[key], ctx, delimitersSettings, opts)
200200
node.attrs[key] = node.attrs[key]
201201
.replace(unescapeDelimitersReplace, delimitersSettings[0].text[0])
202202
.replace(delimitersReplace, delimitersSettings[1].text[0])
203203
}
204204

205205
// if key is parametr
206-
const _key = placeholders(key, ctx, delimitersSettings)
206+
const _key = placeholders(key, ctx, delimitersSettings, opts)
207207
if (key !== _key) {
208208
node.attrs[_key] = node.attrs[key]
209209
delete node.attrs[key]

lib/placeholders.js

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,11 @@ function escapeHTML (unescaped) {
3232
* @param {String} input Input
3333
* @param {Object} ctx Context
3434
* @param {Array} settings Settings
35+
* @param {Array} opts Options
3536
*
3637
* @return {String} input Replaced Input
3738
*/
38-
function placeholders (input, ctx, settings) {
39+
function placeholders (input, ctx, settings, opts) {
3940
// Since we are matching multiple sets of delimiters, we need to run a loop
4041
// here to match each one.
4142
for (let i = 0; i < settings.length; i++) {
@@ -54,7 +55,13 @@ function placeholders (input, ctx, settings) {
5455
let value
5556

5657
if (/\W+/.test(expression)) {
57-
value = vm.runInContext(expression, ctx)
58+
try {
59+
value = vm.runInContext(expression, ctx)
60+
} catch (error) {
61+
if (opts.strictMode) {
62+
throw new SyntaxError(error)
63+
}
64+
}
5865
} else if (Object.prototype.hasOwnProperty.call(ctx, expression)) {
5966
value = ctx[expression]
6067
}

package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "posthtml-expressions",
3-
"version": "1.6.0",
3+
"version": "1.6.1",
44
"description": "Expressions Plugin for PostHTML",
55
"engines": {
66
"node": ">=10"
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
11
<if condition="key_not_exists">
22
it works!
33
</if>
4+
5+
<if condition="key_not_exists">
6+
{{ key_not_exists.foo }}
7+
it works!
8+
</if>

test/test-core.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ test('Expressions - spacing', (t) => {
6666

6767
test('Expressions - error', (t) => {
6868
return error('expression_error', (err) => {
69-
t.is(err.message, 'Invalid or unexpected token')
69+
t.is(err.message, 'SyntaxError: Invalid or unexpected token')
7070
})
7171
})
7272

0 commit comments

Comments
 (0)