Skip to content

Infer function expressions in matching contexts #514

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

Merged
merged 7 commits into from
Feb 27, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 31 additions & 1 deletion src/ast.ts
Original file line number Diff line number Diff line change
Expand Up @@ -864,6 +864,7 @@ export abstract class Node {
body: Statement | null,
decorators: DecoratorNode[] | null,
flags: CommonFlags,
arrowKind: ArrowKind,
range: Range
): FunctionDeclaration {
var stmt = new FunctionDeclaration();
Expand All @@ -874,6 +875,7 @@ export abstract class Node {
stmt.signature = signature;
stmt.body = body;
stmt.decorators = decorators;
stmt.arrowKind = arrowKind;
return stmt;
}

Expand Down Expand Up @@ -1773,6 +1775,16 @@ export class ForStatement extends Statement {
statement: Statement;
}

/** Indicates the kind of an array function. */
export const enum ArrowKind {
/** Not an arrow function. */
NONE,
/** Parenthesized parameter list. */
ARROW_PARENTHESIZED,
/** Single parameter without parenthesis. */
ARROW_SINGLE
}

/** Represents a `function` declaration. */
export class FunctionDeclaration extends DeclarationStatement {
kind = NodeKind.FUNCTIONDECLARATION;
Expand All @@ -1783,6 +1795,8 @@ export class FunctionDeclaration extends DeclarationStatement {
signature: SignatureNode;
/** Body statement. Usually a block. */
body: Statement | null;
/** Arrow function kind, if applicable. */
arrowKind: ArrowKind;

get isGeneric(): bool {
var typeParameters = this.typeParameters;
Expand All @@ -1792,7 +1806,14 @@ export class FunctionDeclaration extends DeclarationStatement {
/** Clones this function declaration. */
clone(): FunctionDeclaration {
return Node.createFunctionDeclaration(
this.name, this.typeParameters, this.signature, this.body, this.decorators, this.flags, this.range
this.name,
this.typeParameters,
this.signature,
this.body,
this.decorators,
this.flags,
this.arrowKind,
this.range
);
}
}
Expand Down Expand Up @@ -1960,3 +1981,12 @@ export function mangleInternalPath(path: string): string {
if (path.endsWith(".ts")) path = path.substring(0, path.length - 3);
return path;
}

/** Tests if the specified type node represents an omitted type. */
export function isTypeOmitted(type: CommonTypeNode): bool {
if (type.kind == NodeKind.TYPE) {
let name = (<TypeNode>type).name;
return !(name.next || name.identifier.text.length);
}
return false;
}
22 changes: 10 additions & 12 deletions src/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,33 +51,31 @@ export enum CommonFlags {
INSTANCE = 1 << 17,
/** Is a constructor. */
CONSTRUCTOR = 1 << 18,
/** Is an arrow function. */
ARROW = 1 << 19,
/** Is a module export. */
MODULE_EXPORT = 1 << 20,
MODULE_EXPORT = 1 << 19,
/** Is a module import. */
MODULE_IMPORT = 1 << 21,
MODULE_IMPORT = 1 << 20,

// Compilation states

/** Is resolved. */
RESOLVED = 1 << 22,
RESOLVED = 1 << 21,
/** Is compiled. */
COMPILED = 1 << 23,
COMPILED = 1 << 22,
/** Has a constant value and is therefore inlined. */
INLINED = 1 << 24,
INLINED = 1 << 23,
/** Is scoped. */
SCOPED = 1 << 25,
SCOPED = 1 << 24,
/** Is a trampoline. */
TRAMPOLINE = 1 << 26,
TRAMPOLINE = 1 << 25,
/** Is a virtual method. */
VIRTUAL = 1 << 27,
VIRTUAL = 1 << 26,
/** Is the main function. */
MAIN = 1 << 28,
MAIN = 1 << 27,

// Other

QUOTED = 1 << 29
QUOTED = 1 << 28
}

/** Path delimiter inserted between file system levels. */
Expand Down
Loading