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

Fix: Convert TSTypeOfExpression to UnaryExpression (fixes #85) #86

Merged
merged 1 commit into from
Sep 12, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions lib/ast-converter.js
Original file line number Diff line number Diff line change
Expand Up @@ -1484,6 +1484,15 @@ module.exports = function(ast, extra) {
});
break;

case SyntaxKind.TypeOfExpression:
assign(result, {
type: "UnaryExpression",
operator: "typeof",
prefix: true,
argument: convertChild(node.expression)
});
break;

// Binary Operations

case SyntaxKind.BinaryExpression:
Expand Down
113 changes: 113 additions & 0 deletions tests/fixtures/basics/typeof-expression.result.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
module.exports = {
"type": "Program",
"range": [
0,
12
],
"loc": {
"start": {
"line": 1,
"column": 0
},
"end": {
"line": 1,
"column": 12
}
},
"body": [
{
"type": "ExpressionStatement",
"range": [
0,
12
],
"loc": {
"start": {
"line": 1,
"column": 0
},
"end": {
"line": 1,
"column": 12
}
},
"expression": {
"type": "UnaryExpression",
"operator": "typeof",
"prefix": true,
"range": [
0,
12
],
"loc": {
"start": {
"line": 1,
"column": 0
},
"end": {
"line": 1,
"column": 12
}
},
"argument": {
"type": "Literal",
"range": [
7,
12
],
"loc": {
"start": {
"line": 1,
"column": 7
},
"end": {
"line": 1,
"column": 12
}
},
"value": "str",
"raw": "'str'"
}
}
}
],
"sourceType": "script",
"tokens": [
{
"type": "Keyword",
"value": "typeof",
"range": [
0,
6
],
"loc": {
"start": {
"line": 1,
"column": 0
},
"end": {
"line": 1,
"column": 6
}
}
},
{
"type": "String",
"value": "'str'",
"range": [
7,
12
],
"loc": {
"start": {
"line": 1,
"column": 7
},
"end": {
"line": 1,
"column": 12
}
}
}
]
};
1 change: 1 addition & 0 deletions tests/fixtures/basics/typeof-expression.src.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
typeof 'str'