compiler.js 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179
  1. declare type CompilerOptions = {
  2. warn?: Function; // allow customizing warning in different environments; e.g. node
  3. expectHTML?: boolean; // only false for non-web builds
  4. modules?: Array<ModuleOptions>; // platform specific modules; e.g. style; class
  5. staticKeys?: string; // a list of AST properties to be considered static; for optimization
  6. directives?: { [key: string]: Function }; // platform specific directives
  7. isUnaryTag?: (tag: string) => ?boolean; // check if a tag is unary for the platform
  8. isReservedTag?: (tag: string) => ?boolean; // check if a tag is a native for the platform
  9. mustUseProp?: (tag: string, type: ?string, name: string) => boolean; // check if an attribute should be bound as a property
  10. isPreTag?: (attr: string) => ?boolean; // check if a tag needs to preserve whitespace
  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. isFromDOM?: boolean;
  15. shouldDecodeTags?: boolean;
  16. shouldDecodeNewlines?: boolean;
  17. // runtime user-configurable
  18. delimiters?: [string, string]; // template delimiters
  19. }
  20. declare type CompiledResult = {
  21. ast: ?ASTElement;
  22. render: string;
  23. staticRenderFns: Array<string>;
  24. errors?: Array<string>;
  25. tips?: Array<string>;
  26. }
  27. declare type CompiledFunctionResult = {
  28. render: Function;
  29. staticRenderFns: Array<Function>;
  30. }
  31. declare type ModuleOptions = {
  32. preTransformNode: (el: ASTElement) => void;
  33. transformNode: (el: ASTElement) => void; // transform an element's AST node
  34. postTransformNode: (el: ASTElement) => void;
  35. genData: (el: ASTElement) => string; // generate extra data string for an element
  36. transformCode?: (el: ASTElement, code: string) => string; // further transform generated code for an element
  37. staticKeys?: Array<string>; // AST properties to be considered static
  38. }
  39. declare type ASTModifiers = { [key: string]: boolean }
  40. declare type ASTIfConditions = Array<{ exp: ?string; block: ASTElement }>
  41. declare type ASTElementHandler = {
  42. value: string;
  43. modifiers: ?ASTModifiers;
  44. }
  45. declare type ASTElementHandlers = {
  46. [key: string]: ASTElementHandler | Array<ASTElementHandler>;
  47. }
  48. declare type ASTDirective = {
  49. name: string;
  50. rawName: string;
  51. value: string;
  52. arg: ?string;
  53. modifiers: ?ASTModifiers;
  54. }
  55. declare type ASTNode = ASTElement | ASTText | ASTExpression
  56. declare type ASTElement = {
  57. type: 1;
  58. tag: string;
  59. attrsList: Array<{ name: string; value: string }>;
  60. attrsMap: { [key: string]: string | null };
  61. parent: ASTElement | void;
  62. children: Array<ASTNode>;
  63. static?: boolean;
  64. staticRoot?: boolean;
  65. staticInFor?: boolean;
  66. staticProcessed?: boolean;
  67. hasBindings?: boolean;
  68. text?: string;
  69. attrs?: Array<{ name: string; value: string }>;
  70. props?: Array<{ name: string; value: string }>;
  71. plain?: boolean;
  72. pre?: true;
  73. ns?: string;
  74. component?: string;
  75. inlineTemplate?: true;
  76. transitionMode?: string | null;
  77. slotName?: ?string;
  78. slotTarget?: ?string;
  79. slotScope?: ?string;
  80. scopedSlots?: { [name: string]: ASTElement };
  81. ref?: string;
  82. refInFor?: boolean;
  83. if?: string;
  84. ifProcessed?: boolean;
  85. elseif?: string;
  86. else?: true;
  87. ifConditions?: ASTIfConditions;
  88. for?: string;
  89. forProcessed?: boolean;
  90. key?: string;
  91. alias?: string;
  92. iterator1?: string;
  93. iterator2?: string;
  94. staticClass?: string;
  95. classBinding?: string;
  96. staticStyle?: string;
  97. styleBinding?: string;
  98. events?: ASTElementHandlers;
  99. nativeEvents?: ASTElementHandlers;
  100. transition?: string | true;
  101. transitionOnAppear?: boolean;
  102. model?: {
  103. value: string;
  104. callback: string;
  105. expression: string;
  106. };
  107. directives?: Array<ASTDirective>;
  108. forbidden?: true;
  109. once?: true;
  110. onceProcessed?: boolean;
  111. wrapData?: (code: string) => string;
  112. // weex specific
  113. appendAsTree?: boolean;
  114. }
  115. declare type ASTExpression = {
  116. type: 2;
  117. expression: string;
  118. text: string;
  119. static?: boolean;
  120. }
  121. declare type ASTText = {
  122. type: 3;
  123. text: string;
  124. static?: boolean;
  125. }
  126. // SFC-parser related declarations
  127. // an object format describing a single-file component.
  128. declare type SFCDescriptor = {
  129. template: ?SFCBlock;
  130. script: ?SFCBlock;
  131. styles: Array<SFCBlock>;
  132. customBlocks: Array<SFCCustomBlock>;
  133. }
  134. declare type SFCCustomBlock = {
  135. type: string;
  136. content: string;
  137. start?: number;
  138. end?: number;
  139. src?: string;
  140. attrs: {[attribute:string]: string};
  141. }
  142. declare type SFCBlock = {
  143. type: string;
  144. content: string;
  145. start?: number;
  146. end?: number;
  147. lang?: string;
  148. src?: string;
  149. scoped?: boolean;
  150. module?: string | boolean;
  151. }