Skip to content
This repository was archived by the owner on Feb 22, 2018. It is now read-only.

fix(parser): Getter should call member classes #29

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
11 changes: 9 additions & 2 deletions lib/parser.dart
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,13 @@ abstract class Getter {
operator[](name);
}

stripTrailingNulls(List l) {
while (l.length > 0 && l.last == null) {
l.removeLast();
}
return l;
}

// Returns a tuple [found, value]
getterChild(value, childKey) {
if (value is List && childKey is num) {
Expand Down Expand Up @@ -163,8 +170,8 @@ getterChild(value, childKey) {
// maybe it is a member method?
if (instanceMirror.type.members.containsKey(curSym)) {
MethodMirror methodMirror = instanceMirror.type.members[curSym];
return [true, _relaxFnArgs((args) {
if (args == null) args = [];
return [true, _relaxFnArgs(([a0, a1, a2, a3, a4, a5]) {
var args = stripTrailingNulls([a0, a1, a2, a3, a4, a5]);
try {
return instanceMirror.invoke(curSym, args).reflectee;
} catch (e) {
Expand Down
11 changes: 11 additions & 0 deletions test/parser_spec.dart
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,11 @@ class TestData {
method() => "testMethod";
}

class Ident {
id(x) => x;
doubleId(x,y) => [x,y];
}

class Mixin {}
class MixedTestData extends TestData with Mixin {
}
Expand Down Expand Up @@ -355,6 +360,12 @@ main() {
expect(eval("x.y.z")).toEqual(null);
});

it('should access classes on scope', () {
scope['ident'] = new Ident();
expect(eval('ident.id(6)')).toEqual(6);
expect(eval('ident.doubleId(4,5)')).toEqual([4, 5]);
});

it('should resolve deeply nested paths (important for CSP mode)', () {
scope['a'] = {'b': {'c': {'d': {'e': {'f': {'g': {'h': {'i': {'j': {'k': {'l': {'m': {'n': 'nooo!'}}}}}}}}}}}}};
expect(eval("a.b.c.d.e.f.g.h.i.j.k.l.m.n")).toBe('nooo!');
Expand Down