Skip to content

Commit 5a81fa7

Browse files
committed
okay i think this shit actually works now, types and all. except windows. fuckin windows
1 parent ce0aad5 commit 5a81fa7

File tree

14 files changed

+69
-48
lines changed

14 files changed

+69
-48
lines changed

package.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,11 @@
1818
},
1919
"./languages/ts": {
2020
"types": "./types/index.d.ts",
21-
"default": "./src/languages/ts.js"
21+
"default": "./src/languages/ts/index.js"
2222
},
2323
"./languages/tsx": {
2424
"types": "./types/index.d.ts",
25-
"default": "./src/languages/tsx.js"
25+
"default": "./src/languages/tsx/index.js"
2626
}
2727
},
2828
"types": "./types/index.d.ts",
@@ -32,7 +32,7 @@
3232
"@typescript-eslint/types": "^8.2.0",
3333
"@vitest/ui": "^2.1.1",
3434
"acorn": "^8.15.0",
35-
"dts-buddy": "^0.5.4",
35+
"dts-buddy": "^0.6.2",
3636
"prettier": "^3.0.3",
3737
"typescript": "^5.7.2",
3838
"vitest": "^2.1.1",
@@ -42,7 +42,7 @@
4242
"changeset:version": "changeset version",
4343
"changeset:publish": "changeset publish",
4444
"check": "tsc",
45-
"prepublishOnly": "pnpm test && dts-buddy -m esrap:./src/public.d.ts -m esrap/languages/ts:./src/languages/ts.js -m esrap/languages/tsx:./src/languages/tsx.js",
45+
"prepublishOnly": "pnpm test && dts-buddy -m esrap:./src/public.d.ts -m esrap/languages/ts:./src/languages/ts/public.d.ts -m esrap/languages/tsx:./src/languages/tsx/public.d.ts",
4646
"sandbox": "node test/sandbox/index.js",
4747
"test": "vitest --run",
4848
"test:ui": "vitest --ui"

pnpm-lock.yaml

Lines changed: 28 additions & 26 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/context.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/** @import { TSESTree } from '@typescript-eslint/types' */
2-
/** @import { Command, Visitors } from './types' */
2+
/** @import { BaseNode, Command, Visitors } from './types' */
33

44
export const margin = 0;
55
export const newline = 1;
@@ -49,7 +49,7 @@ export class Context {
4949
/**
5050
*
5151
* @param {string} content
52-
* @param {TSESTree.Node} [node]
52+
* @param {BaseNode} [node]
5353
*/
5454
write(content, node) {
5555
if (node?.loc) {
@@ -91,8 +91,10 @@ export class Context {
9191
}
9292

9393
if (this.#visitors._) {
94+
// @ts-expect-error
9495
this.#visitors._(node, this, (node) => visitor(node, this));
9596
} else {
97+
// @ts-expect-error
9698
visitor(node, this);
9799
}
98100
}

src/index.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,3 +153,8 @@ export function print(node, visitors, opts = {}) {
153153
}
154154
};
155155
}
156+
157+
// it sucks that we have to export the class rather than just
158+
// re-exporting it via public.d.ts, but otherwise TypeScript
159+
// gets confused about private fields because it is really dumb!
160+
export { Context };

src/languages/ts.js renamed to src/languages/ts/index.js

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
/** @import { TSESTree } from '@typescript-eslint/types' */
2-
/** @import { Visitors } from '../types.js' */
3-
/** @import { TSOptions, Comment } from './types.js' */
4-
import { Context } from '../context.js';
2+
/** @import { Visitors } from '../../types.js' */
3+
/** @import { TSOptions, Comment } from '../types.js' */
4+
import { Context } from 'esrap';
5+
6+
/** @typedef {TSESTree.Node} Node */
57

68
/** @type {Record<TSESTree.Expression['type'] | 'Super' | 'RestElement', number>} */
79
export const EXPRESSIONS_PRECEDENCE = {

src/languages/ts/public.d.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
export * from './index';
2+
export { Comment } from '../types';

src/languages/tsx.js renamed to src/languages/tsx/index.js

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
1-
/** @import { Visitors } from '../types' */
2-
/** @import { TSOptions } from './types.js' */
3-
import { TSESTree } from '@typescript-eslint/types';
4-
import ts from './ts.js';
1+
/** @import { TSESTree } from '@typescript-eslint/types' */
2+
/** @import { Visitors } from '../../types.js' */
3+
/** @import { TSOptions } from '../types.js' */
4+
import ts from '../ts/index.js';
5+
6+
/** @typedef {TSESTree.Node} Node */
57

68
/**
79
* @param {TSOptions} [options]

src/languages/tsx/public.d.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
export * from './index';
2+
export { Comment } from '../types';

src/languages/types.d.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
import type { TSESTree } from '@typescript-eslint/types';
2-
31
export type TSOptions = {
42
quotes?: 'double' | 'single';
53
comments?: Comment[];

src/public.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
export { PrintOptions, Context, Visitors } from './types';
1+
export { PrintOptions, Visitors } from './types';
22
export * from './index';

0 commit comments

Comments
 (0)