From 32e0e63caf18c286e2287d9f4308228ae3000ab2 Mon Sep 17 00:00:00 2001 From: Ivo Gabe de Wolff Date: Tue, 11 Apr 2017 10:35:41 +0200 Subject: [PATCH 1/2] Mark fields nullable --- types/acorn/index.d.ts | 2 +- types/estree/flow.d.ts | 20 ++++++++++---------- types/estree/index.d.ts | 38 +++++++++++++++++++------------------- 3 files changed, 30 insertions(+), 30 deletions(-) diff --git a/types/acorn/index.d.ts b/types/acorn/index.d.ts index 441deb29c3..ce7da6d368 100644 --- a/types/acorn/index.d.ts +++ b/types/acorn/index.d.ts @@ -63,7 +63,7 @@ declare namespace acorn { class SourceLocation implements ESTree.SourceLocation { start: Position; end: Position; - source?: string; + source?: string | null; constructor(p: Parser, start: Position, end: Position); } diff --git a/types/estree/flow.d.ts b/types/estree/flow.d.ts index 76c76008e6..605765e8ec 100644 --- a/types/estree/flow.d.ts +++ b/types/estree/flow.d.ts @@ -26,20 +26,20 @@ declare namespace ESTree { interface ClassImplements extends Node { id: Identifier; - typeParameters?: TypeParameterInstantiation; + typeParameters?: TypeParameterInstantiation | null; } interface ClassProperty { key: Expression; - value?: Expression; - typeAnnotation?: TypeAnnotation; + value?: Expression | null; + typeAnnotation?: TypeAnnotation | null; computed: boolean; static: boolean; } interface DeclareClass extends FlowDeclaration { id: Identifier; - typeParameters?: TypeParameterDeclaration; + typeParameters?: TypeParameterDeclaration | null; body: ObjectTypeAnnotation; extends: Array; } @@ -60,8 +60,8 @@ declare namespace ESTree { interface FunctionTypeAnnotation extends FlowTypeAnnotation { params: Array; returnType: FlowTypeAnnotation; - rest?: FunctionTypeParam; - typeParameters?: TypeParameterDeclaration; + rest?: FunctionTypeParam | null; + typeParameters?: TypeParameterDeclaration | null; } interface FunctionTypeParam { @@ -72,17 +72,17 @@ declare namespace ESTree { interface GenericTypeAnnotation extends FlowTypeAnnotation { id: Identifier | QualifiedTypeIdentifier; - typeParameters?: TypeParameterInstantiation; + typeParameters?: TypeParameterInstantiation | null; } interface InterfaceExtends extends Node { id: Identifier | QualifiedTypeIdentifier; - typeParameters?: TypeParameterInstantiation; + typeParameters?: TypeParameterInstantiation | null; } interface InterfaceDeclaration extends FlowDeclaration { id: Identifier; - typeParameters?: TypeParameterDeclaration; + typeParameters?: TypeParameterDeclaration | null; extends: Array; body: ObjectTypeAnnotation; } @@ -115,7 +115,7 @@ declare namespace ESTree { interface TypeAlias extends FlowDeclaration { id: Identifier; - typeParameters?: TypeParameterDeclaration; + typeParameters?: TypeParameterDeclaration | null; right: FlowTypeAnnotation; } diff --git a/types/estree/index.d.ts b/types/estree/index.d.ts index 26bccf1731..b7a4005add 100644 --- a/types/estree/index.d.ts +++ b/types/estree/index.d.ts @@ -28,7 +28,7 @@ interface BaseNode { leadingComments?: Array; trailingComments?: Array; - loc?: SourceLocation; + loc?: SourceLocation | null; range?: [number, number]; } export type Node = @@ -42,7 +42,7 @@ export interface Comment { } interface SourceLocation { - source?: string; + source?: string | null; start: Position; end: Position; } @@ -100,7 +100,7 @@ export interface IfStatement extends BaseStatement { type: "IfStatement"; test: Expression; consequent: Statement; - alternate?: Statement; + alternate?: Statement | null; } export interface LabeledStatement extends BaseStatement { @@ -111,12 +111,12 @@ export interface LabeledStatement extends BaseStatement { export interface BreakStatement extends BaseStatement { type: "BreakStatement"; - label?: Identifier; + label?: Identifier | null; } export interface ContinueStatement extends BaseStatement { type: "ContinueStatement"; - label?: Identifier; + label?: Identifier | null; } export interface WithStatement extends BaseStatement { @@ -133,7 +133,7 @@ export interface SwitchStatement extends BaseStatement { export interface ReturnStatement extends BaseStatement { type: "ReturnStatement"; - argument?: Expression; + argument?: Expression | null; } export interface ThrowStatement extends BaseStatement { @@ -144,8 +144,8 @@ export interface ThrowStatement extends BaseStatement { export interface TryStatement extends BaseStatement { type: "TryStatement"; block: BlockStatement; - handler?: CatchClause; - finalizer?: BlockStatement; + handler?: CatchClause | null; + finalizer?: BlockStatement | null; } export interface WhileStatement extends BaseStatement { @@ -162,9 +162,9 @@ export interface DoWhileStatement extends BaseStatement { export interface ForStatement extends BaseStatement { type: "ForStatement"; - init?: VariableDeclaration | Expression; - test?: Expression; - update?: Expression; + init?: VariableDeclaration | Expression | null; + test?: Expression | null; + update?: Expression | null; body: Statement; } @@ -201,7 +201,7 @@ export interface VariableDeclaration extends BaseDeclaration { export interface VariableDeclarator extends BaseNode { type: "VariableDeclarator"; id: Pattern; - init?: Expression; + init?: Expression | null; } type Expression = @@ -239,7 +239,7 @@ export interface Property extends BaseNode { } export interface FunctionExpression extends BaseFunction, BaseExpression { - id?: Identifier; + id?: Identifier | null; type: "FunctionExpression"; body: BlockStatement; } @@ -319,7 +319,7 @@ interface BasePattern extends BaseNode { } export interface SwitchCase extends BaseNode { type: "SwitchCase"; - test?: Expression; + test?: Expression | null; consequent: Array; } @@ -389,7 +389,7 @@ export interface ArrowFunctionExpression extends BaseExpression, BaseFunction { export interface YieldExpression extends BaseExpression { type: "YieldExpression"; - argument?: Expression; + argument?: Expression | null; delegate: boolean; } @@ -443,7 +443,7 @@ export interface AssignmentPattern extends BasePattern { export type Class = ClassDeclaration | ClassExpression; interface BaseClass extends BaseNode { - superClass?: Expression; + superClass?: Expression | null; body: ClassBody; } @@ -468,7 +468,7 @@ export interface ClassDeclaration extends BaseClass, BaseDeclaration { export interface ClassExpression extends BaseClass, BaseExpression { type: "ClassExpression"; - id?: Identifier; + id?: Identifier | null; } export interface MetaProperty extends BaseExpression { @@ -510,9 +510,9 @@ export interface ImportNamespaceSpecifier extends BaseModuleSpecifier { export interface ExportNamedDeclaration extends BaseModuleDeclaration { type: "ExportNamedDeclaration"; - declaration?: Declaration; + declaration?: Declaration | null; specifiers: Array; - source?: Literal; + source?: Literal | null; } export interface ExportSpecifier extends BaseModuleSpecifier { From 9ae701b9ed4b8e76c29e0de6f70306f092a1f41b Mon Sep 17 00:00:00 2001 From: Ivo Gabe de Wolff Date: Tue, 11 Apr 2017 10:38:04 +0200 Subject: [PATCH 2/2] Update estree tests with nullable values --- types/estree/estree-tests.ts | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/types/estree/estree-tests.ts b/types/estree/estree-tests.ts index 0d4b8f5bd9..ace67225a4 100644 --- a/types/estree/estree-tests.ts +++ b/types/estree/estree-tests.ts @@ -123,7 +123,7 @@ expression = expressionStatement.expression; var ifStatement: ESTree.IfStatement; expression = ifStatement.test; statement = ifStatement.consequent; -var statementOrNull: ESTree.Statement | undefined = ifStatement.alternate; +var statementOrNull: ESTree.Statement | null | undefined = ifStatement.alternate; // LabeledStatement var labeledStatement: ESTree.LabeledStatement; @@ -141,18 +141,18 @@ switchCase = switchStatement.cases[0]; // ReturnStatement var returnStatement: ESTree.ReturnStatement; -var expressionMaybe: ESTree.Expression | undefined = returnStatement.argument; +var expressionMaybe: ESTree.Expression | null | undefined = returnStatement.argument; // TryStatement var tryStatement: ESTree.TryStatement; blockStatement = tryStatement.block; -var catchClauseMaybe: ESTree.CatchClause | undefined = tryStatement.handler; -var blockStatementMaybe: ESTree.BlockStatement | undefined = tryStatement.finalizer; +var catchClauseMaybe: ESTree.CatchClause | null | undefined = tryStatement.handler; +var blockStatementMaybe: ESTree.BlockStatement | null | undefined = tryStatement.finalizer; // ForStatement var forStatement: ESTree.ForStatement; -var variableDeclaratorOrExpressionMaybe: typeof variableDeclaratorOrExpression | undefined = forStatement.init; -var expressionMaybe: ESTree.Expression | undefined = forStatement.update; +var variableDeclaratorOrExpressionMaybe: typeof variableDeclaratorOrExpression | null | undefined = forStatement.init; +var expressionMaybe: ESTree.Expression | null | undefined = forStatement.update; // ForInStatement var forInStatement: ESTree.ForInStatement; @@ -176,7 +176,7 @@ string = property.kind; // FunctionExpression var functionExpression: ESTree.FunctionExpression; -var identifierMaybe: ESTree.Identifier | undefined = functionExpression.id; +var identifierMaybe: ESTree.Identifier | null | undefined = functionExpression.id; pattern = functionExpression.params[0]; pattern = assignmentPattern.left; expression = assignmentPattern.right;