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