Skip to content

Commit ca17de5

Browse files
committed
fix: Fix parsing of optional parameters with annotations
1 parent 4ea3a95 commit ca17de5

File tree

4 files changed

+279
-33
lines changed

4 files changed

+279
-33
lines changed

__tests__/__snapshots__/test.js.snap

+250-7
Original file line numberDiff line numberDiff line change
@@ -19444,6 +19444,136 @@ Array [
1944419444
},
1944519445
"yields": Array [],
1944619446
},
19447+
Object {
19448+
"augments": Array [],
19449+
"context": Object {
19450+
"loc": Object {
19451+
"end": Object {
19452+
"column": 42,
19453+
"line": 16,
19454+
},
19455+
"start": Object {
19456+
"column": 0,
19457+
"line": 16,
19458+
},
19459+
},
19460+
},
19461+
"description": Object {
19462+
"children": Array [
19463+
Object {
19464+
"children": Array [
19465+
Object {
19466+
"position": Object {
19467+
"end": Object {
19468+
"column": 3,
19469+
"line": 1,
19470+
"offset": 2,
19471+
},
19472+
"indent": Array [],
19473+
"start": Object {
19474+
"column": 1,
19475+
"line": 1,
19476+
"offset": 0,
19477+
},
19478+
},
19479+
"type": "text",
19480+
"value": "T3",
19481+
},
19482+
],
19483+
"position": Object {
19484+
"end": Object {
19485+
"column": 3,
19486+
"line": 1,
19487+
"offset": 2,
19488+
},
19489+
"indent": Array [],
19490+
"start": Object {
19491+
"column": 1,
19492+
"line": 1,
19493+
"offset": 0,
19494+
},
19495+
},
19496+
"type": "paragraph",
19497+
},
19498+
],
19499+
"position": Object {
19500+
"end": Object {
19501+
"column": 3,
19502+
"line": 1,
19503+
"offset": 2,
19504+
},
19505+
"start": Object {
19506+
"column": 1,
19507+
"line": 1,
19508+
"offset": 0,
19509+
},
19510+
},
19511+
"type": "root",
19512+
},
19513+
"errors": Array [],
19514+
"examples": Array [],
19515+
"implements": Array [],
19516+
"kind": "typedef",
19517+
"loc": Object {
19518+
"end": Object {
19519+
"column": 9,
19520+
"line": 15,
19521+
},
19522+
"start": Object {
19523+
"column": 0,
19524+
"line": 15,
19525+
},
19526+
},
19527+
"members": Object {
19528+
"events": Array [],
19529+
"global": Array [],
19530+
"inner": Array [],
19531+
"instance": Array [],
19532+
"static": Array [],
19533+
},
19534+
"name": "T3",
19535+
"namespace": "T3",
19536+
"params": Array [],
19537+
"path": Array [
19538+
Object {
19539+
"kind": "typedef",
19540+
"name": "T3",
19541+
},
19542+
],
19543+
"properties": Array [],
19544+
"returns": Array [],
19545+
"sees": Array [],
19546+
"tags": Array [],
19547+
"throws": Array [],
19548+
"todos": Array [],
19549+
"type": Object {
19550+
"params": Array [
19551+
Object {
19552+
"expression": Object {
19553+
"name": "string",
19554+
"type": "NameExpression",
19555+
},
19556+
"name": "a",
19557+
"type": "ParameterType",
19558+
},
19559+
],
19560+
"result": Object {
19561+
"fields": Array [
19562+
Object {
19563+
"key": "num",
19564+
"type": "FieldType",
19565+
"value": Object {
19566+
"name": "number",
19567+
"type": "NameExpression",
19568+
},
19569+
},
19570+
],
19571+
"type": "RecordType",
19572+
},
19573+
"type": "FunctionType",
19574+
},
19575+
"yields": Array [],
19576+
},
1944719577
]
1944819578
`;
1944919579

@@ -19455,38 +19585,47 @@ exports[`outputs flow-unnamed-params.input.js markdown 1`] = `
1945519585
- [x2][1]
1945619586
- [T][2]
1945719587
- [T2][3]
19588+
- [T3][4]
1945819589

1945919590
## x2
1946019591

1946119592
x2
1946219593

19463-
Type: function (a: [T][4]): [string][5]
19594+
Type: function (a: [T][5]): [string][6]
1946419595

1946519596
## T
1946619597

1946719598
T
1946819599

19469-
Type: function ([Array][6]<[string][5]>): {num: [number][7]}
19600+
Type: function ([Array][7]<[string][6]>): {num: [number][8]}
1947019601

1947119602
## T2
1947219603

1947319604
T2
1947419605

19475-
Type: function (a: [Array][6]<[string][5]>): {num: [number][7]}
19606+
Type: function (a: [Array][7]<[string][6]>): {num: [number][8]}
19607+
19608+
## T3
19609+
19610+
T3
19611+
19612+
Type: function (a: [string][6]): {num: [number][8]}
1947619613

1947719614
[1]: #x2
1947819615

1947919616
[2]: #t
1948019617

1948119618
[3]: #t2
1948219619

19483-
[4]: #t
19620+
[4]: #t3
1948419621

19485-
[5]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String
19622+
[5]: #t
1948619623

19487-
[6]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Array
19624+
[6]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String
19625+
19626+
[7]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Array
1948819627

19489-
[7]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number
19628+
[8]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number
1949019629
"
1949119630
`;
1949219631

@@ -19831,6 +19970,110 @@ Object {
1983119970
],
1983219971
"type": "paragraph",
1983319972
},
19973+
Object {
19974+
"children": Array [
19975+
Object {
19976+
"type": "text",
19977+
"value": "T3",
19978+
},
19979+
],
19980+
"depth": 2,
19981+
"type": "heading",
19982+
},
19983+
Object {
19984+
"children": Array [
19985+
Object {
19986+
"position": Position {
19987+
"end": Object {
19988+
"column": 3,
19989+
"line": 1,
19990+
"offset": 2,
19991+
},
19992+
"indent": Array [],
19993+
"start": Object {
19994+
"column": 1,
19995+
"line": 1,
19996+
"offset": 0,
19997+
},
19998+
},
19999+
"type": "text",
20000+
"value": "T3",
20001+
},
20002+
],
20003+
"position": Position {
20004+
"end": Object {
20005+
"column": 3,
20006+
"line": 1,
20007+
"offset": 2,
20008+
},
20009+
"indent": Array [],
20010+
"start": Object {
20011+
"column": 1,
20012+
"line": 1,
20013+
"offset": 0,
20014+
},
20015+
},
20016+
"type": "paragraph",
20017+
},
20018+
Object {
20019+
"children": Array [
20020+
Object {
20021+
"type": "text",
20022+
"value": "Type: ",
20023+
},
20024+
Object {
20025+
"type": "text",
20026+
"value": "function (",
20027+
},
20028+
Object {
20029+
"type": "text",
20030+
"value": "a: ",
20031+
},
20032+
Object {
20033+
"children": Array [
20034+
Object {
20035+
"type": "text",
20036+
"value": "string",
20037+
},
20038+
],
20039+
"identifier": "2",
20040+
"referenceType": "full",
20041+
"type": "linkReference",
20042+
},
20043+
Object {
20044+
"type": "text",
20045+
"value": ")",
20046+
},
20047+
Object {
20048+
"type": "text",
20049+
"value": ": ",
20050+
},
20051+
Object {
20052+
"type": "text",
20053+
"value": "{",
20054+
},
20055+
Object {
20056+
"type": "text",
20057+
"value": "num: ",
20058+
},
20059+
Object {
20060+
"children": Array [
20061+
Object {
20062+
"type": "text",
20063+
"value": "number",
20064+
},
20065+
],
20066+
"identifier": "4",
20067+
"referenceType": "full",
20068+
"type": "linkReference",
20069+
},
20070+
Object {
20071+
"type": "text",
20072+
"value": "}",
20073+
},
20074+
],
20075+
"type": "paragraph",
20076+
},
1983420077
Object {
1983520078
"identifier": "1",
1983620079
"title": undefined,

__tests__/fixture/flow-unnamed-params.input.js

+3
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,6 @@ type T = (string[]) => { num: number };
1111

1212
/** T2 */
1313
type T2 = (a: string[]) => { num: number };
14+
15+
/** T3 */
16+
type T3 = (a?: string) => { num: number };

0 commit comments

Comments
 (0)