[@babel/types] Moved generators related to babel-types into the babel-types package directory. (#9245)
This commit is contained in:
parent
46e3f6df1f
commit
778a61a3c2
7
Makefile
7
Makefile
@ -15,8 +15,8 @@ build: clean clean-lib
|
||||
# call build again as the generated files might need to be compiled again.
|
||||
./node_modules/.bin/gulp build
|
||||
# generate flow and typescript typings
|
||||
node scripts/generators/flow.js > ./packages/babel-types/lib/index.js.flow
|
||||
node scripts/generators/typescript.js > ./packages/babel-types/lib/index.d.ts
|
||||
node packages/babel-types/scripts/generators/flow.js > ./packages/babel-types/lib/index.js.flow
|
||||
node packages/babel-types/scripts/generators/typescript.js > ./packages/babel-types/lib/index.d.ts
|
||||
ifneq ("$(BABEL_COVERAGE)", "true")
|
||||
make build-standalone
|
||||
make build-preset-env-standalone
|
||||
@ -46,7 +46,8 @@ watch: clean clean-lib
|
||||
# development too.
|
||||
BABEL_ENV=development ./node_modules/.bin/gulp build-no-bundle
|
||||
node ./packages/babel-types/scripts/generateTypeHelpers.js
|
||||
node scripts/generators/flow.js > ./packages/babel-types/lib/index.js.flow
|
||||
node packages/babel-types/scripts/generators/flow.js > ./packages/babel-types/lib/index.js.flow
|
||||
node packages/babel-types/scripts/generators/typescript.js > ./packages/babel-types/lib/index.d.ts
|
||||
BABEL_ENV=development ./node_modules/.bin/gulp watch
|
||||
|
||||
flow:
|
||||
|
||||
@ -1,9 +1,10 @@
|
||||
"use strict";
|
||||
|
||||
const util = require("util");
|
||||
const utils = require("./utils");
|
||||
const stringifyValidator = require("../utils/stringifyValidator");
|
||||
const toFunctionName = require("../utils/toFunctionName");
|
||||
|
||||
const types = require("../../packages/babel-types");
|
||||
const types = require("../../");
|
||||
|
||||
const readme = [
|
||||
`# @babel/types
|
||||
@ -43,7 +44,7 @@ Object.keys(types.BUILDER_KEYS)
|
||||
readme.push("```javascript");
|
||||
readme.push(
|
||||
"t." +
|
||||
utils.toFunctionName(key) +
|
||||
toFunctionName(key) +
|
||||
"(" +
|
||||
types.BUILDER_KEYS[key].join(", ") +
|
||||
")"
|
||||
@ -87,7 +88,7 @@ Object.keys(types.BUILDER_KEYS)
|
||||
} else if (validator) {
|
||||
try {
|
||||
fieldDescription.push(
|
||||
": `" + utils.stringifyValidator(validator, "") + "`"
|
||||
": `" + stringifyValidator(validator, "") + "`"
|
||||
);
|
||||
} catch (ex) {
|
||||
if (ex.code === "UNEXPECTED_VALIDATOR_TYPE") {
|
||||
@ -1,12 +1,13 @@
|
||||
"use strict";
|
||||
|
||||
const t = require("../../packages/babel-types");
|
||||
const utils = require("./utils");
|
||||
const t = require("../../");
|
||||
const stringifyValidator = require("../utils/stringifyValidator");
|
||||
const toFunctionName = require("../utils/toFunctionName");
|
||||
|
||||
const NODE_PREFIX = "BabelNode";
|
||||
|
||||
let code = `// NOTE: This file is autogenerated. Do not modify.
|
||||
// See scripts/generators/flow.js for script used.
|
||||
// See packages/babel-types/scripts/generators/flow.js for script used.
|
||||
|
||||
declare class ${NODE_PREFIX}Comment {
|
||||
value: string;
|
||||
@ -73,7 +74,7 @@ for (const type in t.NODE_FIELDS) {
|
||||
|
||||
const validate = field.validate;
|
||||
if (validate) {
|
||||
typeAnnotation = utils.stringifyValidator(validate, NODE_PREFIX);
|
||||
typeAnnotation = stringifyValidator(validate, NODE_PREFIX);
|
||||
}
|
||||
|
||||
if (typeAnnotation) {
|
||||
@ -94,7 +95,7 @@ for (const type in t.NODE_FIELDS) {
|
||||
// Flow chokes on super() and import() :/
|
||||
if (type !== "Super" && type !== "Import") {
|
||||
lines.push(
|
||||
`declare function ${utils.toFunctionName(type)}(${args.join(
|
||||
`declare function ${toFunctionName(type)}(${args.join(
|
||||
", "
|
||||
)}): ${NODE_PREFIX}${type};`
|
||||
);
|
||||
@ -1,10 +1,11 @@
|
||||
"use strict";
|
||||
|
||||
const t = require("../../packages/babel-types");
|
||||
const utils = require("./utils");
|
||||
const t = require("../../");
|
||||
const stringifyValidator = require("../utils/stringifyValidator");
|
||||
const toFunctionName = require("../utils/toFunctionName");
|
||||
|
||||
let code = `// NOTE: This file is autogenerated. Do not modify.
|
||||
// See scripts/generators/typescript.js for script used.
|
||||
// See packages/babel-types/scripts/generators/typescript.js for script used.
|
||||
|
||||
interface BaseComment {
|
||||
value: string;
|
||||
@ -61,7 +62,7 @@ for (const type in t.NODE_FIELDS) {
|
||||
|
||||
fieldNames.forEach(fieldName => {
|
||||
const field = fields[fieldName];
|
||||
let typeAnnotation = utils.stringifyValidator(field.validate, "");
|
||||
let typeAnnotation = stringifyValidator(field.validate, "");
|
||||
|
||||
if (isNullable(field) && !hasDefault(field)) {
|
||||
typeAnnotation += " | null";
|
||||
@ -97,9 +98,7 @@ for (const type in t.NODE_FIELDS) {
|
||||
// super and import are reserved words in JavaScript
|
||||
if (type !== "Super" && type !== "Import") {
|
||||
lines.push(
|
||||
`export function ${utils.toFunctionName(type)}(${args.join(
|
||||
", "
|
||||
)}): ${type};`
|
||||
`export function ${toFunctionName(type)}(${args.join(", ")}): ${type};`
|
||||
);
|
||||
}
|
||||
}
|
||||
@ -1,7 +1,4 @@
|
||||
exports.stringifyValidator = function stringifyValidator(
|
||||
validator,
|
||||
nodePrefix
|
||||
) {
|
||||
module.exports = function stringifyValidator(validator, nodePrefix) {
|
||||
if (validator === undefined) {
|
||||
return "any";
|
||||
}
|
||||
@ -37,11 +34,6 @@ exports.stringifyValidator = function stringifyValidator(
|
||||
return ["any"];
|
||||
};
|
||||
|
||||
exports.toFunctionName = function toFunctionName(typeName) {
|
||||
const _ = typeName.replace(/^TS/, "ts").replace(/^JSX/, "jsx");
|
||||
return _.slice(0, 1).toLowerCase() + _.slice(1);
|
||||
};
|
||||
|
||||
/**
|
||||
* Heuristic to decide whether or not the given type is a value type (eg. "null")
|
||||
* or a Node type (eg. "Expression").
|
||||
4
packages/babel-types/scripts/utils/toFunctionName.js
Normal file
4
packages/babel-types/scripts/utils/toFunctionName.js
Normal file
@ -0,0 +1,4 @@
|
||||
module.exports = function toFunctionName(typeName) {
|
||||
const _ = typeName.replace(/^TS/, "ts").replace(/^JSX/, "jsx");
|
||||
return _.slice(0, 1).toLowerCase() + _.slice(1);
|
||||
};
|
||||
Loading…
x
Reference in New Issue
Block a user