Skip to content

Commit

Permalink
Version 3.1.0-0.0.dev
Browse files Browse the repository at this point in the history
Merge f9eb97f into dev
  • Loading branch information
Dart CI committed Apr 13, 2023
2 parents 66d24b6 + f9eb97f commit 6eb25c3
Show file tree
Hide file tree
Showing 213 changed files with 3,325 additions and 2,730 deletions.
32 changes: 16 additions & 16 deletions pkg/_fe_analyzer_shared/lib/src/experiments/flags.dart
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ enum ExperimentalFlag {
name: 'const-functions',
isEnabledByDefault: false,
isExpired: false,
experimentEnabledVersion: const Version(3, 0),
experimentReleasedVersion: const Version(3, 0)),
experimentEnabledVersion: const Version(3, 1),
experimentReleasedVersion: const Version(3, 1)),

constantUpdate2018(
name: 'constant-update-2018',
Expand Down Expand Up @@ -62,8 +62,8 @@ enum ExperimentalFlag {
name: 'extension-types',
isEnabledByDefault: false,
isExpired: false,
experimentEnabledVersion: const Version(3, 0),
experimentReleasedVersion: const Version(3, 0)),
experimentEnabledVersion: const Version(3, 1),
experimentReleasedVersion: const Version(3, 1)),

genericMetadata(
name: 'generic-metadata',
Expand All @@ -83,22 +83,22 @@ enum ExperimentalFlag {
name: 'inference-update-2',
isEnabledByDefault: false,
isExpired: false,
experimentEnabledVersion: const Version(3, 0),
experimentReleasedVersion: const Version(3, 0)),
experimentEnabledVersion: const Version(3, 1),
experimentReleasedVersion: const Version(3, 1)),

inlineClass(
name: 'inline-class',
isEnabledByDefault: false,
isExpired: false,
experimentEnabledVersion: const Version(3, 0),
experimentReleasedVersion: const Version(3, 0)),
experimentEnabledVersion: const Version(3, 1),
experimentReleasedVersion: const Version(3, 1)),

macros(
name: 'macros',
isEnabledByDefault: false,
isExpired: false,
experimentEnabledVersion: const Version(3, 0),
experimentReleasedVersion: const Version(3, 0)),
experimentEnabledVersion: const Version(3, 1),
experimentReleasedVersion: const Version(3, 1)),

namedArgumentsAnywhere(
name: 'named-arguments-anywhere',
Expand Down Expand Up @@ -167,8 +167,8 @@ enum ExperimentalFlag {
name: 'test-experiment',
isEnabledByDefault: false,
isExpired: false,
experimentEnabledVersion: const Version(3, 0),
experimentReleasedVersion: const Version(3, 0)),
experimentEnabledVersion: const Version(3, 1),
experimentReleasedVersion: const Version(3, 1)),

tripleShift(
name: 'triple-shift',
Expand All @@ -188,15 +188,15 @@ enum ExperimentalFlag {
name: 'value-class',
isEnabledByDefault: false,
isExpired: false,
experimentEnabledVersion: const Version(3, 0),
experimentReleasedVersion: const Version(3, 0)),
experimentEnabledVersion: const Version(3, 1),
experimentReleasedVersion: const Version(3, 1)),

variance(
name: 'variance',
isEnabledByDefault: false,
isExpired: false,
experimentEnabledVersion: const Version(3, 0),
experimentReleasedVersion: const Version(3, 0)),
experimentEnabledVersion: const Version(3, 1),
experimentReleasedVersion: const Version(3, 1)),
;

final String name;
Expand Down
24 changes: 24 additions & 0 deletions pkg/_fe_analyzer_shared/lib/src/messages/codes_generated.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7648,6 +7648,18 @@ Message _withArgumentsJsInteropDartClassExtendsJSClass(
arguments: {'name': name, 'name2': name2});
}

// DO NOT EDIT. THIS FILE IS GENERATED. SEE TOP OF FILE.
const Code<Null> codeJsInteropDartJsInteropAnnotationForStaticInteropOnly =
messageJsInteropDartJsInteropAnnotationForStaticInteropOnly;

// DO NOT EDIT. THIS FILE IS GENERATED. SEE TOP OF FILE.
const MessageCode messageJsInteropDartJsInteropAnnotationForStaticInteropOnly =
const MessageCode("JsInteropDartJsInteropAnnotationForStaticInteropOnly",
problemMessage:
r"""The '@JS' annotation from 'dart:js_interop' can only be used for static interop, either through inline classes or '@staticInterop'.""",
correctionMessage:
r"""Try making this class an inline class or marking it as '@staticInterop'.""");

// DO NOT EDIT. THIS FILE IS GENERATED. SEE TOP OF FILE.
const Code<Null> codeJsInteropEnclosingClassJSAnnotation =
messageJsInteropEnclosingClassJSAnnotation;
Expand Down Expand Up @@ -7842,6 +7854,18 @@ const MessageCode messageJsInteropExternalMemberNotJSAnnotated = const MessageCo
correctionMessage:
r"""Try removing the 'external' keyword or adding a JS interop annotation.""");

// DO NOT EDIT. THIS FILE IS GENERATED. SEE TOP OF FILE.
const Code<Null> codeJsInteropInlineClassUsedWithWrongJsAnnotation =
messageJsInteropInlineClassUsedWithWrongJsAnnotation;

// DO NOT EDIT. THIS FILE IS GENERATED. SEE TOP OF FILE.
const MessageCode messageJsInteropInlineClassUsedWithWrongJsAnnotation =
const MessageCode("JsInteropInlineClassUsedWithWrongJsAnnotation",
problemMessage:
r"""Inline classes should use the '@JS' annotation from 'dart:js_interop' and not from 'package:js'.""",
correctionMessage:
r"""Try using the '@JS' annotation from 'dart:js_interop' annotation on this inline class instead.""");

// DO NOT EDIT. THIS FILE IS GENERATED. SEE TOP OF FILE.
const Code<Null> codeJsInteropInvalidStaticClassMemberName =
messageJsInteropInvalidStaticClassMemberName;
Expand Down
23 changes: 23 additions & 0 deletions pkg/_js_interop_checks/lib/js_interop_checks.dart
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,12 @@ import 'package:_fe_analyzer_shared/src/messages/codes.dart'
Message,
LocatedMessage,
messageJsInteropAnonymousFactoryPositionalParameters,
messageJsInteropDartJsInteropAnnotationForStaticInteropOnly,
messageJsInteropEnclosingClassJSAnnotation,
messageJsInteropEnclosingClassJSAnnotationContext,
messageJsInteropExternalExtensionMemberOnTypeInvalid,
messageJsInteropExternalMemberNotJSAnnotated,
messageJsInteropInlineClassUsedWithWrongJsAnnotation,
messageJsInteropInvalidStaticClassMemberName,
messageJsInteropNamedParameters,
messageJsInteropNonExternalConstructor,
Expand Down Expand Up @@ -164,6 +166,18 @@ class JsInteropChecks extends RecursiveVisitor {
_staticTypeContext.leaveMember(node);
}

@override
void visitInlineClass(InlineClass node) {
if (hasPackageJSAnnotation(node)) {
_diagnosticsReporter.report(
messageJsInteropInlineClassUsedWithWrongJsAnnotation,
node.fileOffset,
node.name.length,
node.fileUri);
}
super.visitInlineClass(node);
}

@override
void visitClass(Class node) {
_classHasJSAnnotation = hasJSInteropAnnotation(node);
Expand Down Expand Up @@ -257,6 +271,15 @@ class JsInteropChecks extends RecursiveVisitor {
node.fileUri);
}
}
// For non-inline classes, `dart:_js_annotations`'s `@JS` can only be used
// with `@staticInterop`.
if (hasJSAnnotationsJSAnnotation(node)) {
_diagnosticsReporter.report(
messageJsInteropDartJsInteropAnnotationForStaticInteropOnly,
node.fileOffset,
node.name.length,
node.fileUri);
}
}
// Since this is a breaking check, it is language-versioned.
if (node.enclosingLibrary.languageVersion >= Version(2, 13) &&
Expand Down
35 changes: 21 additions & 14 deletions pkg/_js_interop_checks/lib/src/js_interop.dart
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,16 @@ import 'package:kernel/util/graph.dart' as kernel_graph;
/// Returns true iff the node has an `@JS(...)` annotation from `package:js` or
/// from the internal `dart:_js_annotations`.
bool hasJSInteropAnnotation(Annotatable a) =>
a.annotations.any(_isPublicJSAnnotation);
a.annotations.any(_isJSInteropAnnotation);

/// Returns true iff the node has an `@JS(...)` annotation from `package:js`.
bool hasPackageJSAnnotation(Annotatable a) =>
a.annotations.any(_isPackageJSAnnotation);

/// Returns true iff the node has an `@JS(...)` annotation from the internal
/// `dart:_js_annotations`.
bool hasInternalJSInteropAnnotation(Annotatable a) =>
a.annotations.any(_isInternalJSAnnotation);
bool hasJSAnnotationsJSAnnotation(Annotatable a) =>
a.annotations.any(_isJSAnnotationsJSAnnotation);

/// Returns true iff the node has an `@anonymous` annotation from `package:js`
/// or from the internal `dart:_js_annotations`.
Expand Down Expand Up @@ -53,7 +57,7 @@ bool hasObjectLiteralAnnotation(Annotatable a) =>
String getJSName(Annotatable a) {
String jsClass = '';
for (var annotation in a.annotations) {
if (_isPublicJSAnnotation(annotation)) {
if (_isJSInteropAnnotation(annotation)) {
var jsClasses = stringAnnotationValues(annotation);
if (jsClasses.isNotEmpty) {
jsClass = jsClasses[0];
Expand Down Expand Up @@ -103,30 +107,33 @@ String getJSExportName(Annotatable a) {
}

final _packageJs = Uri.parse('package:js/js.dart');
final _internalJs = Uri.parse('dart:_js_annotations');
final _jsAnnotations = Uri.parse('dart:_js_annotations');
final _jsHelper = Uri.parse('dart:_js_helper');
final _jsInterop = Uri.parse('dart:js_interop');

/// Returns true if [value] is the interop annotation whose class is
/// [annotationClassName] from `package:js` or from `dart:_js_annotations`.
/// [annotationClassName] from [interopLibraries].
///
/// If [internalJsOnly] is true, we only check if it's the annotation from
/// If [interopLibraries] is null, we check `package:js` and
/// `dart:_js_annotations`.
bool _isInteropAnnotation(Expression value, String annotationClassName,
{bool internalJsOnly = false}) {
{Set<Uri>? interopLibraries}) {
interopLibraries ??= {_packageJs, _jsAnnotations};
var c = annotationClass(value);
if (c == null || c.name != annotationClassName) return false;
var importUri = c.enclosingLibrary.importUri;
if (internalJsOnly) return importUri == _internalJs;
return importUri == _packageJs || importUri == _internalJs;
return interopLibraries.contains(importUri);
}

bool _isInternalJSAnnotation(Expression value) =>
_isInteropAnnotation(value, 'JS', internalJsOnly: true);

bool _isPublicJSAnnotation(Expression value) =>
bool _isJSInteropAnnotation(Expression value) =>
_isInteropAnnotation(value, 'JS');

bool _isPackageJSAnnotation(Expression value) =>
_isInteropAnnotation(value, 'JS', interopLibraries: {_packageJs});

bool _isJSAnnotationsJSAnnotation(Expression value) =>
_isInteropAnnotation(value, 'JS', interopLibraries: {_jsAnnotations});

bool _isAnonymousAnnotation(Expression value) =>
_isInteropAnnotation(value, '_Anonymous');

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import '../js_interop.dart'
show
getJSName,
hasAnonymousAnnotation,
hasInternalJSInteropAnnotation,
hasJSAnnotationsJSAnnotation,
hasJSInteropAnnotation,
hasNativeAnnotation,
hasObjectLiteralAnnotation,
Expand Down Expand Up @@ -233,8 +233,8 @@ class JsUtilOptimizer extends Transformer {

if (!node.isInlineClassMember &&
node.enclosingClass == null &&
((hasInternalJSInteropAnnotation(node) ||
hasInternalJSInteropAnnotation(node.enclosingLibrary)) &&
((hasJSAnnotationsJSAnnotation(node) ||
hasJSAnnotationsJSAnnotation(node.enclosingLibrary)) &&
!_existingJsAnnotationsUsers
.contains(node.enclosingLibrary.importUri.toString()))) {
// Top-level external member. We only lower top-levels if we're using the
Expand Down Expand Up @@ -892,24 +892,24 @@ class InlineExtensionIndex {
}

bool isJSInteropMember(Procedure node) {
if (hasInternalJSInteropAnnotation(node) ||
hasInternalJSInteropAnnotation(node.enclosingLibrary) ||
if (hasJSAnnotationsJSAnnotation(node) ||
hasJSAnnotationsJSAnnotation(node.enclosingLibrary) ||
(node.enclosingClass != null &&
hasInternalJSInteropAnnotation(node.enclosingClass!))) {
hasJSAnnotationsJSAnnotation(node.enclosingClass!))) {
return true;
}

if (node.isExtensionMember) {
final annotatable = getExtensionAnnotatable(node.reference);
if (annotatable != null) {
return hasInternalJSInteropAnnotation(annotatable);
return hasJSAnnotationsJSAnnotation(annotatable);
}
}

if (node.isInlineClassMember) {
final cls = getInlineClass(node.reference);
if (cls != null) {
return hasInternalJSInteropAnnotation(cls);
return hasJSAnnotationsJSAnnotation(cls);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,7 @@ class ConvertToContains extends CorrectionProducer {
var startArgumentRange = _startArgumentRange(rightOperand);
var deletionRange = range.startStart(leftOperand, rightOperand);
var notOffset = -1;
var style =
_negationStyle(_invertedTokenType(comparison.operator.type), value);
var style = _negationStyle(comparison.operator.type.inverted, value);
if (style == NegationStyle.none) {
return;
} else if (style == NegationStyle.negated) {
Expand Down Expand Up @@ -106,16 +105,6 @@ class ConvertToContains extends CorrectionProducer {
return null;
}

TokenType _invertedTokenType(TokenType type) {
return switch (type) {
TokenType.LT_EQ => TokenType.GT_EQ,
TokenType.LT => TokenType.GT,
TokenType.GT => TokenType.LT,
TokenType.GT_EQ => TokenType.LT_EQ,
_ => type
};
}

/// Return `true` if the given [expression] is a literal integer, possibly
/// prefixed by a negation operator.
bool _isInteger(Expression expression) {
Expand Down Expand Up @@ -175,3 +164,13 @@ class ConvertToContains extends CorrectionProducer {
/// An indication of whether the `contains` test should be negated, not negated,
/// or whether neither is appropriate and the code should be left unchanged.
enum NegationStyle { none, negated, positive }

extension on TokenType {
TokenType get inverted => switch (this) {
TokenType.LT_EQ => TokenType.GT_EQ,
TokenType.LT => TokenType.GT,
TokenType.GT => TokenType.LT,
TokenType.GT_EQ => TokenType.LT_EQ,
_ => this
};
}
2 changes: 1 addition & 1 deletion pkg/analyzer/lib/src/dart/analysis/experiments.g.dart
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ part of 'experiments.dart';

/// The current version of the Dart language (or, for non-stable releases, the
/// version of the language currently in the process of being developed).
const _currentVersion = '3.0.0';
const _currentVersion = '3.1.0';

/// A map containing information about all known experimental flags.
final _knownFeatures = <String, ExperimentalFeature>{
Expand Down
6 changes: 5 additions & 1 deletion pkg/compiler/lib/src/source_file_provider.dart
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,11 @@ abstract class SourceFileProvider implements api.CompilerInput {
if (!resourceUri.isAbsolute) {
resourceUri = cwd.resolveUri(resourceUri);
}
registerUri(resourceUri);
// Do not register URIs with schemes other than 'file' as these are internal
// libraries that we cannot read later.
if (resourceUri.isScheme('file')) {
registerUri(resourceUri);
}
}

/// Registers the URI and returns true if the URI is new.
Expand Down
7 changes: 5 additions & 2 deletions pkg/compiler/test/jsinterop/internal_annotations_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,12 @@ import 'package:compiler/src/util/memory_compiler.dart';

void main() {
asyncTest(() async {
await testClasses('package:js/js.dart', 'dart:_js_annotations');
// TODO(srujzs): Uncomment these tests when we create a `dart:js_interop`
// `@JS` annotation. Currently these tests fail because
// `dart:_js_annotations`' `@JS` can only be used for static interop.
// await testClasses('package:js/js.dart', 'dart:_js_annotations');
await testClasses('package:js/js.dart', 'package:js/js.dart');
await testClasses('dart:_js_annotations', 'dart:_js_annotations');
// await testClasses('dart:_js_annotations', 'dart:_js_annotations');
});
}

Expand Down
Loading

0 comments on commit 6eb25c3

Please sign in to comment.