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

Commit

Permalink
fix(Compiler): allow use of named argument that collides with an export
Browse files Browse the repository at this point in the history
The template parser will no longer crash if a named argument in a function
invocation collides with the name of an exported symbol.

Fixes #1625.

PiperOrigin-RevId: 214860587
  • Loading branch information
leonsenft authored and alorenzen committed Oct 1, 2018
1 parent b951008 commit d7e0b8d
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 2 deletions.
9 changes: 9 additions & 0 deletions _tests/test/compiler/expression_parser/parser_test.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
@TestOn('vm')
import 'package:test/test.dart';
import 'package:_tests/test_util.dart';
import 'package:angular/src/compiler/compile_metadata.dart'
show CompileIdentifierMetadata;
import 'package:angular/src/compiler/expression_parser/ast.dart'
show BindingPipe, AST;
import 'package:angular/src/compiler/expression_parser/lexer.dart' show Lexer;
Expand Down Expand Up @@ -168,6 +170,13 @@ void main() {
checkAction("fn().add(1, 2)");
checkAction("fn(a: 1)");
});
test("should parse named argument that collides with an export", () {
final parser = createParser();
final text = "fn(a: 1)";
final export = CompileIdentifierMetadata(name: "a");
final ast = parser.parseAction(text, null, [export]);
expect(unparse(ast), text);
});
});
group("functional calls", () {
test("should parse function calls", () {
Expand Down
5 changes: 5 additions & 0 deletions angular/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,10 @@
* Named arguments are now supported for function calls in templates where the
function is an exported symbol (`Component(exports: [someFunction])`).

* [#1625][]: Named arguments in function calls in templates that collide with
an exported symbol (`Component(exports: [someExport])`) no longer cause a
parsing error.

[#434]: https://github.com/dart-lang/angular/issues/434
[#880]: https://github.com/dart-lang/angular/issues/880
[#930]: https://github.com/dart-lang/angular/issues/930
Expand All @@ -207,6 +211,7 @@
[#1570]: https://github.com/dart-lang/angular/issues/1570
[#1591]: https://github.com/dart-lang/angular/issues/1591
[#1598]: https://github.com/dart-lang/angular/issues/1598
[#1625]: https://github.com/dart-lang/angular/issues/1625

### Other improvements

Expand Down
7 changes: 5 additions & 2 deletions angular/lib/src/compiler/expression_parser/parser.dart
Original file line number Diff line number Diff line change
Expand Up @@ -480,10 +480,13 @@ class _ParseAST {
_parseCall = false;
var expression = parseExpression();
_parseCall = true;
if (result is! PropertyRead) {
if (result is PropertyRead) {
result = NamedExpr((result as PropertyRead).name, expression);
} else if (result is StaticRead && result.id.prefix == null) {
result = NamedExpr((result as StaticRead).id.name, expression);
} else {
error('Expected previous token to be an identifier');
}
result = NamedExpr((result as PropertyRead).name, expression);
} else if (optionalCharacter($LPAREN)) {
var args = parseCallArguments();
expectCharacter($RPAREN);
Expand Down

0 comments on commit d7e0b8d

Please sign in to comment.