Skip to content

Instantly share code, notes, and snippets.

@swyxio
Last active August 7, 2020 01:56
Show Gist options
  • Save swyxio/21ca6ad7f582c4a1a191f4835d8c2553 to your computer and use it in GitHub Desktop.
Save swyxio/21ca6ad7f582c4a1a191f4835d8c2553 to your computer and use it in GitHub Desktop.
types for estree with JSX - the default estree types (https://github.com/DefinitelyTyped/DefinitelyTyped/blob/master/types/estree/index.d.ts) dont come with JSX definitions so i made a short start on them. pls comment if you have more to add
interface Location {
start: number;
end: number;
};
interface JSXOpeningElement extends Location {
type: 'JSXOpeningElement',
attributes: JSXAttribute[],
name: JSXIdentifier,
selfClosing: boolean
}
interface JSXClosingElement extends Location {
type: 'JSXClosingElement'
name: JSXIdentifier
}
interface JSXElement extends Location {
type: 'JSXElement',
attributes: JSXAttribute[],
openingElement: JSXOpeningElement
closingElement: JSXClosingElement
children: (JSXElement | JSXText)[]
}
interface JSXText extends Location {
type: 'JSXText'
value: string,
raw: string
}
interface JSXAttribute extends Location {
type: 'JSXAttribute',
name: JSXNamespacedName | JSXIdentifier,
value: JSXExpressionContainer | Literal
}
interface JSXIdentifier extends Location {
type: 'JSXIdentifier'
name: string
}
interface JSXNamespacedName extends Location {
type: 'JSXNamespacedName',
namespace: JSXIdentifier,
name: JSXIdentifier
}
interface JSXExpressionContainer extends Location {
type: 'JSXExpressionContainer'
expression: Identifier
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment