Skip to content
This repository has been archived by the owner on Mar 8, 2019. It is now read-only.

Commit

Permalink
fix(events): first argument of events is the type (not a property)
Browse files Browse the repository at this point in the history
  • Loading branch information
elevatebart committed Jan 25, 2019
1 parent a97838c commit ed60c18
Show file tree
Hide file tree
Showing 7 changed files with 31 additions and 82 deletions.
9 changes: 3 additions & 6 deletions src/script-handlers/__tests__/eventHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,19 +74,16 @@ describe('eventHandler', () => {
eventHandler(documentation, def[0])
const eventComp: EventDescriptor = {
description: '',
type: {
names: ['undefined'],
},
properties: [
{
name: '<anonymous1>',
type: {
names: ['undefined'],
},
},
{
name: '<anonymous2>',
type: {
names: ['undefined'],
},
},
],
}
expect(documentation.getEventDescriptor).toHaveBeenCalledWith('success')
Expand Down
15 changes: 11 additions & 4 deletions src/script-handlers/eventHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,15 +45,22 @@ export default function eventHandler(documentation: Documentation, path: NodePat
// fetch the leading comments on the wrapping expression
const docblock = getDocblock(pathExpression.parentPath)
setEventDescriptor(evtDescriptor, getDoclets(docblock || ''))
if (args.length > 1 && !evtDescriptor.properties) {

if (args.length > 1 && !evtDescriptor.type) {
evtDescriptor.type = {
names: ['undefined'],
}
}

if (args.length > 2 && !evtDescriptor.properties) {
evtDescriptor.properties = []
}
if (evtDescriptor.properties && evtDescriptor.properties.length < args.length - 1) {
let i = args.length - 1 - evtDescriptor.properties.length
if (evtDescriptor.properties && evtDescriptor.properties.length < args.length - 2) {
let i = args.length - 2 - evtDescriptor.properties.length
while (i--) {
evtDescriptor.properties.push({
type: { names: ['undefined'] },
name: `<anonymous${args.length - i - 1}>`,
name: `<anonymous${args.length - i - 2}>`,
})
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,12 @@ Object {
"events": Object {
"success": Object {
"description": "Success event when we click",
"properties": Array [
Object {
"name": "<anonymous1>",
"type": Object {
"names": Array [
"undefined",
],
},
},
],
"type": undefined,
"properties": undefined,
"type": Object {
"names": Array [
"undefined",
],
},
},
},
"methods": Array [
Expand Down
6 changes: 5 additions & 1 deletion tests/components/button/__snapshots__/button.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,11 @@ Object {
},
},
],
"type": undefined,
"type": Object {
"names": Array [
"undefined",
],
},
},
},
"methods": Array [],
Expand Down
22 changes: 2 additions & 20 deletions tests/components/grid-jsx/__snapshots__/grid-jsx.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,7 @@ Object {
"events": Object {
"error": Object {
"description": "Error event.",
"properties": Array [
Object {
"name": "<anonymous1>",
"type": Object {
"names": Array [
"undefined",
],
},
},
],
"properties": undefined,
"type": Object {
"names": Array [
"object",
Expand All @@ -25,16 +16,7 @@ Object {
},
"success": Object {
"description": "Success event.",
"properties": Array [
Object {
"name": "<anonymous1>",
"type": Object {
"names": Array [
"undefined",
],
},
},
],
"properties": undefined,
"type": Object {
"names": Array [
"object",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,7 @@ Object {
"events": Object {
"error": Object {
"description": "Error event.",
"properties": Array [
Object {
"name": "<anonymous1>",
"type": Object {
"names": Array [
"undefined",
],
},
},
],
"properties": undefined,
"type": Object {
"names": Array [
"object",
Expand All @@ -25,16 +16,7 @@ Object {
},
"success": Object {
"description": "Success event.",
"properties": Array [
Object {
"name": "<anonymous1>",
"type": Object {
"names": Array [
"undefined",
],
},
},
],
"properties": undefined,
"type": Object {
"names": Array [
"object",
Expand Down
22 changes: 2 additions & 20 deletions tests/components/grid/__snapshots__/grid.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,7 @@ Object {
"events": Object {
"error": Object {
"description": "Error event.",
"properties": Array [
Object {
"name": "<anonymous1>",
"type": Object {
"names": Array [
"undefined",
],
},
},
],
"properties": undefined,
"type": Object {
"names": Array [
"object",
Expand All @@ -25,16 +16,7 @@ Object {
},
"success": Object {
"description": "Success event.",
"properties": Array [
Object {
"name": "<anonymous1>",
"type": Object {
"names": Array [
"undefined",
],
},
},
],
"properties": undefined,
"type": Object {
"names": Array [
"object",
Expand Down

0 comments on commit ed60c18

Please sign in to comment.