File tree Expand file tree Collapse file tree 3 files changed +43
-0
lines changed Expand file tree Collapse file tree 3 files changed +43
-0
lines changed Original file line number Diff line number Diff line change @@ -16,9 +16,17 @@ const babelPluginUntyped: PluginItem = function (
1616 api : ConfigAPI ,
1717 options : { experimentalFunctions ?: boolean } ,
1818) {
19+ const name = "untyped" ;
1920 api . cache . using ( ( ) => version ) ;
2021
2122 return < PluginObj > {
23+ name,
24+ manipulateOptions ( opts : { plugins : Array < { key : string } > } ) {
25+ // This `untyped` plugin must come before the `transform-typescript` plugin,
26+ // otherwise the `returnType` annotations will be removed.
27+ // So put it at the beginning.
28+ opts . plugins ! . sort ( ( a ) => ( a . key === name ? - 1 : 0 ) ) ;
29+ } ,
2230 visitor : {
2331 VariableDeclaration ( p ) {
2432 const declaration = p . node . declarations [ 0 ] ;
Original file line number Diff line number Diff line change 1+ export function main ( a : number ) : string {
2+ return a . toString ( ) ;
3+ }
Original file line number Diff line number Diff line change @@ -36,4 +36,36 @@ describe("loader", () => {
3636 }
3737 ` ) ;
3838 } ) ;
39+
40+ it ( "should load a schema with function return type annotations" , async ( ) => {
41+ const schema = await loadSchema ( "./test/fixtures/functions.ts" ) ;
42+ expect ( schema ) . toMatchInlineSnapshot ( `
43+ {
44+ "default": {},
45+ "id": "#",
46+ "properties": {
47+ "main": {
48+ "args": [
49+ {
50+ "items": {},
51+ "name": "a",
52+ "tsType": "number",
53+ "type": "number",
54+ },
55+ ],
56+ "description": "",
57+ "id": "#main",
58+ "returns": {
59+ "tsType": "string",
60+ "type": "string",
61+ },
62+ "tags": [],
63+ "title": "",
64+ "type": "function",
65+ },
66+ },
67+ "type": "object",
68+ }
69+ ` ) ;
70+ } ) ;
3971} ) ;
You can’t perform that action at this time.
0 commit comments