mirror of
https://github.com/beautifier/js-beautify.git
synced 2024-11-27 06:30:32 +00:00
Fix #134, a regex-as-parameter regression
This commit is contained in:
parent
b147439fa2
commit
57ad392ed2
@ -491,7 +491,7 @@ function js_beautify(js_source_text, options) {
|
||||
(c === '/' &&
|
||||
((last_type === 'TK_WORD' && is_special_word(last_text)) ||
|
||||
(last_text === ')' && in_array(flags.previous_mode, ['(COND-EXPRESSION)', '(FOR-EXPRESSION)'])) ||
|
||||
(last_type === 'TK_COMMENT' || last_type === 'TK_START_EXPR' || last_type === 'TK_START_BLOCK' || last_type === 'TK_END_BLOCK' || last_type === 'TK_OPERATOR' || last_type === 'TK_EQUALS' || last_type === 'TK_EOF' || last_type === 'TK_SEMICOLON')))) { // regexp
|
||||
(last_type === 'TK_COMMA' || last_type === 'TK_COMMENT' || last_type === 'TK_START_EXPR' || last_type === 'TK_START_BLOCK' || last_type === 'TK_END_BLOCK' || last_type === 'TK_OPERATOR' || last_type === 'TK_EQUALS' || last_type === 'TK_EOF' || last_type === 'TK_SEMICOLON')))) { // regexp
|
||||
var sep = c;
|
||||
var esc = false;
|
||||
var esc1 = 0;
|
||||
|
@ -526,7 +526,7 @@ class Beautifier:
|
||||
(c == '/' and ((self.last_type == 'TK_WORD' and self.is_special_word(self.last_text)) or \
|
||||
(self.last_type == 'TK_END_EXPR' and self.flags.previous_mode in ['(FOR-EXPRESSION)', '(COND-EXPRESSION)']) or \
|
||||
(self.last_type in ['TK_COMMENT', 'TK_START_EXPR', 'TK_START_BLOCK', 'TK_END_BLOCK', 'TK_OPERATOR',
|
||||
'TK_EQUALS', 'TK_EOF', 'TK_SEMICOLON']))):
|
||||
'TK_EQUALS', 'TK_EOF', 'TK_SEMICOLON', 'TK_COMMA']))):
|
||||
sep = c
|
||||
esc = False
|
||||
esc1 = 0
|
||||
|
@ -453,6 +453,7 @@ class TestJSBeautifier(unittest.TestCase):
|
||||
bt('import foo.*;', 'import foo.*;') # actionscript's import
|
||||
test_fragment('function f(a: a, b: b)') # actionscript
|
||||
bt('foo(a, function() {})');
|
||||
bt('foo(a, /regex/)');
|
||||
|
||||
|
||||
def decodesto(self, input, expectation=None):
|
||||
|
@ -510,6 +510,8 @@ function run_beautifier_tests(test_obj)
|
||||
bt('function a(a) {} function b(b) {} function c(c) {}', 'function a(a) {}\nfunction b(b) {}\nfunction c(c) {}');
|
||||
bt('foo(a, function() {})');
|
||||
|
||||
bt('foo(a, /regex/)');
|
||||
|
||||
return sanitytest;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user