diff --git a/lib/ast-converter.js b/lib/ast-converter.js index b63aa32..23a05c6 100644 --- a/lib/ast-converter.js +++ b/lib/ast-converter.js @@ -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: diff --git a/tests/fixtures/basics/typeof-expression.result.js b/tests/fixtures/basics/typeof-expression.result.js new file mode 100644 index 0000000..f2bc933 --- /dev/null +++ b/tests/fixtures/basics/typeof-expression.result.js @@ -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 + } + } + } + ] +}; diff --git a/tests/fixtures/basics/typeof-expression.src.js b/tests/fixtures/basics/typeof-expression.src.js new file mode 100644 index 0000000..43d0ea7 --- /dev/null +++ b/tests/fixtures/basics/typeof-expression.src.js @@ -0,0 +1 @@ +typeof 'str'