Use TS3.7 when possible for @babel/type dts (#12317)
This commit is contained in:
parent
07607fa7c7
commit
a9bc9becc5
1
Makefile
1
Makefile
@ -49,6 +49,7 @@ build-flow-typings:
|
|||||||
|
|
||||||
build-typescript-typings:
|
build-typescript-typings:
|
||||||
$(NODE) packages/babel-types/scripts/generators/typescript.js > packages/babel-types/lib/index.d.ts
|
$(NODE) packages/babel-types/scripts/generators/typescript.js > packages/babel-types/lib/index.d.ts
|
||||||
|
$(NODE) packages/babel-types/scripts/generators/typescript.js --ts3.7 > packages/babel-types/lib/index-ts3.7.d.ts
|
||||||
|
|
||||||
build-standalone: build-babel-standalone
|
build-standalone: build-babel-standalone
|
||||||
|
|
||||||
|
|||||||
@ -15,6 +15,13 @@
|
|||||||
},
|
},
|
||||||
"main": "lib/index.js",
|
"main": "lib/index.js",
|
||||||
"types": "lib/index.d.ts",
|
"types": "lib/index.d.ts",
|
||||||
|
"typesVersions": {
|
||||||
|
">=3.7": {
|
||||||
|
"lib/index.d.ts": [
|
||||||
|
"lib/index-ts3.7.d.ts"
|
||||||
|
]
|
||||||
|
}
|
||||||
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@babel/helper-validator-identifier": "workspace:^7.10.4",
|
"@babel/helper-validator-identifier": "workspace:^7.10.4",
|
||||||
"lodash": "^4.17.19",
|
"lodash": "^4.17.19",
|
||||||
|
|||||||
@ -4,6 +4,15 @@ const t = require("../../");
|
|||||||
const stringifyValidator = require("../utils/stringifyValidator");
|
const stringifyValidator = require("../utils/stringifyValidator");
|
||||||
const toFunctionName = require("../utils/toFunctionName");
|
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.
|
let code = `// NOTE: This file is autogenerated. Do not modify.
|
||||||
// See packages/babel-types/scripts/generators/typescript.js for script used.
|
// 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};`,
|
`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
|
// TypeScript 3.7: https://github.com/microsoft/TypeScript/pull/32695 will allow assert declarations
|
||||||
// eslint-disable-next-line max-len
|
// 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
|
result === "boolean" ? "node" : result
|
||||||
};`
|
};`
|
||||||
);
|
);
|
||||||
@ -138,8 +147,7 @@ for (const typeName of t.TYPES) {
|
|||||||
|
|
||||||
lines.push(
|
lines.push(
|
||||||
// assert/
|
// assert/
|
||||||
// Commented out as this declaration requires TypeScript 3.7 (what do?)
|
ts3_7`export function assertNode(obj: any): asserts obj is Node`,
|
||||||
`// export function assertNode(obj: any): asserts obj is Node`,
|
|
||||||
|
|
||||||
// builders/
|
// builders/
|
||||||
// eslint-disable-next-line max-len
|
// eslint-disable-next-line max-len
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user