From 44845839a60326f85ffd437a4e2a3233d4868792 Mon Sep 17 00:00:00 2001 From: Tobias Bosch Date: Sun, 15 Feb 2015 19:56:03 -0800 Subject: [PATCH] fix(transpiler): support arrow functions with complex body in named arguments --- tools/transpiler/spec/arrow_functions_spec.js | 17 ++++++++++++++++- .../src/codegeneration/DartTransformer.js | 2 +- 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/tools/transpiler/spec/arrow_functions_spec.js b/tools/transpiler/spec/arrow_functions_spec.js index 8acad0abc1..60a9e28bb1 100644 --- a/tools/transpiler/spec/arrow_functions_spec.js +++ b/tools/transpiler/spec/arrow_functions_spec.js @@ -1,4 +1,4 @@ -import {describe, it, expect} from 'angular2/test_lib'; +import {describe, it, expect, iit} from 'angular2/test_lib'; var inc = x => x + 1; @@ -12,6 +12,10 @@ var max = (a, b) => { } }; +var namedFn = function({fn}) { + return fn(); +} + class LexicalThis { zero; @@ -30,6 +34,10 @@ export function main() { expect(inc(0)).toBe(1); }); + it('should support implicit return in named arguments', function() { + expect(namedFn({fn: () => 1})).toBe(1); + }); + it('should support object literal', function() { var o = objLiteral('val'); expect(o['key']).toBe('val'); @@ -40,9 +48,16 @@ export function main() { expect(max(1, 0)).toBe(1); }); + it('should support complex body in named arguments', function() { + expect(namedFn({fn: () => { + return 1; + }})).toBe(1); + }); + it('should support lexical this', function() { var lthis = new LexicalThis(); expect(lthis.getZero()).toBe(0); }); + }); } diff --git a/tools/transpiler/src/codegeneration/DartTransformer.js b/tools/transpiler/src/codegeneration/DartTransformer.js index a16bb8d1d7..94afc881bd 100644 --- a/tools/transpiler/src/codegeneration/DartTransformer.js +++ b/tools/transpiler/src/codegeneration/DartTransformer.js @@ -25,8 +25,8 @@ export class DartTransformer extends MultiTransformer { }); }; - append(NamedParamsTransformer); append(ArrowFunctionTransformer); + append(NamedParamsTransformer); append(MultiVarTransformer); append(InstanceOfTransformer); append(StrictEqualityTransformer);