-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Some of this is hacky ways to normalizing the inputs. Unfortunate, but effective. Closes #715
- Loading branch information
1 parent
c77d0d8
commit 1b4be9b
Showing
17 changed files
with
182 additions
and
72 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -101,7 +101,8 @@ | |
wrap_attributes, | ||
wrap_attributes_indent_size, | ||
end_with_newline, | ||
extra_liners; | ||
extra_liners, | ||
eol; | ||
|
||
options = options || {}; | ||
|
||
|
@@ -130,12 +131,15 @@ | |
extra_liners = Array.isArray(options.extra_liners) ? | ||
options.extra_liners.concat() : (typeof options.extra_liners === 'string') ? | ||
options.extra_liners.split(',') : 'head,body,/html'.split(','); | ||
eol = options.eol ? options.eol : '\n'; | ||
|
||
if(options.indent_with_tabs){ | ||
indent_character = '\t'; | ||
indent_size = 1; | ||
} | ||
|
||
eol = eol.replace(/\\r/, '\r').replace(/\\n/, '\n') | ||
|
||
function Parser() { | ||
|
||
this.pos = 0; //Parser position | ||
|
@@ -684,6 +688,10 @@ | |
this.printer = function(js_source, indent_character, indent_size, wrap_line_length, brace_style) { //handles input/output and some other printing functions | ||
|
||
this.input = js_source || ''; //gets the input for the Parser | ||
|
||
// HACK: newline parsing inconsistent. This brute force normalizes the input. | ||
this.input = this.input.replace(/\r\n|[\r\u2028\u2029]/g, '\n') | ||
|
||
this.output = []; | ||
this.indent_character = indent_character; | ||
this.indent_string = ''; | ||
|
@@ -859,8 +867,11 @@ | |
|
||
var indentation = multi_parser.get_full_indent(script_indent_level); | ||
if (_beautifier) { | ||
|
||
// call the Beautifier if avaliable | ||
text = _beautifier(text.replace(/^\s*/, indentation), options); | ||
var child_options = JSON.parse(JSON.stringify(options)); | ||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
bitwiseman
Author
Member
|
||
child_options.eol = '\n'; | ||
text = _beautifier(text.replace(/^\s*/, indentation), child_options); | ||
} else { | ||
// simply indent the string otherwise | ||
var white = text.match(/^\s*/)[0]; | ||
|
@@ -889,9 +900,16 @@ | |
multi_parser.last_text = multi_parser.token_text; | ||
} | ||
var sweet_code = multi_parser.output.join('').replace(/[\r\n\t ]+$/, ''); | ||
|
||
// establish end_with_newline | ||
if (end_with_newline) { | ||
sweet_code += '\n'; | ||
} | ||
|
||
if (eol != '\n') { | ||
sweet_code = sweet_code.replace(/[\n]/g, eol); | ||
} | ||
|
||
return sweet_code; | ||
} | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
1 comment
on commit 1b4be9b
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why not simple /\n/g
instead of /[\n]/g
?
Not sure how much this matters, but this doesn't work in old browsers and in WSH+JScript:
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON#Browser_compatibility
May be converted into something like
Anyway, I already have some automated patches for things like string[N] vs string.charAt(N):
https://github.com/Infocatcher/AkelPad_scripts/blob/d2dc1306146f108294b7ceb821990fdc51db6b84/jsBeautifier.js#L7756-L7814
So, this doesn't matters for me, if may be easily fixed. And the main question is about officially supported JavaScript versions.
An yes, it's good for me to keep the code more old-school, of course. :)