diff --git a/js/src/javascript/acorn.js b/js/src/javascript/acorn.js index 9cc74dd48..0442c30eb 100644 --- a/js/src/javascript/acorn.js +++ b/js/src/javascript/acorn.js @@ -35,12 +35,12 @@ var nonASCIIidentifierChars = "\\u0300-\\u036f\\u0483-\\u0487\\u0591-\\u05bd\\u0 //var nonASCIIidentifierStart = new RegExp("[" + nonASCIIidentifierStartChars + "]"); //var nonASCIIidentifier = new RegExp("[" + nonASCIIidentifierStartChars + nonASCIIidentifierChars + "]"); -var identifierStart = "[" + baseASCIIidentifierStartChars + nonASCIIidentifierStartChars + "]"; -var identifierChars = "[" + baseASCIIidentifierChars + nonASCIIidentifierStartChars + nonASCIIidentifierChars + "]*"; +var identifierStart = "(?:\\\\u[0-9a-fA-F]{4}|[" + baseASCIIidentifierStartChars + nonASCIIidentifierStartChars + "])"; +var identifierChars = "(?:\\\\u[0-9a-fA-F]{4}|[" + baseASCIIidentifierChars + nonASCIIidentifierStartChars + nonASCIIidentifierChars + "])*"; exports.identifier = new RegExp(identifierStart + identifierChars, 'g'); exports.identifierStart = new RegExp(identifierStart); -exports.identifierMatch = new RegExp("[" + baseASCIIidentifierChars + nonASCIIidentifierStartChars + nonASCIIidentifierChars + "]+"); +exports.identifierMatch = new RegExp("(?:\\\\u[0-9a-fA-F]{4}|[" + baseASCIIidentifierChars + nonASCIIidentifierStartChars + nonASCIIidentifierChars + "])+"); var nonASCIIwhitespace = /[\u1680\u180e\u2000-\u200a\u202f\u205f\u3000\ufeff]/; // jshint ignore:line diff --git a/js/test/generated/beautify-javascript-tests.js b/js/test/generated/beautify-javascript-tests.js index ff63d31cc..4e9a25163 100644 --- a/js/test/generated/beautify-javascript-tests.js +++ b/js/test/generated/beautify-javascript-tests.js @@ -350,6 +350,14 @@ function run_javascript_tests(test_obj, Urlencoded, js_beautify, html_beautify, 'var ' + unicode_char(228) + 'x = {\n' + ' ' + unicode_char(228) + 'rgerlich: true\n' + '};'); + bt( + 'var \\u00E4\\u0ca0\\u0cA0\\u0Ca0 = {\n' + + ' \\u0ca0rgerlich: true\n' + + '};'); + bt( + 'var \\u00E4add\\u0025 = {\n' + + ' \\u0044rgerlich\\u0ca0: true\n' + + '};'); bt( 'var' + unicode_char(160) + unicode_char(3232) + '_' + unicode_char(3232) + ' = "hi";', // -- output -- diff --git a/package-lock.json b/package-lock.json index fa9d7538b..9bb24f767 100644 --- a/package-lock.json +++ b/package-lock.json @@ -2014,7 +2014,8 @@ "ansi-regex": { "version": "2.1.1", "bundled": true, - "dev": true + "dev": true, + "optional": true }, "aproba": { "version": "1.2.0", @@ -2035,12 +2036,14 @@ "balanced-match": { "version": "1.0.0", "bundled": true, - "dev": true + "dev": true, + "optional": true }, "brace-expansion": { "version": "1.1.11", "bundled": true, "dev": true, + "optional": true, "requires": { "balanced-match": "^1.0.0", "concat-map": "0.0.1" @@ -2055,17 +2058,20 @@ "code-point-at": { "version": "1.1.0", "bundled": true, - "dev": true + "dev": true, + "optional": true }, "concat-map": { "version": "0.0.1", "bundled": true, - "dev": true + "dev": true, + "optional": true }, "console-control-strings": { "version": "1.1.0", "bundled": true, - "dev": true + "dev": true, + "optional": true }, "core-util-is": { "version": "1.0.2", @@ -2182,7 +2188,8 @@ "inherits": { "version": "2.0.3", "bundled": true, - "dev": true + "dev": true, + "optional": true }, "ini": { "version": "1.3.5", @@ -2194,6 +2201,7 @@ "version": "1.0.0", "bundled": true, "dev": true, + "optional": true, "requires": { "number-is-nan": "^1.0.0" } @@ -2208,6 +2216,7 @@ "version": "3.0.4", "bundled": true, "dev": true, + "optional": true, "requires": { "brace-expansion": "^1.1.7" } @@ -2215,12 +2224,14 @@ "minimist": { "version": "0.0.8", "bundled": true, - "dev": true + "dev": true, + "optional": true }, "minipass": { "version": "2.3.5", "bundled": true, "dev": true, + "optional": true, "requires": { "safe-buffer": "^5.1.2", "yallist": "^3.0.0" @@ -2239,6 +2250,7 @@ "version": "0.5.1", "bundled": true, "dev": true, + "optional": true, "requires": { "minimist": "0.0.8" } @@ -2319,7 +2331,8 @@ "number-is-nan": { "version": "1.0.1", "bundled": true, - "dev": true + "dev": true, + "optional": true }, "object-assign": { "version": "4.1.1", @@ -2331,6 +2344,7 @@ "version": "1.4.0", "bundled": true, "dev": true, + "optional": true, "requires": { "wrappy": "1" } @@ -2416,7 +2430,8 @@ "safe-buffer": { "version": "5.1.2", "bundled": true, - "dev": true + "dev": true, + "optional": true }, "safer-buffer": { "version": "2.1.2", @@ -2452,6 +2467,7 @@ "version": "1.0.2", "bundled": true, "dev": true, + "optional": true, "requires": { "code-point-at": "^1.0.0", "is-fullwidth-code-point": "^1.0.0", @@ -2471,6 +2487,7 @@ "version": "3.0.1", "bundled": true, "dev": true, + "optional": true, "requires": { "ansi-regex": "^2.0.0" } @@ -2514,12 +2531,14 @@ "wrappy": { "version": "1.0.2", "bundled": true, - "dev": true + "dev": true, + "optional": true }, "yallist": { "version": "3.0.3", "bundled": true, - "dev": true + "dev": true, + "optional": true } } }, diff --git a/python/jsbeautifier/javascript/acorn.py b/python/jsbeautifier/javascript/acorn.py index 87434c497..25818a10a 100644 --- a/python/jsbeautifier/javascript/acorn.py +++ b/python/jsbeautifier/javascript/acorn.py @@ -39,24 +39,24 @@ #_nonASCIIidentifierStart = re.compile("[" + _nonASCIIidentifierStartChars + "]") #_nonASCIIidentifier = re.compile("[" + _nonASCIIidentifierStartChars + _nonASCIIidentifierChars + "]") -_identifierStart = six.u("[") + \ +_identifierStart = six.u(r"(?:\\u[0-9a-fA-F]{4}|[") + \ _baseASCIIidentifierStartChars + \ _nonASCIIidentifierStartChars + \ - six.u("]") -_identifierChars = six.u("[") + \ + six.u("])") +_identifierChars = six.u(r"(?:\\u[0-9a-fA-F]{4}|[") + \ _baseASCIIidentifierChars + \ _nonASCIIidentifierStartChars + \ _nonASCIIidentifierChars + \ - six.u("]*") + six.u("])*") identifier = re.compile(_identifierStart + _identifierChars) identifierStart = re.compile(_identifierStart) -identifierMatch = re.compile(six.u("[") + \ +identifierMatch = re.compile(six.u(r"(?:\\u[0-9a-fA-F]{4}|[") + \ _baseASCIIidentifierChars + \ _nonASCIIidentifierStartChars + \ _nonASCIIidentifierChars + \ - six.u("]+")) + six.u("])+")) _nonASCIIwhitespace = re.compile( six.u(r"[\u1680\u180e\u2000-\u200a\u202f\u205f\u3000\ufeff]")) diff --git a/python/jsbeautifier/tests/generated/tests.py b/python/jsbeautifier/tests/generated/tests.py index 32c9527a0..41b9a683c 100644 --- a/python/jsbeautifier/tests/generated/tests.py +++ b/python/jsbeautifier/tests/generated/tests.py @@ -158,6 +158,14 @@ def unicode_char(value): 'var ' + unicode_char(228) + 'x = {\n' + ' ' + unicode_char(228) + 'rgerlich: true\n' + '};') + bt( + 'var \\u00E4\\u0ca0\\u0cA0\\u0Ca0 = {\n' + + ' \\u0ca0rgerlich: true\n' + + '};') + bt( + 'var \\u00E4add\\u0025 = {\n' + + ' \\u0044rgerlich\\u0ca0: true\n' + + '};') bt( 'var' + unicode_char(160) + unicode_char(3232) + '_' + unicode_char(3232) + ' = "hi";', # -- output -- diff --git a/test/data/javascript/tests.js b/test/data/javascript/tests.js index bcbe3af48..8e75ba6b3 100644 --- a/test/data/javascript/tests.js +++ b/test/data/javascript/tests.js @@ -44,6 +44,18 @@ exports.test_data = { " ' + unicode_char(228) + 'rgerlich: true", "};" ] + }, { + unchanged: [ + "var \\\\u00E4\\\\u0ca0\\\\u0cA0\\\\u0Ca0 = {", + " \\\\u0ca0rgerlich: true", + "};" + ] + }, { + unchanged: [ + "var \\\\u00E4add\\\\u0025 = {", + " \\\\u0044rgerlich\\\\u0ca0: true", + "};" + ] }, { input_: "var' + unicode_char(160) + unicode_char(3232) + '_' + unicode_char(3232) + ' = \"hi\";", output: "var ' + unicode_char(3232) + '_' + unicode_char(3232) + ' = \"hi\";"