diff --git a/ast/spec.md b/ast/spec.md index 0ff1c87c51..07c6a6482d 100644 --- a/ast/spec.md +++ b/ast/spec.md @@ -144,13 +144,13 @@ interface Position { ### Babylon 7 Flow: Node renamed from `ExistentialTypeParam` to `ExistsTypeAnnotation` [#322](https://github.com/babel/babylon/pull/322) - + Flow: Node renamed from `NumericLiteralTypeAnnotation` to `NumberLiteralTypeAnnotation` [babel/babylon#332](https://github.com/babel/babylon/pull/332) - + Flow: Node `Variance` which replaces the string value of the `variance` field on several nodes [babel/babylon#333](https://github.com/babel/babylon/pull/333) Flow: `ObjectTypeIndexer` location info matches Flow's better [babel/babylon#228](https://github.com/babel/babylon/pull/228) - + Node `ForAwaitStatement` has been removed [#349](https://github.com/babel/babylon/pull/349) in favor of modifying `ForOfStatement` `RestProperty` and `SpreadProperty` have been dropped in favor of `RestElement` and `SpreadElement`. @@ -514,7 +514,7 @@ interface FunctionDeclaration <: Function, Declaration { } ``` -A function declaration. Note that unlike in the parent interface `Function`, the `id` cannot be `null`. +A function declaration. Note that unlike in the parent interface `Function`, the `id` cannot be `null`, except when this is the child of an `ExportDefaultDeclaration`. ## VariableDeclaration @@ -1166,9 +1166,17 @@ An exported variable binding, e.g., `{foo}` in `export {foo}` or `{bar as foo}` ### ExportDefaultDeclaration ```js +interface OptFunctionDeclaration <: FunctionDeclaration { + id: Identifier | null; +} + +interface OptClasDeclaration <: ClassDeclaration { + id: Identifier | null; +} + interface ExportDefaultDeclaration <: ModuleDeclaration { type: "ExportDefaultDeclaration"; - declaration: Declaration | Expression; + declaration: OptFunctionDeclaration | OptClassDeclaration | Expression; } ``` diff --git a/src/types.js b/src/types.js index b42f72a154..e76d738994 100644 --- a/src/types.js +++ b/src/types.js @@ -266,11 +266,14 @@ export type ForOfStatement = ForInOfBase & { // Declarations -export type FunctionDeclaration = FunctionBase & DeclarationBase & HasDecorators & { +export type OptFunctionDeclaration = FunctionBase & DeclarationBase & HasDecorators & { type: "FunctionDeclaration"; - id: Identifier; }; +export type FunctionDeclaration = OptFunctionDeclaration & { + id: Identifier; +} + export type VariableDeclaration = DeclarationBase & HasDecorators & { type: "VariableDeclaration"; declarations: $ReadOnlyArray; @@ -581,13 +584,16 @@ export type ClassProperty = ClassMemberBase & { readonly?: true; }; -export type ClassDeclaration = ClassBase & DeclarationBase & HasDecorators & { +export type OptClassDeclaration = ClassBase & DeclarationBase & HasDecorators & { type: "ClassDeclaration"; - id: Identifier; // TypeScript only abstract?: ?true; }; +export type ClassDeclaration = OptClassDeclaration & { + id: Identifier; +}; + export type ClassExpression = ClassBase & { type: "ClassExpression" }; export type MetaProperty = NodeBase & { @@ -653,7 +659,7 @@ export type ExportSpecifier = NodeBase & { export type ExportDefaultDeclaration = NodeBase & { type: "ExportDefaultDeclaration"; - declaration: Declaration | Expression; + declaration: OptFunctionDeclaration | OptClassDeclaration | Expression; }; export type ExportAllDeclaration = NodeBase & {