Something went wrong. Try again.
[READ-ONLY] Mirror of https://github.com/sxzz/rolldown-plugin-dts. A Rolldown plugin to generate and bundle dts files.
Something went wrong. Try again.
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111import { b } from 'yuku'import { is } from 'yuku/utils'import type * as t from 'yuku'
/** * A variable declaration that declares a runtime binding variable. It represents a declaration like: * * ```js * var binding = [declarationId, (param, ...) => [dep, ...], sideEffect()] * ``` * * For an more concrete example, the following TypeScript declaration: * * ```ts * interface Bar extends Foo { bar: number } * ``` * * Will be transformed to the following JavaScript code: * * ```js * const Bar = [123, () => [Foo]] * ``` * * Which will be represented by this type. */export type RuntimeBindingVariableDeclration = t.VariableDeclaration & { declarations: [ t.VariableDeclarator & { id: t.ArrayPattern init: RuntimeBindingArrayExpression }, ...t.VariableDeclarator[], ]}
/** * Check if the given node is a {@link RuntimeBindingVariableDeclration} */export function isRuntimeBindingVariableDeclaration( node: t.Node | null | undefined,): node is RuntimeBindingVariableDeclration { return ( node?.type === 'VariableDeclaration' && node.declarations.length === 1 && node.declarations[0].type === 'VariableDeclarator' && node.declarations[0].id.type === 'ArrayPattern' && isRuntimeBindingArrayExpression(node.declarations[0].init) )}
/** * A array expression that contains {@link RuntimeBindingArrayElements} * * It can be used to represent the following JavaScript code: * * ```js * [declarationId, (param, ...) => [dep, ...], sideEffect()] * ``` */export type RuntimeBindingArrayExpression = t.ArrayExpression & { elements: RuntimeBindingArrayElements}
/** * Check if the given node is a {@link RuntimeBindingArrayExpression} */function isRuntimeBindingArrayExpression( node: t.Node | null | undefined,): node is RuntimeBindingArrayExpression { return ( node?.type === 'ArrayExpression' && isRuntimeBindingArrayElements(node.elements) )}
/** * Check if the given array is a {@link RuntimeBindingArrayElements} */function isRuntimeBindingArrayElements( elements: Array<t.Node | null | undefined>,): elements is RuntimeBindingArrayElements { const [declarationId, deps, children, effect] = elements return ( is.NumericLiteral(declarationId) && deps?.type === 'ArrowFunctionExpression' && children?.type === 'ArrayExpression' && (!effect || effect.type === 'CallExpression') )}
export function runtimeBindingArrayExpression( elements: RuntimeBindingArrayElements,): RuntimeBindingArrayExpression { return b.ArrayExpression({ elements: [...elements], }) as RuntimeBindingArrayExpression}
type RuntimeBindingArrayElementsBase = [ declarationId: t.NumericLiteral, deps: t.ArrowFunctionExpression, children: t.ArrayExpression,]
/** * An array that represents the elements in {@link RuntimeBindingArrayExpression} */export type RuntimeBindingArrayElements = | RuntimeBindingArrayElementsBase | [...RuntimeBindingArrayElementsBase, effect: t.CallExpression]