Skip to content

Commit

Permalink
feat: #467 - Wrap ClassExpression.
Browse files Browse the repository at this point in the history
  • Loading branch information
dsherret committed Oct 21, 2018
1 parent fdb5f42 commit 92f4be3
Show file tree
Hide file tree
Showing 10 changed files with 1,424 additions and 1,325 deletions.
19 changes: 18 additions & 1 deletion lib/ts-simple-ast.d.ts

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions src/compiler/ast/CompilerNodeToWrappedType.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ export type CompilerNodeToWrappedType<T extends ts.Node> = T extends ts.ArrayBin
T extends ts.BindingElement ? compiler.BindingElement :
T extends ts.ObjectBindingPattern ? compiler.ObjectBindingPattern :
T extends ts.ClassDeclaration ? compiler.ClassDeclaration :
T extends ts.ClassExpression ? compiler.ClassExpression :
T extends ts.ConstructorDeclaration ? compiler.ConstructorDeclaration :
T extends ts.GetAccessorDeclaration ? compiler.GetAccessorDeclaration :
T extends ts.MethodDeclaration ? compiler.MethodDeclaration :
Expand Down
7 changes: 7 additions & 0 deletions src/compiler/ast/class/ClassExpression.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { ts } from "../../../typescript";
import { ClassLikeDeclarationBase } from "./base";
import { PrimaryExpression } from "../expression/PrimaryExpression";

export const ClassExpressionBase = ClassLikeDeclarationBase(PrimaryExpression);
export class ClassExpression extends ClassExpressionBase<ts.ClassExpression> {
}
1 change: 1 addition & 0 deletions src/compiler/ast/class/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
export * from "./base";
export * from "./ClassDeclaration";
export * from "./ClassExpression";
export * from "./ConstructorDeclaration";
export * from "./GetAccessorDeclaration";
export * from "./MethodDeclaration";
Expand Down
2 changes: 2 additions & 0 deletions src/compiler/ast/kindToNodeMappings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ export interface KindToNodeMappings {
[SyntaxKind.CaseClause]: compiler.CaseClause;
[SyntaxKind.CatchClause]: compiler.CatchClause;
[SyntaxKind.ClassDeclaration]: compiler.ClassDeclaration;
[SyntaxKind.ClassExpression]: compiler.ClassExpression;
[SyntaxKind.Constructor]: compiler.ConstructorDeclaration;
[SyntaxKind.ConstructorType]: compiler.ConstructorTypeNode;
[SyntaxKind.ConstructSignature]: compiler.ConstructSignatureDeclaration;
Expand Down Expand Up @@ -175,6 +176,7 @@ export interface KindToExpressionMappings {
[SyntaxKind.AwaitExpression]: compiler.AwaitExpression;
[SyntaxKind.BinaryExpression]: compiler.BinaryExpression;
[SyntaxKind.CallExpression]: compiler.CallExpression;
[SyntaxKind.ClassExpression]: compiler.ClassExpression;
[SyntaxKind.CommaListExpression]: compiler.CommaListExpression;
[SyntaxKind.ConditionalExpression]: compiler.ConditionalExpression;
[SyntaxKind.DeleteExpression]: compiler.DeleteExpression;
Expand Down
1 change: 1 addition & 0 deletions src/factories/kindToWrapperMappings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ export const kindToWrapperMappings: { [key: number]: any } = {
[SyntaxKind.CaseClause]: compiler.CaseClause,
[SyntaxKind.CatchClause]: compiler.CatchClause,
[SyntaxKind.ClassDeclaration]: compiler.ClassDeclaration,
[SyntaxKind.ClassExpression]: compiler.ClassExpression,
[SyntaxKind.Constructor]: compiler.ConstructorDeclaration,
[SyntaxKind.ConstructorType]: compiler.ConstructorTypeNode,
[SyntaxKind.ConstructSignature]: compiler.ConstructSignatureDeclaration,
Expand Down
1,344 changes: 1,344 additions & 0 deletions src/tests/compiler/class/base/classDeclarationBaseTests.ts

Large diffs are not rendered by default.

1,322 changes: 2 additions & 1,320 deletions src/tests/compiler/class/classDeclarationTests.ts

Large diffs are not rendered by default.

46 changes: 45 additions & 1 deletion src/utils/TypeGuards.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ export class TypeGuards {
static isAbstractableNode(node: compiler.Node): node is compiler.AbstractableNode & compiler.AbstractableNodeExtensionType {
switch (node.getKind()) {
case SyntaxKind.ClassDeclaration:
case SyntaxKind.ClassExpression:
case SyntaxKind.GetAccessor:
case SyntaxKind.MethodDeclaration:
case SyntaxKind.PropertyDeclaration:
Expand Down Expand Up @@ -370,6 +371,28 @@ export class TypeGuards {
return node.getKind() === SyntaxKind.ClassDeclaration;
}

/**
* Gets if the node is a ClassExpression.
* @param node - Node to check.
*/
static isClassExpression(node: compiler.Node): node is compiler.ClassExpression {
return node.getKind() === SyntaxKind.ClassExpression;
}

/**
* Gets if the node is a ClassLikeDeclarationBase.
* @param node - Node to check.
*/
static isClassLikeDeclarationBase(node: compiler.Node): node is compiler.ClassLikeDeclarationBase & compiler.ClassLikeDeclarationBaseExtensionType {
switch (node.getKind()) {
case SyntaxKind.ClassDeclaration:
case SyntaxKind.ClassExpression:
return true;
default:
return false;
}
}

/**
* Gets if the node is a CommaListExpression.
* @param node - Node to check.
Expand Down Expand Up @@ -449,6 +472,7 @@ export class TypeGuards {
static isDecoratableNode(node: compiler.Node): node is compiler.DecoratableNode & compiler.DecoratableNodeExtensionType {
switch (node.getKind()) {
case SyntaxKind.ClassDeclaration:
case SyntaxKind.ClassExpression:
case SyntaxKind.GetAccessor:
case SyntaxKind.MethodDeclaration:
case SyntaxKind.PropertyDeclaration:
Expand Down Expand Up @@ -595,6 +619,7 @@ export class TypeGuards {
case SyntaxKind.StringKeyword:
case SyntaxKind.SymbolKeyword:
case SyntaxKind.UndefinedKeyword:
case SyntaxKind.ClassExpression:
case SyntaxKind.Identifier:
case SyntaxKind.AsExpression:
case SyntaxKind.AwaitExpression:
Expand Down Expand Up @@ -825,6 +850,7 @@ export class TypeGuards {
static isHeritageClauseableNode(node: compiler.Node): node is compiler.HeritageClauseableNode & compiler.HeritageClauseableNodeExtensionType {
switch (node.getKind()) {
case SyntaxKind.ClassDeclaration:
case SyntaxKind.ClassExpression:
case SyntaxKind.InterfaceDeclaration:
return true;
default:
Expand Down Expand Up @@ -853,7 +879,13 @@ export class TypeGuards {
* @param node - Node to check.
*/
static isImplementsClauseableNode(node: compiler.Node): node is compiler.ImplementsClauseableNode & compiler.ImplementsClauseableNodeExtensionType {
return node.getKind() === SyntaxKind.ClassDeclaration;
switch (node.getKind()) {
case SyntaxKind.ClassDeclaration:
case SyntaxKind.ClassExpression:
return true;
default:
return false;
}
}

/**
Expand Down Expand Up @@ -1114,6 +1146,7 @@ export class TypeGuards {
static isJSDocableNode(node: compiler.Node): node is compiler.JSDocableNode & compiler.JSDocableNodeExtensionType {
switch (node.getKind()) {
case SyntaxKind.ClassDeclaration:
case SyntaxKind.ClassExpression:
case SyntaxKind.Constructor:
case SyntaxKind.GetAccessor:
case SyntaxKind.MethodDeclaration:
Expand Down Expand Up @@ -1273,6 +1306,7 @@ export class TypeGuards {
*/
static isLeftHandSideExpression(node: compiler.Node): node is compiler.LeftHandSideExpression {
switch (node.getKind()) {
case SyntaxKind.ClassExpression:
case SyntaxKind.Identifier:
case SyntaxKind.CallExpression:
case SyntaxKind.ElementAccessExpression:
Expand Down Expand Up @@ -1370,6 +1404,7 @@ export class TypeGuards {
*/
static isMemberExpression(node: compiler.Node): node is compiler.MemberExpression {
switch (node.getKind()) {
case SyntaxKind.ClassExpression:
case SyntaxKind.Identifier:
case SyntaxKind.ElementAccessExpression:
case SyntaxKind.ImportKeyword:
Expand Down Expand Up @@ -1430,6 +1465,7 @@ export class TypeGuards {
static isModifierableNode(node: compiler.Node): node is compiler.ModifierableNode & compiler.ModifierableNodeExtensionType {
switch (node.getKind()) {
case SyntaxKind.ClassDeclaration:
case SyntaxKind.ClassExpression:
case SyntaxKind.Constructor:
case SyntaxKind.GetAccessor:
case SyntaxKind.MethodDeclaration:
Expand Down Expand Up @@ -1475,6 +1511,7 @@ export class TypeGuards {
static isNameableNode(node: compiler.Node): node is compiler.NameableNode & compiler.NameableNodeExtensionType {
switch (node.getKind()) {
case SyntaxKind.ClassDeclaration:
case SyntaxKind.ClassExpression:
case SyntaxKind.FunctionDeclaration:
case SyntaxKind.FunctionExpression:
return true;
Expand Down Expand Up @@ -1728,6 +1765,7 @@ export class TypeGuards {
*/
static isPrimaryExpression(node: compiler.Node): node is compiler.PrimaryExpression {
switch (node.getKind()) {
case SyntaxKind.ClassExpression:
case SyntaxKind.Identifier:
case SyntaxKind.ImportKeyword:
case SyntaxKind.MetaProperty:
Expand Down Expand Up @@ -1856,6 +1894,7 @@ export class TypeGuards {
switch (node.getKind()) {
case SyntaxKind.BindingElement:
case SyntaxKind.ClassDeclaration:
case SyntaxKind.ClassExpression:
case SyntaxKind.GetAccessor:
case SyntaxKind.MethodDeclaration:
case SyntaxKind.PropertyDeclaration:
Expand Down Expand Up @@ -1901,6 +1940,7 @@ export class TypeGuards {
switch (node.getKind()) {
case SyntaxKind.BindingElement:
case SyntaxKind.ClassDeclaration:
case SyntaxKind.ClassExpression:
case SyntaxKind.GetAccessor:
case SyntaxKind.MethodDeclaration:
case SyntaxKind.PropertyDeclaration:
Expand Down Expand Up @@ -2246,6 +2286,7 @@ export class TypeGuards {
static isTextInsertableNode(node: compiler.Node): node is compiler.TextInsertableNode & compiler.TextInsertableNodeExtensionType {
switch (node.getKind()) {
case SyntaxKind.ClassDeclaration:
case SyntaxKind.ClassExpression:
case SyntaxKind.Constructor:
case SyntaxKind.GetAccessor:
case SyntaxKind.MethodDeclaration:
Expand Down Expand Up @@ -2425,6 +2466,7 @@ export class TypeGuards {
static isTypeParameteredNode(node: compiler.Node): node is compiler.TypeParameteredNode & compiler.TypeParameteredNodeExtensionType {
switch (node.getKind()) {
case SyntaxKind.ClassDeclaration:
case SyntaxKind.ClassExpression:
case SyntaxKind.Constructor:
case SyntaxKind.GetAccessor:
case SyntaxKind.MethodDeclaration:
Expand Down Expand Up @@ -2477,6 +2519,7 @@ export class TypeGuards {
*/
static isUnaryExpression(node: compiler.Node): node is compiler.UnaryExpression {
switch (node.getKind()) {
case SyntaxKind.ClassExpression:
case SyntaxKind.Identifier:
case SyntaxKind.AwaitExpression:
case SyntaxKind.CallExpression:
Expand Down Expand Up @@ -2568,6 +2611,7 @@ export class TypeGuards {
*/
static isUpdateExpression(node: compiler.Node): node is compiler.UpdateExpression {
switch (node.getKind()) {
case SyntaxKind.ClassExpression:
case SyntaxKind.Identifier:
case SyntaxKind.CallExpression:
case SyntaxKind.ElementAccessExpression:
Expand Down
6 changes: 3 additions & 3 deletions wrapped-nodes.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ The disadvantage to a node not being wrapped is that it won't have helper method

## Exist

**Total:** 163
**Total:** 164

* [ArrayBindingPattern](src/compiler/ast/binding/ArrayBindingPattern.ts)
* :heavy_check_mark: elements
Expand Down Expand Up @@ -57,6 +57,7 @@ The disadvantage to a node not being wrapped is that it won't have helper method
* :heavy_check_mark: block
* [ClassDeclaration](src/compiler/ast/class/ClassDeclaration.ts)
* :heavy_check_mark: name
* [ClassExpression](src/compiler/ast/class/ClassExpression.ts)
* [CommaListExpression](src/compiler/ast/expression/CommaListExpression.ts)
* :heavy_check_mark: elements
* [ComputedPropertyName](src/compiler/ast/common/ComputedPropertyName.ts)
Expand Down Expand Up @@ -413,11 +414,10 @@ The disadvantage to a node not being wrapped is that it won't have helper method

## Not Exist

**Total:** 58
**Total:** 57

* Bundle
* ClassElement
* ClassExpression
* ClassLikeDeclarationBase
* ConditionalTypeNode
* DeclarationStatement
Expand Down

0 comments on commit 92f4be3

Please sign in to comment.