js-beautify
Advanced tools
Comparing version 1.14.11 to 1.15.0
@@ -574,6 +574,6 @@ /* AUTO-GENERATED. DO NOT MODIFY. */ | ||
// valid templating languages ['django', 'erb', 'handlebars', 'php', 'smarty'] | ||
// valid templating languages ['django', 'erb', 'handlebars', 'php', 'smarty', 'angular'] | ||
// For now, 'auto' = all off for javascript, all on for html (and inline javascript). | ||
// other values ignored | ||
this.templating = this._get_selection_list('templating', ['auto', 'none', 'django', 'erb', 'handlebars', 'php', 'smarty'], ['auto']); | ||
this.templating = this._get_selection_list('templating', ['auto', 'none', 'django', 'erb', 'handlebars', 'php', 'smarty', 'angular'], ['auto']); | ||
} | ||
@@ -580,0 +580,0 @@ |
@@ -373,3 +373,3 @@ #!/usr/bin/env node | ||
' --indent-empty-lines Keep indentation on empty lines', | ||
' --templating List of templating languages (auto,none,django,erb,handlebars,php,smarty) ["auto"] auto = none in JavaScript, all in html', | ||
' --templating List of templating languages (auto,none,django,erb,handlebars,php,smarty,angular) ["auto"] auto = none in JavaScript, all in html', | ||
' --editorconfig Use EditorConfig to set up the options' | ||
@@ -376,0 +376,0 @@ ]; |
@@ -373,3 +373,3 @@ #!/usr/bin/env node | ||
' --indent-empty-lines Keep indentation on empty lines', | ||
' --templating List of templating languages (auto,none,django,erb,handlebars,php,smarty) ["auto"] auto = none in JavaScript, all in html', | ||
' --templating List of templating languages (auto,none,django,erb,handlebars,php,smarty,angular) ["auto"] auto = none in JavaScript, all in html', | ||
' --editorconfig Use EditorConfig to set up the options' | ||
@@ -376,0 +376,0 @@ ]; |
@@ -70,6 +70,6 @@ /*jshint node:true */ | ||
// valid templating languages ['django', 'erb', 'handlebars', 'php', 'smarty'] | ||
// valid templating languages ['django', 'erb', 'handlebars', 'php', 'smarty', 'angular'] | ||
// For now, 'auto' = all off for javascript, all on for html (and inline javascript). | ||
// other values ignored | ||
this.templating = this._get_selection_list('templating', ['auto', 'none', 'django', 'erb', 'handlebars', 'php', 'smarty'], ['auto']); | ||
this.templating = this._get_selection_list('templating', ['auto', 'none', 'django', 'erb', 'handlebars', 'php', 'smarty', 'angular'], ['auto']); | ||
} | ||
@@ -76,0 +76,0 @@ |
@@ -39,3 +39,4 @@ /*jshint node:true */ | ||
php: false, | ||
smarty: false | ||
smarty: false, | ||
angular: false | ||
}; | ||
@@ -42,0 +43,0 @@ |
@@ -114,2 +114,9 @@ /*jshint node:true */ | ||
Printer.prototype.deindent = function() { | ||
if (this.indent_level > 0) { | ||
this.indent_level--; | ||
this._output.set_indent(this.indent_level, this.alignment_size); | ||
} | ||
}; | ||
Printer.prototype.get_full_indent = function(level) { | ||
@@ -309,2 +316,6 @@ level = this.indent_level + (level || 0); | ||
parser_token = this._handle_text(printer, raw_token, last_tag_token); | ||
} else if (raw_token.type === TOKEN.CONTROL_FLOW_OPEN) { | ||
parser_token = this._handle_control_flow_open(printer, raw_token); | ||
} else if (raw_token.type === TOKEN.CONTROL_FLOW_CLOSE) { | ||
parser_token = this._handle_control_flow_close(printer, raw_token); | ||
} else { | ||
@@ -324,2 +335,34 @@ // This should never happen, but if it does. Print the raw token | ||
Beautifier.prototype._handle_control_flow_open = function(printer, raw_token) { | ||
var parser_token = { | ||
text: raw_token.text, | ||
type: raw_token.type | ||
}; | ||
printer.set_space_before_token(raw_token.newlines || raw_token.whitespace_before !== '', true); | ||
if (raw_token.newlines) { | ||
printer.print_preserved_newlines(raw_token); | ||
} else { | ||
printer.set_space_before_token(raw_token.newlines || raw_token.whitespace_before !== '', true); | ||
} | ||
printer.print_token(raw_token); | ||
printer.indent(); | ||
return parser_token; | ||
}; | ||
Beautifier.prototype._handle_control_flow_close = function(printer, raw_token) { | ||
var parser_token = { | ||
text: raw_token.text, | ||
type: raw_token.type | ||
}; | ||
printer.deindent(); | ||
if (raw_token.newlines) { | ||
printer.print_preserved_newlines(raw_token); | ||
} else { | ||
printer.set_space_before_token(raw_token.newlines || raw_token.whitespace_before !== '', true); | ||
} | ||
printer.print_token(raw_token); | ||
return parser_token; | ||
}; | ||
Beautifier.prototype._handle_tag_close = function(printer, raw_token, last_tag_token) { | ||
@@ -326,0 +369,0 @@ var parser_token = { |
@@ -36,3 +36,3 @@ /*jshint node:true */ | ||
if (this.templating.length === 1 && this.templating[0] === 'auto') { | ||
this.templating = ['django', 'erb', 'handlebars', 'php']; | ||
this.templating = ['django', 'erb', 'handlebars', 'php', 'angular']; | ||
} | ||
@@ -39,0 +39,0 @@ |
@@ -40,2 +40,4 @@ /*jshint node:true */ | ||
TAG_CLOSE: 'TK_TAG_CLOSE', | ||
CONTROL_FLOW_OPEN: 'TK_CONTROL_FLOW_OPEN', | ||
CONTROL_FLOW_CLOSE: 'TK_CONTROL_FLOW_CLOSE', | ||
ATTRIBUTE: 'TK_ATTRIBUTE', | ||
@@ -65,2 +67,3 @@ EQUALS: 'TK_EQUALS', | ||
word: templatable_reader.until(/[\n\r\t <]/), | ||
word_control_flow_close_excluded: templatable_reader.until(/[\n\r\t <}]/), | ||
single_quote: templatable_reader.until_after(/'/), | ||
@@ -71,2 +74,3 @@ double_quote: templatable_reader.until_after(/"/), | ||
angular_control_flow_start: pattern_reader.matching(/\@[a-zA-Z]+[^({]*[({]/), | ||
handlebars_comment: pattern_reader.starting_with(/{{!--/).until_after(/--}}/), | ||
@@ -85,2 +89,3 @@ handlebars: pattern_reader.starting_with(/{{/).until_after(/}}/), | ||
this.__patterns.word = this.__patterns.word.exclude('handlebars'); | ||
this.__patterns.word_control_flow_close_excluded = this.__patterns.word_control_flow_close_excluded.exclude('handlebars'); | ||
} | ||
@@ -104,10 +109,12 @@ | ||
Tokenizer.prototype._is_opening = function(current_token) { | ||
return current_token.type === TOKEN.TAG_OPEN; | ||
return current_token.type === TOKEN.TAG_OPEN || current_token.type === TOKEN.CONTROL_FLOW_OPEN; | ||
}; | ||
Tokenizer.prototype._is_closing = function(current_token, open_token) { | ||
return current_token.type === TOKEN.TAG_CLOSE && | ||
return (current_token.type === TOKEN.TAG_CLOSE && | ||
(open_token && ( | ||
((current_token.text === '>' || current_token.text === '/>') && open_token.text[0] === '<') || | ||
(current_token.text === '}}' && open_token.text[0] === '{' && open_token.text[1] === '{'))); | ||
(current_token.text === '}}' && open_token.text[0] === '{' && open_token.text[1] === '{'))) | ||
) || (current_token.type === TOKEN.CONTROL_FLOW_CLOSE && | ||
(current_token.text === '}' && open_token.text.endsWith('{'))); | ||
}; | ||
@@ -131,4 +138,5 @@ | ||
token = token || this._read_close(c, open_token); | ||
token = token || this._read_control_flows(c, open_token); | ||
token = token || this._read_raw_content(c, previous_token, open_token); | ||
token = token || this._read_content_word(c); | ||
token = token || this._read_content_word(c, open_token); | ||
token = token || this._read_comment_or_cdata(c); | ||
@@ -198,3 +206,3 @@ token = token || this._read_processing(c); | ||
var token = null; | ||
if (!open_token) { | ||
if (!open_token || open_token.type === TOKEN.CONTROL_FLOW_OPEN) { | ||
if (c === '<') { | ||
@@ -216,3 +224,3 @@ | ||
var token = null; | ||
if (!open_token) { | ||
if (!open_token || open_token.type === TOKEN.CONTROL_FLOW_OPEN) { | ||
if (this._options.indent_handlebars && c === '{' && this._input.peek(1) === '{') { | ||
@@ -232,7 +240,44 @@ if (this._input.peek(2) === '!') { | ||
Tokenizer.prototype._read_control_flows = function(c, open_token) { | ||
var resulting_string = ''; | ||
var token = null; | ||
// Only check for control flows if angular templating is set AND indenting is set | ||
if (!this._options.templating.includes('angular') || !this._options.indent_handlebars) { | ||
return token; | ||
} | ||
if (c === '@') { | ||
resulting_string = this.__patterns.angular_control_flow_start.read(); | ||
if (resulting_string === '') { | ||
return token; | ||
} | ||
var opening_parentheses_count = resulting_string.endsWith('(') ? 1 : 0; | ||
var closing_parentheses_count = 0; | ||
// The opening brace of the control flow is where the number of opening and closing parentheses equal | ||
// e.g. @if({value: true} !== null) { | ||
while (!(resulting_string.endsWith('{') && opening_parentheses_count === closing_parentheses_count)) { | ||
var next_char = this._input.next(); | ||
if (next_char === null) { | ||
break; | ||
} else if (next_char === '(') { | ||
opening_parentheses_count++; | ||
} else if (next_char === ')') { | ||
closing_parentheses_count++; | ||
} | ||
resulting_string += next_char; | ||
} | ||
token = this._create_token(TOKEN.CONTROL_FLOW_OPEN, resulting_string); | ||
} else if (c === '}' && open_token && open_token.type === TOKEN.CONTROL_FLOW_OPEN) { | ||
resulting_string = this._input.next(); | ||
token = this._create_token(TOKEN.CONTROL_FLOW_CLOSE, resulting_string); | ||
} | ||
return token; | ||
}; | ||
Tokenizer.prototype._read_close = function(c, open_token) { | ||
var resulting_string = null; | ||
var token = null; | ||
if (open_token) { | ||
if (open_token && open_token.type === TOKEN.TAG_OPEN) { | ||
if (open_token.text[0] === '<' && (c === '>' || (c === '/' && this._input.peek(1) === '>'))) { | ||
@@ -324,3 +369,3 @@ resulting_string = this._input.next(); | ||
Tokenizer.prototype._read_content_word = function(c) { | ||
Tokenizer.prototype._read_content_word = function(c, open_token) { | ||
var resulting_string = ''; | ||
@@ -334,3 +379,3 @@ if (this._options.unformatted_content_delimiter) { | ||
if (!resulting_string) { | ||
resulting_string = this.__patterns.word.read(); | ||
resulting_string = (open_token && open_token.type === TOKEN.CONTROL_FLOW_OPEN) ? this.__patterns.word_control_flow_close_excluded.read() : this.__patterns.word.read(); | ||
} | ||
@@ -337,0 +382,0 @@ if (resulting_string) { |
{ | ||
"name": "js-beautify", | ||
"version": "1.14.11", | ||
"version": "1.15.0", | ||
"description": "beautifier.io for node", | ||
@@ -20,10 +20,10 @@ "main": "js/index.js", | ||
"js/index.js", | ||
"js/src/**/*" | ||
"js/src/" | ||
], | ||
"scripts": {}, | ||
"bugs": "https://github.com/beautify-web/js-beautify/issues", | ||
"bugs": "https://github.com/beautifier/js-beautify/issues", | ||
"homepage": "https://beautifier.io/", | ||
"repository": { | ||
"type": "git", | ||
"url": "git://github.com/beautify-web/js-beautify.git" | ||
"url": "git://github.com/beautifier/js-beautify.git" | ||
}, | ||
@@ -54,4 +54,5 @@ "keywords": [ | ||
"config-chain": "^1.1.13", | ||
"editorconfig": "^1.0.3", | ||
"editorconfig": "^1.0.4", | ||
"glob": "^10.3.3", | ||
"js-cookie": "^3.0.5", | ||
"nopt": "^7.2.0" | ||
@@ -62,3 +63,3 @@ }, | ||
"benchmark": "^2.1.4", | ||
"codemirror": "^5.65.13", | ||
"codemirror": "^5.65.16", | ||
"jquery": "^3.6.4", | ||
@@ -65,0 +66,0 @@ "jshint": "^2.13.6", |
@@ -1,8 +0,8 @@ | ||
<p align="center"><img src="https://raw.githubusercontent.com/beautify-web/js-beautify/7db71fc/web/wordmark-light.svg" height="200px" align="center" alt="JS Beautifier"/></p> | ||
<p align="center"><img src="https://raw.githubusercontent.com/beautifier/js-beautify/7db71fc/web/wordmark-light.svg" height="200px" align="center" alt="JS Beautifier"/></p> | ||
<p align="center"><a href="https://github.com/beautify-web/js-beautify/actions/workflows/main.yml"><img alt="CI" src="https://github.com/beautify-web/js-beautify/workflows/CI/badge.svg"/></a> <a href="https://greenkeeper.io/" target="_blank"><img alt="Greenkeeper badge" src="https://badges.greenkeeper.io/beautify-web/js-beautify.svg"/></a></p> | ||
<p align="center"><a href="https://github.com/beautifier/js-beautify/actions/workflows/main.yml"><img alt="CI" src="https://github.com/beautifier/js-beautify/workflows/CI/badge.svg"/></a> <a href="https://greenkeeper.io/" target="_blank"><img alt="Greenkeeper badge" src="https://badges.greenkeeper.io/beautifier/js-beautify.svg"/></a></p> | ||
<p align="center"><a href="https://pypi.python.org/pypi/jsbeautifier" target="_blank"><img alt="PyPI version" src="https://img.shields.io/pypi/v/jsbeautifier.svg"/></a> <a href="https://cdnjs.com/libraries/js-beautify" target="_blank"><img alt="CDNJS version" src="https://img.shields.io/cdnjs/v/js-beautify.svg"/></a> <a href="https://www.npmjs.com/package/js-beautify" target="_blank"><img alt="NPM @latest" src="https://img.shields.io/npm/v/js-beautify.svg"/></a> <a href="https://www.npmjs.com/package/js-beautify?activeTab=versions" target="_blank"><img alt="NPM @next" src="https://img.shields.io/npm/v/js-beautify/next.svg"/></a></p> | ||
<p align="center"><a href="https://gitter.im/beautify-web/js-beautify?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge" target="_blank"><img alt="Join the chat at https://gitter.im/beautify-web/js-beautify" src="https://badges.gitter.im/Join%20Chat.svg"></a> <a href="https://twitter.com/intent/user?screen_name=js_beautifier" target="_blank"><img alt="Twitter Follow" src="https://img.shields.io/twitter/follow/js_beautifier.svg?style=social&label=Follow"/></a></p> | ||
<p align="center"><a href="https://gitter.im/beautifier/js-beautify?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge" target="_blank"><img alt="Join the chat at https://gitter.im/beautifier/js-beautify" src="https://badges.gitter.im/Join%20Chat.svg"></a> <a href="https://twitter.com/intent/user?screen_name=js_beautifier" target="_blank"><img alt="Twitter Follow" src="https://img.shields.io/twitter/follow/js_beautifier.svg?style=social&label=Follow"/></a></p> | ||
@@ -24,3 +24,3 @@ <p align="center"><a href="https://www.npmjs.org/package/js-beautify" target="_blank"><img alt="NPM stats" src=https://nodei.co/npm/js-beautify.svg?downloadRank=true&downloads=true"/></a></p> | ||
If you are interested, please take a look at the [CONTRIBUTING.md](https://github.com/beautify-web/js-beautify/blob/main/CONTRIBUTING.md) then fix an issue marked with the ["Good first issue"](https://github.com/beautify-web/js-beautify/issues?q=is%3Aissue+is%3Aopen+label%3A%22good+first+issue%22) label and submit a PR. Repeat as often as possible. Thanks! | ||
If you are interested, please take a look at the [CONTRIBUTING.md](https://github.com/beautifier/js-beautify/blob/main/CONTRIBUTING.md) then fix an issue marked with the ["Good first issue"](https://github.com/beautifier/js-beautify/issues?q=is%3Aissue+is%3Aopen+label%3A%22good+first+issue%22) label and submit a PR. Repeat as often as possible. Thanks! | ||
@@ -62,9 +62,9 @@ | ||
```html | ||
<script src="https://cdnjs.cloudflare.com/ajax/libs/js-beautify/1.14.11/beautify.js"></script> | ||
<script src="https://cdnjs.cloudflare.com/ajax/libs/js-beautify/1.14.11/beautify-css.js"></script> | ||
<script src="https://cdnjs.cloudflare.com/ajax/libs/js-beautify/1.14.11/beautify-html.js"></script> | ||
<script src="https://cdnjs.cloudflare.com/ajax/libs/js-beautify/1.15.0/beautify.js"></script> | ||
<script src="https://cdnjs.cloudflare.com/ajax/libs/js-beautify/1.15.0/beautify-css.js"></script> | ||
<script src="https://cdnjs.cloudflare.com/ajax/libs/js-beautify/1.15.0/beautify-html.js"></script> | ||
<script src="https://cdnjs.cloudflare.com/ajax/libs/js-beautify/1.14.11/beautify.min.js"></script> | ||
<script src="https://cdnjs.cloudflare.com/ajax/libs/js-beautify/1.14.11/beautify-css.min.js"></script> | ||
<script src="https://cdnjs.cloudflare.com/ajax/libs/js-beautify/1.14.11/beautify-html.min.js"></script> | ||
<script src="https://cdnjs.cloudflare.com/ajax/libs/js-beautify/1.15.0/beautify.min.js"></script> | ||
<script src="https://cdnjs.cloudflare.com/ajax/libs/js-beautify/1.15.0/beautify-css.min.js"></script> | ||
<script src="https://cdnjs.cloudflare.com/ajax/libs/js-beautify/1.15.0/beautify-html.min.js"></script> | ||
``` | ||
@@ -81,3 +81,3 @@ | ||
<script src="https://cdnjs.cloudflare.com/ajax/libs/js-beautify/1.14.11/beautify.min.js"></script> | ||
<script src="https://cdnjs.cloudflare.com/ajax/libs/js-beautify/1.15.0/beautify.min.js"></script> | ||
<script src="script.js"></script> | ||
@@ -229,3 +229,3 @@ </body> | ||
--indent-empty-lines Keep indentation on empty lines | ||
--templating List of templating languages (auto,django,erb,handlebars,php,smarty) ["auto"] auto = none in JavaScript, all in HTML | ||
--templating List of templating languages (auto,django,erb,handlebars,php,smarty,angular) ["auto"] auto = none in JavaScript, all in HTML | ||
``` | ||
@@ -386,3 +386,3 @@ | ||
--indent-empty-lines Keep indentation on empty lines | ||
--templating List of templating languages (auto,none,django,erb,handlebars,php,smarty) ["auto"] auto = none in JavaScript, all in html | ||
--templating List of templating languages (auto,none,django,erb,handlebars,php,smarty,angular) ["auto"] auto = none in JavaScript, all in html | ||
``` | ||
@@ -442,2 +442,2 @@ | ||
(README.md: js-beautify@1.14.11) | ||
(README.md: js-beautify@1.15.0) |
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is too big to display
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
No bug tracker
MaintenancePackage does not have a linked bug tracker in package.json.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
No bug tracker
MaintenancePackage does not have a linked bug tracker in package.json.
Found 1 instance in 1 package
978726
20227
5
+ Addedjs-cookie@^3.0.5
+ Addedjs-cookie@3.0.5(transitive)
Updatededitorconfig@^1.0.4