Просмотр исходного кода

use more proper flow type syntax

Evan You 9 лет назад
Родитель
Сommit
3ce450b6dc
3 измененных файлов с 161 добавлено и 160 удалено
  1. 103 102
      flow/compiler.js
  2. 43 43
      flow/options.js
  3. 15 15
      flow/vnode.js

+ 103 - 102
flow/compiler.js

@@ -1,146 +1,147 @@
 declare type CompilerOptions = {
-  warn?: Function, // allow customizing warning in different environments, e.g. node
-  isIE?: boolean, // for detecting IE SVG innerHTML bug
-  expectHTML?: boolean, // only false for non-web builds
-  modules?: Array<ModuleOptions>, // platform specific modules, e.g. style, class
-  staticKeys?: string, // a list of AST properties to be considered static, for optimization
-  directives?: { [key: string]: Function }, // platform specific directives
-  isUnaryTag?: (tag: string) => ?boolean, // check if a tag is unary for the platform
-  isReservedTag?: (tag: string) => ?boolean, // check if a tag is a native for the platform
-  mustUseProp?: (attr: string) => ?boolean, // check if an attribute should be bound as a property
-  getTagNamespace?: (tag: string) => ?string, // check the namespace for a tag
-  transforms?: Array<Function>, // a list of transforms on parsed AST before codegen
-  preserveWhitespace?: boolean,
+  warn?: Function; // allow customizing warning in different environments; e.g. node
+  isIE?: boolean; // for detecting IE SVG innerHTML bug
+  expectHTML?: boolean; // only false for non-web builds
+  modules?: Array<ModuleOptions>; // platform specific modules; e.g. style; class
+  staticKeys?: string; // a list of AST properties to be considered static; for optimization
+  directives?: { [key: string]: Function }; // platform specific directives
+  isUnaryTag?: (tag: string) => ?boolean; // check if a tag is unary for the platform
+  isReservedTag?: (tag: string) => ?boolean; // check if a tag is a native for the platform
+  mustUseProp?: (attr: string) => ?boolean; // check if an attribute should be bound as a property
+  getTagNamespace?: (tag: string) => ?string; // check the namespace for a tag
+  transforms?: Array<Function>; // a list of transforms on parsed AST before codegen
+  preserveWhitespace?: boolean;
+  shouldDecodeAttr?: boolean;
 
   // runtime user-configurable
-  delimiters?: [string, string] // template delimiters
+  delimiters?: [string, string]; // template delimiters
 }
 
 declare type CompiledResult = {
-  ast: ?ASTElement,
-  render: string,
-  staticRenderFns: Array<string>,
-  errors?: Array<string>
+  ast: ?ASTElement;
+  render: string;
+  staticRenderFns: Array<string>;
+  errors?: Array<string>;
 }
 
 declare type CompiledFunctionResult = {
-  render: Function,
-  staticRenderFns: Array<Function>
+  render: Function;
+  staticRenderFns: Array<Function>;
 }
 
 declare type ModuleOptions = {
-  transformNode: (el: ASTElement) => void, // transform an element's AST node
-  genData: (el: ASTElement) => string, // generate extra data string for an element
-  transformCode?: (el: ASTElement, code: string) => string, // further transform generated code for an element
-  staticKeys?: Array<string> // AST properties to be considered static
+  transformNode: (el: ASTElement) => void; // transform an element's AST node
+  genData: (el: ASTElement) => string; // generate extra data string for an element
+  transformCode?: (el: ASTElement, code: string) => string; // further transform generated code for an element
+  staticKeys?: Array<string>; // AST properties to be considered static
 }
 
 declare type ASTElementHandler = {
-  value: string,
-  modifiers: ?{ [key: string]: true }
+  value: string;
+  modifiers: ?{ [key: string]: true };
 }
 
 declare type ASTElementHandlers = {
-  [key: string]: ASTElementHandler | Array<ASTElementHandler>
+  [key: string]: ASTElementHandler | Array<ASTElementHandler>;
 }
 
 declare type ASTElementHooks = { [key: string]: Array<string> }
 
 declare type ASTDirective = {
-  name: string,
-  value: ?string,
-  arg: ?string,
-  modifiers: ?{ [key: string]: true }
+  name: string;
+  value: ?string;
+  arg: ?string;
+  modifiers: ?{ [key: string]: true };
 }
 
 declare type ASTNode = ASTElement | ASTText | ASTExpression
 
 declare type ASTElement = {
-  type: 1,
-  tag: string,
-  attrsList: Array<{ name: string, value: string }>,
-  attrsMap: { [key: string]: string | null },
-  parent: ASTElement | void,
-  children: Array<ASTNode>,
-
-  static?: boolean,
-  staticRoot?: boolean,
-  staticProcessed?: boolean,
-
-  text?: string,
-  attrs?: Array<{ name: string, value: string }>,
-  props?: Array<{ name: string, value: string }>,
-  staticAttrs?: Array<{ name: string, value: string }>,
-  plain?: boolean,
-  pre?: true,
-  ns?: string,
-
-  component?: string,
-  keepAlive?: boolean,
-  inlineTemplate?: true,
-  transitionMode?: string | null,
-  slotName?: ?string,
-  slotTarget?: ?string,
-
-  ref?: string,
-  refInFor?: boolean,
-
-  if?: string,
-  ifProcessed?: boolean,
-  else?: true,
-  elseBlock?: ASTElement,
-
-  for?: string,
-  forProcessed?: boolean,
-  key?: string,
-  alias?: string,
-  iterator1?: string,
-  iterator2?: string,
-
-  staticClass?: string,
-  classBinding?: string,
-  styleBinding?: string,
-  hooks?: ASTElementHooks,
-  events?: ASTElementHandlers,
-  nativeEvents?: ASTElementHandlers,
-
-  transition?: string | true,
-  transitionOnAppear?: boolean,
-
-  directives?: Array<ASTDirective>,
-
-  forbidden?: true,
-  once?: true
+  type: 1;
+  tag: string;
+  attrsList: Array<{ name: string; value: string }>;
+  attrsMap: { [key: string]: string | null };
+  parent: ASTElement | void;
+  children: Array<ASTNode>;
+
+  static?: boolean;
+  staticRoot?: boolean;
+  staticProcessed?: boolean;
+
+  text?: string;
+  attrs?: Array<{ name: string; value: string }>;
+  props?: Array<{ name: string; value: string }>;
+  staticAttrs?: Array<{ name: string; value: string }>;
+  plain?: boolean;
+  pre?: true;
+  ns?: string;
+
+  component?: string;
+  keepAlive?: boolean;
+  inlineTemplate?: true;
+  transitionMode?: string | null;
+  slotName?: ?string;
+  slotTarget?: ?string;
+
+  ref?: string;
+  refInFor?: boolean;
+
+  if?: string;
+  ifProcessed?: boolean;
+  else?: true;
+  elseBlock?: ASTElement;
+
+  for?: string;
+  forProcessed?: boolean;
+  key?: string;
+  alias?: string;
+  iterator1?: string;
+  iterator2?: string;
+
+  staticClass?: string;
+  classBinding?: string;
+  styleBinding?: string;
+  hooks?: ASTElementHooks;
+  events?: ASTElementHandlers;
+  nativeEvents?: ASTElementHandlers;
+
+  transition?: string | true;
+  transitionOnAppear?: boolean;
+
+  directives?: Array<ASTDirective>;
+
+  forbidden?: true;
+  once?: true;
 }
 
 declare type ASTExpression = {
-  type: 2,
-  expression: string,
-  text: string,
-  static?: boolean
+  type: 2;
+  expression: string;
+  text: string;
+  static?: boolean;
 }
 
 declare type ASTText = {
-  type: 3,
-  text: string,
-  static?: boolean
+  type: 3;
+  text: string;
+  static?: boolean;
 }
 
 // SFC-parser related declarations
 
 // an object format describing a single-file component.
 declare type SFCDescriptor = {
-  template: ?SFCBlock,
-  script: ?SFCBlock,
-  styles: Array<SFCBlock>
+  template: ?SFCBlock;
+  script: ?SFCBlock;
+  styles: Array<SFCBlock>;
 }
 
 declare type SFCBlock = {
-  type: string,
-  content: string,
-  start?: number,
-  end?: number,
-  lang?: string,
-  src?: string,
-  scoped?: boolean
+  type: string;
+  content: string;
+  start?: number;
+  end?: number;
+  lang?: string;
+  src?: string;
+  scoped?: boolean;
 }

+ 43 - 43
flow/options.js

@@ -1,68 +1,68 @@
 declare type InternalComponentOptions = {
-  _isComponent: true,
-  parent: Component,
-  propsData: ?Object,
-  _parentVnode: VNode,
-  _parentListeners: ?Object,
-  _renderChildren: ?VNodeChildren,
-  _componentTag: ?string,
-  render?: Function,
+  _isComponent: true;
+  parent: Component;
+  propsData: ?Object;
+  _parentVnode: VNode;
+  _parentListeners: ?Object;
+  _renderChildren: ?VNodeChildren;
+  _componentTag: ?string;
+  render?: Function;
   staticRenderFns?: Array<Function>
 }
 
 declare type ComponentOptions = {
   // data
-  data: Object | Function | void,
-  props?: { [key: string]: PropOptions },
-  propsData?: ?Object,
+  data: Object | Function | void;
+  props?: { [key: string]: PropOptions };
+  propsData?: ?Object;
   computed?: {
     [key: string]: Function | {
-      get?: Function,
-      set?: Function,
+      get?: Function;
+      set?: Function;
       cache?: boolean
     }
-  },
+  };
   methods?: {
     [key: string]: Function
-  },
+  };
   watch?: {
     [key: string]: Function | string
-  },
+  };
   // DOM
-  el?: string | Element,
-  template?: string,
-  render: () => VNode,
-  staticRenderFns?: Array<() => VNode>,
+  el?: string | Element;
+  template?: string;
+  render: () => VNode;
+  staticRenderFns?: Array<() => VNode>;
   // lifecycle
-  init?: Function,
-  created?: Function,
-  beforeMount?: Function,
-  mounted?: Function,
-  beforeUpdate?: Function,
-  updated?: Function,
+  init?: Function;
+  created?: Function;
+  beforeMount?: Function;
+  mounted?: Function;
+  beforeUpdate?: Function;
+  updated?: Function;
   // assets
-  directives?: { [key: string]: Object },
-  components?: { [key: string]: Class<Component> },
-  transitions?: { [key: string]: Object },
-  filters?: { [key: string]: Function },
+  directives?: { [key: string]: Object };
+  components?: { [key: string]: Class<Component> };
+  transitions?: { [key: string]: Object };
+  filters?: { [key: string]: Function };
   // misc
-  parent?: Component,
-  mixins?: Array<Object>,
-  name?: string,
-  extends?: Class<Component> | Object,
-  delimiters?: [string, string],
+  parent?: Component;
+  mixins?: Array<Object>;
+  name?: string;
+  extends?: Class<Component> | Object;
+  delimiters?: [string, string];
 
   // private
-  _isComponent?: true,
-  _propKeys?: Array<string>,
-  _parentVnode?: VNode,
-  _parentListeners?: ?Object,
+  _isComponent?: true;
+  _propKeys?: Array<string>;
+  _parentVnode?: VNode;
+  _parentListeners?: ?Object;
   _renderChildren?: ?VNodeChildren
 }
 
 declare type PropOptions = {
-  type: Function | Array<Function> | null,
-  default: any,
-  required: ?boolean,
-  validator: ?Function
+  type: Function | Array<Function> | null;
+  default: any;
+  required: ?boolean;
+  validator: ?Function;
 }

+ 15 - 15
flow/vnode.js

@@ -1,15 +1,15 @@
 declare type VNodeChildren = Array<any> | () => Array<any> | string
 
 declare type VNodeComponentOptions = {
-  Ctor: Class<Component>,
-  propsData: ?Object,
-  listeners: ?Object,
-  parent: Component,
-  children: ?VNodeChildren,
-  tag?: string
+  Ctor: Class<Component>;
+  propsData: ?Object;
+  listeners: ?Object;
+  parent: Component;
+  children: ?VNodeChildren;
+  tag?: string;
 }
 
-declare interface MountedComponentVNode {
+declare type MountedComponentVNode = {
   componentOptions: VNodeComponentOptions;
   child: Component;
   parent: VNode;
@@ -17,7 +17,7 @@ declare interface MountedComponentVNode {
 }
 
 // interface for vnodes in update modules
-declare interface VNodeWithData {
+declare type VNodeWithData = {
   tag: string;
   data: VNodeData;
   children: Array<VNode> | void;
@@ -48,17 +48,17 @@ declare interface VNodeData {
   nativeOn?: { [key: string]: Function | Array<Function> };
   transition?: Object;
   inlineTemplate?: {
-    render: Function,
-    staticRenderFns: Array<Function>
+    render: Function;
+    staticRenderFns: Array<Function>;
   };
   directives?: Array<VNodeDirective>;
   keepAlive?: boolean;
 }
 
 declare type VNodeDirective = {
-  name: string,
-  value?: any,
-  oldValue?: any,
-  arg?: string,
-  modifiers?: { [key: string]: boolean }
+  name: string;
+  value?: any;
+  oldValue?: any;
+  arg?: string;
+  modifiers?: { [key: string]: boolean };
 }