Skip to content

Commit

Permalink
Release: 1.14.10
Browse files Browse the repository at this point in the history
  • Loading branch information
GitHub Action committed Nov 7, 2023
1 parent 13bb155 commit 340b577
Show file tree
Hide file tree
Showing 9 changed files with 138 additions and 34 deletions.
32 changes: 21 additions & 11 deletions js/lib/beautifier.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion js/lib/beautifier.js.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion js/lib/beautifier.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion js/lib/beautifier.min.js.map

Large diffs are not rendered by default.

8 changes: 2 additions & 6 deletions js/lib/beautify-css.js
Original file line number Diff line number Diff line change
Expand Up @@ -1281,13 +1281,11 @@ Beautifier.prototype.beautify = function() {

if (variable.match(/[ :]$/)) {
// we have a variable or pseudo-class, add it and insert one space before continuing
variable = this.eatString(": ").replace(/\s$/, '');
variable = this.eatString(": ").replace(/\s+$/, '');
this.print_string(variable);
this._output.space_before_token = true;
}

variable = variable.replace(/\s$/, '');

// might be sass variable
if (parenLevel === 0 && variable.indexOf(':') !== -1) {
insidePropertyValue = true;
Expand All @@ -1307,13 +1305,11 @@ Beautifier.prototype.beautify = function() {

if (variableOrRule.match(/[ :]$/)) {
// we have a variable or pseudo-class, add it and insert one space before continuing
variableOrRule = this.eatString(": ").replace(/\s$/, '');
variableOrRule = this.eatString(": ").replace(/\s+$/, '');
this.print_string(variableOrRule);
this._output.space_before_token = true;
}

variableOrRule = variableOrRule.replace(/\s$/, '');

// might be less variable
if (parenLevel === 0 && variableOrRule.indexOf(':') !== -1) {
insidePropertyValue = true;
Expand Down
24 changes: 19 additions & 5 deletions js/lib/beautify.js
Original file line number Diff line number Diff line change
Expand Up @@ -1036,7 +1036,9 @@ Beautifier.prototype.handle_word = function(current_token) {
}

if (this._flags.last_token.type === TOKEN.COMMA || this._flags.last_token.type === TOKEN.START_EXPR || this._flags.last_token.type === TOKEN.EQUALS || this._flags.last_token.type === TOKEN.OPERATOR) {
if (!this.start_of_object_property()) {
if (!this.start_of_object_property() && !(
// start of object property is different for numeric values with +/- prefix operators
in_array(this._flags.last_token.text, ['+', '-']) && this._last_last_text === ':' && this._flags.parent.mode === MODE.ObjectLiteral)) {
this.allow_wrap_or_preserved_newline(current_token);
}
}
Expand Down Expand Up @@ -1317,6 +1319,12 @@ Beautifier.prototype.handle_operator = function(current_token) {
return;
}

if (in_array(current_token.text, ['-', '+']) && this.start_of_object_property()) {
// numeric value with +/- symbol in front as a property
this.print_token(current_token);
return;
}

// Allow line wrapping between operators when operator_position is
// set to before or preserve
if (this._flags.last_token.type === TOKEN.OPERATOR && in_array(this._options.operator_position, OPERATOR_POSITION_BEFORE_OR_PRESERVE)) {
Expand Down Expand Up @@ -2143,12 +2151,13 @@ var nonASCIIidentifierChars = "\\u0300-\\u036f\\u0483-\\u0487\\u0591-\\u05bd\\u0
//var nonASCIIidentifierStart = new RegExp("[" + nonASCIIidentifierStartChars + "]");
//var nonASCIIidentifier = new RegExp("[" + nonASCIIidentifierStartChars + nonASCIIidentifierChars + "]");

var identifierStart = "(?:\\\\u[0-9a-fA-F]{4}|[" + baseASCIIidentifierStartChars + nonASCIIidentifierStartChars + "])";
var identifierChars = "(?:\\\\u[0-9a-fA-F]{4}|[" + baseASCIIidentifierChars + nonASCIIidentifierStartChars + nonASCIIidentifierChars + "])*";
var unicodeEscapeOrCodePoint = "\\\\u[0-9a-fA-F]{4}|\\\\u\\{[0-9a-fA-F]+\\}";
var identifierStart = "(?:" + unicodeEscapeOrCodePoint + "|[" + baseASCIIidentifierStartChars + nonASCIIidentifierStartChars + "])";
var identifierChars = "(?:" + unicodeEscapeOrCodePoint + "|[" + baseASCIIidentifierChars + nonASCIIidentifierStartChars + nonASCIIidentifierChars + "])*";

exports.identifier = new RegExp(identifierStart + identifierChars, 'g');
exports.identifierStart = new RegExp(identifierStart);
exports.identifierMatch = new RegExp("(?:\\\\u[0-9a-fA-F]{4}|[" + baseASCIIidentifierChars + nonASCIIidentifierStartChars + nonASCIIidentifierChars + "])+");
exports.identifierMatch = new RegExp("(?:" + unicodeEscapeOrCodePoint + "|[" + baseASCIIidentifierChars + nonASCIIidentifierStartChars + nonASCIIidentifierChars + "])+");

var nonASCIIwhitespace = /[\u1680\u180e\u2000-\u200a\u202f\u205f\u3000\ufeff]/; // jshint ignore:line

Expand Down Expand Up @@ -2953,6 +2962,9 @@ function unescape_string(s) {
matched = input_scan.match(/x([0-9A-Fa-f]{2})/g);
} else if (input_scan.peek() === 'u') {
matched = input_scan.match(/u([0-9A-Fa-f]{4})/g);
if (!matched) {
matched = input_scan.match(/u\{([0-9A-Fa-f]+)\}/g);
}
} else {
out += '\\';
if (input_scan.hasNext()) {
Expand All @@ -2976,7 +2988,9 @@ function unescape_string(s) {
} else if (escaped >= 0x00 && escaped < 0x20) {
// leave 0x00...0x1f escaped
out += '\\' + matched[0];
continue;
} else if (escaped > 0x10FFFF) {
// If the escape sequence is out of bounds, keep the original sequence and continue conversion
out += '\\' + matched[0];
} else if (escaped === 0x22 || escaped === 0x27 || escaped === 0x5c) {
// single-quote, apostrophe, backslash - escape these
out += '\\' + String.fromCharCode(escaped);
Expand Down
8 changes: 5 additions & 3 deletions js/lib/cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@
*/
/*jshint strict:false */
/*jshint esversion: 6 */

const { globSync } = require('glob');

var debug = process.env.DEBUG_JSBEAUTIFY || process.env.JSBEAUTIFY_DEBUG ? function() {
console.error.apply(console, arguments);
Expand All @@ -41,7 +44,7 @@ var fs = require('fs'),
cc = require('config-chain'),
beautify = require('../index'),
nopt = require('nopt'),
glob = require('glob');
glob = require("glob");

nopt.invalidHandler = function(key, val) {
throw new Error(key + " was invalid with value \"" + val + "\"");
Expand Down Expand Up @@ -634,8 +637,7 @@ function checkFiles(parsed) {
// Input was a glob
if (isGlob) {
hadGlob = true;
foundFiles = glob(f, {
sync: true,
foundFiles = globSync(f, {
absolute: true,
ignore: ['**/node_modules/**', '**/.git/**']
});
Expand Down
51 changes: 47 additions & 4 deletions js/test/generated/beautify-javascript-tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -362,6 +362,18 @@ function run_javascript_tests(test_obj, Urlencoded, js_beautify, html_beautify,
'var' + unicode_char(160) + unicode_char(3232) + '_' + unicode_char(3232) + ' = "hi";',
// -- output --
'var ' + unicode_char(3232) + '_' + unicode_char(3232) + ' = "hi";');

// Issue #2159: Invalid prettification of object with unicode escape character as object key - test scenario: object with unicode as key
bt(
'{\\u{1d4b6}:"ascr"}',
// -- output --
'{\n' +
' \\u{1d4b6}: "ascr"\n' +
'}');
bt(
'var \\u{E4}\\u{ca0}\\u{0cA0}\\u{000000Ca0} = {\n' +
' \\u{ca0}rgerlich: true\n' +
'};');


//============================================================
Expand Down Expand Up @@ -2755,6 +2767,18 @@ function run_javascript_tests(test_obj, Urlencoded, js_beautify, html_beautify,
' proper: "first_token_should_never_wrap" +\n' +
' "but_this_can"\n' +
'}');

// Issue #1932 - Javascript object property with -/+ symbol wraps issue
bt(
'{\n' +
' "1234567891234567891234567891234": -433,\n' +
' "abcdefghijklmnopqrstuvwxyz12345": +11\n' +
'}',
// -- output --
'{\n' +
' "1234567891234567891234567891234": -433,\n' +
' "abcdefghijklmnopqrstuvwxyz12345": +11\n' +
'}');
test_fragment(
'' + wrap_input_2 + '',
// -- output --
Expand Down Expand Up @@ -10271,21 +10295,40 @@ function run_javascript_tests(test_obj, Urlencoded, js_beautify, html_beautify,
bt('"—"');
bt('"\\x41\\x42\\x43\\x01"', '"\\x41\\x42\\x43\\x01"');
bt('"\\u2022"', '"\\u2022"');
bt('"\\u{2022}"', '"\\u{2022}"');
bt('a = /\s+/');
// bt('a = /\\x41/','a = /A/');
bt('"\\u2022";a = /\s+/;"\\x41\\x42\\x43\\x01".match(/\\x41/);','"\\u2022";\na = /\s+/;\n"\\x41\\x42\\x43\\x01".match(/\\x41/);');
test_fragment('"\\x22\\x27",\'\\x22\\x27\',"\\x5c",\'\\x5c\',"\\xff and \\xzz","unicode \\u0000 \\u0022 \\u0027 \\u005c \\uffff \\uzzzz"', '"\\x22\\x27", \'\\x22\\x27\', "\\x5c", \'\\x5c\', "\\xff and \\xzz", "unicode \\u0000 \\u0022 \\u0027 \\u005c \\uffff \\uzzzz"');

test_fragment('"\\x41\\x42\\x01\\x43"');
test_fragment('"\\x41\\x42\\u0001\\x43"');
test_fragment('"\\x41\\x42\\u{0001}\\x43"');
test_fragment('"\\x20\\x40\\x4a"');
test_fragment('"\\xff\\x40\\x4a"');
test_fragment('"\\u0072\\u016B\\u0137\\u012B\\u0074\\u0069\\u0073"');
test_fragment('"\\u{0072}\\u{016B}\\u{110000}\\u{137}\\u012B\\x74\\u{0000069}\\u{073}"');
test_fragment('"Google Chrome est\\u00E1 actualizado."');
test_fragment(
'"\\x22\\x27",\'\\x22\\x27\',"\\x5c",\'\\x5c\',"\\xff and \\xzz","unicode \\u0000 \\u0022 \\u0027 \\u005c \\uffff \\uzzzz"',
'"\\x22\\x27", \'\\x22\\x27\', "\\x5c", \'\\x5c\', "\\xff and \\xzz", "unicode \\u0000 \\u0022 \\u0027 \\u005c \\uffff \\uzzzz"');

opts.unescape_strings = true;

test_fragment('"\\x41\\x42\\x01\\x43"', '"AB\\x01C"');
test_fragment('"\\x41\\x42\\u0001\\x43"', '"AB\\u0001C"');
test_fragment('"\\x41\\x42\\u{0001}\\x43"', '"AB\\u{0001}C"');
test_fragment('"\\x20\\x40\\x4a"', '" @J"');
test_fragment('"\\xff\\x40\\x4a"');
test_fragment('"\\u0072\\u016B\\u0137\\u012B\\u0074\\u0069\\u0073"', '"\u0072\u016B\u0137\u012B\u0074\u0069\u0073"');
test_fragment('"\\u{0072}\\u{016B}\\u{110000}\\u{137}\\u012B\\x74\\u{0000069}\\u{073}"', '"\u0072\u016B\\u{110000}\u0137\u012B\u0074\u0069\u0073"');
test_fragment('"Google Chrome est\\u00E1 actualizado."', '"Google Chrome está actualizado."');
test_fragment('"\\x22\\x27",\'\\x22\\x27\',"\\x5c",\'\\x5c\',"\\xff and \\xzz","unicode \\u0000 \\u0022 \\u0027 \\u005c \\uffff"',
'"\\"\\\'", \'\\"\\\'\', "\\\\", \'\\\\\', "\\xff and \\xzz", "unicode \\u0000 \\" \\\' \\\\ ' + unicode_char(0xffff) + '"');
test_fragment(
'"\\x22\\x27",\'\\x22\\x27\',"\\x5c",\'\\x5c\',"\\xff and \\xzz","unicode \\u0000 \\u0022 \\u0027 \\u005c \\uffff"',
'"\\"\\\'", \'\\"\\\'\', "\\\\", \'\\\\\', "\\xff and \\xzz", "unicode \\u0000 \\" \\\' \\\\ ' + unicode_char(0xffff) + '"');

// For error case, return the string unchanged
test_fragment('"\\x22\\x27",\'\\x22\\x27\',"\\x5c",\'\\x5c\',"\\xff and \\xzz","unicode \\u0000 \\u0022 \\u0027 \\u005c \\uffff \\uzzzz"',
test_fragment(
'"\\x22\\x27",\'\\x22\\x27\',"\\x5c",\'\\x5c\',"\\xff and \\xzz","unicode \\u0000 \\u0022 \\u0027 \\u005c \\uffff \\uzzzz"',
'"\\"\\\'", \'\\"\\\'\', "\\\\", \'\\\\\', "\\xff and \\xzz", "unicode \\u0000 \\u0022 \\u0027 \\u005c \\uffff \\uzzzz"');

reset_options();
Expand Down
43 changes: 41 additions & 2 deletions python/jsbeautifier/tests/generated/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,17 +83,32 @@ def unicode_char(value):
bt('"—"')
bt('"\\x41\\x42\\x43\\x01"', '"\\x41\\x42\\x43\\x01"')
bt('"\\u2022"', '"\\u2022"')
bt('"\\u{2022}"', '"\\u{2022}"')
bt('a = /\s+/')
#bt('a = /\\x41/','a = /A/')
bt('"\\u2022";a = /\s+/;"\\x41\\x42\\x43\\x01".match(/\\x41/);','"\\u2022";\na = /\s+/;\n"\\x41\\x42\\x43\\x01".match(/\\x41/);')
test_fragment('"\\x22\\x27",\'\\x22\\x27\',"\\x5c",\'\\x5c\',"\\xff and \\xzz","unicode \\u0000 \\u0022 \\u0027 \\u005c \\uffff \\uzzzz"', '"\\x22\\x27", \'\\x22\\x27\', "\\x5c", \'\\x5c\', "\\xff and \\xzz", "unicode \\u0000 \\u0022 \\u0027 \\u005c \\uffff \\uzzzz"')

test_fragment('"\\x41\\x42\\x01\\x43"')
test_fragment('"\\x41\\x42\\u0001\\x43"')
test_fragment('"\\x41\\x42\\u{0001}\\x43"')
test_fragment('"\\x20\\x40\\x4a"')
test_fragment('"\\xff\\x40\\x4a"')
test_fragment('"\\u0072\\u016B\\u0137\\u012B\\u0074\\u0069\\u0073"')
test_fragment('"\\u{0072}\\u{016B}\\u{110000}\\u{137}\\u012B\\x74\\u{0000069}\\u{073}"')
test_fragment('"Google Chrome est\\u00E1 actualizado."')
test_fragment(
'"\\x22\\x27",\'\\x22\\x27\',"\\x5c",\'\\x5c\',"\\xff and \\xzz","unicode \\u0000 \\u0022 \\u0027 \\u005c \\uffff \\uzzzz"',
'"\\x22\\x27", \'\\x22\\x27\', "\\x5c", \'\\x5c\', "\\xff and \\xzz", "unicode \\u0000 \\u0022 \\u0027 \\u005c \\uffff \\uzzzz"')

self.options.unescape_strings = True

bt('"\\x41\\x42\\x43\\x01"', '"ABC\\x01"')
bt('"\\x41\\x42\\x01\\x43"', '"AB\\x01C"')
bt('"\\x41\\x42\\u0001\\x43"', '"AB\\u0001C"')
bt('"\\x41\\x42\\u{0001}\\x43"', '"AB\\u{0001}C"')
test_fragment('"\\x20\\x40\\x4a"', '" @J"')
test_fragment('"\\xff\\x40\\x4a"')
test_fragment('"\\u0072\\u016B\\u0137\\u012B\\u0074\\u0069\\u0073"', six.u('"\u0072\u016B\u0137\u012B\u0074\u0069\u0073"'))
test_fragment('"\\u{0072}\\u{016B}\\u{110000}\\u{137}\\u012B\\x74\\u{0000069}\\u{073}"', six.u('"\u0072\u016B\\u{110000}\u0137\u012B\u0074\u0069\u0073"'))

bt('a = /\s+/')
test_fragment('"\\x22\\x27",\'\\x22\\x27\',"\\x5c",\'\\x5c\',"\\xff","unicode \\u0000 \\u0022 \\u0027 \\u005c \\uffff"',
Expand Down Expand Up @@ -170,6 +185,18 @@ def unicode_char(value):
'var' + unicode_char(160) + unicode_char(3232) + '_' + unicode_char(3232) + ' = "hi";',
# -- output --
'var ' + unicode_char(3232) + '_' + unicode_char(3232) + ' = "hi";')

# Issue #2159: Invalid prettification of object with unicode escape character as object key - test scenario: object with unicode as key
bt(
'{\\u{1d4b6}:"ascr"}',
# -- output --
'{\n' +
' \\u{1d4b6}: "ascr"\n' +
'}')
bt(
'var \\u{E4}\\u{ca0}\\u{0cA0}\\u{000000Ca0} = {\n' +
' \\u{ca0}rgerlich: true\n' +
'};')


#============================================================
Expand Down Expand Up @@ -2525,6 +2552,18 @@ def unicode_char(value):
' proper: "first_token_should_never_wrap" +\n' +
' "but_this_can"\n' +
'}')

# Issue #1932 - Javascript object property with -/+ symbol wraps issue
bt(
'{\n' +
' "1234567891234567891234567891234": -433,\n' +
' "abcdefghijklmnopqrstuvwxyz12345": +11\n' +
'}',
# -- output --
'{\n' +
' "1234567891234567891234567891234": -433,\n' +
' "abcdefghijklmnopqrstuvwxyz12345": +11\n' +
'}')
test_fragment(
'' + wrap_input_2 + '',
# -- output --
Expand Down

0 comments on commit 340b577

Please sign in to comment.