esquery icon indicating copy to clipboard operation
esquery copied to clipboard

What is the `external:AST` type?

Open sakgoyal opened this issue 10 months ago • 4 comments

the jsdoc comments have

@param {?external:AST} node

around. what does this mean? Where can I find the AST type? I am trying to write a .ts version of esquery but im having trouble figuring out where the following exist:

  • external:AST
  • PlainObject

You can see my progress here: https://github.com/sakgoyal/esquery/tree/esm

sakgoyal avatar Feb 27 '25 02:02 sakgoyal

Also, what is the [?type] syntax? I made the assumption that ? means nullable here since [] already means optional

sakgoyal avatar Feb 27 '25 03:02 sakgoyal

external: is the pre-TypeScript way of JSDoc to refer to an external source (pointed to by an @external tag).

You can see in the @types/esquery package, that the proper AST should be import('estree').Node.

PlainObject was a way to indicate an arbitrary object. It needs to be elaborated (as does SelectorMatcher).

As per https://jsdoc.app/tags-type , ?type is type or null (though undefined may also be relevant here I think).

Before doing more work, however, I'd confirm that @michaelficarra would accept a TypeScript PR.

brettz9 avatar Feb 27 '25 08:02 brettz9

so does this mean I should do this in my code?

import type { Node as AST } from "estree";

I dont quite understand what you are trying to tell me. Same with the "elaborate". I dont quite understand what this means either.

sakgoyal avatar Feb 27 '25 09:02 sakgoyal

so does this mean I should do this in my code?

import type { Node as AST } from "estree";

I think that should work. I normally use JSDoc for TypeScript rather than pure TS, but that looks right.

I dont quite understand what you are trying to tell me. Same with the "elaborate". I dont quite understand what this means either.

It means you will need more type info than we provided. Look at the @types/esquery package (or just use that).

brettz9 avatar Feb 27 '25 09:02 brettz9