Skip to content

Commit 922a0a9

Browse files
authored
Merge pull request #121 from posthtml/milestone-1.9.0
Milestone 1.9.0
2 parents 3f3d261 + fd4287b commit 922a0a9

File tree

9 files changed

+37
-4
lines changed

9 files changed

+37
-4
lines changed

changelog.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,17 @@
1+
# [1.9.0](https://github.com/posthtml/posthtml-expressions/compare/v1.8.1...v1.9.0) (2021-08-23)
2+
3+
4+
### Features
5+
6+
* remove script locals, close [#120](https://github.com/posthtml/posthtml-expressions/issues/120) ([023fcb9](https://github.com/posthtml/posthtml-expressions/commit/023fcb9845939524265589d5b59741e41ea73aa4))
7+
8+
9+
### Performance Improvements
10+
11+
* default locals attr ([73dc216](https://github.com/posthtml/posthtml-expressions/commit/73dc216c2adae6de9582c1c65a83d460df836f0a))
12+
13+
14+
115
## [1.8.1](https://github.com/posthtml/posthtml-expressions/compare/v1.8.0...v1.8.1) (2021-08-10)
216

317

lib/index.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,9 @@ module.exports = function postHTMLExpressions (options) {
114114
loopTags: ['each'],
115115
scopeTags: ['scope'],
116116
ignoredTag: 'raw',
117-
strictMode: true
117+
strictMode: true,
118+
localsAttr: 'locals',
119+
removeScriptLocals: false
118120
}, options)
119121

120122
// set tags

lib/locals.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ const ctx = vm.createContext({ module })
2121
*/
2222
function scriptDataLocals (tree, options) {
2323
const locals = {}
24-
const localsAttr = options.localsAttr || 'locals'
24+
const localsAttr = options.localsAttr
2525

2626
match.call(tree, matchHelper(`script[${localsAttr}]`), node => {
2727
if (node.content) {
@@ -34,6 +34,10 @@ function scriptDataLocals (tree, options) {
3434
} catch {};
3535
}
3636

37+
if (options.removeScriptLocals) {
38+
return ''
39+
}
40+
3741
return node
3842
})
3943

package-lock.json

Lines changed: 1 addition & 1 deletion
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.8.1",
3+
"version": "1.9.0",
44
"description": "Expressions Plugin for PostHTML",
55
"engines": {
66
"node": ">=10"

readme.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ You have full control over the delimiters used for injecting locals, as well as
4141
| **unescapeDelimiters** | `['{{{', '}}}']` | Array containing beginning and ending delimiters for unescaped locals |
4242
| **locals** | `{}` | Object containing any local variables you want to be available inside your expressions |
4343
| **localsAttr** | `locals` | Attribute name for the tag `script` which contains ***[locals](#locals)***|
44+
| **removeScriptLocals** | `false` | Will remove tag `script` which contains ***[locals](#locals)***|
4445
| **conditionalTags** | `['if', 'elseif', 'else']` | Array containing names for tags used for `if/else if/else` statements |
4546
| **switchTags** | `['switch', 'case', 'default']` | Array containing names for tags used for `switch/case/default` statements |
4647
| **loopTags** | `['each']` | Array containing names for `for` loops |
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
<div>My name: Scrum</div>
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<script locals>
2+
module.exports = {
3+
name: 'Scrum'
4+
}
5+
</script>
6+
7+
<div>My name: {{name}}</div>

test/test-locals.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,3 +34,7 @@ function clean (html) {
3434
test('Basic', (t) => {
3535
return process(t, 'script-locals')
3636
})
37+
38+
test('Remove script locals', (t) => {
39+
return process(t, 'script-locals-remove', { removeScriptLocals: true })
40+
})

0 commit comments

Comments
 (0)