IssueRaiser

Dart conditionally imported library

This is a proposal for a new guarded import syntax which allows conditionally either importing or *not* importing a library, and telling at runtime which one it was. The allowed conditions are the same as for the current conditional imports. The import works like a deferred library which is either always loaded or never loaded. We add guards to check whether the library is loaded or not. ## Specification ### Import syntax and semantics The import syntax of conditional imports is changed so you can omit the *first* URI string. In that case, it must be followed by precisely one `if (….) URI` condition, and it must then be followed by a prefix name clause `as name` . It cannot be `deferred`. ```ebnf <importSpecification> ::= `import' <configurableUri> (`deferred' `as' <identifier>)? <combinator>* `;' <configurableUri> ::= <uri> <configurationUri>* ``` becomes ```ebnf <importSpecification> ::= `import' <configurableUri> (`deferred' `as' <identifier>)? <combinator>* `;' | `import' <configurationUri> `as' <identifier> <combinator>* `;' <configurableUri> ::= <uri> <configurationUri>* ``` Example: ```dart import if (dart.library.io) "some_io_library.dart" as some; ``` The prefix name can only be shared with other conditionally imported libraries with the *same* condition. _Alternatively we can allow `<configurationUri>+` in the conditional import, to allow at most one of multiple libraries to be loaded, depending on configuration, but still allow ending up wi

Posted by lrhn on May 12, 2022, 2:48 PM

Tags

Related issues

Raise real-world problems, find people facing the same issue, and discuss solutions.2,500 issues0 comments

github (Software)

Dart conditionally imported library

lrhnMay 12, 2022, 2:48 PM

This is a proposal for a new guarded import syntax which allows conditionally either importing or *not* importing a library, and telling at runtime which one it was. The allowed conditions are the same as for the current conditional imports. The import works like a deferred library which is either always loaded or never loaded. We add guards to check whether the library is loaded or not. ## Specification ### Import syntax and semantics The import syntax of conditional imports is changed so you can omit the *first* URI string. In that case, it must be followed by precisely one `if (….) URI` condition, and it must then be followed by a prefix name clause `as name` . It cannot be `deferred`. ```ebnf <importSpecification> ::= `import' <configurableUri> (`deferred' `as' <identifier>)? <combinator>* `;' <configurableUri> ::= <uri> <configurationUri>* ``` becomes ```ebnf <importSpecification> ::= `import' <configurableUri> (`deferred' `as' <identifier>)? <combinator>* `;' | `import' <configurationUri> `as' <identifier> <combinator>* `;' <configurableUri> ::= <uri> <configurationUri>* ``` Example: ```dart import if (dart.library.io) "some_io_library.dart" as some; ``` The prefix name can only be shared with other conditionally imported libraries with the *same* condition. _Alternatively we can allow `<configurationUri>+` in the conditional import, to allow at most one of multiple libraries to be loaded, depending on configuration, but still allow ending up wi

Comments (0)

No comments yet. Start the discussion.

Comment on this issue