mirror of
https://github.com/slint-ui/slint.git
synced 2025-11-02 04:48:27 +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
|
|
@ -292,10 +292,14 @@ export { MathLogic } // known as "MathLogic" when using native APIs to access gl
|
|||
The following syntax is supported for importing types:
|
||||
|
||||
```slint no-test
|
||||
import { export1 } from "module.slint";
|
||||
import { export1, export2 } from "module.slint";
|
||||
import { export1 as alias1 } from "module.slint";
|
||||
import { export1, export2 as alias2, /* ... */ } from "module.slint";
|
||||
import { MyButton } from "module.slint";
|
||||
import { MyButton, MySwitch } from "module.slint";
|
||||
import { MyButton as OtherButton } from "module.slint";
|
||||
import {
|
||||
MyButton,
|
||||
/* ... */,
|
||||
MySwitch as OtherSwitch,
|
||||
} from "module.slint";
|
||||
```
|
||||
|
||||
The following syntax is supported for exporting types:
|
||||
|
|
|
|||
|
|
@ -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}
|
||||
|
|
@ -2,7 +2,10 @@
|
|||
// SPDX-License-Identifier: GPL-3.0-only OR LicenseRef-Slint-Royalty-free-2.0 OR LicenseRef-Slint-Software-3.0
|
||||
|
||||
//include_path: ../../helper_components
|
||||
import { UseGlobal, ExportedGlobal as FromExport } from "export_globals.slint";
|
||||
import {
|
||||
UseGlobal,
|
||||
ExportedGlobal as FromExport,
|
||||
} from "export_globals.slint";
|
||||
|
||||
global NotExported := {
|
||||
property<int> abc: 1000;
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@
|
|||
// SPDX-License-Identifier: GPL-3.0-only OR LicenseRef-Slint-Royalty-free-2.0 OR LicenseRef-Slint-Software-3.0
|
||||
|
||||
//include_path: ../../helper_components
|
||||
import { UseStruct , ExportedStruct, ExportEnum } from "export_structs.slint";
|
||||
import { UseStruct , ExportedStruct, ExportEnum , } from "export_structs.slint";
|
||||
TestCase := Rectangle {
|
||||
property <ExportedStruct> exp: { d: 3001, e: {a: 2001} };
|
||||
u := UseStruct {
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@
|
|||
// SPDX-License-Identifier: GPL-3.0-only OR LicenseRef-Slint-Royalty-free-2.0 OR LicenseRef-Slint-Software-3.0
|
||||
|
||||
//include_path: ../../helper_components
|
||||
import { TestButton as RealButton } from "test_button.slint";
|
||||
import { TestButton as RealButton, } from "test_button.slint";
|
||||
import { ColorButton } from "../helper_components/test_button.slint";
|
||||
import { Button } from "std-widgets.slint";
|
||||
import { TestButton as ReExportedButton } from "re_export.slint";
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue