TypeScript parser plugin (#523)

This commit is contained in:
Andy 2017-06-28 07:57:50 -07:00 committed by Henry Zhu
parent f7547fd35a
commit 97c23461f9
296 changed files with 33129 additions and 185 deletions

View File

@ -19,9 +19,11 @@ import type { Expression, File } from "./types";
import estreePlugin from "./plugins/estree";
import flowPlugin from "./plugins/flow";
import jsxPlugin from "./plugins/jsx";
import typescriptPlugin from "./plugins/typescript";
plugins.estree = estreePlugin;
plugins.flow = flowPlugin;
plugins.jsx = jsxPlugin;
plugins.typescript = typescriptPlugin;
export function parse(input: string, options?: Options): File {
return getParser(options, input).parse();
@ -53,7 +55,8 @@ function getParserClass(pluginsFromOptions: $ReadOnlyArray<string>): Class<Parse
}
// Filter out just the plugins that have an actual mixin associated with them.
let pluginList = pluginsFromOptions.filter((p) => p === "estree" || p === "flow" || p === "jsx");
let pluginList = pluginsFromOptions.filter((p) =>
p === "estree" || p === "flow" || p === "jsx" || p === "typescript");
if (pluginList.indexOf("flow") >= 0) {
// ensure flow plugin loads last
@ -61,6 +64,16 @@ function getParserClass(pluginsFromOptions: $ReadOnlyArray<string>): Class<Parse
pluginList.push("flow");
}
if (pluginList.indexOf("flow") >= 0 && pluginList.indexOf("typescript") >= 0) {
throw new Error("Cannot combine flow and typescript plugins.");
}
if (pluginList.indexOf("typescript") >= 0) {
// ensure typescript plugin loads last
pluginList = pluginList.filter((plugin) => plugin !== "typescript");
pluginList.push("typescript");
}
if (pluginList.indexOf("estree") >= 0) {
// ensure estree plugin loads first
pluginList = pluginList.filter((plugin) => plugin !== "estree");

View File

@ -302,7 +302,7 @@ export default class ExpressionParser extends LValParser {
return this.parseSubscripts(expr, startPos, startLoc);
}
parseSubscripts(base: N.Expression, startPos: number, startLoc: Position, noCalls?: ?boolean) {
parseSubscripts(base: N.Expression, startPos: number, startLoc: Position, noCalls?: ?boolean): N.Expression {
const state = { stop: false };
do {
base = this.parseSubscript(base, startPos, startLoc, noCalls, state);
@ -340,10 +340,7 @@ export default class ExpressionParser extends LValParser {
this.expect(tt.bracketR);
return this.finishNode(node, "MemberExpression");
} else if (this.eat(tt.parenL)) {
const possibleAsync = this.state.potentialArrowAt === base.start &&
base.type === "Identifier" &&
base.name === "async" &&
!this.canInsertSemicolon();
const possibleAsync = this.atPossibleAsync(base);
node.callee = base;
node.arguments = this.parseCallExpressionArguments(tt.parenR, possibleAsync);
@ -371,23 +368,13 @@ export default class ExpressionParser extends LValParser {
this.expect(tt.bracketR);
return this.finishNode(node, "MemberExpression");
} else if (!noCalls && this.match(tt.parenL)) {
const possibleAsync = this.state.potentialArrowAt === base.start && base.type === "Identifier" && base.name === "async" && !this.canInsertSemicolon();
const possibleAsync = this.atPossibleAsync(base);
this.next();
const node = this.startNodeAt(startPos, startLoc);
node.callee = base;
node.arguments = this.parseCallExpressionArguments(tt.parenR, possibleAsync);
if (node.callee.type === "Import") {
if (node.arguments.length !== 1) {
this.raise(node.start, "import() requires exactly one argument");
}
const importArg = node.arguments[0];
if (importArg && importArg.type === "SpreadElement") {
this.raise(importArg.start, "... is not allowed in import()");
}
}
this.finishNode(node, "CallExpression");
this.finishCallExpression(node);
if (possibleAsync && this.shouldParseAsyncArrow()) {
state.stop = true;
@ -407,6 +394,24 @@ export default class ExpressionParser extends LValParser {
}
}
atPossibleAsync(base: N.Expression): boolean {
return this.state.potentialArrowAt === base.start && base.type === "Identifier" && base.name === "async" && !this.canInsertSemicolon();
}
finishCallExpression(node: N.CallExpression): N.CallExpression {
if (node.callee.type === "Import") {
if (node.arguments.length !== 1) {
this.raise(node.start, "import() requires exactly one argument");
}
const importArg = node.arguments[0];
if (importArg && importArg.type === "SpreadElement") {
this.raise(importArg.start, "... is not allowed in import()");
}
}
return this.finishNode(node, "CallExpression");
}
parseCallExpressionArguments(close: TokenType, possibleAsyncArrow: boolean): $ReadOnlyArray<?N.Expression> {
const elts = [];
let innerParenStart;
@ -566,10 +571,7 @@ export default class ExpressionParser extends LValParser {
return this.finishNode(node, "NullLiteral");
case tt._true: case tt._false:
node = this.startNode();
node.value = this.match(tt._true);
this.next();
return this.finishNode(node, "BooleanLiteral");
return this.parseBooleanLiteral();
case tt.parenL:
return this.parseParenAndDistinguishExpression(canBeArrow);
@ -624,6 +626,13 @@ export default class ExpressionParser extends LValParser {
}
}
parseBooleanLiteral(): N.BooleanLiteral {
const node = this.startNode();
node.value = this.match(tt._true);
this.next();
return this.finishNode(node, "BooleanLiteral");
}
parseMaybePrivateName(): N.PrivateName | N.Identifier {
const isPrivate = this.eat(tt.hash);
@ -795,19 +804,20 @@ export default class ExpressionParser extends LValParser {
}
node.callee = this.parseNoCallExpr();
const optional = this.eat(tt.questionDot);
if (this.eat(tt.questionDot)) node.optional = true;
this.parseNewArguments(node);
return this.finishNode(node, "NewExpression");
}
parseNewArguments(node: N.NewExpression): void {
if (this.eat(tt.parenL)) {
node.arguments = this.parseExprList(tt.parenR);
this.toReferencedList(node.arguments);
const args = this.parseExprList(tt.parenR);
this.toReferencedList(args);
// $FlowFixMe (parseExprList should be all non-null in this case)
node.arguments = args;
} else {
node.arguments = [];
}
if (optional) {
node.optional = true;
}
return this.finishNode(node, "NewExpression");
}
// Parse template expression.
@ -989,19 +999,16 @@ export default class ExpressionParser extends LValParser {
if (isPattern) this.unexpected();
prop.kind = "method";
prop.method = true;
this.parseMethod(prop, isGenerator, isAsync);
return this.finishNode(prop, "ObjectMethod");
return this.parseMethod(prop, isGenerator, isAsync, /* isConstructor */ false, "ObjectMethod");
}
if (this.isGetterOrSetterMethod(prop, isPattern)) {
if (isGenerator || isAsync) this.unexpected();
prop.kind = prop.key.name;
this.parsePropertyName(prop);
this.parseMethod(prop);
this.parseMethod(prop, /* isGenerator */false, /* isAsync */ false, /* isConstructor */ false, "ObjectMethod");
this.checkGetterSetterParamCount(prop);
return this.finishNode(prop, "ObjectMethod");
return prop;
}
}
@ -1039,9 +1046,12 @@ export default class ExpressionParser extends LValParser {
this.parseObjectProperty(prop, startPos, startLoc, isPattern, refShorthandDefaultPos);
if (!node) this.unexpected();
// $FlowFixMe
return node;
}
parsePropertyName(prop: N.ObjectOrClassMember): N.Expression {
parsePropertyName(prop: N.ObjectOrClassMember | N.TsNamedTypeElementBase): N.Expression {
if (this.eat(tt.bracketL)) {
prop.computed = true;
prop.key = this.parseMaybeAssign();
@ -1059,7 +1069,7 @@ export default class ExpressionParser extends LValParser {
// Initialize empty function node.
initFunction(node: N.Function, isAsync: ?boolean): void {
initFunction(node: N.BodilessFunctionOrMethodBase, isAsync: ?boolean): void {
node.id = null;
node.generator = false;
node.expression = false;
@ -1068,14 +1078,15 @@ export default class ExpressionParser extends LValParser {
// Parse object or class method.
parseMethod(node: N.MethodLike, isGenerator?: boolean, isAsync?: boolean): N.MethodLike {
parseMethod<T : N.MethodLike>(node: T, isGenerator: boolean, isAsync: boolean, isConstructor: boolean, type: string): T {
const oldInMethod = this.state.inMethod;
this.state.inMethod = node.kind || true;
this.initFunction(node, isAsync);
this.expect(tt.parenL);
node.params = this.parseBindingList(tt.parenR);
const allowModifiers = isConstructor; // For TypeScript parameter properties
node.params = this.parseBindingList(tt.parenR, /* allowEmpty */ false, allowModifiers);
node.generator = !!isGenerator;
this.parseFunctionBody(node);
this.parseFunctionBodyAndFinish(node, type);
this.state.inMethod = oldInMethod;
return node;
}
@ -1089,7 +1100,7 @@ export default class ExpressionParser extends LValParser {
return this.finishNode(node, "ArrowFunctionExpression");
}
isStrictBody(node: { body: N.BlockStatement }, isExpression?: boolean): boolean {
isStrictBody(node: { body: N.BlockStatement }, isExpression: ?boolean): boolean {
if (!isExpression && node.body.directives.length) {
for (const directive of node.body.directives) {
if (directive.value.value === "use strict") {
@ -1101,8 +1112,14 @@ export default class ExpressionParser extends LValParser {
return false;
}
parseFunctionBodyAndFinish(node: N.BodilessFunctionOrMethodBase, type: string, allowExpressionBody?: boolean): void {
// $FlowIgnore (node is not bodiless if we get here)
this.parseFunctionBody(node, allowExpressionBody);
this.finishNode(node, type);
}
// Parse function body and check parameters.
parseFunctionBody(node: N.Function, allowExpression?: boolean): void {
parseFunctionBody(node: N.Function, allowExpression: ?boolean): void {
const isExpression = allowExpression && !this.match(tt.braceL);
const oldInAsync = this.state.inAsync;
@ -1192,26 +1209,33 @@ export default class ExpressionParser extends LValParser {
parseIdentifier(liberal?: boolean): N.Identifier {
const node = this.startNode();
const name = this.parseIdentifierName(node.start, liberal);
node.name = name;
node.loc.identifierName = name;
return this.finishNode(node, "Identifier");
}
parseIdentifierName(pos: number, liberal?: boolean): string {
if (!liberal) {
this.checkReservedWord(this.state.value, this.state.start, !!this.state.type.keyword, false);
}
let name: string;
if (this.match(tt.name)) {
node.name = this.state.value;
name = this.state.value;
} else if (this.state.type.keyword) {
node.name = this.state.type.keyword;
name = this.state.type.keyword;
} else {
this.unexpected();
throw this.unexpected();
}
if (!liberal && node.name === "await" && this.state.inAsync) {
this.raise(node.start, "invalid use of await inside of an async function");
if (!liberal && name === "await" && this.state.inAsync) {
this.raise(pos, "invalid use of await inside of an async function");
}
node.loc.identifierName = node.name;
this.next();
return this.finishNode(node, "Identifier");
return name;
}
checkReservedWord(word: string, startLoc: number, checkKeywords: boolean, isBinding: boolean): void {

View File

@ -1,8 +1,8 @@
// @flow
import { types as tt, type TokenType } from "../tokenizer/types";
import type { Decorator, Expression, Identifier, Node, ObjectExpression, ObjectPattern, Pattern, RestElement,
SpreadElement } from "../types";
import type { TSParameterProperty, Decorator, Expression, Identifier, Node, ObjectExpression,
ObjectPattern, Pattern, RestElement, SpreadElement } from "../types";
import type { Pos, Position } from "../util/location";
import { NodeUtils } from "./node";
@ -167,8 +167,12 @@ export default class LValParser extends NodeUtils {
}
}
parseBindingList(close: TokenType, allowEmpty?: boolean): $ReadOnlyArray<Pattern> {
const elts = [];
parseBindingList(
close: TokenType,
allowEmpty?: boolean,
allowModifiers?: boolean
): $ReadOnlyArray<Pattern | TSParameterProperty> {
const elts: Array<Pattern | TSParameterProperty> = [];
let first = true;
while (!this.eat(close)) {
if (first) {
@ -193,17 +197,22 @@ export default class LValParser extends NodeUtils {
while (this.match(tt.at)) {
decorators.push(this.parseDecorator());
}
const left = this.parseMaybeDefault();
if (decorators.length) {
left.decorators = decorators;
}
this.parseAssignableListItemTypes(left);
elts.push(this.parseMaybeDefault(left.start, left.loc.start, left));
elts.push(this.parseAssignableListItem(allowModifiers, decorators));
}
}
return elts;
}
parseAssignableListItem(allowModifiers: ?boolean, decorators: Decorator[]): Pattern | TSParameterProperty {
const left = this.parseMaybeDefault();
this.parseAssignableListItemTypes(left);
const elt = this.parseMaybeDefault(left.start, left.loc.start, left);
if (decorators.length) {
left.decorators = decorators;
}
return elt;
}
parseAssignableListItemTypes(param: Pattern): Pattern {
return param;
}

View File

@ -55,6 +55,11 @@ export class NodeUtils extends UtilParser {
return new Node(this, pos, loc);
}
/** Start a new node with a previous node's location. */
startNodeAtNode<T : NodeType>(type: NodeType): T {
return this.startNodeAt(type.start, type.loc.start);
}
// Finish an AST node, adding `type` and `end` properties.
finishNode<T : NodeType>(node: T, type: string): T {

View File

@ -3,7 +3,7 @@
// @flow
import * as N from "../types";
import { types as tt, TokenType } from "../tokenizer/types";
import { types as tt, type TokenType } from "../tokenizer/types";
import ExpressionParser from "./expression";
import type { Position } from "../util/location";
import { lineBreak } from "../util/whitespace";
@ -15,7 +15,6 @@ const empty = [];
const loopLabel = { kind: "loop" }, switchLabel = { kind: "switch" };
export default class StatementParser extends ExpressionParser {
// ### Statement parsing
// Parse a program. Initializes the parser, reads any number of
@ -66,7 +65,10 @@ export default class StatementParser extends ExpressionParser {
if (this.match(tt.at)) {
this.parseDecorators(true);
}
return this.parseStatementContent(declaration, topLevel);
}
parseStatementContent(declaration: boolean, topLevel: ?boolean): N.Statement {
const starttype = this.state.type;
const node = this.startNode();
@ -119,7 +121,13 @@ export default class StatementParser extends ExpressionParser {
this.raise(this.state.start, `'import' and 'export' may appear only with 'sourceType: "module"'`);
}
}
return starttype === tt._import ? this.parseImport(node) : this.parseExport(node);
this.next();
if (starttype == tt._import) {
return this.parseImport(node);
} else {
return this.parseExport(node);
}
case tt.name:
if (this.state.value === "async") {
@ -522,7 +530,11 @@ export default class StatementParser extends ExpressionParser {
parseBlockBody(node: N.BlockStatementLike, allowDirectives: ?boolean, topLevel: boolean, end: TokenType): void {
const body = node.body = [];
const directives = node.directives = [];
this.parseBlockOrModuleBlockBody(body, allowDirectives ? directives : undefined, topLevel, end);
}
// Undefined directives means that directives are not allowed.
parseBlockOrModuleBlockBody(body: N.Statement[], directives: ?N.Directive[], topLevel: boolean, end: TokenType): void {
let parsedNonDirective = false;
let oldStrict;
let octalPosition;
@ -534,7 +546,7 @@ export default class StatementParser extends ExpressionParser {
const stmt = this.parseStatement(true, topLevel);
if (allowDirectives && !parsedNonDirective && this.isValidDirective(stmt)) {
if (directives && !parsedNonDirective && this.isValidDirective(stmt)) {
const directive = this.stmtToDirective(stmt);
directives.push(directive);
@ -607,11 +619,15 @@ export default class StatementParser extends ExpressionParser {
this.parseVarHead(decl);
if (this.eat(tt.eq)) {
decl.init = this.parseMaybeAssign(isFor);
} else if (kind === tt._const && !(this.match(tt._in) || this.isContextual("of"))) {
this.unexpected();
} else if (decl.id.type !== "Identifier" && !(isFor && (this.match(tt._in) || this.isContextual("of")))) {
this.raise(this.state.lastTokEnd, "Complex binding patterns require an initialization value");
} else {
if (kind === tt._const && !(this.match(tt._in) || this.isContextual("of"))) {
// `const` with no initializer is allowed in TypeScript. It could be a declaration `const x: number;`.
if (!this.hasPlugin("typescript")) {
this.unexpected();
}
} else if (decl.id.type !== "Identifier" && !(isFor && (this.match(tt._in) || this.isContextual("of")))) {
this.raise(this.state.lastTokEnd, "Complex binding patterns require an initialization value");
}
decl.init = null;
}
declarations.push(this.finishNode(decl, "VariableDeclarator"));
@ -652,14 +668,12 @@ export default class StatementParser extends ExpressionParser {
}
this.parseFunctionParams(node);
this.parseFunctionBody(node, allowExpressionBody);
this.parseFunctionBodyAndFinish(node, isStatement ? "FunctionDeclaration" : "FunctionExpression", allowExpressionBody);
this.state.inMethod = oldInMethod;
return this.finishNode(node, isStatement ? "FunctionDeclaration" : "FunctionExpression");
return node;
}
parseFunctionParams(node: N.NormalFunction): void {
parseFunctionParams(node: N.Function): void {
this.expect(tt.parenL);
node.params = this.parseBindingList(tt.parenR);
}
@ -667,7 +681,7 @@ export default class StatementParser extends ExpressionParser {
// Parse a class declaration or literal (depending on the
// `isStatement` parameter).
parseClass(node: N.Class, isStatement: boolean, optionalId?: boolean): N.Class {
parseClass<T : N.Class>(node: T, isStatement: /* T === ClassDeclaration */boolean, optionalId?: boolean): T {
this.next();
this.takeDecorators(node);
this.parseClassId(node, isStatement, optionalId);
@ -698,8 +712,8 @@ export default class StatementParser extends ExpressionParser {
this.state.classLevel++;
const state = { hadConstructor: false };
let decorators = [];
const classBody = this.startNode();
let decorators: N.Decorator[] = [];
const classBody: N.ClassBody = this.startNode();
classBody.body = [];
@ -749,7 +763,6 @@ export default class StatementParser extends ExpressionParser {
parseClassMember(classBody: N.ClassBody, member: N.ClassMember, state: { hadConstructor: boolean }): void {
// Use the appropriate variable to represent `member` once a more specific type is known.
const memberAny: any = member;
const methodOrProp: N.ClassMethod | N.ClassProperty = memberAny;
const method: N.ClassMethod = memberAny;
const prop: N.ClassProperty = memberAny;
@ -761,7 +774,7 @@ export default class StatementParser extends ExpressionParser {
return;
}
methodOrProp.static = false;
let isStatic = false;
if (this.match(tt.name) && this.state.value === "static") {
const key = this.parseIdentifier(true); // eats 'static'
if (this.isClassMethod()) {
@ -769,19 +782,32 @@ export default class StatementParser extends ExpressionParser {
method.kind = "method";
method.computed = false;
method.key = key;
this.parseClassMethod(classBody, method, false, false);
method.static = false;
this.parseClassMethod(classBody, method, false, false, /* isConstructor */ false);
return;
} else if (this.isClassProperty()) {
// a property named 'static'
prop.computed = false;
prop.key = key;
prop.static = false;
classBody.body.push(this.parseClassProperty(prop));
return;
}
// otherwise something static
methodOrProp.static = true;
isStatic = true;
}
this.parseClassMemberWithIsStatic(classBody, member, state, isStatic);
}
parseClassMemberWithIsStatic(classBody: N.ClassBody, member: N.ClassMember, state: { hadConstructor: boolean }, isStatic: boolean) {
const memberAny: any = member;
const methodOrProp: N.ClassMethod | N.ClassProperty = memberAny;
const method: N.ClassMethod = memberAny;
const prop: N.ClassProperty = memberAny;
methodOrProp.static = isStatic;
if (this.eat(tt.star)) {
// a generator
method.kind = "method";
@ -792,36 +818,40 @@ export default class StatementParser extends ExpressionParser {
if (!method.computed && method.static && (method.key.name === "prototype" || method.key.value === "prototype")) {
this.raise(method.key.start, "Classes may not have static property named prototype");
}
this.parseClassMethod(classBody, method, true, false);
this.parseClassMethod(classBody, method, true, false, /* isConstructor */ false);
return;
}
const isSimple = this.match(tt.name);
const key = this.parsePropertyName(methodOrProp);
if (!methodOrProp.computed && methodOrProp.static && (methodOrProp.key.name === "prototype" || methodOrProp.key.value === "prototype")) {
this.raise(methodOrProp.key.start, "Classes may not have static property named prototype");
}
const key = this.parseClassPropertyName(methodOrProp);
this.parsePostMemberNameModifiers(methodOrProp);
if (this.isClassMethod()) {
// a normal method
if (this.isNonstaticConstructor(method)) {
if (state.hadConstructor) {
this.raise(key.start, "Duplicate constructor in the same class");
} else if (method.decorators) {
this.raise(method.start, "You can't attach decorators to a class constructor");
}
state.hadConstructor = true;
const isConstructor = this.isNonstaticConstructor(method);
if (isConstructor) {
method.kind = "constructor";
} else {
method.kind = "method";
}
this.parseClassMethod(classBody, method, false, false);
} else if (this.isClassProperty()) {
// a normal property
if (this.isNonstaticConstructor(prop)) {
this.raise(prop.key.start, "Classes may not have a non-static field named 'constructor'");
if (isConstructor) {
if (method.decorators) {
this.raise(method.start, "You can't attach decorators to a class constructor");
}
// TypeScript allows multiple overloaded constructor declarations.
if (state.hadConstructor && !this.hasPlugin("typescript")) {
this.raise(key.start, "Duplicate constructor in the same class");
}
state.hadConstructor = true;
}
classBody.body.push(this.parseClassProperty(prop));
this.parseClassMethod(classBody, method, false, false, isConstructor);
} else if (this.isClassProperty()) {
this.pushClassProperty(classBody, prop);
} else if (isSimple && key.name === "async" && !this.isLineTerminator()) {
// an async method
const isGenerator = this.hasPlugin("asyncGenerators") && this.eat(tt.star);
@ -830,7 +860,7 @@ export default class StatementParser extends ExpressionParser {
if (this.isNonstaticConstructor(method)) {
this.raise(method.key.start, "Constructor can't be an async function");
}
this.parseClassMethod(classBody, method, isGenerator, true);
this.parseClassMethod(classBody, method, isGenerator, true, /* isConstructor */ false);
} else if (isSimple && (key.name === "get" || key.name === "set") && !(this.isLineTerminator() && this.match(tt.star))) { // `get\n*` is an uninitialized property named 'get' followed by a generator.
// a getter or setter
method.kind = key.name;
@ -838,7 +868,7 @@ export default class StatementParser extends ExpressionParser {
if (this.isNonstaticConstructor(method)) {
this.raise(method.key.start, "Constructor can't have get/set modifier");
}
this.parseClassMethod(classBody, method, false, false);
this.parseClassMethod(classBody, method, false, false, /* isConstructor */ false);
this.checkGetterSetterParamCount(method);
} else if (this.isLineTerminator()) {
// an uninitialized class property (due to ASI, since we don't otherwise recognize the next token)
@ -851,6 +881,30 @@ export default class StatementParser extends ExpressionParser {
}
}
parseClassPropertyName(methodOrProp: N.ClassMethod | N.ClassProperty): N.Expression {
const key = this.parsePropertyName(methodOrProp);
if (!methodOrProp.computed && methodOrProp.static && (methodOrProp.key.name === "prototype" || methodOrProp.key.value === "prototype")) {
this.raise(methodOrProp.key.start, "Classes may not have static property named prototype");
}
return key;
}
pushClassProperty(classBody: N.ClassBody, prop: N.ClassProperty) {
if (this.isNonstaticConstructor(prop)) {
this.raise(prop.key.start, "Classes may not have a non-static field named 'constructor'");
}
classBody.body.push(this.parseClassProperty(prop));
}
// Overridden in typescript.js
// eslint-disable-next-line no-unused-vars
parsePostMemberNameModifiers(methodOrProp: N.ClassMethod | N.ClassProperty): void {}
// Overridden in typescript.js
parseAccessModifier(): ?N.Accessibility {
return undefined;
}
parsePrivateClassProperty(node: N.ClassPrivateProperty): N.ClassPrivateProperty {
this.state.inClassProperty = true;
@ -865,9 +919,8 @@ export default class StatementParser extends ExpressionParser {
return this.finishNode(node, "ClassPrivateProperty");
}
parseClassProperty(node: N.ClassProperty): N.ClassProperty {
const hasPlugin = this.hasPlugin("classProperties");
const hasPlugin = this.hasPlugin("classProperties") || this.hasPlugin("typescript");
const noPluginMsg = "You can only use Class Properties when the 'classProperties' plugin is enabled.";
if (!node.typeAnnotation && !hasPlugin) {
this.raise(node.start, noPluginMsg);
@ -887,9 +940,8 @@ export default class StatementParser extends ExpressionParser {
return this.finishNode(node, "ClassProperty");
}
parseClassMethod(classBody: N.ClassBody, method: N.ClassMethod, isGenerator: boolean, isAsync: boolean): void {
this.parseMethod(method, isGenerator, isAsync);
classBody.body.push(this.finishNode(method, "ClassMethod"));
parseClassMethod(classBody: N.ClassBody, method: N.ClassMethod, isGenerator: boolean, isAsync: boolean, isConstructor: boolean): void {
classBody.body.push(this.parseMethod(method, isGenerator, isAsync, isConstructor, "ClassMethod"));
}
parseClassId(node: N.Class, isStatement: boolean, optionalId: ?boolean): void {
@ -910,9 +962,8 @@ export default class StatementParser extends ExpressionParser {
// Parses module export declaration.
parseExport(node: N.ExportNamedDeclaration): N.ExportNamedDeclaration {
this.eat(tt._export);
// TODO: better type. Node is an N.AnyExport.
parseExport(node: N.Node): N.Node {
// export * from '...'
if (this.match(tt.star)) {
const specifier = this.startNode();
@ -960,7 +1011,6 @@ export default class StatementParser extends ExpressionParser {
needsSemi = true;
expr = this.parseMaybeAssign();
}
// $FlowFixMe
node.declaration = expr;
if (needsSemi) this.semicolon();
this.checkExport(node, true, true);
@ -1026,7 +1076,7 @@ export default class StatementParser extends ExpressionParser {
|| this.isContextual("async");
}
checkExport(node: N.ExportNamedDeclaration, checkNames: ?boolean, isDefault: ?boolean): void {
checkExport(node: N.ExportNamedDeclaration, checkNames: ?boolean, isDefault?: boolean): void {
if (checkNames) {
// Check for duplicate exports
if (isDefault) {
@ -1131,9 +1181,7 @@ export default class StatementParser extends ExpressionParser {
// Parses import declaration.
parseImport(node: N.ImportDeclaration): N.ImportDeclaration {
this.eat(tt._import);
parseImport(node: N.Node): N.ImportDeclaration | N.TsImportEqualsDeclaration {
// import '...'
if (this.match(tt.string)) {
node.specifiers = [];

View File

@ -33,6 +33,16 @@ export default class UtilParser extends Tokenizer {
}
}
// eat() for relational operators.
eatRelational(op: "<" | ">"): boolean {
if (this.isRelational(op)) {
this.next();
return true;
}
return false;
}
// Tests whether parsed token is a contextual keyword.
isContextual(name: string): boolean {
@ -56,7 +66,11 @@ export default class UtilParser extends Tokenizer {
canInsertSemicolon(): boolean {
return this.match(tt.eof) ||
this.match(tt.braceR) ||
lineBreak.test(this.input.slice(this.state.lastTokEnd, this.state.start));
this.hasPrecedingLineBreak();
}
hasPrecedingLineBreak(): boolean {
return lineBreak.test(this.input.slice(this.state.lastTokEnd, this.state.start));
}
// TODO

View File

@ -108,7 +108,7 @@ export default (superClass: Class<Parser>): Class<Parser> => class extends super
}
}
isStrictBody(node: { body: N.BlockStatement }, isExpression?: boolean): boolean {
isStrictBody(node: { body: N.BlockStatement }, isExpression: ?boolean): boolean {
if (!isExpression && node.body.body.length > 0) {
for (const directive of node.body.body) {
if (directive.type === "ExpressionStatement" && directive.expression.type === "Literal") {
@ -158,15 +158,16 @@ export default (superClass: Class<Parser>): Class<Parser> => class extends super
classBody: N.ClassBody,
method: N.ClassMethod,
isGenerator: boolean,
isAsync: boolean
isAsync: boolean,
isConstructor: boolean
): void {
this.parseMethod(method, isGenerator, isAsync);
this.parseMethod(method, isGenerator, isAsync, isConstructor, "MethodDefinition");
if (method.typeParameters) {
// $FlowIgnore
method.value.typeParameters = method.typeParameters;
delete method.typeParameters;
}
classBody.body.push(this.finishNode(method, "MethodDefinition"));
classBody.body.push(method);
}
parseExprAtom(refShorthandDefaultPos?: ?Pos): N.Expression {
@ -205,19 +206,21 @@ export default (superClass: Class<Parser>): Class<Parser> => class extends super
return node;
}
parseMethod(
node: N.MethodLike,
isGenerator?: boolean,
isAsync?: boolean
): N.MethodLike {
parseMethod<T : N.MethodLike>(
node: T,
isGenerator: boolean,
isAsync: boolean,
isConstructor: boolean,
type: string,
): T {
let funcNode = this.startNode();
funcNode.kind = node.kind; // provide kind, so super method correctly sets state
funcNode = super.parseMethod(funcNode, isGenerator, isAsync);
funcNode = super.parseMethod(funcNode, isGenerator, isAsync, isConstructor, "FunctionExpression");
delete funcNode.kind;
// $FlowIgnore
node.value = this.finishNode(funcNode, "FunctionExpression");
node.value = funcNode;
return node;
return this.finishNode(node, type);
}
parseObjectMethod(

View File

@ -178,7 +178,7 @@ export default (superClass: Class<Parser>): Class<Parser> => class extends super
if (lookahead.value !== "type" && lookahead.value !== "typeof") {
this.unexpected(null, "Imports within a `declare module` body must always be `import type` or `import typeof`");
}
this.next();
this.parseImport(bodyNode);
} else {
this.expectContextual("declare", "Only declares and type imports are allowed inside declare module");
@ -372,7 +372,7 @@ export default (superClass: Class<Parser>): Class<Parser> => class extends super
// Type annotations
flowParseTypeParameter(): N.FlowTypeParameter {
flowParseTypeParameter(): N.TypeParameter {
const node = this.startNode();
const variance = this.flowParseVariance();
@ -390,7 +390,7 @@ export default (superClass: Class<Parser>): Class<Parser> => class extends super
return this.finishNode(node, "TypeParameter");
}
flowParseTypeParameterDeclaration(): N.FlowTypeParameterDeclaration {
flowParseTypeParameterDeclaration(): N.TypeParameterDeclaration {
const oldInType = this.state.inType;
const node = this.startNode();
node.params = [];
@ -417,7 +417,7 @@ export default (superClass: Class<Parser>): Class<Parser> => class extends super
return this.finishNode(node, "TypeParameterDeclaration");
}
flowParseTypeParameterInstantiation(): N.FlowTypeParameterInstantiation {
flowParseTypeParameterInstantiation(): N.TypeParameterInstantiation {
const node = this.startNode();
const oldInType = this.state.inType;
node.params = [];
@ -1008,21 +1008,18 @@ export default (superClass: Class<Parser>): Class<Parser> => class extends super
// Overrides
// ==================================
// plain function return types: function name(): string {}
parseFunctionBody(node: N.Function, allowExpression?: boolean): void {
if (this.match(tt.colon) && !allowExpression) {
// if allowExpression is true then we're parsing an arrow function and if
// there's a return type then it's been handled elsewhere
parseFunctionBodyAndFinish(node: N.BodilessFunctionOrMethodBase, type: string, allowExpressionBody?: boolean): void {
// For arrow functions, `parseArrow` handles the return type itself.
if (!allowExpressionBody && this.match(tt.colon)) {
const typeNode = this.startNode();
// $FlowFixMe (destructuring not yet supported)
// $FlowFixMe
[typeNode.typeAnnotation, node.predicate] = this.flowParseTypeAndPredicateInitialiser();
node.returnType = typeNode.typeAnnotation
? this.finishNode(typeNode, "TypeAnnotation")
: null;
}
return super.parseFunctionBody(node, allowExpression);
super.parseFunctionBodyAndFinish(node, type, allowExpressionBody);
}
// interfaces
@ -1258,7 +1255,8 @@ export default (superClass: Class<Parser>): Class<Parser> => class extends super
classBody: N.ClassBody,
method: N.ClassMethod,
isGenerator: boolean,
isAsync: boolean
isAsync: boolean,
isConstructor: boolean
): void {
if (method.variance) {
this.unexpected(method.variance.start);
@ -1268,7 +1266,7 @@ export default (superClass: Class<Parser>): Class<Parser> => class extends super
method.typeParameters = this.flowParseTypeParameterDeclaration();
}
super.parseClassMethod(classBody, method, isGenerator, isAsync);
super.parseClassMethod(classBody, method, isGenerator, isAsync, isConstructor);
}
// parse a the super class type parameters and implements
@ -1279,7 +1277,7 @@ export default (superClass: Class<Parser>): Class<Parser> => class extends super
}
if (this.isContextual("implements")) {
this.next();
const implemented = node.implements = [];
const implemented: N.FlowClassImplements[] = node.implements = [];
do {
const node = this.startNode();
node.id = this.parseIdentifier();
@ -1293,9 +1291,10 @@ export default (superClass: Class<Parser>): Class<Parser> => class extends super
}
}
parsePropertyName(node: N.ObjectOrClassMember): N.Identifier {
parsePropertyName(node: N.ObjectOrClassMember | N.TsNamedTypeElementBase): N.Identifier {
const variance = this.flowParseVariance();
const key = super.parsePropertyName(node);
// $FlowIgnore ("variance" not defined on TsNamedTypeElementBase)
node.variance = variance;
return key;
}
@ -1342,6 +1341,12 @@ export default (superClass: Class<Parser>): Class<Parser> => class extends super
parseAssignableListItemTypes(param: N.Pattern): N.Pattern {
if (this.eat(tt.question)) {
if (param.type !== "Identifier") {
throw this.raise(
param.start,
"A binding pattern parameter cannot be optional in an implementation signature.");
}
param.optional = true;
}
if (this.match(tt.colon)) {
@ -1440,7 +1445,7 @@ export default (superClass: Class<Parser>): Class<Parser> => class extends super
}
// parse function type parameters - function foo<T>() {}
parseFunctionParams(node: N.NormalFunction): void {
parseFunctionParams(node: N.Function): void {
if (this.isRelational("<")) {
node.typeParameters = this.flowParseTypeParameterDeclaration();
}

1717
src/plugins/typescript.js Normal file

File diff suppressed because it is too large Load Diff

View File

@ -12,7 +12,7 @@ export class TokContext {
token: string,
isExpr?: boolean,
preserveSpace?: boolean,
override?: Function,
override?: Function, // Takes a Tokenizer as a this-parameter, and returns void.
) {
this.token = token;
this.isExpr = !!isExpr;

View File

@ -2,11 +2,10 @@
// @flow
import type { TokenType } from "./types";
import type { Options } from "../options";
import type { Position } from "../util/location";
import { isIdentifierStart, isIdentifierChar, isKeyword } from "../util/identifier";
import { types as tt, keywords as keywordTypes } from "./types";
import { types as tt, keywords as keywordTypes, type TokenType } from "./types";
import { type TokContext, types as ct } from "./context";
import LocationParser from "../parser/location";
import { SourceLocation } from "../util/location";
@ -425,7 +424,7 @@ export default class Tokenizer extends LocationParser {
this.state.pos += 2;
return this.finishToken(tt.arrow);
}
return this.finishOp(code === 61 ? tt.eq : tt.prefix, 1);
return this.finishOp(code === 61 ? tt.eq : tt.bang, 1);
}
readToken_question() { // '?'
@ -531,7 +530,7 @@ export default class Tokenizer extends LocationParser {
return this.readToken_eq_excl(code);
case 126: // '~'
return this.finishOp(tt.prefix, 1);
return this.finishOp(tt.tilde, 1);
}
this.raise(this.state.pos, `Unexpected character '${codePointToString(code)}'`);
@ -958,6 +957,11 @@ export default class Tokenizer extends LocationParser {
return this.curContext() === ct.braceStatement;
}
if (prevType === tt.relational) {
// `class C<T> { ... }`
return true;
}
return !this.state.exprAllowed;
}

View File

@ -2,13 +2,11 @@
import type { Options } from "../options";
import * as N from "../types";
import type { TokContext } from "./context";
import type { Token } from "./index";
import type { TokenType } from "./types";
import { Position } from "../util/location";
import { types as ct } from "./context";
import { types as tt } from "./types";
import { types as ct, type TokContext } from "./context";
import type { Token } from "./index";
import { types as tt, type TokenType } from "./types";
export default class State {
init(options: Options, input: string): void {

View File

@ -129,7 +129,8 @@ export const types: { [name: string]: TokenType } = {
eq: new TokenType("=", { beforeExpr, isAssign }),
assign: new TokenType("_=", { beforeExpr, isAssign }),
incDec: new TokenType("++/--", { prefix, postfix, startsExpr }),
prefix: new TokenType("prefix", { beforeExpr, prefix, startsExpr }),
bang: new TokenType("!", { beforeExpr, prefix, startsExpr }),
tilde: new TokenType("~", { beforeExpr, prefix, startsExpr }),
logicalOR: new BinopTokenType("||", 1),
logicalAND: new BinopTokenType("&&", 2),
bitwiseOR: new BinopTokenType("|", 3),

View File

@ -47,8 +47,16 @@ export type Pattern =
export type Declaration =
| VariableDeclaration
| ClassDeclaration
| FunctionDeclaration;
export type DeclarationBase = NodeBase;
| FunctionDeclaration
| TsInterfaceDeclaration
| TsTypeAliasDeclaration
| TsEnumDeclaration
| TsModuleDeclaration;
export type DeclarationBase = NodeBase & {
// TypeScript allows declarations to be prefixed by `declare`.
//TODO: a FunctionDeclaration is never "declare", because it's a TSDeclareFunction instead.
declare?: true;
}
// TODO: Not in spec
export type HasDecorators = NodeBase & {
@ -60,6 +68,9 @@ export type Identifier = PatternBase & {
name: string;
__clone(): Identifier;
// TypeScript only. Used in case of an optional parameter.
optional?: ?true;
};
export type PrivateName = NodeBase & {
@ -127,16 +138,28 @@ export type Function =
export type NormalFunction =
FunctionDeclaration | FunctionExpression;
export type FunctionBase = HasDecorators & {
export type BodilessFunctionOrMethodBase = HasDecorators & {
// TODO: Remove this. Should not assign "id" to methods.
// https://github.com/babel/babylon/issues/535
id: ?Identifier;
params: $ReadOnlyArray<Pattern>;
params: $ReadOnlyArray<Pattern | TSParameterProperty>;
body: BlockStatement;
generator: boolean;
async: boolean;
expression: boolean; // TODO: Not in spec
typeParameters?: ?FlowTypeParameterDeclaration; // TODO: Not in spec
returnType?: ?FlowTypeAnnotation; // TODO: Not in spec
// TODO: All not in spec
expression: boolean;
typeParameters?: ?TypeParameterDeclaration;
returnType?: ?TypeAnnotation;
}
export type BodilessFunctionBase = BodilessFunctionOrMethodBase & {
id: ?Identifier;
}
export type FunctionBase = BodilessFunctionBase & {
body: BlockStatement;
};
// Statements
@ -276,7 +299,7 @@ export type ForOfStatement = ForInOfBase & {
// Declarations
export type OptFunctionDeclaration = FunctionBase & DeclarationBase & HasDecorators & {
export type OptFunctionDeclaration = FunctionBase & DeclarationBase & {
type: "FunctionDeclaration";
};
@ -460,6 +483,7 @@ export type ConditionalExpression = NodeBase & {
export type CallOrNewBase = NodeBase & {
callee: Expression | Super | Import;
arguments: Array<Expression | SpreadElement>; // TODO: $ReadOnlyArray
typeParameters?: ?TypeParameterInstantiation; // TODO: Not in spec
};
export type CallExpression = CallOrNewBase & {
@ -468,6 +492,7 @@ export type CallExpression = CallOrNewBase & {
export type NewExpression = CallOrNewBase & {
type: "NewExpression";
optional?: boolean; // TODO: Not in spec
};
export type SequenceExpression = NodeBase & {
@ -500,10 +525,13 @@ export type TemplateElement = NodeBase & {
// Patterns
// TypeScript access modifiers
export type Accessibility = "public" | "protected" | "private";
export type PatternBase = HasDecorators & {
// Flow only:
optional?: true;
typeAnnotation?: ?FlowTypeAnnotation;
// TODO: All not in spec
// Flow/TypeScript only:
typeAnnotation?: ?TypeAnnotation;
};
export type AssignmentProperty = ObjectProperty & {
@ -541,9 +569,10 @@ export type ClassBase = HasDecorators & {
body: ClassBody;
decorators: $ReadOnlyArray<Decorator>;
typeParameters?: ?FlowTypeParameterDeclaration; // TODO: Not in spec
superTypeParameters?: ?FlowTypeParameterInstantiation; // TODO: Not in spec
implements?: $ReadOnlyArray<FlowClassImplements>;
// TODO: All not in spec
typeParameters?: ?TypeParameterDeclaration;
superTypeParameters?: ?TypeParameterInstantiation;
implements?: ?$ReadOnlyArray<TsExpressionWithTypeArguments> | $ReadOnlyArray<FlowClassImplements>;
};
export type ClassBody = NodeBase & {
@ -555,30 +584,30 @@ export type ClassMemberBase = NodeBase & HasDecorators & {
static: boolean;
computed: boolean;
// TypeScript only:
access?: ?Accessibility;
accessibility?: ?Accessibility;
abstract?: ?true;
optional?: ?true;
}
export type Accessibility = "public" | "protected" | "private";
export type ClassMember = ClassMethod | ClassProperty | ClassPrivateProperty | TsIndexSignature;
export type ClassMember = ClassMethod | ClassProperty | ClassPrivateProperty;
export type MethodLike = ObjectMethod | FunctionExpression | ClassMethod;
export type MethodLike = ObjectMethod | FunctionExpression | ClassMethod | TSDeclareMethod;
export type MethodBase = FunctionBase & {
+kind?: MethodKind;
+kind: MethodKind;
};
export type MethodKind = "constructor" | "method" | "get" | "set";
export type ClassMethod = MethodBase & ClassMemberBase & {
export type ClassMethodOrDeclareMethodCommon = ClassMemberBase & {
type: "ClassMethod";
key: Expression;
kind: MethodKind;
static: boolean;
decorators: $ReadOnlyArray<Decorator>;
};
export type ClassMethod = MethodBase & ClassMethodOrDeclareMethodCommon & {
variance?: ?FlowVariance; // TODO: Not in spec
};
@ -587,7 +616,7 @@ export type ClassProperty = ClassMemberBase & {
key: Expression;
value: ?Expression; // TODO: Not in spec that this is nullable.
typeAnnotation?: ?FlowTypeAnnotation; // TODO: Not in spec
typeAnnotation?: ?TypeAnnotation; // TODO: Not in spec
variance?: ?FlowVariance; // TODO: Not in spec
// TypeScript only: (TODO: Not in spec)
@ -622,12 +651,13 @@ export type MetaProperty = NodeBase & {
export type ModuleDeclaration = AnyImport | AnyExport;
export type AnyImport = ImportDeclaration;
export type AnyImport = ImportDeclaration | TsImportEqualsDeclaration;
export type AnyExport =
| ExportNamedDeclaration
| ExportDefaultDeclaration
| ExportAllDeclaration;
| ExportAllDeclaration
| TsExportAssignment;
export type ModuleSpecifier = NodeBase & {
local: Identifier;
@ -675,7 +705,7 @@ export type ExportSpecifier = NodeBase & {
export type ExportDefaultDeclaration = NodeBase & {
type: "ExportDefaultDeclaration";
declaration: OptFunctionDeclaration | OptClassDeclaration | Expression;
declaration: OptFunctionDeclaration | OptTSDeclareFunction | OptClassDeclaration | Expression;
};
export type ExportAllDeclaration = NodeBase & {
@ -696,8 +726,38 @@ export type JSXOpeningElement = Node;
export type JSXClosingElement = Node;
export type JSXElement = Node;
// Flow/TypeScript common (TODO: Not in spec)
export type TypeAnnotation = NodeBase & {
type: "TypeAnnotation";
typeAnnotation: TsType | FlowTypeAnnotation;
}
export type TypeParameterDeclaration = NodeBase & {
type: "TypeParameterDeclaration";
params: $ReadOnlyArray<TypeParameter>;
};
export type TypeParameter = NodeBase & {
type: "TypeParameter";
name: string;
constraint?: TsType;
default?: TsType;
};
export type TypeParameterInstantiation = NodeBase & {
type: "TypeParameterInstantiation";
params: $ReadOnlyArray<TsType> | $ReadOnlyArray<FlowType>;
};
// Flow (TODO: Not in spec)
export type TypeCastExpression = NodeBase & {
type: "TypeCastExpression";
expression: Expression;
typeAnnotation: TypeAnnotation;
};
export type FlowType = Node;
export type FlowPredicate = Node;
export type FlowDeclare = Node;
@ -712,9 +772,6 @@ export type FlowDeclareInterface = Node;
export type FlowInterface = Node;
export type FlowInterfaceExtends = Node;
export type FlowTypeAlias = Node;
export type FlowTypeParameter = Node;
export type FlowTypeParameterDeclaration = Node;
export type FlowTypeParameterInstantiation = Node;
export type FlowObjectTypeIndexer = Node;
export type FlowFunctionTypeAnnotation = Node;
export type FlowObjectTypeProperty = Node;
@ -730,7 +787,6 @@ export type FlowTypeAnnotation = Node;
export type FlowVariance = Node;
export type FlowClassImplements = Node;
// estree
export type EstreeProperty = NodeBase & {
@ -744,3 +800,362 @@ export type EstreeProperty = NodeBase & {
variance?: ?FlowVariance;
};
// === === === ===
// TypeScript
// === === === ===
// Note: A type named `TsFoo` is based on TypeScript's `FooNode` type,
// defined in https://github.com/Microsoft/TypeScript/blob/master/src/compiler/types.ts
// Differences:
// * Change `NodeArray<T>` to just `$ReadOnlyArray<T>`.
// * Don't give nodes a "modifiers" list; use boolean flags instead,
// and only allow modifiers that are not considered errors.
// * A property named `type` must be renamed to `typeAnnotation` to avoid conflict with the node's type.
// * Sometimes TypeScript allows to parse something which will be a grammar error later;
// in babylon these cause exceptions, so the AST format is stricter.
// ================
// Misc
// ================
export type TSParameterProperty = HasDecorators & {
// Note: This has decorators instead of its parameter.
type: "TSParameterProperty";
// At least one of `accessibility` or `readonly` must be set.
accessibility?: ?Accessibility;
readonly?: ?true;
parameter: Identifier | AssignmentPattern;
}
export type OptTSDeclareFunction = BodilessFunctionBase & DeclarationBase & {
type: "TSDeclareFunction";
}
export type TSDeclareFunction = OptTSDeclareFunction & {
id: Identifier;
};
export type TSDeclareMethod = BodilessFunctionOrMethodBase & ClassMethodOrDeclareMethodCommon & {
type: "TSDeclareMethod";
+kind: MethodKind;
};
export type TsQualifiedName = NodeBase & {
type: "TSQualifiedName";
left: TsEntityName;
right: Identifier;
}
export type TsEntityName = Identifier | TsQualifiedName;
export type TsSignatureDeclaration =
| TsCallSignatureDeclaration
| TsConstructSignatureDeclaration
| TsMethodSignature
| TsFunctionType
| TsConstructorType;
export type TsSignatureDeclarationOrIndexSignatureBase = NodeBase & {
// Not using TypeScript's "ParameterDeclaration" here, since it's inconsistent with regular functions.
parameters: $ReadOnlyArray<Identifier | RestElement>;
typeAnnotation: ?TypeAnnotation;
}
export type TsSignatureDeclarationBase = TsSignatureDeclarationOrIndexSignatureBase & {
typeParameters: ?TypeParameterDeclaration;
}
// ================
// TypeScript type members (for type literal / interface / class)
// ================
export type TsTypeElement =
| TsCallSignatureDeclaration
| TsConstructSignatureDeclaration
| TsPropertySignature
| TsMethodSignature
| TsIndexSignature;
export type TsCallSignatureDeclaration = TsSignatureDeclarationBase & {
type: "TSCallSignatureDeclaration";
}
export type TsConstructSignatureDeclaration = TsSignatureDeclarationBase & {
type: "TSConstructSignature";
}
export type TsNamedTypeElementBase = NodeBase & {
// Not using TypeScript's `PropertyName` here since we don't have a `ComputedPropertyName` node type.
// This is usually an Identifier but may be e.g. `Symbol.iterator` if `computed` is true.
key: Expression;
computed: boolean;
optional?: true;
}
export type TsPropertySignature = TsNamedTypeElementBase & {
type: "TSPropertySignature";
readonly?: true;
typeAnnotation?: TypeAnnotation;
initializer?: Expression;
};
export type TsMethodSignature = TsSignatureDeclarationBase & TsNamedTypeElementBase & {
type: "TSMethodSignature";
}
// *Not* a ClassMemberBase: Can't have accessibility, can't be abstract, can't be optional.
export type TsIndexSignature = TsSignatureDeclarationOrIndexSignatureBase & {
readonly?: true;
type: "TSIndexSignature";
// Note: parameters.length must be 1.
};
// ================
// TypeScript types
// ================
export type TsType =
| TsKeywordType
| TsThisType
| TsFunctionOrConstructorType
| TsTypeReference
| TsTypeQuery
| TsTypeLiteral
| TsArrayType
| TsTupleType
| TsUnionOrIntersectionType
| TsParenthesizedType
| TsTypeOperator
| TsIndexedAccessType
| TsMappedType
| TsLiteralType
// TODO: This probably shouldn't be included here.
| TsTypePredicate;
export type TsTypeBase = NodeBase;
export type TsKeywordTypeType =
| "TSAnyKeyword"
| "TSNumberKeyword"
| "TSObjectKeyword"
| "TSBooleanKeyword"
| "TSStringKeyword"
| "TSSymbolKeyword"
| "TSVoidKeyword"
| "TSUndefinedKeyword"
| "TSNullKeyword"
| "TSNeverKeyword";
export type TsKeywordType = TsTypeBase & {
type: TsKeywordTypeType;
}
export type TsThisType = TsTypeBase & {
type: "TSThisType"
};
export type TsFunctionOrConstructorType = TsFunctionType | TsConstructorType;
export type TsFunctionType = TsTypeBase & TsSignatureDeclarationBase & {
type: "TSFunctionType";
typeAnnotation: TypeAnnotation; // not optional
};
export type TsConstructorType = TsTypeBase & TsSignatureDeclarationBase & {
type: "TSConstructorType";
typeAnnotation: TypeAnnotation;
};
export type TsTypeReference = TsTypeBase & {
type: "TSTypeReference";
typeName: TsEntityName;
typeParameters?: TypeParameterInstantiation;
};
export type TsTypePredicate = TsTypeBase & {
type: "TSTypePredicate";
parameterName: Identifier | TsThisType;
typeAnnotation: TypeAnnotation;
};
// `typeof` operator
export type TsTypeQuery = TsTypeBase & {
type: "TSTypeQuery";
exprName: TsEntityName;
};
export type TsTypeLiteral = TsTypeBase & {
type: "TSTypeLiteral";
members: $ReadOnlyArray<TsTypeElement>;
};
export type TsArrayType = TsTypeBase & {
type: "TSArrayType";
elementType: TsType;
};
export type TsTupleType = TsTypeBase & {
type: "TSTupleType";
elementTypes: $ReadOnlyArray<TsType>;
};
export type TsUnionOrIntersectionType = TsUnionType | TsIntersectionType;
export type TsUnionOrIntersectionTypeBase = TsTypeBase & {
types: $ReadOnlyArray<TsType>;
};
export type TsUnionType = TsUnionOrIntersectionTypeBase & {
type: "TSUnionType";
};
export type TsIntersectionType = TsUnionOrIntersectionTypeBase & {
type: "TSIntersectionType";
};
export type TsParenthesizedType = TsTypeBase & {
type: "TSParenthesizedType";
typeAnnotation: TsType;
};
export type TsTypeOperator = TsTypeBase & {
type: "TSTypeOperator";
operator: "keyof";
typeAnnotation: TsType;
};
export type TsIndexedAccessType = TsTypeBase & {
type: "TSIndexedAccessType";
objectType: TsType;
indexType: TsType;
};
export type TsMappedType = TsTypeBase & {
type: "TSMappedType";
readonly?: true;
typeParameter: TypeParameter;
optional?: true;
typeAnnotation: ?TsType;
};
export type TsLiteralType = TsTypeBase & {
type: "TSLiteralType";
literal: NumericLiteral | StringLiteral | BooleanLiteral;
};
// ================
// TypeScript declarations
// ================
export type TsInterfaceDeclaration = DeclarationBase & {
type: "TSInterfaceDeclaration";
id: Identifier;
typeParameters: ?TypeParameterDeclaration;
// TS uses "heritageClauses", but want this to resemble ClassBase.
extends?: $ReadOnlyArray<TsExpressionWithTypeArguments>;
body: TSInterfaceBody;
}
export type TSInterfaceBody = NodeBase & {
type: "TSInterfaceBody";
body: $ReadOnlyArray<TsTypeElement>;
};
export type TsExpressionWithTypeArguments = TsTypeBase & {
type: "TSExpressionWithTypeArguments";
expression: TsEntityName;
typeParameters?: TypeParameterInstantiation;
};
export type TsTypeAliasDeclaration = DeclarationBase & {
type: "TSTypeAliasDeclaration";
id: Identifier;
typeParameters: ?TypeParameterDeclaration;
typeAnnotation: TsType;
};
export type TsEnumDeclaration = DeclarationBase & {
type: "TSEnumDeclaration";
const?: true;
id: Identifier;
members: $ReadOnlyArray<TsEnumMember>;
};
export type TsEnumMember = NodeBase & {
type: "TSEnumMemodulmber";
id: Identifier | StringLiteral;
initializer?: Expression;
};
export type TsModuleDeclaration = DeclarationBase & {
type: "TSModuleDeclaration";
global?: true; // In TypeScript, this is only available through `node.flags`.
id: TsModuleName;
body: TsNamespaceBody;
};
// `namespace A.B { }` is a namespace named `A` with another TsNamespaceDeclaration as its body.
export type TsNamespaceBody = TsModuleBlock | TsNamespaceDeclaration;
export type TsModuleBlock = NodeBase & {
type: "TSModuleBlock";
body: $ReadOnlyArray<Statement>;
};
export type TsNamespaceDeclaration = TsModuleDeclaration & {
id: Identifier;
body: TsNamespaceBody;
};
export type TsModuleName = Identifier | StringLiteral;
export type TsImportEqualsDeclaration = NodeBase & {
type: "TSImportEqualsDeclaration";
isExport: boolean;
id: Identifier;
moduleReference: TsModuleReference;
};
export type TsModuleReference = TsEntityName | TsExternalModuleReference;
export type TsExternalModuleReference = NodeBase & {
type: "TSExternalModuleReference";
expression: StringLiteral;
};
// TypeScript's own parser uses ExportAssignment for both `export default` and `export =`.
// But for babylon, `export default` is an ExportDefaultDeclaration,
// so a TsExportAssignment is always `export =`.
export type TsExportAssignment = NodeBase & {
type: "TSExportAssignment";
expression: Expression;
};
export type TsNamespaceExportDeclaration = NodeBase & {
type: "TSNamespaceExportDeclaration";
id: Identifier;
};
// ================
// TypeScript expressions
// ================
export type TsTypeAssertionLikeBase = NodeBase & {
expression: Expression;
typeAnnotation: TsType;
};
export type TsAsExpression = TsTypeAssertionLikeBase & {
type: "TSAsExpression";
};
export type TsTypeAssertion = TsTypeAssertionLikeBase & {
type: "TSTypeAssertion";
typeAnnotation: TsType;
expression: Expression;
};
export type TsNonNullExpression = NodeBase & {
type: "TSNonNullExpression";
expression: Expression;
};

View File

@ -0,0 +1 @@
function f([]?, {}) {}

View File

@ -0,0 +1,3 @@
{
"throws": "A binding pattern parameter cannot be optional in an implementation signature. (1:11)"
}

View File

@ -0,0 +1 @@
(x: number): number => x;

View File

@ -0,0 +1,164 @@
{
"type": "File",
"start": 0,
"end": 25,
"loc": {
"start": {
"line": 1,
"column": 0
},
"end": {
"line": 1,
"column": 25
}
},
"program": {
"type": "Program",
"start": 0,
"end": 25,
"loc": {
"start": {
"line": 1,
"column": 0
},
"end": {
"line": 1,
"column": 25
}
},
"sourceType": "module",
"body": [
{
"type": "ExpressionStatement",
"start": 0,
"end": 25,
"loc": {
"start": {
"line": 1,
"column": 0
},
"end": {
"line": 1,
"column": 25
}
},
"expression": {
"type": "ArrowFunctionExpression",
"start": 0,
"end": 24,
"loc": {
"start": {
"line": 1,
"column": 0
},
"end": {
"line": 1,
"column": 24
}
},
"returnType": {
"type": "TypeAnnotation",
"start": 11,
"end": 19,
"loc": {
"start": {
"line": 1,
"column": 11
},
"end": {
"line": 1,
"column": 19
}
},
"typeAnnotation": {
"type": "TSNumberKeyword",
"start": 13,
"end": 19,
"loc": {
"start": {
"line": 1,
"column": 13
},
"end": {
"line": 1,
"column": 19
}
}
}
},
"id": null,
"generator": false,
"expression": true,
"async": false,
"params": [
{
"type": "Identifier",
"start": 1,
"end": 10,
"loc": {
"start": {
"line": 1,
"column": 1
},
"end": {
"line": 1,
"column": 10
},
"identifierName": "x"
},
"name": "x",
"typeAnnotation": {
"type": "TypeAnnotation",
"start": 2,
"end": 10,
"loc": {
"start": {
"line": 1,
"column": 2
},
"end": {
"line": 1,
"column": 10
}
},
"typeAnnotation": {
"type": "TSNumberKeyword",
"start": 4,
"end": 10,
"loc": {
"start": {
"line": 1,
"column": 4
},
"end": {
"line": 1,
"column": 10
}
}
}
}
}
],
"body": {
"type": "Identifier",
"start": 23,
"end": 24,
"loc": {
"start": {
"line": 1,
"column": 23
},
"end": {
"line": 1,
"column": 24
},
"identifierName": "x"
},
"name": "x"
}
}
}
],
"directives": []
}
}

View File

@ -0,0 +1,2 @@
async < 1;
async<T>() == 0;

View File

@ -0,0 +1,235 @@
{
"type": "File",
"start": 0,
"end": 27,
"loc": {
"start": {
"line": 1,
"column": 0
},
"end": {
"line": 2,
"column": 16
}
},
"program": {
"type": "Program",
"start": 0,
"end": 27,
"loc": {
"start": {
"line": 1,
"column": 0
},
"end": {
"line": 2,
"column": 16
}
},
"sourceType": "module",
"body": [
{
"type": "ExpressionStatement",
"start": 0,
"end": 10,
"loc": {
"start": {
"line": 1,
"column": 0
},
"end": {
"line": 1,
"column": 10
}
},
"expression": {
"type": "BinaryExpression",
"start": 0,
"end": 9,
"loc": {
"start": {
"line": 1,
"column": 0
},
"end": {
"line": 1,
"column": 9
}
},
"left": {
"type": "Identifier",
"start": 0,
"end": 5,
"loc": {
"start": {
"line": 1,
"column": 0
},
"end": {
"line": 1,
"column": 5
},
"identifierName": "async"
},
"name": "async"
},
"operator": "<",
"right": {
"type": "NumericLiteral",
"start": 8,
"end": 9,
"loc": {
"start": {
"line": 1,
"column": 8
},
"end": {
"line": 1,
"column": 9
}
},
"extra": {
"rawValue": 1,
"raw": "1"
},
"value": 1
}
}
},
{
"type": "ExpressionStatement",
"start": 11,
"end": 27,
"loc": {
"start": {
"line": 2,
"column": 0
},
"end": {
"line": 2,
"column": 16
}
},
"expression": {
"type": "BinaryExpression",
"start": 11,
"end": 26,
"loc": {
"start": {
"line": 2,
"column": 0
},
"end": {
"line": 2,
"column": 15
}
},
"left": {
"type": "CallExpression",
"start": 11,
"end": 21,
"loc": {
"start": {
"line": 2,
"column": 0
},
"end": {
"line": 2,
"column": 10
}
},
"callee": {
"type": "Identifier",
"start": 11,
"end": 16,
"loc": {
"start": {
"line": 2,
"column": 0
},
"end": {
"line": 2,
"column": 5
},
"identifierName": "async"
},
"name": "async"
},
"arguments": [],
"typeParameters": {
"type": "TypeParameterInstantiation",
"start": 16,
"end": 19,
"loc": {
"start": {
"line": 2,
"column": 5
},
"end": {
"line": 2,
"column": 8
}
},
"params": [
{
"type": "TSTypeReference",
"start": 17,
"end": 18,
"loc": {
"start": {
"line": 2,
"column": 6
},
"end": {
"line": 2,
"column": 7
}
},
"typeName": {
"type": "Identifier",
"start": 17,
"end": 18,
"loc": {
"start": {
"line": 2,
"column": 6
},
"end": {
"line": 2,
"column": 7
},
"identifierName": "T"
},
"name": "T"
}
}
]
}
},
"operator": "==",
"right": {
"type": "NumericLiteral",
"start": 25,
"end": 26,
"loc": {
"start": {
"line": 2,
"column": 14
},
"end": {
"line": 2,
"column": 15
}
},
"extra": {
"rawValue": 0,
"raw": "0"
},
"value": 0
}
}
}
],
"directives": []
}
}

View File

@ -0,0 +1 @@
async <T>(a: T): T => a;

View File

@ -0,0 +1,231 @@
{
"type": "File",
"start": 0,
"end": 24,
"loc": {
"start": {
"line": 1,
"column": 0
},
"end": {
"line": 1,
"column": 24
}
},
"program": {
"type": "Program",
"start": 0,
"end": 24,
"loc": {
"start": {
"line": 1,
"column": 0
},
"end": {
"line": 1,
"column": 24
}
},
"sourceType": "module",
"body": [
{
"type": "ExpressionStatement",
"start": 0,
"end": 24,
"loc": {
"start": {
"line": 1,
"column": 0
},
"end": {
"line": 1,
"column": 24
}
},
"expression": {
"type": "ArrowFunctionExpression",
"start": 0,
"end": 23,
"loc": {
"start": {
"line": 1,
"column": 0
},
"end": {
"line": 1,
"column": 23
}
},
"typeParameters": {
"type": "TypeParameterDeclaration",
"start": 7,
"end": 9,
"loc": {
"start": {
"line": 1,
"column": 7
},
"end": {
"line": 1,
"column": 9
}
},
"params": [
{
"type": "TypeParameter",
"start": 7,
"end": 8,
"loc": {
"start": {
"line": 1,
"column": 7
},
"end": {
"line": 1,
"column": 8
}
},
"name": "T"
}
]
},
"params": [
{
"type": "Identifier",
"start": 10,
"end": 14,
"loc": {
"start": {
"line": 1,
"column": 10
},
"end": {
"line": 1,
"column": 14
},
"identifierName": "a"
},
"name": "a",
"typeAnnotation": {
"type": "TypeAnnotation",
"start": 11,
"end": 14,
"loc": {
"start": {
"line": 1,
"column": 11
},
"end": {
"line": 1,
"column": 14
}
},
"typeAnnotation": {
"type": "TSTypeReference",
"start": 13,
"end": 14,
"loc": {
"start": {
"line": 1,
"column": 13
},
"end": {
"line": 1,
"column": 14
}
},
"typeName": {
"type": "Identifier",
"start": 13,
"end": 14,
"loc": {
"start": {
"line": 1,
"column": 13
},
"end": {
"line": 1,
"column": 14
},
"identifierName": "T"
},
"name": "T"
}
}
}
}
],
"returnType": {
"type": "TypeAnnotation",
"start": 15,
"end": 18,
"loc": {
"start": {
"line": 1,
"column": 15
},
"end": {
"line": 1,
"column": 18
}
},
"typeAnnotation": {
"type": "TSTypeReference",
"start": 17,
"end": 18,
"loc": {
"start": {
"line": 1,
"column": 17
},
"end": {
"line": 1,
"column": 18
}
},
"typeName": {
"type": "Identifier",
"start": 17,
"end": 18,
"loc": {
"start": {
"line": 1,
"column": 17
},
"end": {
"line": 1,
"column": 18
},
"identifierName": "T"
},
"name": "T"
}
}
},
"id": null,
"generator": false,
"expression": true,
"async": true,
"body": {
"type": "Identifier",
"start": 22,
"end": 23,
"loc": {
"start": {
"line": 1,
"column": 22
},
"end": {
"line": 1,
"column": 23
},
"identifierName": "a"
},
"name": "a"
}
}
}
],
"directives": []
}
}

View File

@ -0,0 +1 @@
async (x?: number): any => x;

View File

@ -0,0 +1,165 @@
{
"type": "File",
"start": 0,
"end": 29,
"loc": {
"start": {
"line": 1,
"column": 0
},
"end": {
"line": 1,
"column": 29
}
},
"program": {
"type": "Program",
"start": 0,
"end": 29,
"loc": {
"start": {
"line": 1,
"column": 0
},
"end": {
"line": 1,
"column": 29
}
},
"sourceType": "module",
"body": [
{
"type": "ExpressionStatement",
"start": 0,
"end": 29,
"loc": {
"start": {
"line": 1,
"column": 0
},
"end": {
"line": 1,
"column": 29
}
},
"expression": {
"type": "ArrowFunctionExpression",
"start": 0,
"end": 28,
"loc": {
"start": {
"line": 1,
"column": 0
},
"end": {
"line": 1,
"column": 28
}
},
"returnType": {
"type": "TypeAnnotation",
"start": 18,
"end": 23,
"loc": {
"start": {
"line": 1,
"column": 18
},
"end": {
"line": 1,
"column": 23
}
},
"typeAnnotation": {
"type": "TSAnyKeyword",
"start": 20,
"end": 23,
"loc": {
"start": {
"line": 1,
"column": 20
},
"end": {
"line": 1,
"column": 23
}
}
}
},
"id": null,
"generator": false,
"expression": true,
"async": true,
"params": [
{
"type": "Identifier",
"start": 7,
"end": 17,
"loc": {
"start": {
"line": 1,
"column": 7
},
"end": {
"line": 1,
"column": 17
},
"identifierName": "x"
},
"name": "x",
"optional": true,
"typeAnnotation": {
"type": "TypeAnnotation",
"start": 9,
"end": 17,
"loc": {
"start": {
"line": 1,
"column": 9
},
"end": {
"line": 1,
"column": 17
}
},
"typeAnnotation": {
"type": "TSNumberKeyword",
"start": 11,
"end": 17,
"loc": {
"start": {
"line": 1,
"column": 11
},
"end": {
"line": 1,
"column": 17
}
}
}
}
}
],
"body": {
"type": "Identifier",
"start": 27,
"end": 28,
"loc": {
"start": {
"line": 1,
"column": 27
},
"end": {
"line": 1,
"column": 28
},
"identifierName": "x"
},
"name": "x"
}
}
}
],
"directives": []
}
}

View File

@ -0,0 +1 @@
(x: number = 0) => 0;

View File

@ -0,0 +1,172 @@
{
"type": "File",
"start": 0,
"end": 21,
"loc": {
"start": {
"line": 1,
"column": 0
},
"end": {
"line": 1,
"column": 21
}
},
"program": {
"type": "Program",
"start": 0,
"end": 21,
"loc": {
"start": {
"line": 1,
"column": 0
},
"end": {
"line": 1,
"column": 21
}
},
"sourceType": "module",
"body": [
{
"type": "ExpressionStatement",
"start": 0,
"end": 21,
"loc": {
"start": {
"line": 1,
"column": 0
},
"end": {
"line": 1,
"column": 21
}
},
"expression": {
"type": "ArrowFunctionExpression",
"start": 0,
"end": 20,
"loc": {
"start": {
"line": 1,
"column": 0
},
"end": {
"line": 1,
"column": 20
}
},
"id": null,
"generator": false,
"expression": true,
"async": false,
"params": [
{
"type": "AssignmentPattern",
"start": 1,
"end": 14,
"loc": {
"start": {
"line": 1,
"column": 1
},
"end": {
"line": 1,
"column": 14
}
},
"left": {
"type": "Identifier",
"start": 1,
"end": 10,
"loc": {
"start": {
"line": 1,
"column": 1
},
"end": {
"line": 1,
"column": 10
},
"identifierName": "x"
},
"name": "x",
"typeAnnotation": {
"type": "TypeAnnotation",
"start": 2,
"end": 10,
"loc": {
"start": {
"line": 1,
"column": 2
},
"end": {
"line": 1,
"column": 10
}
},
"typeAnnotation": {
"type": "TSNumberKeyword",
"start": 4,
"end": 10,
"loc": {
"start": {
"line": 1,
"column": 4
},
"end": {
"line": 1,
"column": 10
}
}
}
}
},
"right": {
"type": "NumericLiteral",
"start": 13,
"end": 14,
"loc": {
"start": {
"line": 1,
"column": 13
},
"end": {
"line": 1,
"column": 14
}
},
"extra": {
"rawValue": 0,
"raw": "0"
},
"value": 0
}
}
],
"body": {
"type": "NumericLiteral",
"start": 19,
"end": 20,
"loc": {
"start": {
"line": 1,
"column": 19
},
"end": {
"line": 1,
"column": 20
}
},
"extra": {
"rawValue": 0,
"raw": "0"
},
"value": 0
}
}
}
],
"directives": []
}
}

View File

@ -0,0 +1 @@
({ a = 0 }) => 0;

View File

@ -0,0 +1,197 @@
{
"type": "File",
"start": 0,
"end": 17,
"loc": {
"start": {
"line": 1,
"column": 0
},
"end": {
"line": 1,
"column": 17
}
},
"program": {
"type": "Program",
"start": 0,
"end": 17,
"loc": {
"start": {
"line": 1,
"column": 0
},
"end": {
"line": 1,
"column": 17
}
},
"sourceType": "module",
"body": [
{
"type": "ExpressionStatement",
"start": 0,
"end": 17,
"loc": {
"start": {
"line": 1,
"column": 0
},
"end": {
"line": 1,
"column": 17
}
},
"expression": {
"type": "ArrowFunctionExpression",
"start": 0,
"end": 16,
"loc": {
"start": {
"line": 1,
"column": 0
},
"end": {
"line": 1,
"column": 16
}
},
"id": null,
"generator": false,
"expression": true,
"async": false,
"params": [
{
"type": "ObjectPattern",
"start": 1,
"end": 10,
"loc": {
"start": {
"line": 1,
"column": 1
},
"end": {
"line": 1,
"column": 10
}
},
"properties": [
{
"type": "ObjectProperty",
"start": 3,
"end": 8,
"loc": {
"start": {
"line": 1,
"column": 3
},
"end": {
"line": 1,
"column": 8
}
},
"method": false,
"computed": false,
"key": {
"type": "Identifier",
"start": 3,
"end": 4,
"loc": {
"start": {
"line": 1,
"column": 3
},
"end": {
"line": 1,
"column": 4
},
"identifierName": "a"
},
"name": "a"
},
"shorthand": true,
"value": {
"type": "AssignmentPattern",
"start": 3,
"end": 8,
"loc": {
"start": {
"line": 1,
"column": 3
},
"end": {
"line": 1,
"column": 8
}
},
"left": {
"type": "Identifier",
"start": 3,
"end": 4,
"loc": {
"start": {
"line": 1,
"column": 3
},
"end": {
"line": 1,
"column": 4
},
"identifierName": "a"
},
"name": "a"
},
"right": {
"type": "NumericLiteral",
"start": 7,
"end": 8,
"loc": {
"start": {
"line": 1,
"column": 7
},
"end": {
"line": 1,
"column": 8
}
},
"extra": {
"rawValue": 0,
"raw": "0"
},
"value": 0
}
},
"extra": {
"shorthand": true
}
}
]
}
],
"body": {
"type": "NumericLiteral",
"start": 15,
"end": 16,
"loc": {
"start": {
"line": 1,
"column": 15
},
"end": {
"line": 1,
"column": 16
}
},
"extra": {
"rawValue": 0,
"raw": "0"
},
"value": 0
}
}
}
],
"directives": []
}
}

View File

@ -0,0 +1,2 @@
// Same as `generic`. Verify that JSX doesn't change things.
<T>(a: T): T => a;

View File

@ -0,0 +1,269 @@
{
"type": "File",
"start": 0,
"end": 79,
"loc": {
"start": {
"line": 1,
"column": 0
},
"end": {
"line": 2,
"column": 18
}
},
"program": {
"type": "Program",
"start": 0,
"end": 79,
"loc": {
"start": {
"line": 1,
"column": 0
},
"end": {
"line": 2,
"column": 18
}
},
"sourceType": "module",
"body": [
{
"type": "ExpressionStatement",
"start": 61,
"end": 79,
"loc": {
"start": {
"line": 2,
"column": 0
},
"end": {
"line": 2,
"column": 18
}
},
"expression": {
"type": "ArrowFunctionExpression",
"start": 62,
"end": 78,
"loc": {
"start": {
"line": 2,
"column": 1
},
"end": {
"line": 2,
"column": 17
}
},
"returnType": {
"type": "TypeAnnotation",
"start": 70,
"end": 73,
"loc": {
"start": {
"line": 2,
"column": 9
},
"end": {
"line": 2,
"column": 12
}
},
"typeAnnotation": {
"type": "TSTypeReference",
"start": 72,
"end": 73,
"loc": {
"start": {
"line": 2,
"column": 11
},
"end": {
"line": 2,
"column": 12
}
},
"typeName": {
"type": "Identifier",
"start": 72,
"end": 73,
"loc": {
"start": {
"line": 2,
"column": 11
},
"end": {
"line": 2,
"column": 12
},
"identifierName": "T"
},
"name": "T"
}
}
},
"id": null,
"generator": false,
"expression": true,
"async": false,
"params": [
{
"type": "Identifier",
"start": 65,
"end": 69,
"loc": {
"start": {
"line": 2,
"column": 4
},
"end": {
"line": 2,
"column": 8
},
"identifierName": "a"
},
"name": "a",
"typeAnnotation": {
"type": "TypeAnnotation",
"start": 66,
"end": 69,
"loc": {
"start": {
"line": 2,
"column": 5
},
"end": {
"line": 2,
"column": 8
}
},
"typeAnnotation": {
"type": "TSTypeReference",
"start": 68,
"end": 69,
"loc": {
"start": {
"line": 2,
"column": 7
},
"end": {
"line": 2,
"column": 8
}
},
"typeName": {
"type": "Identifier",
"start": 68,
"end": 69,
"loc": {
"start": {
"line": 2,
"column": 7
},
"end": {
"line": 2,
"column": 8
},
"identifierName": "T"
},
"name": "T"
}
}
}
}
],
"body": {
"type": "Identifier",
"start": 77,
"end": 78,
"loc": {
"start": {
"line": 2,
"column": 16
},
"end": {
"line": 2,
"column": 17
},
"identifierName": "a"
},
"name": "a"
},
"typeParameters": {
"type": "TypeParameterDeclaration",
"start": 62,
"end": 64,
"loc": {
"start": {
"line": 2,
"column": 1
},
"end": {
"line": 2,
"column": 3
}
},
"params": [
{
"type": "TypeParameter",
"start": 62,
"end": 63,
"loc": {
"start": {
"line": 2,
"column": 1
},
"end": {
"line": 2,
"column": 2
}
},
"name": "T",
"leadingComments": null
}
],
"leadingComments": null
}
},
"leadingComments": [
{
"type": "CommentLine",
"value": " Same as `generic`. Verify that JSX doesn't change things.",
"start": 0,
"end": 60,
"loc": {
"start": {
"line": 1,
"column": 0
},
"end": {
"line": 1,
"column": 60
}
}
}
]
}
],
"directives": []
},
"comments": [
{
"type": "CommentLine",
"value": " Same as `generic`. Verify that JSX doesn't change things.",
"start": 0,
"end": 60,
"loc": {
"start": {
"line": 1,
"column": 0
},
"end": {
"line": 1,
"column": 60
}
}
}
]
}

View File

@ -0,0 +1,3 @@
{
"plugins": ["jsx", "typescript"]
}

View File

@ -0,0 +1 @@
<T>(a: T): T => a;

View File

@ -0,0 +1,231 @@
{
"type": "File",
"start": 0,
"end": 18,
"loc": {
"start": {
"line": 1,
"column": 0
},
"end": {
"line": 1,
"column": 18
}
},
"program": {
"type": "Program",
"start": 0,
"end": 18,
"loc": {
"start": {
"line": 1,
"column": 0
},
"end": {
"line": 1,
"column": 18
}
},
"sourceType": "module",
"body": [
{
"type": "ExpressionStatement",
"start": 0,
"end": 18,
"loc": {
"start": {
"line": 1,
"column": 0
},
"end": {
"line": 1,
"column": 18
}
},
"expression": {
"type": "ArrowFunctionExpression",
"start": 1,
"end": 17,
"loc": {
"start": {
"line": 1,
"column": 1
},
"end": {
"line": 1,
"column": 17
}
},
"returnType": {
"type": "TypeAnnotation",
"start": 9,
"end": 12,
"loc": {
"start": {
"line": 1,
"column": 9
},
"end": {
"line": 1,
"column": 12
}
},
"typeAnnotation": {
"type": "TSTypeReference",
"start": 11,
"end": 12,
"loc": {
"start": {
"line": 1,
"column": 11
},
"end": {
"line": 1,
"column": 12
}
},
"typeName": {
"type": "Identifier",
"start": 11,
"end": 12,
"loc": {
"start": {
"line": 1,
"column": 11
},
"end": {
"line": 1,
"column": 12
},
"identifierName": "T"
},
"name": "T"
}
}
},
"id": null,
"generator": false,
"expression": true,
"async": false,
"params": [
{
"type": "Identifier",
"start": 4,
"end": 8,
"loc": {
"start": {
"line": 1,
"column": 4
},
"end": {
"line": 1,
"column": 8
},
"identifierName": "a"
},
"name": "a",
"typeAnnotation": {
"type": "TypeAnnotation",
"start": 5,
"end": 8,
"loc": {
"start": {
"line": 1,
"column": 5
},
"end": {
"line": 1,
"column": 8
}
},
"typeAnnotation": {
"type": "TSTypeReference",
"start": 7,
"end": 8,
"loc": {
"start": {
"line": 1,
"column": 7
},
"end": {
"line": 1,
"column": 8
}
},
"typeName": {
"type": "Identifier",
"start": 7,
"end": 8,
"loc": {
"start": {
"line": 1,
"column": 7
},
"end": {
"line": 1,
"column": 8
},
"identifierName": "T"
},
"name": "T"
}
}
}
}
],
"body": {
"type": "Identifier",
"start": 16,
"end": 17,
"loc": {
"start": {
"line": 1,
"column": 16
},
"end": {
"line": 1,
"column": 17
},
"identifierName": "a"
},
"name": "a"
},
"typeParameters": {
"type": "TypeParameterDeclaration",
"start": 1,
"end": 3,
"loc": {
"start": {
"line": 1,
"column": 1
},
"end": {
"line": 1,
"column": 3
}
},
"params": [
{
"type": "TypeParameter",
"start": 1,
"end": 2,
"loc": {
"start": {
"line": 1,
"column": 1
},
"end": {
"line": 1,
"column": 2
}
},
"name": "T"
}
]
}
}
}
],
"directives": []
}
}

View File

@ -0,0 +1 @@
(x?: number): any => x;

View File

@ -0,0 +1,165 @@
{
"type": "File",
"start": 0,
"end": 23,
"loc": {
"start": {
"line": 1,
"column": 0
},
"end": {
"line": 1,
"column": 23
}
},
"program": {
"type": "Program",
"start": 0,
"end": 23,
"loc": {
"start": {
"line": 1,
"column": 0
},
"end": {
"line": 1,
"column": 23
}
},
"sourceType": "module",
"body": [
{
"type": "ExpressionStatement",
"start": 0,
"end": 23,
"loc": {
"start": {
"line": 1,
"column": 0
},
"end": {
"line": 1,
"column": 23
}
},
"expression": {
"type": "ArrowFunctionExpression",
"start": 0,
"end": 22,
"loc": {
"start": {
"line": 1,
"column": 0
},
"end": {
"line": 1,
"column": 22
}
},
"returnType": {
"type": "TypeAnnotation",
"start": 12,
"end": 17,
"loc": {
"start": {
"line": 1,
"column": 12
},
"end": {
"line": 1,
"column": 17
}
},
"typeAnnotation": {
"type": "TSAnyKeyword",
"start": 14,
"end": 17,
"loc": {
"start": {
"line": 1,
"column": 14
},
"end": {
"line": 1,
"column": 17
}
}
}
},
"id": null,
"generator": false,
"expression": true,
"async": false,
"params": [
{
"type": "Identifier",
"start": 1,
"end": 11,
"loc": {
"start": {
"line": 1,
"column": 1
},
"end": {
"line": 1,
"column": 11
},
"identifierName": "x"
},
"name": "x",
"optional": true,
"typeAnnotation": {
"type": "TypeAnnotation",
"start": 3,
"end": 11,
"loc": {
"start": {
"line": 1,
"column": 3
},
"end": {
"line": 1,
"column": 11
}
},
"typeAnnotation": {
"type": "TSNumberKeyword",
"start": 5,
"end": 11,
"loc": {
"start": {
"line": 1,
"column": 5
},
"end": {
"line": 1,
"column": 11
}
}
}
}
}
],
"body": {
"type": "Identifier",
"start": 21,
"end": 22,
"loc": {
"start": {
"line": 1,
"column": 21
},
"end": {
"line": 1,
"column": 22
},
"identifierName": "x"
},
"name": "x"
}
}
}
],
"directives": []
}
}

View File

@ -0,0 +1 @@
(x: any): x is string => true;

View File

@ -0,0 +1,210 @@
{
"type": "File",
"start": 0,
"end": 30,
"loc": {
"start": {
"line": 1,
"column": 0
},
"end": {
"line": 1,
"column": 30
}
},
"program": {
"type": "Program",
"start": 0,
"end": 30,
"loc": {
"start": {
"line": 1,
"column": 0
},
"end": {
"line": 1,
"column": 30
}
},
"sourceType": "module",
"body": [
{
"type": "ExpressionStatement",
"start": 0,
"end": 30,
"loc": {
"start": {
"line": 1,
"column": 0
},
"end": {
"line": 1,
"column": 30
}
},
"expression": {
"type": "ArrowFunctionExpression",
"start": 0,
"end": 29,
"loc": {
"start": {
"line": 1,
"column": 0
},
"end": {
"line": 1,
"column": 29
}
},
"returnType": {
"type": "TypeAnnotation",
"start": 8,
"end": 21,
"loc": {
"start": {
"line": 1,
"column": 8
},
"end": {
"line": 1,
"column": 21
}
},
"typeAnnotation": {
"type": "TSTypePredicate",
"start": 10,
"end": 21,
"loc": {
"start": {
"line": 1,
"column": 10
},
"end": {
"line": 1,
"column": 21
}
},
"parameterName": {
"type": "Identifier",
"start": 10,
"end": 11,
"loc": {
"start": {
"line": 1,
"column": 10
},
"end": {
"line": 1,
"column": 11
},
"identifierName": "x"
},
"name": "x"
},
"typeAnnotation": {
"type": "TypeAnnotation",
"start": 15,
"end": 21,
"loc": {
"start": {
"line": 1,
"column": 15
},
"end": {
"line": 1,
"column": 21
}
},
"typeAnnotation": {
"type": "TSStringKeyword",
"start": 15,
"end": 21,
"loc": {
"start": {
"line": 1,
"column": 15
},
"end": {
"line": 1,
"column": 21
}
}
}
}
}
},
"id": null,
"generator": false,
"expression": true,
"async": false,
"params": [
{
"type": "Identifier",
"start": 1,
"end": 7,
"loc": {
"start": {
"line": 1,
"column": 1
},
"end": {
"line": 1,
"column": 7
},
"identifierName": "x"
},
"name": "x",
"typeAnnotation": {
"type": "TypeAnnotation",
"start": 2,
"end": 7,
"loc": {
"start": {
"line": 1,
"column": 2
},
"end": {
"line": 1,
"column": 7
}
},
"typeAnnotation": {
"type": "TSAnyKeyword",
"start": 4,
"end": 7,
"loc": {
"start": {
"line": 1,
"column": 4
},
"end": {
"line": 1,
"column": 7
}
}
}
}
}
],
"body": {
"type": "BooleanLiteral",
"start": 25,
"end": 29,
"loc": {
"start": {
"line": 1,
"column": 25
},
"end": {
"line": 1,
"column": 29
}
},
"value": true
}
}
}
],
"directives": []
}
}

View File

@ -0,0 +1,4 @@
x as T;
x < y as boolean; // (x < y) as boolean;
x === 1 as number; // x === (1 as number);
x as any as T;

View File

@ -0,0 +1,526 @@
{
"type": "File",
"start": 0,
"end": 106,
"loc": {
"start": {
"line": 1,
"column": 0
},
"end": {
"line": 4,
"column": 14
}
},
"program": {
"type": "Program",
"start": 0,
"end": 106,
"loc": {
"start": {
"line": 1,
"column": 0
},
"end": {
"line": 4,
"column": 14
}
},
"sourceType": "module",
"body": [
{
"type": "ExpressionStatement",
"start": 0,
"end": 7,
"loc": {
"start": {
"line": 1,
"column": 0
},
"end": {
"line": 1,
"column": 7
}
},
"expression": {
"type": "TSAsExpression",
"start": 0,
"end": 6,
"loc": {
"start": {
"line": 1,
"column": 0
},
"end": {
"line": 1,
"column": 6
}
},
"expression": {
"type": "Identifier",
"start": 0,
"end": 1,
"loc": {
"start": {
"line": 1,
"column": 0
},
"end": {
"line": 1,
"column": 1
},
"identifierName": "x"
},
"name": "x"
},
"typeAnnotation": {
"type": "TSTypeReference",
"start": 5,
"end": 6,
"loc": {
"start": {
"line": 1,
"column": 5
},
"end": {
"line": 1,
"column": 6
}
},
"typeName": {
"type": "Identifier",
"start": 5,
"end": 6,
"loc": {
"start": {
"line": 1,
"column": 5
},
"end": {
"line": 1,
"column": 6
},
"identifierName": "T"
},
"name": "T"
}
}
}
},
{
"type": "ExpressionStatement",
"start": 8,
"end": 25,
"loc": {
"start": {
"line": 2,
"column": 0
},
"end": {
"line": 2,
"column": 17
}
},
"expression": {
"type": "TSAsExpression",
"start": 8,
"end": 24,
"loc": {
"start": {
"line": 2,
"column": 0
},
"end": {
"line": 2,
"column": 16
}
},
"expression": {
"type": "BinaryExpression",
"start": 8,
"end": 13,
"loc": {
"start": {
"line": 2,
"column": 0
},
"end": {
"line": 2,
"column": 5
}
},
"left": {
"type": "Identifier",
"start": 8,
"end": 9,
"loc": {
"start": {
"line": 2,
"column": 0
},
"end": {
"line": 2,
"column": 1
},
"identifierName": "x"
},
"name": "x"
},
"operator": "<",
"right": {
"type": "Identifier",
"start": 12,
"end": 13,
"loc": {
"start": {
"line": 2,
"column": 4
},
"end": {
"line": 2,
"column": 5
},
"identifierName": "y"
},
"name": "y"
}
},
"typeAnnotation": {
"type": "TSBooleanKeyword",
"start": 17,
"end": 24,
"loc": {
"start": {
"line": 2,
"column": 9
},
"end": {
"line": 2,
"column": 16
}
}
}
},
"trailingComments": [
{
"type": "CommentLine",
"value": " (x < y) as boolean;",
"start": 26,
"end": 48,
"loc": {
"start": {
"line": 2,
"column": 18
},
"end": {
"line": 2,
"column": 40
}
}
}
]
},
{
"type": "ExpressionStatement",
"start": 49,
"end": 67,
"loc": {
"start": {
"line": 3,
"column": 0
},
"end": {
"line": 3,
"column": 18
}
},
"expression": {
"type": "BinaryExpression",
"start": 49,
"end": 66,
"loc": {
"start": {
"line": 3,
"column": 0
},
"end": {
"line": 3,
"column": 17
}
},
"left": {
"type": "Identifier",
"start": 49,
"end": 50,
"loc": {
"start": {
"line": 3,
"column": 0
},
"end": {
"line": 3,
"column": 1
},
"identifierName": "x"
},
"name": "x",
"leadingComments": null
},
"operator": "===",
"right": {
"type": "TSAsExpression",
"start": 55,
"end": 66,
"loc": {
"start": {
"line": 3,
"column": 6
},
"end": {
"line": 3,
"column": 17
}
},
"expression": {
"type": "NumericLiteral",
"start": 55,
"end": 56,
"loc": {
"start": {
"line": 3,
"column": 6
},
"end": {
"line": 3,
"column": 7
}
},
"extra": {
"rawValue": 1,
"raw": "1"
},
"value": 1
},
"typeAnnotation": {
"type": "TSNumberKeyword",
"start": 60,
"end": 66,
"loc": {
"start": {
"line": 3,
"column": 11
},
"end": {
"line": 3,
"column": 17
}
}
}
},
"leadingComments": null
},
"leadingComments": [
{
"type": "CommentLine",
"value": " (x < y) as boolean;",
"start": 26,
"end": 48,
"loc": {
"start": {
"line": 2,
"column": 18
},
"end": {
"line": 2,
"column": 40
}
}
}
],
"trailingComments": [
{
"type": "CommentLine",
"value": " x === (1 as number);",
"start": 68,
"end": 91,
"loc": {
"start": {
"line": 3,
"column": 19
},
"end": {
"line": 3,
"column": 42
}
}
}
]
},
{
"type": "ExpressionStatement",
"start": 92,
"end": 106,
"loc": {
"start": {
"line": 4,
"column": 0
},
"end": {
"line": 4,
"column": 14
}
},
"expression": {
"type": "TSAsExpression",
"start": 92,
"end": 105,
"loc": {
"start": {
"line": 4,
"column": 0
},
"end": {
"line": 4,
"column": 13
}
},
"expression": {
"type": "TSAsExpression",
"start": 92,
"end": 100,
"loc": {
"start": {
"line": 4,
"column": 0
},
"end": {
"line": 4,
"column": 8
}
},
"expression": {
"type": "Identifier",
"start": 92,
"end": 93,
"loc": {
"start": {
"line": 4,
"column": 0
},
"end": {
"line": 4,
"column": 1
},
"identifierName": "x"
},
"name": "x",
"leadingComments": null
},
"typeAnnotation": {
"type": "TSAnyKeyword",
"start": 97,
"end": 100,
"loc": {
"start": {
"line": 4,
"column": 5
},
"end": {
"line": 4,
"column": 8
}
}
},
"leadingComments": null
},
"typeAnnotation": {
"type": "TSTypeReference",
"start": 104,
"end": 105,
"loc": {
"start": {
"line": 4,
"column": 12
},
"end": {
"line": 4,
"column": 13
}
},
"typeName": {
"type": "Identifier",
"start": 104,
"end": 105,
"loc": {
"start": {
"line": 4,
"column": 12
},
"end": {
"line": 4,
"column": 13
},
"identifierName": "T"
},
"name": "T"
}
},
"leadingComments": null
},
"leadingComments": [
{
"type": "CommentLine",
"value": " x === (1 as number);",
"start": 68,
"end": 91,
"loc": {
"start": {
"line": 3,
"column": 19
},
"end": {
"line": 3,
"column": 42
}
}
}
]
}
],
"directives": []
},
"comments": [
{
"type": "CommentLine",
"value": " (x < y) as boolean;",
"start": 26,
"end": 48,
"loc": {
"start": {
"line": 2,
"column": 18
},
"end": {
"line": 2,
"column": 40
}
}
},
{
"type": "CommentLine",
"value": " x === (1 as number);",
"start": 68,
"end": 91,
"loc": {
"start": {
"line": 3,
"column": 19
},
"end": {
"line": 3,
"column": 42
}
}
}
]
}

View File

@ -0,0 +1 @@
f(x < 0, /a/);

View File

@ -0,0 +1,156 @@
{
"type": "File",
"start": 0,
"end": 14,
"loc": {
"start": {
"line": 1,
"column": 0
},
"end": {
"line": 1,
"column": 14
}
},
"program": {
"type": "Program",
"start": 0,
"end": 14,
"loc": {
"start": {
"line": 1,
"column": 0
},
"end": {
"line": 1,
"column": 14
}
},
"sourceType": "module",
"body": [
{
"type": "ExpressionStatement",
"start": 0,
"end": 14,
"loc": {
"start": {
"line": 1,
"column": 0
},
"end": {
"line": 1,
"column": 14
}
},
"expression": {
"type": "CallExpression",
"start": 0,
"end": 13,
"loc": {
"start": {
"line": 1,
"column": 0
},
"end": {
"line": 1,
"column": 13
}
},
"callee": {
"type": "Identifier",
"start": 0,
"end": 1,
"loc": {
"start": {
"line": 1,
"column": 0
},
"end": {
"line": 1,
"column": 1
},
"identifierName": "f"
},
"name": "f"
},
"arguments": [
{
"type": "BinaryExpression",
"start": 2,
"end": 7,
"loc": {
"start": {
"line": 1,
"column": 2
},
"end": {
"line": 1,
"column": 7
}
},
"left": {
"type": "Identifier",
"start": 2,
"end": 3,
"loc": {
"start": {
"line": 1,
"column": 2
},
"end": {
"line": 1,
"column": 3
},
"identifierName": "x"
},
"name": "x"
},
"operator": "<",
"right": {
"type": "NumericLiteral",
"start": 6,
"end": 7,
"loc": {
"start": {
"line": 1,
"column": 6
},
"end": {
"line": 1,
"column": 7
}
},
"extra": {
"rawValue": 0,
"raw": "0"
},
"value": 0
}
},
{
"type": "RegExpLiteral",
"start": 9,
"end": 12,
"loc": {
"start": {
"line": 1,
"column": 9
},
"end": {
"line": 1,
"column": 12
}
},
"extra": {
"raw": "/a/"
},
"pattern": "a",
"flags": ""
}
]
}
}
],
"directives": []
}
}

View File

@ -0,0 +1,3 @@
(<T> x).y;
(x as T).y;
x!.y;

View File

@ -0,0 +1,346 @@
{
"type": "File",
"start": 0,
"end": 28,
"loc": {
"start": {
"line": 1,
"column": 0
},
"end": {
"line": 3,
"column": 5
}
},
"program": {
"type": "Program",
"start": 0,
"end": 28,
"loc": {
"start": {
"line": 1,
"column": 0
},
"end": {
"line": 3,
"column": 5
}
},
"sourceType": "module",
"body": [
{
"type": "ExpressionStatement",
"start": 0,
"end": 10,
"loc": {
"start": {
"line": 1,
"column": 0
},
"end": {
"line": 1,
"column": 10
}
},
"expression": {
"type": "MemberExpression",
"start": 0,
"end": 9,
"loc": {
"start": {
"line": 1,
"column": 0
},
"end": {
"line": 1,
"column": 9
}
},
"object": {
"type": "TSTypeAssertion",
"start": 2,
"end": 6,
"loc": {
"start": {
"line": 1,
"column": 2
},
"end": {
"line": 1,
"column": 6
}
},
"typeAnnotation": {
"type": "TSTypeReference",
"start": 2,
"end": 3,
"loc": {
"start": {
"line": 1,
"column": 2
},
"end": {
"line": 1,
"column": 3
}
},
"typeName": {
"type": "Identifier",
"start": 2,
"end": 3,
"loc": {
"start": {
"line": 1,
"column": 2
},
"end": {
"line": 1,
"column": 3
},
"identifierName": "T"
},
"name": "T"
}
},
"expression": {
"type": "Identifier",
"start": 5,
"end": 6,
"loc": {
"start": {
"line": 1,
"column": 5
},
"end": {
"line": 1,
"column": 6
},
"identifierName": "x"
},
"name": "x"
},
"extra": {
"parenthesized": true,
"parenStart": 0
}
},
"property": {
"type": "Identifier",
"start": 8,
"end": 9,
"loc": {
"start": {
"line": 1,
"column": 8
},
"end": {
"line": 1,
"column": 9
},
"identifierName": "y"
},
"name": "y"
},
"computed": false
}
},
{
"type": "ExpressionStatement",
"start": 11,
"end": 22,
"loc": {
"start": {
"line": 2,
"column": 0
},
"end": {
"line": 2,
"column": 11
}
},
"expression": {
"type": "MemberExpression",
"start": 11,
"end": 21,
"loc": {
"start": {
"line": 2,
"column": 0
},
"end": {
"line": 2,
"column": 10
}
},
"object": {
"type": "TSAsExpression",
"start": 12,
"end": 18,
"loc": {
"start": {
"line": 2,
"column": 1
},
"end": {
"line": 2,
"column": 7
}
},
"expression": {
"type": "Identifier",
"start": 12,
"end": 13,
"loc": {
"start": {
"line": 2,
"column": 1
},
"end": {
"line": 2,
"column": 2
},
"identifierName": "x"
},
"name": "x"
},
"typeAnnotation": {
"type": "TSTypeReference",
"start": 17,
"end": 18,
"loc": {
"start": {
"line": 2,
"column": 6
},
"end": {
"line": 2,
"column": 7
}
},
"typeName": {
"type": "Identifier",
"start": 17,
"end": 18,
"loc": {
"start": {
"line": 2,
"column": 6
},
"end": {
"line": 2,
"column": 7
},
"identifierName": "T"
},
"name": "T"
}
},
"extra": {
"parenthesized": true,
"parenStart": 11
}
},
"property": {
"type": "Identifier",
"start": 20,
"end": 21,
"loc": {
"start": {
"line": 2,
"column": 9
},
"end": {
"line": 2,
"column": 10
},
"identifierName": "y"
},
"name": "y"
},
"computed": false
}
},
{
"type": "ExpressionStatement",
"start": 23,
"end": 28,
"loc": {
"start": {
"line": 3,
"column": 0
},
"end": {
"line": 3,
"column": 5
}
},
"expression": {
"type": "MemberExpression",
"start": 23,
"end": 27,
"loc": {
"start": {
"line": 3,
"column": 0
},
"end": {
"line": 3,
"column": 4
}
},
"object": {
"type": "TSNonNullExpression",
"start": 23,
"end": 25,
"loc": {
"start": {
"line": 3,
"column": 0
},
"end": {
"line": 3,
"column": 2
}
},
"expression": {
"type": "Identifier",
"start": 23,
"end": 24,
"loc": {
"start": {
"line": 3,
"column": 0
},
"end": {
"line": 3,
"column": 1
},
"identifierName": "x"
},
"name": "x"
}
},
"property": {
"type": "Identifier",
"start": 26,
"end": 27,
"loc": {
"start": {
"line": 3,
"column": 3
},
"end": {
"line": 3,
"column": 4
},
"identifierName": "y"
},
"name": "y"
},
"computed": false
}
}
],
"directives": []
}
}

View File

@ -0,0 +1 @@
x!.y;

View File

@ -0,0 +1,114 @@
{
"type": "File",
"start": 0,
"end": 5,
"loc": {
"start": {
"line": 1,
"column": 0
},
"end": {
"line": 1,
"column": 5
}
},
"program": {
"type": "Program",
"start": 0,
"end": 5,
"loc": {
"start": {
"line": 1,
"column": 0
},
"end": {
"line": 1,
"column": 5
}
},
"sourceType": "module",
"body": [
{
"type": "ExpressionStatement",
"start": 0,
"end": 5,
"loc": {
"start": {
"line": 1,
"column": 0
},
"end": {
"line": 1,
"column": 5
}
},
"expression": {
"type": "MemberExpression",
"start": 0,
"end": 4,
"loc": {
"start": {
"line": 1,
"column": 0
},
"end": {
"line": 1,
"column": 4
}
},
"object": {
"type": "TSNonNullExpression",
"start": 0,
"end": 2,
"loc": {
"start": {
"line": 1,
"column": 0
},
"end": {
"line": 1,
"column": 2
}
},
"expression": {
"type": "Identifier",
"start": 0,
"end": 1,
"loc": {
"start": {
"line": 1,
"column": 0
},
"end": {
"line": 1,
"column": 1
},
"identifierName": "x"
},
"name": "x"
}
},
"property": {
"type": "Identifier",
"start": 3,
"end": 4,
"loc": {
"start": {
"line": 1,
"column": 3
},
"end": {
"line": 1,
"column": 4
},
"identifierName": "y"
},
"name": "y"
},
"computed": false
}
}
],
"directives": []
}
}

View File

@ -0,0 +1 @@
x!;

View File

@ -0,0 +1,81 @@
{
"type": "File",
"start": 0,
"end": 3,
"loc": {
"start": {
"line": 1,
"column": 0
},
"end": {
"line": 1,
"column": 3
}
},
"program": {
"type": "Program",
"start": 0,
"end": 3,
"loc": {
"start": {
"line": 1,
"column": 0
},
"end": {
"line": 1,
"column": 3
}
},
"sourceType": "module",
"body": [
{
"type": "ExpressionStatement",
"start": 0,
"end": 3,
"loc": {
"start": {
"line": 1,
"column": 0
},
"end": {
"line": 1,
"column": 3
}
},
"expression": {
"type": "TSNonNullExpression",
"start": 0,
"end": 2,
"loc": {
"start": {
"line": 1,
"column": 0
},
"end": {
"line": 1,
"column": 2
}
},
"expression": {
"type": "Identifier",
"start": 0,
"end": 1,
"loc": {
"start": {
"line": 1,
"column": 0
},
"end": {
"line": 1,
"column": 1
},
"identifierName": "x"
},
"name": "x"
}
}
}
],
"directives": []
}
}

View File

@ -0,0 +1 @@
1 + <number> 1;

View File

@ -0,0 +1,135 @@
{
"type": "File",
"start": 0,
"end": 15,
"loc": {
"start": {
"line": 1,
"column": 0
},
"end": {
"line": 1,
"column": 15
}
},
"program": {
"type": "Program",
"start": 0,
"end": 15,
"loc": {
"start": {
"line": 1,
"column": 0
},
"end": {
"line": 1,
"column": 15
}
},
"sourceType": "module",
"body": [
{
"type": "ExpressionStatement",
"start": 0,
"end": 15,
"loc": {
"start": {
"line": 1,
"column": 0
},
"end": {
"line": 1,
"column": 15
}
},
"expression": {
"type": "BinaryExpression",
"start": 0,
"end": 14,
"loc": {
"start": {
"line": 1,
"column": 0
},
"end": {
"line": 1,
"column": 14
}
},
"left": {
"type": "NumericLiteral",
"start": 0,
"end": 1,
"loc": {
"start": {
"line": 1,
"column": 0
},
"end": {
"line": 1,
"column": 1
}
},
"extra": {
"rawValue": 1,
"raw": "1"
},
"value": 1
},
"operator": "+",
"right": {
"type": "TSTypeAssertion",
"start": 5,
"end": 14,
"loc": {
"start": {
"line": 1,
"column": 5
},
"end": {
"line": 1,
"column": 14
}
},
"typeAnnotation": {
"type": "TSNumberKeyword",
"start": 5,
"end": 11,
"loc": {
"start": {
"line": 1,
"column": 5
},
"end": {
"line": 1,
"column": 11
}
}
},
"expression": {
"type": "NumericLiteral",
"start": 13,
"end": 14,
"loc": {
"start": {
"line": 1,
"column": 13
},
"end": {
"line": 1,
"column": 14
}
},
"extra": {
"rawValue": 1,
"raw": "1"
},
"value": 1
}
}
}
}
],
"directives": []
}
}

View File

@ -0,0 +1 @@
<number> 1 + 1;

View File

@ -0,0 +1,135 @@
{
"type": "File",
"start": 0,
"end": 15,
"loc": {
"start": {
"line": 1,
"column": 0
},
"end": {
"line": 1,
"column": 15
}
},
"program": {
"type": "Program",
"start": 0,
"end": 15,
"loc": {
"start": {
"line": 1,
"column": 0
},
"end": {
"line": 1,
"column": 15
}
},
"sourceType": "module",
"body": [
{
"type": "ExpressionStatement",
"start": 0,
"end": 15,
"loc": {
"start": {
"line": 1,
"column": 0
},
"end": {
"line": 1,
"column": 15
}
},
"expression": {
"type": "BinaryExpression",
"start": 0,
"end": 14,
"loc": {
"start": {
"line": 1,
"column": 0
},
"end": {
"line": 1,
"column": 14
}
},
"left": {
"type": "TSTypeAssertion",
"start": 1,
"end": 10,
"loc": {
"start": {
"line": 1,
"column": 1
},
"end": {
"line": 1,
"column": 10
}
},
"typeAnnotation": {
"type": "TSNumberKeyword",
"start": 1,
"end": 7,
"loc": {
"start": {
"line": 1,
"column": 1
},
"end": {
"line": 1,
"column": 7
}
}
},
"expression": {
"type": "NumericLiteral",
"start": 9,
"end": 10,
"loc": {
"start": {
"line": 1,
"column": 9
},
"end": {
"line": 1,
"column": 10
}
},
"extra": {
"rawValue": 1,
"raw": "1"
},
"value": 1
}
},
"operator": "+",
"right": {
"type": "NumericLiteral",
"start": 13,
"end": 14,
"loc": {
"start": {
"line": 1,
"column": 13
},
"end": {
"line": 1,
"column": 14
}
},
"extra": {
"rawValue": 1,
"raw": "1"
},
"value": 1
}
}
}
],
"directives": []
}
}

View File

@ -0,0 +1 @@
<number> 1;

View File

@ -0,0 +1,99 @@
{
"type": "File",
"start": 0,
"end": 11,
"loc": {
"start": {
"line": 1,
"column": 0
},
"end": {
"line": 1,
"column": 11
}
},
"program": {
"type": "Program",
"start": 0,
"end": 11,
"loc": {
"start": {
"line": 1,
"column": 0
},
"end": {
"line": 1,
"column": 11
}
},
"sourceType": "module",
"body": [
{
"type": "ExpressionStatement",
"start": 0,
"end": 11,
"loc": {
"start": {
"line": 1,
"column": 0
},
"end": {
"line": 1,
"column": 11
}
},
"expression": {
"type": "TSTypeAssertion",
"start": 1,
"end": 10,
"loc": {
"start": {
"line": 1,
"column": 1
},
"end": {
"line": 1,
"column": 10
}
},
"typeAnnotation": {
"type": "TSNumberKeyword",
"start": 1,
"end": 7,
"loc": {
"start": {
"line": 1,
"column": 1
},
"end": {
"line": 1,
"column": 7
}
}
},
"expression": {
"type": "NumericLiteral",
"start": 9,
"end": 10,
"loc": {
"start": {
"line": 1,
"column": 9
},
"end": {
"line": 1,
"column": 10
}
},
"extra": {
"rawValue": 1,
"raw": "1"
},
"value": 1
}
}
}
],
"directives": []
}
}

View File

@ -0,0 +1,6 @@
abstract class C {}
declare abstract class C {}
export abstract class C {}
// `export abstract class { }` is not valid.
// `export default abstract class C { }` is not valid.
// `abstract class` is not valid as an expression.

View File

@ -0,0 +1,305 @@
{
"type": "File",
"start": 0,
"end": 225,
"loc": {
"start": {
"line": 1,
"column": 0
},
"end": {
"line": 6,
"column": 50
}
},
"program": {
"type": "Program",
"start": 0,
"end": 225,
"loc": {
"start": {
"line": 1,
"column": 0
},
"end": {
"line": 6,
"column": 50
}
},
"sourceType": "module",
"body": [
{
"type": "ClassDeclaration",
"start": 0,
"end": 19,
"loc": {
"start": {
"line": 1,
"column": 0
},
"end": {
"line": 1,
"column": 19
}
},
"abstract": true,
"id": {
"type": "Identifier",
"start": 15,
"end": 16,
"loc": {
"start": {
"line": 1,
"column": 15
},
"end": {
"line": 1,
"column": 16
},
"identifierName": "C"
},
"name": "C"
},
"superClass": null,
"body": {
"type": "ClassBody",
"start": 17,
"end": 19,
"loc": {
"start": {
"line": 1,
"column": 17
},
"end": {
"line": 1,
"column": 19
}
},
"body": []
}
},
{
"type": "ClassDeclaration",
"start": 20,
"end": 47,
"loc": {
"start": {
"line": 2,
"column": 0
},
"end": {
"line": 2,
"column": 27
}
},
"abstract": true,
"id": {
"type": "Identifier",
"start": 43,
"end": 44,
"loc": {
"start": {
"line": 2,
"column": 23
},
"end": {
"line": 2,
"column": 24
},
"identifierName": "C"
},
"name": "C"
},
"superClass": null,
"body": {
"type": "ClassBody",
"start": 45,
"end": 47,
"loc": {
"start": {
"line": 2,
"column": 25
},
"end": {
"line": 2,
"column": 27
}
},
"body": []
},
"declare": true
},
{
"type": "ExportNamedDeclaration",
"start": 48,
"end": 74,
"loc": {
"start": {
"line": 3,
"column": 0
},
"end": {
"line": 3,
"column": 26
}
},
"specifiers": [],
"source": null,
"declaration": {
"type": "ClassDeclaration",
"start": 55,
"end": 74,
"loc": {
"start": {
"line": 3,
"column": 7
},
"end": {
"line": 3,
"column": 26
}
},
"abstract": true,
"id": {
"type": "Identifier",
"start": 70,
"end": 71,
"loc": {
"start": {
"line": 3,
"column": 22
},
"end": {
"line": 3,
"column": 23
},
"identifierName": "C"
},
"name": "C"
},
"superClass": null,
"body": {
"type": "ClassBody",
"start": 72,
"end": 74,
"loc": {
"start": {
"line": 3,
"column": 24
},
"end": {
"line": 3,
"column": 26
}
},
"body": [],
"leadingComments": null,
"trailingComments": null
},
"trailingComments": null
},
"trailingComments": [
{
"type": "CommentLine",
"value": " `export abstract class { }` is not valid.",
"start": 75,
"end": 119,
"loc": {
"start": {
"line": 4,
"column": 0
},
"end": {
"line": 4,
"column": 44
}
}
},
{
"type": "CommentLine",
"value": " `export default abstract class C { }` is not valid.",
"start": 120,
"end": 174,
"loc": {
"start": {
"line": 5,
"column": 0
},
"end": {
"line": 5,
"column": 54
}
}
},
{
"type": "CommentLine",
"value": " `abstract class` is not valid as an expression.",
"start": 175,
"end": 225,
"loc": {
"start": {
"line": 6,
"column": 0
},
"end": {
"line": 6,
"column": 50
}
}
}
]
}
],
"directives": []
},
"comments": [
{
"type": "CommentLine",
"value": " `export abstract class { }` is not valid.",
"start": 75,
"end": 119,
"loc": {
"start": {
"line": 4,
"column": 0
},
"end": {
"line": 4,
"column": 44
}
}
},
{
"type": "CommentLine",
"value": " `export default abstract class C { }` is not valid.",
"start": 120,
"end": 174,
"loc": {
"start": {
"line": 5,
"column": 0
},
"end": {
"line": 5,
"column": 54
}
}
},
{
"type": "CommentLine",
"value": " `abstract class` is not valid as an expression.",
"start": 175,
"end": 225,
"loc": {
"start": {
"line": 6,
"column": 0
},
"end": {
"line": 6,
"column": 50
}
}
}
]
}

View File

@ -0,0 +1,5 @@
class C {
constructor(x: number, y: number);
constructor(x: string, y: string);
constructor(x: any, y: any) {}
}

View File

@ -0,0 +1,506 @@
{
"type": "File",
"start": 0,
"end": 124,
"loc": {
"start": {
"line": 1,
"column": 0
},
"end": {
"line": 5,
"column": 1
}
},
"program": {
"type": "Program",
"start": 0,
"end": 124,
"loc": {
"start": {
"line": 1,
"column": 0
},
"end": {
"line": 5,
"column": 1
}
},
"sourceType": "module",
"body": [
{
"type": "ClassDeclaration",
"start": 0,
"end": 124,
"loc": {
"start": {
"line": 1,
"column": 0
},
"end": {
"line": 5,
"column": 1
}
},
"id": {
"type": "Identifier",
"start": 6,
"end": 7,
"loc": {
"start": {
"line": 1,
"column": 6
},
"end": {
"line": 1,
"column": 7
},
"identifierName": "C"
},
"name": "C"
},
"superClass": null,
"body": {
"type": "ClassBody",
"start": 8,
"end": 124,
"loc": {
"start": {
"line": 1,
"column": 8
},
"end": {
"line": 5,
"column": 1
}
},
"body": [
{
"type": "TSDeclareMethod",
"start": 14,
"end": 48,
"loc": {
"start": {
"line": 2,
"column": 4
},
"end": {
"line": 2,
"column": 38
}
},
"static": false,
"computed": false,
"key": {
"type": "Identifier",
"start": 14,
"end": 25,
"loc": {
"start": {
"line": 2,
"column": 4
},
"end": {
"line": 2,
"column": 15
},
"identifierName": "constructor"
},
"name": "constructor"
},
"kind": "constructor",
"id": null,
"generator": false,
"expression": false,
"async": false,
"params": [
{
"type": "Identifier",
"start": 26,
"end": 35,
"loc": {
"start": {
"line": 2,
"column": 16
},
"end": {
"line": 2,
"column": 25
},
"identifierName": "x"
},
"name": "x",
"typeAnnotation": {
"type": "TypeAnnotation",
"start": 27,
"end": 35,
"loc": {
"start": {
"line": 2,
"column": 17
},
"end": {
"line": 2,
"column": 25
}
},
"typeAnnotation": {
"type": "TSNumberKeyword",
"start": 29,
"end": 35,
"loc": {
"start": {
"line": 2,
"column": 19
},
"end": {
"line": 2,
"column": 25
}
}
}
}
},
{
"type": "Identifier",
"start": 37,
"end": 46,
"loc": {
"start": {
"line": 2,
"column": 27
},
"end": {
"line": 2,
"column": 36
},
"identifierName": "y"
},
"name": "y",
"typeAnnotation": {
"type": "TypeAnnotation",
"start": 38,
"end": 46,
"loc": {
"start": {
"line": 2,
"column": 28
},
"end": {
"line": 2,
"column": 36
}
},
"typeAnnotation": {
"type": "TSNumberKeyword",
"start": 40,
"end": 46,
"loc": {
"start": {
"line": 2,
"column": 30
},
"end": {
"line": 2,
"column": 36
}
}
}
}
}
]
},
{
"type": "TSDeclareMethod",
"start": 53,
"end": 87,
"loc": {
"start": {
"line": 3,
"column": 4
},
"end": {
"line": 3,
"column": 38
}
},
"static": false,
"computed": false,
"key": {
"type": "Identifier",
"start": 53,
"end": 64,
"loc": {
"start": {
"line": 3,
"column": 4
},
"end": {
"line": 3,
"column": 15
},
"identifierName": "constructor"
},
"name": "constructor"
},
"kind": "constructor",
"id": null,
"generator": false,
"expression": false,
"async": false,
"params": [
{
"type": "Identifier",
"start": 65,
"end": 74,
"loc": {
"start": {
"line": 3,
"column": 16
},
"end": {
"line": 3,
"column": 25
},
"identifierName": "x"
},
"name": "x",
"typeAnnotation": {
"type": "TypeAnnotation",
"start": 66,
"end": 74,
"loc": {
"start": {
"line": 3,
"column": 17
},
"end": {
"line": 3,
"column": 25
}
},
"typeAnnotation": {
"type": "TSStringKeyword",
"start": 68,
"end": 74,
"loc": {
"start": {
"line": 3,
"column": 19
},
"end": {
"line": 3,
"column": 25
}
}
}
}
},
{
"type": "Identifier",
"start": 76,
"end": 85,
"loc": {
"start": {
"line": 3,
"column": 27
},
"end": {
"line": 3,
"column": 36
},
"identifierName": "y"
},
"name": "y",
"typeAnnotation": {
"type": "TypeAnnotation",
"start": 77,
"end": 85,
"loc": {
"start": {
"line": 3,
"column": 28
},
"end": {
"line": 3,
"column": 36
}
},
"typeAnnotation": {
"type": "TSStringKeyword",
"start": 79,
"end": 85,
"loc": {
"start": {
"line": 3,
"column": 30
},
"end": {
"line": 3,
"column": 36
}
}
}
}
}
]
},
{
"type": "ClassMethod",
"start": 92,
"end": 122,
"loc": {
"start": {
"line": 4,
"column": 4
},
"end": {
"line": 4,
"column": 34
}
},
"static": false,
"computed": false,
"key": {
"type": "Identifier",
"start": 92,
"end": 103,
"loc": {
"start": {
"line": 4,
"column": 4
},
"end": {
"line": 4,
"column": 15
},
"identifierName": "constructor"
},
"name": "constructor"
},
"kind": "constructor",
"id": null,
"generator": false,
"expression": false,
"async": false,
"params": [
{
"type": "Identifier",
"start": 104,
"end": 110,
"loc": {
"start": {
"line": 4,
"column": 16
},
"end": {
"line": 4,
"column": 22
},
"identifierName": "x"
},
"name": "x",
"typeAnnotation": {
"type": "TypeAnnotation",
"start": 105,
"end": 110,
"loc": {
"start": {
"line": 4,
"column": 17
},
"end": {
"line": 4,
"column": 22
}
},
"typeAnnotation": {
"type": "TSAnyKeyword",
"start": 107,
"end": 110,
"loc": {
"start": {
"line": 4,
"column": 19
},
"end": {
"line": 4,
"column": 22
}
}
}
}
},
{
"type": "Identifier",
"start": 112,
"end": 118,
"loc": {
"start": {
"line": 4,
"column": 24
},
"end": {
"line": 4,
"column": 30
},
"identifierName": "y"
},
"name": "y",
"typeAnnotation": {
"type": "TypeAnnotation",
"start": 113,
"end": 118,
"loc": {
"start": {
"line": 4,
"column": 25
},
"end": {
"line": 4,
"column": 30
}
},
"typeAnnotation": {
"type": "TSAnyKeyword",
"start": 115,
"end": 118,
"loc": {
"start": {
"line": 4,
"column": 27
},
"end": {
"line": 4,
"column": 30
}
}
}
}
}
],
"body": {
"type": "BlockStatement",
"start": 120,
"end": 122,
"loc": {
"start": {
"line": 4,
"column": 32
},
"end": {
"line": 4,
"column": 34
}
},
"body": [],
"directives": []
}
}
]
}
}
],
"directives": []
}
}

View File

@ -0,0 +1,7 @@
declare class C {
[x: string]: any;
x;
x: number;
f();
f(): void;
}

View File

@ -0,0 +1,389 @@
{
"type": "File",
"start": 0,
"end": 87,
"loc": {
"start": {
"line": 1,
"column": 0
},
"end": {
"line": 7,
"column": 1
}
},
"program": {
"type": "Program",
"start": 0,
"end": 87,
"loc": {
"start": {
"line": 1,
"column": 0
},
"end": {
"line": 7,
"column": 1
}
},
"sourceType": "module",
"body": [
{
"type": "ClassDeclaration",
"start": 0,
"end": 87,
"loc": {
"start": {
"line": 1,
"column": 0
},
"end": {
"line": 7,
"column": 1
}
},
"id": {
"type": "Identifier",
"start": 14,
"end": 15,
"loc": {
"start": {
"line": 1,
"column": 14
},
"end": {
"line": 1,
"column": 15
},
"identifierName": "C"
},
"name": "C"
},
"superClass": null,
"body": {
"type": "ClassBody",
"start": 16,
"end": 87,
"loc": {
"start": {
"line": 1,
"column": 16
},
"end": {
"line": 7,
"column": 1
}
},
"body": [
{
"type": "TSIndexSignature",
"start": 22,
"end": 39,
"loc": {
"start": {
"line": 2,
"column": 4
},
"end": {
"line": 2,
"column": 21
}
},
"parameters": [
{
"type": "Identifier",
"start": 23,
"end": 24,
"loc": {
"start": {
"line": 2,
"column": 5
},
"end": {
"line": 2,
"column": 6
},
"identifierName": "x"
},
"name": "x",
"typeAnnotation": {
"type": "TypeAnnotation",
"start": 26,
"end": 32,
"loc": {
"start": {
"line": 2,
"column": 8
},
"end": {
"line": 2,
"column": 14
}
},
"typeAnnotation": {
"type": "TSStringKeyword",
"start": 26,
"end": 32,
"loc": {
"start": {
"line": 2,
"column": 8
},
"end": {
"line": 2,
"column": 14
}
}
}
}
}
],
"typeAnnotation": {
"type": "TypeAnnotation",
"start": 33,
"end": 38,
"loc": {
"start": {
"line": 2,
"column": 15
},
"end": {
"line": 2,
"column": 20
}
},
"typeAnnotation": {
"type": "TSAnyKeyword",
"start": 35,
"end": 38,
"loc": {
"start": {
"line": 2,
"column": 17
},
"end": {
"line": 2,
"column": 20
}
}
}
}
},
{
"type": "ClassProperty",
"start": 44,
"end": 46,
"loc": {
"start": {
"line": 3,
"column": 4
},
"end": {
"line": 3,
"column": 6
}
},
"static": false,
"computed": false,
"key": {
"type": "Identifier",
"start": 44,
"end": 45,
"loc": {
"start": {
"line": 3,
"column": 4
},
"end": {
"line": 3,
"column": 5
},
"identifierName": "x"
},
"name": "x"
},
"value": null
},
{
"type": "ClassProperty",
"start": 51,
"end": 61,
"loc": {
"start": {
"line": 4,
"column": 4
},
"end": {
"line": 4,
"column": 14
}
},
"static": false,
"computed": false,
"key": {
"type": "Identifier",
"start": 51,
"end": 52,
"loc": {
"start": {
"line": 4,
"column": 4
},
"end": {
"line": 4,
"column": 5
},
"identifierName": "x"
},
"name": "x"
},
"typeAnnotation": {
"type": "TypeAnnotation",
"start": 52,
"end": 60,
"loc": {
"start": {
"line": 4,
"column": 5
},
"end": {
"line": 4,
"column": 13
}
},
"typeAnnotation": {
"type": "TSNumberKeyword",
"start": 54,
"end": 60,
"loc": {
"start": {
"line": 4,
"column": 7
},
"end": {
"line": 4,
"column": 13
}
}
}
},
"value": null
},
{
"type": "TSDeclareMethod",
"start": 66,
"end": 70,
"loc": {
"start": {
"line": 5,
"column": 4
},
"end": {
"line": 5,
"column": 8
}
},
"static": false,
"computed": false,
"key": {
"type": "Identifier",
"start": 66,
"end": 67,
"loc": {
"start": {
"line": 5,
"column": 4
},
"end": {
"line": 5,
"column": 5
},
"identifierName": "f"
},
"name": "f"
},
"kind": "method",
"id": null,
"generator": false,
"expression": false,
"async": false,
"params": []
},
{
"type": "TSDeclareMethod",
"start": 75,
"end": 85,
"loc": {
"start": {
"line": 6,
"column": 4
},
"end": {
"line": 6,
"column": 14
}
},
"static": false,
"computed": false,
"key": {
"type": "Identifier",
"start": 75,
"end": 76,
"loc": {
"start": {
"line": 6,
"column": 4
},
"end": {
"line": 6,
"column": 5
},
"identifierName": "f"
},
"name": "f"
},
"kind": "method",
"id": null,
"generator": false,
"expression": false,
"async": false,
"params": [],
"returnType": {
"type": "TypeAnnotation",
"start": 78,
"end": 84,
"loc": {
"start": {
"line": 6,
"column": 7
},
"end": {
"line": 6,
"column": 13
}
},
"typeAnnotation": {
"type": "TSVoidKeyword",
"start": 80,
"end": 84,
"loc": {
"start": {
"line": 6,
"column": 9
},
"end": {
"line": 6,
"column": 13
}
}
}
}
}
]
},
"declare": true
}
],
"directives": []
}
}

View File

@ -0,0 +1,2 @@
(class extends f()<T> implements X.Y<T> {});
(class C extends f()<T> implements X.Y<T> {});

View File

@ -0,0 +1,546 @@
{
"type": "File",
"start": 0,
"end": 91,
"loc": {
"start": {
"line": 1,
"column": 0
},
"end": {
"line": 2,
"column": 46
}
},
"program": {
"type": "Program",
"start": 0,
"end": 91,
"loc": {
"start": {
"line": 1,
"column": 0
},
"end": {
"line": 2,
"column": 46
}
},
"sourceType": "module",
"body": [
{
"type": "ExpressionStatement",
"start": 0,
"end": 44,
"loc": {
"start": {
"line": 1,
"column": 0
},
"end": {
"line": 1,
"column": 44
}
},
"expression": {
"type": "ClassExpression",
"start": 1,
"end": 42,
"loc": {
"start": {
"line": 1,
"column": 1
},
"end": {
"line": 1,
"column": 42
}
},
"id": null,
"superClass": {
"type": "CallExpression",
"start": 15,
"end": 18,
"loc": {
"start": {
"line": 1,
"column": 15
},
"end": {
"line": 1,
"column": 18
}
},
"callee": {
"type": "Identifier",
"start": 15,
"end": 16,
"loc": {
"start": {
"line": 1,
"column": 15
},
"end": {
"line": 1,
"column": 16
},
"identifierName": "f"
},
"name": "f"
},
"arguments": []
},
"superTypeParameters": {
"type": "TypeParameterInstantiation",
"start": 18,
"end": 21,
"loc": {
"start": {
"line": 1,
"column": 18
},
"end": {
"line": 1,
"column": 21
}
},
"params": [
{
"type": "TSTypeReference",
"start": 19,
"end": 20,
"loc": {
"start": {
"line": 1,
"column": 19
},
"end": {
"line": 1,
"column": 20
}
},
"typeName": {
"type": "Identifier",
"start": 19,
"end": 20,
"loc": {
"start": {
"line": 1,
"column": 19
},
"end": {
"line": 1,
"column": 20
},
"identifierName": "T"
},
"name": "T"
}
}
]
},
"implements": [
{
"type": "TSExpressionWithTypeArguments",
"start": 33,
"end": 39,
"loc": {
"start": {
"line": 1,
"column": 33
},
"end": {
"line": 1,
"column": 39
}
},
"expression": {
"type": "TSQualifiedName",
"start": 33,
"end": 36,
"loc": {
"start": {
"line": 1,
"column": 33
},
"end": {
"line": 1,
"column": 36
}
},
"left": {
"type": "Identifier",
"start": 33,
"end": 34,
"loc": {
"start": {
"line": 1,
"column": 33
},
"end": {
"line": 1,
"column": 34
},
"identifierName": "X"
},
"name": "X"
},
"right": {
"type": "Identifier",
"start": 35,
"end": 36,
"loc": {
"start": {
"line": 1,
"column": 35
},
"end": {
"line": 1,
"column": 36
},
"identifierName": "Y"
},
"name": "Y"
}
},
"typeParameters": {
"type": "TypeParameterInstantiation",
"start": 36,
"end": 39,
"loc": {
"start": {
"line": 1,
"column": 36
},
"end": {
"line": 1,
"column": 39
}
},
"params": [
{
"type": "TSTypeReference",
"start": 37,
"end": 38,
"loc": {
"start": {
"line": 1,
"column": 37
},
"end": {
"line": 1,
"column": 38
}
},
"typeName": {
"type": "Identifier",
"start": 37,
"end": 38,
"loc": {
"start": {
"line": 1,
"column": 37
},
"end": {
"line": 1,
"column": 38
},
"identifierName": "T"
},
"name": "T"
}
}
]
}
}
],
"body": {
"type": "ClassBody",
"start": 40,
"end": 42,
"loc": {
"start": {
"line": 1,
"column": 40
},
"end": {
"line": 1,
"column": 42
}
},
"body": []
},
"extra": {
"parenthesized": true,
"parenStart": 0
}
}
},
{
"type": "ExpressionStatement",
"start": 45,
"end": 91,
"loc": {
"start": {
"line": 2,
"column": 0
},
"end": {
"line": 2,
"column": 46
}
},
"expression": {
"type": "ClassExpression",
"start": 46,
"end": 89,
"loc": {
"start": {
"line": 2,
"column": 1
},
"end": {
"line": 2,
"column": 44
}
},
"id": {
"type": "Identifier",
"start": 52,
"end": 53,
"loc": {
"start": {
"line": 2,
"column": 7
},
"end": {
"line": 2,
"column": 8
},
"identifierName": "C"
},
"name": "C"
},
"superClass": {
"type": "CallExpression",
"start": 62,
"end": 65,
"loc": {
"start": {
"line": 2,
"column": 17
},
"end": {
"line": 2,
"column": 20
}
},
"callee": {
"type": "Identifier",
"start": 62,
"end": 63,
"loc": {
"start": {
"line": 2,
"column": 17
},
"end": {
"line": 2,
"column": 18
},
"identifierName": "f"
},
"name": "f"
},
"arguments": []
},
"superTypeParameters": {
"type": "TypeParameterInstantiation",
"start": 65,
"end": 68,
"loc": {
"start": {
"line": 2,
"column": 20
},
"end": {
"line": 2,
"column": 23
}
},
"params": [
{
"type": "TSTypeReference",
"start": 66,
"end": 67,
"loc": {
"start": {
"line": 2,
"column": 21
},
"end": {
"line": 2,
"column": 22
}
},
"typeName": {
"type": "Identifier",
"start": 66,
"end": 67,
"loc": {
"start": {
"line": 2,
"column": 21
},
"end": {
"line": 2,
"column": 22
},
"identifierName": "T"
},
"name": "T"
}
}
]
},
"implements": [
{
"type": "TSExpressionWithTypeArguments",
"start": 80,
"end": 86,
"loc": {
"start": {
"line": 2,
"column": 35
},
"end": {
"line": 2,
"column": 41
}
},
"expression": {
"type": "TSQualifiedName",
"start": 80,
"end": 83,
"loc": {
"start": {
"line": 2,
"column": 35
},
"end": {
"line": 2,
"column": 38
}
},
"left": {
"type": "Identifier",
"start": 80,
"end": 81,
"loc": {
"start": {
"line": 2,
"column": 35
},
"end": {
"line": 2,
"column": 36
},
"identifierName": "X"
},
"name": "X"
},
"right": {
"type": "Identifier",
"start": 82,
"end": 83,
"loc": {
"start": {
"line": 2,
"column": 37
},
"end": {
"line": 2,
"column": 38
},
"identifierName": "Y"
},
"name": "Y"
}
},
"typeParameters": {
"type": "TypeParameterInstantiation",
"start": 83,
"end": 86,
"loc": {
"start": {
"line": 2,
"column": 38
},
"end": {
"line": 2,
"column": 41
}
},
"params": [
{
"type": "TSTypeReference",
"start": 84,
"end": 85,
"loc": {
"start": {
"line": 2,
"column": 39
},
"end": {
"line": 2,
"column": 40
}
},
"typeName": {
"type": "Identifier",
"start": 84,
"end": 85,
"loc": {
"start": {
"line": 2,
"column": 39
},
"end": {
"line": 2,
"column": 40
},
"identifierName": "T"
},
"name": "T"
}
}
]
}
}
],
"body": {
"type": "ClassBody",
"start": 87,
"end": 89,
"loc": {
"start": {
"line": 2,
"column": 42
},
"end": {
"line": 2,
"column": 44
}
},
"body": []
},
"extra": {
"parenthesized": true,
"parenStart": 45
}
}
}
],
"directives": []
}
}

View File

@ -0,0 +1,2 @@
(class extends f()<T> {});
(class C extends f()<T> {});

View File

@ -0,0 +1,316 @@
{
"type": "File",
"start": 0,
"end": 55,
"loc": {
"start": {
"line": 1,
"column": 0
},
"end": {
"line": 2,
"column": 28
}
},
"program": {
"type": "Program",
"start": 0,
"end": 55,
"loc": {
"start": {
"line": 1,
"column": 0
},
"end": {
"line": 2,
"column": 28
}
},
"sourceType": "module",
"body": [
{
"type": "ExpressionStatement",
"start": 0,
"end": 26,
"loc": {
"start": {
"line": 1,
"column": 0
},
"end": {
"line": 1,
"column": 26
}
},
"expression": {
"type": "ClassExpression",
"start": 1,
"end": 24,
"loc": {
"start": {
"line": 1,
"column": 1
},
"end": {
"line": 1,
"column": 24
}
},
"id": null,
"superClass": {
"type": "CallExpression",
"start": 15,
"end": 18,
"loc": {
"start": {
"line": 1,
"column": 15
},
"end": {
"line": 1,
"column": 18
}
},
"callee": {
"type": "Identifier",
"start": 15,
"end": 16,
"loc": {
"start": {
"line": 1,
"column": 15
},
"end": {
"line": 1,
"column": 16
},
"identifierName": "f"
},
"name": "f"
},
"arguments": []
},
"superTypeParameters": {
"type": "TypeParameterInstantiation",
"start": 18,
"end": 21,
"loc": {
"start": {
"line": 1,
"column": 18
},
"end": {
"line": 1,
"column": 21
}
},
"params": [
{
"type": "TSTypeReference",
"start": 19,
"end": 20,
"loc": {
"start": {
"line": 1,
"column": 19
},
"end": {
"line": 1,
"column": 20
}
},
"typeName": {
"type": "Identifier",
"start": 19,
"end": 20,
"loc": {
"start": {
"line": 1,
"column": 19
},
"end": {
"line": 1,
"column": 20
},
"identifierName": "T"
},
"name": "T"
}
}
]
},
"body": {
"type": "ClassBody",
"start": 22,
"end": 24,
"loc": {
"start": {
"line": 1,
"column": 22
},
"end": {
"line": 1,
"column": 24
}
},
"body": []
},
"extra": {
"parenthesized": true,
"parenStart": 0
}
}
},
{
"type": "ExpressionStatement",
"start": 27,
"end": 55,
"loc": {
"start": {
"line": 2,
"column": 0
},
"end": {
"line": 2,
"column": 28
}
},
"expression": {
"type": "ClassExpression",
"start": 28,
"end": 53,
"loc": {
"start": {
"line": 2,
"column": 1
},
"end": {
"line": 2,
"column": 26
}
},
"id": {
"type": "Identifier",
"start": 34,
"end": 35,
"loc": {
"start": {
"line": 2,
"column": 7
},
"end": {
"line": 2,
"column": 8
},
"identifierName": "C"
},
"name": "C"
},
"superClass": {
"type": "CallExpression",
"start": 44,
"end": 47,
"loc": {
"start": {
"line": 2,
"column": 17
},
"end": {
"line": 2,
"column": 20
}
},
"callee": {
"type": "Identifier",
"start": 44,
"end": 45,
"loc": {
"start": {
"line": 2,
"column": 17
},
"end": {
"line": 2,
"column": 18
},
"identifierName": "f"
},
"name": "f"
},
"arguments": []
},
"superTypeParameters": {
"type": "TypeParameterInstantiation",
"start": 47,
"end": 50,
"loc": {
"start": {
"line": 2,
"column": 20
},
"end": {
"line": 2,
"column": 23
}
},
"params": [
{
"type": "TSTypeReference",
"start": 48,
"end": 49,
"loc": {
"start": {
"line": 2,
"column": 21
},
"end": {
"line": 2,
"column": 22
}
},
"typeName": {
"type": "Identifier",
"start": 48,
"end": 49,
"loc": {
"start": {
"line": 2,
"column": 21
},
"end": {
"line": 2,
"column": 22
},
"identifierName": "T"
},
"name": "T"
}
}
]
},
"body": {
"type": "ClassBody",
"start": 51,
"end": 53,
"loc": {
"start": {
"line": 2,
"column": 24
},
"end": {
"line": 2,
"column": 26
}
},
"body": []
},
"extra": {
"parenthesized": true,
"parenStart": 27
}
}
}
],
"directives": []
}
}

View File

@ -0,0 +1,2 @@
(class<T> {});
(class C<T> {});

View File

@ -0,0 +1,220 @@
{
"type": "File",
"start": 0,
"end": 31,
"loc": {
"start": {
"line": 1,
"column": 0
},
"end": {
"line": 2,
"column": 16
}
},
"program": {
"type": "Program",
"start": 0,
"end": 31,
"loc": {
"start": {
"line": 1,
"column": 0
},
"end": {
"line": 2,
"column": 16
}
},
"sourceType": "module",
"body": [
{
"type": "ExpressionStatement",
"start": 0,
"end": 14,
"loc": {
"start": {
"line": 1,
"column": 0
},
"end": {
"line": 1,
"column": 14
}
},
"expression": {
"type": "ClassExpression",
"start": 1,
"end": 12,
"loc": {
"start": {
"line": 1,
"column": 1
},
"end": {
"line": 1,
"column": 12
}
},
"id": null,
"typeParameters": {
"type": "TypeParameterDeclaration",
"start": 7,
"end": 9,
"loc": {
"start": {
"line": 1,
"column": 7
},
"end": {
"line": 1,
"column": 9
}
},
"params": [
{
"type": "TypeParameter",
"start": 7,
"end": 8,
"loc": {
"start": {
"line": 1,
"column": 7
},
"end": {
"line": 1,
"column": 8
}
},
"name": "T"
}
]
},
"superClass": null,
"body": {
"type": "ClassBody",
"start": 10,
"end": 12,
"loc": {
"start": {
"line": 1,
"column": 10
},
"end": {
"line": 1,
"column": 12
}
},
"body": []
},
"extra": {
"parenthesized": true,
"parenStart": 0
}
}
},
{
"type": "ExpressionStatement",
"start": 15,
"end": 31,
"loc": {
"start": {
"line": 2,
"column": 0
},
"end": {
"line": 2,
"column": 16
}
},
"expression": {
"type": "ClassExpression",
"start": 16,
"end": 29,
"loc": {
"start": {
"line": 2,
"column": 1
},
"end": {
"line": 2,
"column": 14
}
},
"id": {
"type": "Identifier",
"start": 22,
"end": 23,
"loc": {
"start": {
"line": 2,
"column": 7
},
"end": {
"line": 2,
"column": 8
},
"identifierName": "C"
},
"name": "C"
},
"typeParameters": {
"type": "TypeParameterDeclaration",
"start": 24,
"end": 26,
"loc": {
"start": {
"line": 2,
"column": 9
},
"end": {
"line": 2,
"column": 11
}
},
"params": [
{
"type": "TypeParameter",
"start": 24,
"end": 25,
"loc": {
"start": {
"line": 2,
"column": 9
},
"end": {
"line": 2,
"column": 10
}
},
"name": "T"
}
]
},
"superClass": null,
"body": {
"type": "ClassBody",
"start": 27,
"end": 29,
"loc": {
"start": {
"line": 2,
"column": 12
},
"end": {
"line": 2,
"column": 14
}
},
"body": []
},
"extra": {
"parenthesized": true,
"parenStart": 15
}
}
}
],
"directives": []
}
}

View File

@ -0,0 +1,2 @@
(class implements X.Y<T> {});
(class C implements X.Y<T> {});

View File

@ -0,0 +1,383 @@
{
"type": "File",
"start": 0,
"end": 61,
"loc": {
"start": {
"line": 1,
"column": 0
},
"end": {
"line": 2,
"column": 31
}
},
"program": {
"type": "Program",
"start": 0,
"end": 61,
"loc": {
"start": {
"line": 1,
"column": 0
},
"end": {
"line": 2,
"column": 31
}
},
"sourceType": "module",
"body": [
{
"type": "ExpressionStatement",
"start": 0,
"end": 29,
"loc": {
"start": {
"line": 1,
"column": 0
},
"end": {
"line": 1,
"column": 29
}
},
"expression": {
"type": "ClassExpression",
"start": 1,
"end": 27,
"loc": {
"start": {
"line": 1,
"column": 1
},
"end": {
"line": 1,
"column": 27
}
},
"superClass": null,
"implements": [
{
"type": "TSExpressionWithTypeArguments",
"start": 18,
"end": 24,
"loc": {
"start": {
"line": 1,
"column": 18
},
"end": {
"line": 1,
"column": 24
}
},
"expression": {
"type": "TSQualifiedName",
"start": 18,
"end": 21,
"loc": {
"start": {
"line": 1,
"column": 18
},
"end": {
"line": 1,
"column": 21
}
},
"left": {
"type": "Identifier",
"start": 18,
"end": 19,
"loc": {
"start": {
"line": 1,
"column": 18
},
"end": {
"line": 1,
"column": 19
},
"identifierName": "X"
},
"name": "X"
},
"right": {
"type": "Identifier",
"start": 20,
"end": 21,
"loc": {
"start": {
"line": 1,
"column": 20
},
"end": {
"line": 1,
"column": 21
},
"identifierName": "Y"
},
"name": "Y"
}
},
"typeParameters": {
"type": "TypeParameterInstantiation",
"start": 21,
"end": 24,
"loc": {
"start": {
"line": 1,
"column": 21
},
"end": {
"line": 1,
"column": 24
}
},
"params": [
{
"type": "TSTypeReference",
"start": 22,
"end": 23,
"loc": {
"start": {
"line": 1,
"column": 22
},
"end": {
"line": 1,
"column": 23
}
},
"typeName": {
"type": "Identifier",
"start": 22,
"end": 23,
"loc": {
"start": {
"line": 1,
"column": 22
},
"end": {
"line": 1,
"column": 23
},
"identifierName": "T"
},
"name": "T"
}
}
]
}
}
],
"body": {
"type": "ClassBody",
"start": 25,
"end": 27,
"loc": {
"start": {
"line": 1,
"column": 25
},
"end": {
"line": 1,
"column": 27
}
},
"body": []
},
"extra": {
"parenthesized": true,
"parenStart": 0
}
}
},
{
"type": "ExpressionStatement",
"start": 30,
"end": 61,
"loc": {
"start": {
"line": 2,
"column": 0
},
"end": {
"line": 2,
"column": 31
}
},
"expression": {
"type": "ClassExpression",
"start": 31,
"end": 59,
"loc": {
"start": {
"line": 2,
"column": 1
},
"end": {
"line": 2,
"column": 29
}
},
"id": {
"type": "Identifier",
"start": 37,
"end": 38,
"loc": {
"start": {
"line": 2,
"column": 7
},
"end": {
"line": 2,
"column": 8
},
"identifierName": "C"
},
"name": "C"
},
"superClass": null,
"implements": [
{
"type": "TSExpressionWithTypeArguments",
"start": 50,
"end": 56,
"loc": {
"start": {
"line": 2,
"column": 20
},
"end": {
"line": 2,
"column": 26
}
},
"expression": {
"type": "TSQualifiedName",
"start": 50,
"end": 53,
"loc": {
"start": {
"line": 2,
"column": 20
},
"end": {
"line": 2,
"column": 23
}
},
"left": {
"type": "Identifier",
"start": 50,
"end": 51,
"loc": {
"start": {
"line": 2,
"column": 20
},
"end": {
"line": 2,
"column": 21
},
"identifierName": "X"
},
"name": "X"
},
"right": {
"type": "Identifier",
"start": 52,
"end": 53,
"loc": {
"start": {
"line": 2,
"column": 22
},
"end": {
"line": 2,
"column": 23
},
"identifierName": "Y"
},
"name": "Y"
}
},
"typeParameters": {
"type": "TypeParameterInstantiation",
"start": 53,
"end": 56,
"loc": {
"start": {
"line": 2,
"column": 23
},
"end": {
"line": 2,
"column": 26
}
},
"params": [
{
"type": "TSTypeReference",
"start": 54,
"end": 55,
"loc": {
"start": {
"line": 2,
"column": 24
},
"end": {
"line": 2,
"column": 25
}
},
"typeName": {
"type": "Identifier",
"start": 54,
"end": 55,
"loc": {
"start": {
"line": 2,
"column": 24
},
"end": {
"line": 2,
"column": 25
},
"identifierName": "T"
},
"name": "T"
}
}
]
}
}
],
"body": {
"type": "ClassBody",
"start": 57,
"end": 59,
"loc": {
"start": {
"line": 2,
"column": 27
},
"end": {
"line": 2,
"column": 29
}
},
"body": []
},
"extra": {
"parenthesized": true,
"parenStart": 30
}
}
}
],
"directives": []
}
}

View File

@ -0,0 +1 @@
class C extends f()<T> implements X.Y<T> {}

View File

@ -0,0 +1,279 @@
{
"type": "File",
"start": 0,
"end": 43,
"loc": {
"start": {
"line": 1,
"column": 0
},
"end": {
"line": 1,
"column": 43
}
},
"program": {
"type": "Program",
"start": 0,
"end": 43,
"loc": {
"start": {
"line": 1,
"column": 0
},
"end": {
"line": 1,
"column": 43
}
},
"sourceType": "module",
"body": [
{
"type": "ClassDeclaration",
"start": 0,
"end": 43,
"loc": {
"start": {
"line": 1,
"column": 0
},
"end": {
"line": 1,
"column": 43
}
},
"id": {
"type": "Identifier",
"start": 6,
"end": 7,
"loc": {
"start": {
"line": 1,
"column": 6
},
"end": {
"line": 1,
"column": 7
},
"identifierName": "C"
},
"name": "C"
},
"superClass": {
"type": "CallExpression",
"start": 16,
"end": 19,
"loc": {
"start": {
"line": 1,
"column": 16
},
"end": {
"line": 1,
"column": 19
}
},
"callee": {
"type": "Identifier",
"start": 16,
"end": 17,
"loc": {
"start": {
"line": 1,
"column": 16
},
"end": {
"line": 1,
"column": 17
},
"identifierName": "f"
},
"name": "f"
},
"arguments": []
},
"superTypeParameters": {
"type": "TypeParameterInstantiation",
"start": 19,
"end": 22,
"loc": {
"start": {
"line": 1,
"column": 19
},
"end": {
"line": 1,
"column": 22
}
},
"params": [
{
"type": "TSTypeReference",
"start": 20,
"end": 21,
"loc": {
"start": {
"line": 1,
"column": 20
},
"end": {
"line": 1,
"column": 21
}
},
"typeName": {
"type": "Identifier",
"start": 20,
"end": 21,
"loc": {
"start": {
"line": 1,
"column": 20
},
"end": {
"line": 1,
"column": 21
},
"identifierName": "T"
},
"name": "T"
}
}
]
},
"implements": [
{
"type": "TSExpressionWithTypeArguments",
"start": 34,
"end": 40,
"loc": {
"start": {
"line": 1,
"column": 34
},
"end": {
"line": 1,
"column": 40
}
},
"expression": {
"type": "TSQualifiedName",
"start": 34,
"end": 37,
"loc": {
"start": {
"line": 1,
"column": 34
},
"end": {
"line": 1,
"column": 37
}
},
"left": {
"type": "Identifier",
"start": 34,
"end": 35,
"loc": {
"start": {
"line": 1,
"column": 34
},
"end": {
"line": 1,
"column": 35
},
"identifierName": "X"
},
"name": "X"
},
"right": {
"type": "Identifier",
"start": 36,
"end": 37,
"loc": {
"start": {
"line": 1,
"column": 36
},
"end": {
"line": 1,
"column": 37
},
"identifierName": "Y"
},
"name": "Y"
}
},
"typeParameters": {
"type": "TypeParameterInstantiation",
"start": 37,
"end": 40,
"loc": {
"start": {
"line": 1,
"column": 37
},
"end": {
"line": 1,
"column": 40
}
},
"params": [
{
"type": "TSTypeReference",
"start": 38,
"end": 39,
"loc": {
"start": {
"line": 1,
"column": 38
},
"end": {
"line": 1,
"column": 39
}
},
"typeName": {
"type": "Identifier",
"start": 38,
"end": 39,
"loc": {
"start": {
"line": 1,
"column": 38
},
"end": {
"line": 1,
"column": 39
},
"identifierName": "T"
},
"name": "T"
}
}
]
}
}
],
"body": {
"type": "ClassBody",
"start": 41,
"end": 43,
"loc": {
"start": {
"line": 1,
"column": 41
},
"end": {
"line": 1,
"column": 43
}
},
"body": []
}
}
],
"directives": []
}
}

View File

@ -0,0 +1 @@
class C extends f()<T> {}

View File

@ -0,0 +1,164 @@
{
"type": "File",
"start": 0,
"end": 25,
"loc": {
"start": {
"line": 1,
"column": 0
},
"end": {
"line": 1,
"column": 25
}
},
"program": {
"type": "Program",
"start": 0,
"end": 25,
"loc": {
"start": {
"line": 1,
"column": 0
},
"end": {
"line": 1,
"column": 25
}
},
"sourceType": "module",
"body": [
{
"type": "ClassDeclaration",
"start": 0,
"end": 25,
"loc": {
"start": {
"line": 1,
"column": 0
},
"end": {
"line": 1,
"column": 25
}
},
"id": {
"type": "Identifier",
"start": 6,
"end": 7,
"loc": {
"start": {
"line": 1,
"column": 6
},
"end": {
"line": 1,
"column": 7
},
"identifierName": "C"
},
"name": "C"
},
"superClass": {
"type": "CallExpression",
"start": 16,
"end": 19,
"loc": {
"start": {
"line": 1,
"column": 16
},
"end": {
"line": 1,
"column": 19
}
},
"callee": {
"type": "Identifier",
"start": 16,
"end": 17,
"loc": {
"start": {
"line": 1,
"column": 16
},
"end": {
"line": 1,
"column": 17
},
"identifierName": "f"
},
"name": "f"
},
"arguments": []
},
"superTypeParameters": {
"type": "TypeParameterInstantiation",
"start": 19,
"end": 22,
"loc": {
"start": {
"line": 1,
"column": 19
},
"end": {
"line": 1,
"column": 22
}
},
"params": [
{
"type": "TSTypeReference",
"start": 20,
"end": 21,
"loc": {
"start": {
"line": 1,
"column": 20
},
"end": {
"line": 1,
"column": 21
}
},
"typeName": {
"type": "Identifier",
"start": 20,
"end": 21,
"loc": {
"start": {
"line": 1,
"column": 20
},
"end": {
"line": 1,
"column": 21
},
"identifierName": "T"
},
"name": "T"
}
}
]
},
"body": {
"type": "ClassBody",
"start": 23,
"end": 25,
"loc": {
"start": {
"line": 1,
"column": 23
},
"end": {
"line": 1,
"column": 25
}
},
"body": []
}
}
],
"directives": []
}
}

View File

@ -0,0 +1 @@
class C<T extends object = { x: number }> {}

View File

@ -0,0 +1,211 @@
{
"type": "File",
"start": 0,
"end": 44,
"loc": {
"start": {
"line": 1,
"column": 0
},
"end": {
"line": 1,
"column": 44
}
},
"program": {
"type": "Program",
"start": 0,
"end": 44,
"loc": {
"start": {
"line": 1,
"column": 0
},
"end": {
"line": 1,
"column": 44
}
},
"sourceType": "module",
"body": [
{
"type": "ClassDeclaration",
"start": 0,
"end": 44,
"loc": {
"start": {
"line": 1,
"column": 0
},
"end": {
"line": 1,
"column": 44
}
},
"id": {
"type": "Identifier",
"start": 6,
"end": 7,
"loc": {
"start": {
"line": 1,
"column": 6
},
"end": {
"line": 1,
"column": 7
},
"identifierName": "C"
},
"name": "C"
},
"typeParameters": {
"type": "TypeParameterDeclaration",
"start": 8,
"end": 41,
"loc": {
"start": {
"line": 1,
"column": 8
},
"end": {
"line": 1,
"column": 41
}
},
"params": [
{
"type": "TypeParameter",
"start": 8,
"end": 40,
"loc": {
"start": {
"line": 1,
"column": 8
},
"end": {
"line": 1,
"column": 40
}
},
"name": "T",
"constraint": {
"type": "TSObjectKeyword",
"start": 18,
"end": 24,
"loc": {
"start": {
"line": 1,
"column": 18
},
"end": {
"line": 1,
"column": 24
}
}
},
"default": {
"type": "TSTypeLiteral",
"start": 27,
"end": 40,
"loc": {
"start": {
"line": 1,
"column": 27
},
"end": {
"line": 1,
"column": 40
}
},
"members": [
{
"type": "TSPropertySignature",
"start": 29,
"end": 38,
"loc": {
"start": {
"line": 1,
"column": 29
},
"end": {
"line": 1,
"column": 38
}
},
"computed": false,
"key": {
"type": "Identifier",
"start": 29,
"end": 30,
"loc": {
"start": {
"line": 1,
"column": 29
},
"end": {
"line": 1,
"column": 30
},
"identifierName": "x"
},
"name": "x"
},
"typeAnnotation": {
"type": "TypeAnnotation",
"start": 30,
"end": 38,
"loc": {
"start": {
"line": 1,
"column": 30
},
"end": {
"line": 1,
"column": 38
}
},
"typeAnnotation": {
"type": "TSNumberKeyword",
"start": 32,
"end": 38,
"loc": {
"start": {
"line": 1,
"column": 32
},
"end": {
"line": 1,
"column": 38
}
}
}
}
}
]
}
}
]
},
"superClass": null,
"body": {
"type": "ClassBody",
"start": 42,
"end": 44,
"loc": {
"start": {
"line": 1,
"column": 42
},
"end": {
"line": 1,
"column": 44
}
},
"body": []
}
}
],
"directives": []
}
}

View File

@ -0,0 +1,3 @@
declare class C {
get<T>(): void;
}

View File

@ -0,0 +1,188 @@
{
"type": "File",
"start": 0,
"end": 39,
"loc": {
"start": {
"line": 1,
"column": 0
},
"end": {
"line": 3,
"column": 1
}
},
"program": {
"type": "Program",
"start": 0,
"end": 39,
"loc": {
"start": {
"line": 1,
"column": 0
},
"end": {
"line": 3,
"column": 1
}
},
"sourceType": "module",
"body": [
{
"type": "ClassDeclaration",
"start": 0,
"end": 39,
"loc": {
"start": {
"line": 1,
"column": 0
},
"end": {
"line": 3,
"column": 1
}
},
"id": {
"type": "Identifier",
"start": 14,
"end": 15,
"loc": {
"start": {
"line": 1,
"column": 14
},
"end": {
"line": 1,
"column": 15
},
"identifierName": "C"
},
"name": "C"
},
"superClass": null,
"body": {
"type": "ClassBody",
"start": 16,
"end": 39,
"loc": {
"start": {
"line": 1,
"column": 16
},
"end": {
"line": 3,
"column": 1
}
},
"body": [
{
"type": "TSDeclareMethod",
"start": 22,
"end": 37,
"loc": {
"start": {
"line": 2,
"column": 4
},
"end": {
"line": 2,
"column": 19
}
},
"static": false,
"computed": false,
"key": {
"type": "Identifier",
"start": 22,
"end": 25,
"loc": {
"start": {
"line": 2,
"column": 4
},
"end": {
"line": 2,
"column": 7
},
"identifierName": "get"
},
"name": "get"
},
"kind": "method",
"typeParameters": {
"type": "TypeParameterDeclaration",
"start": 26,
"end": 28,
"loc": {
"start": {
"line": 2,
"column": 8
},
"end": {
"line": 2,
"column": 10
}
},
"params": [
{
"type": "TypeParameter",
"start": 26,
"end": 27,
"loc": {
"start": {
"line": 2,
"column": 8
},
"end": {
"line": 2,
"column": 9
}
},
"name": "T"
}
]
},
"id": null,
"generator": false,
"expression": false,
"async": false,
"params": [],
"returnType": {
"type": "TypeAnnotation",
"start": 30,
"end": 36,
"loc": {
"start": {
"line": 2,
"column": 12
},
"end": {
"line": 2,
"column": 18
}
},
"typeAnnotation": {
"type": "TSVoidKeyword",
"start": 32,
"end": 36,
"loc": {
"start": {
"line": 2,
"column": 14
},
"end": {
"line": 2,
"column": 18
}
}
}
}
}
]
},
"declare": true
}
],
"directives": []
}
}

View File

@ -0,0 +1 @@
class C implements X.Y<T> {}

View File

@ -0,0 +1,198 @@
{
"type": "File",
"start": 0,
"end": 28,
"loc": {
"start": {
"line": 1,
"column": 0
},
"end": {
"line": 1,
"column": 28
}
},
"program": {
"type": "Program",
"start": 0,
"end": 28,
"loc": {
"start": {
"line": 1,
"column": 0
},
"end": {
"line": 1,
"column": 28
}
},
"sourceType": "module",
"body": [
{
"type": "ClassDeclaration",
"start": 0,
"end": 28,
"loc": {
"start": {
"line": 1,
"column": 0
},
"end": {
"line": 1,
"column": 28
}
},
"id": {
"type": "Identifier",
"start": 6,
"end": 7,
"loc": {
"start": {
"line": 1,
"column": 6
},
"end": {
"line": 1,
"column": 7
},
"identifierName": "C"
},
"name": "C"
},
"superClass": null,
"implements": [
{
"type": "TSExpressionWithTypeArguments",
"start": 19,
"end": 25,
"loc": {
"start": {
"line": 1,
"column": 19
},
"end": {
"line": 1,
"column": 25
}
},
"expression": {
"type": "TSQualifiedName",
"start": 19,
"end": 22,
"loc": {
"start": {
"line": 1,
"column": 19
},
"end": {
"line": 1,
"column": 22
}
},
"left": {
"type": "Identifier",
"start": 19,
"end": 20,
"loc": {
"start": {
"line": 1,
"column": 19
},
"end": {
"line": 1,
"column": 20
},
"identifierName": "X"
},
"name": "X"
},
"right": {
"type": "Identifier",
"start": 21,
"end": 22,
"loc": {
"start": {
"line": 1,
"column": 21
},
"end": {
"line": 1,
"column": 22
},
"identifierName": "Y"
},
"name": "Y"
}
},
"typeParameters": {
"type": "TypeParameterInstantiation",
"start": 22,
"end": 25,
"loc": {
"start": {
"line": 1,
"column": 22
},
"end": {
"line": 1,
"column": 25
}
},
"params": [
{
"type": "TSTypeReference",
"start": 23,
"end": 24,
"loc": {
"start": {
"line": 1,
"column": 23
},
"end": {
"line": 1,
"column": 24
}
},
"typeName": {
"type": "Identifier",
"start": 23,
"end": 24,
"loc": {
"start": {
"line": 1,
"column": 23
},
"end": {
"line": 1,
"column": 24
},
"identifierName": "T"
},
"name": "T"
}
}
]
}
}
],
"body": {
"type": "ClassBody",
"start": 26,
"end": 28,
"loc": {
"start": {
"line": 1,
"column": 26
},
"end": {
"line": 1,
"column": 28
}
},
"body": []
}
}
],
"directives": []
}
}

View File

@ -0,0 +1,4 @@
class C {
[x: string]: any;
readonly [x: string]: any;
}

View File

@ -0,0 +1,273 @@
{
"type": "File",
"start": 0,
"end": 64,
"loc": {
"start": {
"line": 1,
"column": 0
},
"end": {
"line": 4,
"column": 1
}
},
"program": {
"type": "Program",
"start": 0,
"end": 64,
"loc": {
"start": {
"line": 1,
"column": 0
},
"end": {
"line": 4,
"column": 1
}
},
"sourceType": "module",
"body": [
{
"type": "ClassDeclaration",
"start": 0,
"end": 64,
"loc": {
"start": {
"line": 1,
"column": 0
},
"end": {
"line": 4,
"column": 1
}
},
"id": {
"type": "Identifier",
"start": 6,
"end": 7,
"loc": {
"start": {
"line": 1,
"column": 6
},
"end": {
"line": 1,
"column": 7
},
"identifierName": "C"
},
"name": "C"
},
"superClass": null,
"body": {
"type": "ClassBody",
"start": 8,
"end": 64,
"loc": {
"start": {
"line": 1,
"column": 8
},
"end": {
"line": 4,
"column": 1
}
},
"body": [
{
"type": "TSIndexSignature",
"start": 14,
"end": 31,
"loc": {
"start": {
"line": 2,
"column": 4
},
"end": {
"line": 2,
"column": 21
}
},
"parameters": [
{
"type": "Identifier",
"start": 15,
"end": 16,
"loc": {
"start": {
"line": 2,
"column": 5
},
"end": {
"line": 2,
"column": 6
},
"identifierName": "x"
},
"name": "x",
"typeAnnotation": {
"type": "TypeAnnotation",
"start": 18,
"end": 24,
"loc": {
"start": {
"line": 2,
"column": 8
},
"end": {
"line": 2,
"column": 14
}
},
"typeAnnotation": {
"type": "TSStringKeyword",
"start": 18,
"end": 24,
"loc": {
"start": {
"line": 2,
"column": 8
},
"end": {
"line": 2,
"column": 14
}
}
}
}
}
],
"typeAnnotation": {
"type": "TypeAnnotation",
"start": 25,
"end": 30,
"loc": {
"start": {
"line": 2,
"column": 15
},
"end": {
"line": 2,
"column": 20
}
},
"typeAnnotation": {
"type": "TSAnyKeyword",
"start": 27,
"end": 30,
"loc": {
"start": {
"line": 2,
"column": 17
},
"end": {
"line": 2,
"column": 20
}
}
}
}
},
{
"type": "TSIndexSignature",
"start": 36,
"end": 62,
"loc": {
"start": {
"line": 3,
"column": 4
},
"end": {
"line": 3,
"column": 30
}
},
"readonly": true,
"parameters": [
{
"type": "Identifier",
"start": 46,
"end": 47,
"loc": {
"start": {
"line": 3,
"column": 14
},
"end": {
"line": 3,
"column": 15
},
"identifierName": "x"
},
"name": "x",
"typeAnnotation": {
"type": "TypeAnnotation",
"start": 49,
"end": 55,
"loc": {
"start": {
"line": 3,
"column": 17
},
"end": {
"line": 3,
"column": 23
}
},
"typeAnnotation": {
"type": "TSStringKeyword",
"start": 49,
"end": 55,
"loc": {
"start": {
"line": 3,
"column": 17
},
"end": {
"line": 3,
"column": 23
}
}
}
}
}
],
"typeAnnotation": {
"type": "TypeAnnotation",
"start": 56,
"end": 61,
"loc": {
"start": {
"line": 3,
"column": 24
},
"end": {
"line": 3,
"column": 29
}
},
"typeAnnotation": {
"type": "TSAnyKeyword",
"start": 58,
"end": 61,
"loc": {
"start": {
"line": 3,
"column": 26
},
"end": {
"line": 3,
"column": 29
}
}
}
}
}
]
}
}
],
"directives": []
}
}

View File

@ -0,0 +1,6 @@
class C {
public(): void;
public static(): void;
readonly = 0;
async<T>(): void;
}

View File

@ -0,0 +1,382 @@
{
"type": "File",
"start": 0,
"end": 98,
"loc": {
"start": {
"line": 1,
"column": 0
},
"end": {
"line": 6,
"column": 1
}
},
"program": {
"type": "Program",
"start": 0,
"end": 98,
"loc": {
"start": {
"line": 1,
"column": 0
},
"end": {
"line": 6,
"column": 1
}
},
"sourceType": "module",
"body": [
{
"type": "ClassDeclaration",
"start": 0,
"end": 98,
"loc": {
"start": {
"line": 1,
"column": 0
},
"end": {
"line": 6,
"column": 1
}
},
"id": {
"type": "Identifier",
"start": 6,
"end": 7,
"loc": {
"start": {
"line": 1,
"column": 6
},
"end": {
"line": 1,
"column": 7
},
"identifierName": "C"
},
"name": "C"
},
"superClass": null,
"body": {
"type": "ClassBody",
"start": 8,
"end": 98,
"loc": {
"start": {
"line": 1,
"column": 8
},
"end": {
"line": 6,
"column": 1
}
},
"body": [
{
"type": "TSDeclareMethod",
"start": 14,
"end": 29,
"loc": {
"start": {
"line": 2,
"column": 4
},
"end": {
"line": 2,
"column": 19
}
},
"static": false,
"computed": false,
"key": {
"type": "Identifier",
"start": 14,
"end": 20,
"loc": {
"start": {
"line": 2,
"column": 4
},
"end": {
"line": 2,
"column": 10
},
"identifierName": "public"
},
"name": "public"
},
"kind": "method",
"id": null,
"generator": false,
"expression": false,
"async": false,
"params": [],
"returnType": {
"type": "TypeAnnotation",
"start": 22,
"end": 28,
"loc": {
"start": {
"line": 2,
"column": 12
},
"end": {
"line": 2,
"column": 18
}
},
"typeAnnotation": {
"type": "TSVoidKeyword",
"start": 24,
"end": 28,
"loc": {
"start": {
"line": 2,
"column": 14
},
"end": {
"line": 2,
"column": 18
}
}
}
}
},
{
"type": "TSDeclareMethod",
"start": 34,
"end": 56,
"loc": {
"start": {
"line": 3,
"column": 4
},
"end": {
"line": 3,
"column": 26
}
},
"accessibility": "public",
"kind": "method",
"computed": false,
"key": {
"type": "Identifier",
"start": 41,
"end": 47,
"loc": {
"start": {
"line": 3,
"column": 11
},
"end": {
"line": 3,
"column": 17
},
"identifierName": "static"
},
"name": "static"
},
"static": false,
"id": null,
"generator": false,
"expression": false,
"async": false,
"params": [],
"returnType": {
"type": "TypeAnnotation",
"start": 49,
"end": 55,
"loc": {
"start": {
"line": 3,
"column": 19
},
"end": {
"line": 3,
"column": 25
}
},
"typeAnnotation": {
"type": "TSVoidKeyword",
"start": 51,
"end": 55,
"loc": {
"start": {
"line": 3,
"column": 21
},
"end": {
"line": 3,
"column": 25
}
}
}
}
},
{
"type": "ClassProperty",
"start": 61,
"end": 74,
"loc": {
"start": {
"line": 4,
"column": 4
},
"end": {
"line": 4,
"column": 17
}
},
"static": false,
"computed": false,
"key": {
"type": "Identifier",
"start": 61,
"end": 69,
"loc": {
"start": {
"line": 4,
"column": 4
},
"end": {
"line": 4,
"column": 12
},
"identifierName": "readonly"
},
"name": "readonly"
},
"value": {
"type": "NumericLiteral",
"start": 72,
"end": 73,
"loc": {
"start": {
"line": 4,
"column": 15
},
"end": {
"line": 4,
"column": 16
}
},
"extra": {
"rawValue": 0,
"raw": "0"
},
"value": 0
}
},
{
"type": "TSDeclareMethod",
"start": 79,
"end": 96,
"loc": {
"start": {
"line": 5,
"column": 4
},
"end": {
"line": 5,
"column": 21
}
},
"static": false,
"computed": false,
"key": {
"type": "Identifier",
"start": 79,
"end": 84,
"loc": {
"start": {
"line": 5,
"column": 4
},
"end": {
"line": 5,
"column": 9
},
"identifierName": "async"
},
"name": "async"
},
"kind": "method",
"typeParameters": {
"type": "TypeParameterDeclaration",
"start": 85,
"end": 87,
"loc": {
"start": {
"line": 5,
"column": 10
},
"end": {
"line": 5,
"column": 12
}
},
"params": [
{
"type": "TypeParameter",
"start": 85,
"end": 86,
"loc": {
"start": {
"line": 5,
"column": 10
},
"end": {
"line": 5,
"column": 11
}
},
"name": "T"
}
]
},
"id": null,
"generator": false,
"expression": false,
"async": false,
"params": [],
"returnType": {
"type": "TypeAnnotation",
"start": 89,
"end": 95,
"loc": {
"start": {
"line": 5,
"column": 14
},
"end": {
"line": 5,
"column": 20
}
},
"typeAnnotation": {
"type": "TSVoidKeyword",
"start": 91,
"end": 95,
"loc": {
"start": {
"line": 5,
"column": 16
},
"end": {
"line": 5,
"column": 20
}
}
}
}
}
]
}
}
],
"directives": []
}
}

View File

@ -0,0 +1,3 @@
class C {
public delete(): void;
}

View File

@ -0,0 +1,155 @@
{
"type": "File",
"start": 0,
"end": 38,
"loc": {
"start": {
"line": 1,
"column": 0
},
"end": {
"line": 3,
"column": 1
}
},
"program": {
"type": "Program",
"start": 0,
"end": 38,
"loc": {
"start": {
"line": 1,
"column": 0
},
"end": {
"line": 3,
"column": 1
}
},
"sourceType": "module",
"body": [
{
"type": "ClassDeclaration",
"start": 0,
"end": 38,
"loc": {
"start": {
"line": 1,
"column": 0
},
"end": {
"line": 3,
"column": 1
}
},
"id": {
"type": "Identifier",
"start": 6,
"end": 7,
"loc": {
"start": {
"line": 1,
"column": 6
},
"end": {
"line": 1,
"column": 7
},
"identifierName": "C"
},
"name": "C"
},
"superClass": null,
"body": {
"type": "ClassBody",
"start": 8,
"end": 38,
"loc": {
"start": {
"line": 1,
"column": 8
},
"end": {
"line": 3,
"column": 1
}
},
"body": [
{
"type": "TSDeclareMethod",
"start": 14,
"end": 36,
"loc": {
"start": {
"line": 2,
"column": 4
},
"end": {
"line": 2,
"column": 26
}
},
"accessibility": "public",
"static": false,
"computed": false,
"key": {
"type": "Identifier",
"start": 21,
"end": 27,
"loc": {
"start": {
"line": 2,
"column": 11
},
"end": {
"line": 2,
"column": 17
},
"identifierName": "delete"
},
"name": "delete"
},
"kind": "method",
"id": null,
"generator": false,
"expression": false,
"async": false,
"params": [],
"returnType": {
"type": "TypeAnnotation",
"start": 29,
"end": 35,
"loc": {
"start": {
"line": 2,
"column": 19
},
"end": {
"line": 2,
"column": 25
}
},
"typeAnnotation": {
"type": "TSVoidKeyword",
"start": 31,
"end": 35,
"loc": {
"start": {
"line": 2,
"column": 21
},
"end": {
"line": 2,
"column": 25
}
}
}
}
}
]
}
}
],
"directives": []
}
}

View File

@ -0,0 +1,4 @@
class C {
[Symbol.iterator](): void;
[Symbol.iterator]?(): void;
}

View File

@ -0,0 +1,291 @@
{
"type": "File",
"start": 0,
"end": 74,
"loc": {
"start": {
"line": 1,
"column": 0
},
"end": {
"line": 4,
"column": 1
}
},
"program": {
"type": "Program",
"start": 0,
"end": 74,
"loc": {
"start": {
"line": 1,
"column": 0
},
"end": {
"line": 4,
"column": 1
}
},
"sourceType": "module",
"body": [
{
"type": "ClassDeclaration",
"start": 0,
"end": 74,
"loc": {
"start": {
"line": 1,
"column": 0
},
"end": {
"line": 4,
"column": 1
}
},
"id": {
"type": "Identifier",
"start": 6,
"end": 7,
"loc": {
"start": {
"line": 1,
"column": 6
},
"end": {
"line": 1,
"column": 7
},
"identifierName": "C"
},
"name": "C"
},
"superClass": null,
"body": {
"type": "ClassBody",
"start": 8,
"end": 74,
"loc": {
"start": {
"line": 1,
"column": 8
},
"end": {
"line": 4,
"column": 1
}
},
"body": [
{
"type": "TSDeclareMethod",
"start": 14,
"end": 40,
"loc": {
"start": {
"line": 2,
"column": 4
},
"end": {
"line": 2,
"column": 30
}
},
"static": false,
"computed": true,
"key": {
"type": "MemberExpression",
"start": 15,
"end": 30,
"loc": {
"start": {
"line": 2,
"column": 5
},
"end": {
"line": 2,
"column": 20
}
},
"object": {
"type": "Identifier",
"start": 15,
"end": 21,
"loc": {
"start": {
"line": 2,
"column": 5
},
"end": {
"line": 2,
"column": 11
},
"identifierName": "Symbol"
},
"name": "Symbol"
},
"property": {
"type": "Identifier",
"start": 22,
"end": 30,
"loc": {
"start": {
"line": 2,
"column": 12
},
"end": {
"line": 2,
"column": 20
},
"identifierName": "iterator"
},
"name": "iterator"
},
"computed": false
},
"kind": "method",
"id": null,
"generator": false,
"expression": false,
"async": false,
"params": [],
"returnType": {
"type": "TypeAnnotation",
"start": 33,
"end": 39,
"loc": {
"start": {
"line": 2,
"column": 23
},
"end": {
"line": 2,
"column": 29
}
},
"typeAnnotation": {
"type": "TSVoidKeyword",
"start": 35,
"end": 39,
"loc": {
"start": {
"line": 2,
"column": 25
},
"end": {
"line": 2,
"column": 29
}
}
}
}
},
{
"type": "TSDeclareMethod",
"start": 45,
"end": 72,
"loc": {
"start": {
"line": 3,
"column": 4
},
"end": {
"line": 3,
"column": 31
}
},
"static": false,
"computed": true,
"key": {
"type": "MemberExpression",
"start": 46,
"end": 61,
"loc": {
"start": {
"line": 3,
"column": 5
},
"end": {
"line": 3,
"column": 20
}
},
"object": {
"type": "Identifier",
"start": 46,
"end": 52,
"loc": {
"start": {
"line": 3,
"column": 5
},
"end": {
"line": 3,
"column": 11
},
"identifierName": "Symbol"
},
"name": "Symbol"
},
"property": {
"type": "Identifier",
"start": 53,
"end": 61,
"loc": {
"start": {
"line": 3,
"column": 12
},
"end": {
"line": 3,
"column": 20
},
"identifierName": "iterator"
},
"name": "iterator"
},
"computed": false
},
"optional": true,
"kind": "method",
"id": null,
"generator": false,
"expression": false,
"async": false,
"params": [],
"returnType": {
"type": "TypeAnnotation",
"start": 65,
"end": 71,
"loc": {
"start": {
"line": 3,
"column": 24
},
"end": {
"line": 3,
"column": 30
}
},
"typeAnnotation": {
"type": "TSVoidKeyword",
"start": 67,
"end": 71,
"loc": {
"start": {
"line": 3,
"column": 26
},
"end": {
"line": 3,
"column": 30
}
}
}
}
}
]
}
}
],
"directives": []
}
}

View File

@ -0,0 +1,4 @@
class C {
f<T>(a: T, b?: T, ...c: T[]): T {}
[Symbol.iterator]<T>(): T {}
}

View File

@ -0,0 +1,615 @@
{
"type": "File",
"start": 0,
"end": 83,
"loc": {
"start": {
"line": 1,
"column": 0
},
"end": {
"line": 4,
"column": 1
}
},
"program": {
"type": "Program",
"start": 0,
"end": 83,
"loc": {
"start": {
"line": 1,
"column": 0
},
"end": {
"line": 4,
"column": 1
}
},
"sourceType": "module",
"body": [
{
"type": "ClassDeclaration",
"start": 0,
"end": 83,
"loc": {
"start": {
"line": 1,
"column": 0
},
"end": {
"line": 4,
"column": 1
}
},
"id": {
"type": "Identifier",
"start": 6,
"end": 7,
"loc": {
"start": {
"line": 1,
"column": 6
},
"end": {
"line": 1,
"column": 7
},
"identifierName": "C"
},
"name": "C"
},
"superClass": null,
"body": {
"type": "ClassBody",
"start": 8,
"end": 83,
"loc": {
"start": {
"line": 1,
"column": 8
},
"end": {
"line": 4,
"column": 1
}
},
"body": [
{
"type": "ClassMethod",
"start": 14,
"end": 48,
"loc": {
"start": {
"line": 2,
"column": 4
},
"end": {
"line": 2,
"column": 38
}
},
"static": false,
"computed": false,
"key": {
"type": "Identifier",
"start": 14,
"end": 15,
"loc": {
"start": {
"line": 2,
"column": 4
},
"end": {
"line": 2,
"column": 5
},
"identifierName": "f"
},
"name": "f"
},
"kind": "method",
"typeParameters": {
"type": "TypeParameterDeclaration",
"start": 16,
"end": 18,
"loc": {
"start": {
"line": 2,
"column": 6
},
"end": {
"line": 2,
"column": 8
}
},
"params": [
{
"type": "TypeParameter",
"start": 16,
"end": 17,
"loc": {
"start": {
"line": 2,
"column": 6
},
"end": {
"line": 2,
"column": 7
}
},
"name": "T"
}
]
},
"id": null,
"generator": false,
"expression": false,
"async": false,
"params": [
{
"type": "Identifier",
"start": 19,
"end": 23,
"loc": {
"start": {
"line": 2,
"column": 9
},
"end": {
"line": 2,
"column": 13
},
"identifierName": "a"
},
"name": "a",
"typeAnnotation": {
"type": "TypeAnnotation",
"start": 20,
"end": 23,
"loc": {
"start": {
"line": 2,
"column": 10
},
"end": {
"line": 2,
"column": 13
}
},
"typeAnnotation": {
"type": "TSTypeReference",
"start": 22,
"end": 23,
"loc": {
"start": {
"line": 2,
"column": 12
},
"end": {
"line": 2,
"column": 13
}
},
"typeName": {
"type": "Identifier",
"start": 22,
"end": 23,
"loc": {
"start": {
"line": 2,
"column": 12
},
"end": {
"line": 2,
"column": 13
},
"identifierName": "T"
},
"name": "T"
}
}
}
},
{
"type": "Identifier",
"start": 25,
"end": 30,
"loc": {
"start": {
"line": 2,
"column": 15
},
"end": {
"line": 2,
"column": 20
},
"identifierName": "b"
},
"name": "b",
"optional": true,
"typeAnnotation": {
"type": "TypeAnnotation",
"start": 27,
"end": 30,
"loc": {
"start": {
"line": 2,
"column": 17
},
"end": {
"line": 2,
"column": 20
}
},
"typeAnnotation": {
"type": "TSTypeReference",
"start": 29,
"end": 30,
"loc": {
"start": {
"line": 2,
"column": 19
},
"end": {
"line": 2,
"column": 20
}
},
"typeName": {
"type": "Identifier",
"start": 29,
"end": 30,
"loc": {
"start": {
"line": 2,
"column": 19
},
"end": {
"line": 2,
"column": 20
},
"identifierName": "T"
},
"name": "T"
}
}
}
},
{
"type": "RestElement",
"start": 32,
"end": 41,
"loc": {
"start": {
"line": 2,
"column": 22
},
"end": {
"line": 2,
"column": 31
}
},
"argument": {
"type": "Identifier",
"start": 35,
"end": 36,
"loc": {
"start": {
"line": 2,
"column": 25
},
"end": {
"line": 2,
"column": 26
},
"identifierName": "c"
},
"name": "c"
},
"typeAnnotation": {
"type": "TypeAnnotation",
"start": 36,
"end": 41,
"loc": {
"start": {
"line": 2,
"column": 26
},
"end": {
"line": 2,
"column": 31
}
},
"typeAnnotation": {
"type": "TSArrayType",
"start": 38,
"end": 41,
"loc": {
"start": {
"line": 2,
"column": 28
},
"end": {
"line": 2,
"column": 31
}
},
"elementType": {
"type": "TSTypeReference",
"start": 38,
"end": 39,
"loc": {
"start": {
"line": 2,
"column": 28
},
"end": {
"line": 2,
"column": 29
}
},
"typeName": {
"type": "Identifier",
"start": 38,
"end": 39,
"loc": {
"start": {
"line": 2,
"column": 28
},
"end": {
"line": 2,
"column": 29
},
"identifierName": "T"
},
"name": "T"
}
}
}
}
}
],
"returnType": {
"type": "TypeAnnotation",
"start": 42,
"end": 45,
"loc": {
"start": {
"line": 2,
"column": 32
},
"end": {
"line": 2,
"column": 35
}
},
"typeAnnotation": {
"type": "TSTypeReference",
"start": 44,
"end": 45,
"loc": {
"start": {
"line": 2,
"column": 34
},
"end": {
"line": 2,
"column": 35
}
},
"typeName": {
"type": "Identifier",
"start": 44,
"end": 45,
"loc": {
"start": {
"line": 2,
"column": 34
},
"end": {
"line": 2,
"column": 35
},
"identifierName": "T"
},
"name": "T"
}
}
},
"body": {
"type": "BlockStatement",
"start": 46,
"end": 48,
"loc": {
"start": {
"line": 2,
"column": 36
},
"end": {
"line": 2,
"column": 38
}
},
"body": [],
"directives": []
}
},
{
"type": "ClassMethod",
"start": 53,
"end": 81,
"loc": {
"start": {
"line": 3,
"column": 4
},
"end": {
"line": 3,
"column": 32
}
},
"static": false,
"computed": true,
"key": {
"type": "MemberExpression",
"start": 54,
"end": 69,
"loc": {
"start": {
"line": 3,
"column": 5
},
"end": {
"line": 3,
"column": 20
}
},
"object": {
"type": "Identifier",
"start": 54,
"end": 60,
"loc": {
"start": {
"line": 3,
"column": 5
},
"end": {
"line": 3,
"column": 11
},
"identifierName": "Symbol"
},
"name": "Symbol"
},
"property": {
"type": "Identifier",
"start": 61,
"end": 69,
"loc": {
"start": {
"line": 3,
"column": 12
},
"end": {
"line": 3,
"column": 20
},
"identifierName": "iterator"
},
"name": "iterator"
},
"computed": false
},
"kind": "method",
"typeParameters": {
"type": "TypeParameterDeclaration",
"start": 71,
"end": 73,
"loc": {
"start": {
"line": 3,
"column": 22
},
"end": {
"line": 3,
"column": 24
}
},
"params": [
{
"type": "TypeParameter",
"start": 71,
"end": 72,
"loc": {
"start": {
"line": 3,
"column": 22
},
"end": {
"line": 3,
"column": 23
}
},
"name": "T"
}
]
},
"id": null,
"generator": false,
"expression": false,
"async": false,
"params": [],
"returnType": {
"type": "TypeAnnotation",
"start": 75,
"end": 78,
"loc": {
"start": {
"line": 3,
"column": 26
},
"end": {
"line": 3,
"column": 29
}
},
"typeAnnotation": {
"type": "TSTypeReference",
"start": 77,
"end": 78,
"loc": {
"start": {
"line": 3,
"column": 28
},
"end": {
"line": 3,
"column": 29
}
},
"typeName": {
"type": "Identifier",
"start": 77,
"end": 78,
"loc": {
"start": {
"line": 3,
"column": 28
},
"end": {
"line": 3,
"column": 29
},
"identifierName": "T"
},
"name": "T"
}
}
},
"body": {
"type": "BlockStatement",
"start": 79,
"end": 81,
"loc": {
"start": {
"line": 3,
"column": 30
},
"end": {
"line": 3,
"column": 32
}
},
"body": [],
"directives": []
}
}
]
}
}
],
"directives": []
}
}

View File

@ -0,0 +1,4 @@
class C {
f();
f(): void;
}

View File

@ -0,0 +1,194 @@
{
"type": "File",
"start": 0,
"end": 35,
"loc": {
"start": {
"line": 1,
"column": 0
},
"end": {
"line": 4,
"column": 1
}
},
"program": {
"type": "Program",
"start": 0,
"end": 35,
"loc": {
"start": {
"line": 1,
"column": 0
},
"end": {
"line": 4,
"column": 1
}
},
"sourceType": "module",
"body": [
{
"type": "ClassDeclaration",
"start": 0,
"end": 35,
"loc": {
"start": {
"line": 1,
"column": 0
},
"end": {
"line": 4,
"column": 1
}
},
"id": {
"type": "Identifier",
"start": 6,
"end": 7,
"loc": {
"start": {
"line": 1,
"column": 6
},
"end": {
"line": 1,
"column": 7
},
"identifierName": "C"
},
"name": "C"
},
"superClass": null,
"body": {
"type": "ClassBody",
"start": 8,
"end": 35,
"loc": {
"start": {
"line": 1,
"column": 8
},
"end": {
"line": 4,
"column": 1
}
},
"body": [
{
"type": "TSDeclareMethod",
"start": 14,
"end": 18,
"loc": {
"start": {
"line": 2,
"column": 4
},
"end": {
"line": 2,
"column": 8
}
},
"static": false,
"computed": false,
"key": {
"type": "Identifier",
"start": 14,
"end": 15,
"loc": {
"start": {
"line": 2,
"column": 4
},
"end": {
"line": 2,
"column": 5
},
"identifierName": "f"
},
"name": "f"
},
"kind": "method",
"id": null,
"generator": false,
"expression": false,
"async": false,
"params": []
},
{
"type": "TSDeclareMethod",
"start": 23,
"end": 33,
"loc": {
"start": {
"line": 3,
"column": 4
},
"end": {
"line": 3,
"column": 14
}
},
"static": false,
"computed": false,
"key": {
"type": "Identifier",
"start": 23,
"end": 24,
"loc": {
"start": {
"line": 3,
"column": 4
},
"end": {
"line": 3,
"column": 5
},
"identifierName": "f"
},
"name": "f"
},
"kind": "method",
"id": null,
"generator": false,
"expression": false,
"async": false,
"params": [],
"returnType": {
"type": "TypeAnnotation",
"start": 26,
"end": 32,
"loc": {
"start": {
"line": 3,
"column": 7
},
"end": {
"line": 3,
"column": 13
}
},
"typeAnnotation": {
"type": "TSVoidKeyword",
"start": 28,
"end": 32,
"loc": {
"start": {
"line": 3,
"column": 9
},
"end": {
"line": 3,
"column": 13
}
}
}
}
}
]
}
}
],
"directives": []
}
}

View File

@ -0,0 +1,3 @@
class C {
m?(): void {}
}

View File

@ -0,0 +1,172 @@
{
"type": "File",
"start": 0,
"end": 29,
"loc": {
"start": {
"line": 1,
"column": 0
},
"end": {
"line": 3,
"column": 1
}
},
"program": {
"type": "Program",
"start": 0,
"end": 29,
"loc": {
"start": {
"line": 1,
"column": 0
},
"end": {
"line": 3,
"column": 1
}
},
"sourceType": "module",
"body": [
{
"type": "ClassDeclaration",
"start": 0,
"end": 29,
"loc": {
"start": {
"line": 1,
"column": 0
},
"end": {
"line": 3,
"column": 1
}
},
"id": {
"type": "Identifier",
"start": 6,
"end": 7,
"loc": {
"start": {
"line": 1,
"column": 6
},
"end": {
"line": 1,
"column": 7
},
"identifierName": "C"
},
"name": "C"
},
"superClass": null,
"body": {
"type": "ClassBody",
"start": 8,
"end": 29,
"loc": {
"start": {
"line": 1,
"column": 8
},
"end": {
"line": 3,
"column": 1
}
},
"body": [
{
"type": "ClassMethod",
"start": 14,
"end": 27,
"loc": {
"start": {
"line": 2,
"column": 4
},
"end": {
"line": 2,
"column": 17
}
},
"static": false,
"computed": false,
"key": {
"type": "Identifier",
"start": 14,
"end": 15,
"loc": {
"start": {
"line": 2,
"column": 4
},
"end": {
"line": 2,
"column": 5
},
"identifierName": "m"
},
"name": "m"
},
"optional": true,
"kind": "method",
"id": null,
"generator": false,
"expression": false,
"async": false,
"params": [],
"returnType": {
"type": "TypeAnnotation",
"start": 18,
"end": 24,
"loc": {
"start": {
"line": 2,
"column": 8
},
"end": {
"line": 2,
"column": 14
}
},
"typeAnnotation": {
"type": "TSVoidKeyword",
"start": 20,
"end": 24,
"loc": {
"start": {
"line": 2,
"column": 10
},
"end": {
"line": 2,
"column": 14
}
}
}
},
"body": {
"type": "BlockStatement",
"start": 25,
"end": 27,
"loc": {
"start": {
"line": 2,
"column": 15
},
"end": {
"line": 2,
"column": 17
}
},
"body": [],
"directives": []
}
}
]
}
}
],
"directives": []
}
}

View File

@ -0,0 +1,3 @@
class C {
readonly m() {}
}

View File

@ -0,0 +1,3 @@
{
"throws": "Unexpected token, expected ; (2:14)"
}

View File

@ -0,0 +1,3 @@
class C {
f(): void {}
}

View File

@ -0,0 +1,171 @@
{
"type": "File",
"start": 0,
"end": 28,
"loc": {
"start": {
"line": 1,
"column": 0
},
"end": {
"line": 3,
"column": 1
}
},
"program": {
"type": "Program",
"start": 0,
"end": 28,
"loc": {
"start": {
"line": 1,
"column": 0
},
"end": {
"line": 3,
"column": 1
}
},
"sourceType": "module",
"body": [
{
"type": "ClassDeclaration",
"start": 0,
"end": 28,
"loc": {
"start": {
"line": 1,
"column": 0
},
"end": {
"line": 3,
"column": 1
}
},
"id": {
"type": "Identifier",
"start": 6,
"end": 7,
"loc": {
"start": {
"line": 1,
"column": 6
},
"end": {
"line": 1,
"column": 7
},
"identifierName": "C"
},
"name": "C"
},
"superClass": null,
"body": {
"type": "ClassBody",
"start": 8,
"end": 28,
"loc": {
"start": {
"line": 1,
"column": 8
},
"end": {
"line": 3,
"column": 1
}
},
"body": [
{
"type": "ClassMethod",
"start": 14,
"end": 26,
"loc": {
"start": {
"line": 2,
"column": 4
},
"end": {
"line": 2,
"column": 16
}
},
"static": false,
"computed": false,
"key": {
"type": "Identifier",
"start": 14,
"end": 15,
"loc": {
"start": {
"line": 2,
"column": 4
},
"end": {
"line": 2,
"column": 5
},
"identifierName": "f"
},
"name": "f"
},
"kind": "method",
"id": null,
"generator": false,
"expression": false,
"async": false,
"params": [],
"returnType": {
"type": "TypeAnnotation",
"start": 17,
"end": 23,
"loc": {
"start": {
"line": 2,
"column": 7
},
"end": {
"line": 2,
"column": 13
}
},
"typeAnnotation": {
"type": "TSVoidKeyword",
"start": 19,
"end": 23,
"loc": {
"start": {
"line": 2,
"column": 9
},
"end": {
"line": 2,
"column": 13
}
}
}
},
"body": {
"type": "BlockStatement",
"start": 24,
"end": 26,
"loc": {
"start": {
"line": 2,
"column": 14
},
"end": {
"line": 2,
"column": 16
}
},
"body": [],
"directives": []
}
}
]
}
}
],
"directives": []
}
}

View File

@ -0,0 +1,6 @@
class C
{
m()
{
}
}

View File

@ -0,0 +1,141 @@
{
"type": "File",
"start": 0,
"end": 31,
"loc": {
"start": {
"line": 1,
"column": 0
},
"end": {
"line": 6,
"column": 1
}
},
"program": {
"type": "Program",
"start": 0,
"end": 31,
"loc": {
"start": {
"line": 1,
"column": 0
},
"end": {
"line": 6,
"column": 1
}
},
"sourceType": "module",
"body": [
{
"type": "ClassDeclaration",
"start": 0,
"end": 31,
"loc": {
"start": {
"line": 1,
"column": 0
},
"end": {
"line": 6,
"column": 1
}
},
"id": {
"type": "Identifier",
"start": 6,
"end": 7,
"loc": {
"start": {
"line": 1,
"column": 6
},
"end": {
"line": 1,
"column": 7
},
"identifierName": "C"
},
"name": "C"
},
"superClass": null,
"body": {
"type": "ClassBody",
"start": 8,
"end": 31,
"loc": {
"start": {
"line": 2,
"column": 0
},
"end": {
"line": 6,
"column": 1
}
},
"body": [
{
"type": "ClassMethod",
"start": 14,
"end": 29,
"loc": {
"start": {
"line": 3,
"column": 4
},
"end": {
"line": 5,
"column": 5
}
},
"static": false,
"computed": false,
"key": {
"type": "Identifier",
"start": 14,
"end": 15,
"loc": {
"start": {
"line": 3,
"column": 4
},
"end": {
"line": 3,
"column": 5
},
"identifierName": "m"
},
"name": "m"
},
"kind": "method",
"id": null,
"generator": false,
"expression": false,
"async": false,
"params": [],
"body": {
"type": "BlockStatement",
"start": 22,
"end": 29,
"loc": {
"start": {
"line": 4,
"column": 4
},
"end": {
"line": 5,
"column": 5
}
},
"body": [],
"directives": []
}
}
]
}
}
],
"directives": []
}
}

View File

@ -0,0 +1,5 @@
class C
{
m()
n()
}

View File

@ -0,0 +1,164 @@
{
"type": "File",
"start": 0,
"end": 27,
"loc": {
"start": {
"line": 1,
"column": 0
},
"end": {
"line": 5,
"column": 1
}
},
"program": {
"type": "Program",
"start": 0,
"end": 27,
"loc": {
"start": {
"line": 1,
"column": 0
},
"end": {
"line": 5,
"column": 1
}
},
"sourceType": "module",
"body": [
{
"type": "ClassDeclaration",
"start": 0,
"end": 27,
"loc": {
"start": {
"line": 1,
"column": 0
},
"end": {
"line": 5,
"column": 1
}
},
"id": {
"type": "Identifier",
"start": 6,
"end": 7,
"loc": {
"start": {
"line": 1,
"column": 6
},
"end": {
"line": 1,
"column": 7
},
"identifierName": "C"
},
"name": "C"
},
"superClass": null,
"body": {
"type": "ClassBody",
"start": 8,
"end": 27,
"loc": {
"start": {
"line": 2,
"column": 0
},
"end": {
"line": 5,
"column": 1
}
},
"body": [
{
"type": "TSDeclareMethod",
"start": 14,
"end": 17,
"loc": {
"start": {
"line": 3,
"column": 4
},
"end": {
"line": 3,
"column": 7
}
},
"static": false,
"computed": false,
"key": {
"type": "Identifier",
"start": 14,
"end": 15,
"loc": {
"start": {
"line": 3,
"column": 4
},
"end": {
"line": 3,
"column": 5
},
"identifierName": "m"
},
"name": "m"
},
"kind": "method",
"id": null,
"generator": false,
"expression": false,
"async": false,
"params": []
},
{
"type": "TSDeclareMethod",
"start": 22,
"end": 25,
"loc": {
"start": {
"line": 4,
"column": 4
},
"end": {
"line": 4,
"column": 7
}
},
"static": false,
"computed": false,
"key": {
"type": "Identifier",
"start": 22,
"end": 23,
"loc": {
"start": {
"line": 4,
"column": 4
},
"end": {
"line": 4,
"column": 5
},
"identifierName": "n"
},
"name": "n"
},
"kind": "method",
"id": null,
"generator": false,
"expression": false,
"async": false,
"params": []
}
]
}
}
],
"directives": []
}
}

View File

@ -0,0 +1,11 @@
// Copy of modifiers-methods with 'get'
abstract class C {
abstract get a();
static get s() { return 0; }
public abstract get pua();
public static get pus() { return 0; }
public get pu() { return 0; }
protected get po() { return 0; }
private get pi() { return 0; }
}

Some files were not shown because too many files have changed in this diff Show More