-
Notifications
You must be signed in to change notification settings - Fork 730
Fix encode and decode bug for binary ast #2006
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||
|---|---|---|---|---|
|
|
@@ -390,6 +390,29 @@ export class RemoteNode extends RemoteNodeBase implements Node { | |||
| return this.decoder.decode(text); | ||||
| } | ||||
|
|
||||
| private getChildAtNodeIndex(parent: number, index: number): RemoteNode | RemoteNodeList | undefined { | ||||
| let next = parent + 1; | ||||
| let count = 0; | ||||
| while (next !== 0) { | ||||
| let child = new RemoteNode(this.view, this.decoder, next, this); | ||||
|
|
||||
| if (child.parent.index !== parent) { | ||||
| return undefined; | ||||
| } | ||||
|
|
||||
| if (count === index) { | ||||
| if (child.kind == KIND_NODE_LIST) { | ||||
| return new RemoteNodeList(this.view, this.decoder, child.index, this); | ||||
| } else { | ||||
| return child; | ||||
| } | ||||
| } | ||||
|
|
||||
| count += 1; | ||||
| next = child.next; | ||||
| } | ||||
| } | ||||
|
|
||||
| private getOrCreateChildAtNodeIndex(index: number): RemoteNode | RemoteNodeList { | ||||
| const pos = this.view.getUint32(this.offsetNodes + index * NODE_LEN + NODE_OFFSET_POS, true); | ||||
| let child = (this._children ??= new Map()).get(pos); | ||||
|
|
@@ -487,7 +510,8 @@ export class RemoteNode extends RemoteNodeBase implements Node { | |||
| // were present, we would have `parameters = children[5]`, but since `postfixToken` and `astersiskToken` are | ||||
| // missing, we have `parameters = children[5 - 2]`. | ||||
| const propertyIndex = order - popcount8[~(mask | ((0xff << order) & 0xff)) & 0xff]; | ||||
| return this.getOrCreateChildAtNodeIndex(this.index + 1 + propertyIndex); | ||||
| return this.getChildAtNodeIndex(this.index, propertyIndex); | ||||
| // return this.getOrCreateChildAtNodeIndex(this.index + 1 + propertyIndex); | ||||
|
||||
| // return this.getOrCreateChildAtNodeIndex(this.index + 1 + propertyIndex); |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -440,7 +440,7 @@ func getChildrenPropertyMask(node *ast.Node) uint8 { | |
| return (boolToByte(n.DotDotDotToken != nil) << 0) | (boolToByte(n.PropertyName != nil) << 1) | (boolToByte(n.Name() != nil) << 2) | (boolToByte(n.Initializer != nil) << 3) | ||
| case ast.KindFunctionDeclaration: | ||
| n := node.AsFunctionDeclaration() | ||
| return (boolToByte(n.Modifiers() != nil) << 0) | (boolToByte(n.AsteriskToken != nil) << 1) | (boolToByte(n.Name() != nil) << 2) | (boolToByte(n.TypeParameters != nil) << 3) | (boolToByte(n.Parameters != nil) << 4) | (boolToByte(n.Type != nil) << 5) | (boolToByte(n.Body != nil) << 6) | ||
| return (boolToByte(n.Modifiers() != nil) << 0) | (boolToByte(n.AsteriskToken != nil) << 1) | (boolToByte(n.Name() != nil) << 2) | (boolToByte(n.TypeParameters != nil) << 3) | (boolToByte(n.Parameters != nil && len(n.Parameters.Nodes) > 0) << 4) | (boolToByte(n.Type != nil) << 5) | (boolToByte(n.Body != nil) << 6) | ||
|
||
| case ast.KindInterfaceDeclaration: | ||
| n := node.AsInterfaceDeclaration() | ||
| return (boolToByte(n.Modifiers() != nil) << 0) | (boolToByte(n.Name() != nil) << 1) | (boolToByte(n.TypeParameters != nil) << 2) | (boolToByte(n.HeritageClauses != nil) << 3) | (boolToByte(n.Members != nil) << 4) | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The new
getChildAtNodeIndexmethod is missing documentation. Add a JSDoc comment explaining its purpose, parameters (parent- the parent node index,index- the child's ordinal position), return value, and how it differs fromgetOrCreateChildAtNodeIndex(specifically that it doesn't cache children).