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