mirror of
https://github.com/beautifier/js-beautify.git
synced 2025-01-31 09:52:17 +00:00
parent
01111faed5
commit
5329720021
@ -865,6 +865,8 @@ function Beautifier(js_source_text, options) {
|
||||
} else if (in_array(flags.last_word, ['await', 'async'])) {
|
||||
// Should be a space between await and an IIFE, or async and an arrow function
|
||||
output.space_before_token = true;
|
||||
} else if (flags.last_text === 'import' && current_token.whitespace_before === '') {
|
||||
output.space_before_token = false;
|
||||
} else if (in_array(flags.last_text, tokenizer.line_starters) || flags.last_text === 'catch') {
|
||||
output.space_before_token = true;
|
||||
}
|
||||
|
@ -633,6 +633,8 @@ function Beautifier(js_source_text, options) {
|
||||
} else if (in_array(flags.last_word, ['await', 'async'])) {
|
||||
// Should be a space between await and an IIFE, or async and an arrow function
|
||||
output.space_before_token = true;
|
||||
} else if (flags.last_text === 'import' && current_token.whitespace_before === '') {
|
||||
output.space_before_token = false;
|
||||
} else if (in_array(flags.last_text, tokenizer.line_starters) || flags.last_text === 'catch') {
|
||||
output.space_before_token = true;
|
||||
}
|
||||
|
@ -3747,7 +3747,16 @@ function run_javascript_tests(test_obj, Urlencoded, js_beautify, html_beautify,
|
||||
'import { member1, member2 as alias2 } from "module-name";\n' +
|
||||
'import defaultMember, { member, member2 } from "module-name";\n' +
|
||||
'import defaultMember, * as name from "module-name";\n' +
|
||||
'import "module-name";');
|
||||
'import "module-name";\n' +
|
||||
'import("module-name")');
|
||||
|
||||
// Issue #1393 - dynamic import()
|
||||
bt(
|
||||
'if (from < to) {\n' +
|
||||
' import(`dynamic${library}`);\n' +
|
||||
'} else {\n' +
|
||||
' import("otherdynamic");\n' +
|
||||
'}');
|
||||
|
||||
// Issue 858 - from is a keyword only after import
|
||||
bt(
|
||||
|
@ -472,6 +472,8 @@ class Beautifier:
|
||||
elif self.flags.last_word in ['await', 'async']:
|
||||
# Should be a space between await and an IIFE, or async and an arrow function
|
||||
self.output.space_before_token = True
|
||||
elif self.flags.last_text == 'import' and current_token.whitespace_before == '':
|
||||
self.output.space_before_token = False
|
||||
elif self.flags.last_text in Tokenizer.line_starters or self.flags.last_text == 'catch':
|
||||
self.output.space_before_token = True
|
||||
|
||||
|
@ -3575,7 +3575,16 @@ class TestJSBeautifier(unittest.TestCase):
|
||||
'import { member1, member2 as alias2 } from "module-name";\n' +
|
||||
'import defaultMember, { member, member2 } from "module-name";\n' +
|
||||
'import defaultMember, * as name from "module-name";\n' +
|
||||
'import "module-name";')
|
||||
'import "module-name";\n' +
|
||||
'import("module-name")')
|
||||
|
||||
# Issue #1393 - dynamic import()
|
||||
bt(
|
||||
'if (from < to) {\n' +
|
||||
' import(`dynamic${library}`);\n' +
|
||||
'} else {\n' +
|
||||
' import("otherdynamic");\n' +
|
||||
'}')
|
||||
|
||||
# Issue 858 - from is a keyword only after import
|
||||
bt(
|
||||
|
@ -2556,7 +2556,18 @@ exports.test_data = {
|
||||
'import { member1, member2 as alias2 } from "module-name";',
|
||||
'import defaultMember, { member, member2 } from "module-name";',
|
||||
'import defaultMember, * as name from "module-name";',
|
||||
'import "module-name";'
|
||||
'import "module-name";',
|
||||
'import("module-name")'
|
||||
]
|
||||
},
|
||||
{
|
||||
comment: "Issue #1393 - dynamic import()",
|
||||
unchanged: [
|
||||
'if (from < to) {',
|
||||
' import(`dynamic${library}`);',
|
||||
'} else {',
|
||||
' import("otherdynamic");',
|
||||
'}'
|
||||
]
|
||||
},
|
||||
{
|
||||
|
Loading…
x
Reference in New Issue
Block a user