From e10042eecd1575d408a3dd32a9d03220d370636f Mon Sep 17 00:00:00 2001 From: Rasmus Jensen Date: Fri, 12 Apr 2013 11:13:01 +0200 Subject: [PATCH 1/6] test case --- js/test/beautify-tests.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/js/test/beautify-tests.js b/js/test/beautify-tests.js index d52147f3..cdbc15a4 100755 --- a/js/test/beautify-tests.js +++ b/js/test/beautify-tests.js @@ -78,6 +78,7 @@ function run_beautifier_tests(test_obj, Urlencoded, js_beautify) opts.jslint_happy = false; opts.keep_array_indentation = false; opts.brace_style = "collapse"; + opts.e4x = true; bt(''); @@ -849,6 +850,7 @@ function run_beautifier_tests(test_obj, Urlencoded, js_beautify) opts.max_preserve_newlines = 8; bt('a = 1;\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\nb = 2;', 'a = 1;\n\n\n\n\n\n\n\nb = 2;'); + test_fragment('xml=\n foox;', 'xml = \n foox;'); Urlencoded.run_tests(sanitytest); From 0036967763635c546d7066041306590daeb87052 Mon Sep 17 00:00:00 2001 From: Rasmus Jensen Date: Fri, 12 Apr 2013 11:21:44 +0200 Subject: [PATCH 2/6] option for ignoring e4x literals --- js/lib/beautify.js | 30 ++++++++++++++++++++++++++++++ js/lib/cli.js | 3 +++ 2 files changed, 33 insertions(+) diff --git a/js/lib/beautify.js b/js/lib/beautify.js index c5c2d53d..3dc89f4c 100644 --- a/js/lib/beautify.js +++ b/js/lib/beautify.js @@ -812,6 +812,36 @@ } } + if (options.e4x && c === '<') { + // pass e4x-literals untouched through the pretty-printing + var xmlRegExp = /<(\/?)([a-zA-Z:0-9]+)\s*([a-zA-Z:0-9]+="[^"]*"\s*)*(\/?)\s*>/g; + var xmlStr = input.slice(parser_pos - 1); + var match = xmlRegExp.exec(xmlStr); + if (match && match.index === 0) { + var rootTag = match[2]; + var depth = 0; + while (match) { + var isEndTag = !! match[1]; + var tagName = match[2]; + var isSingletonTag = !! match[match.length - 1]; + if (tagName === rootTag && !isSingletonTag) { + if (isEndTag) { + --depth; + } else { + ++depth; + } + } + if (depth <= 0) { + break; + } + match = xmlRegExp.exec(xmlStr); + } + var xmlLength = match.index + match[0].length; + parser_pos += xmlLength - 1; + return [xmlStr.slice(0, xmlLength), "TK_WORD"]; + }; + } + if (c === '<' && input.substring(parser_pos - 1, parser_pos + 3) === '