diff --git a/js/lib/beautify.js b/js/lib/beautify.js
index 6d363e1b8..eb9c365fa 100644
--- a/js/lib/beautify.js
+++ b/js/lib/beautify.js
@@ -801,7 +801,7 @@
}
- if (c === "'" || c === '"' || // string
+ if (c === '`' || c === "'" || c === '"' || // string
(
(c === '/') || // regexp
(opt.e4x && c === "<" && input.slice(parser_pos - 1).match(/^<([-a-zA-Z:0-9_.]+|{[^{}]*}|!\[CDATA\[[\s\S]*?\]\])\s*([-a-zA-Z:0-9_.]+=('[^']*'|"[^"]*"|{[^{}]*})\s*)*\/?\s*>/)) // xml
diff --git a/js/test/beautify-tests.js b/js/test/beautify-tests.js
index 7292b8393..1a8a8d407 100755
--- a/js/test/beautify-tests.js
+++ b/js/test/beautify-tests.js
@@ -294,6 +294,7 @@ function run_beautifier_tests(test_obj, Urlencoded, js_beautify, html_beautify,
test_fragment('"incomplete-string');
test_fragment("'incomplete-string");
test_fragment('/incomplete-regex');
+ test_fragment('`incomplete-template-string');
test_fragment('{a:1},{a:2}', '{\n a: 1\n}, {\n a: 2\n}');
test_fragment('var ary=[{a:1}, {a:2}];', 'var ary = [{\n a: 1\n}, {\n a: 2\n}];');
@@ -1385,6 +1386,10 @@ function run_beautifier_tests(test_obj, Urlencoded, js_beautify, html_beautify,
opts.space_in_empty_paren = false;
opts.space_in_paren = false;
+ // Test template strings
+ bt('`This is a ${template} string.`', '`This is a ${template} string.`');
+ bt('`This\n is\n a\n ${template}\n string.`', '`This\n is\n a\n ${template}\n string.`');
+
// Test that e4x literals passed through when e4x-option is enabled
bt('xml=\n foox;', 'xml = < a b = "c" > < d / > < e >\n foo < /e>x ;');
opts.e4x = true;
@@ -1729,7 +1734,7 @@ function run_beautifier_tests(test_obj, Urlencoded, js_beautify, html_beautify,
bth('
Some text that should not wrap at all. Some text that should not wrap at all. Some text that should not wrap at all. Some text that should not wrap at all. Some text that should not wrap at all. Some text that should not wrap at all. Some text that should not wrap at all.
',
/* expected */
'Some text that should not wrap at all. Some text that should not wrap at all. Some text that should not wrap at all. Some text that should not wrap at all. Some text that should not wrap at all. Some text that should not wrap at all. Some text that should not wrap at all.
');
-
+
//BUGBUG: This should wrap before 40 not after.
opts.wrap_line_length = 40;
//...---------1---------2---------3---------4---------5---------6---------7
diff --git a/python/jsbeautifier/__init__.py b/python/jsbeautifier/__init__.py
index 4837a904f..ee5390bdd 100644
--- a/python/jsbeautifier/__init__.py
+++ b/python/jsbeautifier/__init__.py
@@ -676,7 +676,7 @@ def get_next_token(self):
return comment, 'TK_COMMENT'
- if c == "'" or c == '"' or \
+ if c == '`' or c == "'" or c == '"' or \
( \
(c == '/') or \
(self.opts.e4x and c == "<" and re.match('^<(!\[CDATA\[[\s\S]*?\]\]|[-a-zA-Z:0-9_.]+|\{[^{}]*\})\s*([-a-zA-Z:0-9_.]+=(\{[^{}]*\}|"[^"]*"|\'[^\']*\')\s*)*\/?\s*>', self.input[self.parser_pos - 1:])) \
diff --git a/python/jsbeautifier/tests/testjsbeautifier.py b/python/jsbeautifier/tests/testjsbeautifier.py
index 6da9f7d4f..b81c6ba33 100644
--- a/python/jsbeautifier/tests/testjsbeautifier.py
+++ b/python/jsbeautifier/tests/testjsbeautifier.py
@@ -189,6 +189,7 @@ def test_beautifier(self):
test_fragment('"incomplete-string');
test_fragment("'incomplete-string");
test_fragment('/incomplete-regex');
+ test_fragment('`incomplete-regex');
test_fragment('{a:1},{a:2}', '{\n a: 1\n}, {\n a: 2\n}');
test_fragment('var ary=[{a:1}, {a:2}];', 'var ary = [{\n a: 1\n}, {\n a: 2\n}];');
@@ -1260,6 +1261,9 @@ def test_beautifier(self):
self.options.space_in_paren = False
self.options.space_in_empty_paren = False
+ # Test template strings
+ bt('`This is a ${template} string.`', '`This is a ${template} string.`');
+ bt('`This\n is\n a\n ${template}\n string.`', '`This\n is\n a\n ${template}\n string.`');
# Test that e4x literals passed through when e4x-option is enabled
bt('xml=\n foox;', 'xml = < a b = "c" > < d / > < e >\n foo < /e>x ;');