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