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

Commit f92381e

Browse files
committed
fix(parser): Getter should call member classes
1 parent f73def3 commit f92381e

File tree

2 files changed

+20
-2
lines changed

2 files changed

+20
-2
lines changed

lib/parser.dart

+9-2
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,13 @@ abstract class Getter {
132132
operator[](name);
133133
}
134134

135+
stripTrailingNulls(List l) {
136+
while (l.length > 0 && l.last == null) {
137+
l.removeLast();
138+
}
139+
return l;
140+
}
141+
135142
// Returns a tuple [found, value]
136143
getterChild(value, childKey) {
137144
if (value is List && childKey is num) {
@@ -161,8 +168,8 @@ getterChild(value, childKey) {
161168
// maybe it is a member method?
162169
if (instanceMirror.type.members.containsKey(curSym)) {
163170
MethodMirror methodMirror = instanceMirror.type.members[curSym];
164-
return [true, _relaxFnArgs((args) {
165-
if (args == null) args = [];
171+
return [true, _relaxFnArgs(([a0, a1, a2, a3, a4, a5]) {
172+
var args = stripTrailingNulls([a0, a1, a2, a3, a4, a5]);
166173
try {
167174
return instanceMirror.invoke(curSym, args).reflectee;
168175
} catch (e) {

test/parser_spec.dart

+11
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,11 @@ class TestData {
99
method() => "testMethod";
1010
}
1111

12+
class Ident {
13+
id(x) => x;
14+
doubleId(x,y) => [x,y];
15+
}
16+
1217
class Mixin {}
1318
class MixedTestData extends TestData with Mixin {
1419
}
@@ -354,6 +359,12 @@ main() {
354359
expect(eval("x.y.z")).toEqual(null);
355360
});
356361

362+
it('should access classes on scope', () {
363+
scope['ident'] = new Ident();
364+
expect(eval('ident.id(6)')).toEqual(6);
365+
expect(eval('ident.doubleId(4,5)')).toEqual([4, 5]);
366+
});
367+
357368
it('should resolve deeply nested paths (important for CSP mode)', () {
358369
scope['a'] = {'b': {'c': {'d': {'e': {'f': {'g': {'h': {'i': {'j': {'k': {'l': {'m': {'n': 'nooo!'}}}}}}}}}}}}};
359370
expect(eval("a.b.c.d.e.f.g.h.i.j.k.l.m.n")).toBe('nooo!');

0 commit comments

Comments
 (0)