Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(119)

Unified Diff: lib/src/chunk_builder.dart

Issue 1183633004: Harden named arguments if a hard split occurs in the positional ones. (Closed) Base URL: https://github.com/dart-lang/dart_style.git@master
Patch Set: Update changelog. Created 5 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « CHANGELOG.md ('k') | test/comments/expressions.stmt » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: lib/src/chunk_builder.dart
diff --git a/lib/src/chunk_builder.dart b/lib/src/chunk_builder.dart
index 843fcb3c5591a46e12b458b7fc0a2e6814b0c918..f8f354f650286cc2dd3291af1f9a5188a38a7bb0 100644
--- a/lib/src/chunk_builder.dart
+++ b/lib/src/chunk_builder.dart
@@ -47,6 +47,17 @@ class ChunkBuilder {
/// ended.
final _rules = <Rule>[];
+ /// The set of rules known to contain hard splits that will in turn force
+ /// these rules to harden.
+ ///
+ /// This is accumulated lazily while chunks are being built. Then, once they
+ /// are all done, the rules are all hardened. We do this later because some
+ /// rules may not have all of their constraints fully wired up until after
+ /// the hard split appears. For example, a hard split in a positional
+ /// argument list needs to force the named arguments to split too, but we
+ /// don't create that rule until after the positional arguments are done.
+ final _rulesToHarden = new Set<Rule>();
+
/// The list of rules that are waiting until the next whitespace has been
/// written before they start.
final _lazyRules = <Rule>[];
@@ -733,6 +744,12 @@ class ChunkBuilder {
/// Marks ranges of chunks that can be line split independently to keep the
/// batches we send to [LineSplitter] small.
void _divideChunks() {
+ // Harden all of the rules that we know get forced by containing hard
+ // splits, along with all of the other rules they constrain.
+ for (var rule in _rulesToHarden) {
+ _hardenRule(rule);
+ }
+
// For each independent set of chunks, see if there are any rules in them
// that we want to preemptively harden. This is basically to send smaller
// batches of chunks to LineSplitter in cases where the code is deeply
@@ -855,7 +872,7 @@ class ChunkBuilder {
// Start with the innermost rule. This will traverse the other rules it
// constrains.
- _hardenRule(_rules.last);
+ _rulesToHarden.add(_rules.last);
}
/// Replaces [rule] with a hard split.
« no previous file with comments | « CHANGELOG.md ('k') | test/comments/expressions.stmt » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698