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
7c7a888fa6
commit
8f104313ff
3 changed files with 264 additions and 82 deletions
|
@ -95,7 +95,9 @@ const Flags = {
|
||||||
FnAsync: 0b00000001,
|
FnAsync: 0b00000001,
|
||||||
FnGenerator: 0b00000010,
|
FnGenerator: 0b00000010,
|
||||||
FnDeclare: 0b00000100,
|
FnDeclare: 0b00000100,
|
||||||
|
FnOptional: 0b00001000,
|
||||||
MemberComputed: 0b00000001,
|
MemberComputed: 0b00000001,
|
||||||
|
MemberOptional: 0b00000010,
|
||||||
PropShorthand: 0b00000001,
|
PropShorthand: 0b00000001,
|
||||||
PropComputed: 0b00000010,
|
PropComputed: 0b00000010,
|
||||||
PropGetter: 0b00000100,
|
PropGetter: 0b00000100,
|
||||||
|
@ -243,7 +245,7 @@ const AstType = {
|
||||||
TSInstantiation: 68,
|
TSInstantiation: 68,
|
||||||
TSSatisfies: 69,
|
TSSatisfies: 69,
|
||||||
PrivateIdentifier: 70,
|
PrivateIdentifier: 70,
|
||||||
OptChain: 71,
|
ChainExpression: 71,
|
||||||
|
|
||||||
StringLiteral: 72,
|
StringLiteral: 72,
|
||||||
BooleanLiteral: 73,
|
BooleanLiteral: 73,
|
||||||
|
@ -1519,7 +1521,7 @@ class CallExpression extends BaseNode {
|
||||||
return createAstNode(this.#ctx, this.#typeArgId);
|
return createAstNode(this.#ctx, this.#typeArgId);
|
||||||
}
|
}
|
||||||
|
|
||||||
optional = false; // FIXME
|
optional = false;
|
||||||
|
|
||||||
#ctx;
|
#ctx;
|
||||||
#calleeId;
|
#calleeId;
|
||||||
|
@ -1530,13 +1532,15 @@ class CallExpression extends BaseNode {
|
||||||
* @param {AstContext} ctx
|
* @param {AstContext} ctx
|
||||||
* @param {number} parentId
|
* @param {number} parentId
|
||||||
* @param {Deno.Range} range
|
* @param {Deno.Range} range
|
||||||
|
* @param {number} flags
|
||||||
* @param {number} calleeId
|
* @param {number} calleeId
|
||||||
* @param {number} typeArgId
|
* @param {number} typeArgId
|
||||||
* @param {number[]} argumentIds
|
* @param {number[]} argumentIds
|
||||||
*/
|
*/
|
||||||
constructor(ctx, parentId, range, calleeId, typeArgId, argumentIds) {
|
constructor(ctx, parentId, range, flags, calleeId, typeArgId, argumentIds) {
|
||||||
super(ctx, parentId);
|
super(ctx, parentId);
|
||||||
|
|
||||||
|
this.optional = (flags & Flags.FnOptional) !== 0;
|
||||||
this.#ctx = ctx;
|
this.#ctx = ctx;
|
||||||
this.#calleeId = calleeId;
|
this.#calleeId = calleeId;
|
||||||
this.range = range;
|
this.range = range;
|
||||||
|
@ -1546,19 +1550,28 @@ class CallExpression extends BaseNode {
|
||||||
}
|
}
|
||||||
|
|
||||||
/** @implements {Deno.ChainExpression} */
|
/** @implements {Deno.ChainExpression} */
|
||||||
class ChainExpression {
|
class ChainExpression extends BaseNode {
|
||||||
type = /** @type {const} */ ("ChainExpression");
|
type = /** @type {const} */ ("ChainExpression");
|
||||||
range;
|
range;
|
||||||
|
|
||||||
|
get expression() {
|
||||||
|
return /** @type {*} */ (createAstNode(this.#ctx, this.#exprId));
|
||||||
|
}
|
||||||
|
|
||||||
#ctx;
|
#ctx;
|
||||||
|
#exprId;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param {AstContext} ctx
|
* @param {AstContext} ctx
|
||||||
|
* @param {number} parentId
|
||||||
* @param {Deno.Range} range
|
* @param {Deno.Range} range
|
||||||
|
* @param {number} exprId
|
||||||
*/
|
*/
|
||||||
constructor(ctx, range) {
|
constructor(ctx, parentId, range, exprId) {
|
||||||
|
super(ctx, parentId);
|
||||||
this.#ctx = ctx;
|
this.#ctx = ctx;
|
||||||
this.range = range;
|
this.range = range;
|
||||||
|
this.#exprId = exprId;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1774,8 +1787,8 @@ class MemberExpression extends BaseNode {
|
||||||
this.#propId,
|
this.#propId,
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
optional = false; // FIXME
|
optional = false;
|
||||||
computed = false; // FIXME
|
computed = false;
|
||||||
|
|
||||||
#ctx;
|
#ctx;
|
||||||
#objId;
|
#objId;
|
||||||
|
@ -1794,6 +1807,7 @@ class MemberExpression extends BaseNode {
|
||||||
|
|
||||||
this.#ctx = ctx;
|
this.#ctx = ctx;
|
||||||
this.computed = (flags & Flags.MemberComputed) !== 0;
|
this.computed = (flags & Flags.MemberComputed) !== 0;
|
||||||
|
this.optional = (flags & Flags.MemberOptional) !== 0;
|
||||||
this.#objId = objId;
|
this.#objId = objId;
|
||||||
this.#propId = propId;
|
this.#propId = propId;
|
||||||
this.range = range;
|
this.range = range;
|
||||||
|
@ -3192,6 +3206,8 @@ function createAstNode(ctx, id) {
|
||||||
return new BinaryExpression(ctx, parentId, range, flags, leftId, rightId);
|
return new BinaryExpression(ctx, parentId, range, flags, leftId, rightId);
|
||||||
}
|
}
|
||||||
case AstType.CallExpression: {
|
case AstType.CallExpression: {
|
||||||
|
const flags = buf[offset];
|
||||||
|
offset += 1;
|
||||||
const calleeId = readU32(buf, offset);
|
const calleeId = readU32(buf, offset);
|
||||||
const typeArgId = readU32(buf, offset + 4);
|
const typeArgId = readU32(buf, offset + 4);
|
||||||
const childIds = readChildIds(buf, offset + 8);
|
const childIds = readChildIds(buf, offset + 8);
|
||||||
|
@ -3199,11 +3215,16 @@ function createAstNode(ctx, id) {
|
||||||
ctx,
|
ctx,
|
||||||
parentId,
|
parentId,
|
||||||
range,
|
range,
|
||||||
|
flags,
|
||||||
calleeId,
|
calleeId,
|
||||||
typeArgId,
|
typeArgId,
|
||||||
childIds,
|
childIds,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
case AstType.ChainExpression: {
|
||||||
|
const argId = readU32(buf, offset);
|
||||||
|
return new ChainExpression(ctx, parentId, range, argId);
|
||||||
|
}
|
||||||
case AstType.ConditionalExpression: {
|
case AstType.ConditionalExpression: {
|
||||||
const testId = readU32(buf, offset);
|
const testId = readU32(buf, offset);
|
||||||
const consId = readU32(buf, offset + 4);
|
const consId = readU32(buf, offset + 4);
|
||||||
|
@ -3735,9 +3756,10 @@ function traverseInner(ctx, visitTypes, visitor, id) {
|
||||||
|
|
||||||
// Expressions
|
// Expressions
|
||||||
case AstType.CallExpression: {
|
case AstType.CallExpression: {
|
||||||
const calleeId = readU32(buf, offset);
|
offset += 1; // skip flags
|
||||||
const typeArgId = readU32(buf, offset + 4);
|
const calleeId = readU32(buf, offset + 1);
|
||||||
const childIds = readChildIds(buf, offset + 8);
|
const typeArgId = readU32(buf, offset + 5);
|
||||||
|
const childIds = readChildIds(buf, offset + 9);
|
||||||
|
|
||||||
traverseInner(ctx, visitTypes, visitor, calleeId);
|
traverseInner(ctx, visitTypes, visitor, calleeId);
|
||||||
traverseInner(ctx, visitTypes, visitor, typeArgId);
|
traverseInner(ctx, visitTypes, visitor, typeArgId);
|
||||||
|
@ -3945,6 +3967,7 @@ function traverseInner(ctx, visitTypes, visitor, id) {
|
||||||
case AstType.AwaitExpression:
|
case AstType.AwaitExpression:
|
||||||
case AstType.BreakStatement:
|
case AstType.BreakStatement:
|
||||||
case AstType.ContinueStatement:
|
case AstType.ContinueStatement:
|
||||||
|
case AstType.ChainExpression:
|
||||||
case AstType.ExpressionStatement:
|
case AstType.ExpressionStatement:
|
||||||
case AstType.JSXClosingElement:
|
case AstType.JSXClosingElement:
|
||||||
case AstType.JSXExpressionContainer:
|
case AstType.JSXExpressionContainer:
|
||||||
|
|
|
@ -6,11 +6,13 @@ use deno_ast::{
|
||||||
Ident, IdentName, JSXAttrName, JSXAttrOrSpread, JSXAttrValue, JSXElement,
|
Ident, IdentName, JSXAttrName, JSXAttrOrSpread, JSXAttrValue, JSXElement,
|
||||||
JSXElementChild, JSXElementName, JSXEmptyExpr, JSXExpr, JSXExprContainer,
|
JSXElementChild, JSXElementName, JSXEmptyExpr, JSXExpr, JSXExprContainer,
|
||||||
JSXFragment, JSXMemberExpr, JSXNamespacedName, JSXObject,
|
JSXFragment, JSXMemberExpr, JSXNamespacedName, JSXObject,
|
||||||
JSXOpeningElement, Lit, MemberProp, ModuleDecl, ModuleExportName,
|
JSXOpeningElement, Lit, MemberExpr, MemberProp, ModuleDecl,
|
||||||
ModuleItem, ObjectPatProp, Param, ParamOrTsParamProp, Pat, Program, Prop,
|
ModuleExportName, ModuleItem, ObjectPatProp, OptChainBase, Param,
|
||||||
PropName, PropOrSpread, SimpleAssignTarget, Stmt, SuperProp, Tpl,
|
ParamOrTsParamProp, Pat, PrivateName, Program, Prop, PropName,
|
||||||
TsEntityName, TsEnumMemberId, TsLit, TsType, TsTypeAnn, TsTypeElement,
|
PropOrSpread, SimpleAssignTarget, Stmt, SuperProp, Tpl, TsEntityName,
|
||||||
TsTypeParam, TsTypeParamDecl, TsUnionOrIntersectionType, VarDeclOrExpr,
|
TsEnumMemberId, TsFnOrConstructorType, TsFnParam, TsLit, TsType,
|
||||||
|
TsTypeAnn, TsTypeElement, TsTypeParam, TsTypeParamDecl, TsTypeQueryExpr,
|
||||||
|
TsUnionOrIntersectionType, VarDeclOrExpr,
|
||||||
},
|
},
|
||||||
common::{Span, Spanned, SyntaxContext, DUMMY_SP},
|
common::{Span, Spanned, SyntaxContext, DUMMY_SP},
|
||||||
},
|
},
|
||||||
|
@ -84,7 +86,7 @@ enum AstNode {
|
||||||
MemberExpression,
|
MemberExpression,
|
||||||
Super,
|
Super,
|
||||||
Cond,
|
Cond,
|
||||||
Call,
|
CallExpression,
|
||||||
New,
|
New,
|
||||||
Paren,
|
Paren,
|
||||||
Seq,
|
Seq,
|
||||||
|
@ -104,7 +106,7 @@ enum AstNode {
|
||||||
TsInstantiation,
|
TsInstantiation,
|
||||||
TsSatisfies,
|
TsSatisfies,
|
||||||
PrivateIdentifier,
|
PrivateIdentifier,
|
||||||
OptChain,
|
ChainExpression,
|
||||||
|
|
||||||
// Literals
|
// Literals
|
||||||
StringLiteral,
|
StringLiteral,
|
||||||
|
@ -161,6 +163,10 @@ enum AstNode {
|
||||||
TSUnionType,
|
TSUnionType,
|
||||||
TSIntersectionType,
|
TSIntersectionType,
|
||||||
TSMappedType,
|
TSMappedType,
|
||||||
|
TSTypeQuery,
|
||||||
|
TSTupleType,
|
||||||
|
TSFunctionType,
|
||||||
|
TsCallSignatureDeclaration,
|
||||||
|
|
||||||
TSAnyKeyword,
|
TSAnyKeyword,
|
||||||
TSBigIntKeyword,
|
TSBigIntKeyword,
|
||||||
|
@ -224,7 +230,9 @@ enum Flag {
|
||||||
FnAsync,
|
FnAsync,
|
||||||
FnGenerator,
|
FnGenerator,
|
||||||
FnDeclare,
|
FnDeclare,
|
||||||
|
FnOptional,
|
||||||
MemberComputed,
|
MemberComputed,
|
||||||
|
MemberOptional,
|
||||||
PropShorthand,
|
PropShorthand,
|
||||||
PropComputed,
|
PropComputed,
|
||||||
PropGetter,
|
PropGetter,
|
||||||
|
@ -324,7 +332,9 @@ impl From<Flag> for u8 {
|
||||||
Flag::FnAsync => 0b00000001,
|
Flag::FnAsync => 0b00000001,
|
||||||
Flag::FnGenerator => 0b00000010,
|
Flag::FnGenerator => 0b00000010,
|
||||||
Flag::FnDeclare => 0b00000100,
|
Flag::FnDeclare => 0b00000100,
|
||||||
|
Flag::FnOptional => 0b00001000,
|
||||||
Flag::MemberComputed => 0b00000001,
|
Flag::MemberComputed => 0b00000001,
|
||||||
|
Flag::MemberOptional => 0b00000010,
|
||||||
Flag::PropShorthand => 0b00000001,
|
Flag::PropShorthand => 0b00000001,
|
||||||
Flag::PropComputed => 0b00000010,
|
Flag::PropComputed => 0b00000010,
|
||||||
Flag::PropGetter => 0b00000100,
|
Flag::PropGetter => 0b00000100,
|
||||||
|
@ -1312,21 +1322,23 @@ fn serialize_expr(
|
||||||
let left_id = match &node.left {
|
let left_id = match &node.left {
|
||||||
AssignTarget::Simple(simple_assign_target) => {
|
AssignTarget::Simple(simple_assign_target) => {
|
||||||
match simple_assign_target {
|
match simple_assign_target {
|
||||||
SimpleAssignTarget::Ident(binding_ident) => {
|
SimpleAssignTarget::Ident(target) => {
|
||||||
serialize_ident(ctx, &binding_ident.id, id)
|
serialize_ident(ctx, &target.id, id)
|
||||||
}
|
}
|
||||||
SimpleAssignTarget::Member(member_expr) => {
|
SimpleAssignTarget::Member(target) => {
|
||||||
serialize_expr(ctx, &Expr::Member(member_expr.clone()), id)
|
serialize_expr(ctx, &Expr::Member(target.clone()), id)
|
||||||
}
|
}
|
||||||
SimpleAssignTarget::SuperProp(super_prop_expr) => todo!(),
|
SimpleAssignTarget::SuperProp(target) => todo!(),
|
||||||
SimpleAssignTarget::Paren(paren_expr) => todo!(),
|
SimpleAssignTarget::Paren(paren_expr) => todo!(),
|
||||||
SimpleAssignTarget::OptChain(opt_chain_expr) => todo!(),
|
SimpleAssignTarget::OptChain(target) => {
|
||||||
|
serialize_expr(ctx, &Expr::OptChain(target.clone()), id)
|
||||||
|
}
|
||||||
SimpleAssignTarget::TsAs(ts_as_expr) => todo!(),
|
SimpleAssignTarget::TsAs(ts_as_expr) => todo!(),
|
||||||
SimpleAssignTarget::TsSatisfies(ts_satisfies_expr) => todo!(),
|
SimpleAssignTarget::TsSatisfies(ts_satisfies_expr) => todo!(),
|
||||||
SimpleAssignTarget::TsNonNull(ts_non_null_expr) => todo!(),
|
SimpleAssignTarget::TsNonNull(ts_non_null_expr) => todo!(),
|
||||||
SimpleAssignTarget::TsTypeAssertion(ts_type_assertion) => todo!(),
|
SimpleAssignTarget::TsTypeAssertion(ts_type_assertion) => todo!(),
|
||||||
SimpleAssignTarget::TsInstantiation(ts_instantiation) => todo!(),
|
SimpleAssignTarget::TsInstantiation(ts_instantiation) => todo!(),
|
||||||
SimpleAssignTarget::Invalid(invalid) => todo!(),
|
SimpleAssignTarget::Invalid(_) => unreachable!(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
AssignTarget::Pat(target) => match target {
|
AssignTarget::Pat(target) => match target {
|
||||||
|
@ -1336,7 +1348,7 @@ fn serialize_expr(
|
||||||
AssignTargetPat::Object(object_pat) => {
|
AssignTargetPat::Object(object_pat) => {
|
||||||
serialize_pat(ctx, &Pat::Object(object_pat.clone()), id)
|
serialize_pat(ctx, &Pat::Object(object_pat.clone()), id)
|
||||||
}
|
}
|
||||||
AssignTargetPat::Invalid(invalid) => todo!(),
|
AssignTargetPat::Invalid(_) => unreachable!(),
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -1349,38 +1361,7 @@ fn serialize_expr(
|
||||||
|
|
||||||
id
|
id
|
||||||
}
|
}
|
||||||
Expr::Member(node) => {
|
Expr::Member(node) => serialize_member_expr(ctx, node, parent_id, false),
|
||||||
let id = ctx.next_id();
|
|
||||||
|
|
||||||
let mut flags = FlagValue::new();
|
|
||||||
let obj_id = serialize_expr(ctx, node.obj.as_ref(), id);
|
|
||||||
|
|
||||||
let prop_id = match &node.prop {
|
|
||||||
MemberProp::Ident(ident_name) => {
|
|
||||||
serialize_ident_name(ctx, ident_name, id)
|
|
||||||
}
|
|
||||||
MemberProp::PrivateName(private_name) => {
|
|
||||||
let child_id =
|
|
||||||
ctx.push_node(AstNode::PrivateIdentifier, id, &private_name.span);
|
|
||||||
|
|
||||||
let str_id = ctx.str_table.insert(private_name.name.as_str());
|
|
||||||
append_usize(&mut ctx.result, str_id);
|
|
||||||
|
|
||||||
child_id
|
|
||||||
}
|
|
||||||
MemberProp::Computed(computed_prop_name) => {
|
|
||||||
flags.set(Flag::MemberComputed);
|
|
||||||
serialize_expr(ctx, computed_prop_name.expr.as_ref(), id)
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
ctx.write_node(id, AstNode::MemberExpression, parent_id, &node.span);
|
|
||||||
ctx.write_flags(&flags);
|
|
||||||
ctx.write_id(obj_id);
|
|
||||||
ctx.write_id(prop_id);
|
|
||||||
|
|
||||||
id
|
|
||||||
}
|
|
||||||
Expr::SuperProp(node) => {
|
Expr::SuperProp(node) => {
|
||||||
let id = ctx.next_id();
|
let id = ctx.next_id();
|
||||||
|
|
||||||
|
@ -1440,7 +1421,8 @@ fn serialize_expr(
|
||||||
.map(|arg| serialize_expr_or_spread(ctx, arg, id))
|
.map(|arg| serialize_expr_or_spread(ctx, arg, id))
|
||||||
.collect::<Vec<_>>();
|
.collect::<Vec<_>>();
|
||||||
|
|
||||||
ctx.write_node(id, AstNode::Call, parent_id, &node.span);
|
ctx.write_node(id, AstNode::CallExpression, parent_id, &node.span);
|
||||||
|
ctx.write_flags(&FlagValue::new());
|
||||||
ctx.write_id(callee_id);
|
ctx.write_id(callee_id);
|
||||||
ctx.write_id(type_id);
|
ctx.write_id(type_id);
|
||||||
ctx.write_ids(arg_ids);
|
ctx.write_ids(arg_ids);
|
||||||
|
@ -1692,27 +1674,86 @@ fn serialize_expr(
|
||||||
|
|
||||||
id
|
id
|
||||||
}
|
}
|
||||||
Expr::PrivateName(node) => {
|
Expr::PrivateName(node) => serialize_private_name(ctx, node, parent_id),
|
||||||
let id = ctx.push_node(AstNode::PrivateIdentifier, parent_id, &node.span);
|
|
||||||
|
|
||||||
// FIXME
|
|
||||||
|
|
||||||
id
|
|
||||||
}
|
|
||||||
Expr::OptChain(node) => {
|
Expr::OptChain(node) => {
|
||||||
let id = ctx.push_node(AstNode::OptChain, parent_id, &node.span);
|
let id = ctx.next_id();
|
||||||
|
|
||||||
// FIXME
|
let arg_id = match node.base.as_ref() {
|
||||||
|
OptChainBase::Member(member_expr) => {
|
||||||
|
serialize_member_expr(ctx, member_expr, id, true)
|
||||||
|
}
|
||||||
|
OptChainBase::Call(opt_call) => {
|
||||||
|
let call_id = ctx.next_id();
|
||||||
|
|
||||||
|
let mut flags = FlagValue::new();
|
||||||
|
flags.set(Flag::FnOptional);
|
||||||
|
|
||||||
|
let callee_id = serialize_expr(ctx, &opt_call.callee, id);
|
||||||
|
let type_id = opt_call.type_args.as_ref().map_or(0, |type_arg| {
|
||||||
|
todo!() // FIXME
|
||||||
|
});
|
||||||
|
|
||||||
|
let arg_ids = opt_call
|
||||||
|
.args
|
||||||
|
.iter()
|
||||||
|
.map(|arg| serialize_expr_or_spread(ctx, arg, id))
|
||||||
|
.collect::<Vec<_>>();
|
||||||
|
|
||||||
|
ctx.write_node(call_id, AstNode::CallExpression, id, &opt_call.span);
|
||||||
|
ctx.write_flags(&flags);
|
||||||
|
ctx.write_id(callee_id);
|
||||||
|
ctx.write_id(type_id);
|
||||||
|
ctx.write_ids(arg_ids);
|
||||||
|
|
||||||
|
call_id
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
ctx.write_node(id, AstNode::ChainExpression, parent_id, &node.span);
|
||||||
|
ctx.write_id(arg_id);
|
||||||
|
|
||||||
id
|
id
|
||||||
}
|
}
|
||||||
Expr::Invalid(invalid) => {
|
Expr::Invalid(_) => {
|
||||||
// ctx.push_node(result, AstNode::Invalid.into(), &invalid.span);
|
unreachable!()
|
||||||
todo!()
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn serialize_member_expr(
|
||||||
|
ctx: &mut SerializeCtx,
|
||||||
|
node: &MemberExpr,
|
||||||
|
parent_id: usize,
|
||||||
|
optional: bool,
|
||||||
|
) -> usize {
|
||||||
|
let id = ctx.next_id();
|
||||||
|
|
||||||
|
let mut flags = FlagValue::new();
|
||||||
|
if optional {
|
||||||
|
flags.set(Flag::MemberOptional)
|
||||||
|
}
|
||||||
|
|
||||||
|
let obj_id = serialize_expr(ctx, node.obj.as_ref(), id);
|
||||||
|
|
||||||
|
let prop_id = match &node.prop {
|
||||||
|
MemberProp::Ident(ident_name) => serialize_ident_name(ctx, ident_name, id),
|
||||||
|
MemberProp::PrivateName(private_name) => {
|
||||||
|
serialize_private_name(ctx, private_name, id)
|
||||||
|
}
|
||||||
|
MemberProp::Computed(computed_prop_name) => {
|
||||||
|
flags.set(Flag::MemberComputed);
|
||||||
|
serialize_expr(ctx, computed_prop_name.expr.as_ref(), id)
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
ctx.write_node(id, AstNode::MemberExpression, parent_id, &node.span);
|
||||||
|
ctx.write_flags(&flags);
|
||||||
|
ctx.write_id(obj_id);
|
||||||
|
ctx.write_id(prop_id);
|
||||||
|
|
||||||
|
id
|
||||||
|
}
|
||||||
|
|
||||||
fn serialize_expr_or_spread(
|
fn serialize_expr_or_spread(
|
||||||
ctx: &mut SerializeCtx,
|
ctx: &mut SerializeCtx,
|
||||||
arg: &ExprOrSpread,
|
arg: &ExprOrSpread,
|
||||||
|
@ -2033,7 +2074,31 @@ fn serialize_decl(
|
||||||
.body
|
.body
|
||||||
.iter()
|
.iter()
|
||||||
.map(|item| match item {
|
.map(|item| match item {
|
||||||
TsTypeElement::TsCallSignatureDecl(ts_call_signature_decl) => todo!(),
|
TsTypeElement::TsCallSignatureDecl(ts_call) => {
|
||||||
|
let item_id = ctx.next_id();
|
||||||
|
|
||||||
|
let type_param_id =
|
||||||
|
maybe_serialize_ts_type_param(ctx, &ts_call.type_params, id);
|
||||||
|
let return_type_id =
|
||||||
|
maybe_serialize_ts_type_ann(ctx, &ts_call.type_ann, id);
|
||||||
|
let param_ids = ts_call
|
||||||
|
.params
|
||||||
|
.iter()
|
||||||
|
.map(|param| serialize_ts_fn_param(ctx, param, id))
|
||||||
|
.collect::<Vec<_>>();
|
||||||
|
|
||||||
|
ctx.write_node(
|
||||||
|
item_id,
|
||||||
|
AstNode::TsCallSignatureDeclaration,
|
||||||
|
id,
|
||||||
|
&ts_call.span,
|
||||||
|
);
|
||||||
|
ctx.write_id(type_param_id);
|
||||||
|
ctx.write_ids(param_ids);
|
||||||
|
ctx.write_id(return_type_id);
|
||||||
|
|
||||||
|
item_id
|
||||||
|
}
|
||||||
TsTypeElement::TsConstructSignatureDecl(
|
TsTypeElement::TsConstructSignatureDecl(
|
||||||
ts_construct_signature_decl,
|
ts_construct_signature_decl,
|
||||||
) => todo!(),
|
) => todo!(),
|
||||||
|
@ -2147,6 +2212,19 @@ fn accessibility_to_flag(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn serialize_private_name(
|
||||||
|
ctx: &mut SerializeCtx,
|
||||||
|
node: &PrivateName,
|
||||||
|
parent_id: usize,
|
||||||
|
) -> usize {
|
||||||
|
let id = ctx.push_node(AstNode::PrivateIdentifier, parent_id, &node.span);
|
||||||
|
|
||||||
|
let str_id = ctx.str_table.insert(node.name.as_str());
|
||||||
|
append_usize(&mut ctx.result, str_id);
|
||||||
|
|
||||||
|
id
|
||||||
|
}
|
||||||
|
|
||||||
fn serialize_jsx_element(
|
fn serialize_jsx_element(
|
||||||
ctx: &mut SerializeCtx,
|
ctx: &mut SerializeCtx,
|
||||||
node: &JSXElement,
|
node: &JSXElement,
|
||||||
|
@ -2539,7 +2617,7 @@ fn serialize_pat(ctx: &mut SerializeCtx, pat: &Pat, parent_id: usize) -> usize {
|
||||||
|
|
||||||
id
|
id
|
||||||
}
|
}
|
||||||
Pat::Invalid(node) => todo!(),
|
Pat::Invalid(_) => unreachable!(),
|
||||||
Pat::Expr(node) => serialize_expr(ctx, node, parent_id),
|
Pat::Expr(node) => serialize_expr(ctx, node, parent_id),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -2553,7 +2631,9 @@ fn serialize_for_head(
|
||||||
ForHead::VarDecl(var_decl) => {
|
ForHead::VarDecl(var_decl) => {
|
||||||
serialize_decl(ctx, &Decl::Var(var_decl.clone()), parent_id)
|
serialize_decl(ctx, &Decl::Var(var_decl.clone()), parent_id)
|
||||||
}
|
}
|
||||||
ForHead::UsingDecl(using_decl) => todo!(),
|
ForHead::UsingDecl(using_decl) => {
|
||||||
|
serialize_decl(ctx, &Decl::Using(using_decl.clone()), parent_id)
|
||||||
|
}
|
||||||
ForHead::Pat(pat) => serialize_pat(ctx, pat, parent_id),
|
ForHead::Pat(pat) => serialize_pat(ctx, pat, parent_id),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -2694,13 +2774,30 @@ fn serialize_ts_type(
|
||||||
TsType::TsThisType(node) => {
|
TsType::TsThisType(node) => {
|
||||||
ctx.push_node(AstNode::TSThisType, parent_id, &node.span)
|
ctx.push_node(AstNode::TSThisType, parent_id, &node.span)
|
||||||
}
|
}
|
||||||
TsType::TsFnOrConstructorType(ts_fn_or_constructor_type) => todo!(),
|
TsType::TsFnOrConstructorType(node) => {
|
||||||
|
match node {
|
||||||
|
TsFnOrConstructorType::TsFnType(node) => {
|
||||||
|
let id = ctx.next_id();
|
||||||
|
|
||||||
|
let param_ids = node
|
||||||
|
.params
|
||||||
|
.iter()
|
||||||
|
.map(|param| serialize_ts_fn_param(ctx, param, id))
|
||||||
|
.collect::<Vec<_>>();
|
||||||
|
|
||||||
|
ctx.write_node(id, AstNode::TSFunctionType, parent_id, &node.span);
|
||||||
|
ctx.write_ids(param_ids);
|
||||||
|
//
|
||||||
|
id
|
||||||
|
}
|
||||||
|
TsFnOrConstructorType::TsConstructorType(ts_constructor_type) => {
|
||||||
|
todo!()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
TsType::TsTypeRef(node) => {
|
TsType::TsTypeRef(node) => {
|
||||||
let id = ctx.next_id();
|
let id = ctx.next_id();
|
||||||
let name_id = match &node.type_name {
|
let name_id = serialize_ts_entity_name(ctx, &node.type_name, id);
|
||||||
TsEntityName::TsQualifiedName(ts_qualified_name) => todo!(),
|
|
||||||
TsEntityName::Ident(ident) => serialize_ident(ctx, ident, id),
|
|
||||||
};
|
|
||||||
|
|
||||||
// FIXME params
|
// FIXME params
|
||||||
|
|
||||||
|
@ -2709,10 +2806,38 @@ fn serialize_ts_type(
|
||||||
|
|
||||||
id
|
id
|
||||||
}
|
}
|
||||||
TsType::TsTypeQuery(ts_type_query) => todo!(),
|
TsType::TsTypeQuery(node) => {
|
||||||
|
let id = ctx.next_id();
|
||||||
|
|
||||||
|
let name_id = match &node.expr_name {
|
||||||
|
TsTypeQueryExpr::TsEntityName(entity) => {
|
||||||
|
serialize_ts_entity_name(ctx, entity, id)
|
||||||
|
}
|
||||||
|
TsTypeQueryExpr::Import(ts_import_type) => todo!(),
|
||||||
|
};
|
||||||
|
|
||||||
|
// FIXME: params
|
||||||
|
|
||||||
|
ctx.write_node(id, AstNode::TSTypeQuery, parent_id, &node.span);
|
||||||
|
ctx.write_id(name_id);
|
||||||
|
|
||||||
|
id
|
||||||
|
}
|
||||||
TsType::TsTypeLit(ts_type_lit) => todo!(),
|
TsType::TsTypeLit(ts_type_lit) => todo!(),
|
||||||
TsType::TsArrayType(ts_array_type) => todo!(),
|
TsType::TsArrayType(ts_array_type) => todo!(),
|
||||||
TsType::TsTupleType(ts_tuple_type) => todo!(),
|
TsType::TsTupleType(node) => {
|
||||||
|
let id = ctx.next_id();
|
||||||
|
let children = node
|
||||||
|
.elem_types
|
||||||
|
.iter()
|
||||||
|
.map(|elem| todo!())
|
||||||
|
.collect::<Vec<_>>();
|
||||||
|
|
||||||
|
ctx.write_node(id, AstNode::TSTupleType, parent_id, &node.span);
|
||||||
|
ctx.write_ids(children);
|
||||||
|
|
||||||
|
id
|
||||||
|
}
|
||||||
TsType::TsOptionalType(ts_optional_type) => todo!(),
|
TsType::TsOptionalType(ts_optional_type) => todo!(),
|
||||||
TsType::TsRestType(ts_rest_type) => todo!(),
|
TsType::TsRestType(ts_rest_type) => todo!(),
|
||||||
TsType::TsUnionOrIntersectionType(node) => match node {
|
TsType::TsUnionOrIntersectionType(node) => match node {
|
||||||
|
@ -2834,6 +2959,17 @@ fn serialize_ts_type(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn serialize_ts_entity_name(
|
||||||
|
ctx: &mut SerializeCtx,
|
||||||
|
node: &TsEntityName,
|
||||||
|
parent_id: usize,
|
||||||
|
) -> usize {
|
||||||
|
match &node {
|
||||||
|
TsEntityName::TsQualifiedName(ts_qualified_name) => todo!(),
|
||||||
|
TsEntityName::Ident(ident) => serialize_ident(ctx, ident, parent_id),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
fn maybe_serialize_ts_type_ann(
|
fn maybe_serialize_ts_type_ann(
|
||||||
ctx: &mut SerializeCtx,
|
ctx: &mut SerializeCtx,
|
||||||
node: &Option<Box<TsTypeAnn>>,
|
node: &Option<Box<TsTypeAnn>>,
|
||||||
|
@ -2918,3 +3054,22 @@ fn maybe_serialize_ts_type_param(
|
||||||
id
|
id
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn serialize_ts_fn_param(
|
||||||
|
ctx: &mut SerializeCtx,
|
||||||
|
node: &TsFnParam,
|
||||||
|
parent_id: usize,
|
||||||
|
) -> usize {
|
||||||
|
match node {
|
||||||
|
TsFnParam::Ident(ident) => serialize_ident(ctx, ident, parent_id),
|
||||||
|
TsFnParam::Array(pat) => {
|
||||||
|
serialize_pat(ctx, &Pat::Array(pat.clone()), parent_id)
|
||||||
|
}
|
||||||
|
TsFnParam::Rest(pat) => {
|
||||||
|
serialize_pat(ctx, &Pat::Rest(pat.clone()), parent_id)
|
||||||
|
}
|
||||||
|
TsFnParam::Object(pat) => {
|
||||||
|
serialize_pat(ctx, &Pat::Object(pat.clone()), parent_id)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
8
cli/tsc/dts/lib.deno.ns.d.ts
vendored
8
cli/tsc/dts/lib.deno.ns.d.ts
vendored
|
@ -6305,8 +6305,7 @@ declare namespace Deno {
|
||||||
|
|
||||||
export interface ChainExpression extends BaseNode {
|
export interface ChainExpression extends BaseNode {
|
||||||
type: "ChainExpression";
|
type: "ChainExpression";
|
||||||
// FIXME
|
expression: CallExpression | MemberExpression | TSNonNullExpression;
|
||||||
// expression: CallExpression | MemberExpression | TsNonNullExpression;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// FIXME
|
// FIXME
|
||||||
|
@ -6977,6 +6976,11 @@ declare namespace Deno {
|
||||||
// FIXME
|
// FIXME
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export interface TSNonNullExpression extends BaseNode {
|
||||||
|
type: "TSNonNullExpression";
|
||||||
|
// FIXME
|
||||||
|
}
|
||||||
|
|
||||||
export interface TSAnyKeyword extends BaseNode {
|
export interface TSAnyKeyword extends BaseNode {
|
||||||
type: "TSAnyKeyword";
|
type: "TSAnyKeyword";
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue