Skip to content

Commit

Permalink
Version 3.2.0-143.0.dev
Browse files Browse the repository at this point in the history
Merge 5b44717 into dev
  • Loading branch information
Dart CI committed Sep 8, 2023
2 parents 4cf3043 + 5b44717 commit 164b289
Show file tree
Hide file tree
Showing 97 changed files with 2,982 additions and 2,271 deletions.
20 changes: 5 additions & 15 deletions pkg/_js_interop_checks/lib/js_interop_checks.dart
Original file line number Diff line number Diff line change
Expand Up @@ -98,13 +98,6 @@ class JsInteropChecks extends RecursiveVisitor {
RegExp(r'(?<!generated_)tests/lib_2/js'),
];

/// Libraries that need to use external extension members with static interop
/// types.
static const Iterable<String> _customStaticInteropImplementations = [
'js_interop',
'js_interop_unsafe',
];

/// Libraries that cannot be used when [_enforceStrictMode] is true.
static const _disallowedLibrariesInStrictMode = [
'package:js/js.dart',
Expand Down Expand Up @@ -149,13 +142,10 @@ class JsInteropChecks extends RecursiveVisitor {
_typeParameterBoundChecker = _TypeParameterBoundChecker(_extensionIndex);
}

/// Verifies given [member] is an external extension member on a static
/// interop type that needs custom behavior.
static bool isAllowedCustomStaticInteropImplementation(Member member) {
Uri uri = member.enclosingLibrary.importUri;
return uri.isScheme('dart') &&
_customStaticInteropImplementations.contains(uri.path);
}
/// Determines if given [member] is an external extension member that needs to
/// be patched instead of lowered.
static bool isPatchedMember(Member member) =>
member.isExternal && hasPatchAnnotation(member);

/// Extract all native class names from the [component].
///
Expand Down Expand Up @@ -381,7 +371,7 @@ class JsInteropChecks extends RecursiveVisitor {
} else {
annotatable = node.enclosingClass;
}
if (!isAllowedCustomStaticInteropImplementation(node)) {
if (!isPatchedMember(node)) {
if (annotatable == null ||
((hasDartJSInteropAnnotation(annotatable) ||
annotatable is ExtensionTypeDeclaration))) {
Expand Down
12 changes: 12 additions & 0 deletions pkg/_js_interop_checks/lib/src/js_interop.dart
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,9 @@ bool hasJSExportAnnotation(Annotatable a) =>
bool hasNativeAnnotation(Annotatable a) =>
a.annotations.any(_isNativeAnnotation);

/// Returns true iff the node has an `@patch` annotation from `dart:_internal`.
bool hasPatchAnnotation(Annotatable a) => a.annotations.any(_isPatchAnnotation);

/// If [a] has a `@JS('...')` annotation, returns the value inside the
/// parentheses.
///
Expand Down Expand Up @@ -105,6 +108,7 @@ String getJSExportName(Annotatable a) {
}

final _packageJs = Uri.parse('package:js/js.dart');
final _internal = Uri.parse('dart:_internal');
final _jsAnnotations = Uri.parse('dart:_js_annotations');
final _jsHelper = Uri.parse('dart:_js_helper');
final _jsInterop = Uri.parse('dart:js_interop');
Expand Down Expand Up @@ -153,6 +157,14 @@ bool _isNativeAnnotation(Expression value) {
c.enclosingLibrary.importUri == _jsHelper;
}

/// Returns true if [value] is the `patch` annotation from `dart:_internal`.
bool _isPatchAnnotation(Expression value) {
var c = annotationClass(value);
return c != null &&
c.name == '_Patch' &&
c.enclosingLibrary.importUri == _internal;
}

/// Returns the class of the instance referred to by metadata annotation [node].
///
/// For example:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -304,20 +304,19 @@ class ExportCreator extends Transformer {
var getter = getSet.getter;
var setter = getSet.setter;
if (getter != null) {
final resultType = _staticInteropMockValidator.typeParameterResolver
.resolve(getter.getterType);
block.add(setProperty(
VariableGet(getSetMap),
'get',
StaticInvocation(
_functionToJS,
Arguments([
FunctionExpression(FunctionNode(ReturnStatement(InstanceGet(
InstanceAccessKind.Instance,
VariableGet(dartInstance),
getter.name,
interfaceTarget: getter,
resultType: _staticInteropMockValidator
.typeParameterResolver
.resolve(getter.getterType)))))
FunctionExpression(FunctionNode(
ReturnStatement(InstanceGet(InstanceAccessKind.Instance,
VariableGet(dartInstance), getter.name,
interfaceTarget: getter, resultType: resultType)),
returnType: resultType))
]))));
}
if (setter != null) {
Expand All @@ -340,7 +339,8 @@ class ExportCreator extends Transformer {
setter.name,
VariableGet(setterParameter),
interfaceTarget: setter)),
positionalParameters: [setterParameter]))
positionalParameters: [setterParameter],
returnType: const VoidType()))
]))));
}
// Call `Object.defineProperty` to define the export name with the
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -466,8 +466,7 @@ class JsUtilOptimizer extends Transformer {
invocation = _lowerCallMethod(node, shouldTrustType: false);
} else if (target == _callConstructorTarget) {
invocation = _lowerCallConstructor(node);
} else if (target.isExternal &&
!JsInteropChecks.isAllowedCustomStaticInteropImplementation(target)) {
} else if (target.isExternal && !JsInteropChecks.isPatchedMember(target)) {
final builder = _externalInvocationBuilders.putIfAbsent(
target, () => _getExternalInvocationBuilder(target));
if (builder != null) invocation = builder(node.arguments, node);
Expand Down
27 changes: 11 additions & 16 deletions pkg/analysis_server/benchmark/perf/memory_tests.dart
Original file line number Diff line number Diff line change
Expand Up @@ -169,27 +169,22 @@ class LspAnalysisServerBenchmarkTest extends AbstractBenchmarkTest

@override
Future<void> setUp(String dartSdkPath, List<String> roots) async {
// Use some reasonable default client capabilities that will activate
// features that will exercise more code that benchmarks should measure
// (such as applyEdit to allow suggestion sets results to be merged in).
setDocumentChangesSupport();
setApplyEditSupport();
setWorkDoneProgressSupport();
setCompletionItemSnippetSupport();
setCompletionItemKinds(
LspClientCapabilities.defaultSupportedCompletionKinds.toList());

_test.dartSdkPath = dartSdkPath;
_test.instrumentationService = InstrumentationLogAdapter(_logger);
await _test.setUp();
_test.projectFolderPath = roots.single;
_test.projectFolderUri = Uri.file(_test.projectFolderPath);
// Use some reasonable default client capabilities that will activate
// features that will exercise more code that benchmarks should measure
// (such as applyEdit to allow suggestion sets results to be merged in).
await _test.initialize(
textDocumentCapabilities: withCompletionItemSnippetSupport(
withCompletionItemKinds(
emptyTextDocumentClientCapabilities,
LspClientCapabilities.defaultSupportedCompletionKinds.toList(),
),
),
workspaceCapabilities: withDocumentChangesSupport(
withApplyEditSupport(emptyWorkspaceClientCapabilities),
),
windowCapabilities:
withWorkDoneProgressSupport(emptyWindowClientCapabilities),
);
await _test.initialize();
}

@override
Expand Down
2 changes: 1 addition & 1 deletion pkg/analysis_server/lib/src/analysis_server.dart
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@ import 'package:analysis_server/src/lsp/client_configuration.dart';
import 'package:analysis_server/src/plugin/notification_manager.dart';
import 'package:analysis_server/src/plugin/plugin_manager.dart';
import 'package:analysis_server/src/plugin/plugin_watcher.dart';
import 'package:analysis_server/src/protocol_server.dart' as server;
import 'package:analysis_server/src/protocol_server.dart' as legacy
show MessageType;
import 'package:analysis_server/src/protocol_server.dart' as server;
import 'package:analysis_server/src/server/crash_reporting_attachments.dart';
import 'package:analysis_server/src/server/diagnostic_server.dart';
import 'package:analysis_server/src/server/performance.dart';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ import 'package:analysis_server/src/lsp/mapping.dart';
import 'package:analysis_server/src/lsp/registration/feature_registration.dart';
import 'package:analyzer/dart/ast/ast.dart';
import 'package:analyzer/dart/ast/syntactic_entity.dart';
import 'package:analyzer/dart/element/element.dart';
import 'package:analyzer/dart/element/element.dart' as analyzer;
import 'package:analyzer/dart/element/element.dart';
import 'package:analyzer/dart/element/type.dart';
import 'package:analyzer/source/line_info.dart';
import 'package:analyzer/src/dart/ast/extensions.dart';
Expand Down
2 changes: 1 addition & 1 deletion pkg/analysis_server/lib/src/lsp/mapping.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
// 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.

import 'package:analysis_server/lsp_protocol/protocol.dart' hide Declaration;
import 'package:analysis_server/lsp_protocol/protocol.dart' as lsp;
import 'package:analysis_server/lsp_protocol/protocol.dart' hide Declaration;
import 'package:analysis_server/src/collections.dart';
import 'package:analysis_server/src/computer/computer_hover.dart';
import 'package:analysis_server/src/lsp/client_capabilities.dart';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ import 'dart:collection';

import 'package:_fe_analyzer_shared/src/base/syntactic_entity.dart';
import 'package:analysis_server/src/computer/computer_hover.dart';
import 'package:analysis_server/src/protocol_server.dart' as protocol;
import 'package:analysis_server/src/protocol_server.dart'
hide Element, ElementKind;
import 'package:analysis_server/src/protocol_server.dart' as protocol;
import 'package:analysis_server/src/provisional/completion/dart/completion_dart.dart';
import 'package:analysis_server/src/services/completion/dart/completion_manager.dart';
import 'package:analysis_server/src/services/completion/dart/dart_completion_suggestion.dart';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ import 'package:analyzer/dart/analysis/results.dart';
import 'package:analyzer/dart/ast/ast.dart';
import 'package:analyzer/dart/ast/token.dart';
import 'package:analyzer/dart/element/element.dart';
import 'package:analyzer/error/error.dart';
import 'package:analyzer/error/error.dart' as engine;
import 'package:analyzer/error/error.dart';
import 'package:analyzer/src/dart/ast/utilities.dart';
import 'package:analyzer/src/dart/error/syntactic_errors.dart';
import 'package:analyzer/src/error/codes.dart';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1803,14 +1803,6 @@ HintCode.CAN_BE_NULL_AFTER_NULL_AWARE:
status: hasFix
HintCode.DEPRECATED_COLON_FOR_DEFAULT_VALUE:
status: hasFix
HintCode.DEPRECATED_EXPORT_USE:
status: needsFix
notes: |-
Low priority, because this is likely not encountered often.
The fix is to look for a non-deprecated way to import the name and to add a
new import for it. It might be possible to remove the old import if all of
the names being imported through it are available through the new import.
HintCode.DEPRECATED_MEMBER_USE:
status: hasFix
HintCode.DEPRECATED_MEMBER_USE_FROM_SAME_PACKAGE:
Expand Down Expand Up @@ -3446,6 +3438,14 @@ WarningCode.DEAD_CODE_CATCH_FOLLOWING_CATCH:
status: hasFix
WarningCode.DEAD_CODE_ON_CATCH_SUBTYPE:
status: hasFix
WarningCode.DEPRECATED_EXPORT_USE:
status: needsFix
notes: |-
Low priority, because this is likely not encountered often.
The fix is to look for a non-deprecated way to import the name and to add a
new import for it. It might be possible to remove the old import if all of
the names being imported through it are available through the new import.
WarningCode.DEPRECATED_EXTENDS_FUNCTION:
status: needsFix
notes: |-
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -169,10 +169,12 @@ class ImportOrganizer {
{
var sb = StringBuffer();
_DirectivePriority? currentPriority;
var previousDirectiveText = '';
for (var directiveInfo in directives) {
if (!hasUnresolvedIdentifierError) {
var directive = directiveInfo.directive;
if (removeUnused && _isUnusedImport(directive)) {
if (removeUnused && _isUnusedImport(directive) ||
(removeUnused && previousDirectiveText == directiveInfo.text)) {
continue;
}
}
Expand All @@ -184,6 +186,7 @@ class ImportOrganizer {
}
sb.write(directiveInfo.text);
sb.write(endOfLine);
previousDirectiveText = directiveInfo.text;
}
directivesCode = sb.toString();
directivesCode = directivesCode.trimRight();
Expand Down Expand Up @@ -253,6 +256,17 @@ class ImportOrganizer {
var previousDirectiveLine =
lineInfo.getLocation(beginToken.previous!.end).lineNumber;
comment = firstComment;
// For first directive, do not attach comment if there is a line break
// between comment and directive.
if (isPseudoLibraryDirective && comment != null) {
var directiveLine = lineInfo.getLocation(beginToken.offset).lineNumber;
if ((directiveLine - 1) ==
lineInfo.getLocation(comment.offset).lineNumber) {
return comment;
} else {
return null;
}
}
while (comment != null &&
previousDirectiveLine ==
lineInfo.getLocation(comment.offset).lineNumber) {
Expand Down Expand Up @@ -334,19 +348,17 @@ class _DirectiveInfo implements Comparable<_DirectiveInfo> {
/// The text excluding comments, documentation and annotations.
final String text;

_DirectiveInfo(
this.directive,
this.priority,
this.uri,
this.offset,
this.end,
this.text,
);
_DirectiveInfo(this.directive, this.priority, this.uri, this.offset, this.end,
this.text);

@override
int compareTo(_DirectiveInfo other) {
if (priority == other.priority) {
return _compareUri(uri, other.uri);
var compare = _compareUri(uri, other.uri);
if (compare != 0) {
return compare;
}
return text.compareTo(other.text);
}
return priority.ordinal - other.priority.ordinal;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@
import 'package:analysis_server/src/services/correction/util.dart';
import 'package:analysis_server/src/services/refactoring/framework/formal_parameter.dart';
import 'package:analysis_server/src/services/refactoring/framework/refactoring_context.dart';
import 'package:analysis_server/src/services/refactoring/framework/write_invocation_arguments.dart'
show ArgumentsTrailingComma;
import 'package:analysis_server/src/services/refactoring/framework/write_invocation_arguments.dart'
as framework;
import 'package:analysis_server/src/services/refactoring/framework/write_invocation_arguments.dart'
show ArgumentsTrailingComma;
import 'package:analysis_server/src/services/search/hierarchy.dart';
import 'package:analysis_server/src/services/search/search_engine.dart';
import 'package:analysis_server/src/utilities/selection.dart';
Expand Down
Loading

0 comments on commit 164b289

Please sign in to comment.