2
0

compiler.js 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  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. rawName: string;
  49. value: string;
  50. arg: ?string;
  51. modifiers: ?{ [key: string]: true };
  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. styleBinding?: string;
  92. events?: ASTElementHandlers;
  93. nativeEvents?: ASTElementHandlers;
  94. transition?: string | true;
  95. transitionOnAppear?: boolean;
  96. directives?: Array<ASTDirective>;
  97. forbidden?: true;
  98. once?: true;
  99. wrapData?: (code: string) => string;
  100. }
  101. declare type ASTExpression = {
  102. type: 2;
  103. expression: string;
  104. text: string;
  105. static?: boolean;
  106. }
  107. declare type ASTText = {
  108. type: 3;
  109. text: string;
  110. static?: boolean;
  111. }
  112. // SFC-parser related declarations
  113. // an object format describing a single-file component.
  114. declare type SFCDescriptor = {
  115. template: ?SFCBlock;
  116. script: ?SFCBlock;
  117. styles: Array<SFCBlock>;
  118. }
  119. declare type SFCBlock = {
  120. type: string;
  121. content: string;
  122. start?: number;
  123. end?: number;
  124. lang?: string;
  125. src?: string;
  126. scoped?: boolean;
  127. }