Skip to content

Commit

Permalink
Add support for es module
Browse files Browse the repository at this point in the history
  • Loading branch information
bitwiseman committed Apr 5, 2020
1 parent a98a43d commit c006887
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 5 deletions.
2 changes: 1 addition & 1 deletion js/src/html/beautifier.js
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ var get_custom_beautifier_name = function(tag_check, raw_token) {
// For those without a type attribute use default;
if (typeAttribute.search('text/css') > -1) {
result = 'css';
} else if (typeAttribute.search(/(text|application|dojo)\/(x-)?(javascript|ecmascript|jscript|livescript|(ld\+)?json|method|aspect)/) > -1) {
} else if (typeAttribute.search(/module|((text|application|dojo)\/(x-)?(javascript|ecmascript|jscript|livescript|(ld\+)?json|method|aspect))/) > -1) {
result = 'javascript';
} else if (typeAttribute.search(/(text|application|dojo)\/(x-)?(html)/) > -1) {
result = 'html';
Expand Down
12 changes: 10 additions & 2 deletions js/test/generated/beautify-html-tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -670,10 +670,18 @@ function run_html_tests(test_obj, Urlencoded, js_beautify, html_beautify, css_be
'\n' +
'<input type="submit"></input>');
bth(
'<script type="text/javascript">var foo = "bar";</script>',
'<script type="text/javascript">console.log(1 + 1);</script>',
// -- output --
'<script type="text/javascript">\n' +
' var foo = "bar";\n' +
' console.log(1 + 1);\n' +
'</script>');

// Issue #1706 - es script module
bth(
'<script type="module">console.log(1 + 1);</script>',
// -- output --
'<script type="module">\n' +
' console.log(1 + 1);\n' +
'</script>');
bth(
'<script type="application/javascript">var foo = "bar";</script>',
Expand Down
12 changes: 10 additions & 2 deletions test/data/html/tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -516,10 +516,18 @@ exports.test_data = {
'<input type="submit"></input>'
]
}, {
input: '<script type="text/javascript">var foo = "bar";</script>',
input: '<script type="text/javascript">console.log(1 + 1);</script>',
output: [
'<script type="text/javascript">',
' var foo = "bar";',
' console.log(1 + 1);',
'</script>'
]
}, {
comment: 'Issue #1706 - es script module',
input: '<script type="module">console.log(1 + 1);</script>',
output: [
'<script type="module">',
' console.log(1 + 1);',
'</script>'
]
}, {
Expand Down

0 comments on commit c006887

Please sign in to comment.