generate ts types from rust (#291)
* initial types Signed-off-by: Jess Frazelle <github@jessfraz.com> * updates Signed-off-by: Jess Frazelle <github@jessfraz.com> * start using generated types Signed-off-by: Jess Frazelle <github@jessfraz.com> * generate ast types Signed-off-by: Jess Frazelle <github@jessfraz.com> * cleanup Signed-off-by: Jess Frazelle <github@jessfraz.com> * generate for error types as well Signed-off-by: Jess Frazelle <github@jessfraz.com> --------- Signed-off-by: Jess Frazelle <github@jessfraz.com>
This commit is contained in:
@ -1,3 +1,21 @@
|
||||
export type { Program } from '../wasm-lib/bindings/Program'
|
||||
export type { Value } from '../wasm-lib/bindings/Value'
|
||||
export type { ObjectExpression } from '../wasm-lib/bindings/ObjectExpression'
|
||||
export type { MemberExpression } from '../wasm-lib/bindings/MemberExpression'
|
||||
export type { PipeExpression } from '../wasm-lib/bindings/PipeExpression'
|
||||
export type { VariableDeclaration } from '../wasm-lib/bindings/VariableDeclaration'
|
||||
export type { PipeSubstitution } from '../wasm-lib/bindings/PipeSubstitution'
|
||||
export type { Identifier } from '../wasm-lib/bindings/Identifier'
|
||||
export type { UnaryExpression } from '../wasm-lib/bindings/UnaryExpression'
|
||||
export type { BinaryExpression } from '../wasm-lib/bindings/BinaryExpression'
|
||||
export type { ReturnStatement } from '../wasm-lib/bindings/ReturnStatement'
|
||||
export type { ExpressionStatement } from '../wasm-lib/bindings/ExpressionStatement'
|
||||
export type { CallExpression } from '../wasm-lib/bindings/CallExpression'
|
||||
export type { VariableDeclarator } from '../wasm-lib/bindings/VariableDeclarator'
|
||||
export type { BinaryPart } from '../wasm-lib/bindings/BinaryPart'
|
||||
export type { Literal } from '../wasm-lib/bindings/Literal'
|
||||
export type { ArrayExpression } from '../wasm-lib/bindings/ArrayExpression'
|
||||
|
||||
export type SyntaxType =
|
||||
| 'Program'
|
||||
| 'ExpressionStatement'
|
||||
@ -18,160 +36,3 @@ export type SyntaxType =
|
||||
| 'Literal'
|
||||
| 'NoneCodeNode'
|
||||
| 'UnaryExpression'
|
||||
|
||||
export interface Program {
|
||||
type: SyntaxType
|
||||
start: number
|
||||
end: number
|
||||
body: BodyItem[]
|
||||
nonCodeMeta: NoneCodeMeta
|
||||
}
|
||||
interface GeneralStatement {
|
||||
type: SyntaxType
|
||||
start: number
|
||||
end: number
|
||||
}
|
||||
|
||||
export type BodyItem =
|
||||
| ExpressionStatement
|
||||
| VariableDeclaration
|
||||
| ReturnStatement
|
||||
|
||||
export type Value =
|
||||
| Literal
|
||||
| Identifier
|
||||
| BinaryExpression
|
||||
| FunctionExpression
|
||||
| CallExpression
|
||||
| PipeExpression
|
||||
| PipeSubstitution
|
||||
| ArrayExpression
|
||||
| ObjectExpression
|
||||
| MemberExpression
|
||||
| UnaryExpression
|
||||
|
||||
export type BinaryPart =
|
||||
| Literal
|
||||
| Identifier
|
||||
| BinaryExpression
|
||||
| CallExpression
|
||||
| UnaryExpression
|
||||
|
||||
export interface NoneCodeNode extends GeneralStatement {
|
||||
type: 'NoneCodeNode'
|
||||
value: string
|
||||
}
|
||||
|
||||
export interface NoneCodeMeta {
|
||||
// Stores the whitespace/comments that go after the statement who's index we're using here
|
||||
noneCodeNodes: { [statementIndex: number]: NoneCodeNode }
|
||||
// Which is why we also need `start` for and whitespace at the start of the file/block
|
||||
start?: NoneCodeNode
|
||||
}
|
||||
|
||||
export interface ExpressionStatement extends GeneralStatement {
|
||||
type: 'ExpressionStatement'
|
||||
expression: Value
|
||||
}
|
||||
|
||||
export interface CallExpression extends GeneralStatement {
|
||||
type: 'CallExpression'
|
||||
callee: Identifier
|
||||
arguments: Value[]
|
||||
optional: boolean
|
||||
}
|
||||
|
||||
export interface VariableDeclaration extends GeneralStatement {
|
||||
type: 'VariableDeclaration'
|
||||
declarations: VariableDeclarator[]
|
||||
kind: 'const' | 'unknown' | 'fn' //| "solid" | "surface" | "face"
|
||||
}
|
||||
|
||||
export interface VariableDeclarator extends GeneralStatement {
|
||||
type: 'VariableDeclarator'
|
||||
id: Identifier
|
||||
init: Value
|
||||
}
|
||||
|
||||
export interface Literal extends GeneralStatement {
|
||||
type: 'Literal'
|
||||
value: string | number | boolean | null
|
||||
raw: string
|
||||
}
|
||||
|
||||
export interface Identifier extends GeneralStatement {
|
||||
type: 'Identifier'
|
||||
name: string
|
||||
}
|
||||
|
||||
export interface PipeSubstitution extends GeneralStatement {
|
||||
type: 'PipeSubstitution'
|
||||
}
|
||||
|
||||
export interface ArrayExpression extends GeneralStatement {
|
||||
type: 'ArrayExpression'
|
||||
elements: Value[]
|
||||
}
|
||||
|
||||
export interface ObjectExpression extends GeneralStatement {
|
||||
type: 'ObjectExpression'
|
||||
properties: ObjectProperty[]
|
||||
}
|
||||
|
||||
export interface ObjectProperty extends GeneralStatement {
|
||||
type: 'ObjectProperty'
|
||||
key: Identifier
|
||||
value: Value
|
||||
}
|
||||
|
||||
export interface MemberExpression extends GeneralStatement {
|
||||
type: 'MemberExpression'
|
||||
object: MemberExpression | Identifier
|
||||
property: Identifier | Literal
|
||||
computed: boolean
|
||||
}
|
||||
|
||||
export interface ObjectKeyInfo {
|
||||
key: Identifier | Literal
|
||||
index: number
|
||||
computed: boolean
|
||||
}
|
||||
|
||||
export interface BinaryExpression extends GeneralStatement {
|
||||
type: 'BinaryExpression'
|
||||
operator: string
|
||||
left: BinaryPart
|
||||
right: BinaryPart
|
||||
}
|
||||
|
||||
export interface UnaryExpression extends GeneralStatement {
|
||||
type: 'UnaryExpression'
|
||||
operator: '-' | '!'
|
||||
argument: BinaryPart
|
||||
}
|
||||
|
||||
export interface PipeExpression extends GeneralStatement {
|
||||
type: 'PipeExpression'
|
||||
body: Value[]
|
||||
nonCodeMeta: NoneCodeMeta
|
||||
}
|
||||
|
||||
export interface FunctionExpression extends GeneralStatement {
|
||||
type: 'FunctionExpression'
|
||||
id: Identifier | null
|
||||
params: Identifier[]
|
||||
body: BlockStatement
|
||||
}
|
||||
|
||||
export interface BlockStatement extends GeneralStatement {
|
||||
type: 'BlockStatement'
|
||||
body: BodyItem[]
|
||||
nonCodeMeta: NoneCodeMeta
|
||||
}
|
||||
|
||||
export interface ReturnStatement extends GeneralStatement {
|
||||
type: 'ReturnStatement'
|
||||
argument: Value
|
||||
}
|
||||
|
||||
export type All = Program | ExpressionStatement[] | BinaryExpression | Literal
|
||||
|
Reference in New Issue
Block a user