compiler.js 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  1. declare type CompilerOptions = {
  2. warn?: Function, // allow customizing warning in different environments, e.g. node
  3. isIE?: boolean, // for detecting IE SVG innerHTML bug
  4. expectHTML?: boolean, // only false for non-web builds
  5. modules?: Array<ModuleOptions>, // platform specific modules, e.g. style, class
  6. staticKeys?: string, // a list of AST properties to be considered static, for optimization
  7. directives?: { [key: string]: Function }, // platform specific directives
  8. isUnaryTag?: (tag: string) => ?boolean, // check if a tag is unary for the platform
  9. isReservedTag?: (tag: string) => ?boolean, // check if a tag is a native for the platform
  10. mustUseProp?: (attr: string) => ?boolean, // check if an attribute should be bound as a property
  11. getTagNamespace?: (tag: string) => ?string, // check the namespace for a tag
  12. transforms?: Array<Function>, // a list of transforms on parsed AST before codegen
  13. preserveWhitespace?: boolean,
  14. // runtime user-configurable
  15. delimiters?: [string, string] // template delimiters
  16. }
  17. declare type CompiledResult = {
  18. ast: ?ASTElement,
  19. render: string,
  20. staticRenderFns: Array<string>,
  21. errors?: Array<string>
  22. }
  23. declare type CompiledFunctionResult = {
  24. render: Function,
  25. staticRenderFns: Array<Function>
  26. }
  27. declare type ModuleOptions = {
  28. transformNode: (el: ASTElement) => void, // transform an element's AST node
  29. genData: (el: ASTElement) => string, // generate extra data string for an element
  30. transformCode?: (el: ASTElement, code: string) => string, // further transform generated code for an element
  31. staticKeys?: Array<string> // AST properties to be considered static
  32. }
  33. declare type ASTElementHandler = {
  34. value: string,
  35. modifiers: ?{ [key: string]: true }
  36. }
  37. declare type ASTElementHandlers = {
  38. [key: string]: ASTElementHandler | Array<ASTElementHandler>
  39. }
  40. declare type ASTElementHooks = { [key: string]: Array<string> }
  41. declare type ASTDirective = {
  42. name: string,
  43. value: ?string,
  44. arg: ?string,
  45. modifiers: ?{ [key: string]: true }
  46. }
  47. declare type ASTNode = ASTElement | ASTText | ASTExpression
  48. declare type ASTElement = {
  49. type: 1,
  50. tag: string,
  51. attrsList: Array<{ name: string, value: string }>,
  52. attrsMap: { [key: string]: string | null },
  53. parent: ASTElement | void,
  54. children: Array<ASTNode>,
  55. static?: boolean,
  56. staticRoot?: boolean,
  57. staticProcessed?: boolean,
  58. text?: string,
  59. attrs?: Array<{ name: string, value: string }>,
  60. props?: Array<{ name: string, value: string }>,
  61. staticAttrs?: Array<{ name: string, value: string }>,
  62. plain?: boolean,
  63. pre?: true,
  64. ns?: string,
  65. component?: string,
  66. keepAlive?: boolean,
  67. inlineTemplate?: true,
  68. transitionMode?: string | null,
  69. slotName?: ?string,
  70. slotTarget?: ?string,
  71. ref?: string,
  72. refInFor?: boolean,
  73. if?: string,
  74. ifProcessed?: boolean,
  75. else?: true,
  76. elseBlock?: ASTElement,
  77. for?: string,
  78. forProcessed?: boolean,
  79. key?: string,
  80. alias?: string,
  81. iterator1?: string,
  82. iterator2?: string,
  83. staticClass?: string,
  84. classBinding?: string,
  85. styleBinding?: string,
  86. hooks?: ASTElementHooks,
  87. events?: ASTElementHandlers,
  88. transition?: string | true,
  89. transitionOnAppear?: boolean,
  90. directives?: Array<ASTDirective>,
  91. forbidden?: true,
  92. once?: true
  93. }
  94. declare type ASTExpression = {
  95. type: 2,
  96. expression: string,
  97. text: string,
  98. static?: boolean
  99. }
  100. declare type ASTText = {
  101. type: 3,
  102. text: string,
  103. static?: boolean
  104. }
  105. // SFC-parser related declarations
  106. // an object format describing a single-file component.
  107. declare type SFCDescriptor = {
  108. template: ?SFCBlock,
  109. script: ?SFCBlock,
  110. styles: Array<SFCBlock>
  111. }
  112. declare type SFCBlock = {
  113. type: string,
  114. content: string,
  115. start?: number,
  116. end?: number,
  117. lang?: string,
  118. src?: string,
  119. scoped?: boolean
  120. }