forked from TypeScriptToLua/TypeScriptToLua
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtypescript.ts
More file actions
26 lines (22 loc) · 1.05 KB
/
Copy pathtypescript.ts
File metadata and controls
26 lines (22 loc) · 1.05 KB
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
import * as ts from "typescript";
import { FunctionVisitor, Visitors } from "../context";
import { validateAssignment } from "../utils/assignment-validation";
const transformAssertionExpression: FunctionVisitor<ts.AssertionExpression> = (expression, context) => {
if (!ts.isConstTypeReference(expression.type)) {
validateAssignment(
context,
expression,
context.checker.getTypeAtLocation(expression.expression),
context.checker.getTypeAtLocation(expression.type)
);
}
return context.transformExpression(expression.expression);
};
export const typescriptVisitors: Visitors = {
[ts.SyntaxKind.TypeAliasDeclaration]: () => undefined,
[ts.SyntaxKind.InterfaceDeclaration]: () => undefined,
[ts.SyntaxKind.NonNullExpression]: (node, context) => context.transformExpression(node.expression),
[ts.SyntaxKind.AsExpression]: transformAssertionExpression,
[ts.SyntaxKind.TypeAssertionExpression]: transformAssertionExpression,
[ts.SyntaxKind.NotEmittedStatement]: () => undefined,
};