Skip to content

Commit

Permalink
Version 3.6.0-58.0.dev
Browse files Browse the repository at this point in the history
Merge 9440ad9 into dev
  • Loading branch information
Dart CI committed Jul 19, 2024
2 parents 5031922 + 9440ad9 commit 0b5cb8d
Show file tree
Hide file tree
Showing 13 changed files with 1,212 additions and 1,325 deletions.
769 changes: 382 additions & 387 deletions pkg/analysis_server/lib/src/services/correction/fix.dart

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ import 'package:analysis_server/src/services/correction/dart/data_driven.dart';
import 'package:analysis_server/src/services/correction/dart/extend_class_for_mixin.dart';
import 'package:analysis_server/src/services/correction/dart/extract_local_variable.dart';
import 'package:analysis_server/src/services/correction/dart/flutter_remove_widget.dart';
import 'package:analysis_server/src/services/correction/dart/ignore_diagnostic.dart';
import 'package:analysis_server/src/services/correction/dart/import_library.dart';
import 'package:analysis_server/src/services/correction/dart/inline_invocation.dart';
import 'package:analysis_server/src/services/correction/dart/inline_typedef.dart';
Expand Down Expand Up @@ -1833,6 +1834,11 @@ void registerBuiltInProducers() {
FixProcessor.nonLintMultiProducerMap.addAll(_builtInNonLintMultiProducers);
FixProcessor.nonLintProducerMap.addAll(_builtInNonLintProducers);
FixProcessor.parseLintProducerMap.addAll(_builtInParseLintProducers);
FixProcessor.ignoreProducerGenerators.addAll([
IgnoreDiagnosticOnLine.new,
IgnoreDiagnosticInFile.new,
IgnoreDiagnosticInAnalysisOptionsFile.new,
]);
}

/// Computer for Dart "fix all in file" fixes.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
// BSD-style license that can be found in the LICENSE file.

import 'package:analysis_server/src/services/correction/bulk_fix_processor.dart';
import 'package:analysis_server/src/services/correction/dart/ignore_diagnostic.dart';
import 'package:analysis_server/src/services/linter/lint_names.dart';
import 'package:analysis_server_plugin/edit/dart/correction_producer.dart';
import 'package:analysis_server_plugin/edit/fix/dart_fix_context.dart';
Expand Down Expand Up @@ -63,6 +62,10 @@ class FixProcessor {
/// parsed results.
static final Map<String, List<ProducerGenerator>> parseLintProducerMap = {};

/// A list of generators that are used to create correction producers that
/// produce corrections that ignore diagnostics locally.
static final List<ProducerGenerator> ignoreProducerGenerators = [];

final DartFixContext _fixContext;

final List<Fix> fixes = <Fix>[];
Expand Down Expand Up @@ -152,12 +155,7 @@ class FixProcessor {
if (errorCode is LintCode ||
errorCode is HintCode ||
errorCode is WarningCode) {
var generators = [
IgnoreDiagnosticOnLine.new,
IgnoreDiagnosticInFile.new,
IgnoreDiagnosticInAnalysisOptionsFile.new,
];
for (var generator in generators) {
for (var generator in ignoreProducerGenerators) {
await compute(generator(context: context));
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
// BSD-style license that can be found in the LICENSE file.

import 'package:analysis_server/src/services/correction/bulk_fix_processor.dart';
import 'package:analysis_server/src/services/correction/fix.dart';
import 'package:analysis_server/src/services/correction/fix_internal.dart';
import 'package:analysis_server_plugin/edit/dart/dart_fix_kind_priority.dart';
import 'package:analysis_server_plugin/edit/fix/dart_fix_context.dart';
import 'package:analysis_server_plugin/edit/fix/fix.dart';
import 'package:analysis_server_plugin/src/correction/change_workspace.dart';
Expand Down Expand Up @@ -588,5 +588,5 @@ extension FixExtension on Fix {

extension FixKindExtension on FixKind {
// TODO(pq): temporary
bool canBeAppliedTogether() => priority == DartFixKindPriority.IN_FILE;
bool canBeAppliedTogether() => priority == DartFixKindPriority.inFile;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
// 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.

abstract final class DartFixKindPriority {
static const int standard = 50;
static const int inFile = 40;
static const int ignore = 30;
}
2 changes: 1 addition & 1 deletion pkg/dev_compiler/lib/src/compiler/js_metalet.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
// 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;
import 'js_utils.dart' show YieldFinder;

/// A synthetic `let*` node, similar to that found in Scheme.
///
Expand Down
100 changes: 100 additions & 0 deletions pkg/dev_compiler/lib/src/compiler/js_utils.dart
Original file line number Diff line number Diff line change
Expand Up @@ -72,3 +72,103 @@ Expression createRtiUniverse() {

return ObjectInitializer(universeFields);
}

/// Whether a variable with [name] is referenced in the [node].
bool variableIsReferenced(String name, Node node) {
var finder = _IdentifierFinder.instance(name);
node.accept(finder);
return finder.found;
}

class _IdentifierFinder extends BaseVisitorVoid {
String nameToFind;
bool found = false;

_IdentifierFinder(this.nameToFind);

static final _instance = _IdentifierFinder('');

factory _IdentifierFinder.instance(String nameToFind) => _instance
..nameToFind = nameToFind
..found = false;

@override
void visitIdentifier(node) {
if (node.name == nameToFind) found = true;
}

@override
void visitNode(node) {
if (!found) super.visitNode(node);
}
}

class YieldFinder extends BaseVisitorVoid {
bool hasYield = false;
bool hasThis = false;
bool _nestedFunction = false;

@override
void visitThis(This node) {
hasThis = true;
}

@override
void visitFunctionExpression(FunctionExpression node) {
var savedNested = _nestedFunction;
_nestedFunction = true;
super.visitFunctionExpression(node);
_nestedFunction = savedNested;
}

@override
void visitYield(Yield node) {
if (!_nestedFunction) hasYield = true;
super.visitYield(node);
}

@override
void visitNode(Node node) {
if (hasYield && hasThis) return; // found both, nothing more to do.
super.visitNode(node);
}
}

/// Given the function [fn], returns a function declaration statement, binding
/// `this` and `super` if necessary (using an arrow function).
Statement toBoundFunctionStatement(Fun fn, Identifier name) {
if (usesThisOrSuper(fn)) {
return js.statement('const # = (#) => {#}', [name, fn.params, fn.body]);
} else {
return FunctionDeclaration(name, fn);
}
}

/// Returns whether [node] uses `this` or `super`.
bool usesThisOrSuper(Expression node) {
var finder = _ThisOrSuperFinder.instance;
finder.found = false;
node.accept(finder);
return finder.found;
}

class _ThisOrSuperFinder extends BaseVisitorVoid {
bool found = false;

static final instance = _ThisOrSuperFinder();

@override
void visitThis(This node) {
found = true;
}

@override
void visitSuper(Super node) {
found = true;
}

@override
void visitNode(Node node) {
if (!found) super.visitNode(node);
}
}
4 changes: 2 additions & 2 deletions pkg/dev_compiler/lib/src/compiler/module_builder.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ import 'package:args/args.dart' show ArgParser, ArgResults;
import 'package:path/path.dart' as p;

import '../js_ast/js_ast.dart';
import '../kernel/compiler.dart';
import 'js_names.dart';
import 'shared_compiler.dart';

/// The module format to emit.
enum ModuleFormat {
Expand Down Expand Up @@ -294,7 +294,7 @@ class DdcModuleBuilder extends _ModuleBuilder {
js.commentExpression(
'Imports', ArrayInitializer(importNames, multiline: true)),
resultModule,
SharedCompiler.metricsLocationID
ProgramCompiler.metricsLocationID
]);
return Program(<ModuleItem>[...module.header, moduleDef]);
}
Expand Down
Loading

0 comments on commit 0b5cb8d

Please sign in to comment.