Skip to content
This repository has been archived by the owner on Sep 16, 2022. It is now read-only.

fix(AST): Parse an identifier with a trailing space. #1565

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions _tests/test/regression/880_ngfor_extra_spaces_test.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
@TestOn('browser')
import 'package:angular/angular.dart';
import 'package:angular_test/angular_test.dart';
import 'package:test/test.dart';

import '880_ngfor_extra_spaces_test.template.dart' as ng;

// See https://github.com/dart-lang/angular/issues/880.
void main() {
tearDown(disposeAnyRunningTest);

test('should ignore extra spaces after a let assignment', () async {
final fixture = await NgTestBed.forComponent(
ng.LetAssignmentSpacingTestNgFactory,
).create();
expect(fixture.text, '012');
});
}

@Component(
selector: 'let-assignment-spacing-test', directives: [NgFor], template: r'''
<ng-container *ngFor="let item of items; let i = index">
{{i}}
</ng-container>
''')
class LetAssignmentSpacingTest {
final items = [1, 2, 3];
}
7 changes: 5 additions & 2 deletions angular_ast/lib/src/expression/micro/parser.dart
Original file line number Diff line number Diff line change
Expand Up @@ -118,8 +118,11 @@ class _RecursiveMicroAstParser {
return;
}
if (_tokens.current.type == NgMicroTokenType.letAssignment) {
letBindings
.add(LetBindingAst.from(_origin, identifier, _tokens.current.lexeme));
letBindings.add(LetBindingAst.from(
_origin,
identifier,
_tokens.current.lexeme.trimRight(),
));
} else {
letBindings.add(LetBindingAst.from(_origin, identifier));
if (_tokens.current.type != NgMicroTokenType.bindIdentifier) {
Expand Down
13 changes: 13 additions & 0 deletions angular_ast/test/expression/micro/parser_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,19 @@ void main() {
);
});

test('should parse a simple let and a let assignment with extra spaces', () {
expect(
parse('ngThing', 'let baz; let foo = bar ', 0),
NgMicroAst(
letBindings: [
LetBindingAst('baz'),
LetBindingAst('foo', 'bar'),
],
properties: [],
),
);
});

test('should parse a let with a full Dart expression', () {
expect(
parse('ngFor', 'let x of items.where(filter)', 0),
Expand Down