Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion types/estree/estree-tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,8 @@ boolean = memberExpression.computed;

// Declarations
var functionDeclaration: ESTree.FunctionDeclaration;
identifier = functionDeclaration.id;
var identifierOrNull: ESTree.Identifier | null = functionDeclaration.id;
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

functionDeclaration.id = null would be a better test, as the identifierOrNull test wouldn't fail even without the change to the declaration.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think I'll keep both. In any case you can assign nullable functionDeclaration.id to a not nullable identifier.

functionDeclaration.id = null;
var params: Array<ESTree.Pattern> = functionDeclaration.params;
blockStatement = functionDeclaration.body;
booleanMaybe = functionDeclaration.generator;
Expand All @@ -237,6 +238,10 @@ var variableDeclarator: ESTree.VariableDeclarator;
pattern = variableDeclarator.id; // Pattern
expressionMaybe = variableDeclarator.init;

var classDeclaration: ESTree.ClassDeclaration;
identifierOrNull = classDeclaration.id;
classDeclaration.id = null;

// Clauses
// SwitchCase
string = switchCase.type;
Expand Down
6 changes: 4 additions & 2 deletions types/estree/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,8 @@ interface BaseDeclaration extends BaseStatement { }

export interface FunctionDeclaration extends BaseFunction, BaseDeclaration {
type: "FunctionDeclaration";
id: Identifier;
/** It is null when a function declaration is a part of the `export default function` statement */
id: Identifier | null;
body: BlockStatement;
}

Expand Down Expand Up @@ -473,7 +474,8 @@ export interface MethodDefinition extends BaseNode {

export interface ClassDeclaration extends BaseClass, BaseDeclaration {
type: "ClassDeclaration";
id: Identifier;
/** It is null when a class declaration is a part of the `export default class` statement */
id: Identifier | null;
}

export interface ClassExpression extends BaseClass, BaseExpression {
Expand Down