compiler.js 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  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. text?: string,
  58. attrs?: Array<{ name: string, value: string }>,
  59. props?: Array<{ name: string, value: string }>,
  60. staticAttrs?: Array<{ name: string, value: string }>,
  61. plain?: boolean,
  62. pre?: true,
  63. ns?: string,
  64. component?: string,
  65. keepAlive?: boolean,
  66. inlineTemplate?: true,
  67. transitionMode?: string | null,
  68. slotName?: ?string,
  69. slotTarget?: ?string,
  70. ref?: string,
  71. refInFor?: boolean,
  72. if?: string,
  73. ifProcessed?: boolean,
  74. else?: true,
  75. elseBlock?: ASTElement,
  76. for?: string,
  77. forProcessed?: boolean,
  78. key?: string,
  79. alias?: string,
  80. iterator1?: string,
  81. iterator2?: string,
  82. staticClass?: string,
  83. classBinding?: string,
  84. styleBinding?: string,
  85. hooks?: ASTElementHooks,
  86. events?: ASTElementHandlers,
  87. transition?: string | true,
  88. transitionOnAppear?: boolean,
  89. directives?: Array<ASTDirective>,
  90. forbidden?: true,
  91. once?: true
  92. }
  93. declare type ASTExpression = {
  94. type: 2,
  95. expression: string,
  96. text: string,
  97. static?: boolean
  98. }
  99. declare type ASTText = {
  100. type: 3,
  101. text: string,
  102. static?: boolean
  103. }
  104. // SFC-parser related declarations
  105. // an object format describing a single-file component.
  106. declare type SFCDescriptor = {
  107. template: ?SFCBlock,
  108. script: ?SFCBlock,
  109. styles: Array<SFCBlock>
  110. }
  111. declare type SFCBlock = {
  112. type: string,
  113. content: string,
  114. start?: number,
  115. end?: number,
  116. lang?: string,
  117. src?: string,
  118. scoped?: boolean
  119. }