Skip to content

JavaScript argument with default value is output twice #233

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
roadhump opened this issue Nov 8, 2015 · 1 comment
Closed

JavaScript argument with default value is output twice #233

roadhump opened this issue Nov 8, 2015 · 1 comment
Labels

Comments

@roadhump
Copy link

roadhump commented Nov 8, 2015

It looks like a bug in any output format when using default argument value in JavaScript

/**
 * Number
 *
 * @param {number} x an argument
 *
 * @returns {number} some
 */
export const myfunc = (x = 123) => x;

output html
screenshot 2015-11-08 20 08 14

output JSON

[
  {
    "description": "Number",
    "tags": [
      {
        "title": "param",
        "description": "an argument",
        "lineNumber": 3,
        "type": {
          "type": "NameExpression",
          "name": "number"
        },
        "name": "x"
      },
      {
        "title": "returns",
        "description": "some",
        "lineNumber": 5,
        "type": {
          "type": "NameExpression",
          "name": "number"
        }
      }
    ],
    "loc": {
      "start": {
        "line": 1,
        "column": 0
      },
      "end": {
        "line": 7,
        "column": 3
      }
    },
    "context": {
      "loc": {
        "start": {
          "line": 8,
          "column": 0
        },
        "end": {
          "line": 8,
          "column": 30
        }
      },
      "file": "/Users/roadhump/Projects/CustomFieldConstraints/src/shared/services/test.js",
      "code": "/**\n * Number\n *\n * @param {number} x an argument\n *\n * @returns {number} some\n */\nexport default (x = 123) => x;\n"
    },
    "params": [
      {
        "title": "param",
        "description": "an argument",
        "lineNumber": 3,
        "type": {
          "type": "NameExpression",
          "name": "number"
        },
        "name": "x"
      },
      {
        "title": "param",
        "name": "x",
        "default": "123"
      }
    ],
    "returns": [
      {
        "title": "returns",
        "description": "some",
        "lineNumber": 5,
        "type": {
          "type": "NameExpression",
          "name": "number"
        }
      }
    ],
    "name": "x",
    "kind": "function",
    "members": {
      "instance": [],
      "static": []
    },
    "path": [
      "x"
    ]
  }
]
@tmcw tmcw added the bug label Nov 9, 2015
@tmcw
Copy link
Member

tmcw commented Nov 9, 2015

Thanks for the detailed bug report! This is a bug in our type inference system, where it was relying on parameter names to be exposed as .name, which is not true for parameters with default values. I'm rolling a fix in #239 and will publish it in the next patch release.

On a related note, this code demonstrates something a little tricky: we will infer the default value in the parameter declaration from the code, but specifying a parameter type like {number} overrides this: parameter types are either declared explicitly or inferred. I'm not sure about combining inferred and explicit type information, because it could quickly get complex.

@tmcw tmcw closed this as completed in 33552c6 Nov 9, 2015
rhendric pushed a commit to rhendric/documentation that referenced this issue Sep 15, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants