compiler.js 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168
  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. ref?: string;
  78. refInFor?: boolean;
  79. if?: string;
  80. ifProcessed?: boolean;
  81. else?: true;
  82. elseBlock?: ASTElement;
  83. for?: string;
  84. forProcessed?: boolean;
  85. key?: string;
  86. alias?: string;
  87. iterator1?: string;
  88. iterator2?: string;
  89. staticClass?: string;
  90. classBinding?: string;
  91. staticStyle?: string;
  92. styleBinding?: string;
  93. events?: ASTElementHandlers;
  94. nativeEvents?: ASTElementHandlers;
  95. transition?: string | true;
  96. transitionOnAppear?: boolean;
  97. directives?: Array<ASTDirective>;
  98. forbidden?: true;
  99. once?: true;
  100. onceProcessed?: boolean;
  101. wrapData?: (code: string) => string;
  102. // weex specific
  103. atom?: boolean;
  104. }
  105. declare type ASTExpression = {
  106. type: 2;
  107. expression: string;
  108. text: string;
  109. static?: boolean;
  110. }
  111. declare type ASTText = {
  112. type: 3;
  113. text: string;
  114. static?: boolean;
  115. }
  116. // SFC-parser related declarations
  117. // an object format describing a single-file component.
  118. declare type SFCDescriptor = {
  119. template: ?SFCBlock;
  120. script: ?SFCBlock;
  121. styles: Array<SFCBlock>;
  122. customBlocks: Array<SFCCustomBlock>;
  123. }
  124. declare type SFCCustomBlock = {
  125. type: string;
  126. content: string;
  127. start?: number;
  128. end?: number;
  129. src?: string;
  130. attrs: {[attribute:string]: string};
  131. }
  132. declare type SFCBlock = {
  133. type: string;
  134. content: string;
  135. start?: number;
  136. end?: number;
  137. lang?: string;
  138. src?: string;
  139. scoped?: boolean;
  140. module?: string | boolean;
  141. }