mirror of
https://github.com/beautifier/js-beautify.git
synced 2025-02-17 03:38:08 +00:00
Allow # to start identifier, such as private fields in classes
To resolve #1734 , this change adds # which is hex 23 to begin an identifier name.
This commit is contained in:
parent
db4bc4d889
commit
c26968ab88
@ -274,6 +274,12 @@ Tokenizer.prototype._read_non_javascript = function(c) {
|
||||
this._input.next();
|
||||
}
|
||||
return this._create_token(TOKEN.WORD, sharp);
|
||||
} else if (this._input.hasNext()) {
|
||||
// Handle private field (ie. #privateExample)
|
||||
resulting_string = this.__patterns.identifier.read();
|
||||
if (resulting_string) {
|
||||
return this._create_token(TOKEN.WORD, sharp + resulting_string);
|
||||
}
|
||||
}
|
||||
|
||||
this._input.back();
|
||||
|
@ -404,6 +404,20 @@ function run_javascript_tests(test_obj, Urlencoded, js_beautify, html_beautify,
|
||||
'};');
|
||||
|
||||
|
||||
//============================================================
|
||||
// ES5 Class Private Fields
|
||||
reset_options();
|
||||
set_name('ES5 Class Private Fields');
|
||||
bt('#foo');
|
||||
bt(
|
||||
'class X {\n' +
|
||||
' #foo = null;\n' +
|
||||
' get foo() {\n' +
|
||||
' return this.#foo;\n' +
|
||||
' }\n' +
|
||||
'}');
|
||||
|
||||
|
||||
//============================================================
|
||||
// ES7 Decorators
|
||||
reset_options();
|
||||
|
@ -408,6 +408,11 @@ class Tokenizer(BaseTokenizer):
|
||||
self._input.next()
|
||||
|
||||
return self._create_token(TOKEN.WORD, sharp)
|
||||
elif self._input.hasNext():
|
||||
# Handle private field (ie. #privateExample)
|
||||
resulting_string = self._patterns.identifier.read()
|
||||
if resulting_string:
|
||||
return self._create_token(TOKEN.WORD, sharp + resulting_string)
|
||||
|
||||
self._input.back()
|
||||
|
||||
|
@ -211,6 +211,19 @@ class TestJSBeautifier(unittest.TestCase):
|
||||
'};')
|
||||
|
||||
|
||||
#============================================================
|
||||
# ES5 Class Private Fields
|
||||
self.reset_options()
|
||||
bt('#foo')
|
||||
bt(
|
||||
'class X {\n' +
|
||||
' #foo = null;\n' +
|
||||
' get foo() {\n' +
|
||||
' return this.#foo;\n' +
|
||||
' }\n' +
|
||||
'}')
|
||||
|
||||
|
||||
#============================================================
|
||||
# ES7 Decorators
|
||||
self.reset_options()
|
||||
|
@ -169,6 +169,22 @@ exports.test_data = {
|
||||
]
|
||||
}
|
||||
]
|
||||
}, {
|
||||
name: "ES5 Class Private Fields",
|
||||
description: "Permit ES5 private class fields which are declared with a leading \"#\".",
|
||||
tests: [
|
||||
{ unchanged: '#foo' },
|
||||
{
|
||||
unchanged: [
|
||||
'class X {',
|
||||
' #foo = null;',
|
||||
' get foo() {',
|
||||
' return this.#foo;',
|
||||
' }',
|
||||
'}'
|
||||
]
|
||||
}
|
||||
]
|
||||
}, {
|
||||
name: "ES7 Decorators",
|
||||
description: "Permit ES7 decorators, which are invoked with a leading \"@\".",
|
||||
|
Loading…
x
Reference in New Issue
Block a user