|
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183 |
- import { MagicString, SFC } from '@vue-macros/common';
- export { MagicString, SFC, parseSFC } from '@vue-macros/common';
- import { Node, TSModuleBlock, CallExpression, TSType, LVal, VariableDeclaration, ExpressionStatement, TSCallSignatureDeclaration, TSFunctionType, TSTypeLiteral, TSIntersectionType, TSInterfaceDeclaration, StringLiteral, TSMethodSignature, TSPropertySignature, TSMappedType, TSUnionType, ObjectMethod, ObjectProperty, Expression } from '@babel/types';
- import { TSFile, TSResolvedType, TSExports } from './ts.js';
- export { ResolveTSFileIdImpl, TSDeclaration, TSProperties, TSScope, exportsSymbol, getTSFile, isTSDeclaration, isTSExports, mergeTSProperties, resolveTSEntityName, resolveTSExports, resolveTSFileId, resolveTSFileIdNode, resolveTSProperties, resolveTSReferencedType, resolveTSScope, resolveTypeElements, setResolveTSFileIdImpl, tsFileCache, tsFileExportsCache } from './ts.js';
- export { RollupResolve } from './resolve.js';
- export { keyToString } from './utils.js';
- import 'vite';
- import 'rollup';
-
- declare enum DefinitionKind {
- /**
- * Definition is a referenced variable.
- *
- * @example defineSomething(foo)
- */
- Reference = "Reference",
- /**
- * Definition is a `ObjectExpression`.
- *
- * @example defineSomething({ ... })
- */
- Object = "Object",
- /**
- * Definition is TypeScript interface.
- *
- * @example defineSomething<{ ... }>()
- */
- TS = "TS"
- }
- interface ASTDefinition<T extends Node> {
- code: string;
- scope: TSFile | TSResolvedType<TSModuleBlock> | undefined;
- ast: T;
- }
-
- declare function handleTSEmitsDefinition({ s, file, offset, defineEmitsAst, typeDeclRaw, declId, statement, }: {
- s: MagicString;
- file: TSFile;
- sfc: SFC;
- offset: number;
- defineEmitsAst: CallExpression;
- typeDeclRaw: TSType;
- statement: DefineEmitsStatement;
- declId?: LVal;
- }): Promise<TSEmits>;
- type Emits = TSEmits | undefined;
- type DefineEmitsStatement = VariableDeclaration | ExpressionStatement;
- interface EmitsBase {
- declId?: LVal;
- statementAst: DefineEmitsStatement;
- defineEmitsAst: CallExpression;
- }
- interface TSEmits extends EmitsBase {
- kind: DefinitionKind.TS;
- definitions: Record<string, ASTDefinition<TSCallSignatureDeclaration | TSFunctionType>[]>;
- definitionsAst: ASTDefinition<TSTypeLiteral | TSIntersectionType | TSInterfaceDeclaration | TSFunctionType>;
- /**
- * Adds a new emit to the definitions. `definitions` will updated after this call.
- *
- * Added definition cannot be set and removed again.
- *
- * @example add('change', '(evt: "change", value: string): void')
- */
- addEmit(name: string | StringLiteral, signature: string): void;
- /**
- * Modify a definition of a emit. `definitions` will updated after this call.
- *
- * @limitation Cannot set the emit added by `addEmit`.
- *
- * @example setEmit('foo', 0, '(evt: "change", value: string): void')
- *
- * @returns false if the definition does not exist.
- */
- setEmit(name: string | StringLiteral, index: number, signature: string): boolean;
- /**
- * Removes specified emit from TS interface. `definitions` will updated after this call.
- *
- * @limitation Cannot remove emit added by `addEmit`. (it will be removed in definitions though)
- *
- * @returns `true` if emit was removed, `false` if emit was not found.
- */
- removeEmit(name: string | StringLiteral, index: number): boolean;
- }
-
- declare function handleTSPropsDefinition({ s, file, offset, definePropsAst, typeDeclRaw, withDefaultsAst, defaultsDeclRaw, statement, declId, }: {
- s: MagicString;
- file: TSFile;
- sfc: SFC;
- offset: number;
- definePropsAst: CallExpression;
- typeDeclRaw: TSType;
- withDefaultsAst?: CallExpression;
- defaultsDeclRaw?: DefaultsASTRaw;
- statement: DefinePropsStatement;
- declId?: LVal;
- }): Promise<TSProps>;
- type Props = /* ReferenceProps | ObjectProps | */ TSProps | undefined;
- type DefinePropsStatement = VariableDeclaration | ExpressionStatement;
- type DefaultsASTRaw = CallExpression['arguments'][number];
- interface PropsBase {
- declId?: LVal;
- statementAst: DefinePropsStatement;
- definePropsAst: CallExpression;
- withDefaultsAst?: CallExpression;
- }
- interface TSPropsMethod {
- type: 'method';
- methods: ASTDefinition<TSMethodSignature>[];
- optional: boolean;
- }
- interface TSPropsProperty {
- type: 'property';
- value: ASTDefinition<TSResolvedType['type']> | undefined;
- optional: boolean;
- signature: ASTDefinition<TSPropertySignature | TSMappedType>;
- /** Whether added by `addProp` API */
- addByAPI: boolean;
- }
- interface RuntimePropDefinition {
- type: string[];
- required: boolean;
- default?: (key?: string) => string;
- }
- interface TSProps extends PropsBase {
- kind: DefinitionKind.TS;
- definitions: Record<string | number, TSPropsMethod | TSPropsProperty>;
- definitionsAst: ASTDefinition<TSInterfaceDeclaration | TSTypeLiteral | TSIntersectionType | TSUnionType | TSMappedType>;
- /**
- * Default value of props.
- *
- * `undefined` if not defined or it's not a static expression that cannot be analyzed statically.
- */
- defaults?: Record<string, ObjectMethod | ObjectProperty>;
- /**
- * `undefined` if not defined.
- */
- defaultsAst?: Expression;
- /**
- * Adds a new prop to the definitions. `definitions` will updated after this call.
- *
- * Added definition cannot be set and removed again.
- *
- * @example addProp('foo', 'string | boolean')
- *
- * @returns false if the definition already exists.
- */
- addProp(name: string | StringLiteral, type: string, optional?: boolean): boolean;
- /**
- * Modify a definition of a prop. `definitions` will updated after this call.
- *
- * @limitation Cannot set the prop added by `addProp`.
- *
- * @example setProp('foo', 'string | boolean')
- *
- * @returns false if the definition does not exist.
- */
- setProp(name: string | StringLiteral, type: string, optional?: boolean): boolean;
- /**
- * Removes specified prop from TS interface. `definitions` will updated after this call.
- *
- * @limitation Cannot remove prop added by `addProp`. (it will be removed in definitions though)
- *
- * @returns `true` if prop was removed, `false` if prop was not found.
- */
- removeProp(name: string | StringLiteral): boolean;
- /**
- * get runtime definitions.
- */
- getRuntimeDefinitions(): Promise<Record<string, RuntimePropDefinition>>;
- }
-
- interface AnalyzeResult {
- props: Props;
- emits: Emits;
- }
- declare function analyzeSFC(s: MagicString, sfc: SFC): Promise<AnalyzeResult>;
-
- declare function inferRuntimeType(node: TSResolvedType | TSExports): Promise<string[]>;
- declare function attachNodeLoc(node: Node, newNode: Node): void;
- declare function toRuntimeTypeString(types: string[]): string;
-
- export { ASTDefinition, AnalyzeResult, DefaultsASTRaw, DefineEmitsStatement, DefinePropsStatement, DefinitionKind, Emits, EmitsBase, Props, PropsBase, RuntimePropDefinition, TSEmits, TSExports, TSFile, TSProps, TSPropsMethod, TSPropsProperty, TSResolvedType, analyzeSFC, attachNodeLoc, handleTSEmitsDefinition, handleTSPropsDefinition, inferRuntimeType, toRuntimeTypeString };
|