Skip to content

Commit

Permalink
minify-javascript-script: remove trailing semicolon
Browse files Browse the repository at this point in the history
  • Loading branch information
wooorm committed Nov 17, 2018
1 parent bda84c4 commit e8cacd3
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 4 deletions.
8 changes: 7 additions & 1 deletion packages/rehype-minify-javascript-script/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,15 @@ function transform(tree) {
}

function visitor(node) {
var val
if (js(node) && !has(node, 'src')) {
try {
fromString(node, Uglify.minify(toString(node)).code)
val = Uglify.minify(toString(node)).code
/* istanbul ignore else - not used, but just to be sure there’s an if */
if (val.charAt(val.length - 1) === ';') {
val = val.slice(0, -1)
}
fromString(node, val)
} catch (error) {}
}
}
2 changes: 1 addition & 1 deletion packages/rehype-minify-javascript-script/readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ npm install rehype-minify-javascript-script
##### Out

```html
<script>var name="World";console.log("Hello, "+name+"!");</script>
<script>var name="World";console.log("Hello, "+name+"!")</script>
```

## License
Expand Down
4 changes: 2 additions & 2 deletions packages/rehype-minify-javascript-script/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ test('rehype-minify-javascript-script', function(t) {
.runSync(
h('script', 'var name = "World";\nconsole.log("Hello, " + name + "!");')
),
h('script', 'var name="World";console.log("Hello, "+name+"!");')
h('script', 'var name="World";console.log("Hello, "+name+"!")')
)

t.deepEqual(
Expand All @@ -26,7 +26,7 @@ test('rehype-minify-javascript-script', function(t) {
'(function () {var name = "World";\nconsole.log("Hello, " + name + "!");})()'
)
),
h('script', 'console.log("Hello, World!");')
h('script', 'console.log("Hello, World!")')
)

t.deepEqual(
Expand Down

0 comments on commit e8cacd3

Please sign in to comment.