mirror of
https://github.com/beautifier/js-beautify.git
synced 2025-02-18 20:28:59 +00:00
Treat HTML comments better, fixes #99
This commit is contained in:
parent
c2e8472664
commit
068ec1701a
5
Makefile
5
Makefile
@ -47,6 +47,11 @@ testj:
|
||||
./tests/run-tests
|
||||
echo
|
||||
|
||||
edit:
|
||||
vim \
|
||||
beautify.js python/jsbeautifier/__init__.py \
|
||||
tests/beautify-tests.js python/jsbeautifier/tests/testjsbeautifier.py
|
||||
|
||||
tests: testp testj
|
||||
|
||||
test: testp testj
|
||||
|
@ -570,8 +570,13 @@ function js_beautify(js_source_text, options) {
|
||||
|
||||
if (c === '<' && input.substring(parser_pos - 1, parser_pos + 3) === '<!--') {
|
||||
parser_pos += 3;
|
||||
c = '<!--';
|
||||
while (input[parser_pos] != '\n' && parser_pos < input_length) {
|
||||
c += input[parser_pos];
|
||||
parser_pos++;
|
||||
}
|
||||
flags.in_html_comment = true;
|
||||
return ['<!--', 'TK_COMMENT'];
|
||||
return [c, 'TK_COMMENT'];
|
||||
}
|
||||
|
||||
if (c === '-' && flags.in_html_comment && input.substring(parser_pos - 1, parser_pos + 2) === '-->') {
|
||||
|
@ -603,8 +603,12 @@ class Beautifier:
|
||||
|
||||
if c == '<' and self.input[parser_pos - 1 : parser_pos + 3] == '<!--':
|
||||
parser_pos += 3
|
||||
c = '<!--'
|
||||
while parser_pos < len(self.input) and self.input[parser_pos] != '\n':
|
||||
c += self.input[parser_pos]
|
||||
parser_pos += 1
|
||||
self.flags.in_html_comment = True
|
||||
return '<!--', 'TK_COMMENT'
|
||||
return c, 'TK_COMMENT'
|
||||
|
||||
if c == '-' and self.flags.in_html_comment and self.input[parser_pos - 1 : parser_pos + 2] == '-->':
|
||||
self.flags.in_html_comment = False
|
||||
|
@ -418,6 +418,8 @@ class TestJSBeautifier(unittest.TestCase):
|
||||
bt("var x = {\n set function()\n}")
|
||||
bt("var x = set\n\nfunction() {}")
|
||||
|
||||
bt('<!-- foo\nbar();\n-->');
|
||||
bt('<!-- dont crash');
|
||||
|
||||
def decodesto(self, input, expectation=None):
|
||||
self.assertEqual(
|
||||
|
@ -471,8 +471,12 @@ function run_beautifier_tests(test_obj)
|
||||
bt("var x = {\n set function()\n}");
|
||||
bt("var x = set\n\nfunction() {}");
|
||||
|
||||
bt('<!-- foo\nbar();\n-->');
|
||||
bt('<!-- dont crash');
|
||||
|
||||
opts.space_before_conditional = false;
|
||||
bt('if(a) b()');
|
||||
|
||||
return sanitytest;
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user