-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.ts
45 lines (39 loc) · 1.44 KB
/
index.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
import { ts, Plugin, PluginContext } from 'dtsgenerator';
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
const packageJson: {
name: string;
version: string;
description: string;
// eslint-disable-next-line @typescript-eslint/no-var-requires
} = require('./package.json');
const singleQuote: Plugin = {
meta: {
name: packageJson.name,
version: packageJson.version,
description: packageJson.description,
},
postProcess,
};
// eslint-disable-next-line @typescript-eslint/require-await
async function postProcess(
_pluginContext: PluginContext,
): Promise<ts.TransformerFactory<ts.SourceFile> | undefined> {
return (context: ts.TransformationContext) =>
(root: ts.SourceFile): ts.SourceFile => {
function visit<T extends ts.Node>(node: T): T {
node = ts.visitEachChild(node, visit, context);
if (ts.isStringLiteral(node)) {
// `singleQuote` is internal property.
// via: https://github.com/microsoft/TypeScript/blob/v3.9.2/src/compiler/types.ts#L1353
(
node as unknown as {
singleQuote: boolean;
}
).singleQuote = true;
}
return node;
}
return ts.visitNode(root, visit, ts.isSourceFile);
};
}
export default singleQuote;