Skip to content

Comments

[api-extractor] Classify arrow functions as function kind in the doc model exports.#4513

Merged
iclanton merged 4 commits intomicrosoft:mainfrom
bartvandenende-wm:bartvandenende-wm/api-extractor-arrow-func
Feb 6, 2024
Merged

[api-extractor] Classify arrow functions as function kind in the doc model exports.#4513
iclanton merged 4 commits intomicrosoft:mainfrom
bartvandenende-wm:bartvandenende-wm/api-extractor-arrow-func

Conversation

@bartvandenende-wm
Copy link
Contributor

@bartvandenende-wm bartvandenende-wm commented Feb 6, 2024

Summary

Classify arrow functions as function kind in the doc model exports.

Related issue ticket #1629

Screenshot 2024-02-06 at 16 54 40

Details

The current behaviour of api-extractor is to classify arrow functions as variable kind. Even though syntactically correct, semantically (for documentation & usage purposes) this doesn't make any sense - and worse - it invalidates any documentation effort in the docstrings related to parameter descriptions, return types etc.

This PR modifies the doc-model generation to identify arrow functions in the variable declarations and processes them as function kinds instead.

Example code

/**
 * Demo log function
 * @param message - log message
 * @public
 */
export const log = (message: string): void => {console.log(message)}

doc model exports
Previous behaviour

{
  "kind": "Variable",
  "canonicalReference": "sample-lib!log:var",
  "docComment": "/**\n * Demo log function\n *\n * @param message - log message\n */\n",
  "excerptTokens": [
    {
      "kind": "Content",
      "text": "log: "
    },
    {
      "kind": "Content",
      "text": "(message: string) => void"
    }
  ],
  "fileUrlPath": "src/index.ts",
  "isReadonly": true,
  "releaseTag": "Public",
  "name": "log",
  "variableTypeTokenRange": {
    "startIndex": 1,
    "endIndex": 2
  }
}

New behaviour

  {
    "kind": "Function",
    "canonicalReference": "sample-lib!log:function(1)",
    "docComment": "/**\n * Demo log function\n *\n * @param message - log message\n */\n",
    "excerptTokens": [
      {
        "kind": "Content",
        "text": "log: (message: "
      },
      {
        "kind": "Content",
        "text": "string"
      },
      {
        "kind": "Content",
        "text": ") => "
      },
      {
        "kind": "Content",
        "text": "void"
      }
    ],
    "fileUrlPath": "src/index.ts",
    "returnTypeTokenRange": {
      "startIndex": 3,
      "endIndex": 4
    },
    "releaseTag": "Public",
    "overloadIndex": 1,
    "parameters": [
      {
        "parameterName": "message",
        "parameterTypeTokenRange": {
          "startIndex": 1,
          "endIndex": 2
        },
        "isOptional": false
      }
    ],
    "name": "log"
  }

How it was tested

manual testing

Impacted documentation

N/A

@iclanton iclanton merged commit c88b970 into microsoft:main Feb 6, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Archived in project

Development

Successfully merging this pull request may close these issues.

2 participants