compiler.d.ts 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224
  1. declare type CompilerOptions = {
  2. warn?: Function // allow customizing warning in different environments; e.g. node
  3. modules?: Array<ModuleOptions> // platform specific modules; e.g. style; class
  4. directives?: { [key: string]: Function } // platform specific directives
  5. staticKeys?: string // a list of AST properties to be considered static; for optimization
  6. isUnaryTag?: (tag: string) => boolean | undefined // check if a tag is unary for the platform
  7. canBeLeftOpenTag?: (tag: string) => boolean | undefined // check if a tag can be left opened
  8. isReservedTag?: (tag: string) => boolean | undefined // check if a tag is a native for the platform
  9. preserveWhitespace?: boolean // preserve whitespace between elements? (Deprecated)
  10. whitespace?: 'preserve' | 'condense' // whitespace handling strategy
  11. optimize?: boolean // optimize static content?
  12. // web specific
  13. mustUseProp?: (tag: string, type: string | null, name: string) => boolean // check if an attribute should be bound as a property
  14. isPreTag?: (attr: string) => boolean | null // check if a tag needs to preserve whitespace
  15. getTagNamespace?: (tag: string) => string | undefined // check the namespace for a tag
  16. expectHTML?: boolean // only false for non-web builds
  17. isFromDOM?: boolean
  18. shouldDecodeTags?: boolean
  19. shouldDecodeNewlines?: boolean
  20. shouldDecodeNewlinesForHref?: boolean
  21. outputSourceRange?: boolean
  22. // runtime user-configurable
  23. delimiters?: [string, string] // template delimiters
  24. comments?: boolean // preserve comments in template
  25. // for ssr optimization compiler
  26. scopeId?: string
  27. }
  28. declare type WarningMessage = {
  29. msg: string
  30. start?: number
  31. end?: number
  32. }
  33. declare type CompiledResult = {
  34. ast: ASTElement | null
  35. render: string
  36. staticRenderFns: Array<string>
  37. stringRenderFns?: Array<string>
  38. errors?: Array<string | WarningMessage>
  39. tips?: Array<string | WarningMessage>
  40. }
  41. declare type ModuleOptions = {
  42. // transform an AST node before any attributes are processed
  43. // returning an ASTElement from pre/transforms replaces the element
  44. preTransformNode: (el: ASTElement) => ASTElement | null
  45. // transform an AST node after built-ins like v-if, v-for are processed
  46. transformNode: (el: ASTElement) => ASTElement | null
  47. // transform an AST node after its children have been processed
  48. // cannot return replacement in postTransform because tree is already finalized
  49. postTransformNode: (el: ASTElement) => void
  50. genData: (el: ASTElement) => string // generate extra data string for an element
  51. transformCode?: (el: ASTElement, code: string) => string // further transform generated code for an element
  52. staticKeys?: Array<string> // AST properties to be considered static
  53. }
  54. declare type ASTModifiers = { [key: string]: boolean }
  55. declare type ASTIfCondition = { exp: string | null; block: ASTElement }
  56. declare type ASTIfConditions = Array<ASTIfCondition>
  57. declare type ASTAttr = {
  58. name: string
  59. value: any
  60. dynamic?: boolean
  61. start?: number
  62. end?: number
  63. }
  64. declare type ASTElementHandler = {
  65. value: string
  66. params?: Array<any>
  67. modifiers: ASTModifiers | null
  68. dynamic?: boolean
  69. start?: number
  70. end?: number
  71. }
  72. declare type ASTElementHandlers = {
  73. [key: string]: ASTElementHandler | Array<ASTElementHandler>
  74. }
  75. declare type ASTDirective = {
  76. name: string
  77. rawName: string
  78. value: string
  79. arg: string | null
  80. isDynamicArg: boolean
  81. modifiers: ASTModifiers | null
  82. start?: number
  83. end?: number
  84. }
  85. declare type ASTNode = ASTElement | ASTText | ASTExpression
  86. declare type ASTElement = {
  87. type: 1
  88. tag: string
  89. attrsList: Array<ASTAttr>
  90. attrsMap: { [key: string]: any }
  91. rawAttrsMap: { [key: string]: ASTAttr }
  92. parent: ASTElement | void
  93. children: Array<ASTNode>
  94. start?: number
  95. end?: number
  96. processed?: true
  97. static?: boolean
  98. staticRoot?: boolean
  99. staticInFor?: boolean
  100. staticProcessed?: boolean
  101. hasBindings?: boolean
  102. text?: string
  103. attrs?: Array<ASTAttr>
  104. dynamicAttrs?: Array<ASTAttr>
  105. props?: Array<ASTAttr>
  106. plain?: boolean
  107. pre?: true
  108. ns?: string
  109. component?: string
  110. inlineTemplate?: true
  111. transitionMode?: string | null
  112. slotName?: string | null
  113. slotTarget?: string | null
  114. slotTargetDynamic?: boolean
  115. slotScope?: string | null
  116. scopedSlots?: { [name: string]: ASTElement }
  117. ref?: string
  118. refInFor?: boolean
  119. if?: string
  120. ifProcessed?: boolean
  121. elseif?: string
  122. else?: true
  123. ifConditions?: ASTIfConditions
  124. for?: string
  125. forProcessed?: boolean
  126. key?: string
  127. alias?: string
  128. iterator1?: string
  129. iterator2?: string
  130. staticClass?: string
  131. classBinding?: string
  132. staticStyle?: string
  133. styleBinding?: string
  134. events?: ASTElementHandlers
  135. nativeEvents?: ASTElementHandlers
  136. transition?: string | true
  137. transitionOnAppear?: boolean
  138. model?: {
  139. value: string
  140. callback: string
  141. expression: string
  142. }
  143. directives?: Array<ASTDirective>
  144. forbidden?: true
  145. once?: true
  146. onceProcessed?: boolean
  147. wrapData?: (code: string) => string
  148. wrapListeners?: (code: string) => string
  149. // 2.4 ssr optimization
  150. ssrOptimizability?: number
  151. }
  152. declare type ASTExpression = {
  153. type: 2
  154. expression: string
  155. text: string
  156. tokens: Array<string | Object>
  157. static?: boolean
  158. // 2.4 ssr optimization
  159. ssrOptimizability?: number
  160. start?: number
  161. end?: number
  162. }
  163. declare type ASTText = {
  164. type: 3
  165. text: string
  166. static?: boolean
  167. isComment?: boolean
  168. // 2.4 ssr optimization
  169. ssrOptimizability?: number
  170. start?: number
  171. end?: number
  172. }
  173. // SFC-parser related declarations
  174. // an object format describing a single-file component
  175. declare type SFCDescriptor = {
  176. template: SFCBlock | null
  177. script: SFCBlock | null
  178. styles: Array<SFCBlock>
  179. customBlocks: Array<SFCBlock>
  180. errors: Array<string | WarningMessage>
  181. }
  182. declare type SFCBlock = {
  183. type: string
  184. content: string
  185. attrs: { [attribute: string]: string }
  186. start?: number
  187. end?: number
  188. lang?: string
  189. src?: string
  190. scoped?: boolean
  191. module?: string | boolean
  192. }