diff --git a/modules/@angular/compiler-cli/src/static_reflector.ts b/modules/@angular/compiler-cli/src/static_reflector.ts index 8b9203faec..4dfb7cd75e 100644 --- a/modules/@angular/compiler-cli/src/static_reflector.ts +++ b/modules/@angular/compiler-cli/src/static_reflector.ts @@ -279,16 +279,18 @@ export class StaticReflector implements ReflectorReader { let callContext: {[name: string]: string}|undefined = undefined; if (expression['__symbolic'] == 'call') { let target = expression['expression']; + let functionSymbol: StaticSymbol; let targetFunction: any; if (target && target.__symbolic === 'reference') { callContext = {name: target.name}; - targetFunction = resolveReferenceValue(resolveReference(context, target)); + functionSymbol = resolveReference(context, target); + targetFunction = resolveReferenceValue(functionSymbol); } if (targetFunction && targetFunction['__symbolic'] == 'function') { - if (calling.get(targetFunction)) { + if (calling.get(functionSymbol)) { throw new Error('Recursion not supported'); } - calling.set(targetFunction, true); + calling.set(functionSymbol, true); let value = targetFunction['value']; if (value) { // Determine the arguments @@ -302,13 +304,13 @@ export class StaticReflector implements ReflectorReader { let result: any; try { scope = functionScope.done(); - result = simplify(value); + result = simplifyInContext(functionSymbol, value, depth + 1); } finally { scope = oldScope; } return result; } - calling.delete(targetFunction); + calling.delete(functionSymbol); } } diff --git a/modules/@angular/compiler-cli/test/static_reflector_spec.ts b/modules/@angular/compiler-cli/test/static_reflector_spec.ts index b719c4b7eb..585adb0a6b 100644 --- a/modules/@angular/compiler-cli/test/static_reflector_spec.ts +++ b/modules/@angular/compiler-cli/test/static_reflector_spec.ts @@ -322,8 +322,8 @@ describe('StaticReflector', () => { })).toEqual(['some-value']); expect(simplify(new StaticSymbol('/tmp/src/function-reference.ts', ''), { __symbolic: 'reference', - name: 'two' - })).toEqual(2); + name: 'three' + })).toEqual(3); }); it('should error on direct recursive calls', () => { @@ -332,7 +332,7 @@ describe('StaticReflector', () => { new StaticSymbol('/tmp/src/function-reference.ts', ''), {__symbolic: 'reference', name: 'recursion'})) .toThrow(new Error( - 'Recursion not supported, resolving symbol recursion in /tmp/src/function-reference.ts, resolving symbol in /tmp/src/function-reference.ts')); + 'Recursion not supported, resolving symbol recursive in /tmp/src/function-recursive.d.ts, resolving symbol recursion in /tmp/src/function-reference.ts, resolving symbol in /tmp/src/function-reference.ts')); }); it('should error on indirect recursive calls', () => { @@ -341,7 +341,7 @@ describe('StaticReflector', () => { new StaticSymbol('/tmp/src/function-reference.ts', ''), {__symbolic: 'reference', name: 'indirectRecursion'})) .toThrow(new Error( - 'Recursion not supported, resolving symbol indirectRecursion in /tmp/src/function-reference.ts, resolving symbol in /tmp/src/function-reference.ts')); + 'Recursion not supported, resolving symbol indirectRecursion2 in /tmp/src/function-recursive.d.ts, resolving symbol indirectRecursion1 in /tmp/src/function-recursive.d.ts, resolving symbol indirectRecursion in /tmp/src/function-reference.ts, resolving symbol in /tmp/src/function-reference.ts')); }); it('should simplify a spread expression', () => { @@ -749,9 +749,15 @@ class MockReflectorHost implements StaticReflectorHost { __symbolic: 'binop', operator: '+', left: {__symbolic: 'reference', name: 'a'}, - right: {__symbolic: 'reference', name: 'b'} + right: { + __symbolic: 'binop', + operator: '+', + left: {__symbolic: 'reference', name: 'b'}, + right: {__symbolic: 'reference', name: 'oneLiteral'} + } } - } + }, + oneLiteral: 1 } }, '/tmp/src/function-reference.ts': { @@ -767,7 +773,7 @@ class MockReflectorHost implements StaticReflectorHost { }, arguments: ['some-value'] }, - two: { + three: { __symbolic: 'call', expression: { __symbolic: 'reference',