diff --git a/changelog.md b/changelog.md index 90a56a5..b4cd351 100644 --- a/changelog.md +++ b/changelog.md @@ -1,3 +1,17 @@ +# [1.9.0](https://github.com/posthtml/posthtml-expressions/compare/v1.8.1...v1.9.0) (2021-08-23) + + +### Features + +* remove script locals, close [#120](https://github.com/posthtml/posthtml-expressions/issues/120) ([023fcb9](https://github.com/posthtml/posthtml-expressions/commit/023fcb9845939524265589d5b59741e41ea73aa4)) + + +### Performance Improvements + +* default locals attr ([73dc216](https://github.com/posthtml/posthtml-expressions/commit/73dc216c2adae6de9582c1c65a83d460df836f0a)) + + + ## [1.8.1](https://github.com/posthtml/posthtml-expressions/compare/v1.8.0...v1.8.1) (2021-08-10) diff --git a/lib/index.js b/lib/index.js index 2095a9f..50375a0 100644 --- a/lib/index.js +++ b/lib/index.js @@ -114,7 +114,9 @@ module.exports = function postHTMLExpressions (options) { loopTags: ['each'], scopeTags: ['scope'], ignoredTag: 'raw', - strictMode: true + strictMode: true, + localsAttr: 'locals', + removeScriptLocals: false }, options) // set tags diff --git a/lib/locals.js b/lib/locals.js index 081405b..2e631c2 100644 --- a/lib/locals.js +++ b/lib/locals.js @@ -21,7 +21,7 @@ const ctx = vm.createContext({ module }) */ function scriptDataLocals (tree, options) { const locals = {} - const localsAttr = options.localsAttr || 'locals' + const localsAttr = options.localsAttr match.call(tree, matchHelper(`script[${localsAttr}]`), node => { if (node.content) { @@ -34,6 +34,10 @@ function scriptDataLocals (tree, options) { } catch {}; } + if (options.removeScriptLocals) { + return '' + } + return node }) diff --git a/package-lock.json b/package-lock.json index 4149619..8d786be 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,6 +1,6 @@ { "name": "posthtml-expressions", - "version": "1.8.1", + "version": "1.9.0", "lockfileVersion": 1, "requires": true, "dependencies": { diff --git a/package.json b/package.json index cba9672..6c72249 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "posthtml-expressions", - "version": "1.8.1", + "version": "1.9.0", "description": "Expressions Plugin for PostHTML", "engines": { "node": ">=10" diff --git a/readme.md b/readme.md index bb3cd61..af6f7de 100644 --- a/readme.md +++ b/readme.md @@ -41,6 +41,7 @@ You have full control over the delimiters used for injecting locals, as well as | **unescapeDelimiters** | `['{{{', '}}}']` | Array containing beginning and ending delimiters for unescaped locals | | **locals** | `{}` | Object containing any local variables you want to be available inside your expressions | | **localsAttr** | `locals` | Attribute name for the tag `script` which contains ***[locals](#locals)***| +| **removeScriptLocals** | `false` | Will remove tag `script` which contains ***[locals](#locals)***| | **conditionalTags** | `['if', 'elseif', 'else']` | Array containing names for tags used for `if/else if/else` statements | | **switchTags** | `['switch', 'case', 'default']` | Array containing names for tags used for `switch/case/default` statements | | **loopTags** | `['each']` | Array containing names for `for` loops | diff --git a/test/expect/script-locals-remove.html b/test/expect/script-locals-remove.html new file mode 100644 index 0000000..03a5f9a --- /dev/null +++ b/test/expect/script-locals-remove.html @@ -0,0 +1 @@ +