Skip to content

Bug: The token type of null should be Null instead of Keyword #11027

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
4 tasks done
JLHwung opened this issue Apr 3, 2025 · 2 comments · Fixed by #11283
Closed
4 tasks done

Bug: The token type of null should be Null instead of Keyword #11027

JLHwung opened this issue Apr 3, 2025 · 2 comments · Fixed by #11283
Labels
accepting prs Go ahead, send a pull request that resolves this issue AST PRs and Issues about the AST structure bug Something isn't working package: typescript-estree Issues related to @typescript-eslint/typescript-estree

Comments

@JLHwung
Copy link

JLHwung commented Apr 3, 2025

Before You File a Bug Report Please Confirm You Have Done The Following...

  • I have tried restarting my IDE and the issue persists.
  • I have updated to the latest version of the packages.
  • I have searched for related issues and found none that matched my issue.
  • I have read the FAQ and my problem is not listed.

Relevant Package

typescript-estree

Playground Link

https://typescript-eslint.io/play/#ts=5.6.2&showAST=es&fileType=.tsx&code=HYVwNmQ&eslintrc=N4KABGBEBOCuA2BTAzpAXGYBfEWg&tsconfig=N4KABGBEDGD2C2AHAlgGwKYCcDyiAuysAdgM6QBcYoEEkJemy0eAcgK6qoDCAFutAGsylBm3TgwAXxCSgA&tokens=true

Repro Code

null

ESLint Config

module.exports = {
  parser: "@typescript-eslint/parser",
  rules: {
    "@typescript-eslint/<rule-name>": ["error", ...<options>],
  },
};

tsconfig

{
  "compilerOptions": {
    // ...
  }
}

Expected Result

.ast.tokens[0].type should be Null.

Actual Result

.ast.tokens[0].type is Keyword.

Additional Info

No response

Versions

package version
@typescript-eslint/typescript-estree 8.28.0
@JLHwung JLHwung added bug Something isn't working triage Waiting for team members to take a look labels Apr 3, 2025
@JoshuaKGoldberg
Copy link
Member

Sorry, I'm still not 100% familiar with these nuances - could you please explain why the token type should be "null" instead of "keyword"? null is a keyword. Other keywords such as instanceof have "keyword" types too:

"a" instanceof "b"

https://typescript-eslint.io/play/#ts=5.6.2&showAST=es&fileType=.tsx&code=EQQ2AIEsDsGcBcTQMYFMD2AzcwBGwg&eslintrc=N4KABGBEBOCuA2BTAzpAXGYBfEWg&tsconfig=N4KABGBEDGD2C2AHAlgGwKYCcDyiAuysAdgM6QBcYoEEkJemy0eAcgK6qoDCAFutAGsylBm3TgwAXxCSgA&tokens=true

{
  type: "Keyword",
  loc: {end, start},
  range: [4, 14],
  value: "instanceof"
},

@JoshuaKGoldberg JoshuaKGoldberg added awaiting response Issues waiting for a reply from the OP or another party and removed triage Waiting for team members to take a look labels Apr 16, 2025
@JLHwung
Copy link
Author

JLHwung commented Apr 16, 2025

could you please explain why the token type should be "null" instead of "keyword"?

Good question. I don't know the design choice behind it. Either a null type or a keyword type look good to me personally. But this is the espree behaviour (AST explorer), here is the espree output for the input source null:

{
  "type": "Program",
  "start": 0,
  "end": 4,
  "range": [
    0,
    4
  ],
  "body": [
    {
      "type": "ExpressionStatement",
      "start": 0,
      "end": 4,
      "range": [
        0,
        4
      ],
      "expression": {
        "type": "Literal",
        "start": 0,
        "end": 4,
        "range": [
          0,
          4
        ],
        "value": null,
        "raw": "null"
      }
    }
  ],
  "sourceType": "module",
  "tokens": [
    {
      "type": "Null",
      "value": "null",
      "start": 0,
      "end": 4,
      "range": [
        0,
        4
      ]
    }
  ]
}

Since espree is the canonical implementation of estree, I think we should just align to it.

@JoshuaKGoldberg JoshuaKGoldberg added triage Waiting for team members to take a look and removed awaiting response Issues waiting for a reply from the OP or another party labels Apr 16, 2025
@bradzacher bradzacher added package: typescript-estree Issues related to @typescript-eslint/typescript-estree AST PRs and Issues about the AST structure accepting prs Go ahead, send a pull request that resolves this issue and removed triage Waiting for team members to take a look labels Apr 17, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
accepting prs Go ahead, send a pull request that resolves this issue AST PRs and Issues about the AST structure bug Something isn't working package: typescript-estree Issues related to @typescript-eslint/typescript-estree
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants