babel-generator: Add TypeScript support (#5896)
* babel-generator: Add TypeScript support * Remove type declarations; not published from babylon * Remove TODOs * Consistently use `this.word` for tokens that are words
This commit is contained in:
parent
f83c83d49c
commit
c1d07fd6db
@ -8,6 +8,16 @@ export function ClassDeclaration(node: Object, parent: Object) {
|
|||||||
this.printJoin(node.decorators, node);
|
this.printJoin(node.decorators, node);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (node.declare) {
|
||||||
|
this.word("declare");
|
||||||
|
this.space();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (node.abstract) {
|
||||||
|
this.word("abstract");
|
||||||
|
this.space();
|
||||||
|
}
|
||||||
|
|
||||||
this.word("class");
|
this.word("class");
|
||||||
|
|
||||||
if (node.id) {
|
if (node.id) {
|
||||||
@ -59,10 +69,22 @@ export function ClassBody(node: Object) {
|
|||||||
export function ClassProperty(node: Object) {
|
export function ClassProperty(node: Object) {
|
||||||
this.printJoin(node.decorators, node);
|
this.printJoin(node.decorators, node);
|
||||||
|
|
||||||
|
if (node.accessibility) {
|
||||||
|
this.word(node.accessibility);
|
||||||
|
this.space();
|
||||||
|
}
|
||||||
if (node.static) {
|
if (node.static) {
|
||||||
this.word("static");
|
this.word("static");
|
||||||
this.space();
|
this.space();
|
||||||
}
|
}
|
||||||
|
if (node.abstract) {
|
||||||
|
this.word("abstract");
|
||||||
|
this.space();
|
||||||
|
}
|
||||||
|
if (node.readonly) {
|
||||||
|
this.word("readonly");
|
||||||
|
this.space();
|
||||||
|
}
|
||||||
if (node.computed) {
|
if (node.computed) {
|
||||||
this.token("[");
|
this.token("[");
|
||||||
this.print(node.key, node);
|
this.print(node.key, node);
|
||||||
@ -71,6 +93,11 @@ export function ClassProperty(node: Object) {
|
|||||||
this._variance(node);
|
this._variance(node);
|
||||||
this.print(node.key, node);
|
this.print(node.key, node);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (node.optional) {
|
||||||
|
this.token("?");
|
||||||
|
}
|
||||||
|
|
||||||
this.print(node.typeAnnotation, node);
|
this.print(node.typeAnnotation, node);
|
||||||
if (node.value) {
|
if (node.value) {
|
||||||
this.space();
|
this.space();
|
||||||
@ -82,12 +109,28 @@ export function ClassProperty(node: Object) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export function ClassMethod(node: Object) {
|
export function ClassMethod(node: Object) {
|
||||||
|
this._classMethodHead(node);
|
||||||
|
this.space();
|
||||||
|
this.print(node.body, node);
|
||||||
|
}
|
||||||
|
|
||||||
|
export function _classMethodHead(node) {
|
||||||
this.printJoin(node.decorators, node);
|
this.printJoin(node.decorators, node);
|
||||||
|
|
||||||
|
if (node.accessibility) {
|
||||||
|
this.word(node.accessibility);
|
||||||
|
this.space();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (node.abstract) {
|
||||||
|
this.word("abstract");
|
||||||
|
this.space();
|
||||||
|
}
|
||||||
|
|
||||||
if (node.static) {
|
if (node.static) {
|
||||||
this.word("static");
|
this.word("static");
|
||||||
this.space();
|
this.space();
|
||||||
}
|
}
|
||||||
|
|
||||||
this._method(node);
|
this._methodHead(node);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -65,6 +65,8 @@ export function NewExpression(node: Object, parent: Object) {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
this.print(node.typeParameters, node);
|
||||||
|
|
||||||
if (node.optional) {
|
if (node.optional) {
|
||||||
this.token("?.");
|
this.token("?.");
|
||||||
}
|
}
|
||||||
@ -94,6 +96,8 @@ export function Decorator(node: Object) {
|
|||||||
export function CallExpression(node: Object) {
|
export function CallExpression(node: Object) {
|
||||||
this.print(node.callee, node);
|
this.print(node.callee, node);
|
||||||
|
|
||||||
|
this.print(node.typeParameters, node);
|
||||||
|
|
||||||
if (node.optional) {
|
if (node.optional) {
|
||||||
this.token("?.");
|
this.token("?.");
|
||||||
}
|
}
|
||||||
|
|||||||
@ -303,38 +303,6 @@ export function TypeAlias(node: Object) {
|
|||||||
this.semicolon();
|
this.semicolon();
|
||||||
}
|
}
|
||||||
|
|
||||||
export function TypeAnnotation(node: Object) {
|
|
||||||
this.token(":");
|
|
||||||
this.space();
|
|
||||||
if (node.optional) this.token("?");
|
|
||||||
this.print(node.typeAnnotation, node);
|
|
||||||
}
|
|
||||||
|
|
||||||
export function TypeParameter(node: Object) {
|
|
||||||
this._variance(node);
|
|
||||||
|
|
||||||
this.word(node.name);
|
|
||||||
|
|
||||||
if (node.bound) {
|
|
||||||
this.print(node.bound, node);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (node.default) {
|
|
||||||
this.space();
|
|
||||||
this.token("=");
|
|
||||||
this.space();
|
|
||||||
this.print(node.default, node);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
export function TypeParameterInstantiation(node: Object) {
|
|
||||||
this.token("<");
|
|
||||||
this.printList(node.params, node, {});
|
|
||||||
this.token(">");
|
|
||||||
}
|
|
||||||
|
|
||||||
export { TypeParameterInstantiation as TypeParameterDeclaration };
|
|
||||||
|
|
||||||
export function ObjectTypeAnnotation(node: Object) {
|
export function ObjectTypeAnnotation(node: Object) {
|
||||||
if (node.exact) {
|
if (node.exact) {
|
||||||
this.token("{|");
|
this.token("{|");
|
||||||
|
|||||||
@ -8,3 +8,5 @@ export * from "./types";
|
|||||||
export * from "./flow";
|
export * from "./flow";
|
||||||
export * from "./base";
|
export * from "./base";
|
||||||
export * from "./jsx";
|
export * from "./jsx";
|
||||||
|
export * from "./tsFlowCommon";
|
||||||
|
export * from "./typescript";
|
||||||
|
|||||||
@ -3,20 +3,31 @@ import * as t from "babel-types";
|
|||||||
export function _params(node: Object) {
|
export function _params(node: Object) {
|
||||||
this.print(node.typeParameters, node);
|
this.print(node.typeParameters, node);
|
||||||
this.token("(");
|
this.token("(");
|
||||||
this.printList(node.params, node, {
|
this._parameters(node.params, node);
|
||||||
iterator: node => {
|
|
||||||
if (node.optional) this.token("?");
|
|
||||||
this.print(node.typeAnnotation, node);
|
|
||||||
},
|
|
||||||
});
|
|
||||||
this.token(")");
|
this.token(")");
|
||||||
|
|
||||||
if (node.returnType) {
|
|
||||||
this.print(node.returnType, node);
|
this.print(node.returnType, node);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function _parameters(parameters, parent) {
|
||||||
|
for (let i = 0; i < parameters.length; i++) {
|
||||||
|
this._param(parameters[i], parent);
|
||||||
|
|
||||||
|
if (i < parameters.length - 1) {
|
||||||
|
this.token(",");
|
||||||
|
this.space();
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export function _method(node: Object) {
|
export function _param(parameter, parent) {
|
||||||
|
this.printJoin(parameter.decorators, parameter);
|
||||||
|
this.print(parameter, parent);
|
||||||
|
if (parameter.optional) this.token("?");
|
||||||
|
this.print(parameter.typeAnnotation, parameter);
|
||||||
|
}
|
||||||
|
|
||||||
|
export function _methodHead(node: Object) {
|
||||||
const kind = node.kind;
|
const kind = node.kind;
|
||||||
const key = node.key;
|
const key = node.key;
|
||||||
|
|
||||||
@ -44,9 +55,11 @@ export function _method(node: Object) {
|
|||||||
this.print(key, node);
|
this.print(key, node);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (node.optional) {
|
||||||
|
this.token("?");
|
||||||
|
}
|
||||||
|
|
||||||
this._params(node);
|
this._params(node);
|
||||||
this.space();
|
|
||||||
this.print(node.body, node);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export function _predicate(node: Object) {
|
export function _predicate(node: Object) {
|
||||||
@ -59,7 +72,7 @@ export function _predicate(node: Object) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export function FunctionExpression(node: Object) {
|
export function _functionHead(node: Object) {
|
||||||
if (node.async) {
|
if (node.async) {
|
||||||
this.word("async");
|
this.word("async");
|
||||||
this.space();
|
this.space();
|
||||||
@ -67,16 +80,17 @@ export function FunctionExpression(node: Object) {
|
|||||||
this.word("function");
|
this.word("function");
|
||||||
if (node.generator) this.token("*");
|
if (node.generator) this.token("*");
|
||||||
|
|
||||||
|
this.space();
|
||||||
if (node.id) {
|
if (node.id) {
|
||||||
this.space();
|
|
||||||
this.print(node.id, node);
|
this.print(node.id, node);
|
||||||
} else {
|
|
||||||
this.space();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
this._params(node);
|
this._params(node);
|
||||||
this._predicate(node);
|
this._predicate(node);
|
||||||
|
}
|
||||||
|
|
||||||
|
export function FunctionExpression(node: Object) {
|
||||||
|
this._functionHead(node);
|
||||||
this.space();
|
this.space();
|
||||||
this.print(node.body, node);
|
this.print(node.body, node);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -236,6 +236,11 @@ function constDeclarationIndent() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export function VariableDeclaration(node: Object, parent: Object) {
|
export function VariableDeclaration(node: Object, parent: Object) {
|
||||||
|
if (node.declare) {
|
||||||
|
this.word("declare");
|
||||||
|
this.space();
|
||||||
|
}
|
||||||
|
|
||||||
this.word(node.kind);
|
this.word(node.kind);
|
||||||
this.space();
|
this.space();
|
||||||
|
|
||||||
|
|||||||
38
packages/babel-generator/src/generators/tsFlowCommon.js
Normal file
38
packages/babel-generator/src/generators/tsFlowCommon.js
Normal file
@ -0,0 +1,38 @@
|
|||||||
|
export function TypeAnnotation(node) {
|
||||||
|
this.token(":");
|
||||||
|
this.space();
|
||||||
|
if (node.optional) this.token("?");
|
||||||
|
this.print(node.typeAnnotation, node);
|
||||||
|
}
|
||||||
|
|
||||||
|
export function TypeParameterInstantiation(node): void {
|
||||||
|
this.token("<");
|
||||||
|
this.printList(node.params, node, {});
|
||||||
|
this.token(">");
|
||||||
|
}
|
||||||
|
|
||||||
|
export { TypeParameterInstantiation as TypeParameterDeclaration };
|
||||||
|
|
||||||
|
export function TypeParameter(node) {
|
||||||
|
this._variance(node);
|
||||||
|
|
||||||
|
this.word(node.name);
|
||||||
|
|
||||||
|
if (node.bound) {
|
||||||
|
this.print(node.bound, node);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (node.constraint) {
|
||||||
|
this.space();
|
||||||
|
this.word("extends");
|
||||||
|
this.space();
|
||||||
|
this.print(node.constraint, node);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (node.default) {
|
||||||
|
this.space();
|
||||||
|
this.token("=");
|
||||||
|
this.space();
|
||||||
|
this.print(node.default, node);
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -31,7 +31,9 @@ export { ObjectExpression as ObjectPattern };
|
|||||||
|
|
||||||
export function ObjectMethod(node: Object) {
|
export function ObjectMethod(node: Object) {
|
||||||
this.printJoin(node.decorators, node);
|
this.printJoin(node.decorators, node);
|
||||||
this._method(node);
|
this._methodHead(node);
|
||||||
|
this.space();
|
||||||
|
this.print(node.body, node);
|
||||||
}
|
}
|
||||||
|
|
||||||
export function ObjectProperty(node: Object) {
|
export function ObjectProperty(node: Object) {
|
||||||
|
|||||||
456
packages/babel-generator/src/generators/typescript.js
Normal file
456
packages/babel-generator/src/generators/typescript.js
Normal file
@ -0,0 +1,456 @@
|
|||||||
|
export function TSParameterProperty(node) {
|
||||||
|
if (node.accessibility) {
|
||||||
|
this.word(node.accessibility);
|
||||||
|
this.space();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (node.readonly) {
|
||||||
|
this.word("readonly");
|
||||||
|
this.space();
|
||||||
|
}
|
||||||
|
|
||||||
|
this._param(node.parameter);
|
||||||
|
}
|
||||||
|
|
||||||
|
export function TSDeclareFunction(node) {
|
||||||
|
if (node.declare) {
|
||||||
|
this.word("declare");
|
||||||
|
this.space();
|
||||||
|
}
|
||||||
|
this._functionHead(node);
|
||||||
|
this.token(";");
|
||||||
|
}
|
||||||
|
|
||||||
|
export function TSDeclareMethod(node) {
|
||||||
|
this._classMethodHead(node);
|
||||||
|
this.token(";");
|
||||||
|
}
|
||||||
|
|
||||||
|
export function TSQualifiedName(node) {
|
||||||
|
this.print(node.left, node);
|
||||||
|
this.token(".");
|
||||||
|
this.print(node.right, node);
|
||||||
|
}
|
||||||
|
|
||||||
|
export function TSCallSignatureDeclaration(node) {
|
||||||
|
this.tsPrintSignatureDeclarationBase(node);
|
||||||
|
}
|
||||||
|
|
||||||
|
export function TSConstructSignatureDeclaration(node) {
|
||||||
|
this.word("new");
|
||||||
|
this.space();
|
||||||
|
this.tsPrintSignatureDeclarationBase(node);
|
||||||
|
}
|
||||||
|
|
||||||
|
export function TSPropertySignature(node) {
|
||||||
|
const { readonly, initializer } = node;
|
||||||
|
if (readonly) {
|
||||||
|
this.word("readonly");
|
||||||
|
this.space();
|
||||||
|
}
|
||||||
|
this.tsPrintPropertyOrMethodName(node);
|
||||||
|
this.print(node.typeAnnotation, node);
|
||||||
|
if (initializer) {
|
||||||
|
this.space();
|
||||||
|
this.token("=");
|
||||||
|
this.space();
|
||||||
|
this.print(initializer, node);
|
||||||
|
}
|
||||||
|
this.token(";");
|
||||||
|
}
|
||||||
|
|
||||||
|
export function tsPrintPropertyOrMethodName(node) {
|
||||||
|
if (node.computed) {
|
||||||
|
this.token("[");
|
||||||
|
}
|
||||||
|
this.print(node.key, node);
|
||||||
|
if (node.computed) {
|
||||||
|
this.token("]");
|
||||||
|
}
|
||||||
|
if (node.optional) {
|
||||||
|
this.token("?");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export function TSMethodSignature(node) {
|
||||||
|
this.tsPrintPropertyOrMethodName(node);
|
||||||
|
this.tsPrintSignatureDeclarationBase(node);
|
||||||
|
this.token(";");
|
||||||
|
}
|
||||||
|
|
||||||
|
export function TSIndexSignature(node) {
|
||||||
|
const { readonly } = node;
|
||||||
|
if (readonly) {
|
||||||
|
this.word("readonly");
|
||||||
|
this.space();
|
||||||
|
}
|
||||||
|
this.token("[");
|
||||||
|
this._parameters(node.parameters, node);
|
||||||
|
this.token("]");
|
||||||
|
this.print(node.typeAnnotation, node);
|
||||||
|
this.token(";");
|
||||||
|
}
|
||||||
|
|
||||||
|
export function TSAnyKeyword() {
|
||||||
|
this.word("any");
|
||||||
|
}
|
||||||
|
export function TSNumberKeyword() {
|
||||||
|
this.word("number");
|
||||||
|
}
|
||||||
|
export function TSObjectKeyword() {
|
||||||
|
this.word("object");
|
||||||
|
}
|
||||||
|
export function TSBooleanKeyword() {
|
||||||
|
this.word("boolean");
|
||||||
|
}
|
||||||
|
export function TSStringKeyword() {
|
||||||
|
this.word("string");
|
||||||
|
}
|
||||||
|
export function TSSymbolKeyword() {
|
||||||
|
this.word("symbol");
|
||||||
|
}
|
||||||
|
export function TSVoidKeyword() {
|
||||||
|
this.word("void");
|
||||||
|
}
|
||||||
|
export function TSUndefinedKeyword() {
|
||||||
|
this.word("undefined");
|
||||||
|
}
|
||||||
|
export function TSNullKeyword() {
|
||||||
|
this.word("null");
|
||||||
|
}
|
||||||
|
export function TSNeverKeyword() {
|
||||||
|
this.word("never");
|
||||||
|
}
|
||||||
|
|
||||||
|
export function TSThisType() {
|
||||||
|
this.word("this");
|
||||||
|
}
|
||||||
|
|
||||||
|
export function TSFunctionType(node) {
|
||||||
|
this.tsPrintFunctionOrConstructorType(node);
|
||||||
|
}
|
||||||
|
|
||||||
|
export function TSConstructorType(node) {
|
||||||
|
this.word("new");
|
||||||
|
this.space();
|
||||||
|
this.tsPrintFunctionOrConstructorType(node);
|
||||||
|
}
|
||||||
|
|
||||||
|
export function tsPrintFunctionOrConstructorType(
|
||||||
|
node: FunctionOrConstructorType,
|
||||||
|
) {
|
||||||
|
const { typeParameters, parameters } = node;
|
||||||
|
this.print(typeParameters, node);
|
||||||
|
this.token("(");
|
||||||
|
this._parameters(parameters, node);
|
||||||
|
this.token(")");
|
||||||
|
this.space();
|
||||||
|
this.token("=>");
|
||||||
|
this.space();
|
||||||
|
this.print(node.typeAnnotation.typeAnnotation, node);
|
||||||
|
}
|
||||||
|
|
||||||
|
export function TSTypeReference(node) {
|
||||||
|
this.print(node.typeName, node);
|
||||||
|
this.print(node.typeParameters, node);
|
||||||
|
}
|
||||||
|
|
||||||
|
export function TSTypePredicate(node) {
|
||||||
|
this.print(node.parameterName);
|
||||||
|
this.space();
|
||||||
|
this.word("is");
|
||||||
|
this.space();
|
||||||
|
this.print(node.typeAnnotation.typeAnnotation);
|
||||||
|
}
|
||||||
|
|
||||||
|
export function TSTypeQuery(node) {
|
||||||
|
this.word("typeof");
|
||||||
|
this.space();
|
||||||
|
this.print(node.exprName);
|
||||||
|
}
|
||||||
|
|
||||||
|
export function TSTypeLiteral(node) {
|
||||||
|
this.tsPrintTypeLiteralOrInterfaceBody(node.members, node);
|
||||||
|
}
|
||||||
|
|
||||||
|
export function tsPrintTypeLiteralOrInterfaceBody(members, node) {
|
||||||
|
this.tsPrintBraced(members, node);
|
||||||
|
}
|
||||||
|
|
||||||
|
export function tsPrintBraced(members, node) {
|
||||||
|
this.token("{");
|
||||||
|
if (members.length) {
|
||||||
|
this.indent();
|
||||||
|
this.newline();
|
||||||
|
for (const member of members) {
|
||||||
|
this.print(member, node);
|
||||||
|
//this.token(sep);
|
||||||
|
this.newline();
|
||||||
|
}
|
||||||
|
this.dedent();
|
||||||
|
this.rightBrace();
|
||||||
|
} else {
|
||||||
|
this.token("}");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export function TSArrayType(node) {
|
||||||
|
this.print(node.elementType);
|
||||||
|
this.token("[]");
|
||||||
|
}
|
||||||
|
|
||||||
|
export function TSTupleType(node) {
|
||||||
|
this.token("[");
|
||||||
|
this.printList(node.elementTypes, node);
|
||||||
|
this.token("]");
|
||||||
|
}
|
||||||
|
|
||||||
|
export function TSUnionType(node) {
|
||||||
|
this.tsPrintUnionOrIntersectionType(node, "|");
|
||||||
|
}
|
||||||
|
|
||||||
|
export function TSIntersectionType(node) {
|
||||||
|
this.tsPrintUnionOrIntersectionType(node, "&");
|
||||||
|
}
|
||||||
|
|
||||||
|
export function tsPrintUnionOrIntersectionType(node, sep) {
|
||||||
|
this.printJoin(node.types, node, {
|
||||||
|
separator() {
|
||||||
|
this.space();
|
||||||
|
this.token(sep);
|
||||||
|
this.space();
|
||||||
|
},
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
export function TSParenthesizedType(node) {
|
||||||
|
this.token("(");
|
||||||
|
this.print(node.typeAnnotation, node);
|
||||||
|
this.token(")");
|
||||||
|
}
|
||||||
|
|
||||||
|
export function TSTypeOperator(node) {
|
||||||
|
this.token(node.operator);
|
||||||
|
this.space();
|
||||||
|
this.print(node.typeAnnotation, node);
|
||||||
|
}
|
||||||
|
|
||||||
|
export function TSIndexedAccessType(node) {
|
||||||
|
this.print(node.objectType, node);
|
||||||
|
this.token("[");
|
||||||
|
this.print(node.indexType, node);
|
||||||
|
this.token("]");
|
||||||
|
}
|
||||||
|
|
||||||
|
export function TSMappedType(node) {
|
||||||
|
const { readonly, typeParameter, optional } = node;
|
||||||
|
this.token("{");
|
||||||
|
this.space();
|
||||||
|
if (readonly) {
|
||||||
|
this.word("readonly");
|
||||||
|
this.space();
|
||||||
|
}
|
||||||
|
|
||||||
|
this.token("[");
|
||||||
|
this.word(typeParameter.name);
|
||||||
|
this.space();
|
||||||
|
this.word("in");
|
||||||
|
this.space();
|
||||||
|
this.print(typeParameter.constraint, typeParameter);
|
||||||
|
this.token("]");
|
||||||
|
|
||||||
|
if (optional) {
|
||||||
|
this.token("?");
|
||||||
|
}
|
||||||
|
this.token(":");
|
||||||
|
this.space();
|
||||||
|
this.print(node.typeAnnotation, node);
|
||||||
|
this.space();
|
||||||
|
this.token("}");
|
||||||
|
}
|
||||||
|
|
||||||
|
export function TSLiteralType(node) {
|
||||||
|
this.print(node.literal, node);
|
||||||
|
}
|
||||||
|
|
||||||
|
export function TSExpressionWithTypeArguments(node) {
|
||||||
|
this.print(node.expression, node);
|
||||||
|
this.print(node.typeParameters, node);
|
||||||
|
}
|
||||||
|
|
||||||
|
export function TSInterfaceDeclaration(node) {
|
||||||
|
const { declare, id, typeParameters, extends: extendz, body } = node;
|
||||||
|
if (declare) {
|
||||||
|
this.word("declare");
|
||||||
|
this.space();
|
||||||
|
}
|
||||||
|
this.word("interface");
|
||||||
|
this.space();
|
||||||
|
this.print(id, node);
|
||||||
|
this.print(typeParameters, node);
|
||||||
|
if (extendz) {
|
||||||
|
this.space();
|
||||||
|
this.word("extends");
|
||||||
|
this.space();
|
||||||
|
this.printList(extendz, node);
|
||||||
|
}
|
||||||
|
this.space();
|
||||||
|
this.print(body, node);
|
||||||
|
}
|
||||||
|
|
||||||
|
export function TSInterfaceBody(node) {
|
||||||
|
this.tsPrintTypeLiteralOrInterfaceBody(node.body, node);
|
||||||
|
}
|
||||||
|
|
||||||
|
export function TSTypeAliasDeclaration(node) {
|
||||||
|
const { declare, id, typeParameters, typeAnnotation } = node;
|
||||||
|
if (declare) {
|
||||||
|
this.word("declare");
|
||||||
|
this.space();
|
||||||
|
}
|
||||||
|
this.word("type");
|
||||||
|
this.space();
|
||||||
|
this.print(id, node);
|
||||||
|
this.print(typeParameters, node);
|
||||||
|
this.space();
|
||||||
|
this.token("=");
|
||||||
|
this.space();
|
||||||
|
this.print(typeAnnotation, node);
|
||||||
|
this.token(";");
|
||||||
|
}
|
||||||
|
|
||||||
|
export function TSAsExpression(node) {
|
||||||
|
const { expression, typeAnnotation } = node;
|
||||||
|
this.print(expression, node);
|
||||||
|
this.space();
|
||||||
|
this.word("as");
|
||||||
|
this.space();
|
||||||
|
this.print(typeAnnotation, node);
|
||||||
|
}
|
||||||
|
|
||||||
|
export function TSTypeAssertion(node) {
|
||||||
|
const { typeAnnotation, expression } = node;
|
||||||
|
this.token("<");
|
||||||
|
this.print(typeAnnotation, node);
|
||||||
|
this.token(">");
|
||||||
|
this.space();
|
||||||
|
this.print(expression, node);
|
||||||
|
}
|
||||||
|
|
||||||
|
export function TSEnumDeclaration(node) {
|
||||||
|
const { declare, const: isConst, id, members } = node;
|
||||||
|
if (declare) {
|
||||||
|
this.word("declare");
|
||||||
|
this.space();
|
||||||
|
}
|
||||||
|
if (isConst) {
|
||||||
|
this.word("const");
|
||||||
|
this.space();
|
||||||
|
}
|
||||||
|
this.word("enum");
|
||||||
|
this.space();
|
||||||
|
this.print(id, node);
|
||||||
|
this.space();
|
||||||
|
this.tsPrintBraced(members, node);
|
||||||
|
}
|
||||||
|
|
||||||
|
export function TSEnumMember(node) {
|
||||||
|
const { id, initializer } = node;
|
||||||
|
this.print(id, node);
|
||||||
|
if (initializer) {
|
||||||
|
this.space();
|
||||||
|
this.token("=");
|
||||||
|
this.space();
|
||||||
|
this.print(initializer, node);
|
||||||
|
}
|
||||||
|
this.token(",");
|
||||||
|
}
|
||||||
|
|
||||||
|
export function TSModuleDeclaration(node) {
|
||||||
|
const { declare, id } = node;
|
||||||
|
|
||||||
|
if (declare) {
|
||||||
|
this.word("declare");
|
||||||
|
this.space();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!node.global) {
|
||||||
|
this.word(id.type === "Identifier" ? "namespace" : "module");
|
||||||
|
this.space();
|
||||||
|
}
|
||||||
|
this.print(id, node);
|
||||||
|
|
||||||
|
if (!node.body) {
|
||||||
|
this.token(";");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
let body = node.body;
|
||||||
|
while (body.type === "TSModuleDeclaration") {
|
||||||
|
this.token(".");
|
||||||
|
this.print(body.id, body);
|
||||||
|
body = body.body;
|
||||||
|
}
|
||||||
|
|
||||||
|
this.space();
|
||||||
|
this.print(body, node);
|
||||||
|
}
|
||||||
|
|
||||||
|
export function TSModuleBlock(node) {
|
||||||
|
this.tsPrintBraced(node.body, node);
|
||||||
|
}
|
||||||
|
|
||||||
|
export function TSImportEqualsDeclaration(node) {
|
||||||
|
const { isExport, id, moduleReference } = node;
|
||||||
|
if (isExport) {
|
||||||
|
this.word("export");
|
||||||
|
this.space();
|
||||||
|
}
|
||||||
|
this.word("import");
|
||||||
|
this.space();
|
||||||
|
this.print(id, node);
|
||||||
|
this.space();
|
||||||
|
this.token("=");
|
||||||
|
this.space();
|
||||||
|
this.print(moduleReference, node);
|
||||||
|
this.token(";");
|
||||||
|
}
|
||||||
|
|
||||||
|
export function TSExternalModuleReference(node) {
|
||||||
|
this.token("require(");
|
||||||
|
this.print(node.expression, node);
|
||||||
|
this.token(")");
|
||||||
|
}
|
||||||
|
|
||||||
|
export function TSNonNullExpression(node) {
|
||||||
|
this.print(node.expression, node);
|
||||||
|
this.token("!");
|
||||||
|
}
|
||||||
|
|
||||||
|
export function TSExportAssignment(node) {
|
||||||
|
this.word("export");
|
||||||
|
this.space();
|
||||||
|
this.token("=");
|
||||||
|
this.space();
|
||||||
|
this.print(node.expression, node);
|
||||||
|
this.token(";");
|
||||||
|
}
|
||||||
|
|
||||||
|
export function TSNamespaceExportDeclaration(node) {
|
||||||
|
this.word("export");
|
||||||
|
this.space();
|
||||||
|
this.word("as");
|
||||||
|
this.space();
|
||||||
|
this.word("namespace");
|
||||||
|
this.space();
|
||||||
|
this.print(node.id, node);
|
||||||
|
}
|
||||||
|
|
||||||
|
export function tsPrintSignatureDeclarationBase(node) {
|
||||||
|
const { typeParameters, parameters } = node;
|
||||||
|
this.print(typeParameters, node);
|
||||||
|
this.token("(");
|
||||||
|
this._parameters(parameters, node);
|
||||||
|
this.token(")");
|
||||||
|
this.print(node.typeAnnotation, node);
|
||||||
|
}
|
||||||
@ -93,6 +93,14 @@ export function Binary(node: Object, parent: Object): boolean {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function TSAsExpression() {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
export function TSTypeAssertion() {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
export function BinaryExpression(node: Object, parent: Object): boolean {
|
export function BinaryExpression(node: Object, parent: Object): boolean {
|
||||||
// let i = (1 in []);
|
// let i = (1 in []);
|
||||||
// for ((1 in []);;);
|
// for ((1 in []);;);
|
||||||
@ -173,7 +181,9 @@ export function ConditionalExpression(node: Object, parent: Object): boolean {
|
|||||||
t.isBinary(parent) ||
|
t.isBinary(parent) ||
|
||||||
t.isConditionalExpression(parent, { test: node }) ||
|
t.isConditionalExpression(parent, { test: node }) ||
|
||||||
t.isAwaitExpression(parent) ||
|
t.isAwaitExpression(parent) ||
|
||||||
t.isTaggedTemplateExpression(parent)
|
t.isTaggedTemplateExpression(parent) ||
|
||||||
|
t.isTSTypeAssertion(parent) ||
|
||||||
|
t.isTSAsExpression(parent)
|
||||||
) {
|
) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|||||||
1
packages/babel-generator/test/fixtures/typescript/arrow-function-annotated/actual.js
vendored
Normal file
1
packages/babel-generator/test/fixtures/typescript/arrow-function-annotated/actual.js
vendored
Normal file
@ -0,0 +1 @@
|
|||||||
|
(x: number): number => x;
|
||||||
1
packages/babel-generator/test/fixtures/typescript/arrow-function-annotated/expected.js
vendored
Normal file
1
packages/babel-generator/test/fixtures/typescript/arrow-function-annotated/expected.js
vendored
Normal file
@ -0,0 +1 @@
|
|||||||
|
(x: number): number => x;
|
||||||
@ -0,0 +1,2 @@
|
|||||||
|
async < 1;
|
||||||
|
async<T>() == 0;
|
||||||
@ -0,0 +1,2 @@
|
|||||||
|
async < 1;
|
||||||
|
async<T>() == 0;
|
||||||
1
packages/babel-generator/test/fixtures/typescript/arrow-function-async-generic/actual.js
vendored
Normal file
1
packages/babel-generator/test/fixtures/typescript/arrow-function-async-generic/actual.js
vendored
Normal file
@ -0,0 +1 @@
|
|||||||
|
async <T>(a: T): T => a;
|
||||||
1
packages/babel-generator/test/fixtures/typescript/arrow-function-async-generic/expected.js
vendored
Normal file
1
packages/babel-generator/test/fixtures/typescript/arrow-function-async-generic/expected.js
vendored
Normal file
@ -0,0 +1 @@
|
|||||||
|
async <T>(a: T): T => a;
|
||||||
1
packages/babel-generator/test/fixtures/typescript/arrow-function-async/actual.js
vendored
Normal file
1
packages/babel-generator/test/fixtures/typescript/arrow-function-async/actual.js
vendored
Normal file
@ -0,0 +1 @@
|
|||||||
|
async (x?: number): any => x;
|
||||||
1
packages/babel-generator/test/fixtures/typescript/arrow-function-async/expected.js
vendored
Normal file
1
packages/babel-generator/test/fixtures/typescript/arrow-function-async/expected.js
vendored
Normal file
@ -0,0 +1 @@
|
|||||||
|
async (x?: number): any => x;
|
||||||
@ -0,0 +1 @@
|
|||||||
|
(x: number = 0) => 0;
|
||||||
@ -0,0 +1 @@
|
|||||||
|
(x: number = 0) => 0;
|
||||||
1
packages/babel-generator/test/fixtures/typescript/arrow-function-destructuring/actual.js
vendored
Normal file
1
packages/babel-generator/test/fixtures/typescript/arrow-function-destructuring/actual.js
vendored
Normal file
@ -0,0 +1 @@
|
|||||||
|
({ a = 0 }) => 0;
|
||||||
3
packages/babel-generator/test/fixtures/typescript/arrow-function-destructuring/expected.js
vendored
Normal file
3
packages/babel-generator/test/fixtures/typescript/arrow-function-destructuring/expected.js
vendored
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
({
|
||||||
|
a = 0
|
||||||
|
}) => 0;
|
||||||
2
packages/babel-generator/test/fixtures/typescript/arrow-function-generic-tsx/actual.js
vendored
Normal file
2
packages/babel-generator/test/fixtures/typescript/arrow-function-generic-tsx/actual.js
vendored
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
// Same as `generic`. Verify that JSX doesn't change things.
|
||||||
|
<T>(a: T): T => a;
|
||||||
2
packages/babel-generator/test/fixtures/typescript/arrow-function-generic-tsx/expected.js
vendored
Normal file
2
packages/babel-generator/test/fixtures/typescript/arrow-function-generic-tsx/expected.js
vendored
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
// Same as `generic`. Verify that JSX doesn't change things.
|
||||||
|
<T>(a: T): T => a;
|
||||||
3
packages/babel-generator/test/fixtures/typescript/arrow-function-generic-tsx/options.json
vendored
Normal file
3
packages/babel-generator/test/fixtures/typescript/arrow-function-generic-tsx/options.json
vendored
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
{
|
||||||
|
"plugins": ["jsx", "typescript"]
|
||||||
|
}
|
||||||
1
packages/babel-generator/test/fixtures/typescript/arrow-function-generic/actual.js
vendored
Normal file
1
packages/babel-generator/test/fixtures/typescript/arrow-function-generic/actual.js
vendored
Normal file
@ -0,0 +1 @@
|
|||||||
|
<T>(a: T): T => a;
|
||||||
1
packages/babel-generator/test/fixtures/typescript/arrow-function-generic/expected.js
vendored
Normal file
1
packages/babel-generator/test/fixtures/typescript/arrow-function-generic/expected.js
vendored
Normal file
@ -0,0 +1 @@
|
|||||||
|
<T>(a: T): T => a;
|
||||||
@ -0,0 +1 @@
|
|||||||
|
(x?: number): any => x;
|
||||||
@ -0,0 +1 @@
|
|||||||
|
(x?: number): any => x;
|
||||||
1
packages/babel-generator/test/fixtures/typescript/arrow-function-predicate-types/actual.js
vendored
Normal file
1
packages/babel-generator/test/fixtures/typescript/arrow-function-predicate-types/actual.js
vendored
Normal file
@ -0,0 +1 @@
|
|||||||
|
(x: any): x is string => true;
|
||||||
1
packages/babel-generator/test/fixtures/typescript/arrow-function-predicate-types/expected.js
vendored
Normal file
1
packages/babel-generator/test/fixtures/typescript/arrow-function-predicate-types/expected.js
vendored
Normal file
@ -0,0 +1 @@
|
|||||||
|
(x: any): x is string => true;
|
||||||
4
packages/babel-generator/test/fixtures/typescript/cast-as/actual.js
vendored
Normal file
4
packages/babel-generator/test/fixtures/typescript/cast-as/actual.js
vendored
Normal 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;
|
||||||
6
packages/babel-generator/test/fixtures/typescript/cast-as/expected.js
vendored
Normal file
6
packages/babel-generator/test/fixtures/typescript/cast-as/expected.js
vendored
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
(x as T);
|
||||||
|
(x < y as boolean); // (x < y) as boolean;
|
||||||
|
|
||||||
|
x === (1 as number); // x === (1 as number);
|
||||||
|
|
||||||
|
((x as any) as T);
|
||||||
1
packages/babel-generator/test/fixtures/typescript/cast-false-positive/actual.js
vendored
Normal file
1
packages/babel-generator/test/fixtures/typescript/cast-false-positive/actual.js
vendored
Normal file
@ -0,0 +1 @@
|
|||||||
|
f(x < 0, /a/);
|
||||||
1
packages/babel-generator/test/fixtures/typescript/cast-false-positive/expected.js
vendored
Normal file
1
packages/babel-generator/test/fixtures/typescript/cast-false-positive/expected.js
vendored
Normal file
@ -0,0 +1 @@
|
|||||||
|
f(x < 0, /a/);
|
||||||
3
packages/babel-generator/test/fixtures/typescript/cast-need-parentheses/actual.js
vendored
Normal file
3
packages/babel-generator/test/fixtures/typescript/cast-need-parentheses/actual.js
vendored
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
(<T> x).y;
|
||||||
|
(x as T).y;
|
||||||
|
x!.y;
|
||||||
3
packages/babel-generator/test/fixtures/typescript/cast-need-parentheses/expected.js
vendored
Normal file
3
packages/babel-generator/test/fixtures/typescript/cast-need-parentheses/expected.js
vendored
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
(<T> x).y;
|
||||||
|
(x as T).y;
|
||||||
|
x!.y;
|
||||||
@ -0,0 +1 @@
|
|||||||
|
x!.y;
|
||||||
@ -0,0 +1 @@
|
|||||||
|
x!.y;
|
||||||
1
packages/babel-generator/test/fixtures/typescript/cast-null-assertion/actual.js
vendored
Normal file
1
packages/babel-generator/test/fixtures/typescript/cast-null-assertion/actual.js
vendored
Normal file
@ -0,0 +1 @@
|
|||||||
|
x!;
|
||||||
1
packages/babel-generator/test/fixtures/typescript/cast-null-assertion/expected.js
vendored
Normal file
1
packages/babel-generator/test/fixtures/typescript/cast-null-assertion/expected.js
vendored
Normal file
@ -0,0 +1 @@
|
|||||||
|
x!;
|
||||||
@ -0,0 +1 @@
|
|||||||
|
1 + <number> 1;
|
||||||
@ -0,0 +1 @@
|
|||||||
|
1 + (<number> 1);
|
||||||
@ -0,0 +1 @@
|
|||||||
|
<number> 1 + 1;
|
||||||
@ -0,0 +1 @@
|
|||||||
|
(<number> 1) + 1;
|
||||||
1
packages/babel-generator/test/fixtures/typescript/cast-type-assertion/actual.js
vendored
Normal file
1
packages/babel-generator/test/fixtures/typescript/cast-type-assertion/actual.js
vendored
Normal file
@ -0,0 +1 @@
|
|||||||
|
<number> 1;
|
||||||
1
packages/babel-generator/test/fixtures/typescript/cast-type-assertion/expected.js
vendored
Normal file
1
packages/babel-generator/test/fixtures/typescript/cast-type-assertion/expected.js
vendored
Normal file
@ -0,0 +1 @@
|
|||||||
|
(<number> 1);
|
||||||
6
packages/babel-generator/test/fixtures/typescript/class-abstract/actual.js
vendored
Normal file
6
packages/babel-generator/test/fixtures/typescript/class-abstract/actual.js
vendored
Normal 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.
|
||||||
7
packages/babel-generator/test/fixtures/typescript/class-abstract/expected.js
vendored
Normal file
7
packages/babel-generator/test/fixtures/typescript/class-abstract/expected.js
vendored
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
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.
|
||||||
5
packages/babel-generator/test/fixtures/typescript/class-constructor/actual.js
vendored
Normal file
5
packages/babel-generator/test/fixtures/typescript/class-constructor/actual.js
vendored
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
class C {
|
||||||
|
constructor(x: number, y: number);
|
||||||
|
constructor(x: string, y: string);
|
||||||
|
constructor(x: any, y: any) {}
|
||||||
|
}
|
||||||
7
packages/babel-generator/test/fixtures/typescript/class-constructor/expected.js
vendored
Normal file
7
packages/babel-generator/test/fixtures/typescript/class-constructor/expected.js
vendored
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
class C {
|
||||||
|
constructor(x: number, y: number);
|
||||||
|
constructor(x: string, y: string);
|
||||||
|
|
||||||
|
constructor(x: any, y: any) {}
|
||||||
|
|
||||||
|
}
|
||||||
7
packages/babel-generator/test/fixtures/typescript/class-declare/actual.js
vendored
Normal file
7
packages/babel-generator/test/fixtures/typescript/class-declare/actual.js
vendored
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
declare class C {
|
||||||
|
[x: string]: any;
|
||||||
|
x;
|
||||||
|
x: number;
|
||||||
|
f();
|
||||||
|
f(): void;
|
||||||
|
}
|
||||||
7
packages/babel-generator/test/fixtures/typescript/class-declare/expected.js
vendored
Normal file
7
packages/babel-generator/test/fixtures/typescript/class-declare/expected.js
vendored
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
declare class C {
|
||||||
|
[x: string]: any;
|
||||||
|
x;
|
||||||
|
x: number;
|
||||||
|
f();
|
||||||
|
f(): void;
|
||||||
|
}
|
||||||
@ -0,0 +1,2 @@
|
|||||||
|
(class extends f()<T> implements X.Y<T> {});
|
||||||
|
(class C extends f()<T> implements X.Y<T> {});
|
||||||
@ -0,0 +1,3 @@
|
|||||||
|
(class extends f()<T> implements X.Y<T> {});
|
||||||
|
|
||||||
|
(class C extends f()<T> implements X.Y<T> {});
|
||||||
2
packages/babel-generator/test/fixtures/typescript/class-expression-extends/actual.js
vendored
Normal file
2
packages/babel-generator/test/fixtures/typescript/class-expression-extends/actual.js
vendored
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
(class extends f()<T> {});
|
||||||
|
(class C extends f()<T> {});
|
||||||
3
packages/babel-generator/test/fixtures/typescript/class-expression-extends/expected.js
vendored
Normal file
3
packages/babel-generator/test/fixtures/typescript/class-expression-extends/expected.js
vendored
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
(class extends f()<T> {});
|
||||||
|
|
||||||
|
(class C extends f()<T> {});
|
||||||
2
packages/babel-generator/test/fixtures/typescript/class-expression-generic/actual.js
vendored
Normal file
2
packages/babel-generator/test/fixtures/typescript/class-expression-generic/actual.js
vendored
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
(class<T> {});
|
||||||
|
(class C<T> {});
|
||||||
3
packages/babel-generator/test/fixtures/typescript/class-expression-generic/expected.js
vendored
Normal file
3
packages/babel-generator/test/fixtures/typescript/class-expression-generic/expected.js
vendored
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
(class<T> {});
|
||||||
|
|
||||||
|
(class C<T> {});
|
||||||
2
packages/babel-generator/test/fixtures/typescript/class-expression-implements/actual.js
vendored
Normal file
2
packages/babel-generator/test/fixtures/typescript/class-expression-implements/actual.js
vendored
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
(class implements X.Y<T> {});
|
||||||
|
(class C implements X.Y<T> {});
|
||||||
3
packages/babel-generator/test/fixtures/typescript/class-expression-implements/expected.js
vendored
Normal file
3
packages/babel-generator/test/fixtures/typescript/class-expression-implements/expected.js
vendored
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
(class implements X.Y<T> {});
|
||||||
|
|
||||||
|
(class C implements X.Y<T> {});
|
||||||
1
packages/babel-generator/test/fixtures/typescript/class-extends-implements/actual.js
vendored
Normal file
1
packages/babel-generator/test/fixtures/typescript/class-extends-implements/actual.js
vendored
Normal file
@ -0,0 +1 @@
|
|||||||
|
class C extends f()<T> implements X.Y<T> {}
|
||||||
1
packages/babel-generator/test/fixtures/typescript/class-extends-implements/expected.js
vendored
Normal file
1
packages/babel-generator/test/fixtures/typescript/class-extends-implements/expected.js
vendored
Normal file
@ -0,0 +1 @@
|
|||||||
|
class C extends f()<T> implements X.Y<T> {}
|
||||||
1
packages/babel-generator/test/fixtures/typescript/class-extends/actual.js
vendored
Normal file
1
packages/babel-generator/test/fixtures/typescript/class-extends/actual.js
vendored
Normal file
@ -0,0 +1 @@
|
|||||||
|
class C extends f()<T> {}
|
||||||
1
packages/babel-generator/test/fixtures/typescript/class-extends/expected.js
vendored
Normal file
1
packages/babel-generator/test/fixtures/typescript/class-extends/expected.js
vendored
Normal file
@ -0,0 +1 @@
|
|||||||
|
class C extends f()<T> {}
|
||||||
1
packages/babel-generator/test/fixtures/typescript/class-generic/actual.js
vendored
Normal file
1
packages/babel-generator/test/fixtures/typescript/class-generic/actual.js
vendored
Normal file
@ -0,0 +1 @@
|
|||||||
|
class C<T extends object = { x: number }> {}
|
||||||
3
packages/babel-generator/test/fixtures/typescript/class-generic/expected.js
vendored
Normal file
3
packages/babel-generator/test/fixtures/typescript/class-generic/expected.js
vendored
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
class C<T extends object = {
|
||||||
|
x: number;
|
||||||
|
}> {}
|
||||||
3
packages/babel-generator/test/fixtures/typescript/class-get-generic/actual.js
vendored
Normal file
3
packages/babel-generator/test/fixtures/typescript/class-get-generic/actual.js
vendored
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
declare class C {
|
||||||
|
get<T>(): void;
|
||||||
|
}
|
||||||
3
packages/babel-generator/test/fixtures/typescript/class-get-generic/expected.js
vendored
Normal file
3
packages/babel-generator/test/fixtures/typescript/class-get-generic/expected.js
vendored
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
declare class C {
|
||||||
|
get<T>(): void;
|
||||||
|
}
|
||||||
1
packages/babel-generator/test/fixtures/typescript/class-implements/actual.js
vendored
Normal file
1
packages/babel-generator/test/fixtures/typescript/class-implements/actual.js
vendored
Normal file
@ -0,0 +1 @@
|
|||||||
|
class C implements X.Y<T> {}
|
||||||
1
packages/babel-generator/test/fixtures/typescript/class-implements/expected.js
vendored
Normal file
1
packages/babel-generator/test/fixtures/typescript/class-implements/expected.js
vendored
Normal file
@ -0,0 +1 @@
|
|||||||
|
class C implements X.Y<T> {}
|
||||||
4
packages/babel-generator/test/fixtures/typescript/class-index-signature/actual.js
vendored
Normal file
4
packages/babel-generator/test/fixtures/typescript/class-index-signature/actual.js
vendored
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
class C {
|
||||||
|
[x: string]: any;
|
||||||
|
readonly [x: string]: any;
|
||||||
|
}
|
||||||
4
packages/babel-generator/test/fixtures/typescript/class-index-signature/expected.js
vendored
Normal file
4
packages/babel-generator/test/fixtures/typescript/class-index-signature/expected.js
vendored
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
class C {
|
||||||
|
[x: string]: any;
|
||||||
|
readonly [x: string]: any;
|
||||||
|
}
|
||||||
@ -0,0 +1,6 @@
|
|||||||
|
class C {
|
||||||
|
public(): void;
|
||||||
|
public static(): void;
|
||||||
|
readonly = 0;
|
||||||
|
async<T>(): void;
|
||||||
|
}
|
||||||
@ -0,0 +1,6 @@
|
|||||||
|
class C {
|
||||||
|
public(): void;
|
||||||
|
public static(): void;
|
||||||
|
readonly = 0;
|
||||||
|
async<T>(): void;
|
||||||
|
}
|
||||||
@ -0,0 +1,3 @@
|
|||||||
|
class C {
|
||||||
|
public delete(): void;
|
||||||
|
}
|
||||||
@ -0,0 +1,3 @@
|
|||||||
|
class C {
|
||||||
|
public delete(): void;
|
||||||
|
}
|
||||||
4
packages/babel-generator/test/fixtures/typescript/class-method-computed/actual.js
vendored
Normal file
4
packages/babel-generator/test/fixtures/typescript/class-method-computed/actual.js
vendored
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
class C {
|
||||||
|
[Symbol.iterator](): void;
|
||||||
|
[Symbol.iterator]?(): void;
|
||||||
|
}
|
||||||
4
packages/babel-generator/test/fixtures/typescript/class-method-computed/expected.js
vendored
Normal file
4
packages/babel-generator/test/fixtures/typescript/class-method-computed/expected.js
vendored
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
class C {
|
||||||
|
[Symbol.iterator](): void;
|
||||||
|
[Symbol.iterator]?(): void;
|
||||||
|
}
|
||||||
4
packages/babel-generator/test/fixtures/typescript/class-method-generic/actual.js
vendored
Normal file
4
packages/babel-generator/test/fixtures/typescript/class-method-generic/actual.js
vendored
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
class C {
|
||||||
|
f<T>(a: T, b?: T, ...c: T[]): T {}
|
||||||
|
[Symbol.iterator]<T>(): T {}
|
||||||
|
}
|
||||||
6
packages/babel-generator/test/fixtures/typescript/class-method-generic/expected.js
vendored
Normal file
6
packages/babel-generator/test/fixtures/typescript/class-method-generic/expected.js
vendored
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
class C {
|
||||||
|
f<T>(a: T, b?: T, ...c: T[]): T {}
|
||||||
|
|
||||||
|
[Symbol.iterator]<T>(): T {}
|
||||||
|
|
||||||
|
}
|
||||||
4
packages/babel-generator/test/fixtures/typescript/class-method-no-body/actual.js
vendored
Normal file
4
packages/babel-generator/test/fixtures/typescript/class-method-no-body/actual.js
vendored
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
class C {
|
||||||
|
f();
|
||||||
|
f(): void;
|
||||||
|
}
|
||||||
4
packages/babel-generator/test/fixtures/typescript/class-method-no-body/expected.js
vendored
Normal file
4
packages/babel-generator/test/fixtures/typescript/class-method-no-body/expected.js
vendored
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
class C {
|
||||||
|
f();
|
||||||
|
f(): void;
|
||||||
|
}
|
||||||
3
packages/babel-generator/test/fixtures/typescript/class-method-optional/actual.js
vendored
Normal file
3
packages/babel-generator/test/fixtures/typescript/class-method-optional/actual.js
vendored
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
class C {
|
||||||
|
m?(): void {}
|
||||||
|
}
|
||||||
4
packages/babel-generator/test/fixtures/typescript/class-method-optional/expected.js
vendored
Normal file
4
packages/babel-generator/test/fixtures/typescript/class-method-optional/expected.js
vendored
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
class C {
|
||||||
|
m?(): void {}
|
||||||
|
|
||||||
|
}
|
||||||
3
packages/babel-generator/test/fixtures/typescript/class-method-return-type/actual.js
vendored
Normal file
3
packages/babel-generator/test/fixtures/typescript/class-method-return-type/actual.js
vendored
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
class C {
|
||||||
|
f(): void {}
|
||||||
|
}
|
||||||
4
packages/babel-generator/test/fixtures/typescript/class-method-return-type/expected.js
vendored
Normal file
4
packages/babel-generator/test/fixtures/typescript/class-method-return-type/expected.js
vendored
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
class C {
|
||||||
|
f(): void {}
|
||||||
|
|
||||||
|
}
|
||||||
@ -0,0 +1,6 @@
|
|||||||
|
class C
|
||||||
|
{
|
||||||
|
m()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,4 @@
|
|||||||
|
class C {
|
||||||
|
m() {}
|
||||||
|
|
||||||
|
}
|
||||||
@ -0,0 +1,5 @@
|
|||||||
|
class C
|
||||||
|
{
|
||||||
|
m()
|
||||||
|
n()
|
||||||
|
}
|
||||||
@ -0,0 +1,4 @@
|
|||||||
|
class C {
|
||||||
|
m();
|
||||||
|
n();
|
||||||
|
}
|
||||||
11
packages/babel-generator/test/fixtures/typescript/class-modifiers-accessors/actual.js
vendored
Normal file
11
packages/babel-generator/test/fixtures/typescript/class-modifiers-accessors/actual.js
vendored
Normal 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; }
|
||||||
|
}
|
||||||
27
packages/babel-generator/test/fixtures/typescript/class-modifiers-accessors/expected.js
vendored
Normal file
27
packages/babel-generator/test/fixtures/typescript/class-modifiers-accessors/expected.js
vendored
Normal file
@ -0,0 +1,27 @@
|
|||||||
|
// 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;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
11
packages/babel-generator/test/fixtures/typescript/class-modifiers-methods-async/actual.js
vendored
Normal file
11
packages/babel-generator/test/fixtures/typescript/class-modifiers-methods-async/actual.js
vendored
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
// Copy of modifiers-methods with 'async'
|
||||||
|
abstract class C {
|
||||||
|
abstract async a();
|
||||||
|
static async s() {}
|
||||||
|
public abstract async pua();
|
||||||
|
public static async pus() {}
|
||||||
|
|
||||||
|
public async pu() {}
|
||||||
|
protected async po() {}
|
||||||
|
private async pi() {}
|
||||||
|
}
|
||||||
17
packages/babel-generator/test/fixtures/typescript/class-modifiers-methods-async/expected.js
vendored
Normal file
17
packages/babel-generator/test/fixtures/typescript/class-modifiers-methods-async/expected.js
vendored
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
// Copy of modifiers-methods with 'async'
|
||||||
|
abstract class C {
|
||||||
|
abstract async a();
|
||||||
|
|
||||||
|
static async s() {}
|
||||||
|
|
||||||
|
public abstract async pua();
|
||||||
|
|
||||||
|
public static async pus() {}
|
||||||
|
|
||||||
|
public async pu() {}
|
||||||
|
|
||||||
|
protected async po() {}
|
||||||
|
|
||||||
|
private async pi() {}
|
||||||
|
|
||||||
|
}
|
||||||
21
packages/babel-generator/test/fixtures/typescript/class-modifiers-properties/actual.js
vendored
Normal file
21
packages/babel-generator/test/fixtures/typescript/class-modifiers-properties/actual.js
vendored
Normal file
@ -0,0 +1,21 @@
|
|||||||
|
abstract class C {
|
||||||
|
readonly r;
|
||||||
|
readonly r2?: number;
|
||||||
|
abstract a;
|
||||||
|
static s;
|
||||||
|
|
||||||
|
public pu;
|
||||||
|
protected po;
|
||||||
|
private pi;
|
||||||
|
|
||||||
|
readonly abstract ra;
|
||||||
|
abstract readonly ar;
|
||||||
|
static readonly sr;
|
||||||
|
|
||||||
|
public readonly pur;
|
||||||
|
public abstract pua;
|
||||||
|
public static pus;
|
||||||
|
public readonly abstract pura;
|
||||||
|
public abstract readonly puar;
|
||||||
|
public static readonly pusr;
|
||||||
|
}
|
||||||
18
packages/babel-generator/test/fixtures/typescript/class-modifiers-properties/expected.js
vendored
Normal file
18
packages/babel-generator/test/fixtures/typescript/class-modifiers-properties/expected.js
vendored
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
abstract class C {
|
||||||
|
readonly r;
|
||||||
|
readonly r2?: number;
|
||||||
|
abstract a;
|
||||||
|
static s;
|
||||||
|
public pu;
|
||||||
|
protected po;
|
||||||
|
private pi;
|
||||||
|
abstract readonly ra;
|
||||||
|
abstract readonly ar;
|
||||||
|
static readonly sr;
|
||||||
|
public readonly pur;
|
||||||
|
public abstract pua;
|
||||||
|
public static pus;
|
||||||
|
public abstract readonly pura;
|
||||||
|
public abstract readonly puar;
|
||||||
|
public static readonly pusr;
|
||||||
|
}
|
||||||
@ -0,0 +1,3 @@
|
|||||||
|
class C {
|
||||||
|
constructor(@foo readonly x: number) {}
|
||||||
|
}
|
||||||
@ -0,0 +1,5 @@
|
|||||||
|
class C {
|
||||||
|
constructor(@foo
|
||||||
|
readonly x: number) {}
|
||||||
|
|
||||||
|
}
|
||||||
@ -0,0 +1,3 @@
|
|||||||
|
{
|
||||||
|
"plugins": ["typescript", "decorators"]
|
||||||
|
}
|
||||||
Some files were not shown because too many files have changed in this diff Show More
Loading…
x
Reference in New Issue
Block a user