Skip to content

Commit 2df7989

Browse files
quininerfansenze
authored andcommitted
fix: generate empty slot for empty list (#4)
1 parent 34da224 commit 2df7989

2 files changed

Lines changed: 12 additions & 4 deletions

File tree

_packages/api/test/api.test.ts

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ import {
1717
isCallExpression,
1818
isPropertyAccessExpression,
1919
isIdentifier,
20-
isStringLiteral,
20+
isArrowFunction,
2121
} from "@typescript/ast";
2222
import assert from "node:assert";
2323
import {
@@ -187,7 +187,8 @@ test("Function", () => {
187187
const currentFiles = {
188188
"/tsconfig.json": "{}",
189189
"/src/index.ts": `function foo() {
190-
console.log("hello", "world")
190+
console.log("hello", "world");
191+
() => "1";
191192
}`,
192193
};
193194

@@ -220,6 +221,13 @@ test("Function", () => {
220221
assert.ok(isStringLiteral(arg1));
221222
assert.equal(arg0.text, "hello");
222223
assert.equal(arg1.text, "world");
224+
225+
let arrow_expr = body.statements[1]!;
226+
assert.ok(isExpressionStatement(arrow_expr));
227+
let arrow = arrow_expr.expression;
228+
assert.ok(isArrowFunction(arrow));
229+
assert.ok(isStringLiteral(arrow.body));
230+
assert.equal(arrow.body.text, "1");
223231
});
224232

225233
test("Benchmarks", async () => {

internal/api/encoder/encoder.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -228,7 +228,7 @@ func EncodeSourceFile(sourceFile *ast.SourceFile, id string) ([]byte, error) {
228228
visitor := &ast.NodeVisitor{
229229
Hooks: ast.NodeVisitorHooks{
230230
VisitNodes: func(nodeList *ast.NodeList, visitor *ast.NodeVisitor) *ast.NodeList {
231-
if nodeList == nil || len(nodeList.Nodes) == 0 {
231+
if nodeList == nil {
232232
return nodeList
233233
}
234234

@@ -440,7 +440,7 @@ func getChildrenPropertyMask(node *ast.Node) uint8 {
440440
return (boolToByte(n.DotDotDotToken != nil) << 0) | (boolToByte(n.PropertyName != nil) << 1) | (boolToByte(n.Name() != nil) << 2) | (boolToByte(n.Initializer != nil) << 3)
441441
case ast.KindFunctionDeclaration:
442442
n := node.AsFunctionDeclaration()
443-
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)
443+
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)
444444
case ast.KindInterfaceDeclaration:
445445
n := node.AsInterfaceDeclaration()
446446
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)

0 commit comments

Comments
 (0)