compiler.js 4.6 KB

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