Skip to content

Commit 8264097

Browse files
checkpoint
1 parent e7fddba commit 8264097

File tree

2 files changed

+25
-4
lines changed

2 files changed

+25
-4
lines changed

packages/typestript/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
"name": "typestript",
33
"private": true,
44
"scripts": {
5+
"dev": "tsc --watch",
56
"build": "tsc",
67
"lint": "prettier --check .",
78
"format": "prettier --write ."

packages/typestript/src/index.ts

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,17 +20,25 @@ export function stripTypes(content: string): { content: string; sourceMap: Sourc
2020
walk(ast as unknown as TSESTree.Node, null, {
2121
_: (node, context) => {
2222
console.log(node.type);
23-
if (node.type.startsWith('TS') && node.type !== 'TSAsExpression') {
23+
if (
24+
node.type.startsWith('TS') &&
25+
!['TSAsExpression', 'TSSatisfiesExpression', 'TSNonNullExpression'].includes(node.type)
26+
) {
2427
const { start, end } = node as unknown as { start: number; end: number };
2528
s.overwrite(start, end, ' '.repeat(end - start));
2629
} else {
2730
context.next();
2831
}
2932
},
3033
TSAsExpression: (node) => {
31-
const { end: start } = node.expression as unknown as { end: number; start: number };
32-
const { end } = node.typeAnnotation as unknown as { start: number; end: number };
33-
s.overwrite(start, end, ' '.repeat(end - start));
34+
handleTypeExpression(node, s);
35+
},
36+
TSSatisfiesExpression: (node) => {
37+
handleTypeExpression(node, s);
38+
},
39+
TSNonNullExpression: (node) => {
40+
const { end } = node as unknown as { start: number; end: number };
41+
s.overwrite(end - 1, end, ' ');
3442
},
3543
ImportDeclaration: (node, context) => {
3644
if (
@@ -64,3 +72,15 @@ export function stripTypes(content: string): { content: string; sourceMap: Sourc
6472
})
6573
};
6674
}
75+
76+
function handleTypeExpression(
77+
node: {
78+
expression: unknown;
79+
typeAnnotation: unknown;
80+
},
81+
s: { overwrite: (start: number, end: number, content: string) => void }
82+
) {
83+
const { end: start } = node.expression as unknown as { end: number; start: number };
84+
const { end } = node.typeAnnotation as unknown as { start: number; end: number };
85+
s.overwrite(start, end, ' '.repeat(end - start));
86+
}

0 commit comments

Comments
 (0)