Skip to content

Commit

Permalink
Update js-beautify to 1.11.0
Browse files Browse the repository at this point in the history
  • Loading branch information
bitwiseman committed Apr 6, 2020
1 parent f4777d0 commit 9b5542d
Show file tree
Hide file tree
Showing 8 changed files with 67 additions and 32 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
lib/
node_modules/
package-lock.json
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
3.0.4 /
==================
* Use `TextDocument` from `vscode-languageserver-textdocument`
* Fix formatting for <p> tags with optional closing

3.0.3 / 2019-07-25
==================
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
"devDependencies": {
"@types/mocha": "^5.2.7",
"@types/node": "^10.12.21",
"js-beautify": "^1.10.3",
"js-beautify": "^1.11.0",
"mocha": "^7.0.1",
"rimraf": "^3.0.0",
"tslint": "^6.0.0",
Expand Down
2 changes: 1 addition & 1 deletion src/beautify/beautify-css.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// copied from js-beautify/js/lib/beautify-css.js
// version: 1.10.3
// version: 1.11.0
/* AUTO-GENERATED. DO NOT MODIFY. */
/*
Expand Down
32 changes: 23 additions & 9 deletions src/beautify/beautify-html.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// copied from js-beautify/js/lib/beautify-html.js
// version: 1.10.3
// version: 1.11.0
/* AUTO-GENERATED. DO NOT MODIFY. */
/*
Expand Down Expand Up @@ -1985,7 +1985,7 @@ var get_custom_beautifier_name = function(tag_check, raw_token) {
// For those without a type attribute use default;
if (typeAttribute.search('text/css') > -1) {
result = 'css';
} else if (typeAttribute.search(/(text|application|dojo)\/(x-)?(javascript|ecmascript|jscript|livescript|(ld\+)?json|method|aspect)/) > -1) {
} else if (typeAttribute.search(/module|((text|application|dojo)\/(x-)?(javascript|ecmascript|jscript|livescript|(ld\+)?json|method|aspect))/) > -1) {
result = 'javascript';
} else if (typeAttribute.search(/(text|application|dojo)\/(x-)?(html)/) > -1) {
result = 'html';
Expand Down Expand Up @@ -2376,6 +2376,7 @@ Beautifier.prototype._handle_tag_open = function(printer, raw_token, last_tag_to
// End element tags for unformatted or content_unformatted elements
// are printed raw to keep any newlines inside them exactly the same.
printer.add_raw_token(raw_token);
parser_token.start_tag_token = this._tag_stack.try_pop(parser_token.tag_name);
} else {
printer.traverse_whitespace(raw_token);
this._set_tag_position(printer, raw_token, parser_token, last_tag_token, last_token);
Expand Down Expand Up @@ -2431,8 +2432,13 @@ var TagOpenParserToken = function(parent, raw_token) {
tag_check_match = raw_token.text.match(/^<([^\s>]*)/);
this.tag_check = tag_check_match ? tag_check_match[1] : '';
} else {
tag_check_match = raw_token.text.match(/^{{[#\^]?([^\s}]+)/);
tag_check_match = raw_token.text.match(/^{{(?:[\^]|#\*?)?([^\s}]+)/);
this.tag_check = tag_check_match ? tag_check_match[1] : '';

// handle "{{#> myPartial}}
if (raw_token.text === '{{#>' && this.tag_check === '>' && raw_token.next !== null) {
this.tag_check = raw_token.next.text;
}
}
this.tag_check = this.tag_check.toLowerCase();

Expand Down Expand Up @@ -2561,7 +2567,8 @@ Beautifier.prototype._set_tag_position = function(printer, raw_token, parser_tok
};

//To be used for <p> tag special case:
//var p_closers = ['address', 'article', 'aside', 'blockquote', 'details', 'div', 'dl', 'fieldset', 'figcaption', 'figure', 'footer', 'form', 'h1', 'h2', 'h3', 'h4', 'h5', 'h6', 'header', 'hr', 'main', 'nav', 'ol', 'p', 'pre', 'section', 'table', 'ul'];
var p_closers = ['address', 'article', 'aside', 'blockquote', 'details', 'div', 'dl', 'fieldset', 'figcaption', 'figure', 'footer', 'form', 'h1', 'h2', 'h3', 'h4', 'h5', 'h6', 'header', 'hr', 'main', 'nav', 'ol', 'p', 'pre', 'section', 'table', 'ul'];
var p_parent_excludes = ['a', 'audio', 'del', 'ins', 'map', 'noscript', 'video'];

Beautifier.prototype._do_optional_end_element = function(parser_token) {
var result = null;
Expand All @@ -2572,7 +2579,9 @@ Beautifier.prototype._do_optional_end_element = function(parser_token) {
if (parser_token.is_empty_element || !parser_token.is_start_tag || !parser_token.parent) {
return;

} else if (parser_token.tag_name === 'body') {
}

if (parser_token.tag_name === 'body') {
// A head element’s end tag may be omitted if the head element is not immediately followed by a space character or a comment.
result = result || this._tag_stack.try_pop('head');

Expand All @@ -2589,11 +2598,16 @@ Beautifier.prototype._do_optional_end_element = function(parser_token) {
result = result || this._tag_stack.try_pop('dt', ['dl']);
result = result || this._tag_stack.try_pop('dd', ['dl']);

//} else if (p_closers.indexOf(parser_token.tag_name) !== -1) {
//TODO: THIS IS A BUG FARM. We are not putting this into 1.8.0 as it is likely to blow up.
//A p element’s end tag may be omitted if the p element is immediately followed by an address, article, aside, blockquote, details, div, dl, fieldset, figcaption, figure, footer, form, h1, h2, h3, h4, h5, h6, header, hr, main, nav, ol, p, pre, section, table, or ul element, or if there is no more content in the parent element and the parent element is an HTML element that is not an a, audio, del, ins, map, noscript, or video element, or an autonomous custom element.
//result = result || this._tag_stack.try_pop('p', ['body']);

} else if (parser_token.parent.tag_name === 'p' && p_closers.indexOf(parser_token.tag_name) !== -1) {
// IMPORTANT: this else-if works because p_closers has no overlap with any other element we look for in this method
// check for the parent element is an HTML element that is not an <a>, <audio>, <del>, <ins>, <map>, <noscript>, or <video> element, or an autonomous custom element.
// To do this right, this needs to be coded as an inclusion of the inverse of the exclusion above.
// But to start with (if we ignore "autonomous custom elements") the exclusion would be fine.
var p_parent = parser_token.parent.parent;
if (!p_parent || p_parent_excludes.indexOf(p_parent.tag_name) === -1) {
result = result || this._tag_stack.try_pop('p');
}
} else if (parser_token.tag_name === 'rp' || parser_token.tag_name === 'rt') {
// An rt element’s end tag may be omitted if the rt element is immediately followed by an rt or rp element, or if there is no more content in the parent element.
// An rp element’s end tag may be omitted if the rp element is immediately followed by an rt or rp element, or if there is no more content in the parent element.
Expand Down
2 changes: 1 addition & 1 deletion src/beautify/esm/beautify-css.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// copied from js-beautify/js/lib/beautify-css.js
// version: 1.10.3
// version: 1.11.0
/* AUTO-GENERATED. DO NOT MODIFY. */
/*
Expand Down
32 changes: 23 additions & 9 deletions src/beautify/esm/beautify-html.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// copied from js-beautify/js/lib/beautify-html.js
// version: 1.10.3
// version: 1.11.0
/* AUTO-GENERATED. DO NOT MODIFY. */
/*
Expand Down Expand Up @@ -1985,7 +1985,7 @@ var get_custom_beautifier_name = function(tag_check, raw_token) {
// For those without a type attribute use default;
if (typeAttribute.search('text/css') > -1) {
result = 'css';
} else if (typeAttribute.search(/(text|application|dojo)\/(x-)?(javascript|ecmascript|jscript|livescript|(ld\+)?json|method|aspect)/) > -1) {
} else if (typeAttribute.search(/module|((text|application|dojo)\/(x-)?(javascript|ecmascript|jscript|livescript|(ld\+)?json|method|aspect))/) > -1) {
result = 'javascript';
} else if (typeAttribute.search(/(text|application|dojo)\/(x-)?(html)/) > -1) {
result = 'html';
Expand Down Expand Up @@ -2376,6 +2376,7 @@ Beautifier.prototype._handle_tag_open = function(printer, raw_token, last_tag_to
// End element tags for unformatted or content_unformatted elements
// are printed raw to keep any newlines inside them exactly the same.
printer.add_raw_token(raw_token);
parser_token.start_tag_token = this._tag_stack.try_pop(parser_token.tag_name);
} else {
printer.traverse_whitespace(raw_token);
this._set_tag_position(printer, raw_token, parser_token, last_tag_token, last_token);
Expand Down Expand Up @@ -2431,8 +2432,13 @@ var TagOpenParserToken = function(parent, raw_token) {
tag_check_match = raw_token.text.match(/^<([^\s>]*)/);
this.tag_check = tag_check_match ? tag_check_match[1] : '';
} else {
tag_check_match = raw_token.text.match(/^{{[#\^]?([^\s}]+)/);
tag_check_match = raw_token.text.match(/^{{(?:[\^]|#\*?)?([^\s}]+)/);
this.tag_check = tag_check_match ? tag_check_match[1] : '';

// handle "{{#> myPartial}}
if (raw_token.text === '{{#>' && this.tag_check === '>' && raw_token.next !== null) {
this.tag_check = raw_token.next.text;
}
}
this.tag_check = this.tag_check.toLowerCase();

Expand Down Expand Up @@ -2561,7 +2567,8 @@ Beautifier.prototype._set_tag_position = function(printer, raw_token, parser_tok
};

//To be used for <p> tag special case:
//var p_closers = ['address', 'article', 'aside', 'blockquote', 'details', 'div', 'dl', 'fieldset', 'figcaption', 'figure', 'footer', 'form', 'h1', 'h2', 'h3', 'h4', 'h5', 'h6', 'header', 'hr', 'main', 'nav', 'ol', 'p', 'pre', 'section', 'table', 'ul'];
var p_closers = ['address', 'article', 'aside', 'blockquote', 'details', 'div', 'dl', 'fieldset', 'figcaption', 'figure', 'footer', 'form', 'h1', 'h2', 'h3', 'h4', 'h5', 'h6', 'header', 'hr', 'main', 'nav', 'ol', 'p', 'pre', 'section', 'table', 'ul'];
var p_parent_excludes = ['a', 'audio', 'del', 'ins', 'map', 'noscript', 'video'];

Beautifier.prototype._do_optional_end_element = function(parser_token) {
var result = null;
Expand All @@ -2572,7 +2579,9 @@ Beautifier.prototype._do_optional_end_element = function(parser_token) {
if (parser_token.is_empty_element || !parser_token.is_start_tag || !parser_token.parent) {
return;

} else if (parser_token.tag_name === 'body') {
}

if (parser_token.tag_name === 'body') {
// A head element’s end tag may be omitted if the head element is not immediately followed by a space character or a comment.
result = result || this._tag_stack.try_pop('head');

Expand All @@ -2589,11 +2598,16 @@ Beautifier.prototype._do_optional_end_element = function(parser_token) {
result = result || this._tag_stack.try_pop('dt', ['dl']);
result = result || this._tag_stack.try_pop('dd', ['dl']);

//} else if (p_closers.indexOf(parser_token.tag_name) !== -1) {
//TODO: THIS IS A BUG FARM. We are not putting this into 1.8.0 as it is likely to blow up.
//A p element’s end tag may be omitted if the p element is immediately followed by an address, article, aside, blockquote, details, div, dl, fieldset, figcaption, figure, footer, form, h1, h2, h3, h4, h5, h6, header, hr, main, nav, ol, p, pre, section, table, or ul element, or if there is no more content in the parent element and the parent element is an HTML element that is not an a, audio, del, ins, map, noscript, or video element, or an autonomous custom element.
//result = result || this._tag_stack.try_pop('p', ['body']);

} else if (parser_token.parent.tag_name === 'p' && p_closers.indexOf(parser_token.tag_name) !== -1) {
// IMPORTANT: this else-if works because p_closers has no overlap with any other element we look for in this method
// check for the parent element is an HTML element that is not an <a>, <audio>, <del>, <ins>, <map>, <noscript>, or <video> element, or an autonomous custom element.
// To do this right, this needs to be coded as an inclusion of the inverse of the exclusion above.
// But to start with (if we ignore "autonomous custom elements") the exclusion would be fine.
var p_parent = parser_token.parent.parent;
if (!p_parent || p_parent_excludes.indexOf(p_parent.tag_name) === -1) {
result = result || this._tag_stack.try_pop('p');
}
} else if (parser_token.tag_name === 'rp' || parser_token.tag_name === 'rt') {
// An rt element’s end tag may be omitted if the rt element is immediately followed by an rt or rp element, or if there is no more content in the parent element.
// An rp element’s end tag may be omitted if the rp element is immediately followed by an rt or rp element, or if there is no more content in the parent element.
Expand Down
27 changes: 16 additions & 11 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -421,16 +421,16 @@ isexe@^2.0.0:
resolved "https://registry.yarnpkg.com/isexe/-/isexe-2.0.0.tgz#e8fbf374dc556ff8947a10dcb0572d633f2cfa10"
integrity sha1-6PvzdNxVb/iUehDcsFctYz8s+hA=

js-beautify@^1.10.3:
version "1.10.3"
resolved "https://registry.yarnpkg.com/js-beautify/-/js-beautify-1.10.3.tgz#c73fa10cf69d3dfa52d8ed624f23c64c0a6a94c1"
integrity sha512-wfk/IAWobz1TfApSdivH5PJ0miIHgDoYb1ugSqHcODPmaYu46rYe5FVuIEkhjg8IQiv6rDNPyhsqbsohI/C2vQ==
js-beautify@^1.11.0:
version "1.11.0"
resolved "https://registry.yarnpkg.com/js-beautify/-/js-beautify-1.11.0.tgz#afb873dc47d58986360093dcb69951e8bcd5ded2"
integrity sha512-a26B+Cx7USQGSWnz9YxgJNMmML/QG2nqIaL7VVYPCXbqiKz8PN0waSNvroMtvAK6tY7g/wPdNWGEP+JTNIBr6A==
dependencies:
config-chain "^1.1.12"
editorconfig "^0.15.3"
glob "^7.1.3"
mkdirp "~0.5.1"
nopt "~4.0.1"
mkdirp "~1.0.3"
nopt "^4.0.3"

js-tokens@^4.0.0:
version "4.0.0"
Expand Down Expand Up @@ -485,13 +485,18 @@ [email protected]:
resolved "https://registry.yarnpkg.com/minimist/-/minimist-0.0.8.tgz#857fcabfc3397d2625b8228262e86aa7a011b05d"
integrity sha1-hX/Kv8M5fSYluCKCYuhqp6ARsF0=

[email protected], mkdirp@^0.5.1, mkdirp@~0.5.1:
[email protected], mkdirp@^0.5.1:
version "0.5.1"
resolved "https://registry.yarnpkg.com/mkdirp/-/mkdirp-0.5.1.tgz#30057438eac6cf7f8c4767f38648d6697d75c903"
integrity sha1-MAV0OOrGz3+MR2fzhkjWaX11yQM=
dependencies:
minimist "0.0.8"

mkdirp@~1.0.3:
version "1.0.4"
resolved "https://registry.yarnpkg.com/mkdirp/-/mkdirp-1.0.4.tgz#3eb5ed62622756d79a5f0e2a221dfebad75c2f7e"
integrity sha512-vVqVZQyf3WLx2Shd0qJ9xuvqgAyKPLAiqITEtqW0oIUjzo3PePDd6fW9iFz30ef7Ysp/oiWqbhszeGWW2T6Gzw==

mocha@^7.0.1:
version "7.0.1"
resolved "https://registry.yarnpkg.com/mocha/-/mocha-7.0.1.tgz#276186d35a4852f6249808c6dd4a1376cbf6c6ce"
Expand Down Expand Up @@ -535,10 +540,10 @@ [email protected]:
object.getownpropertydescriptors "^2.0.3"
semver "^5.7.0"

nopt@~4.0.1:
version "4.0.1"
resolved "https://registry.yarnpkg.com/nopt/-/nopt-4.0.1.tgz#d0d4685afd5415193c8c7505602d0d17cd64474d"
integrity sha1-0NRoWv1UFRk8jHUFYC0NF81kR00=
nopt@^4.0.3:
version "4.0.3"
resolved "https://registry.yarnpkg.com/nopt/-/nopt-4.0.3.tgz#a375cad9d02fd921278d954c2254d5aa57e15e48"
integrity sha512-CvaGwVMztSMJLOeXPrez7fyfObdZqNUK1cPAEzLHrTybIua9pMdmmPR5YwtfNftIOMv3DPUhFaxsZMNTQO20Kg==
dependencies:
abbrev "1"
osenv "^0.1.4"
Expand Down

0 comments on commit 9b5542d

Please sign in to comment.