Skip to content

Commit

Permalink
Revert "Apply automated fixes to Dart source code."
Browse files Browse the repository at this point in the history
This reverts commit 4ffc441.
  • Loading branch information
GZGavinZhao committed May 24, 2022
1 parent 4ffc441 commit ad4d56e
Show file tree
Hide file tree
Showing 34 changed files with 178 additions and 130 deletions.
2 changes: 1 addition & 1 deletion _tests/lib/matchers.dart
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class _HasTextContent extends Matcher {

@override
Description describe(Description description) =>
description.add(expectedText);
description.add('$expectedText');

@override
Description describeMismatch(
Expand Down
6 changes: 3 additions & 3 deletions _tests/test/common/directives/for_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -608,7 +608,7 @@ class NgForFirstTest {
@Component(
selector: 'ng-for-last-test',
template: '<div><copy-me *ngFor="let item of items; '
'let isLast=last">{{isLast.toString()}}</copy-me></div>',
'let isLast=last\">{{isLast.toString()}}</copy-me></div>',
directives: [
CopyMe,
NgFor,
Expand All @@ -621,7 +621,7 @@ class NgForLastTest {
@Component(
selector: 'ng-for-even-test',
template: '<div><copy-me *ngFor="let item of items; '
'let isEven=even">{{isEven.toString()}}</copy-me></div>',
'let isEven=even\">{{isEven.toString()}}</copy-me></div>',
directives: [
CopyMe,
NgFor,
Expand Down Expand Up @@ -788,7 +788,7 @@ class ObjectEditorComponent {
}

void mutateItem(int index) {
entities![index] = 'z${entities![index]}';
entities![index] = 'z' + entities![index];
}
}

Expand Down
8 changes: 4 additions & 4 deletions _tests/test/common/pipes/async_pipe_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -52,11 +52,11 @@ void main() {
test('should not dispose of existing subscription when Streams are equal',
() async {
// See https://github.com/angulardart/angular/issues/260
var ctrl = StreamController.broadcast();
expect(pipe.transform(ctrl.stream), isNull);
ctrl.add(message);
var _ctrl = StreamController.broadcast();
expect(pipe.transform(_ctrl.stream), isNull);
_ctrl.add(message);
Timer.run(expectAsync0(() {
expect(pipe.transform(ctrl.stream), isNotNull);
expect(pipe.transform(_ctrl.stream), isNotNull);
}));
});
test('should request a change detection check upon receiving a new value',
Expand Down
9 changes: 4 additions & 5 deletions _tests/test/compiler/ast_template_parser_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,6 @@ void main() {
type: CompileTypeMetadata(moduleUrl: someModuleUrl, name: 'Root'),
metadataType: CompileDirectiveMetadataType.Component);

// ignore: no_leading_underscores_for_local_identifiers
ParseTemplate _parse;

List<TemplateAst> parse(
Expand Down Expand Up @@ -2635,21 +2634,21 @@ CompileDirectiveMetadata createCompileDirectiveMetadata({
}) {
final inputsMap = <String, String>{};
final inputTypeMap = <String, CompileTypeMetadata>{};
for (var input in inputs) {
inputs?.forEach((input) {
final inputParts = input.split(';');
final inputName = inputParts[0];
final bindingParts = splitAtColon(inputName, [inputName, inputName]);
inputsMap[bindingParts[0]] = bindingParts[1];
if (inputParts.length > 1) {
inputTypeMap[bindingParts[0]] = CompileTypeMetadata(name: inputParts[1]);
}
}
});

final outputsMap = <String, String>{};
for (var output in outputs) {
outputs?.forEach((output) {
final bindingParts = splitAtColon(output, [output, output]);
outputsMap[bindingParts[0]] = bindingParts[1];
}
});

return CompileDirectiveMetadata(
type: type,
Expand Down
20 changes: 10 additions & 10 deletions _tests/test/compiler/expression_parser/parser_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,8 @@ void _runTests(ExpressionParser Function() createParser) {
checkAction('1');
});
test('should parse strings', () {
checkAction("'1'", '"1"');
checkAction('"1"');
checkAction("'1'", '\"1\"');
checkAction('\"1\"');
});
test('should require escaping \$ in strings', () {
expectActionError(r"'$100 USD'", _throwsParseException);
Expand Down Expand Up @@ -150,7 +150,7 @@ void _runTests(ExpressionParser Function() createParser) {
test('should only allow identifier or keyword as member names', () {
expectActionError('x.(', _throwsParseException);
expectActionError('x. 1234', _throwsParseException);
expectActionError('x."foo"', _throwsParseException);
expectActionError('x.\"foo\"', _throwsParseException);
});
test('should parse safe field access', () {
checkAction('a?.a');
Expand Down Expand Up @@ -332,15 +332,15 @@ void _runTests(ExpressionParser Function() createParser) {
checkInterpolation('{{ a < b ? a : b }}');
});
test('should parse expression with newline characters', () {
checkInterpolation('''{{ 'foo' +
'bar' +
'baz' }}''', '''{{ "foo" + "bar" + "baz" }}''');
checkInterpolation('''{{ \'foo\' +
\'bar\' +
\'baz\' }}''', '''{{ "foo" + "bar" + "baz" }}''');
});
group('non-comment slashes should parse in', () {
test('single quote strings', () {
checkInterpolation(
"{{ 'http://www.google.com' }}",
'{{ "http://www.google.com" }}',
"{{ \'http://www.google.com\' }}",
'{{ \"http://www.google.com\" }}',
);
});
test('double quote strings', () {
Expand All @@ -367,13 +367,13 @@ void _runTests(ExpressionParser Function() createParser) {
});
test('complex strings', () {
expectInterpolationError(
'''{{"//a'//b`//c`//d'//e" //comment}}''',
'''{{"//a\'//b`//c`//d\'//e" //comment}}''',
_throwsParseException,
);
});
test('nested, unterminated strings', () {
expectInterpolationError(
'''{{ "a'b`" //comment}}''',
'''{{ "a\'b`" //comment}}''',
_throwsParseException,
);
});
Expand Down
2 changes: 1 addition & 1 deletion _tests/test/compiler/expression_parser/unparser.dart
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class Unparser implements AstVisitor<void, String> {
void _,
) {
_visit(ast.receiver);
sb.write(ast.receiver is ImplicitReceiver ? ast.name : '.${ast.name}');
sb.write(ast.receiver is ImplicitReceiver ? '${ast.name}' : '.${ast.name}');
}

@override
Expand Down
8 changes: 4 additions & 4 deletions _tests/test/compiler/output/abstract_emitter_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,16 @@ void main() {
group('AbstractEmitter', () {
group('escapeSingleQuoteString', () {
test('should escape single quotes', () {
expect(escapeSingleQuoteString("'", false), "'\\''");
expect(escapeSingleQuoteString("'", false), "\'\\\'\'");
});
test('should escape backslash', () {
expect(escapeSingleQuoteString('\\', false), "'\\\\'");
expect(escapeSingleQuoteString('\\', false), "\'\\\\\'");
});
test('should escape newlines', () {
expect(escapeSingleQuoteString('\n', false), "'\\n'");
expect(escapeSingleQuoteString('\n', false), "\'\\n\'");
});
test('should escape carriage returns', () {
expect(escapeSingleQuoteString('\r', false), "'\\r'");
expect(escapeSingleQuoteString('\r', false), "\'\\r\'");
});
test('should escape \$', () {
expect(escapeSingleQuoteString('\$', true), "'\\\$'");
Expand Down
2 changes: 1 addition & 1 deletion _tests/test/compiler/selector_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -434,7 +434,7 @@ void main() {
CssSelector.parse('Blink.neon.hotpink[Sweet][Dismissable=false]')[0];
var template = selector.getMatchingElementTemplate();
expect(template,
'<Blink class="neon hotpink" Sweet Dismissable="false"></Blink>');
'<Blink class=\"neon hotpink\" Sweet Dismissable=\"false\"></Blink>');
});
test('should create an element without a tag name', () {
var selector = CssSelector.parse('[fancy]')[0];
Expand Down
26 changes: 13 additions & 13 deletions _tests/test/compiler/style_url_resolver_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,29 +7,29 @@ import 'package:angular_compiler/v1/src/compiler/style_url_resolver.dart'

void main() {
group('extractStyleUrls', () {
test('should not resolve "url()" urls', () {
test('should not resolve \"url()\" urls', () {
var css = '''
.foo {
background-image: url("double.jpg");
background-image: url('simple.jpg');
background-image: url(\'simple.jpg\');
background-image: url(noquote.jpg);
}''';
var resolvedCss = extractStyleUrls('http://ng.io', css).style;
expect(resolvedCss, css);
});
test('should extract "@import" urls', () {
test('should extract \"@import\" urls', () {
var css = '''
@import '1.css';
@import \'1.css\';
@import "2.css";
''';
var styleWithImports = extractStyleUrls('http://ng.io', css);
expect(styleWithImports.style.trim(), '');
expect(styleWithImports.styleUrls,
['http://ng.io/1.css', 'http://ng.io/2.css']);
});
test('should extract "@import url()" urls', () {
test('should extract \"@import url()\" urls', () {
var css = '''
@import url('3.css');
@import url(\'3.css\');
@import url("4.css");
@import url(5.css);
''';
Expand All @@ -38,15 +38,15 @@ void main() {
expect(styleWithImports.styleUrls,
['http://ng.io/3.css', 'http://ng.io/4.css', 'http://ng.io/5.css']);
});
test('should extract "@import urls and keep rules in the same line', () {
var css = '''@import url('some.css');div {color: red};''';
test('should extract \"@import urls and keep rules in the same line', () {
var css = '''@import url(\'some.css\');div {color: red};''';
var styleWithImports = extractStyleUrls('http://ng.io', css);
expect(styleWithImports.style.trim(), 'div {color: red};');
expect(styleWithImports.styleUrls, ['http://ng.io/some.css']);
});
test('should extract media query in "@import"', () {
test('should extract media query in \"@import\"', () {
var css = '''
@import 'print1.css' print;
@import \'print1.css\' print;
@import url(print2.css) print;
''';
var styleWithImports = extractStyleUrls('http://ng.io', css);
Expand All @@ -55,14 +55,14 @@ void main() {
['http://ng.io/print1.css', 'http://ng.io/print2.css']);
});
test('should leave absolute non-package @import urls intact', () {
var css = '''@import url('http://server.com/some.css');''';
var css = '''@import url(\'http://server.com/some.css\');''';
var styleWithImports = extractStyleUrls('http://ng.io', css);
expect(styleWithImports.style.trim(),
'''@import url('http://server.com/some.css');''');
'''@import url(\'http://server.com/some.css\');''');
expect(styleWithImports.styleUrls, []);
});
test('should resolve package @import urls', () {
var css = '''@import url('package:a/b/some.css');''';
var css = '''@import url(\'package:a/b/some.css\');''';
var styleWithImports = extractStyleUrls('http://ng.io', css);
expect(styleWithImports.style.trim(), '''''');
expect(styleWithImports.styleUrls, ['package:a/b/some.css']);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -429,5 +429,22 @@ String iterableChangesAsString({
List<Object> removals = const [],
List<Object> identityChanges = const [],
}) {
return 'collection: ${collection.join(', ')}\nprevious: ${previous.join(', ')}\nadditions: ${additions.join(', ')}\nmoves: ${moves.join(', ')}\nremovals: ${removals.join(', ')}\nidentityChanges: ${identityChanges.join(', ')}\n';
return 'collection: ' +
collection.join(', ') +
'\n' +
'previous: ' +
previous.join(', ') +
'\n' +
'additions: ' +
additions.join(', ') +
'\n' +
'moves: ' +
moves.join(', ') +
'\n' +
'removals: ' +
removals.join(', ') +
'\n' +
'identityChanges: ' +
identityChanges.join(', ') +
'\n';
}
8 changes: 2 additions & 6 deletions _tests/test/core/view/projection_integration_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -48,15 +48,11 @@ void main() {
var fixture = await testBed.create();
expect(fixture.text, '(, B)');
await fixture.update((LightDomChangeTest component) {
for (var d in component.viewports!) {
d.show();
}
component.viewports!.forEach((d) => d.show());
});
expect(fixture.text, '(A1, B)');
await fixture.update((LightDomChangeTest component) {
for (var d in component.viewports!) {
d.hide();
}
component.viewports!.forEach((d) => d.hide());
});
expect(fixture.text, '(, B)');
});
Expand Down
6 changes: 3 additions & 3 deletions _tests/test/core/view/projection_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ class ContainerWithProjectedInterpolationBound {
@Component(
selector: 'simple',
template: 'SIMPLE(<div><ng-content></ng-content></div>'
'<div [tabIndex]="0">XY</div>)',
'<div [tabIndex]=\"0\">XY</div>)',
)
class SimpleComponentWithBinding {}

Expand Down Expand Up @@ -274,7 +274,7 @@ class ManualViewportDirective {

@Component(
selector: 'container-with-style-emu',
template: '<div class="blueStyle"></div>',
template: '<div class=\"blueStyle\"></div>',
styles: ['.blueStyle { color: blue}'],
encapsulation: ViewEncapsulation.Emulated,
directives: [SimpleComponent],
Expand All @@ -283,7 +283,7 @@ class ContainerWithStyleEmulated {}

@Component(
selector: 'container-with-style-not-emu',
template: '<div class="redStyle"></div>',
template: '<div class=\"redStyle\"></div>',
styles: ['.redStyle { color: red}'],
encapsulation: ViewEncapsulation.None,
directives: [SimpleComponent],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -223,23 +223,23 @@ class DefaultIterableDiffer {
}
} else {
index = 0;
for (var item in collection) {
collection.forEach((item) {
var itemTrackBy = _trackByFn(index, item);
if (record == null || !identical(record.trackById, itemTrackBy)) {
if (record == null || !identical(record!.trackById, itemTrackBy)) {
record = _mismatch(record, item, itemTrackBy, index);
mayBeDirty = true;
} else {
if (mayBeDirty) {
// TODO(misko): can we limit this to duplicates only?
record = _verifyReinsertion(record, item, itemTrackBy, index);
record = _verifyReinsertion(record!, item, itemTrackBy, index);
}
if (!identical(record.item, item)) {
_addIdentityChange(record, item);
if (!identical(record!.item, item)) {
_addIdentityChange(record!, item);
}
}
record = record._next;
record = record!._next;
index++;
}
});
_length = index;
}
_truncate(record);
Expand Down Expand Up @@ -583,7 +583,24 @@ class DefaultIterableDiffer {
forEachRemovedItem((record) => removals.add(record));
var identityChanges = <Object>[];
forEachIdentityChange((record) => identityChanges.add(record));
return 'collection: ${list.join(', ')}\nprevious: ${previous.join(', ')}\nadditions: ${additions.join(', ')}\nmoves: ${moves.join(', ')}\nremovals: ${removals.join(', ')}\nidentityChanges: ${identityChanges.join(', ')}\n';
return 'collection: ' +
list.join(', ') +
'\n' +
'previous: ' +
previous.join(', ') +
'\n' +
'additions: ' +
additions.join(', ') +
'\n' +
'moves: ' +
moves.join(', ') +
'\n' +
'removals: ' +
removals.join(', ') +
'\n' +
'identityChanges: ' +
identityChanges.join(', ') +
'\n';
} else {
return super.toString();
}
Expand Down Expand Up @@ -706,7 +723,7 @@ class _DuplicateMap {
/// first or second.
CollectionChangeRecord? get(dynamic trackById, [int? afterIndex]) {
var recordList = _map[trackById];
return recordList?.get(trackById, afterIndex);
return recordList == null ? null : recordList.get(trackById, afterIndex);
}

/// Removes a [CollectionChangeRecord] from the list of duplicates.
Expand Down
Loading

0 comments on commit ad4d56e

Please sign in to comment.