Skip to content

Commit

Permalink
optimize: skip validateNode when builder keys are empty
Browse files Browse the repository at this point in the history
  • Loading branch information
JLHwung committed May 3, 2022
1 parent 055933c commit e77587e
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 40 deletions.
7 changes: 6 additions & 1 deletion packages/babel-types/scripts/generators/builders.js
Expand Up @@ -126,7 +126,12 @@ import type * as t from "../..";
", "
)}) {\n const node: t.${type} = {\n${objectFields
.map(([k, v]) => (k === v ? ` ${k},` : ` ${k}: ${v},`))
.join("\n")} };\n validateNode(node);\n return node;\n}\n`;
.join("\n")} };`;

if (builderNames.length > 0) {
output += `\n validateNode(node);`;
}
output += `\n return node;\n}\n`;

if (formatedBuilderNameLocal !== formatedBuilderName) {
output += `export { ${formatedBuilderNameLocal} as ${formatedBuilderName} };\n`;
Expand Down
39 changes: 0 additions & 39 deletions packages/babel-types/src/builders/generated/index.ts
Expand Up @@ -166,7 +166,6 @@ export function debuggerStatement() {
const node: t.DebuggerStatement = {
type: "DebuggerStatement",
};
validateNode(node);
return node;
}
export function doWhileStatement(test: t.Expression, body: t.Statement) {
Expand All @@ -182,7 +181,6 @@ export function emptyStatement() {
const node: t.EmptyStatement = {
type: "EmptyStatement",
};
validateNode(node);
return node;
}
export function expressionStatement(expression: t.Expression) {
Expand Down Expand Up @@ -324,7 +322,6 @@ export function nullLiteral() {
const node: t.NullLiteral = {
type: "NullLiteral",
};
validateNode(node);
return node;
}
export function booleanLiteral(value: boolean) {
Expand Down Expand Up @@ -515,7 +512,6 @@ export function thisExpression() {
const node: t.ThisExpression = {
type: "ThisExpression",
};
validateNode(node);
return node;
}
export function throwStatement(argument: t.Expression) {
Expand Down Expand Up @@ -868,7 +864,6 @@ function _super() {
const node: t.Super = {
type: "Super",
};
validateNode(node);
return node;
}
export { _super as super };
Expand Down Expand Up @@ -932,7 +927,6 @@ function _import() {
const node: t.Import = {
type: "Import",
};
validateNode(node);
return node;
}
export { _import as import };
Expand Down Expand Up @@ -1085,7 +1079,6 @@ export function anyTypeAnnotation() {
const node: t.AnyTypeAnnotation = {
type: "AnyTypeAnnotation",
};
validateNode(node);
return node;
}
export function arrayTypeAnnotation(elementType: t.FlowType) {
Expand All @@ -1100,7 +1093,6 @@ export function booleanTypeAnnotation() {
const node: t.BooleanTypeAnnotation = {
type: "BooleanTypeAnnotation",
};
validateNode(node);
return node;
}
export function booleanLiteralTypeAnnotation(value: boolean) {
Expand All @@ -1115,7 +1107,6 @@ export function nullLiteralTypeAnnotation() {
const node: t.NullLiteralTypeAnnotation = {
type: "NullLiteralTypeAnnotation",
};
validateNode(node);
return node;
}
export function classImplements(
Expand Down Expand Up @@ -1264,7 +1255,6 @@ export function existsTypeAnnotation() {
const node: t.ExistsTypeAnnotation = {
type: "ExistsTypeAnnotation",
};
validateNode(node);
return node;
}
export function functionTypeAnnotation(
Expand Down Expand Up @@ -1311,7 +1301,6 @@ export function inferredPredicate() {
const node: t.InferredPredicate = {
type: "InferredPredicate",
};
validateNode(node);
return node;
}
export function interfaceExtends(
Expand Down Expand Up @@ -1366,14 +1355,12 @@ export function mixedTypeAnnotation() {
const node: t.MixedTypeAnnotation = {
type: "MixedTypeAnnotation",
};
validateNode(node);
return node;
}
export function emptyTypeAnnotation() {
const node: t.EmptyTypeAnnotation = {
type: "EmptyTypeAnnotation",
};
validateNode(node);
return node;
}
export function nullableTypeAnnotation(typeAnnotation: t.FlowType) {
Expand All @@ -1396,7 +1383,6 @@ export function numberTypeAnnotation() {
const node: t.NumberTypeAnnotation = {
type: "NumberTypeAnnotation",
};
validateNode(node);
return node;
}
export function objectTypeAnnotation(
Expand Down Expand Up @@ -1528,21 +1514,18 @@ export function stringTypeAnnotation() {
const node: t.StringTypeAnnotation = {
type: "StringTypeAnnotation",
};
validateNode(node);
return node;
}
export function symbolTypeAnnotation() {
const node: t.SymbolTypeAnnotation = {
type: "SymbolTypeAnnotation",
};
validateNode(node);
return node;
}
export function thisTypeAnnotation() {
const node: t.ThisTypeAnnotation = {
type: "ThisTypeAnnotation",
};
validateNode(node);
return node;
}
export function tupleTypeAnnotation(types: Array<t.FlowType>) {
Expand Down Expand Up @@ -1646,7 +1629,6 @@ export function voidTypeAnnotation() {
const node: t.VoidTypeAnnotation = {
type: "VoidTypeAnnotation",
};
validateNode(node);
return node;
}
export function enumDeclaration(
Expand Down Expand Up @@ -1822,7 +1804,6 @@ export function jsxEmptyExpression() {
const node: t.JSXEmptyExpression = {
type: "JSXEmptyExpression",
};
validateNode(node);
return node;
}
export { jsxEmptyExpression as jSXEmptyExpression };
Expand Down Expand Up @@ -1939,23 +1920,20 @@ export function jsxOpeningFragment() {
const node: t.JSXOpeningFragment = {
type: "JSXOpeningFragment",
};
validateNode(node);
return node;
}
export { jsxOpeningFragment as jSXOpeningFragment };
export function jsxClosingFragment() {
const node: t.JSXClosingFragment = {
type: "JSXClosingFragment",
};
validateNode(node);
return node;
}
export { jsxClosingFragment as jSXClosingFragment };
export function noop() {
const node: t.Noop = {
type: "Noop",
};
validateNode(node);
return node;
}
export function placeholder(
Expand Down Expand Up @@ -1990,7 +1968,6 @@ export function argumentPlaceholder() {
const node: t.ArgumentPlaceholder = {
type: "ArgumentPlaceholder",
};
validateNode(node);
return node;
}
export function bindExpression(object: t.Expression, callee: t.Expression) {
Expand Down Expand Up @@ -2079,7 +2056,6 @@ export function topicReference() {
const node: t.TopicReference = {
type: "TopicReference",
};
validateNode(node);
return node;
}
export function pipelineTopicExpression(expression: t.Expression) {
Expand All @@ -2102,7 +2078,6 @@ export function pipelinePrimaryTopicReference() {
const node: t.PipelinePrimaryTopicReference = {
type: "PipelinePrimaryTopicReference",
};
validateNode(node);
return node;
}
export function tsParameterProperty(
Expand Down Expand Up @@ -2253,111 +2228,97 @@ export function tsAnyKeyword() {
const node: t.TSAnyKeyword = {
type: "TSAnyKeyword",
};
validateNode(node);
return node;
}
export { tsAnyKeyword as tSAnyKeyword };
export function tsBooleanKeyword() {
const node: t.TSBooleanKeyword = {
type: "TSBooleanKeyword",
};
validateNode(node);
return node;
}
export { tsBooleanKeyword as tSBooleanKeyword };
export function tsBigIntKeyword() {
const node: t.TSBigIntKeyword = {
type: "TSBigIntKeyword",
};
validateNode(node);
return node;
}
export { tsBigIntKeyword as tSBigIntKeyword };
export function tsIntrinsicKeyword() {
const node: t.TSIntrinsicKeyword = {
type: "TSIntrinsicKeyword",
};
validateNode(node);
return node;
}
export { tsIntrinsicKeyword as tSIntrinsicKeyword };
export function tsNeverKeyword() {
const node: t.TSNeverKeyword = {
type: "TSNeverKeyword",
};
validateNode(node);
return node;
}
export { tsNeverKeyword as tSNeverKeyword };
export function tsNullKeyword() {
const node: t.TSNullKeyword = {
type: "TSNullKeyword",
};
validateNode(node);
return node;
}
export { tsNullKeyword as tSNullKeyword };
export function tsNumberKeyword() {
const node: t.TSNumberKeyword = {
type: "TSNumberKeyword",
};
validateNode(node);
return node;
}
export { tsNumberKeyword as tSNumberKeyword };
export function tsObjectKeyword() {
const node: t.TSObjectKeyword = {
type: "TSObjectKeyword",
};
validateNode(node);
return node;
}
export { tsObjectKeyword as tSObjectKeyword };
export function tsStringKeyword() {
const node: t.TSStringKeyword = {
type: "TSStringKeyword",
};
validateNode(node);
return node;
}
export { tsStringKeyword as tSStringKeyword };
export function tsSymbolKeyword() {
const node: t.TSSymbolKeyword = {
type: "TSSymbolKeyword",
};
validateNode(node);
return node;
}
export { tsSymbolKeyword as tSSymbolKeyword };
export function tsUndefinedKeyword() {
const node: t.TSUndefinedKeyword = {
type: "TSUndefinedKeyword",
};
validateNode(node);
return node;
}
export { tsUndefinedKeyword as tSUndefinedKeyword };
export function tsUnknownKeyword() {
const node: t.TSUnknownKeyword = {
type: "TSUnknownKeyword",
};
validateNode(node);
return node;
}
export { tsUnknownKeyword as tSUnknownKeyword };
export function tsVoidKeyword() {
const node: t.TSVoidKeyword = {
type: "TSVoidKeyword",
};
validateNode(node);
return node;
}
export { tsVoidKeyword as tSVoidKeyword };
export function tsThisType() {
const node: t.TSThisType = {
type: "TSThisType",
};
validateNode(node);
return node;
}
export { tsThisType as tSThisType };
Expand Down

0 comments on commit e77587e

Please sign in to comment.