Skip to content

Commit 34ce994

Browse files
committed
Fix crash when converting array from module.exports
Resolves #2909
1 parent 2d95afa commit 34ce994

File tree

5 files changed

+16
-2
lines changed

5 files changed

+16
-2
lines changed

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,12 @@ title: Changelog
1414

1515
- `--watch` can now infer entry points from `package.json` as supported in non-watch mode, #2899.
1616
- `@include` with regions now works on files with CRLF line endings, #2902.
17+
- Generated page names now correctly handles UTF-8 characters requiring more than 16 bits #2905.
18+
- Fixed a crash when converting `module.exports = []`, #2909.
19+
20+
### Thanks!
21+
22+
- @romainmnr
1723

1824
## v0.28.0 (2025-03-15)
1925

src/lib/converter/symbols.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1044,7 +1044,8 @@ function convertVariable(
10441044
reflection.defaultValue = convertDefaultValue(declaration);
10451045
context.finalizeDeclarationReflection(reflection);
10461046

1047-
return ts.SymbolFlags.Property;
1047+
// Exclude ValueModule to handle `module.exports = []`
1048+
return ts.SymbolFlags.Property | ts.SymbolFlags.ValueModule;
10481049
}
10491050

10501051
function isEnumLike(

src/lib/converter/types.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,7 @@ const arrayConverter: TypeConverter<ts.ArrayTypeNode, ts.TypeReference> = {
204204
return new ArrayType(convertType(context, node.elementType));
205205
},
206206
convertType(context, type) {
207-
const params = context.checker.getTypeArguments(type);
207+
const params = type.aliasTypeArguments || context.checker.getTypeArguments(type);
208208
// This is *almost* always true... except for when this type is in the constraint of a type parameter see GH#1408
209209
// assert(params.length === 1);
210210
assert(params.length > 0);

src/test/converter2/issues/gh2909.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
module.exports = [];

src/test/issues.c2.test.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2036,4 +2036,10 @@ describe("Issue Tests", () => {
20362036
notFn: "Variable",
20372037
});
20382038
});
2039+
2040+
it("#2909 handles array export declarations", () => {
2041+
const project = convert();
2042+
const exp = query(project, "export=");
2043+
equal(exp.type?.toString(), "never[]");
2044+
});
20392045
});

0 commit comments

Comments
 (0)