Parse class static block (#12079)
Co-authored-by: Brian Ng <bng412@gmail.com>
This commit is contained in:
committed by
Nicolò Ribaudo
parent
6830c90ac9
commit
3ccca88178
@@ -803,6 +803,9 @@ export function assertTupleExpression(node: Object, opts?: Object = {}): void {
|
||||
export function assertDecimalLiteral(node: Object, opts?: Object = {}): void {
|
||||
assert("DecimalLiteral", node, opts);
|
||||
}
|
||||
export function assertStaticBlock(node: Object, opts?: Object = {}): void {
|
||||
assert("StaticBlock", node, opts);
|
||||
}
|
||||
export function assertTSParameterProperty(
|
||||
node: Object,
|
||||
opts?: Object = {},
|
||||
|
||||
@@ -734,6 +734,10 @@ export function decimalLiteral(...args: Array<any>): Object {
|
||||
return builder("DecimalLiteral", ...args);
|
||||
}
|
||||
export { decimalLiteral as DecimalLiteral };
|
||||
export function staticBlock(...args: Array<any>): Object {
|
||||
return builder("StaticBlock", ...args);
|
||||
}
|
||||
export { staticBlock as StaticBlock };
|
||||
export function tsParameterProperty(...args: Array<any>): Object {
|
||||
return builder("TSParameterProperty", ...args);
|
||||
}
|
||||
|
||||
@@ -245,3 +245,17 @@ defineType("DecimalLiteral", {
|
||||
},
|
||||
aliases: ["Expression", "Pureish", "Literal", "Immutable"],
|
||||
});
|
||||
|
||||
// https://github.com/tc39/proposal-class-static-block
|
||||
defineType("StaticBlock", {
|
||||
visitor: ["body"],
|
||||
fields: {
|
||||
body: {
|
||||
validate: chain(
|
||||
assertValueType("array"),
|
||||
assertEach(assertNodeType("Statement")),
|
||||
),
|
||||
},
|
||||
},
|
||||
aliases: ["Scopable", "BlockParent"],
|
||||
});
|
||||
|
||||
@@ -2587,6 +2587,20 @@ export function isDecimalLiteral(node: ?Object, opts?: Object): boolean {
|
||||
|
||||
return false;
|
||||
}
|
||||
export function isStaticBlock(node: ?Object, opts?: Object): boolean {
|
||||
if (!node) return false;
|
||||
|
||||
const nodeType = node.type;
|
||||
if (nodeType === "StaticBlock") {
|
||||
if (typeof opts === "undefined") {
|
||||
return true;
|
||||
} else {
|
||||
return shallowEqual(node, opts);
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
export function isTSParameterProperty(node: ?Object, opts?: Object): boolean {
|
||||
if (!node) return false;
|
||||
|
||||
@@ -3605,6 +3619,7 @@ export function isScopable(node: ?Object, opts?: Object): boolean {
|
||||
"ForOfStatement" === nodeType ||
|
||||
"ClassMethod" === nodeType ||
|
||||
"ClassPrivateMethod" === nodeType ||
|
||||
"StaticBlock" === nodeType ||
|
||||
"TSModuleBlock" === nodeType ||
|
||||
(nodeType === "Placeholder" && "BlockStatement" === node.expectedNode)
|
||||
) {
|
||||
@@ -3638,6 +3653,7 @@ export function isBlockParent(node: ?Object, opts?: Object): boolean {
|
||||
"ForOfStatement" === nodeType ||
|
||||
"ClassMethod" === nodeType ||
|
||||
"ClassPrivateMethod" === nodeType ||
|
||||
"StaticBlock" === nodeType ||
|
||||
"TSModuleBlock" === nodeType ||
|
||||
(nodeType === "Placeholder" && "BlockStatement" === node.expectedNode)
|
||||
) {
|
||||
|
||||
Reference in New Issue
Block a user