Skip to content

Commit

Permalink
fix: #345 - ArrowFunction should be a FunctionLikeDeclaration.
Browse files Browse the repository at this point in the history
  • Loading branch information
dsherret committed Aug 6, 2018
1 parent 547eb3d commit b3ea86f
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 13 deletions.
18 changes: 9 additions & 9 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,17 @@
"build": "rimraf dist && npx ttsc",
"test": "cross-env TS_NODE_COMPILER=\"ttypescript\" mocha --opts mocha.opts",
"test-coverage": "cross-env TS_NODE_COMPILER=\"ttypescript\" nyc --reporter=lcov mocha --opts mocha.opts",
"code-generate": "ts-node --compiler ttypescript --project tsconfig.scripts.json scripts/code-generate",
"refactor": "ts-node scripts/refactor --ignoreDiagnostics",
"output-wrapped-nodes": "ts-node scripts/outputWrappedNodesInfo",
"package": "npm run build && ts-node scripts/createDeclarationFile",
"code-generate": "ts-node --transpileOnly --compiler ttypescript --project tsconfig.scripts.json scripts/code-generate",
"refactor": "ts-node --transpileOnly scripts/refactor",
"output-wrapped-nodes": "ts-node --transpileOnly scripts/outputWrappedNodesInfo",
"package": "npm run build && ts-node --transpileOnly scripts/createDeclarationFile",
"publish-code-verification": "npm run code-verification && npm run ensure-no-declaration-file-errors && npm run ensure-declaration-file-not-changed",
"code-verification": "ts-node scripts/ensureStructuresMatchClasses && ts-node scripts/ensureOverloadStructuresMatch",
"ensure-no-declaration-file-errors": "ts-node scripts/ensureNoDeclarationFileErrors",
"ensure-declaration-file-not-changed": "ts-node scripts/ensureDeclarationFileNotChanged",
"code-verification": "ts-node --transpileOnly scripts/ensureStructuresMatchClasses && ts-node --transpileOnly scripts/ensureOverloadStructuresMatch",
"ensure-no-declaration-file-errors": "ts-node --transpileOnly scripts/ensureNoDeclarationFileErrors",
"ensure-declaration-file-not-changed": "ts-node --transpileOnly scripts/ensureDeclarationFileNotChanged",
"overwrite-declaration-file": "npm run package && shx cp -rf dist/main.d.ts lib/ts-simple-ast.d.ts && shx cp -rf dist/typescript/typescript.d.ts lib/typescript/typescript.d.ts && shx cp -rf dist/codeBlockWriter/code-block-writer.d.ts lib/codeBlockWriter/code-block-writer.d.ts",
"ensure-or-throw-exists": "ts-node scripts/ensureOrThrowExists",
"type-check-docs": "ts-node scripts/typeCheckDocumentation.ts"
"ensure-or-throw-exists": "ts-node --transpileOnly scripts/ensureOrThrowExists",
"type-check-docs": "ts-node --transpileOnly scripts/typeCheckDocumentation.ts"
},
"repository": "git+https://github.com/dsherret/ts-simple-ast.git",
"keywords": [
Expand Down
2 changes: 1 addition & 1 deletion scripts/inspectors/tsSimpleAst/WrappedNode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ export class WrappedNode {
if (typeArgs.length === 0)
return undefined;
const type = typeArgs[0];
return type.isTypeParameter() ? type.getDefaultOrThrow() : type;
return type.isTypeParameter() ? type.getDefault() : type;
}

function getFromType(type: Type | undefined) {
Expand Down
5 changes: 2 additions & 3 deletions src/compiler/function/ArrowFunction.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
import { ts, SyntaxKind } from "../../typescript";
import { AsyncableNode, BodiedNode, JSDocableNode, ModifierableNode, SignaturedDeclaration, TextInsertableNode, TypeParameteredNode } from "../base";
import { FunctionLikeDeclaration } from "./FunctionLikeDeclaration";
import { Node } from "../common";
import { Expression } from "../expression";
import { StatementedNode } from "../statement";

export const ArrowFunctionBase = JSDocableNode(TextInsertableNode(BodiedNode(AsyncableNode(StatementedNode(
TypeParameteredNode(SignaturedDeclaration(ModifierableNode(Expression))
))))));
export const ArrowFunctionBase = TextInsertableNode(BodiedNode(AsyncableNode(FunctionLikeDeclaration(Expression))));
export class ArrowFunction extends ArrowFunctionBase<ts.ArrowFunction> {
/**
* Gets the equals greater than token of the arrow function.
Expand Down
15 changes: 15 additions & 0 deletions src/utils/TypeGuards.ts
Original file line number Diff line number Diff line change
Expand Up @@ -734,13 +734,28 @@ export class TypeGuards {
case SyntaxKind.GetAccessor:
case SyntaxKind.MethodDeclaration:
case SyntaxKind.SetAccessor:
case SyntaxKind.ArrowFunction:
case SyntaxKind.FunctionDeclaration:
return true;
default:
return false;
}
}

/**
* Gets if the node is a FunctionOrConstructorTypeNodeBase.
* @param node - Node to check.
*/
static isFunctionOrConstructorTypeNodeBase(node: compiler.Node): node is compiler.FunctionOrConstructorTypeNodeBase {
switch (node.getKind()) {
case SyntaxKind.ConstructorType:
case SyntaxKind.FunctionType:
return true;
default:
return false;
}
}

/**
* Gets if the node is a FunctionTypeNode.
* @param node - Node to check.
Expand Down

0 comments on commit b3ea86f

Please sign in to comment.