Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(typescript-estree): remove optionality from AST boolean properties #6274

  •  
  •  
  •  
24 changes: 7 additions & 17 deletions packages/ast-spec/src/base/ClassBase.ts
Expand Up @@ -13,10 +13,8 @@ export interface ClassBase extends BaseNode {
* ```
* abstract class Foo {...}
* ```
* This is always `undefined` for `ClassExpression`.
*/
// TODO(#5020) - make this `false` if it is not `abstract`
abstract?: boolean;
abstract: boolean;
/**
* The class body.
*/
Expand All @@ -26,21 +24,16 @@ export interface ClassBase extends BaseNode {
* ```
* declare class Foo {...}
* ```
* This is always `undefined` for `ClassExpression`.
*/
// TODO(#5020) - make this `false` if it is not `declare`d
declare?: boolean;
declare: boolean;
/**
* The decorators declared for the class.
* This is `undefined` if there are no decorators.
* ```
* @deco
* class Foo {...}
* ```
* This is always `undefined` for `ClassExpression`.
*/
// TODO(#5020) - make this an empty array if there are none declared
decorators?: Decorator[];
decorators: Decorator[];
/**
* The class's name.
* - For a `ClassExpression` this may be `null` if the name is omitted.
Expand All @@ -50,25 +43,22 @@ export interface ClassBase extends BaseNode {
id: Identifier | null;
/**
* The implemented interfaces for the class.
* This is `undefined` if there are no implemented interfaces.
*/
implements?: TSClassImplements[];
implements: TSClassImplements[];
/**
* The super class this class extends.
*/
superClass: LeftHandSideExpression | null;
/**
* The generic type parameters passed to the superClass.
* This is `undefined` if there are no generic type parameters passed.
*/
superTypeArguments?: TSTypeParameterInstantiation;
superTypeArguments: TSTypeParameterInstantiation | undefined;

/** @deprecated Use {@link `superTypeArguments`} instead. */
superTypeParameters?: TSTypeParameterInstantiation;
superTypeParameters: TSTypeParameterInstantiation | undefined;

/**
* The generic type parameters declared for the class.
* This is `undefined` if there are no generic type parameters declared.
*/
typeParameters?: TSTypeParameterDeclaration;
typeParameters: TSTypeParameterDeclaration | undefined;
}
11 changes: 4 additions & 7 deletions packages/ast-spec/src/base/FunctionBase.ts
Expand Up @@ -23,15 +23,14 @@ export interface FunctionBase extends BaseNode {
* - For a `TSDeclareFunction` this is always `undefined`.
* - For a `TSEmptyBodyFunctionExpression` this is always `null`.
*/
body?: BlockStatement | Expression | null;
body: BlockStatement | Expression | null | undefined;
/**
* This is only `true` if and only if the node is a `TSDeclareFunction` and it has `declare`:
* ```
* declare function foo(...) {...}
* ```
*/
// TODO(#5020) - make this always `false` if it is not `declare`d instead of `undefined`
declare?: boolean;
declare: boolean;
/**
* This is only ever `true` if and only the node is an `ArrowFunctionExpression` and the body
* is an expression:
Expand Down Expand Up @@ -63,12 +62,10 @@ export interface FunctionBase extends BaseNode {
params: Parameter[];
/**
* The return type annotation for the function.
* This is `undefined` if there is no return type declared.
*/
returnType?: TSTypeAnnotation;
returnType: TSTypeAnnotation | undefined;
/**
* The generic type parameter declaration for the function.
* This is `undefined` if there are no generic type parameters declared.
*/
typeParameters?: TSTypeParameterDeclaration;
typeParameters: TSTypeParameterDeclaration | undefined;
}
8 changes: 4 additions & 4 deletions packages/ast-spec/src/base/MethodDefinitionBase.ts
Expand Up @@ -17,10 +17,10 @@ interface MethodDefinitionBase extends BaseNode {
computed: boolean;
static: boolean;
kind: 'constructor' | 'get' | 'method' | 'set';
optional?: boolean;
decorators?: Decorator[];
accessibility?: Accessibility;
override?: boolean;
optional: boolean;
decorators: Decorator[];
accessibility: Accessibility | undefined;
override: boolean;
}

export interface MethodDefinitionComputedNameBase extends MethodDefinitionBase {
Expand Down
14 changes: 7 additions & 7 deletions packages/ast-spec/src/base/PropertyDefinitionBase.ts
Expand Up @@ -16,13 +16,13 @@ interface PropertyDefinitionBase extends BaseNode {
computed: boolean;
static: boolean;
declare: boolean;
readonly?: boolean;
decorators?: Decorator[];
accessibility?: Accessibility;
optional?: boolean;
definite?: boolean;
typeAnnotation?: TSTypeAnnotation;
override?: boolean;
readonly: boolean;
decorators: Decorator[];
accessibility: Accessibility | undefined;
optional: boolean;
definite: boolean;
typeAnnotation: TSTypeAnnotation | undefined;
override: boolean;
}

export interface PropertyDefinitionComputedNameBase
Expand Down
4 changes: 2 additions & 2 deletions packages/ast-spec/src/base/TSFunctionSignatureBase.ts
Expand Up @@ -5,6 +5,6 @@ import type { BaseNode } from './BaseNode';

export interface TSFunctionSignatureBase extends BaseNode {
params: Parameter[];
returnType?: TSTypeAnnotation;
typeParameters?: TSTypeParameterDeclaration;
returnType: TSTypeAnnotation | undefined;
typeParameters: TSTypeParameterDeclaration | undefined;
}
4 changes: 2 additions & 2 deletions packages/ast-spec/src/base/TSHeritageBase.ts
Expand Up @@ -5,8 +5,8 @@ import type { BaseNode } from './BaseNode';
export interface TSHeritageBase extends BaseNode {
// TODO(#1852) - this should be restricted to MemberExpression | Identifier
expression: Expression;
typeArguments?: TSTypeParameterInstantiation;
typeArguments: TSTypeParameterInstantiation | undefined;

/** @deprecated Use {@link `typeArguments`} instead. */
typeParameters?: TSTypeParameterInstantiation;
typeParameters: TSTypeParameterInstantiation | undefined;
}
Expand Up @@ -17,16 +17,21 @@ Program {
end: { column: 21, line: 1 },
},
},
declare: false,
decorators: Array [],
id: Identifier {
type: "Identifier",
decorators: Array [],
name: "Foo",
optional: false,

range: [15, 18],
loc: {
start: { column: 15, line: 1 },
end: { column: 18, line: 1 },
},
},
implements: Array [],
superClass: null,

range: [0, 21],
Expand Down
Expand Up @@ -2,5 +2,55 @@

exports[`AST Fixtures declaration ClassDeclaration abstract AST Alignment - AST 1`] = `
"Snapshot Diff:
Compared values have no visual difference."
- TSESTree
+ Babel

Program {
type: 'Program',
body: Array [
ClassDeclaration {
type: 'ClassDeclaration',
abstract: true,
body: ClassBody {
type: 'ClassBody',
body: Array [],

range: [19, 21],
loc: {
start: { column: 19, line: 1 },
end: { column: 21, line: 1 },
},
},
- declare: false,
- decorators: Array [],
id: Identifier {
type: 'Identifier',
- decorators: Array [],
name: 'Foo',
- optional: false,

range: [15, 18],
loc: {
start: { column: 15, line: 1 },
end: { column: 18, line: 1 },
},
},
- implements: Array [],
superClass: null,

range: [0, 21],
loc: {
start: { column: 0, line: 1 },
end: { column: 21, line: 1 },
},
},
],
sourceType: 'script',

range: [0, 22],
loc: {
start: { column: 0, line: 1 },
end: { column: 0, line: 2 },
},
}"
`;
Expand Up @@ -6,6 +6,7 @@ Program {
body: Array [
ClassDeclaration {
type: "ClassDeclaration",
abstract: false,
body: ClassBody {
type: "ClassBody",
body: Array [],
Expand All @@ -17,16 +18,20 @@ Program {
},
},
declare: true,
decorators: Array [],
id: Identifier {
type: "Identifier",
decorators: Array [],
name: "Foo",
optional: false,

range: [14, 17],
loc: {
start: { column: 14, line: 1 },
end: { column: 17, line: 1 },
},
},
implements: Array [],
superClass: null,

range: [0, 20],
Expand Down
Expand Up @@ -2,5 +2,55 @@

exports[`AST Fixtures declaration ClassDeclaration declare AST Alignment - AST 1`] = `
"Snapshot Diff:
Compared values have no visual difference."
- TSESTree
+ Babel

Program {
type: 'Program',
body: Array [
ClassDeclaration {
type: 'ClassDeclaration',
- abstract: false,
body: ClassBody {
type: 'ClassBody',
body: Array [],

range: [18, 20],
loc: {
start: { column: 18, line: 1 },
end: { column: 20, line: 1 },
},
},
declare: true,
- decorators: Array [],
id: Identifier {
type: 'Identifier',
- decorators: Array [],
name: 'Foo',
- optional: false,

range: [14, 17],
loc: {
start: { column: 14, line: 1 },
end: { column: 17, line: 1 },
},
},
- implements: Array [],
superClass: null,

range: [0, 20],
loc: {
start: { column: 0, line: 1 },
end: { column: 20, line: 1 },
},
},
],
sourceType: 'script',

range: [0, 21],
loc: {
start: { column: 0, line: 1 },
end: { column: 0, line: 2 },
},
}"
`;
Expand Up @@ -6,6 +6,7 @@ Program {
body: Array [
ClassDeclaration {
type: "ClassDeclaration",
abstract: false,
body: ClassBody {
type: "ClassBody",
body: Array [],
Expand All @@ -16,12 +17,15 @@ Program {
end: { column: 12, line: 3 },
},
},
declare: false,
decorators: Array [
Decorator {
type: "Decorator",
expression: Identifier {
type: "Identifier",
decorators: Array [],
name: "decoratorOne",
optional: false,

range: [1, 13],
loc: {
Expand All @@ -40,7 +44,9 @@ Program {
type: "Decorator",
expression: Identifier {
type: "Identifier",
decorators: Array [],
name: "decoratorTwo",
optional: false,

range: [15, 27],
loc: {
Expand All @@ -58,14 +64,17 @@ Program {
],
id: Identifier {
type: "Identifier",
decorators: Array [],
name: "Foo",
optional: false,

range: [34, 37],
loc: {
start: { column: 6, line: 3 },
end: { column: 9, line: 3 },
},
},
implements: Array [],
superClass: null,

range: [0, 40],
Expand Down