diff --git a/lib/ast-converter.js b/lib/ast-converter.js index d80831b..05fe978 100644 --- a/lib/ast-converter.js +++ b/lib/ast-converter.js @@ -1653,6 +1653,24 @@ module.exports = function(ast, extra) { }); break; + case SyntaxKind.DeleteExpression: + assign(result, { + type: "UnaryExpression", + operator: "delete", + prefix: true, + argument: convertChild(node.expression) + }); + break; + + case SyntaxKind.VoidExpression: + assign(result, { + type: "UnaryExpression", + operator: "void", + prefix: true, + argument: convertChild(node.expression) + }); + break; + case SyntaxKind.TypeOfExpression: assign(result, { type: "UnaryExpression", diff --git a/tests/fixtures/basics/delete-expression.result.js b/tests/fixtures/basics/delete-expression.result.js new file mode 100644 index 0000000..590085b --- /dev/null +++ b/tests/fixtures/basics/delete-expression.result.js @@ -0,0 +1,202 @@ +module.exports = { + "type": "Program", + "range": [ + 0, + 15 + ], + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 15 + } + }, + "body": [ + { + "type": "ExpressionStatement", + "range": [ + 0, + 15 + ], + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 15 + } + }, + "expression": { + "type": "UnaryExpression", + "range": [ + 0, + 14 + ], + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 14 + } + }, + "operator": "delete", + "prefix": true, + "argument": { + "type": "MemberExpression", + "range": [ + 7, + 14 + ], + "loc": { + "start": { + "line": 1, + "column": 7 + }, + "end": { + "line": 1, + "column": 14 + } + }, + "object": { + "type": "Identifier", + "range": [ + 7, + 10 + ], + "loc": { + "start": { + "line": 1, + "column": 7 + }, + "end": { + "line": 1, + "column": 10 + } + }, + "name": "foo" + }, + "property": { + "type": "Identifier", + "range": [ + 11, + 14 + ], + "loc": { + "start": { + "line": 1, + "column": 11 + }, + "end": { + "line": 1, + "column": 14 + } + }, + "name": "bar" + }, + "computed": false + } + } + } + ], + "sourceType": "script", + "tokens": [ + { + "type": "Keyword", + "value": "delete", + "range": [ + 0, + 6 + ], + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 6 + } + } + }, + { + "type": "Identifier", + "value": "foo", + "range": [ + 7, + 10 + ], + "loc": { + "start": { + "line": 1, + "column": 7 + }, + "end": { + "line": 1, + "column": 10 + } + } + }, + { + "type": "Punctuator", + "value": ".", + "range": [ + 10, + 11 + ], + "loc": { + "start": { + "line": 1, + "column": 10 + }, + "end": { + "line": 1, + "column": 11 + } + } + }, + { + "type": "Identifier", + "value": "bar", + "range": [ + 11, + 14 + ], + "loc": { + "start": { + "line": 1, + "column": 11 + }, + "end": { + "line": 1, + "column": 14 + } + } + }, + { + "type": "Punctuator", + "value": ";", + "range": [ + 14, + 15 + ], + "loc": { + "start": { + "line": 1, + "column": 14 + }, + "end": { + "line": 1, + "column": 15 + } + } + } + ] +}; diff --git a/tests/fixtures/basics/delete-expression.src.js b/tests/fixtures/basics/delete-expression.src.js new file mode 100644 index 0000000..23cb064 --- /dev/null +++ b/tests/fixtures/basics/delete-expression.src.js @@ -0,0 +1 @@ +delete foo.bar; diff --git a/tests/fixtures/basics/void-expression.result.js b/tests/fixtures/basics/void-expression.result.js new file mode 100644 index 0000000..12437f1 --- /dev/null +++ b/tests/fixtures/basics/void-expression.result.js @@ -0,0 +1,276 @@ +module.exports = { + "type": "Program", + "range": [ + 0, + 16 + ], + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 2, + "column": 8 + } + }, + "body": [ + { + "type": "ExpressionStatement", + "range": [ + 0, + 7 + ], + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 7 + } + }, + "expression": { + "type": "UnaryExpression", + "range": [ + 0, + 6 + ], + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 6 + } + }, + "operator": "void", + "prefix": true, + "argument": { + "type": "Literal", + "range": [ + 5, + 6 + ], + "loc": { + "start": { + "line": 1, + "column": 5 + }, + "end": { + "line": 1, + "column": 6 + } + }, + "value": 4, + "raw": "4" + } + } + }, + { + "type": "ExpressionStatement", + "range": [ + 8, + 16 + ], + "loc": { + "start": { + "line": 2, + "column": 0 + }, + "end": { + "line": 2, + "column": 8 + } + }, + "expression": { + "type": "UnaryExpression", + "range": [ + 8, + 15 + ], + "loc": { + "start": { + "line": 2, + "column": 0 + }, + "end": { + "line": 2, + "column": 7 + } + }, + "operator": "void", + "prefix": true, + "argument": { + "type": "Literal", + "range": [ + 13, + 14 + ], + "loc": { + "start": { + "line": 2, + "column": 5 + }, + "end": { + "line": 2, + "column": 6 + } + }, + "value": 3, + "raw": "3" + } + } + } + ], + "sourceType": "script", + "tokens": [ + { + "type": "Keyword", + "value": "void", + "range": [ + 0, + 4 + ], + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 4 + } + } + }, + { + "type": "Numeric", + "value": "4", + "range": [ + 5, + 6 + ], + "loc": { + "start": { + "line": 1, + "column": 5 + }, + "end": { + "line": 1, + "column": 6 + } + } + }, + { + "type": "Punctuator", + "value": ";", + "range": [ + 6, + 7 + ], + "loc": { + "start": { + "line": 1, + "column": 6 + }, + "end": { + "line": 1, + "column": 7 + } + } + }, + { + "type": "Keyword", + "value": "void", + "range": [ + 8, + 12 + ], + "loc": { + "start": { + "line": 2, + "column": 0 + }, + "end": { + "line": 2, + "column": 4 + } + } + }, + { + "type": "Punctuator", + "value": "(", + "range": [ + 12, + 13 + ], + "loc": { + "start": { + "line": 2, + "column": 4 + }, + "end": { + "line": 2, + "column": 5 + } + } + }, + { + "type": "Numeric", + "value": "3", + "range": [ + 13, + 14 + ], + "loc": { + "start": { + "line": 2, + "column": 5 + }, + "end": { + "line": 2, + "column": 6 + } + } + }, + { + "type": "Punctuator", + "value": ")", + "range": [ + 14, + 15 + ], + "loc": { + "start": { + "line": 2, + "column": 6 + }, + "end": { + "line": 2, + "column": 7 + } + } + }, + { + "type": "Punctuator", + "value": ";", + "range": [ + 15, + 16 + ], + "loc": { + "start": { + "line": 2, + "column": 7 + }, + "end": { + "line": 2, + "column": 8 + } + } + } + ] +}; diff --git a/tests/fixtures/basics/void-expression.src.js b/tests/fixtures/basics/void-expression.src.js new file mode 100644 index 0000000..7da947c --- /dev/null +++ b/tests/fixtures/basics/void-expression.src.js @@ -0,0 +1,2 @@ +void 4; +void(3);