compiler.js 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  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. 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. // runtime user-configurable
  17. delimiters?: [string, string]; // template delimiters
  18. }
  19. declare type CompiledResult = {
  20. ast: ?ASTElement;
  21. render: string;
  22. staticRenderFns: Array<string>;
  23. errors?: Array<string>;
  24. }
  25. declare type CompiledFunctionResult = {
  26. render: Function;
  27. staticRenderFns: Array<Function>;
  28. }
  29. declare type ModuleOptions = {
  30. preTransformNode: (el: ASTElement) => void;
  31. transformNode: (el: ASTElement) => void; // transform an element's AST node
  32. postTransformNode: (el: ASTElement) => void;
  33. genData: (el: ASTElement) => string; // generate extra data string for an element
  34. transformCode?: (el: ASTElement, code: string) => string; // further transform generated code for an element
  35. staticKeys?: Array<string>; // AST properties to be considered static
  36. }
  37. declare type ASTElementHandler = {
  38. value: string;
  39. modifiers: ?{ [key: string]: true };
  40. }
  41. declare type ASTElementHandlers = {
  42. [key: string]: ASTElementHandler | Array<ASTElementHandler>;
  43. }
  44. declare type ASTElementHooks = { [key: string]: Array<string> }
  45. declare type ASTDirective = {
  46. name: string;
  47. value: ?string;
  48. arg: ?string;
  49. modifiers: ?{ [key: string]: true };
  50. }
  51. declare type ASTNode = ASTElement | ASTText | ASTExpression
  52. declare type ASTElement = {
  53. type: 1;
  54. tag: string;
  55. attrsList: Array<{ name: string; value: string }>;
  56. attrsMap: { [key: string]: string | null };
  57. parent: ASTElement | void;
  58. children: Array<ASTNode>;
  59. static?: boolean;
  60. staticRoot?: boolean;
  61. staticProcessed?: boolean;
  62. text?: string;
  63. attrs?: Array<{ name: string; value: string }>;
  64. props?: Array<{ name: string; value: string }>;
  65. staticAttrs?: Array<{ name: string; value: string }>;
  66. plain?: boolean;
  67. pre?: true;
  68. ns?: string;
  69. component?: string;
  70. keepAlive?: boolean;
  71. inlineTemplate?: true;
  72. transitionMode?: string | null;
  73. slotName?: ?string;
  74. slotTarget?: ?string;
  75. ref?: string;
  76. refInFor?: boolean;
  77. if?: string;
  78. ifProcessed?: boolean;
  79. else?: true;
  80. elseBlock?: ASTElement;
  81. for?: string;
  82. forProcessed?: boolean;
  83. key?: string;
  84. alias?: string;
  85. iterator1?: string;
  86. iterator2?: string;
  87. staticClass?: string;
  88. classBinding?: string;
  89. styleBinding?: string;
  90. hooks?: ASTElementHooks;
  91. events?: ASTElementHandlers;
  92. nativeEvents?: ASTElementHandlers;
  93. transition?: string | true;
  94. transitionOnAppear?: boolean;
  95. directives?: Array<ASTDirective>;
  96. forbidden?: true;
  97. once?: true;
  98. }
  99. declare type ASTExpression = {
  100. type: 2;
  101. expression: string;
  102. text: string;
  103. static?: boolean;
  104. }
  105. declare type ASTText = {
  106. type: 3;
  107. text: string;
  108. static?: boolean;
  109. }
  110. // SFC-parser related declarations
  111. // an object format describing a single-file component.
  112. declare type SFCDescriptor = {
  113. template: ?SFCBlock;
  114. script: ?SFCBlock;
  115. styles: Array<SFCBlock>;
  116. }
  117. declare type SFCBlock = {
  118. type: string;
  119. content: string;
  120. start?: number;
  121. end?: number;
  122. lang?: string;
  123. src?: string;
  124. scoped?: boolean;
  125. }