Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#2846. Add unquoted imports tests for parts #2890

Merged
merged 1 commit into from
Sep 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions LanguageFeatures/Unquoted-imports/lib/co19_unquoted_imports.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
// Copyright (c) 2024, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.

/// @assertion We make a breaking change and remove support for the
/// long-deprecated library name syntax from `part of` directives. An unquoted
/// series of identifiers after `part of` then gets unambiguously interpreted as
/// this proposal's semantics. In other words, `part of foo.bar;` is part of the
/// library at `package:foo/bar.dart`, not part of the library with name
/// `foo.bar`.
///
/// @description Checks that unquoted syntax can be used in `part` and `part of`
/// directives.
/// @author sgrekhov22@gmail.com
// SharedOptions=--enable-experiment=unquoted-imports,enhanced-parts

part of co19_unquoted_imports/part_A01_t02;
eernstg marked this conversation as resolved.
Show resolved Hide resolved
part co19_unquoted_imports/co19_unquoted_imports_part;

String partId = "co19_unquoted_imports.dart";
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
// Copyright (c) 2024, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.

/// @assertion We make a breaking change and remove support for the
/// long-deprecated library name syntax from `part of` directives. An unquoted
/// series of identifiers after `part of` then gets unambiguously interpreted as
/// this proposal's semantics. In other words, `part of foo.bar;` is part of the
/// library at `package:foo/bar.dart`, not part of the library with name
/// `foo.bar`.
///
/// @description Checks that unquoted syntax can be used in `part` and `part of`
/// directives.
/// @author sgrekhov22@gmail.com
// SharedOptions=--enable-experiment=unquoted-imports,enhanced-parts

part of co19_unquoted_imports;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would be 'package:co19_unquoted_imports/co19_unquoted_imports.dart', which would also be an error as far as I can see.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks fine now!


String partId2 = "co19_unquoted_imports_part.dart";
24 changes: 24 additions & 0 deletions LanguageFeatures/Unquoted-imports/lib/part_A01_t01.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
// Copyright (c) 2024, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.

/// @assertion We make a breaking change and remove support for the
/// long-deprecated library name syntax from `part of` directives. An unquoted
/// series of identifiers after `part of` then gets unambiguously interpreted as
/// this proposal's semantics. In other words, `part of foo.bar;` is part of the
/// library at `package:foo/bar.dart`, not part of the library with name
/// `foo.bar`.
///
/// @description Checks that unquoted syntax can be used in `part` and `part of`
/// directives.
/// @author sgrekhov22@gmail.com
// SharedOptions=--enable-experiment=unquoted-imports

part co19_unquoted_imports/part_A01_t01_part;

main() {
if (partId != "part_A01_t01_part.dart") { // Cannot use expect.dart here
throw "Wrong part '$partId'";
}
}
20 changes: 20 additions & 0 deletions LanguageFeatures/Unquoted-imports/lib/part_A01_t01_part.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
// Copyright (c) 2024, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.

/// @assertion We make a breaking change and remove support for the
/// long-deprecated library name syntax from `part of` directives. An unquoted
/// series of identifiers after `part of` then gets unambiguously interpreted as
/// this proposal's semantics. In other words, `part of foo.bar;` is part of the
/// library at `package:foo/bar.dart`, not part of the library with name
/// `foo.bar`.
///
/// @description Checks that unquoted syntax can be used in `part` and `part of`
/// directives.
/// @author sgrekhov22@gmail.com
// SharedOptions=--enable-experiment=unquoted-imports

part of co19_unquoted_imports/part_A01_t01;

String partId = "part_A01_t01_part.dart";
27 changes: 27 additions & 0 deletions LanguageFeatures/Unquoted-imports/lib/part_A01_t02.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
// Copyright (c) 2024, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.

/// @assertion We make a breaking change and remove support for the
/// long-deprecated library name syntax from `part of` directives. An unquoted
/// series of identifiers after `part of` then gets unambiguously interpreted as
/// this proposal's semantics. In other words, `part of foo.bar;` is part of the
/// library at `package:foo/bar.dart`, not part of the library with name
/// `foo.bar`.
///
/// @description Checks that unquoted syntax can be used in `part` and `part of`
/// directives.
/// @author sgrekhov22@gmail.com
// SharedOptions=--enable-experiment=unquoted-imports,enhanced-parts

part co19_unquoted_imports;

main() {
if (partId != "co19_unquoted_imports.dart") { // Cannot use expect.dart here
throw "Wrong part '$partId'";
}
if (partId2 != "co19_unquoted_imports_part.dart") {
throw "Wrong part '$partId2'";
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
// Copyright (c) 2024, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.

/// @assertion There are two directives for working with part files, `part` and
/// `part of`. This means that when the parser sees `part of`, it doesn't
/// immediately know if it is looking at a `part` directive followed by an
/// unquoted identifier like `part of`; or `part of.some/other.thing;` versus a
/// `part of` directive like `part of thing;` or `part of 'uri.dart';` It must
/// lookahead past the of identifier to see if the next token is `;`, `.`, `/`,
/// or another identifier.
///
/// @description Checks that `part of.parts.test` is parsed like a
/// `part 'package:of.parts.test/test.dart';`.
/// @author sgrekhov22@gmail.com
// SharedOptions=--enable-experiment=unquoted-imports

part of.parts.test;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks tricky, but it should be OK: Even though it might be a part of directive, this will fail to parse when . is encountered, and regular parser behavior will then ensure that of is never parsed as the keyword of in the sequence part, of, it's parsed as part of an unquoted URI.

Nothing surprising about this, that's just the standard ability of parsers to resolve ambiguities based on lookahead.


main() {
if (partId != "test") { // Cannot use expect.dart here
throw "Wrong part '$partId'";
}
}
21 changes: 21 additions & 0 deletions LanguageFeatures/Unquoted-imports/of.parts.test/lib/test.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
// Copyright (c) 2024, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.

/// @assertion There are two directives for working with part files, `part` and
/// `part of`. This means that when the parser sees `part of`, it doesn't
/// immediately know if it is looking at a `part` directive followed by an
/// unquoted identifier like `part of`; or `part of.some/other.thing;` versus a
/// `part of` directive like `part of thing;` or `part of 'uri.dart';` It must
/// lookahead past the of identifier to see if the next token is `;`, `.`, `/`,
/// or another identifier.
///
/// @description Checks that `part of.parts.test` is parsed like a
/// `part 'package:of.parts.test/test.dart';`.
/// @author sgrekhov22@gmail.com
// SharedOptions=--enable-experiment=unquoted-imports

part of of.parts.test/part_A02_t01;

String partId = "test";
8 changes: 8 additions & 0 deletions LanguageFeatures/Unquoted-imports/of.parts.test/pubspec.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
name: of.parts.test
description: Internal package used by co19 tests for Unquoted imports feature

# This tests isn't intended for publishing on pub.dev.
publish_to: none

environment:
sdk: '>=3.6.0-255.0.dev'
Loading