compiler.js 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172
  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 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. directives?: Array<ASTDirective>;
  102. forbidden?: true;
  103. once?: true;
  104. onceProcessed?: boolean;
  105. wrapData?: (code: string) => string;
  106. // weex specific
  107. appendAsTree?: boolean;
  108. }
  109. declare type ASTExpression = {
  110. type: 2;
  111. expression: string;
  112. text: string;
  113. static?: boolean;
  114. }
  115. declare type ASTText = {
  116. type: 3;
  117. text: string;
  118. static?: boolean;
  119. }
  120. // SFC-parser related declarations
  121. // an object format describing a single-file component.
  122. declare type SFCDescriptor = {
  123. template: ?SFCBlock;
  124. script: ?SFCBlock;
  125. styles: Array<SFCBlock>;
  126. customBlocks: Array<SFCCustomBlock>;
  127. }
  128. declare type SFCCustomBlock = {
  129. type: string;
  130. content: string;
  131. start?: number;
  132. end?: number;
  133. src?: string;
  134. attrs: {[attribute:string]: string};
  135. }
  136. declare type SFCBlock = {
  137. type: string;
  138. content: string;
  139. start?: number;
  140. end?: number;
  141. lang?: string;
  142. src?: string;
  143. scoped?: boolean;
  144. module?: string | boolean;
  145. }