|
1 |
| -import { sequence, handle } from '../handlers'; |
| 1 | +import { |
| 2 | + sequence, |
| 3 | + handle, |
| 4 | + EXPRESSIONS_PRECEDENCE, |
| 5 | + dedent, |
| 6 | + newline, |
| 7 | + indent, |
| 8 | + handle_body |
| 9 | +} from '../handlers'; |
2 | 10 | /** @import { Handlers } from '../types' */
|
3 | 11 |
|
4 | 12 | /**
|
@@ -177,5 +185,100 @@ export default {
|
177 | 185 | state.commands.push('.');
|
178 | 186 | handle(node.qualifier, state);
|
179 | 187 | }
|
| 188 | + }, |
| 189 | + |
| 190 | + TSAsExpression(node, state) { |
| 191 | + if (node.expression) { |
| 192 | + const needs_parens = |
| 193 | + EXPRESSIONS_PRECEDENCE[node.expression.type] < EXPRESSIONS_PRECEDENCE.TSAsExpression; |
| 194 | + |
| 195 | + if (needs_parens) { |
| 196 | + state.commands.push('('); |
| 197 | + handle(node.expression, state); |
| 198 | + state.commands.push(')'); |
| 199 | + } else { |
| 200 | + handle(node.expression, state); |
| 201 | + } |
| 202 | + } |
| 203 | + state.commands.push(' as '); |
| 204 | + handle(node.typeAnnotation, state); |
| 205 | + }, |
| 206 | + |
| 207 | + TSEnumDeclaration(node, state) { |
| 208 | + state.commands.push('enum '); |
| 209 | + handle(node.id, state); |
| 210 | + state.commands.push(' {', indent, newline); |
| 211 | + sequence(node.members, state, false, handle); |
| 212 | + state.commands.push(dedent, newline, '}', newline); |
| 213 | + }, |
| 214 | + |
| 215 | + TSModuleBlock(node, state) { |
| 216 | + state.commands.push(' {', indent, newline); |
| 217 | + handle_body(node.body, state); |
| 218 | + state.commands.push(dedent, newline, '}'); |
| 219 | + }, |
| 220 | + |
| 221 | + TSModuleDeclaration(node, state) { |
| 222 | + if (node.declare) state.commands.push('declare '); |
| 223 | + else state.commands.push('namespace '); |
| 224 | + |
| 225 | + handle(node.id, state); |
| 226 | + |
| 227 | + if (!node.body) return; |
| 228 | + handle(node.body, state); |
| 229 | + }, |
| 230 | + |
| 231 | + TSNonNullExpression(node, state) { |
| 232 | + handle(node.expression, state); |
| 233 | + state.commands.push('!'); |
| 234 | + }, |
| 235 | + |
| 236 | + TSInterfaceBody(node, state) { |
| 237 | + sequence(node.body, state, true, handle, ';'); |
| 238 | + }, |
| 239 | + |
| 240 | + TSInterfaceDeclaration(node, state) { |
| 241 | + state.commands.push('interface '); |
| 242 | + handle(node.id, state); |
| 243 | + if (node.typeParameters) handle(node.typeParameters, state); |
| 244 | + if (node.extends) { |
| 245 | + state.commands.push(' extends '); |
| 246 | + sequence(node.extends, state, false, handle); |
| 247 | + } |
| 248 | + state.commands.push(' {'); |
| 249 | + handle(node.body, state); |
| 250 | + state.commands.push('}'); |
| 251 | + }, |
| 252 | + |
| 253 | + TSSatisfiesExpression(node, state) { |
| 254 | + if (node.expression) { |
| 255 | + const needs_parens = |
| 256 | + EXPRESSIONS_PRECEDENCE[node.expression.type] < EXPRESSIONS_PRECEDENCE.TSSatisfiesExpression; |
| 257 | + |
| 258 | + if (needs_parens) { |
| 259 | + state.commands.push('('); |
| 260 | + handle(node.expression, state); |
| 261 | + state.commands.push(')'); |
| 262 | + } else { |
| 263 | + handle(node.expression, state); |
| 264 | + } |
| 265 | + } |
| 266 | + state.commands.push(' satisfies '); |
| 267 | + handle(node.typeAnnotation, state); |
| 268 | + }, |
| 269 | + |
| 270 | + TSTypeAliasDeclaration(node, state) { |
| 271 | + state.commands.push('type '); |
| 272 | + handle(node.id, state); |
| 273 | + if (node.typeParameters) handle(node.typeParameters, state); |
| 274 | + state.commands.push(' = '); |
| 275 | + handle(node.typeAnnotation, state); |
| 276 | + state.commands.push(';'); |
| 277 | + }, |
| 278 | + |
| 279 | + TSQualifiedName(node, state) { |
| 280 | + handle(node.left, state); |
| 281 | + state.commands.push('.'); |
| 282 | + handle(node.right, state); |
180 | 283 | }
|
181 | 284 | };
|
0 commit comments