fix(typescript): handle ExperimentalSpreadOperator, optional method, and abstract interface (#1763)
This commit is contained in:
1 parent
f66d1b05d6
commit
b265713763
7 files changed
+46
No files matched your search
@@ -66,6 +66,21 @@ function massageAST(ast) {
|
||||
delete newObj.params;
|
||||
}
|
||||
|
||||
// (TypeScript) Ignore `static` in `constructor(static p) {}`
|
||||
// and `export` in `constructor(export p) {}`
|
||||
if (
|
||||
ast.type === "TSParameterProperty" &&
|
||||
ast.accessibility === null &&
|
||||
!ast.readonly
|
||||
) {
|
||||
return {
|
||||
type: "Identifier",
|
||||
name: ast.parameter.name,
|
||||
typeAnnotation: newObj.parameter.typeAnnotation,
|
||||
decorators: newObj.decorators
|
||||
};
|
||||
}
|
||||
|
||||
// We convert <div></div> to <div />
|
||||
if (ast.type === "JSXOpeningElement") {
|
||||
delete newObj.selfClosing;
|
||||
|
||||
@@ -356,6 +356,7 @@ function genericPrintNoParens(path, options, print, args) {
|
||||
case "SpreadElementPattern":
|
||||
case "RestProperty":
|
||||
case "ExperimentalRestProperty":
|
||||
case "ExperimentalSpreadProperty":
|
||||
case "SpreadProperty":
|
||||
case "SpreadPropertyPattern":
|
||||
case "RestElement":
|
||||
@@ -779,6 +780,7 @@ function genericPrintNoParens(path, options, print, args) {
|
||||
}
|
||||
case "TSInterfaceDeclaration":
|
||||
parts.push(
|
||||
n.abstract ? "abstract " : "",
|
||||
printTypeScriptModifiers(path, options, print),
|
||||
"interface ",
|
||||
path.call(print, "id"),
|
||||
@@ -2352,6 +2354,7 @@ function genericPrintNoParens(path, options, print, args) {
|
||||
case "TSMethodSignature":
|
||||
parts.push(
|
||||
path.call(print, "name"),
|
||||
n.questionToken ? "?" : "",
|
||||
printFunctionTypeParameters(path, options, print),
|
||||
printFunctionParams(path, print, options)
|
||||
);
|
||||
|
||||
@@ -14,3 +14,14 @@ interface AudioBufferList {
|
||||
}
|
||||
|
||||
`;
|
||||
|
||||
exports[`methods.ts 1`] = `
|
||||
class X {
|
||||
optionalMethod?() {}
|
||||
}
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
class X {
|
||||
optionalMethod?() {}
|
||||
}
|
||||
|
||||
`;
|
||||
@@ -0,0 +1,3 @@
|
||||
class X {
|
||||
optionalMethod?() {}
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
||||
|
||||
exports[`abstract.ts 1`] = `
|
||||
abstract interface I {
|
||||
|
||||
}
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
abstract interface I {}
|
||||
|
||||
`;
|
||||
@@ -0,0 +1,3 @@
|
||||
abstract interface I {
|
||||
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
run_spec(__dirname, { parser: "typescript" });
|
||||
Reference in new issue
Block a user