Use TS3.7 when possible for @babel/type dts (#12317)
This commit is contained in:
@@ -4,6 +4,15 @@ const t = require("../../");
|
||||
const stringifyValidator = require("../utils/stringifyValidator");
|
||||
const toFunctionName = require("../utils/toFunctionName");
|
||||
|
||||
// For backward compat, we cannot use TS 3.7 syntax in published packages
|
||||
const ts3_7 = process.argv.includes("--ts3.7")
|
||||
? (code, ...substitutions) => template(code, substitutions)
|
||||
: () => "";
|
||||
const template = (strings, substitutions) =>
|
||||
strings
|
||||
.slice(1)
|
||||
.reduce((res, str, i) => res + substitutions[i] + str, strings[0]);
|
||||
|
||||
let code = `// NOTE: This file is autogenerated. Do not modify.
|
||||
// See packages/babel-types/scripts/generators/typescript.js for script used.
|
||||
|
||||
@@ -130,7 +139,7 @@ for (const typeName of t.TYPES) {
|
||||
`export function is${typeName}(node: object | null | undefined, opts?: object | null): ${result};`,
|
||||
// TypeScript 3.7: https://github.com/microsoft/TypeScript/pull/32695 will allow assert declarations
|
||||
// eslint-disable-next-line max-len
|
||||
`// export function assert${typeName}(node: object | null | undefined, opts?: object | null): asserts ${
|
||||
ts3_7`export function assert${typeName}(node: object | null | undefined, opts?: object | null): asserts ${
|
||||
result === "boolean" ? "node" : result
|
||||
};`
|
||||
);
|
||||
@@ -138,8 +147,7 @@ for (const typeName of t.TYPES) {
|
||||
|
||||
lines.push(
|
||||
// assert/
|
||||
// Commented out as this declaration requires TypeScript 3.7 (what do?)
|
||||
`// export function assertNode(obj: any): asserts obj is Node`,
|
||||
ts3_7`export function assertNode(obj: any): asserts obj is Node`,
|
||||
|
||||
// builders/
|
||||
// eslint-disable-next-line max-len
|
||||
|
||||
Reference in New Issue
Block a user