compiler.js 4.5 KB

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