Skip to content

Commit 99b86e4

Browse files
author
GitHub Action
committed
Merge remote-tracking branch 'origin/staging/main' into staging/release
2 parents b747a0c + 08b1853 commit 99b86e4

File tree

21 files changed

+594
-507
lines changed

21 files changed

+594
-507
lines changed

.github/dependabot.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,16 +7,19 @@ version: 2
77
updates:
88
- package-ecosystem: "npm" # See documentation for possible values
99
directory: "/" # Location of package manifests
10+
rebase-strategy: "disabled"
1011
schedule:
1112
interval: "weekly"
1213
open-pull-requests-limit: 15
1314
- package-ecosystem: "pip" # See documentation for possible values
1415
directory: "/python" # Location of package manifests
16+
rebase-strategy: "disabled"
1517
schedule:
1618
interval: "weekly"
1719
open-pull-requests-limit: 15
1820
- package-ecosystem: "github-actions"
1921
directory: "/"
22+
rebase-strategy: "disabled"
2023
schedule:
2124
# Check for updates to GitHub Actions every week
2225
interval: "weekly"

.github/workflows/milestone-publish.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -52,14 +52,14 @@ jobs:
5252
git remote add trigger [email protected]:beautifier/js-beautify.git
5353
git fetch --all
5454
- name: Install python twinE
55-
run: pip install twine
55+
run: pip install twine wheel
5656
- name: Run release script for ${{ github.event.milestone.title }}
57-
env:
57+
env:
5858
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
5959
SSH_AUTH_SOCK: /tmp/ssh_agent.sock
6060
MILESTONE_VERSION: ${{ github.event.milestone.title }}
6161
NODE_AUTH_TOKEN: ${{secrets.NPM_TOKEN}}
62-
TWINE_USERNAME: ${{secrets.PYPI_USERNAME}}
63-
TWINE_PASSWORD: ${{secrets.PYPI_PASSWORD}}
62+
TWINE_USERNAME: ${{secrets.PYPI_USERNAME}}
63+
TWINE_PASSWORD: ${{secrets.PYPI_PASSWORD}}
6464
run: |
6565
./tools/release-all.sh ${MILESTONE_VERSION}

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
# Changelog
22

3+
## v1.15.2
4+
* Patch SNYK-JS-CROSSSPAWN-8303230 issue brought it through old glob package ([#2328](https://github.com/beautifier/js-beautify/issues/2328))
5+
* release wheels on pypi ([#2313](https://github.com/beautifier/js-beautify/issues/2313))
6+
* ModuleNotFoundError: No module named 'setuptools.command.test' as of latest setuptools package release ([#2301](https://github.com/beautifier/js-beautify/issues/2301))
7+
* [Python]Compatible with setuptools>=72 ([#2300](https://github.com/beautifier/js-beautify/issues/2300))
8+
39
## v1.15.1
410
* Turn new angular templating off by default in html ([#2247](https://github.com/beautifier/js-beautify/pull/2247))
511
* Perf regression in latest release (1.15.0) ([#2246](https://github.com/beautifier/js-beautify/issues/2246))

README.md

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -58,13 +58,13 @@ JS Beautifier is hosted on two CDN services: [cdnjs](https://cdnjs.com/libraries
5858

5959
To pull the latest version from one of these services include one set of the script tags below in your document:
6060
```html
61-
<script src="https://cdnjs.cloudflare.com/ajax/libs/js-beautify/1.15.1/beautify.js"></script>
62-
<script src="https://cdnjs.cloudflare.com/ajax/libs/js-beautify/1.15.1/beautify-css.js"></script>
63-
<script src="https://cdnjs.cloudflare.com/ajax/libs/js-beautify/1.15.1/beautify-html.js"></script>
61+
<script src="https://cdnjs.cloudflare.com/ajax/libs/js-beautify/1.15.2/beautify.js"></script>
62+
<script src="https://cdnjs.cloudflare.com/ajax/libs/js-beautify/1.15.2/beautify-css.js"></script>
63+
<script src="https://cdnjs.cloudflare.com/ajax/libs/js-beautify/1.15.2/beautify-html.js"></script>
6464

65-
<script src="https://cdnjs.cloudflare.com/ajax/libs/js-beautify/1.15.1/beautify.min.js"></script>
66-
<script src="https://cdnjs.cloudflare.com/ajax/libs/js-beautify/1.15.1/beautify-css.min.js"></script>
67-
<script src="https://cdnjs.cloudflare.com/ajax/libs/js-beautify/1.15.1/beautify-html.min.js"></script>
65+
<script src="https://cdnjs.cloudflare.com/ajax/libs/js-beautify/1.15.2/beautify.min.js"></script>
66+
<script src="https://cdnjs.cloudflare.com/ajax/libs/js-beautify/1.15.2/beautify-css.min.js"></script>
67+
<script src="https://cdnjs.cloudflare.com/ajax/libs/js-beautify/1.15.2/beautify-html.min.js"></script>
6868
```
6969

7070
Example usage of a JS tag in html:
@@ -76,7 +76,7 @@ Example usage of a JS tag in html:
7676

7777
. . .
7878

79-
<script src="https://cdnjs.cloudflare.com/ajax/libs/js-beautify/1.15.1/beautify.min.js"></script>
79+
<script src="https://cdnjs.cloudflare.com/ajax/libs/js-beautify/1.15.2/beautify.min.js"></script>
8080
<script src="script.js"></script>
8181
</body>
8282
</html>
@@ -152,6 +152,17 @@ fs.readFile('foo.js', 'utf8', function (err, data) {
152152
});
153153
```
154154

155+
If you are using ESM Imports, you can import `js-beautify` like this:
156+
157+
```js
158+
// 'beautify' can be any name here.
159+
import beautify from 'js-beautify';
160+
161+
beautify.js(data, options);
162+
beautify.html(data, options);
163+
beautify.css(data, options);
164+
```
165+
155166
## Python
156167
After installing, to beautify using Python:
157168

@@ -434,4 +445,4 @@ Thanks also to Jason Diamond, Patrick Hof, Nochum Sossonko, Andreas Schneider, D
434445
Vasilevsky, Vital Batmanov, Ron Baldwin, Gabriel Harrison, Chris J. Shull,
435446
Mathias Bynens, Vittorio Gambaletta and others.
436447
437-
(README.md: [email protected].1)
448+
(README.md: [email protected].2)

index.html

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535
<title>Online JavaScript beautifier</title>
3636
<link rel="icon" href="web/favicon.png" type="image/png">
3737

38-
<script src="https://cdn.polyfill.io/v2/polyfill.min.js?features=default&flags=gated"></script>
38+
<script src="https://cdnjs.cloudflare.com/polyfill/v2/polyfill.min.js?features=default&flags=gated"></script>
3939

4040
<!-- Codemirror from https://cdnjs.com/libraries/codemirror -->
4141
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/codemirror/5.65.16/codemirror.min.css" integrity="sha512-uf06llspW44/LZpHzHT6qBOIVODjWtv4MxCricRxkzvopAlSWnTf6hpZTFxuuZcuNE9CBQhqE0Seu1CoRk84nQ==" crossorigin="anonymous" referrerpolicy="no-referrer" />
@@ -97,6 +97,7 @@ <h1 class="logo">
9797
<div class="buttons-box">
9898
<button class="submit"><strong>Beautify Code</strong> <em>(ctrl&#8209;enter)</em></button>
9999
<button class="control" type="button" onclick="copyText()"><strong>Copy to Clipboard</strong></button>
100+
<button class="control" type="button" onclick="downloadBeautifiedCode()"><strong>Download</strong></button>
100101
<button class="control" type="button" onclick="selectAll()"><strong>Select All</strong></button>
101102
<button class="control" type="button" onclick="clearAll()"><strong>Clear</strong></button>
102103
<input type="file" onchange="changeToFileContent(this)">

js/src/core/templatablepattern.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,10 @@ TemplatablePattern.prototype.__set_templated_pattern = function() {
135135
if (!this._disabled.handlebars) {
136136
items.push(this.__patterns.handlebars._starting_pattern.source);
137137
}
138+
if (!this._disabled.angular) {
139+
// Handlebars ('{{' and '}}') are also special tokens in Angular)
140+
items.push(this.__patterns.handlebars._starting_pattern.source);
141+
}
138142
if (!this._disabled.erb) {
139143
items.push(this.__patterns.erb._starting_pattern.source);
140144
}

js/src/html/beautifier.js

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -291,7 +291,7 @@ Beautifier.prototype.beautify = function() {
291291
type: ''
292292
};
293293

294-
var last_tag_token = new TagOpenParserToken();
294+
var last_tag_token = new TagOpenParserToken(this._options);
295295

296296
var printer = new Printer(this._options, baseIndentString);
297297
var tokens = new Tokenizer(source_text, this._options).tokenize();
@@ -614,7 +614,7 @@ Beautifier.prototype._handle_tag_open = function(printer, raw_token, last_tag_to
614614
return parser_token;
615615
};
616616

617-
var TagOpenParserToken = function(parent, raw_token) {
617+
var TagOpenParserToken = function(options, parent, raw_token) {
618618
this.parent = parent || null;
619619
this.text = '';
620620
this.type = 'TK_TAG_OPEN';
@@ -681,13 +681,14 @@ var TagOpenParserToken = function(parent, raw_token) {
681681
}
682682

683683
// handlebars tags that don't start with # or ^ are single_tags, and so also start and end.
684+
// if they start with # or ^, they are still considered single tags if indenting of handlebars is set to false
684685
this.is_end_tag = this.is_end_tag ||
685-
(this.tag_start_char === '{' && (this.text.length < 3 || (/[^#\^]/.test(this.text.charAt(handlebar_starts)))));
686+
(this.tag_start_char === '{' && (!options.indent_handlebars || this.text.length < 3 || (/[^#\^]/.test(this.text.charAt(handlebar_starts)))));
686687
}
687688
};
688689

689690
Beautifier.prototype._get_tag_open_token = function(raw_token) { //function to get a full tag and parse its type
690-
var parser_token = new TagOpenParserToken(this._tag_stack.get_parser_token(), raw_token);
691+
var parser_token = new TagOpenParserToken(this._options, this._tag_stack.get_parser_token(), raw_token);
691692

692693
parser_token.alignment_size = this._options.wrap_attributes_indent_size;
693694

js/src/html/tokenizer.js

Lines changed: 26 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,7 @@ Tokenizer.prototype._get_next_token = function(previous_token, open_token) { //
130130
token = token || this._read_open_handlebars(c, open_token);
131131
token = token || this._read_attribute(c, previous_token, open_token);
132132
token = token || this._read_close(c, open_token);
133+
token = token || this._read_script_and_style(c, previous_token);
133134
token = token || this._read_control_flows(c, open_token);
134135
token = token || this._read_raw_content(c, previous_token, open_token);
135136
token = token || this._read_content_word(c, open_token);
@@ -215,8 +216,8 @@ Tokenizer.prototype._read_open_handlebars = function(c, open_token) {
215216
var resulting_string = null;
216217
var token = null;
217218
if (!open_token || open_token.type === TOKEN.CONTROL_FLOW_OPEN) {
218-
if (this._options.indent_handlebars && c === '{' && this._input.peek(1) === '{') {
219-
if (this._input.peek(2) === '!') {
219+
if ((this._options.templating.includes('angular') || this._options.indent_handlebars) && c === '{' && this._input.peek(1) === '{') {
220+
if (this._options.indent_handlebars && this._input.peek(2) === '!') {
220221
resulting_string = this.__patterns.handlebars_comment.read();
221222
resulting_string = resulting_string || this.__patterns.handlebars.read();
222223
token = this._create_token(TOKEN.COMMENT, resulting_string);
@@ -232,8 +233,8 @@ Tokenizer.prototype._read_open_handlebars = function(c, open_token) {
232233
Tokenizer.prototype._read_control_flows = function(c, open_token) {
233234
var resulting_string = '';
234235
var token = null;
235-
// Only check for control flows if angular templating is set AND indenting is set
236-
if (!this._options.templating.includes('angular') || !this._options.indent_handlebars) {
236+
// Only check for control flows if angular templating is set
237+
if (!this._options.templating.includes('angular')) {
237238
return token;
238239
}
239240

@@ -326,14 +327,29 @@ Tokenizer.prototype._is_content_unformatted = function(tag_name) {
326327
this._options.unformatted.indexOf(tag_name) !== -1);
327328
};
328329

329-
330330
Tokenizer.prototype._read_raw_content = function(c, previous_token, open_token) { // jshint unused:false
331331
var resulting_string = '';
332332
if (open_token && open_token.text[0] === '{') {
333333
resulting_string = this.__patterns.handlebars_raw_close.read();
334334
} else if (previous_token.type === TOKEN.TAG_CLOSE &&
335335
previous_token.opened.text[0] === '<' && previous_token.text[0] !== '/') {
336336
// ^^ empty tag has no content
337+
var tag_name = previous_token.opened.text.substr(1).toLowerCase();
338+
if (this._is_content_unformatted(tag_name)) {
339+
340+
resulting_string = this._input.readUntil(new RegExp('</' + tag_name + '[\\n\\r\\t ]*?>', 'ig'));
341+
}
342+
}
343+
344+
if (resulting_string) {
345+
return this._create_token(TOKEN.TEXT, resulting_string);
346+
}
347+
348+
return null;
349+
};
350+
351+
Tokenizer.prototype._read_script_and_style = function(c, previous_token) { // jshint unused:false
352+
if (previous_token.type === TOKEN.TAG_CLOSE && previous_token.opened.text[0] === '<' && previous_token.text[0] !== '/') {
337353
var tag_name = previous_token.opened.text.substr(1).toLowerCase();
338354
if (tag_name === 'script' || tag_name === 'style') {
339355
// Script and style tags are allowed to have comments wrapping their content
@@ -343,17 +359,12 @@ Tokenizer.prototype._read_raw_content = function(c, previous_token, open_token)
343359
token.type = TOKEN.TEXT;
344360
return token;
345361
}
346-
resulting_string = this._input.readUntil(new RegExp('</' + tag_name + '[\\n\\r\\t ]*?>', 'ig'));
347-
} else if (this._is_content_unformatted(tag_name)) {
348-
349-
resulting_string = this._input.readUntil(new RegExp('</' + tag_name + '[\\n\\r\\t ]*?>', 'ig'));
362+
var resulting_string = this._input.readUntil(new RegExp('</' + tag_name + '[\\n\\r\\t ]*?>', 'ig'));
363+
if (resulting_string) {
364+
return this._create_token(TOKEN.TEXT, resulting_string);
365+
}
350366
}
351367
}
352-
353-
if (resulting_string) {
354-
return this._create_token(TOKEN.TEXT, resulting_string);
355-
}
356-
357368
return null;
358369
};
359370

@@ -371,6 +382,7 @@ Tokenizer.prototype._read_content_word = function(c, open_token) {
371382
if (resulting_string) {
372383
return this._create_token(TOKEN.TEXT, resulting_string);
373384
}
385+
return null;
374386
};
375387

376388
module.exports.Tokenizer = Tokenizer;

0 commit comments

Comments
 (0)