compiler.js 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159
  1. declare type CompilerOptions = {
  2. warn?: Function; // allow customizing warning in different environments; e.g. node
  3. isIE?: boolean; // for detecting IE SVG innerHTML bug
  4. expectHTML?: boolean; // only false for non-web builds
  5. modules?: Array<ModuleOptions>; // platform specific modules; e.g. style; class
  6. staticKeys?: string; // a list of AST properties to be considered static; for optimization
  7. directives?: { [key: string]: Function }; // platform specific directives
  8. isUnaryTag?: (tag: string) => ?boolean; // check if a tag is unary for the platform
  9. isReservedTag?: (tag: string) => ?boolean; // check if a tag is a native for the platform
  10. mustUseProp?: (attr: 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. }
  27. declare type CompiledFunctionResult = {
  28. render: Function;
  29. staticRenderFns: Array<Function>;
  30. }
  31. declare type ModuleOptions = {
  32. preTransformNode: (el: ASTElement) => void;
  33. transformNode: (el: ASTElement) => void; // transform an element's AST node
  34. postTransformNode: (el: ASTElement) => void;
  35. genData: (el: ASTElement) => string; // generate extra data string for an element
  36. transformCode?: (el: ASTElement, code: string) => string; // further transform generated code for an element
  37. staticKeys?: Array<string>; // AST properties to be considered static
  38. }
  39. declare type ASTModifiers = { [key: string]: boolean }
  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. ref?: string;
  79. refInFor?: boolean;
  80. if?: string;
  81. ifProcessed?: boolean;
  82. else?: true;
  83. elseBlock?: ASTElement;
  84. for?: string;
  85. forProcessed?: boolean;
  86. key?: string;
  87. alias?: string;
  88. iterator1?: string;
  89. iterator2?: string;
  90. staticClass?: string;
  91. classBinding?: string;
  92. staticStyle?: string;
  93. styleBinding?: string;
  94. events?: ASTElementHandlers;
  95. nativeEvents?: ASTElementHandlers;
  96. transition?: string | true;
  97. transitionOnAppear?: boolean;
  98. directives?: Array<ASTDirective>;
  99. forbidden?: true;
  100. once?: true;
  101. onceProcessed?: boolean;
  102. wrapData?: (code: string) => string;
  103. // weex specific
  104. atom?: boolean;
  105. }
  106. declare type ASTExpression = {
  107. type: 2;
  108. expression: string;
  109. text: string;
  110. static?: boolean;
  111. }
  112. declare type ASTText = {
  113. type: 3;
  114. text: string;
  115. static?: boolean;
  116. }
  117. // SFC-parser related declarations
  118. // an object format describing a single-file component.
  119. declare type SFCDescriptor = {
  120. template: ?SFCBlock;
  121. script: ?SFCBlock;
  122. styles: Array<SFCBlock>;
  123. }
  124. declare type SFCBlock = {
  125. type: string;
  126. content: string;
  127. start?: number;
  128. end?: number;
  129. lang?: string;
  130. src?: string;
  131. scoped?: boolean;
  132. module?: string | boolean;
  133. }