Parse JS Module Blocks proposal (#12469)
This commit is contained in:
@@ -1088,6 +1088,12 @@ export function assertStaticBlock(
|
||||
): asserts node is t.StaticBlock {
|
||||
assert("StaticBlock", node, opts);
|
||||
}
|
||||
export function assertModuleExpression(
|
||||
node: object | null | undefined,
|
||||
opts?: object | null,
|
||||
): asserts node is t.ModuleExpression {
|
||||
assert("ModuleExpression", node, opts);
|
||||
}
|
||||
export function assertTSParameterProperty(
|
||||
node: object | null | undefined,
|
||||
opts?: object | null,
|
||||
|
||||
@@ -182,6 +182,7 @@ export type Node =
|
||||
| Method
|
||||
| MixedTypeAnnotation
|
||||
| ModuleDeclaration
|
||||
| ModuleExpression
|
||||
| ModuleSpecifier
|
||||
| NewExpression
|
||||
| Noop
|
||||
@@ -1621,6 +1622,11 @@ export interface StaticBlock extends BaseNode {
|
||||
body: Array<Statement>;
|
||||
}
|
||||
|
||||
export interface ModuleExpression extends BaseNode {
|
||||
type: "ModuleExpression";
|
||||
body: Program;
|
||||
}
|
||||
|
||||
export interface TSParameterProperty extends BaseNode {
|
||||
type: "TSParameterProperty";
|
||||
parameter: Identifier | AssignmentPattern;
|
||||
@@ -2046,6 +2052,7 @@ export type Expression =
|
||||
| RecordExpression
|
||||
| TupleExpression
|
||||
| DecimalLiteral
|
||||
| ModuleExpression
|
||||
| TSAsExpression
|
||||
| TSTypeAssertion
|
||||
| TSNonNullExpression;
|
||||
|
||||
@@ -1066,6 +1066,9 @@ export function decimalLiteral(value: string): t.DecimalLiteral {
|
||||
export function staticBlock(body: Array<t.Statement>): t.StaticBlock {
|
||||
return builder("StaticBlock", ...arguments);
|
||||
}
|
||||
export function moduleExpression(body: t.Program): t.ModuleExpression {
|
||||
return builder("ModuleExpression", ...arguments);
|
||||
}
|
||||
export function tsParameterProperty(
|
||||
parameter: t.Identifier | t.AssignmentPattern,
|
||||
): t.TSParameterProperty {
|
||||
|
||||
@@ -188,6 +188,7 @@ export {
|
||||
tupleExpression as TupleExpression,
|
||||
decimalLiteral as DecimalLiteral,
|
||||
staticBlock as StaticBlock,
|
||||
moduleExpression as ModuleExpression,
|
||||
tsParameterProperty as TSParameterProperty,
|
||||
tsDeclareFunction as TSDeclareFunction,
|
||||
tsDeclareMethod as TSDeclareMethod,
|
||||
|
||||
@@ -262,3 +262,14 @@ defineType("StaticBlock", {
|
||||
},
|
||||
aliases: ["Scopable", "BlockParent"],
|
||||
});
|
||||
|
||||
// https://github.com/tc39/proposal-js-module-blocks
|
||||
defineType("ModuleExpression", {
|
||||
visitor: ["body"],
|
||||
fields: {
|
||||
body: {
|
||||
validate: assertNodeType("Program"),
|
||||
},
|
||||
},
|
||||
aliases: ["Expression"],
|
||||
});
|
||||
|
||||
@@ -3048,6 +3048,23 @@ export function isStaticBlock(
|
||||
|
||||
return false;
|
||||
}
|
||||
export function isModuleExpression(
|
||||
node: object | null | undefined,
|
||||
opts?: object | null,
|
||||
): node is t.ModuleExpression {
|
||||
if (!node) return false;
|
||||
|
||||
const nodeType = (node as t.Node).type;
|
||||
if (nodeType === "ModuleExpression") {
|
||||
if (typeof opts === "undefined") {
|
||||
return true;
|
||||
} else {
|
||||
return shallowEqual(node, opts);
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
export function isTSParameterProperty(
|
||||
node: object | null | undefined,
|
||||
opts?: object | null,
|
||||
@@ -4169,6 +4186,7 @@ export function isExpression(
|
||||
"RecordExpression" === nodeType ||
|
||||
"TupleExpression" === nodeType ||
|
||||
"DecimalLiteral" === nodeType ||
|
||||
"ModuleExpression" === nodeType ||
|
||||
"TSAsExpression" === nodeType ||
|
||||
"TSTypeAssertion" === nodeType ||
|
||||
"TSNonNullExpression" === nodeType ||
|
||||
|
||||
Reference in New Issue
Block a user