1
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2025-01-21 21:50:00 -05:00

more nodes

This commit is contained in:
Marvin Hagemeister 2024-12-11 17:47:46 +01:00
parent 8e56216adf
commit 17ad68bb53
4 changed files with 67 additions and 4 deletions

View file

@ -147,6 +147,8 @@ const Flags = {
UpdatePrefix: 0b000000001,
UpdatePlusPlus: 0b000000010,
UpdateMinusMinus: 0b000000100,
YieldDelegate: 1,
};
// Keep in sync with Rust
@ -221,7 +223,7 @@ const AstType = {
TaggedTemplateExpression: 57,
ArrowFunctionExpression: 58,
ClassExpr: 59,
Yield: 60,
YieldExpression: 60,
MetaProperty: 61,
AwaitExpression: 62,
LogicalExpression: 63,
@ -2001,6 +2003,39 @@ function getUnaryOperator(n) {
}
}
/** @implements {Deno.YieldExpression} */
class YieldExpression extends BaseNode {
type = /** @type {const} */ ("YieldExpression");
range;
get argument() {
return /** @type {Deno.Expression} */ (createAstNode(
this.#ctx,
this.#argId,
));
}
delegate = false;
#ctx;
#argId;
/**
* @param {AstContext} ctx
* @param {number} parentId
* @param {Deno.Range} range
* @param {number} flags
* @param {number} argId
*/
constructor(ctx, parentId, range, flags, argId) {
super(ctx, parentId);
this.#ctx = ctx;
this.#argId = argId;
this.range = range;
this.delegate = (flags & Flags.YieldDelegate) !== 0;
}
}
// Literals
/** @implements {Deno.BooleanLiteral} */
@ -3013,6 +3048,11 @@ function createAstNode(ctx, id) {
const exprId = readU32(buf, offset + 1);
return new UpdateExpression(ctx, parentId, range, flags, exprId);
}
case AstType.YieldExpression: {
const flags = buf[offset];
const exprId = readU32(buf, offset + 1);
return new YieldExpression(ctx, parentId, range, flags, exprId);
}
// Literals
case AstType.BooleanLiteral: {
@ -3484,7 +3524,8 @@ function traverseInner(ctx, visitTypes, visitor, id) {
return;
}
case AstType.UnaryExpression:
case AstType.UpdateExpression: {
case AstType.UpdateExpression:
case AstType.YieldExpression: {
// Skip flags
offset += 1;

View file

@ -88,7 +88,7 @@ enum AstNode {
TaggedTpl,
ArrowFunctionExpression,
ClassExpr,
Yield,
YieldExpression,
MetaProp,
AwaitExpression,
LogicalExpression,
@ -241,6 +241,8 @@ enum Flag {
UpdatePrefix,
UpdatePlusPlus,
UpdateMinusMinus,
YieldDelegate,
}
fn assign_op_to_flag(m: AssignOp) -> u8 {
@ -322,6 +324,8 @@ impl From<Flag> for u8 {
Flag::UpdatePrefix => 0b000000001,
Flag::UpdatePlusPlus => 0b000000010,
Flag::UpdateMinusMinus => 0b000000100,
Flag::YieldDelegate => 1,
}
}
}
@ -1592,7 +1596,13 @@ fn serialize_expr(
id
}
Expr::Yield(node) => {
let id = ctx.push_node(AstNode::Yield, parent_id, &node.span);
let id = ctx.push_node(AstNode::YieldExpression, parent_id, &node.span);
let mut flags = FlagValue::new();
if node.delegate {
flags.set(Flag::YieldDelegate)
}
ctx.result.push(flags.0);
let offset = ctx.reserve_child_ids(1);
if let Some(arg) = &node.arg {

View file

@ -6438,6 +6438,12 @@ declare namespace Deno {
argument: Expression;
}
export interface YieldExpression extends BaseNode {
type: "YieldExpression";
argument: Expression;
delegate: boolean;
}
// Literals
export interface BigIntLiteral extends BaseNode {
type: "BigIntLiteral";
@ -6499,6 +6505,7 @@ declare namespace Deno {
| UnaryExpression
| UpdateExpression
| Literal
| YieldExpression
// JSX
| JSXElement
| JSXFragment;

View file

@ -12,6 +12,11 @@ function foo5({ a = 2 }) {}
function foo6([a, b]) {}
function foo7<T, U>(a: T, b: U) {}
async function foo() {}
async function* foo() {
yield 2;
}
export const e = 2;
export let e2 = 2;
export function e3() {}