chore: format typescript dir

This commit is contained in:
Evan You 2022-05-27 17:30:12 +08:00
parent 1f1046b7e5
commit 12150f622b
5 changed files with 332 additions and 322 deletions

View File

@ -1,224 +1,224 @@
declare type CompilerOptions = {
warn?: Function; // allow customizing warning in different environments; e.g. node
modules?: Array<ModuleOptions>; // platform specific modules; e.g. style; class
directives?: { [key: string]: Function }; // platform specific directives
staticKeys?: string; // a list of AST properties to be considered static; for optimization
isUnaryTag?: (tag: string) => boolean | undefined; // check if a tag is unary for the platform
canBeLeftOpenTag?: (tag: string) => boolean | undefined; // check if a tag can be left opened
isReservedTag?: (tag: string) => boolean | undefined; // check if a tag is a native for the platform
preserveWhitespace?: boolean; // preserve whitespace between elements? (Deprecated)
whitespace?: "preserve" | "condense"; // whitespace handling strategy
optimize?: boolean; // optimize static content?
warn?: Function // allow customizing warning in different environments; e.g. node
modules?: Array<ModuleOptions> // platform specific modules; e.g. style; class
directives?: { [key: string]: Function } // platform specific directives
staticKeys?: string // a list of AST properties to be considered static; for optimization
isUnaryTag?: (tag: string) => boolean | undefined // check if a tag is unary for the platform
canBeLeftOpenTag?: (tag: string) => boolean | undefined // check if a tag can be left opened
isReservedTag?: (tag: string) => boolean | undefined // check if a tag is a native for the platform
preserveWhitespace?: boolean // preserve whitespace between elements? (Deprecated)
whitespace?: 'preserve' | 'condense' // whitespace handling strategy
optimize?: boolean // optimize static content?
// web specific
mustUseProp?: (tag: string, type: string | null, name: string) => boolean; // check if an attribute should be bound as a property
isPreTag?: (attr: string) => boolean | null; // check if a tag needs to preserve whitespace
getTagNamespace?: (tag: string) => string | undefined; // check the namespace for a tag
expectHTML?: boolean; // only false for non-web builds
isFromDOM?: boolean;
shouldDecodeTags?: boolean;
shouldDecodeNewlines?: boolean;
shouldDecodeNewlinesForHref?: boolean;
outputSourceRange?: boolean;
mustUseProp?: (tag: string, type: string | null, name: string) => boolean // check if an attribute should be bound as a property
isPreTag?: (attr: string) => boolean | null // check if a tag needs to preserve whitespace
getTagNamespace?: (tag: string) => string | undefined // check the namespace for a tag
expectHTML?: boolean // only false for non-web builds
isFromDOM?: boolean
shouldDecodeTags?: boolean
shouldDecodeNewlines?: boolean
shouldDecodeNewlinesForHref?: boolean
outputSourceRange?: boolean
// runtime user-configurable
delimiters?: [string, string]; // template delimiters
comments?: boolean; // preserve comments in template
delimiters?: [string, string] // template delimiters
comments?: boolean // preserve comments in template
// for ssr optimization compiler
scopeId?: string;
};
scopeId?: string
}
declare type WarningMessage = {
msg: string;
start?: number;
end?: number;
};
msg: string
start?: number
end?: number
}
declare type CompiledResult = {
ast: ASTElement | null;
render: string;
staticRenderFns: Array<string>;
stringRenderFns?: Array<string>;
errors?: Array<string | WarningMessage>;
tips?: Array<string | WarningMessage>;
};
ast: ASTElement | null
render: string
staticRenderFns: Array<string>
stringRenderFns?: Array<string>
errors?: Array<string | WarningMessage>
tips?: Array<string | WarningMessage>
}
declare type ModuleOptions = {
// transform an AST node before any attributes are processed
// returning an ASTElement from pre/transforms replaces the element
preTransformNode: (el: ASTElement) => ASTElement | null;
preTransformNode: (el: ASTElement) => ASTElement | null
// transform an AST node after built-ins like v-if, v-for are processed
transformNode: (el: ASTElement) => ASTElement | null;
transformNode: (el: ASTElement) => ASTElement | null
// transform an AST node after its children have been processed
// cannot return replacement in postTransform because tree is already finalized
postTransformNode: (el: ASTElement) => void;
genData: (el: ASTElement) => string; // generate extra data string for an element
transformCode?: (el: ASTElement, code: string) => string; // further transform generated code for an element
staticKeys?: Array<string>; // AST properties to be considered static
};
postTransformNode: (el: ASTElement) => void
genData: (el: ASTElement) => string // generate extra data string for an element
transformCode?: (el: ASTElement, code: string) => string // further transform generated code for an element
staticKeys?: Array<string> // AST properties to be considered static
}
declare type ASTModifiers = { [key: string]: boolean };
declare type ASTIfCondition = { exp: string | null; block: ASTElement };
declare type ASTIfConditions = Array<ASTIfCondition>;
declare type ASTModifiers = { [key: string]: boolean }
declare type ASTIfCondition = { exp: string | null; block: ASTElement }
declare type ASTIfConditions = Array<ASTIfCondition>
declare type ASTAttr = {
name: string;
value: any;
dynamic?: boolean;
start?: number;
end?: number;
};
name: string
value: any
dynamic?: boolean
start?: number
end?: number
}
declare type ASTElementHandler = {
value: string;
params?: Array<any>;
modifiers: ASTModifiers | null;
dynamic?: boolean;
start?: number;
end?: number;
};
value: string
params?: Array<any>
modifiers: ASTModifiers | null
dynamic?: boolean
start?: number
end?: number
}
declare type ASTElementHandlers = {
[key: string]: ASTElementHandler | Array<ASTElementHandler>;
};
[key: string]: ASTElementHandler | Array<ASTElementHandler>
}
declare type ASTDirective = {
name: string;
rawName: string;
value: string;
arg: string | null;
isDynamicArg: boolean;
modifiers: ASTModifiers | null;
start?: number;
end?: number;
};
name: string
rawName: string
value: string
arg: string | null
isDynamicArg: boolean
modifiers: ASTModifiers | null
start?: number
end?: number
}
declare type ASTNode = ASTElement | ASTText | ASTExpression;
declare type ASTNode = ASTElement | ASTText | ASTExpression
declare type ASTElement = {
type: 1;
tag: string;
attrsList: Array<ASTAttr>;
attrsMap: { [key: string]: any };
rawAttrsMap: { [key: string]: ASTAttr };
parent: ASTElement | void;
children: Array<ASTNode>;
type: 1
tag: string
attrsList: Array<ASTAttr>
attrsMap: { [key: string]: any }
rawAttrsMap: { [key: string]: ASTAttr }
parent: ASTElement | void
children: Array<ASTNode>
start?: number;
end?: number;
start?: number
end?: number
processed?: true;
processed?: true
static?: boolean;
staticRoot?: boolean;
staticInFor?: boolean;
staticProcessed?: boolean;
hasBindings?: boolean;
static?: boolean
staticRoot?: boolean
staticInFor?: boolean
staticProcessed?: boolean
hasBindings?: boolean
text?: string;
attrs?: Array<ASTAttr>;
dynamicAttrs?: Array<ASTAttr>;
props?: Array<ASTAttr>;
plain?: boolean;
pre?: true;
ns?: string;
text?: string
attrs?: Array<ASTAttr>
dynamicAttrs?: Array<ASTAttr>
props?: Array<ASTAttr>
plain?: boolean
pre?: true
ns?: string
component?: string;
inlineTemplate?: true;
transitionMode?: string | null;
slotName?: string | null;
slotTarget?: string | null;
slotTargetDynamic?: boolean;
slotScope?: string | null;
scopedSlots?: { [name: string]: ASTElement };
component?: string
inlineTemplate?: true
transitionMode?: string | null
slotName?: string | null
slotTarget?: string | null
slotTargetDynamic?: boolean
slotScope?: string | null
scopedSlots?: { [name: string]: ASTElement }
ref?: string;
refInFor?: boolean;
ref?: string
refInFor?: boolean
if?: string;
ifProcessed?: boolean;
elseif?: string;
else?: true;
ifConditions?: ASTIfConditions;
if?: string
ifProcessed?: boolean
elseif?: string
else?: true
ifConditions?: ASTIfConditions
for?: string;
forProcessed?: boolean;
key?: string;
alias?: string;
iterator1?: string;
iterator2?: string;
for?: string
forProcessed?: boolean
key?: string
alias?: string
iterator1?: string
iterator2?: string
staticClass?: string;
classBinding?: string;
staticStyle?: string;
styleBinding?: string;
events?: ASTElementHandlers;
nativeEvents?: ASTElementHandlers;
staticClass?: string
classBinding?: string
staticStyle?: string
styleBinding?: string
events?: ASTElementHandlers
nativeEvents?: ASTElementHandlers
transition?: string | true;
transitionOnAppear?: boolean;
transition?: string | true
transitionOnAppear?: boolean
model?: {
value: string;
callback: string;
expression: string;
};
value: string
callback: string
expression: string
}
directives?: Array<ASTDirective>;
directives?: Array<ASTDirective>
forbidden?: true;
once?: true;
onceProcessed?: boolean;
wrapData?: (code: string) => string;
wrapListeners?: (code: string) => string;
forbidden?: true
once?: true
onceProcessed?: boolean
wrapData?: (code: string) => string
wrapListeners?: (code: string) => string
// 2.4 ssr optimization
ssrOptimizability?: number;
};
ssrOptimizability?: number
}
declare type ASTExpression = {
type: 2;
expression: string;
text: string;
tokens: Array<string | Object>;
static?: boolean;
type: 2
expression: string
text: string
tokens: Array<string | Object>
static?: boolean
// 2.4 ssr optimization
ssrOptimizability?: number;
start?: number;
end?: number;
};
ssrOptimizability?: number
start?: number
end?: number
}
declare type ASTText = {
type: 3;
text: string;
static?: boolean;
isComment?: boolean;
type: 3
text: string
static?: boolean
isComment?: boolean
// 2.4 ssr optimization
ssrOptimizability?: number;
start?: number;
end?: number;
};
ssrOptimizability?: number
start?: number
end?: number
}
// SFC-parser related declarations
// an object format describing a single-file component
declare type SFCDescriptor = {
template: SFCBlock | null;
script: SFCBlock | null;
styles: Array<SFCBlock>;
customBlocks: Array<SFCBlock>;
errors: Array<string | WarningMessage>;
};
template: SFCBlock | null
script: SFCBlock | null
styles: Array<SFCBlock>
customBlocks: Array<SFCBlock>
errors: Array<string | WarningMessage>
}
declare type SFCBlock = {
type: string;
content: string;
attrs: { [attribute: string]: string };
start?: number;
end?: number;
lang?: string;
src?: string;
scoped?: boolean;
module?: string | boolean;
};
type: string
content: string
attrs: { [attribute: string]: string }
start?: number
end?: number
lang?: string
src?: string
scoped?: boolean
module?: string | boolean
}

View File

@ -1,15 +1,15 @@
declare module 'de-indent' {
export default function deindent (input: string): string
export default function deindent(input: string): string
}
declare namespace jasmine {
interface Matchers<T> {
toHaveBeenWarned(): void;
toHaveBeenTipped(): void;
toHaveBeenWarned(): void
toHaveBeenTipped(): void
}
interface ArrayLikeMatchers<T> {
toHaveBeenWarned(): void;
toHaveBeenTipped(): void;
toHaveBeenWarned(): void
toHaveBeenTipped(): void
}
}
}

View File

@ -1,102 +1,112 @@
import VNode from "../src/core/vdom/vnode";
import { Component } from "./component";
import VNode from '../src/core/vdom/vnode'
import { Component } from './component'
declare type InternalComponentOptions = {
_isComponent: true;
parent: Component;
_parentVnode: VNode;
render?: Function;
staticRenderFns?: Array<Function>;
};
_isComponent: true
parent: Component
_parentVnode: VNode
render?: Function
staticRenderFns?: Array<Function>
}
type InjectKey = string | Symbol;
type InjectKey = string | Symbol
declare interface SetupContext {
attrs: Record<string, any>
slots: Record<string, (() => VNode[]) | undefined>
emit: (event: string, ...args: any[]) => any
expose: (exposed?: Record<string, any>) => void
}
declare type ComponentOptions = {
// v3
setup(props: Record<string, any>, ctx: SetupContext): any
[key: string]: any
componentId?: string;
componentId?: string
// data
data: object | Function | void;
props?: { [key: string]: PropOptions };
propsData?: object;
data: object | Function | void
props?: { [key: string]: PropOptions }
propsData?: object
computed?: {
[key: string]:
| Function
| {
get?: Function;
set?: Function;
cache?: boolean;
};
};
methods?: { [key: string]: Function };
watch?: { [key: string]: Function | string };
get?: Function
set?: Function
cache?: boolean
}
}
methods?: { [key: string]: Function }
watch?: { [key: string]: Function | string }
// DOM
el?: string | Element;
template?: string;
render: (h: () => VNode) => VNode;
renderError?: (h: () => VNode, err: Error) => VNode;
staticRenderFns?: Array<() => VNode>;
el?: string | Element
template?: string
render: (h: () => VNode) => VNode
renderError?: (h: () => VNode, err: Error) => VNode
staticRenderFns?: Array<() => VNode>
// lifecycle
beforeCreate?: Function;
created?: Function;
beforeMount?: Function;
mounted?: Function;
beforeUpdate?: Function;
updated?: Function;
activated?: Function;
deactivated?: Function;
beforeDestroy?: Function;
destroyed?: Function;
errorCaptured?: () => boolean | void;
serverPrefetch?: Function;
beforeCreate?: Function
created?: Function
beforeMount?: Function
mounted?: Function
beforeUpdate?: Function
updated?: Function
activated?: Function
deactivated?: Function
beforeDestroy?: Function
destroyed?: Function
errorCaptured?: () => boolean | void
serverPrefetch?: Function
// assets
directives?: { [key: string]: object };
components?: { [key: string]: Component };
transitions?: { [key: string]: object };
filters?: { [key: string]: Function };
directives?: { [key: string]: object }
components?: { [key: string]: Component }
transitions?: { [key: string]: object }
filters?: { [key: string]: Function }
// context
provide?: Record<string | symbol, any> | (() => Record<string | symbol, any>);
provide?: Record<string | symbol, any> | (() => Record<string | symbol, any>)
inject?:
| { [key: string]: InjectKey | { from?: InjectKey; default?: any } }
| Array<string>;
| Array<string>
// component v-model customization
model?: {
prop?: string;
event?: string;
};
prop?: string
event?: string
}
// misc
parent?: Component;
mixins?: Array<object>;
name?: string;
extends?: Component | object;
delimiters?: [string, string];
comments?: boolean;
inheritAttrs?: boolean;
parent?: Component
mixins?: Array<object>
name?: string
extends?: Component | object
delimiters?: [string, string]
comments?: boolean
inheritAttrs?: boolean
// Class API
abstract?: any
// private
_isComponent?: true;
_propKeys?: Array<string>;
_parentVnode?: VNode;
_parentListeners?: object | null;
_renderChildren?: Array<VNode> | null;
_componentTag: string | null;
_scopeId: string | null;
_base: Component;
};
_isComponent?: true
_propKeys?: Array<string>
_parentVnode?: VNode
_parentListeners?: object | null
_renderChildren?: Array<VNode> | null
_componentTag: string | null
_scopeId: string | null
_base: Component
}
declare type PropOptions = {
type: Function | Array<Function> | null;
default: any;
required: boolean | null;
validator: Function | null;
};
type: Function | Array<Function> | null
default: any
required: boolean | null
validator: Function | null
}

34
typescript/ssr.d.ts vendored
View File

@ -1,27 +1,27 @@
import VNode from "../src/core/vdom/vnode";
import { Component } from "./component";
import VNode from '../src/core/vdom/vnode'
import { Component } from './component'
declare type ComponentWithCacheContext = {
type: "ComponentWithCache";
bufferIndex: number;
buffer: Array<string>;
key: string;
};
type: 'ComponentWithCache'
bufferIndex: number
buffer: Array<string>
key: string
}
declare type ElementContext = {
type: "Element";
children: Array<VNode>;
rendered: number;
endTag: string;
total: number;
};
type: 'Element'
children: Array<VNode>
rendered: number
endTag: string
total: number
}
declare type ComponentContext = {
type: "Component";
prevActive: Component;
};
type: 'Component'
prevActive: Component
}
declare type RenderState =
| ComponentContext
| ComponentWithCacheContext
| ElementContext;
| ElementContext

134
typescript/vnode.d.ts vendored
View File

@ -1,41 +1,41 @@
import VNode from "../src/core/vdom/vnode";
import { Component } from "./component";
import VNode from '../src/core/vdom/vnode'
import { Component } from './component'
declare type VNodeChildren =
| Array<null | VNode | string | VNodeChildren>
| string;
| string
declare type VNodeComponentOptions = {
Ctor: Component;
propsData?: Object;
listeners?: Record<string, Function | Function[]>;
children?: Array<VNode>;
tag?: string;
};
Ctor: Component
propsData?: Object
listeners?: Record<string, Function | Function[]>
children?: Array<VNode>
tag?: string
}
declare type MountedComponentVNode = VNode & {
context: Component;
componentOptions: VNodeComponentOptions;
componentInstance: Component;
parent: VNode;
data: VNodeData;
};
context: Component
componentOptions: VNodeComponentOptions
componentInstance: Component
parent: VNode
data: VNodeData
}
// interface for vnodes in update modules
declare type VNodeWithData = VNode & {
tag: string;
data: VNodeData;
children: Array<VNode>;
text: void;
elm: any;
ns: string | void;
context: Component;
key: string | number | undefined;
parent?: VNodeWithData;
componentOptions?: VNodeComponentOptions;
componentInstance?: Component;
isRootInsert: boolean;
};
tag: string
data: VNodeData
children: Array<VNode>
text: void
elm: any
ns: string | void
context: Component
key: string | number | undefined
parent?: VNodeWithData
componentOptions?: VNodeComponentOptions
componentInstance?: Component
isRootInsert: boolean
}
// // interface for vnodes in update modules
// declare type VNodeWithData = {
@ -54,51 +54,51 @@ declare type VNodeWithData = VNode & {
// };
declare interface VNodeData {
key?: string | number;
slot?: string;
ref?: string;
is?: string;
pre?: boolean;
tag?: string;
staticClass?: string;
class?: any;
staticStyle?: { [key: string]: any };
style?: string | Array<Object> | Object;
normalizedStyle?: Object;
props?: { [key: string]: any };
attrs?: { [key: string]: string };
domProps?: { [key: string]: any };
hook?: { [key: string]: Function };
on?: { [key: string]: Function | Array<Function> };
nativeOn?: { [key: string]: Function | Array<Function> };
transition?: Object;
show?: boolean; // marker for v-show
key?: string | number
slot?: string
ref?: string
is?: string
pre?: boolean
tag?: string
staticClass?: string
class?: any
staticStyle?: { [key: string]: any }
style?: string | Array<Object> | Object
normalizedStyle?: Object
props?: { [key: string]: any }
attrs?: { [key: string]: string }
domProps?: { [key: string]: any }
hook?: { [key: string]: Function }
on?: { [key: string]: Function | Array<Function> }
nativeOn?: { [key: string]: Function | Array<Function> }
transition?: Object
show?: boolean // marker for v-show
inlineTemplate?: {
render: Function;
staticRenderFns: Array<Function>;
};
directives?: Array<VNodeDirective>;
keepAlive?: boolean;
scopedSlots?: { [key: string]: Function };
render: Function
staticRenderFns: Array<Function>
}
directives?: Array<VNodeDirective>
keepAlive?: boolean
scopedSlots?: { [key: string]: Function }
model?: {
value: any;
callback: Function;
};
value: any
callback: Function
}
[key: string]: any;
[key: string]: any
}
declare type VNodeDirective = {
name: string;
rawName: string;
value?: any;
oldValue?: any;
arg?: string;
oldArg?: string;
modifiers?: ASTModifiers;
def?: Object;
};
name: string
rawName: string
value?: any
oldValue?: any
arg?: string
oldArg?: string
modifiers?: ASTModifiers
def?: Object
}
declare type ScopedSlotsData = Array<
{ key: string; fn: Function } | ScopedSlotsData
>;
>