feat(ts): add support for TSInstantiationExpression
Refs #1230 See https://devblogs.microsoft.com/typescript/announcing-typescript-4-7-beta/#instantiation-expressions. This won't work yet because `ast-types` does not yet know about `TSInstantiationExpression`. Once it does `recast` will need to be updated to include the newer release of `ast-types`, at which point it will be supported.
This commit is contained in:
parent
2cf243225c
commit
413d600a0a
2 changed files with 24 additions and 0 deletions
|
|
@ -2532,6 +2532,16 @@ function genericPrintNoParens(path: any, options: any, print: any) {
|
|||
return concat(parts);
|
||||
}
|
||||
|
||||
case "TSInstantiationExpression": {
|
||||
parts.push(
|
||||
path.call(print, "expression"),
|
||||
path.call(print, "typeParameters"),
|
||||
);
|
||||
|
||||
return concat(parts);
|
||||
}
|
||||
|
||||
|
||||
// https://github.com/babel/babel/pull/10148
|
||||
case "V8IntrinsicIdentifier":
|
||||
return concat(["%", path.call(print, "name")]);
|
||||
|
|
|
|||
|
|
@ -428,6 +428,20 @@ const nodeMajorVersion = parseInt(process.versions.node, 10);
|
|||
["type A = {", " x: boolean;", " y: number;", "}"].join(eol),
|
||||
);
|
||||
});
|
||||
|
||||
it("TSInstantiationExpression: round trip", function () {
|
||||
const code = [
|
||||
"const makeHammerBox = makeBox<Hammer>;",
|
||||
"const ErrorMap = Map<string, Error>;",
|
||||
].join(eol);
|
||||
|
||||
const ast = recast.parse(code, { parser });
|
||||
|
||||
assert.strictEqual(
|
||||
recast.prettyPrint(ast).code,
|
||||
code
|
||||
);
|
||||
})
|
||||
});
|
||||
|
||||
testReprinting(
|
||||
|
|
|
|||
Loading…
Reference in a new issue