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

Commit

Permalink
Fix: Convert TSTypeOfExpression to UnaryExpression (fixes #85) (#86)
Browse files Browse the repository at this point in the history
  • Loading branch information
JamesHenry authored and nzakas committed Sep 12, 2016
1 parent 799fd63 commit 5c47ad5
Show file tree
Hide file tree
Showing 3 changed files with 123 additions and 0 deletions.
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'

0 comments on commit 5c47ad5

Please sign in to comment.