compiler.js 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170
  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, attr: 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 ASTElementHandler = {
  40. value: string;
  41. modifiers: ?ASTModifiers;
  42. }
  43. declare type ASTElementHandlers = {
  44. [key: string]: ASTElementHandler | Array<ASTElementHandler>;
  45. }
  46. declare type ASTDirective = {
  47. name: string;
  48. rawName: string;
  49. value: string;
  50. arg: ?string;
  51. modifiers: ?ASTModifiers;
  52. }
  53. declare type ASTNode = ASTElement | ASTText | ASTExpression
  54. declare type ASTElement = {
  55. type: 1;
  56. tag: string;
  57. attrsList: Array<{ name: string; value: string }>;
  58. attrsMap: { [key: string]: string | null };
  59. parent: ASTElement | void;
  60. children: Array<ASTNode>;
  61. static?: boolean;
  62. staticRoot?: boolean;
  63. staticInFor?: boolean;
  64. staticProcessed?: boolean;
  65. hasBindings?: boolean;
  66. text?: string;
  67. attrs?: Array<{ name: string; value: string }>;
  68. props?: Array<{ name: string; value: string }>;
  69. plain?: boolean;
  70. pre?: true;
  71. ns?: string;
  72. component?: string;
  73. inlineTemplate?: true;
  74. transitionMode?: string | null;
  75. slotName?: ?string;
  76. slotTarget?: ?string;
  77. slotScope?: ?string;
  78. scopedSlots?: { [name: string]: ASTElement };
  79. ref?: string;
  80. refInFor?: boolean;
  81. if?: string;
  82. ifProcessed?: boolean;
  83. else?: true;
  84. elseBlock?: ASTElement;
  85. for?: string;
  86. forProcessed?: boolean;
  87. key?: string;
  88. alias?: string;
  89. iterator1?: string;
  90. iterator2?: string;
  91. staticClass?: string;
  92. classBinding?: string;
  93. staticStyle?: string;
  94. styleBinding?: string;
  95. events?: ASTElementHandlers;
  96. nativeEvents?: ASTElementHandlers;
  97. transition?: string | true;
  98. transitionOnAppear?: boolean;
  99. directives?: Array<ASTDirective>;
  100. forbidden?: true;
  101. once?: true;
  102. onceProcessed?: boolean;
  103. wrapData?: (code: string) => string;
  104. // weex specific
  105. atom?: boolean;
  106. }
  107. declare type ASTExpression = {
  108. type: 2;
  109. expression: string;
  110. text: string;
  111. static?: boolean;
  112. }
  113. declare type ASTText = {
  114. type: 3;
  115. text: string;
  116. static?: boolean;
  117. }
  118. // SFC-parser related declarations
  119. // an object format describing a single-file component.
  120. declare type SFCDescriptor = {
  121. template: ?SFCBlock;
  122. script: ?SFCBlock;
  123. styles: Array<SFCBlock>;
  124. customBlocks: Array<SFCCustomBlock>;
  125. }
  126. declare type SFCCustomBlock = {
  127. type: string;
  128. content: string;
  129. start?: number;
  130. end?: number;
  131. src?: string;
  132. attrs: {[attribute:string]: string};
  133. }
  134. declare type SFCBlock = {
  135. type: string;
  136. content: string;
  137. start?: number;
  138. end?: number;
  139. lang?: string;
  140. src?: string;
  141. scoped?: boolean;
  142. module?: string | boolean;
  143. }