mirror of
https://github.com/slint-ui/slint.git
synced 2025-08-04 02:39:28 +00:00
Allow trailing comma in import statements (#8223)
Adding support for (optional) trailing commas like this: import { Foo, Bar, } from "foobar.slint"; This way it's more convenient to keep component imports sorted and leads to smaller diffs when adding more components to the end of the import statement. ChangeLog: Allow trailing comma in import statements Closes #4922
This commit is contained in:
parent
7f352ed764
commit
a5ec77ac99
7 changed files with 35 additions and 24 deletions
|
@ -313,8 +313,11 @@ fn parse_import_specifier(p: &mut impl Parser) -> bool {
|
|||
#[cfg_attr(test, parser_test)]
|
||||
/// ```test,ImportIdentifierList
|
||||
/// { Type1 }
|
||||
/// { Type2, Type3 }
|
||||
/// { Type as Alias1, Type as AnotherAlias }
|
||||
/// { Type2, }
|
||||
/// { Type3, Type4 }
|
||||
/// { Type5, Type6, }
|
||||
/// { Type as Alias1, Type as AnotherAlias1 }
|
||||
/// { Type as Alias2, Type as AnotherAlias2, }
|
||||
/// {}
|
||||
/// ```
|
||||
fn parse_import_identifier_list(p: &mut impl Parser) -> bool {
|
||||
|
@ -322,23 +325,14 @@ fn parse_import_identifier_list(p: &mut impl Parser) -> bool {
|
|||
if !p.expect(SyntaxKind::LBrace) {
|
||||
return false;
|
||||
}
|
||||
if p.test(SyntaxKind::RBrace) {
|
||||
return true;
|
||||
}
|
||||
loop {
|
||||
if p.test(SyntaxKind::RBrace) {
|
||||
return true;
|
||||
}
|
||||
parse_import_identifier(&mut *p);
|
||||
match p.nth(0).kind() {
|
||||
SyntaxKind::RBrace => {
|
||||
p.consume();
|
||||
return true;
|
||||
}
|
||||
SyntaxKind::Comma => {
|
||||
p.consume();
|
||||
}
|
||||
_ => {
|
||||
p.error("Expected comma or brace");
|
||||
return false;
|
||||
}
|
||||
if !p.test(SyntaxKind::Comma) && p.nth(0).kind() != SyntaxKind::RBrace {
|
||||
p.error("Expected comma or brace");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,5 @@
|
|||
// Copyright © SixtyFPS GmbH <info@slint.dev>
|
||||
// SPDX-License-Identifier: GPL-3.0-only OR LicenseRef-Slint-Royalty-free-2.0 OR LicenseRef-Slint-Software-3.0
|
||||
|
||||
import { , SomeRect } from "../../typeloader/incpath/local_helper_type.slint";
|
||||
// ^error{Syntax error: expected Identifier}
|
|
@ -0,0 +1,5 @@
|
|||
// Copyright © SixtyFPS GmbH <info@slint.dev>
|
||||
// SPDX-License-Identifier: GPL-3.0-only OR LicenseRef-Slint-Royalty-free-2.0 OR LicenseRef-Slint-Software-3.0
|
||||
|
||||
import { SomeRect SomeRect as OtherRect } from "../../typeloader/incpath/local_helper_type.slint";
|
||||
// ^error{Expected comma or brace}
|
Loading…
Add table
Add a link
Reference in a new issue