fix(typescript): print readonly and ? tokens in TSMappedType (#1535)
parent
4629db6b0d
commit
3d45278ea7
|
@ -2058,14 +2058,22 @@ function genericPrintNoParens(path, options, print, args) {
|
||||||
// supported by the pretty-printer.
|
// supported by the pretty-printer.
|
||||||
case "DeclaredPredicate":
|
case "DeclaredPredicate":
|
||||||
return concat(["%checks(", path.call(print, "value"), ")"]);
|
return concat(["%checks(", path.call(print, "value"), ")"]);
|
||||||
|
case "TSAbstractKeyword":
|
||||||
|
return "abstract";
|
||||||
case "TSAnyKeyword":
|
case "TSAnyKeyword":
|
||||||
return "any";
|
return "any";
|
||||||
case "TSAsyncKeyword":
|
case "TSAsyncKeyword":
|
||||||
return "async";
|
return "async";
|
||||||
case "TSBooleanKeyword":
|
case "TSBooleanKeyword":
|
||||||
return "boolean";
|
return "boolean";
|
||||||
|
case "TSConstKeyword":
|
||||||
|
return "const";
|
||||||
|
case "TSDeclareKeyword":
|
||||||
|
return "declare"
|
||||||
case "TSExportKeyword":
|
case "TSExportKeyword":
|
||||||
return "export";
|
return "export";
|
||||||
|
case "TSNeverKeyword":
|
||||||
|
return "never";
|
||||||
case "TSNumberKeyword":
|
case "TSNumberKeyword":
|
||||||
return "number";
|
return "number";
|
||||||
case "TSObjectKeyword":
|
case "TSObjectKeyword":
|
||||||
|
@ -2076,12 +2084,18 @@ function genericPrintNoParens(path, options, print, args) {
|
||||||
return "private";
|
return "private";
|
||||||
case "TSPublicKeyword":
|
case "TSPublicKeyword":
|
||||||
return "public";
|
return "public";
|
||||||
|
case "TSQuestionToken":
|
||||||
|
return "?";
|
||||||
case "TSReadonlyKeyword":
|
case "TSReadonlyKeyword":
|
||||||
return "readonly";
|
return "readonly";
|
||||||
|
case "TSSymbolKeyword":
|
||||||
|
return "symbol";
|
||||||
case "TSStaticKeyword":
|
case "TSStaticKeyword":
|
||||||
return "static";
|
return "static";
|
||||||
case "TSStringKeyword":
|
case "TSStringKeyword":
|
||||||
return "string";
|
return "string";
|
||||||
|
case "TSUndefinedKeyword":
|
||||||
|
return "undefined";
|
||||||
case "TSVoidKeyword":
|
case "TSVoidKeyword":
|
||||||
return "void";
|
return "void";
|
||||||
case "TSAsExpression":
|
case "TSAsExpression":
|
||||||
|
@ -2146,12 +2160,6 @@ function genericPrintNoParens(path, options, print, args) {
|
||||||
]);
|
]);
|
||||||
case "TSFirstTypeNode":
|
case "TSFirstTypeNode":
|
||||||
return concat([n.parameterName.name, " is ", path.call(print, "typeAnnotation")])
|
return concat([n.parameterName.name, " is ", path.call(print, "typeAnnotation")])
|
||||||
case "TSNeverKeyword":
|
|
||||||
return "never";
|
|
||||||
case "TSUndefinedKeyword":
|
|
||||||
return "undefined";
|
|
||||||
case "TSSymbolKeyword":
|
|
||||||
return "symbol";
|
|
||||||
case "TSNonNullExpression":
|
case "TSNonNullExpression":
|
||||||
return concat([path.call(print, "expression"), "!"]);
|
return concat([path.call(print, "expression"), "!"]);
|
||||||
case "TSThisType":
|
case "TSThisType":
|
||||||
|
@ -2197,10 +2205,15 @@ function genericPrintNoParens(path, options, print, args) {
|
||||||
indent(
|
indent(
|
||||||
concat([
|
concat([
|
||||||
options.bracketSpacing ? line : softline,
|
options.bracketSpacing ? line : softline,
|
||||||
|
n.readonlyToken
|
||||||
|
? concat([path.call(print, "readonlyToken"), " "])
|
||||||
|
: "",
|
||||||
printTypeScriptModifiers(path, options, print),
|
printTypeScriptModifiers(path, options, print),
|
||||||
"[",
|
"[",
|
||||||
path.call(print, "typeParameter"),
|
path.call(print, "typeParameter"),
|
||||||
"]: ",
|
"]",
|
||||||
|
n.questionToken ? path.call(print, "questionToken") : "",
|
||||||
|
": ",
|
||||||
path.call(print, "typeAnnotation")
|
path.call(print, "typeAnnotation")
|
||||||
])
|
])
|
||||||
),
|
),
|
||||||
|
@ -2358,16 +2371,10 @@ function genericPrintNoParens(path, options, print, args) {
|
||||||
};
|
};
|
||||||
|
|
||||||
return concat(parts);
|
return concat(parts);
|
||||||
case "TSDeclareKeyword":
|
|
||||||
return "declare"
|
|
||||||
case "TSModuleBlock":
|
case "TSModuleBlock":
|
||||||
return path.call(function(bodyPath) {
|
return path.call(function(bodyPath) {
|
||||||
return printStatementSequence(bodyPath, options, print);
|
return printStatementSequence(bodyPath, options, print);
|
||||||
}, "body");
|
}, "body");
|
||||||
case "TSConstKeyword":
|
|
||||||
return "const";
|
|
||||||
case "TSAbstractKeyword":
|
|
||||||
return "abstract";
|
|
||||||
// TODO
|
// TODO
|
||||||
case "ClassHeritage":
|
case "ClassHeritage":
|
||||||
// TODO
|
// TODO
|
||||||
|
|
|
@ -0,0 +1,19 @@
|
||||||
|
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
||||||
|
|
||||||
|
exports[`question.ts 1`] = `
|
||||||
|
var x: {
|
||||||
|
[A in keyof B]?: any;
|
||||||
|
};
|
||||||
|
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||||
|
var x: { [A in keyof B]?: any };
|
||||||
|
|
||||||
|
`;
|
||||||
|
|
||||||
|
exports[`readonly.ts 1`] = `
|
||||||
|
var x: {
|
||||||
|
readonly [A in keyof B]: any;
|
||||||
|
};
|
||||||
|
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||||
|
var x: { readonly [A in keyof B]: any };
|
||||||
|
|
||||||
|
`;
|
|
@ -0,0 +1 @@
|
||||||
|
run_spec(__dirname, { parser: "typescript" });
|
|
@ -0,0 +1,3 @@
|
||||||
|
var x: {
|
||||||
|
[A in keyof B]?: any;
|
||||||
|
};
|
|
@ -0,0 +1,3 @@
|
||||||
|
var x: {
|
||||||
|
readonly [A in keyof B]: any;
|
||||||
|
};
|
Loading…
Reference in New Issue