compiler.js 3.8 KB

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