Skip to content

Commit

Permalink
test(ast-spec): add fixtures for all declaration nodes (#4967)
Browse files Browse the repository at this point in the history
  • Loading branch information
bradzacher committed May 20, 2022
1 parent 7e7b24c commit 450dd47
Show file tree
Hide file tree
Showing 724 changed files with 21,796 additions and 155 deletions.
70 changes: 70 additions & 0 deletions packages/ast-spec/src/base/ClassBase.ts
@@ -0,0 +1,70 @@
import type { Identifier } from '../expression/Identifier/spec';
import type { ClassBody } from '../special/ClassBody/spec';
import type { Decorator } from '../special/Decorator/spec';
import type { TSClassImplements } from '../special/TSClassImplements/spec';
import type { TSTypeParameterDeclaration } from '../special/TSTypeParameterDeclaration/spec';
import type { TSTypeParameterInstantiation } from '../special/TSTypeParameterInstantiation/spec';
import type { LeftHandSideExpression } from '../unions/LeftHandSideExpression';
import type { BaseNode } from './BaseNode';

export interface ClassBase extends BaseNode {
/**
* Whether the class is an abstract class.
* ```
* abstract class Foo {...}
* ```
* This is always `undefined` for `ClassExpression`.
*/
// TODO(#5020) - make this `false` if it is not `abstract`
abstract?: boolean;
/**
* The class body.
*/
body: ClassBody;
/**
* Whether the class has been `declare`d:
* ```
* declare class Foo {...}
* ```
* This is always `undefined` for `ClassExpression`.
*/
// TODO(#5020) - make this `false` if it is not `declare`d
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[];
/**
* The class's name.
* - For a `ClassExpression` this may be `null` if the name is omitted.
* - For a `ClassDeclaration` this may be `null` if and only if the parent is
* an `ExportDefaultDeclaration`.
*/
id: Identifier | null;
/**
* The implemented interfaces for the class.
* This is `undefined` if there are no implemented interfaces.
*/
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.
*/
superTypeParameters?: TSTypeParameterInstantiation;
/**
* The generic type parameters declared for the class.
* This is `undefined` if there are no generic type parameters declared.
*/
typeParameters?: TSTypeParameterDeclaration;
}
20 changes: 0 additions & 20 deletions packages/ast-spec/src/base/ClassDeclarationBase.ts

This file was deleted.

74 changes: 74 additions & 0 deletions packages/ast-spec/src/base/FunctionBase.ts
@@ -0,0 +1,74 @@
import type { Identifier } from '../expression/Identifier/spec';
import type { TSTypeAnnotation } from '../special/TSTypeAnnotation/spec';
import type { TSTypeParameterDeclaration } from '../special/TSTypeParameterDeclaration/spec';
import type { BlockStatement } from '../statement/BlockStatement/spec';
import type { Expression } from '../unions/Expression';
import type { Parameter } from '../unions/Parameter';
import type { BaseNode } from './BaseNode';

export interface FunctionBase extends BaseNode {
/**
* Whether the function is async:
* ```
* async function foo(...) {...}
* const x = async function (...) {...}
* const x = async (...) => {...}
* ```
*/
async: boolean;
/**
* The body of the function.
* - For an `ArrowFunctionExpression` this may be an `Expression` or `BlockStatement`.
* - For a `FunctionDeclaration` or `FunctionExpression` this is always a `BlockStatement.
* - For a `TSDeclareFunction` this is always `undefined`.
* - For a `TSEmptyBodyFunctionExpression` this is always `null`.
*/
body?: BlockStatement | Expression | null;
/**
* 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;
/**
* This is only ever `true` if and only the node is an `ArrowFunctionExpression` and the body
* is an expression:
* ```
* (() => 1)
* ```
*/
expression: boolean;
/**
* Whether the function is a generator function:
* ```
* function *foo(...) {...}
* const x = function *(...) {...}
* ```
* This is always `false` for arrow functions as they cannot be generators.
*/
generator: boolean;
/**
* The function's name.
* - For an `ArrowFunctionExpression` this is always `null`.
* - For a `FunctionExpression` this may be `null` if the name is omitted.
* - For a `FunctionDeclaration` or `TSDeclareFunction` this may be `null` if
* and only if the parent is an `ExportDefaultDeclaration`.
*/
id: Identifier | null;
/**
* The list of parameters declared for the function.
*/
params: Parameter[];
/**
* The return type annotation for the function.
* This is `undefined` if there is no return type declared.
*/
returnType?: TSTypeAnnotation;
/**
* The generic type parameter declaration for the function.
* This is `undefined` if there are no generic type parameters declared.
*/
typeParameters?: TSTypeParameterDeclaration;
}
18 changes: 0 additions & 18 deletions packages/ast-spec/src/base/FunctionDeclarationBase.ts

This file was deleted.

2 changes: 1 addition & 1 deletion packages/ast-spec/src/base/TSHeritageBase.ts
Expand Up @@ -3,7 +3,7 @@ import type { Expression } from '../unions/Expression';
import type { BaseNode } from './BaseNode';

export interface TSHeritageBase extends BaseNode {
// TODO(error handling) - this should be restricted to MemberExpression | Identifier
// TODO(#1852) - this should be restricted to MemberExpression | Identifier
expression: Expression;
typeParameters?: TSTypeParameterInstantiation;
}
@@ -0,0 +1,3 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`AST Fixtures declaration ClassDeclaration _error_ missing-body TSESTree - Error 1`] = `[TSError: '{' expected.]`;
@@ -0,0 +1,3 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`AST Fixtures declaration ClassDeclaration _error_ missing-body Babel - Error 1`] = `[SyntaxError: Unexpected token, expected "{" (1:9)]`;
@@ -0,0 +1,3 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`AST Fixtures declaration ClassDeclaration _error_ missing-body Error Alignment 1`] = `"Both errored"`;
@@ -0,0 +1 @@
class C extends D<> {}
@@ -0,0 +1,3 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`AST Fixtures declaration ClassDeclaration _error_ missing-extends-type-param TSESTree - Error 1`] = `"NO ERROR"`;
@@ -0,0 +1,3 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`AST Fixtures declaration ClassDeclaration _error_ missing-extends-type-param Babel - Error 1`] = `[SyntaxError: Type argument list cannot be empty. (1:17)]`;
@@ -0,0 +1,3 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`AST Fixtures declaration ClassDeclaration _error_ missing-extends-type-param Error Alignment 1`] = `"Babel errored but TSESTree didn't"`;
@@ -0,0 +1 @@
class C<> {}
@@ -0,0 +1,3 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`AST Fixtures declaration ClassDeclaration _error_ missing-type-param TSESTree - Error 1`] = `"NO ERROR"`;
@@ -0,0 +1,3 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`AST Fixtures declaration ClassDeclaration _error_ missing-type-param Babel - Error 1`] = `[SyntaxError: Type parameter list cannot be empty. (1:7)]`;
@@ -0,0 +1,3 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`AST Fixtures declaration ClassDeclaration _error_ missing-type-param Error Alignment 1`] = `"Babel errored but TSESTree didn't"`;

This file was deleted.

This file was deleted.

This file was deleted.

@@ -0,0 +1 @@
class C<1> {}
@@ -0,0 +1,3 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`AST Fixtures declaration ClassDeclaration _error_ non-identifier-type-param TSESTree - Error 1`] = `[TSError: Type parameter declaration expected.]`;
@@ -0,0 +1,3 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`AST Fixtures declaration ClassDeclaration _error_ non-identifier-type-param Babel - Error 1`] = `[SyntaxError: Unexpected token (1:8)]`;
@@ -0,0 +1,3 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`AST Fixtures declaration ClassDeclaration _error_ non-identifier-type-param Error Alignment 1`] = `"Both errored"`;
@@ -1,6 +1,6 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`AST Fixtures declaration ClassDeclaration decoratorMany TSESTree - AST 1`] = `
exports[`AST Fixtures declaration ClassDeclaration decorator-many TSESTree - AST 1`] = `
Program {
type: "Program",
body: Array [
Expand Down
@@ -1,6 +1,6 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`AST Fixtures declaration ClassDeclaration decoratorMany TSESTree - Tokens 1`] = `
exports[`AST Fixtures declaration ClassDeclaration decorator-many TSESTree - Tokens 1`] = `
Array [
Punctuator {
type: "Punctuator",
Expand Down
@@ -1,6 +1,6 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`AST Fixtures declaration ClassDeclaration decoratorMany Babel - AST 1`] = `
exports[`AST Fixtures declaration ClassDeclaration decorator-many Babel - AST 1`] = `
Program {
type: "Program",
body: Array [
Expand Down
@@ -1,6 +1,6 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`AST Fixtures declaration ClassDeclaration decoratorMany Babel - Tokens 1`] = `
exports[`AST Fixtures declaration ClassDeclaration decorator-many Babel - Tokens 1`] = `
Array [
Punctuator {
type: "Punctuator",
Expand Down
@@ -0,0 +1,6 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`AST Fixtures declaration ClassDeclaration decorator-many AST Alignment - AST 1`] = `
"Snapshot Diff:
Compared values have no visual difference."
`;
@@ -0,0 +1,6 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`AST Fixtures declaration ClassDeclaration decorator-many AST Alignment - Token 1`] = `
"Snapshot Diff:
Compared values have no visual difference."
`;
@@ -1,6 +1,6 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`AST Fixtures declaration ClassDeclaration decoratorOne TSESTree - AST 1`] = `
exports[`AST Fixtures declaration ClassDeclaration decorator-one TSESTree - AST 1`] = `
Program {
type: "Program",
body: Array [
Expand Down
@@ -1,6 +1,6 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`AST Fixtures declaration ClassDeclaration decoratorOne TSESTree - Tokens 1`] = `
exports[`AST Fixtures declaration ClassDeclaration decorator-one TSESTree - Tokens 1`] = `
Array [
Punctuator {
type: "Punctuator",
Expand Down
@@ -1,6 +1,6 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`AST Fixtures declaration ClassDeclaration decoratorOne Babel - AST 1`] = `
exports[`AST Fixtures declaration ClassDeclaration decorator-one Babel - AST 1`] = `
Program {
type: "Program",
body: Array [
Expand Down
@@ -1,6 +1,6 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`AST Fixtures declaration ClassDeclaration decoratorOne Babel - Tokens 1`] = `
exports[`AST Fixtures declaration ClassDeclaration decorator-one Babel - Tokens 1`] = `
Array [
Punctuator {
type: "Punctuator",
Expand Down
@@ -1,6 +1,6 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`AST Fixtures declaration ClassDeclaration decoratorMany AST Alignment - AST 1`] = `
exports[`AST Fixtures declaration ClassDeclaration decorator-one AST Alignment - AST 1`] = `
"Snapshot Diff:
Compared values have no visual difference."
`;
@@ -1,6 +1,6 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`AST Fixtures declaration ClassDeclaration decoratorMany AST Alignment - Token 1`] = `
exports[`AST Fixtures declaration ClassDeclaration decorator-one AST Alignment - Token 1`] = `
"Snapshot Diff:
Compared values have no visual difference."
`;
@@ -1,6 +1,6 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`AST Fixtures declaration ClassDeclaration extends-type-parameters TSESTree - AST 1`] = `
exports[`AST Fixtures declaration ClassDeclaration extends-type-param TSESTree - AST 1`] = `
Program {
type: "Program",
body: Array [
Expand Down
@@ -1,6 +1,6 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`AST Fixtures declaration ClassDeclaration extends-type-parameters TSESTree - Tokens 1`] = `
exports[`AST Fixtures declaration ClassDeclaration extends-type-param TSESTree - Tokens 1`] = `
Array [
Keyword {
type: "Keyword",
Expand Down
@@ -1,6 +1,6 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`AST Fixtures declaration ClassDeclaration extends-type-parameters Babel - AST 1`] = `
exports[`AST Fixtures declaration ClassDeclaration extends-type-param Babel - AST 1`] = `
Program {
type: "Program",
body: Array [
Expand Down
@@ -1,6 +1,6 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`AST Fixtures declaration ClassDeclaration extends-type-parameters Babel - Tokens 1`] = `
exports[`AST Fixtures declaration ClassDeclaration extends-type-param Babel - Tokens 1`] = `
Array [
Keyword {
type: "Keyword",
Expand Down
@@ -1,6 +1,6 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`AST Fixtures declaration ClassDeclaration extends-type-parameters AST Alignment - AST 1`] = `
exports[`AST Fixtures declaration ClassDeclaration extends-type-param AST Alignment - AST 1`] = `
"Snapshot Diff:
Compared values have no visual difference."
`;

0 comments on commit 450dd47

Please sign in to comment.