Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.

Commit 406d207

Browse files
author
Dart CI
committed
Version 2.14.0-370.0.dev
Merge commit 'b13dc22338bee08f38029de3afb5c21a2569bd58' into 'dev'
2 parents 2e22cdf + b13dc22 commit 406d207

File tree

32 files changed

+404
-153
lines changed

32 files changed

+404
-153
lines changed

pkg/_fe_analyzer_shared/lib/src/messages/codes_generated.dart

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6237,14 +6237,14 @@ const MessageCode messageJsInteropEnclosingClassJSAnnotationContext =
62376237
message: r"""This is the enclosing class.""");
62386238

62396239
// DO NOT EDIT. THIS FILE IS GENERATED. SEE TOP OF FILE.
6240-
const Code<Null> codeJsInteropExternalExtensionMemberNotOnJSClass =
6241-
messageJsInteropExternalExtensionMemberNotOnJSClass;
6240+
const Code<Null> codeJsInteropExternalExtensionMemberOnTypeInvalid =
6241+
messageJsInteropExternalExtensionMemberOnTypeInvalid;
62426242

62436243
// DO NOT EDIT. THIS FILE IS GENERATED. SEE TOP OF FILE.
6244-
const MessageCode messageJsInteropExternalExtensionMemberNotOnJSClass =
6245-
const MessageCode("JsInteropExternalExtensionMemberNotOnJSClass",
6244+
const MessageCode messageJsInteropExternalExtensionMemberOnTypeInvalid =
6245+
const MessageCode("JsInteropExternalExtensionMemberOnTypeInvalid",
62466246
message:
6247-
r"""JS interop class required for 'external' extension members.""",
6247+
r"""JS interop or Native class required for 'external' extension members.""",
62486248
tip:
62496249
r"""Try adding a JS interop annotation to the on type class of the extension.""");
62506250

pkg/_js_interop_checks/lib/js_interop_checks.dart

Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import 'package:_fe_analyzer_shared/src/messages/codes.dart'
1212
messageJsInteropAnonymousFactoryPositionalParameters,
1313
messageJsInteropEnclosingClassJSAnnotation,
1414
messageJsInteropEnclosingClassJSAnnotationContext,
15-
messageJsInteropExternalExtensionMemberNotOnJSClass,
15+
messageJsInteropExternalExtensionMemberOnTypeInvalid,
1616
messageJsInteropExternalMemberNotJSAnnotated,
1717
messageJsInteropIndexNotSupported,
1818
messageJsInteropNamedParameters,
@@ -282,13 +282,14 @@ class JsInteropChecks extends RecursiveVisitor {
282282
/// [member] is `external` and not an allowed `external` usage.
283283
void _checkDisallowedExternal(Member member) {
284284
if (member.isExternal) {
285-
// TODO(rileyporter): Allow extension members on some Native classes.
286285
if (member.isExtensionMember) {
287-
_diagnosticsReporter.report(
288-
messageJsInteropExternalExtensionMemberNotOnJSClass,
289-
member.fileOffset,
290-
member.name.text.length,
291-
member.fileUri);
286+
if (!_isNativeExtensionMember(member)) {
287+
_diagnosticsReporter.report(
288+
messageJsInteropExternalExtensionMemberOnTypeInvalid,
289+
member.fileOffset,
290+
member.name.text.length,
291+
member.fileUri);
292+
}
292293
} else if (!hasJSInteropAnnotation(member) &&
293294
!_isAllowedExternalUsage(member)) {
294295
// Member could be JS annotated and not considered a JS interop member
@@ -338,6 +339,18 @@ class JsInteropChecks extends RecursiveVisitor {
338339
/// Returns whether given extension [member] is in an extension that is on a
339340
/// JS interop class.
340341
bool _isJSExtensionMember(Member member) {
342+
return _checkExtensionMember(member, hasJSInteropAnnotation);
343+
}
344+
345+
/// Returns whether given extension [member] is in an extension on a Native
346+
/// class.
347+
bool _isNativeExtensionMember(Member member) {
348+
return _checkExtensionMember(member, _nativeClasses.containsValue);
349+
}
350+
351+
/// Returns whether given extension [member] is on a class that passses the
352+
/// given [validateExtensionClass].
353+
bool _checkExtensionMember(Member member, Function validateExtensionClass) {
341354
assert(member.isExtensionMember);
342355
if (_libraryExtensionsIndex == null) {
343356
_libraryExtensionsIndex = {};
@@ -347,6 +360,6 @@ class JsInteropChecks extends RecursiveVisitor {
347360
}
348361

349362
var onType = _libraryExtensionsIndex![member.reference]!.onType;
350-
return onType is InterfaceType && hasJSInteropAnnotation(onType.classNode);
363+
return onType is InterfaceType && validateExtensionClass(onType.classNode);
351364
}
352365
}

pkg/analysis_server/lib/src/services/completion/yaml/analysis_options_generator.dart

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ class AnalysisOptionsGenerator extends YamlCompletionGenerator {
3030
AnalyzerOptions.chromeOsManifestChecks: EmptyProducer(),
3131
}),
3232
AnalyzerOptions.plugins: EmptyProducer(),
33+
AnalyzerOptions.propagateLinterExceptions: EmptyProducer(),
3334
AnalyzerOptions.strong_mode: MapProducer({
3435
AnalyzerOptions.declarationCasts: EmptyProducer(),
3536
AnalyzerOptions.implicitCasts: EmptyProducer(),

pkg/analyzer/lib/src/dart/analysis/library_analyzer.dart

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import 'package:analyzer/src/context/source.dart';
1212
import 'package:analyzer/src/dart/analysis/file_state.dart';
1313
import 'package:analyzer/src/dart/analysis/testing_data.dart';
1414
import 'package:analyzer/src/dart/ast/ast.dart';
15+
import 'package:analyzer/src/dart/ast/utilities.dart';
1516
import 'package:analyzer/src/dart/constant/compute.dart';
1617
import 'package:analyzer/src/dart/constant/constant_verifier.dart';
1718
import 'package:analyzer/src/dart/constant/evaluation.dart';
@@ -351,7 +352,10 @@ class LibraryAnalyzer {
351352
}
352353

353354
// Run lints that handle specific node types.
354-
unit.accept(LinterVisitor(nodeRegistry));
355+
unit.accept(LinterVisitor(
356+
nodeRegistry,
357+
LinterExceptionHandler(_analysisOptions.propagateLinterExceptions)
358+
.logException));
355359
}
356360

357361
void _computeVerifyErrors(FileState file, CompilationUnit unit) {

pkg/analyzer/lib/src/dart/ast/utilities.dart

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1306,6 +1306,12 @@ class DeferredLibraryReferenceDetector extends RecursiveAstVisitor<void> {
13061306
///
13071307
/// Clients may not extend, implement or mix-in this class.
13081308
class LinterExceptionHandler {
1309+
/// Indicates whether linter exceptions should be propagated to the caller (by
1310+
/// re-throwing them)
1311+
final bool propagateLinterExceptions;
1312+
1313+
LinterExceptionHandler(this.propagateLinterExceptions);
1314+
13091315
/// A method that can be passed to the `LinterVisitor` constructor to handle
13101316
/// exceptions that occur during linting.
13111317
void logException(
@@ -1326,6 +1332,9 @@ class LinterExceptionHandler {
13261332
// TODO(39284): should this exception be silent?
13271333
AnalysisEngine.instance.instrumentationService.logException(
13281334
SilentException(buffer.toString(), exception, stackTrace));
1335+
if (propagateLinterExceptions) {
1336+
throw exception;
1337+
}
13291338
}
13301339
}
13311340

pkg/analyzer/lib/src/dart/micro/library_analyzer.dart

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -348,7 +348,10 @@ class LibraryAnalyzer {
348348
}
349349

350350
// Run lints that handle specific node types.
351-
unit.accept(LinterVisitor(nodeRegistry));
351+
unit.accept(LinterVisitor(
352+
nodeRegistry,
353+
LinterExceptionHandler(_analysisOptions.propagateLinterExceptions)
354+
.logException));
352355
}
353356

354357
void _computeVerifyErrors(FileState file, CompilationUnit unit) {

pkg/analyzer/lib/src/generated/engine.dart

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -281,6 +281,10 @@ class AnalysisOptionsImpl implements AnalysisOptions {
281281
/// This option is experimental and subject to change.
282282
bool implicitDynamic = true;
283283

284+
/// Indicates whether linter exceptions should be propagated to the caller (by
285+
/// re-throwing them)
286+
bool propagateLinterExceptions = false;
287+
284288
/// A flag indicating whether inference failures are allowed, off by default.
285289
///
286290
/// This option is experimental and subject to change.
@@ -319,6 +323,7 @@ class AnalysisOptionsImpl implements AnalysisOptions {
319323
if (options is AnalysisOptionsImpl) {
320324
implicitCasts = options.implicitCasts;
321325
implicitDynamic = options.implicitDynamic;
326+
propagateLinterExceptions = options.propagateLinterExceptions;
322327
strictInference = options.strictInference;
323328
strictRawTypes = options.strictRawTypes;
324329
}
@@ -382,6 +387,7 @@ class AnalysisOptionsImpl implements AnalysisOptions {
382387
// Append boolean flags.
383388
buffer.addBool(implicitCasts);
384389
buffer.addBool(implicitDynamic);
390+
buffer.addBool(propagateLinterExceptions);
385391
buffer.addBool(strictInference);
386392
buffer.addBool(strictRawTypes);
387393
buffer.addBool(useFastaParser);

pkg/analyzer/lib/src/lint/linter_visitor.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ class LinterVisitor extends RecursiveAstVisitor<void> {
1919

2020
LinterVisitor(this.registry, [LintRuleExceptionHandler? exceptionHandler])
2121
: exceptionHandler =
22-
exceptionHandler ?? LinterExceptionHandler().logException;
22+
exceptionHandler ?? LinterExceptionHandler(true).logException;
2323

2424
@override
2525
void visitAdjacentStrings(AdjacentStrings node) {

pkg/analyzer/lib/src/task/options.dart

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,8 @@ class AnalyzerOptions {
151151
/// Ways to say `include`.
152152
static const List<String> includeSynonyms = ['include', 'true'];
153153

154+
static const String propagateLinterExceptions = 'propagate-linter-exceptions';
155+
154156
/// Ways to say `true` or `false`.
155157
static const List<String> trueOrFalse = ['true', 'false'];
156158

@@ -163,6 +165,7 @@ class AnalyzerOptions {
163165
language,
164166
optionalChecks,
165167
plugins,
168+
propagateLinterExceptions,
166169
strong_mode,
167170
];
168171

@@ -805,6 +808,9 @@ class _OptionsProcessor {
805808
if (feature == AnalyzerOptions.implicitDynamic) {
806809
options.implicitDynamic = boolValue;
807810
}
811+
if (feature == AnalyzerOptions.propagateLinterExceptions) {
812+
options.propagateLinterExceptions = boolValue;
813+
}
808814
}
809815
}
810816

pkg/analyzer/test/src/dart/analysis/context_builder_test.dart

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -236,6 +236,8 @@ environment:
236236
);
237237
expect(actual.implicitCasts, expected.implicitCasts);
238238
expect(actual.implicitDynamic, expected.implicitDynamic);
239+
expect(
240+
actual.propagateLinterExceptions, expected.propagateLinterExceptions);
239241
expect(actual.strictInference, expected.strictInference);
240242
expect(actual.strictRawTypes, expected.strictRawTypes);
241243
}

0 commit comments

Comments
 (0)