Skip to content
This repository was archived by the owner on Jan 19, 2019. It is now read-only.

Commit 5c47ad5

Browse files
JamesHenrynzakas
authored andcommitted
Fix: Convert TSTypeOfExpression to UnaryExpression (fixes #85) (#86)
1 parent 799fd63 commit 5c47ad5

File tree

3 files changed

+123
-0
lines changed

3 files changed

+123
-0
lines changed

lib/ast-converter.js

+9
Original file line numberDiff line numberDiff line change
@@ -1484,6 +1484,15 @@ module.exports = function(ast, extra) {
14841484
});
14851485
break;
14861486

1487+
case SyntaxKind.TypeOfExpression:
1488+
assign(result, {
1489+
type: "UnaryExpression",
1490+
operator: "typeof",
1491+
prefix: true,
1492+
argument: convertChild(node.expression)
1493+
});
1494+
break;
1495+
14871496
// Binary Operations
14881497

14891498
case SyntaxKind.BinaryExpression:
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,113 @@
1+
module.exports = {
2+
"type": "Program",
3+
"range": [
4+
0,
5+
12
6+
],
7+
"loc": {
8+
"start": {
9+
"line": 1,
10+
"column": 0
11+
},
12+
"end": {
13+
"line": 1,
14+
"column": 12
15+
}
16+
},
17+
"body": [
18+
{
19+
"type": "ExpressionStatement",
20+
"range": [
21+
0,
22+
12
23+
],
24+
"loc": {
25+
"start": {
26+
"line": 1,
27+
"column": 0
28+
},
29+
"end": {
30+
"line": 1,
31+
"column": 12
32+
}
33+
},
34+
"expression": {
35+
"type": "UnaryExpression",
36+
"operator": "typeof",
37+
"prefix": true,
38+
"range": [
39+
0,
40+
12
41+
],
42+
"loc": {
43+
"start": {
44+
"line": 1,
45+
"column": 0
46+
},
47+
"end": {
48+
"line": 1,
49+
"column": 12
50+
}
51+
},
52+
"argument": {
53+
"type": "Literal",
54+
"range": [
55+
7,
56+
12
57+
],
58+
"loc": {
59+
"start": {
60+
"line": 1,
61+
"column": 7
62+
},
63+
"end": {
64+
"line": 1,
65+
"column": 12
66+
}
67+
},
68+
"value": "str",
69+
"raw": "'str'"
70+
}
71+
}
72+
}
73+
],
74+
"sourceType": "script",
75+
"tokens": [
76+
{
77+
"type": "Keyword",
78+
"value": "typeof",
79+
"range": [
80+
0,
81+
6
82+
],
83+
"loc": {
84+
"start": {
85+
"line": 1,
86+
"column": 0
87+
},
88+
"end": {
89+
"line": 1,
90+
"column": 6
91+
}
92+
}
93+
},
94+
{
95+
"type": "String",
96+
"value": "'str'",
97+
"range": [
98+
7,
99+
12
100+
],
101+
"loc": {
102+
"start": {
103+
"line": 1,
104+
"column": 7
105+
},
106+
"end": {
107+
"line": 1,
108+
"column": 12
109+
}
110+
}
111+
}
112+
]
113+
};
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
typeof 'str'

0 commit comments

Comments
 (0)