@stacksjs/zig-dtsx 0.9.18 → 0.9.21
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +2 -2
- package/src/extractors.zig +6 -4
- package/test/zig-dtsx.test.ts +4 -2
- package/zig-out/bin/zig-dtsx +0 -0
- package/zig-out/bin/zig-dtsx.exe +0 -0
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@stacksjs/zig-dtsx",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "0.9.
|
|
4
|
+
"version": "0.9.21",
|
|
5
5
|
"description": "High-performance DTS emitter written in Zig",
|
|
6
6
|
"exports": {
|
|
7
7
|
".": {
|
|
@@ -18,6 +18,6 @@
|
|
|
18
18
|
"benchmark": "bun run test/benchmark.ts"
|
|
19
19
|
},
|
|
20
20
|
"dependencies": {
|
|
21
|
-
"@stacksjs/dtsx": "0.9.
|
|
21
|
+
"@stacksjs/dtsx": "0.9.21"
|
|
22
22
|
}
|
|
23
23
|
}
|
package/src/extractors.zig
CHANGED
|
@@ -1005,16 +1005,18 @@ pub fn extractFunction(s: *Scanner, decl_start: usize, is_exported: bool, is_asy
|
|
|
1005
1005
|
|
|
1006
1006
|
// Build DTS text — single alloc + memcpy is cheaper than ArrayList init +
|
|
1007
1007
|
// multiple appendSlice + toOwnedSlice for the fixed-shape function header.
|
|
1008
|
-
|
|
1009
|
-
|
|
1008
|
+
// `export default function foo()` keeps its `default` keyword in DTS:
|
|
1009
|
+
// `declare` is not allowed alongside `default`, and emitting
|
|
1010
|
+
// `export declare function ...` would silently drop the default-export
|
|
1011
|
+
// signal that consumers (and the dtsx TS reference impl) preserve.
|
|
1012
|
+
const export_prefix: []const u8 = if (is_default) "export default function " else if (is_exported) "export declare function " else "declare function ";
|
|
1010
1013
|
const colon_sep = ": ";
|
|
1011
|
-
const total = export_prefix.len +
|
|
1014
|
+
const total = export_prefix.len + func_name.len + generics.len +
|
|
1012
1015
|
dts_params.len + colon_sep.len + return_type.len + 1; // +1 for ';'
|
|
1013
1016
|
const dts_text = blk: {
|
|
1014
1017
|
const buf = s.allocator.alloc(u8, total) catch break :blk @as([]const u8, "");
|
|
1015
1018
|
var tp: usize = 0;
|
|
1016
1019
|
@memcpy(buf[tp..][0..export_prefix.len], export_prefix); tp += export_prefix.len;
|
|
1017
|
-
@memcpy(buf[tp..][0..declare_kw.len], declare_kw); tp += declare_kw.len;
|
|
1018
1020
|
@memcpy(buf[tp..][0..func_name.len], func_name); tp += func_name.len;
|
|
1019
1021
|
@memcpy(buf[tp..][0..generics.len], generics); tp += generics.len;
|
|
1020
1022
|
@memcpy(buf[tp..][0..dts_params.len], dts_params); tp += dts_params.len;
|
package/test/zig-dtsx.test.ts
CHANGED
|
@@ -963,7 +963,9 @@ export function useFoo(f: Foo): void {}
|
|
|
963
963
|
|
|
964
964
|
test('default export function', () => {
|
|
965
965
|
const result = dts(`export default function main(): void {}`)
|
|
966
|
-
|
|
966
|
+
// `export default function` keeps the `default` keyword in DTS —
|
|
967
|
+
// `export declare function` would lose the default-export signal.
|
|
968
|
+
expect(result).toContain('export default function main(): void')
|
|
967
969
|
})
|
|
968
970
|
|
|
969
971
|
test('default export class', () => {
|
|
@@ -977,7 +979,7 @@ export const version = '1.0.0'
|
|
|
977
979
|
export default function init(): void {}
|
|
978
980
|
`)
|
|
979
981
|
expect(result).toContain('declare const version')
|
|
980
|
-
expect(result).toContain('
|
|
982
|
+
expect(result).toContain('export default function init')
|
|
981
983
|
})
|
|
982
984
|
})
|
|
983
985
|
|
package/zig-out/bin/zig-dtsx
CHANGED
|
Binary file
|
package/zig-out/bin/zig-dtsx.exe
CHANGED
|
Binary file
|