Skip to content

Commit

Permalink
Add generated type helpers
Browse files Browse the repository at this point in the history
  • Loading branch information
jridgewell committed Jul 24, 2019
1 parent 5845c1c commit 096c337
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 1 deletion.
3 changes: 2 additions & 1 deletion packages/babel-types/scripts/utils/formatBuilderName.js
Expand Up @@ -5,5 +5,6 @@ const toLowerCase = Function.call.bind("".toLowerCase);
module.exports = function formatBuilderName(type) {
// FunctionExpression -> functionExpression
// JSXIdentifier -> jsxIdentifier
return type.replace(/^([A-Z](?=[a-z])|[A-Z]+(?=[A-Z]))/, toLowerCase);
// V8IntrinsicIdentifier -> v8IntrinsicIdentifier
return type.replace(/^([A-Z](?=[a-z0-9])|[A-Z]+(?=[A-Z]))/, toLowerCase);
};
6 changes: 6 additions & 0 deletions packages/babel-types/src/asserts/generated/index.js
Expand Up @@ -663,6 +663,12 @@ export function assertNoop(node: Object, opts?: Object = {}): void {
export function assertPlaceholder(node: Object, opts?: Object = {}): void {
assert("Placeholder", node, opts);
}
export function assertV8IntrinsicIdentifier(
node: Object,
opts?: Object = {},
): void {
assert("V8IntrinsicIdentifier", node, opts);
}
export function assertArgumentPlaceholder(
node: Object,
opts?: Object = {},
Expand Down
4 changes: 4 additions & 0 deletions packages/babel-types/src/builders/generated/index.js
Expand Up @@ -600,6 +600,10 @@ export function Placeholder(...args: Array<any>): Object {
return builder("Placeholder", ...args);
}
export { Placeholder as placeholder };
export function V8IntrinsicIdentifier(...args: Array<any>): Object {
return builder("V8IntrinsicIdentifier", ...args);
}
export { V8IntrinsicIdentifier as v8IntrinsicIdentifier };
export function ArgumentPlaceholder(...args: Array<any>): Object {
return builder("ArgumentPlaceholder", ...args);
}
Expand Down
14 changes: 14 additions & 0 deletions packages/babel-types/src/validators/generated/index.js
Expand Up @@ -2107,6 +2107,20 @@ export function isPlaceholder(node: ?Object, opts?: Object): boolean {

return false;
}
export function isV8IntrinsicIdentifier(node: ?Object, opts?: Object): boolean {
if (!node) return false;

const nodeType = node.type;
if (nodeType === "V8IntrinsicIdentifier") {
if (typeof opts === "undefined") {
return true;
} else {
return shallowEqual(node, opts);
}
}

return false;
}
export function isArgumentPlaceholder(node: ?Object, opts?: Object): boolean {
if (!node) return false;

Expand Down

0 comments on commit 096c337

Please sign in to comment.