mirror of
https://github.com/denoland/deno.git
synced 2025-01-21 21:50:00 -05:00
more nodes
This commit is contained in:
parent
8e56216adf
commit
17ad68bb53
4 changed files with 67 additions and 4 deletions
|
@ -147,6 +147,8 @@ const Flags = {
|
||||||
UpdatePrefix: 0b000000001,
|
UpdatePrefix: 0b000000001,
|
||||||
UpdatePlusPlus: 0b000000010,
|
UpdatePlusPlus: 0b000000010,
|
||||||
UpdateMinusMinus: 0b000000100,
|
UpdateMinusMinus: 0b000000100,
|
||||||
|
|
||||||
|
YieldDelegate: 1,
|
||||||
};
|
};
|
||||||
|
|
||||||
// Keep in sync with Rust
|
// Keep in sync with Rust
|
||||||
|
@ -221,7 +223,7 @@ const AstType = {
|
||||||
TaggedTemplateExpression: 57,
|
TaggedTemplateExpression: 57,
|
||||||
ArrowFunctionExpression: 58,
|
ArrowFunctionExpression: 58,
|
||||||
ClassExpr: 59,
|
ClassExpr: 59,
|
||||||
Yield: 60,
|
YieldExpression: 60,
|
||||||
MetaProperty: 61,
|
MetaProperty: 61,
|
||||||
AwaitExpression: 62,
|
AwaitExpression: 62,
|
||||||
LogicalExpression: 63,
|
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
|
// Literals
|
||||||
|
|
||||||
/** @implements {Deno.BooleanLiteral} */
|
/** @implements {Deno.BooleanLiteral} */
|
||||||
|
@ -3013,6 +3048,11 @@ function createAstNode(ctx, id) {
|
||||||
const exprId = readU32(buf, offset + 1);
|
const exprId = readU32(buf, offset + 1);
|
||||||
return new UpdateExpression(ctx, parentId, range, flags, exprId);
|
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
|
// Literals
|
||||||
case AstType.BooleanLiteral: {
|
case AstType.BooleanLiteral: {
|
||||||
|
@ -3484,7 +3524,8 @@ function traverseInner(ctx, visitTypes, visitor, id) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
case AstType.UnaryExpression:
|
case AstType.UnaryExpression:
|
||||||
case AstType.UpdateExpression: {
|
case AstType.UpdateExpression:
|
||||||
|
case AstType.YieldExpression: {
|
||||||
// Skip flags
|
// Skip flags
|
||||||
offset += 1;
|
offset += 1;
|
||||||
|
|
||||||
|
|
|
@ -88,7 +88,7 @@ enum AstNode {
|
||||||
TaggedTpl,
|
TaggedTpl,
|
||||||
ArrowFunctionExpression,
|
ArrowFunctionExpression,
|
||||||
ClassExpr,
|
ClassExpr,
|
||||||
Yield,
|
YieldExpression,
|
||||||
MetaProp,
|
MetaProp,
|
||||||
AwaitExpression,
|
AwaitExpression,
|
||||||
LogicalExpression,
|
LogicalExpression,
|
||||||
|
@ -241,6 +241,8 @@ enum Flag {
|
||||||
UpdatePrefix,
|
UpdatePrefix,
|
||||||
UpdatePlusPlus,
|
UpdatePlusPlus,
|
||||||
UpdateMinusMinus,
|
UpdateMinusMinus,
|
||||||
|
|
||||||
|
YieldDelegate,
|
||||||
}
|
}
|
||||||
|
|
||||||
fn assign_op_to_flag(m: AssignOp) -> u8 {
|
fn assign_op_to_flag(m: AssignOp) -> u8 {
|
||||||
|
@ -322,6 +324,8 @@ impl From<Flag> for u8 {
|
||||||
Flag::UpdatePrefix => 0b000000001,
|
Flag::UpdatePrefix => 0b000000001,
|
||||||
Flag::UpdatePlusPlus => 0b000000010,
|
Flag::UpdatePlusPlus => 0b000000010,
|
||||||
Flag::UpdateMinusMinus => 0b000000100,
|
Flag::UpdateMinusMinus => 0b000000100,
|
||||||
|
|
||||||
|
Flag::YieldDelegate => 1,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1592,7 +1596,13 @@ fn serialize_expr(
|
||||||
id
|
id
|
||||||
}
|
}
|
||||||
Expr::Yield(node) => {
|
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);
|
let offset = ctx.reserve_child_ids(1);
|
||||||
|
|
||||||
if let Some(arg) = &node.arg {
|
if let Some(arg) = &node.arg {
|
||||||
|
|
7
cli/tsc/dts/lib.deno.ns.d.ts
vendored
7
cli/tsc/dts/lib.deno.ns.d.ts
vendored
|
@ -6438,6 +6438,12 @@ declare namespace Deno {
|
||||||
argument: Expression;
|
argument: Expression;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export interface YieldExpression extends BaseNode {
|
||||||
|
type: "YieldExpression";
|
||||||
|
argument: Expression;
|
||||||
|
delegate: boolean;
|
||||||
|
}
|
||||||
|
|
||||||
// Literals
|
// Literals
|
||||||
export interface BigIntLiteral extends BaseNode {
|
export interface BigIntLiteral extends BaseNode {
|
||||||
type: "BigIntLiteral";
|
type: "BigIntLiteral";
|
||||||
|
@ -6499,6 +6505,7 @@ declare namespace Deno {
|
||||||
| UnaryExpression
|
| UnaryExpression
|
||||||
| UpdateExpression
|
| UpdateExpression
|
||||||
| Literal
|
| Literal
|
||||||
|
| YieldExpression
|
||||||
// JSX
|
// JSX
|
||||||
| JSXElement
|
| JSXElement
|
||||||
| JSXFragment;
|
| JSXFragment;
|
||||||
|
|
|
@ -12,6 +12,11 @@ function foo5({ a = 2 }) {}
|
||||||
function foo6([a, b]) {}
|
function foo6([a, b]) {}
|
||||||
function foo7<T, U>(a: T, b: U) {}
|
function foo7<T, U>(a: T, b: U) {}
|
||||||
|
|
||||||
|
async function foo() {}
|
||||||
|
async function* foo() {
|
||||||
|
yield 2;
|
||||||
|
}
|
||||||
|
|
||||||
export const e = 2;
|
export const e = 2;
|
||||||
export let e2 = 2;
|
export let e2 = 2;
|
||||||
export function e3() {}
|
export function e3() {}
|
||||||
|
|
Loading…
Add table
Reference in a new issue