Skip to content

Commit

Permalink
feat: V8IntrinsicIdentifier printing
Browse files Browse the repository at this point in the history
  • Loading branch information
JLHwung committed Jul 24, 2019
2 parents 6bba3c9 + 096c337 commit 3c4fd6c
Show file tree
Hide file tree
Showing 9 changed files with 48 additions and 2 deletions.
5 changes: 5 additions & 0 deletions packages/babel-generator/src/generators/expressions.js
Expand Up @@ -264,3 +264,8 @@ export function PrivateName(node: Object) {
this.token("#");
this.print(node.id, node);
}

export function V8IntrinsicIdentifier(node: Object) {
this.token("%");
this.word(node.name);
}
@@ -0,0 +1 @@
%DebugPrint(foo);
@@ -0,0 +1,3 @@
{
"plugins": ["v8intrinsic"]
}
@@ -0,0 +1 @@
%DebugPrint(foo);
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
13 changes: 12 additions & 1 deletion packages/babel-types/src/definitions/misc.js
@@ -1,5 +1,9 @@
// @flow
import defineType, { assertNodeType, assertOneOf } from "./utils";
import defineType, {
assertNodeType,
assertOneOf,
assertValueType,
} from "./utils";
import { PLACEHOLDERS } from "./placeholders";

defineType("Noop", {
Expand All @@ -19,3 +23,10 @@ defineType("Placeholder", {
},
},
});

defineType("V8IntrinsicIdentifier", {
builder: ["name"],
fields: {
name: assertValueType("string"),
},
});
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 3c4fd6c

Please sign in to comment.