Permalink
Browse files

Merge branch 'master' into node-package

Conflicts:
	.gitignore
  • Loading branch information...
2 parents f3ebac4 + 25e7c4f commit 88437a3796f33bf327439d46384ec1d56ec95433 @evocateur committed Feb 28, 2013
View
@@ -1 +1,3 @@
node_modules
+*.pyc
+gh-pages
View
@@ -1,3 +0,0 @@
-[submodule "third-party/codemirror"]
- path = third-party/codemirror
- url = http://marijnhaverbeke.nl/git/codemirror
View
@@ -19,7 +19,7 @@
The options are:
indent_size (default 4) — indentation size,
indent_char (default space) — character to indent with,
- max_char (default 70) - maximum amount of characters per line,
+ max_char (default 250) - maximum amount of characters per line (0 = disable)
brace_style (default "collapse") - "collapse" | "expand" | "end-expand"
put braces on the same line as control statements (default), or put braces on own line (Allman / ANSI style), or just put end braces on own line.
unformatted (defaults to inline tags) - list of tags, that shouldn't be reformatted
@@ -50,7 +50,7 @@ function style_html(html_source, options) {
indent_size = options.indent_size || 4;
indent_character = options.indent_char || ' ';
brace_style = options.brace_style || 'collapse';
- max_char = options.max_char == 0 ? Infinity : options.max_char || 70;
+ max_char = options.max_char == 0 ? Infinity : options.max_char || 250;
unformatted = options.unformatted || ['a', 'span', 'bdo', 'em', 'strong', 'dfn', 'code', 'samp', 'kbd', 'var', 'cite', 'abbr', 'acronym', 'q', 'sub', 'sup', 'tt', 'i', 'b', 'big', 'small', 'u', 's', 'strike', 'font', 'ins', 'del', 'pre', 'address', 'dt', 'h1', 'h2', 'h3', 'h4', 'h5', 'h6'];
function Parser() {
View
@@ -352,7 +352,6 @@ function js_beautify(js_source_text, options) {
function get_next_token() {
var i;
- var resulting_string;
n_newlines = 0;
@@ -380,12 +379,14 @@ function js_beautify(js_source_text, options) {
just_added_newline = true;
whitespace_count = 0;
} else {
- if (c === '\t') {
- whitespace_count += 4;
- } else if (c === '\r') {
- // nothing
- } else {
- whitespace_count += 1;
+ if (just_added_newline) {
+ if (c === indent_string) {
+ output.push(indent_string);
+ } else {
+ if (c !== '\r') {
+ output.push(' ');
+ }
+ }
}
}
@@ -398,12 +399,6 @@ function js_beautify(js_source_text, options) {
}
- if (just_added_newline) {
- for (i = 0; i < whitespace_count; i++) {
- output.push(' ');
- }
- }
-
} else {
while (in_array(c, whitespace)) {
@@ -537,10 +532,10 @@ function js_beautify(js_source_text, options) {
((last_type === 'TK_WORD' && is_special_word(last_text)) ||
(last_text === ')' && in_array(flags.previous_mode, ['(COND-EXPRESSION)', '(FOR-EXPRESSION)'])) ||
(last_type === 'TK_COMMA' || last_type === 'TK_COMMENT' || last_type === 'TK_START_EXPR' || last_type === 'TK_START_BLOCK' || last_type === 'TK_END_BLOCK' || last_type === 'TK_OPERATOR' || last_type === 'TK_EQUALS' || last_type === 'TK_EOF' || last_type === 'TK_SEMICOLON')))) { // regexp
- var sep = c;
- var esc = false,
- has_char_escapes = false;
- resulting_string = c;
+ var sep = c,
+ esc = false,
+ has_char_escapes = false,
+ resulting_string = c;
if (parser_pos < input_length) {
if (sep === '/') {
@@ -583,6 +578,11 @@ function js_beautify(js_source_text, options) {
esc = input.charAt(parser_pos) === '\\';
}
parser_pos += 1;
+ if (parser_pos >= input_length) {
+ // incomplete string/rexp when end-of-file reached.
+ // bail out with what had been received so far.
+ return [resulting_string, 'TK_STRING'];
+ }
}
}
@@ -877,7 +877,9 @@ function js_beautify(js_source_text, options) {
}
} else {
if (last_type !== 'TK_OPERATOR') {
- if (last_text === '=' || (is_special_word(last_text) && last_text !== 'else')) {
+ if (last_type === 'TK_EQUALS' ||
+ last_type === 'TK_INLINE_COMMENT' || // inline comment will handle newlines
+ (is_special_word(last_text) && last_text !== 'else')) {
print_single_space();
} else {
print_newline(true);
@@ -1308,7 +1310,8 @@ function js_beautify(js_source_text, options) {
case 'TK_INLINE_COMMENT':
print_single_space();
print_token();
- if (is_expression(flags.mode)) {
+ if (is_expression(flags.mode) ||
+ (last_type === 'TK_WORD' && last_word === 'return')) {
print_single_space();
} else {
force_newline();
View
@@ -106,8 +106,8 @@
white-space: nowrap;
}
</style>
-<script src="jquery/jquery.js"></script>
-<script src="jquery/jquery.cookie.js"></script>
+<script src="third-party/jquery/jquery.js"></script>
+<script src="third-party/jquery/jquery.cookie.js"></script>
<script src="beautify.js"></script>
@@ -741,7 +741,7 @@ def handle_start_block(self, token_text):
if self.opts.brace_style == 'expand':
if self.last_type != 'TK_OPERATOR':
- if self.last_text == '=' or (self.is_special_word(self.last_text) and self.last_text != 'else'):
+ if self.last_type == 'TK_EQUALS' or self.last_type == 'TK_INLINE_COMMENT' or (self.is_special_word(self.last_text) and self.last_text != 'else'):
self.append(' ')
else:
self.append_newline(True)
@@ -1100,7 +1100,7 @@ def handle_block_comment(self, token_text):
def handle_inline_comment(self, token_text):
self.append(' ')
self.append(token_text)
- if self.is_expression(self.flags.mode):
+ if self.is_expression(self.flags.mode) or (self.last_type == 'TK_WORD' and self.last_word == 'return'):
self.append(' ')
else:
self.append_newline_forced()
@@ -177,6 +177,10 @@ def test_beautifier(self):
bt('{a:#1={}}', '{\n a: #1={}\n}');
bt('{a:#1#}', '{\n a: #1#\n}');
+ test_fragment('"incomplete-string');
+ test_fragment("'incomplete-string");
+ 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}];');
@@ -378,6 +382,7 @@ def test_beautifier(self):
test_fragment('if (foo) {', 'if (foo)\n{');
test_fragment('foo {', 'foo\n{');
test_fragment('return {', 'return {'); # return needs the brace. maybe something else as well: feel free to report.
+ test_fragment('return /* inline comment */ {', 'return /* inline comment */ {');
# test_fragment('return\n{', 'return\n{'); # can't support this?, but that's an improbable and extreme case anyway.
test_fragment('return;\n{', 'return;\n{');
@@ -387,6 +392,7 @@ def test_beautifier(self):
test_fragment('if (foo) {', 'if (foo)\n{');
test_fragment('foo {', 'foo\n{');
test_fragment('return {', 'return {'); # return needs the brace. maybe something else as well: feel free to report.
+ test_fragment('return /* inline comment */ {', 'return /* inline comment */ {');
# test_fragment('return\n{', 'return\n{'); # can't support this?, but that's an improbable and extreme case anyway.
test_fragment('return;\n{', 'return;\n{');
@@ -396,6 +402,7 @@ def test_beautifier(self):
test_fragment('if (foo) {', 'if (foo) {');
test_fragment('foo {', 'foo {');
test_fragment('return {', 'return {'); # return needs the brace. maybe something else as well: feel free to report.
+ test_fragment('return /* inline comment */ {', 'return /* inline comment */ {');
# test_fragment('return\n{', 'return\n{'); # can't support this?, but that's an improbable and extreme case anyway.
test_fragment('return;\n{', 'return; {');
View
@@ -222,6 +222,10 @@ function run_beautifier_tests(test_obj)
bt('{a:#1={}}', '{\n a: #1={}\n}');
bt('{a:#1#}', '{\n a: #1#\n}');
+ test_fragment('"incomplete-string');
+ test_fragment("'incomplete-string");
+ 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}];');
@@ -415,6 +419,7 @@ function run_beautifier_tests(test_obj)
test_fragment('if (foo) {', 'if (foo)\n{');
test_fragment('foo {', 'foo\n{');
test_fragment('return {', 'return {'); // return needs the brace. maybe something else as well: feel free to report.
+ test_fragment('return /* inline */ {', 'return /* inline */ {');
// test_fragment('return\n{', 'return\n{'); // can't support this?, but that's an improbable and extreme case anyway.
test_fragment('return;\n{', 'return;\n{');
bt("throw {}");
@@ -426,6 +431,7 @@ function run_beautifier_tests(test_obj)
test_fragment('if (foo) {', 'if (foo)\n{');
test_fragment('foo {', 'foo\n{');
test_fragment('return {', 'return {'); // return needs the brace. maybe something else as well: feel free to report.
+ test_fragment('return /* inline */ {', 'return /* inline */ {');
// test_fragment('return\n{', 'return\n{'); // can't support this?, but that's an improbable and extreme case anyway.
test_fragment('return;\n{', 'return;\n{');
@@ -436,6 +442,7 @@ function run_beautifier_tests(test_obj)
test_fragment('if (foo) {', 'if (foo) {');
test_fragment('foo {', 'foo {');
test_fragment('return {', 'return {'); // return needs the brace. maybe something else as well: feel free to report.
+ test_fragment('return /* inline */ {', 'return /* inline */ {');
// test_fragment('return\n{', 'return\n{'); // can't support this?, but that's an improbable and extreme case anyway.
test_fragment('return;\n{', 'return; {');
File renamed without changes.
File renamed without changes.
@@ -25,7 +25,7 @@ var P_A_C_K_E_R = {
unpack: function (str) {
var chunks = P_A_C_K_E_R.get_chunks(str);
for(var i = 0; i < chunks.length; i++) {
- str = str.replace(chunks[i], P_A_C_K_E_R.unpack_chunk(chunks[i]))
+ str = str.split(chunks[i]).join( P_A_C_K_E_R.unpack_chunk(chunks[i]) );
}
return str;
},

0 comments on commit 88437a3

Please sign in to comment.