Skip to content

Commit

Permalink
Merge pull request #51 from beautifier/staging/main
Browse files Browse the repository at this point in the history
Pulling staging/main into main
  • Loading branch information
bitwiseman authored Nov 7, 2023
2 parents c5fe985 + d629d1d commit bb255e0
Show file tree
Hide file tree
Showing 28 changed files with 589 additions and 234 deletions.
23 changes: 23 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# To get started with Dependabot version updates, you'll need to specify which
# package ecosystems to update and where the package manifests are located.
# Please see the documentation for all configuration options:
# https://docs.github.com/github/administering-a-repository/configuration-options-for-dependency-updates

version: 2
updates:
- package-ecosystem: "npm" # See documentation for possible values
directory: "/" # Location of package manifests
schedule:
interval: "weekly"
open-pull-requests-limit: 15
- package-ecosystem: "pip" # See documentation for possible values
directory: "/python" # Location of package manifests
schedule:
interval: "weekly"
open-pull-requests-limit: 15
- package-ecosystem: "github-actions"
directory: "/"
schedule:
# Check for updates to GitHub Actions every week
interval: "weekly"
open-pull-requests-limit: 15
8 changes: 4 additions & 4 deletions .github/workflows/codeql-analysis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,11 @@ jobs:

steps:
- name: Checkout repository
uses: actions/checkout@v2
uses: actions/checkout@v4

# Initializes the CodeQL tools for scanning.
- name: Initialize CodeQL
uses: github/codeql-action/init@v1
uses: github/codeql-action/init@v2
with:
languages: ${{ matrix.language }}
# If you wish to specify custom queries, you can do so here or in a config file.
Expand All @@ -50,7 +50,7 @@ jobs:
# Autobuild attempts to build any compiled languages (C/C++, C#, or Java).
# If this step fails, then you should remove it and run the build manually (see below)
- name: Autobuild
uses: github/codeql-action/autobuild@v1
uses: github/codeql-action/autobuild@v2

# ℹ️ Command-line programs to run using the OS shell.
# 📚 https://git.io/JvXDl
Expand All @@ -64,4 +64,4 @@ jobs:
# make release

- name: Perform CodeQL Analysis
uses: github/codeql-action/analyze@v1
uses: github/codeql-action/analyze@v2
8 changes: 4 additions & 4 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,17 +26,17 @@ jobs:
- python-version: 3.11
node-version: 20
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v4
- name: Set up Node ${{ matrix.node-version }}
uses: actions/setup-node@v1
uses: actions/setup-node@v4
with:
node-version: ${{ matrix.node-version }}
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v2
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}
- name: Cached node_modules
uses: actions/cache@v2
uses: actions/cache@v3
with:
path: node_modules
key: ${{ runner.os }}-node-${{ hashFiles('**/package*.json') }}
Expand Down
10 changes: 5 additions & 5 deletions .github/workflows/milestone-publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,18 +12,18 @@ jobs:
publish:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Set up Node
uses: actions/setup-node@v1
uses: actions/setup-node@v4
with:
node-version: 14
node-version: 18
registry-url: https://registry.npmjs.org/
- name: Set up Python
uses: actions/setup-python@v2
uses: actions/setup-python@v4
with:
python-version: 3.8
python-version: 3.11
- name: Set git user
run: |
git config --global user.email "[email protected]"
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/pr-staging.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ jobs:
PR-from-staging:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v4
with:
fetch-depth: 0
- name: pull-request gh-pages
Expand Down
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# Changelog

## v1.14.10
* Editor not working https://beautifier.io/ ([#2201](https://github.com/beautify-web/js-beautify/issues/2201))
* Set nodejs minimum to v14 ([#2169](https://github.com/beautify-web/js-beautify/pull/2169))
* Invalid prettification of object with unicode escape character as object key ([#2159](https://github.com/beautify-web/js-beautify/issues/2159))
* invalid json being generated with wrap\_line\_length ([#1932](https://github.com/beautify-web/js-beautify/issues/1932))

## v1.14.9
* Bump semver and editorconfig ([#2161](https://github.com/beautify-web/js-beautify/pull/2161))
* Update editorconfig package ([#2160](https://github.com/beautify-web/js-beautify/issues/2160))
Expand Down
4 changes: 2 additions & 2 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ Fixes and enhancements are totally welcome. We prefer you to file an issue befo

* bash
* make
* nodejs - v10.x (with npm)
* python - v2.7.x or v3.x (with pip)
* nodejs - v16.x or greater (with npm)
* python - v3.7 or greater (with pip)

If you encounter issues and cannot build, come chat on gitter.im. We're happy to help.

Expand Down
16 changes: 8 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,13 +58,13 @@ JS Beautifier is hosted on two CDN services: [cdnjs](https://cdnjs.com/libraries

To pull the latest version from one of these services include one set of the script tags below in your document:
```html
<script src="https://cdnjs.cloudflare.com/ajax/libs/js-beautify/1.14.9/beautify.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/js-beautify/1.14.9/beautify-css.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/js-beautify/1.14.9/beautify-html.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/js-beautify/1.14.10/beautify.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/js-beautify/1.14.10/beautify-css.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/js-beautify/1.14.10/beautify-html.js"></script>

<script src="https://cdnjs.cloudflare.com/ajax/libs/js-beautify/1.14.9/beautify.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/js-beautify/1.14.9/beautify-css.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/js-beautify/1.14.9/beautify-html.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/js-beautify/1.14.10/beautify.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/js-beautify/1.14.10/beautify-css.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/js-beautify/1.14.10/beautify-html.min.js"></script>
```

Example usage of a JS tag in html:
Expand All @@ -76,7 +76,7 @@ Example usage of a JS tag in html:

. . .

<script src="https://cdnjs.cloudflare.com/ajax/libs/js-beautify/1.14.9/beautify.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/js-beautify/1.14.10/beautify.min.js"></script>
<script src="script.js"></script>
</body>
</html>
Expand Down Expand Up @@ -434,4 +434,4 @@ Thanks also to Jason Diamond, Patrick Hof, Nochum Sossonko, Andreas Schneider, D
Vasilevsky, Vital Batmanov, Ron Baldwin, Gabriel Harrison, Chris J. Shull,
Mathias Bynens, Vittorio Gambaletta and others.
(README.md: [email protected].9)
(README.md: [email protected].10)
30 changes: 15 additions & 15 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -38,25 +38,25 @@
<script src="https://cdn.polyfill.io/v2/polyfill.min.js?features=default&flags=gated"></script>

<!-- Codemirror from https://cdnjs.com/libraries/codemirror -->
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/codemirror/5.48.4/codemirror.min.css" integrity="sha256-vZ3SaLOjnKO/gGvcUWegySoDU6ff33CS5i9ot8J9Czk=" crossorigin="anonymous" />
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/codemirror/5.48.4/theme/darcula.min.css" integrity="sha256-ZzdkdGSdYSUv4R77x7A5G7EeFDLMhAiCybNBNxNoxos=" crossorigin="anonymous" />
<script src="https://cdnjs.cloudflare.com/ajax/libs/codemirror/5.48.4/codemirror.min.js" integrity="sha256-dPTL2a+npIonoK5i0Tyes0txCMUWZBf8cfKRfACRotc=" crossorigin="anonymous"></script>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/codemirror/5.48.4/codemirror.min.css" integrity="sha512-9VgBnmEYUpZ041Fz5LvsEsFlEzAlUw6Ku5uPhNSKgqY4DgM+g8BRoYvfbfDcTqs3BPsREBB3ccVVlkCSLZ5T+Q==" crossorigin="anonymous" referrerpolicy="no-referrer" />
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/codemirror/5.48.4/theme/darcula.min.css" integrity="sha512-gFMl3u9d0xt3WR8ZeW05MWm3yZ+ZfgsBVXLSOiFz2xeVrZ8Neg0+V1kkRIo9LikyA/T9HuS91kDfc2XWse0K0A==" crossorigin="anonymous" referrerpolicy="no-referrer" />
<script src="https://cdnjs.cloudflare.com/ajax/libs/codemirror/5.48.4/codemirror.min.js" integrity="sha512-wQgeja/1fclPgUWIHnv/MVPCdiL56SK0P8zLgtpOMhUYtvpaZTr/Q/IV2gkvzEYvMc3ZY2PaxarEj0m3CkOtfw==" crossorigin="anonymous" referrerpolicy="no-referrer"></script>

<!-- Codemirror Modes -->
<script src="https://cdnjs.cloudflare.com/ajax/libs/codemirror/5.48.4/mode/xml/xml.min.js" integrity="sha256-cphnEddX56MtGJsi1PoCPLds+dlnDj1QQkAlCWeJYDo=" crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/codemirror/5.48.4/mode/javascript/javascript.min.js" integrity="sha256-7AjEsHnW7cpq2raC/uxnGCP2G4zIKmCdz7OAv6LN00o=" crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/codemirror/5.48.4/mode/css/css.min.js" integrity="sha256-mjhvNBMExwa2AtP0mBlK9NkzJ7sgRSyZdgw9sPhhtb0=" crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/codemirror/5.48.4/mode/htmlmixed/htmlmixed.min.js" integrity="sha256-qfS6ZUe6JhPU75/Sc1ftiWzC2N9IxGEjlRwpKB78Ico=" crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/codemirror/5.48.4/mode/xml/xml.min.js" integrity="sha512-KU6R9MYnyy7/YS6zdRhTpYZJqQmBSEywURvPS9yqLNEXVU/LSkVupFYzekqKmERPF6KQmg1cYlDg+pCOZu3sZQ==" crossorigin="anonymous" referrerpolicy="no-referrer"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/codemirror/5.48.4/mode/javascript/javascript.min.js" integrity="sha512-KRFhN4NY/FfTI0TMPLc2r4iBUOt236/wm5VAIIOMM7s4SJIzErvkwihZb/IyKBJSbUSd4vIcBF8k36TNiCy4DA==" crossorigin="anonymous" referrerpolicy="no-referrer"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/codemirror/5.48.4/mode/css/css.min.js" integrity="sha512-iuxJGOUjCTxOwTeDzLXgima4Q5r6o88tr2GsvmgfSmiqDULC74q5izBnbHG32uOPYnyTL35mmlPGCkaI0Mu0Ww==" crossorigin="anonymous" referrerpolicy="no-referrer"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/codemirror/5.48.4/mode/htmlmixed/htmlmixed.min.js" integrity="sha512-MdDU7KJqREsJm/eOi90N7J/IoYJ81KBhOlgmZmaQNA4i6RksXbffJNywmx3KNlrBQoVRlMnE2mnqJ4VOe2SsEQ==" crossorigin="anonymous" referrerpolicy="no-referrer"></script>

<script src="https://cdnjs.cloudflare.com/ajax/libs/codemirror/5.48.4/addon/search/search.js" integrity="sha256-iUnNlgkrU5Jj8oKl2zBBCTmESI2xpXwZrTX+arxSEKc=" crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/codemirror/5.48.4/addon/search/searchcursor.min.js" integrity="sha256-y7nxCQ9bT6p4fEq9ylGxWfMQBpL6ingXkav6Nr1AcZ8=" crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/codemirror/5.48.4/addon/dialog/dialog.min.js" integrity="sha256-G+QhvxjUNi5P5cyQqjROwriSUy2lZtCFUQh+8W1o6I0=" crossorigin="anonymous"></script>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/codemirror/5.48.4/addon/dialog/dialog.css" integrity="sha256-XfaQ13HxIRg0hWLdKpAGBDOuLt7M0JCKvKpEgLHj5Gg=" crossorigin="anonymous" />
<script src="https://cdnjs.cloudflare.com/ajax/libs/codemirror/5.48.4/addon/search/search.js" integrity="sha512-sHa7Nz2KixDnwwCdtjxUbu4yYsWXNAgto8LNbhrA693xGS12P1/90gdnd837EzBrNg8Suazc70BlFDQIO1qW7w==" crossorigin="anonymous" referrerpolicy="no-referrer"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/codemirror/5.48.4/addon/search/searchcursor.min.js" integrity="sha512-bUUEt0Ckb4QlT1n1+PiNzNcYbWRWLO0iUfvYSYJaAFkmL/VKwrI7HFnSQxAwhtM6Cbd9JDb1RMEaT1aW6PZ1nA==" crossorigin="anonymous" referrerpolicy="no-referrer"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/codemirror/5.48.4/addon/dialog/dialog.min.js" integrity="sha512-WYctQXRN2KbvUe9S67mXvptV2/hGKIKHx14FVbI3Uk4ClGxqnzRxl9pS2A99DhW9kzkWLn+qLwNmhhReJZiOFQ==" crossorigin="anonymous" referrerpolicy="no-referrer"></script>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/codemirror/5.48.4/addon/dialog/dialog.css" integrity="sha512-5/XbSvrM+KAMENYsNpNkIyPT/PF2BKR5eAPfBOTxRKlE3GRsL9ogVI31OK2ndVcBJ7KhVAOZahcc7RdpaX8+5A==" crossorigin="anonymous" referrerpolicy="no-referrer" />

<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.5.1/jquery.min.js" integrity="sha256-9/aliU8dGd2tb6OSsuzixeV4y/faTqgFtohetphbbj0=" crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.5.1/jquery.min.js" integrity="sha512-bLT0Qm9VnAYZDflyKcBaQ2gg0hSYNQrJ8RilYldYQ1FxQYoCLtUjuuRuZo+fjqhx/qtq/1itJ0C2ejDxltZVFg==" crossorigin="anonymous" referrerpolicy="no-referrer"></script>

<script src="https://cdnjs.cloudflare.com/ajax/libs/js-cookie/2.2.1/js.cookie.min.js" integrity="sha256-oE03O+I6Pzff4fiMqwEGHbdfcW7a3GRRxlL+U49L5sA=" crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/require.js/2.3.6/require.min.js" integrity="sha256-1fEPhSsRKlFKGfK3eO710tEweHh1fwokU5wFGDHO+vg=" crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/js-cookie/2.2.1/js.cookie.min.js" integrity="sha512-Meww2sXqNHxI1+5Dyh/9KAtvI9RZSA4c1K2k5iL02oiPO/RH3Q30L3M1albtqMg50u4gRTYdV4EXOQqXEI336A==" crossorigin="anonymous" referrerpolicy="no-referrer"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/require.js/2.3.6/require.min.js" integrity="sha512-c3Nl8+7g4LMSTdrm621y7kf9v3SDPnhxLNhcjFJbKECVnmZHTdo+IRO05sNLTH/D3vA6u1X32ehoLC7WFVdheg==" crossorigin="anonymous" referrerpolicy="no-referrer"></script>

<script src="js/lib/unpackers/javascriptobfuscator_unpacker.js"></script>
<script src="js/lib/unpackers/urlencode_unpacker.js"></script>
Expand Down Expand Up @@ -158,7 +158,7 @@ <h2>Options</h2>
<label for="comma-first">Use comma-first list style?</label>
<br>
<input class="checkbox" type="checkbox" id="detect-packers">
<label for="detect-packers">Detect packers and obfuscators?</label>
<label for="detect-packers">Detect packers and obfuscators? (unsafe)</label>
<br>
<input class="checkbox" type="checkbox" id="brace-preserve-inline">
<label for="brace-preserve-inline">Preserve inline braces/code blocks?</label>
Expand Down
8 changes: 5 additions & 3 deletions js/src/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
8 changes: 2 additions & 6 deletions js/src/css/beautifier.js
Original file line number Diff line number Diff line change
Expand Up @@ -258,13 +258,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 @@ -284,13 +282,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
7 changes: 4 additions & 3 deletions js/src/javascript/acorn.js

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

10 changes: 9 additions & 1 deletion js/src/javascript/beautifier.js
Original file line number Diff line number Diff line change
Expand Up @@ -891,7 +891,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 @@ -1172,6 +1174,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
7 changes: 6 additions & 1 deletion js/src/javascript/tokenizer.js
Original file line number Diff line number Diff line change
Expand Up @@ -484,6 +484,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 @@ -507,7 +510,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
Loading

0 comments on commit bb255e0

Please sign in to comment.