Skip to content

Commit

Permalink
Version 3.6.0-37.0.dev
Browse files Browse the repository at this point in the history
Merge 9dd8b66 into dev
  • Loading branch information
Dart CI committed Jul 12, 2024
2 parents b44d99e + 9dd8b66 commit 8a6b9d4
Show file tree
Hide file tree
Showing 41 changed files with 4,885 additions and 832 deletions.
2 changes: 1 addition & 1 deletion DEPS
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ vars = {
"material_color_utilities_rev": "799b6ba2f3f1c28c67cc7e0b4f18e0c7d7f3c03e",
"mime_rev": "11fec7d6df509a4efd554051cc27e3bf82df9c96",
"mockito_rev": "eb4d1daa20c105c94ac29689c1975f0850fa18f2",
"native_rev": "bc0a10865b5b7b0c5444581b77728fc20bffedb8", # mosum@ and dacoharkes@ are rolling breaking changes manually while the assets features are in experimental.
"native_rev": "b01a3f3ef5e3a219fefb182d4cfc41d2895f32ca", # mosum@ and dacoharkes@ are rolling breaking changes manually while the assets features are in experimental.
"package_config_rev": "f0b72567d85b827aa0f53991fe8a4a8bf36eb479",
"path_rev": "e969f42ed112dd702a9453beb9df6c12ae2d3805",
"pool_rev": "924fb04353cec915d927f9f1aed88e2eda92b98a",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -538,8 +538,14 @@ class BulkFixProcessor {
errorListener,
StringSource(parsedUnit.content, null),
);
allUnits.add(LintRuleUnitContext(
parsedUnit.content, parsedUnit.unit, errorReporter));
allUnits.add(
LintRuleUnitContext(
file: parsedUnit.file,
content: parsedUnit.content,
errorReporter: errorReporter,
unit: parsedUnit.unit,
),
);
}
for (var linterUnit in allUnits) {
_computeParsedResultLint(linterUnit, allUnits);
Expand Down
7 changes: 4 additions & 3 deletions pkg/analyzer/lib/src/dart/analysis/library_analyzer.dart
Original file line number Diff line number Diff line change
Expand Up @@ -353,9 +353,10 @@ class LibraryAnalyzer {
WorkspacePackage? workspacePackage;
for (var unitAnalysis in _libraryUnits.values) {
var linterContextUnit = LintRuleUnitContext(
unitAnalysis.file.content,
unitAnalysis.unit,
unitAnalysis.errorReporter,
file: unitAnalysis.file.resource,
content: unitAnalysis.file.content,
unit: unitAnalysis.unit,
errorReporter: unitAnalysis.errorReporter,
);
analysesToContextUnits[unitAnalysis] = linterContextUnit;
if (unitAnalysis.unit.declaredElement == definingUnit) {
Expand Down
29 changes: 25 additions & 4 deletions pkg/analyzer/lib/src/lint/linter.dart
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import 'package:analyzer/dart/element/type_system.dart';
import 'package:analyzer/diagnostic/diagnostic.dart';
import 'package:analyzer/error/error.dart';
import 'package:analyzer/error/listener.dart';
import 'package:analyzer/file_system/file_system.dart';
import 'package:analyzer/src/dart/ast/ast.dart';
import 'package:analyzer/src/dart/ast/token.dart';
import 'package:analyzer/src/dart/constant/compute.dart';
Expand Down Expand Up @@ -107,6 +108,9 @@ abstract class LinterContext {
/// package-implementation directory, 'lib/src'.
bool get isInLibDir;

/// Whether the [definingUnit] is in a [package]'s "test" directory.
bool get isInTestDirectory;

LibraryElement? get libraryElement;

/// The package in which the library being analyzed lives, or `null` if it
Expand Down Expand Up @@ -142,6 +146,9 @@ final class LinterContextWithParsedResults implements LinterContext {
bool get isInLibDir => LinterContext._isInLibDir(
definingUnit.unit.declaredElement?.source.fullName, package);

@override
bool get isInTestDirectory => false;

@override
LibraryElement get libraryElement => throw UnsupportedError(
'LinterContext with parsed results does not include a LibraryElement');
Expand All @@ -168,6 +175,7 @@ final class LinterContextWithResolvedResults implements LinterContext {

@override
final WorkspacePackage? package;

@override
final TypeProvider typeProvider;

Expand All @@ -190,6 +198,15 @@ final class LinterContextWithResolvedResults implements LinterContext {
bool get isInLibDir => LinterContext._isInLibDir(
definingUnit.unit.declaredElement?.source.fullName, package);

@override
bool get isInTestDirectory {
if (package case var package?) {
var file = definingUnit.file;
return package.isInTestDirectory(file);
}
return false;
}

@override
LibraryElement get libraryElement =>
definingUnit.unit.declaredElement!.library;
Expand Down Expand Up @@ -355,13 +372,17 @@ abstract class LintRule {
/// Provides access to information needed by lint rules that is not available
/// from AST nodes or the element model.
class LintRuleUnitContext {
final File file;
final String content;

final CompilationUnit unit;

final ErrorReporter errorReporter;
final CompilationUnit unit;

LintRuleUnitContext(this.content, this.unit, this.errorReporter);
LintRuleUnitContext({
required this.file,
required this.content,
required this.errorReporter,
required this.unit,
});
}

/// An error listener that only records whether any constant related errors have
Expand Down
7 changes: 7 additions & 0 deletions pkg/analyzer/lib/src/workspace/blaze.dart
Original file line number Diff line number Diff line change
Expand Up @@ -600,6 +600,13 @@ class BlazeWorkspacePackage extends WorkspacePackage {
return workspace.findPackageFor(path)?.root == root;
}

@override
bool isInTestDirectory(File file) {
var resourceProvider = workspace.provider;
var packageRoot = resourceProvider.getFolder(root);
return packageRoot.getChildAssumingFolder('test').contains(file.path);
}

@override
// TODO(brianwilkerson): Implement this by looking in the BUILD file for 'deps'
// lists.
Expand Down
2 changes: 1 addition & 1 deletion pkg/analyzer/lib/src/workspace/pub.dart
Original file line number Diff line number Diff line change
Expand Up @@ -458,7 +458,7 @@ class PubPackage extends WorkspacePackage {
return false;
}

/// Whether [file] is in the `test` directory of this package.
@override
bool isInTestDirectory(File file) {
var resourceProvider = workspace.provider;
var packageRoot = resourceProvider.getFolder(root);
Expand Down
6 changes: 6 additions & 0 deletions pkg/analyzer/lib/src/workspace/workspace.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// 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:analyzer/file_system/file_system.dart';
import 'package:analyzer/source/source.dart';
import 'package:analyzer/src/context/packages.dart';
import 'package:analyzer/src/generated/sdk.dart';
Expand Down Expand Up @@ -107,6 +108,11 @@ abstract class WorkspacePackage {
}
}

/// Whether [file] is in a "test" directory of this package.
bool isInTestDirectory(File file) {
return false;
}

/// Return a map from the names of packages to the absolute and normalized
/// path of the root of those packages for all of the packages that could
/// validly be imported by the library with the given [libraryPath].
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,12 @@ abstract class AbstractLinterContextTest extends PubPackageResolutionTest {
RecordingErrorListener(),
StringSource(result.content, null),
);
var contextUnit =
LintRuleUnitContext(result.content, result.unit, errorReporter);
var contextUnit = LintRuleUnitContext(
file: result.file,
content: result.content,
errorReporter: errorReporter,
unit: result.unit,
);

var libraryElement = result.libraryElement;
var analysisContext = libraryElement.session.analysisContext;
Expand Down
18 changes: 18 additions & 0 deletions pkg/analyzer/test/src/workspace/blaze_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -771,6 +771,24 @@ class BlazeWorkspacePackageTest with ResourceProviderMixin {
expect(package?.workspace, equals(workspace));
}

test_isInTestDirectory() {
_setUpPackage();

expect(
package!.isInTestDirectory(
getFile('/ws/some/code/lib/a.dart'),
),
isFalse,
);

expect(
package!.isInTestDirectory(
getFile('/ws/some/code/test/a.dart'),
),
isTrue,
);
}

void test_packagesAvailableTo() {
_setUpPackage();
var path = convertPath('/ws/some/code/lib/code.dart');
Expand Down
2 changes: 1 addition & 1 deletion pkg/compiler/lib/src/js/rewrite_async.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ library rewrite_async;
import 'dart:collection';
import 'dart:math' show max;

import 'package:js_runtime/synced/async_status_codes.dart' as status_codes;
import 'package:js_shared/synced/async_status_codes.dart' as status_codes;

import '../common.dart';
import '../util/util.dart' show Pair;
Expand Down
21 changes: 1 addition & 20 deletions pkg/dev_compiler/lib/src/compiler/js_metalet.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
// TODO(jmesserly): import from its own package
import '../js_ast/js_ast.dart';
import 'js_names.dart' show TemporaryId;
import 'shared_compiler.dart' show YieldFinder;

/// A synthetic `let*` node, similar to that found in Scheme.
///
Expand Down Expand Up @@ -134,15 +133,6 @@ class MetaLet extends Expression {
return _finishStatement(statements);
}

@override
Block toYieldStatement({bool star = false}) {
var statements = body
.map((e) =>
e == body.last ? e.toYieldStatement(star: star) : e.toStatement())
.toList();
return _finishStatement(statements);
}

@override
T accept<T>(NodeVisitor<T> visitor) {
// TODO(jmesserly): we special case visitors from js_ast.Template, because
Expand Down Expand Up @@ -187,16 +177,7 @@ class MetaLet extends Expression {
}

Expression _toInvokedFunction(Block block) {
var finder = YieldFinder();
block.accept(finder);
if (!finder.hasYield) {
return Call(ArrowFun([], block), []);
}
// If we have a yield, it's more tricky. We'll create a `function*`, which
// we `yield*` to immediately invoke. We also may need to bind this:
Expression fn = Fun([], block, isGenerator: true);
if (finder.hasThis) fn = js.call('#.bind(this)', fn);
return Yield(Call(fn, []), star: true);
return Call(ArrowFun([], block), []);
}

Block _finishStatement(List<Statement> statements) {
Expand Down
Loading

0 comments on commit 8a6b9d4

Please sign in to comment.