From d52ab8e2c9eccfd33467054e8537994f25ea3d66 Mon Sep 17 00:00:00 2001 From: Peter Bacon Darwin Date: Thu, 6 Jul 2017 13:33:49 +0100 Subject: [PATCH] build(aio): fix matchUpDirectiveDecorators processor --- .../processors/matchUpDirectiveDecorators.js | 2 +- .../matchUpDirectiveDecorators.spec.js | 74 +++++++++++++++---- 2 files changed, 62 insertions(+), 14 deletions(-) diff --git a/aio/tools/transforms/angular-api-package/processors/matchUpDirectiveDecorators.js b/aio/tools/transforms/angular-api-package/processors/matchUpDirectiveDecorators.js index 262569fee8..9557ceac2b 100644 --- a/aio/tools/transforms/angular-api-package/processors/matchUpDirectiveDecorators.js +++ b/aio/tools/transforms/angular-api-package/processors/matchUpDirectiveDecorators.js @@ -66,7 +66,7 @@ function getBindingInfo(directiveBindings, members, bindingType) { } function stripQuotes(value) { - return (typeof(value) === 'string') ? value.replace(/^(['"])(.*)\1/, '$2') : value; + return (typeof(value) === 'string') ? value.trim().replace(/^(['"])(.*)\1$/, '$2') : value; } function parseBinding(option) { diff --git a/aio/tools/transforms/angular-api-package/processors/matchUpDirectiveDecorators.spec.js b/aio/tools/transforms/angular-api-package/processors/matchUpDirectiveDecorators.spec.js index f377841958..6a266203d5 100644 --- a/aio/tools/transforms/angular-api-package/processors/matchUpDirectiveDecorators.spec.js +++ b/aio/tools/transforms/angular-api-package/processors/matchUpDirectiveDecorators.spec.js @@ -34,37 +34,59 @@ describe('matchUpDirectiveDecorators processor', () => { expect(docs[0].exportAs).toBeUndefined(); }); - it('should strip quotes off directive properties', () => { - const docs = [{ - docType: 'directive', - directiveOptions: { selector: '"a,b,c"', exportAs: '\'someExport\'' } - }]; + it('should strip whitespace and quotes off directive properties', () => { + const docs = [ + { + docType: 'directive', + directiveOptions: { selector: '"a,b,c"', exportAs: '\'someExport\'' } + }, + { + docType: 'directive', + directiveOptions: { selector: ' a,b,c ', exportAs: ' someExport ' } + }, + { + docType: 'directive', + directiveOptions: { selector: ' "a,b,c" ', exportAs: ' \'someExport\' ' } + } + ]; processorFactory().$process(docs); expect(docs[0].selector).toEqual('a,b,c'); expect(docs[0].exportAs).toEqual('someExport'); + expect(docs[1].selector).toEqual('a,b,c'); + expect(docs[1].exportAs).toEqual('someExport'); + expect(docs[2].selector).toEqual('a,b,c'); + expect(docs[2].exportAs).toEqual('someExport'); }); it('should extract inputs and outputs from the directive decorator', () => { const docs = [{ docType: 'directive', directiveOptions: { - inputs: ['a:b', 'x'], - outputs: ['foo:foo'] + inputs: ['in1:in2', 'in3', ' in4:in5 ', ' in6 '], + outputs: ['out1:out1', ' out2:out3 ', ' out4 '] }, members: [ - { name: 'a' }, - { name: 'x' }, - { name: 'foo' } + { name: 'in1' }, + { name: 'in3' }, + { name: 'in4' }, + { name: 'in6' }, + { name: 'out1' }, + { name: 'out2' }, + { name: 'out4' } ] }]; processorFactory().$process(docs); expect(docs[0].inputs).toEqual([ - { propertyName: 'a', bindingName: 'b', memberDoc: docs[0].members[0] }, - { propertyName: 'x', bindingName: 'x', memberDoc: docs[0].members[1] } + { propertyName: 'in1', bindingName: 'in2', memberDoc: docs[0].members[0] }, + { propertyName: 'in3', bindingName: 'in3', memberDoc: docs[0].members[1] }, + { propertyName: 'in4', bindingName: 'in5', memberDoc: docs[0].members[2] }, + { propertyName: 'in6', bindingName: 'in6', memberDoc: docs[0].members[3] } ]); expect(docs[0].outputs).toEqual([ - { propertyName: 'foo', bindingName: 'foo', memberDoc: docs[0].members[2] } + { propertyName: 'out1', bindingName: 'out1', memberDoc: docs[0].members[4] }, + { propertyName: 'out2', bindingName: 'out3', memberDoc: docs[0].members[5] }, + { propertyName: 'out4', bindingName: 'out4', memberDoc: docs[0].members[6] } ]); }); @@ -90,4 +112,30 @@ describe('matchUpDirectiveDecorators processor', () => { { propertyName: 'd1', bindingName: 'd1', memberDoc: docs[0].members[3] } ]); }); + + it('should merge directive inputs/outputs with decorator property inputs/outputs', () => { + const docs = [{ + docType: 'directive', + directiveOptions: { + inputs: ['a1:a2'], + outputs: ['b1:b2'] + }, + members: [ + { name: 'a1' }, + { name: 'a3', decorators: [{ name: 'Input', arguments: ['a4'] }] }, + { name: 'b1' }, + { name: 'b3', decorators: [{ name: 'Output', arguments: ['b4'] }] }, + ] + }]; + processorFactory().$process(docs); + expect(docs[0].inputs).toEqual([ + { propertyName: 'a1', bindingName: 'a2', memberDoc: docs[0].members[0] }, + { propertyName: 'a3', bindingName: 'a4', memberDoc: docs[0].members[1] } + ]); + + expect(docs[0].outputs).toEqual([ + { propertyName: 'b1', bindingName: 'b2', memberDoc: docs[0].members[2] }, + { propertyName: 'b3', bindingName: 'b4', memberDoc: docs[0].members[3] } + ]); + }); });