@ts-for-gir/lib
Version:
Typescript .d.ts generator from GIR for gjs
170 lines (169 loc) • 5.44 kB
TypeScript
/**
* This is where transformations take place for gjs.
* For example function names should keep their original name for gjs
*/
import { ConstructName, OptionsGeneration, GirCallableParamElement, GirEnumElement, GirBitfieldElement } from './types/index.js';
export declare const ARRAY_TYPE_MAP: {
guint8: string;
gint8: string;
gunichar: string;
};
/**
* Used to parse `name` and
* @see https://developer.gnome.org/glib/stable/glib-Basic-Types.html
* @see https://gi.readthedocs.io/en/latest/annotations/giannotations.html
*/
export declare const PRIMITIVE_TYPE_MAP: {
none: string;
va_list: string;
guintptr: string;
utf8: string;
filename: string;
gunichar: string;
'gunichar*': string;
'char*': string;
'gchar*': string;
'gchar**': string;
'gchar***': string;
'const gchar*': string;
'const char*': string;
gboolean: string;
'gboolean*': string;
gpointer: string;
'gpointer*': string;
gconstpointer: string;
gchar: string;
guchar: string;
glong: string;
gulong: string;
gdouble: string;
gssize: string;
gsize: string;
gshort: string;
guint32: string;
'guint32*': string;
guint: string;
'guint*': string;
guint8: string;
'guint8*': string;
'guint8**': string;
guint16: string;
'guint16*': string;
gint16: string;
'gint16*': string;
guint64: string;
'guint64*': string;
gfloat: string;
'gfloat*': string;
gint: string;
'gint*': string;
gint8: string;
'gint8*': string;
gint32: string;
'gint32*': string;
gint64: string;
'gint64*': string;
gushort: string;
'gushort*': string;
long: string;
double: string;
'double*': string;
uint32: string;
int32: string;
uint8: string;
int8: string;
uint16: string;
'int*': string;
int: string;
this: string;
never: string;
unknown: string;
any: string;
number: string;
string: string;
boolean: string;
object: string;
void: string;
};
export declare const FULL_TYPE_MAP: (value: string, out?: boolean) => string | undefined;
export declare class Transformation {
readonly config: OptionsGeneration;
protected static instance?: Transformation;
/**
* Rules for the name conventions
* For gjs see https://gjs-docs.gnome.org/ and https://wiki.gnome.org/Attic/Gjs
*/
private transformations;
private log;
protected constructor(config: OptionsGeneration, logName?: string);
static getSingleton(config: OptionsGeneration): Transformation;
transformSignalInterfaceName(name: string): string;
transformModuleNamespaceName(name: string): string;
transformClassName(name: string): string;
/**
* // E.g. the NetworkManager-1.0 has enum names starting with 80211
* @param girEnum The enum
* @returns The transformed name
*/
transformEnumName(girEnum: GirEnumElement | GirBitfieldElement): string;
transformEnumMember(memberName: string): string;
transformFunctionName(name: string, isVirtual: boolean): string;
transformReservedVariableNames(name: string, allowQuotes: boolean): string;
/**
* E.g. GstVideo-1.0 has a class `VideoScaler` with a method called `2d`
* or NetworkManager-1.0 has methods starting with `80211`
*/
transformPropertyName(name: string, allowQuotes: boolean): string;
transformConstructorPropertyName(name: string, allowQuotes: boolean): string;
transformConstantName(name: string, allowQuotes: boolean): string;
transformFieldName(name: string, allowQuotes: boolean): string;
transformParameterName(param: GirCallableParamElement, allowQuotes: boolean): string;
/**
* Fixes type names, e.g. Return types or enum definitions can not start with numbers
* @param typeName
*/
transformTypeName(name: string): string;
transform(construct: ConstructName, transformMe: string): string;
/**
* In JavaScript there can be no variables, methods, class names or enum names that start with a number.
* This method converts such names.
* TODO: Prepends an `@` to numeric starting names, how does gjs and node-gtk do that?
* @param name
* @param allowQuotes
*/
private transformNumericName;
/**
* Replaces "@any_property" with "`any_property`"
* @param description E.g. "Creates a binding between @source_property on @source and @target_property on @target."
* @returns E.g. "Creates a binding between `source_property` on `source` and `target_property` on `target`."
*/
private transformGirDocHighlights;
/**
* Replaces:
* |[<!-- language="C" -->
* g_object_notify_by_pspec (self, properties[PROP_FOO]);
* ]|
*
* with
* ```c
* g_object_notify_by_pspec (self, properties[PROP_FOO]);
* ```
*
* @param description
*/
private transformGirDocCodeBlocks;
/**
* Transforms the documentation text to markdown
* TODO: Transform references to link tags: https://tsdoc.org/pages/tags/link/
* @param text
* @returns
*/
transformGirDocText(text: string): string;
/**
* Transforms the tsDoc tag <text> like `@param name <text>`
* @param text
* @returns
*/
transformGirDocTagText(text: string): string;
transformImportName(packageName: string): string;
}