diff --git a/lib/ast-converter.js b/lib/ast-converter.js index eed6498..d80df39 100644 --- a/lib/ast-converter.js +++ b/lib/ast-converter.js @@ -735,7 +735,7 @@ module.exports = function(ast, extra) { case SyntaxKind.Identifier: assign(result, { type: "Identifier", - name: node.text + name: ts.unescapeIdentifier(node.text) }); break; diff --git a/tests/fixtures/basics/identifiers-double-underscore.result.js b/tests/fixtures/basics/identifiers-double-underscore.result.js new file mode 100644 index 0000000..74fe3d4 --- /dev/null +++ b/tests/fixtures/basics/identifiers-double-underscore.result.js @@ -0,0 +1,479 @@ +module.exports = { + "type": "Program", + "range": [ + 0, + 59 + ], + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 9, + "column": 1 + } + }, + "body": [ + { + "type": "VariableDeclaration", + "range": [ + 0, + 18 + ], + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 18 + } + }, + "declarations": [ + { + "type": "VariableDeclarator", + "range": [ + 4, + 17 + ], + "loc": { + "start": { + "line": 1, + "column": 4 + }, + "end": { + "line": 1, + "column": 17 + } + }, + "id": { + "type": "Identifier", + "range": [ + 4, + 10 + ], + "loc": { + "start": { + "line": 1, + "column": 4 + }, + "end": { + "line": 1, + "column": 10 + } + }, + "name": "__test" + }, + "init": { + "type": "Literal", + "range": [ + 13, + 17 + ], + "loc": { + "start": { + "line": 1, + "column": 13 + }, + "end": { + "line": 1, + "column": 17 + } + }, + "value": "ff", + "raw": "'ff'" + } + } + ], + "kind": "var" + }, + { + "type": "ClassDeclaration", + "range": [ + 20, + 36 + ], + "loc": { + "start": { + "line": 3, + "column": 0 + }, + "end": { + "line": 5, + "column": 1 + } + }, + "id": { + "type": "Identifier", + "range": [ + 26, + 31 + ], + "loc": { + "start": { + "line": 3, + "column": 6 + }, + "end": { + "line": 3, + "column": 11 + } + }, + "name": "__Foo" + }, + "body": { + "type": "ClassBody", + "body": [], + "range": [ + 32, + 36 + ], + "loc": { + "start": { + "line": 3, + "column": 12 + }, + "end": { + "line": 5, + "column": 1 + } + } + }, + "superClass": null, + "implements": [], + "decorators": [] + }, + { + "type": "FunctionDeclaration", + "range": [ + 38, + 59 + ], + "loc": { + "start": { + "line": 7, + "column": 0 + }, + "end": { + "line": 9, + "column": 1 + } + }, + "id": { + "type": "Identifier", + "range": [ + 47, + 52 + ], + "loc": { + "start": { + "line": 7, + "column": 9 + }, + "end": { + "line": 7, + "column": 14 + } + }, + "name": "__Bar" + }, + "generator": false, + "expression": false, + "async": false, + "params": [], + "body": { + "type": "BlockStatement", + "range": [ + 55, + 59 + ], + "loc": { + "start": { + "line": 7, + "column": 17 + }, + "end": { + "line": 9, + "column": 1 + } + }, + "body": [] + } + } + ], + "sourceType": "script", + "tokens": [ + { + "type": "Keyword", + "value": "var", + "range": [ + 0, + 3 + ], + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 3 + } + } + }, + { + "type": "Identifier", + "value": "__test", + "range": [ + 4, + 10 + ], + "loc": { + "start": { + "line": 1, + "column": 4 + }, + "end": { + "line": 1, + "column": 10 + } + } + }, + { + "type": "Punctuator", + "value": "=", + "range": [ + 11, + 12 + ], + "loc": { + "start": { + "line": 1, + "column": 11 + }, + "end": { + "line": 1, + "column": 12 + } + } + }, + { + "type": "String", + "value": "'ff'", + "range": [ + 13, + 17 + ], + "loc": { + "start": { + "line": 1, + "column": 13 + }, + "end": { + "line": 1, + "column": 17 + } + } + }, + { + "type": "Punctuator", + "value": ";", + "range": [ + 17, + 18 + ], + "loc": { + "start": { + "line": 1, + "column": 17 + }, + "end": { + "line": 1, + "column": 18 + } + } + }, + { + "type": "Keyword", + "value": "class", + "range": [ + 20, + 25 + ], + "loc": { + "start": { + "line": 3, + "column": 0 + }, + "end": { + "line": 3, + "column": 5 + } + } + }, + { + "type": "Identifier", + "value": "__Foo", + "range": [ + 26, + 31 + ], + "loc": { + "start": { + "line": 3, + "column": 6 + }, + "end": { + "line": 3, + "column": 11 + } + } + }, + { + "type": "Punctuator", + "value": "{", + "range": [ + 32, + 33 + ], + "loc": { + "start": { + "line": 3, + "column": 12 + }, + "end": { + "line": 3, + "column": 13 + } + } + }, + { + "type": "Punctuator", + "value": "}", + "range": [ + 35, + 36 + ], + "loc": { + "start": { + "line": 5, + "column": 0 + }, + "end": { + "line": 5, + "column": 1 + } + } + }, + { + "type": "Keyword", + "value": "function", + "range": [ + 38, + 46 + ], + "loc": { + "start": { + "line": 7, + "column": 0 + }, + "end": { + "line": 7, + "column": 8 + } + } + }, + { + "type": "Identifier", + "value": "__Bar", + "range": [ + 47, + 52 + ], + "loc": { + "start": { + "line": 7, + "column": 9 + }, + "end": { + "line": 7, + "column": 14 + } + } + }, + { + "type": "Punctuator", + "value": "(", + "range": [ + 52, + 53 + ], + "loc": { + "start": { + "line": 7, + "column": 14 + }, + "end": { + "line": 7, + "column": 15 + } + } + }, + { + "type": "Punctuator", + "value": ")", + "range": [ + 53, + 54 + ], + "loc": { + "start": { + "line": 7, + "column": 15 + }, + "end": { + "line": 7, + "column": 16 + } + } + }, + { + "type": "Punctuator", + "value": "{", + "range": [ + 55, + 56 + ], + "loc": { + "start": { + "line": 7, + "column": 17 + }, + "end": { + "line": 7, + "column": 18 + } + } + }, + { + "type": "Punctuator", + "value": "}", + "range": [ + 58, + 59 + ], + "loc": { + "start": { + "line": 9, + "column": 0 + }, + "end": { + "line": 9, + "column": 1 + } + } + } + ] +}; diff --git a/tests/fixtures/basics/identifiers-double-underscore.src.js b/tests/fixtures/basics/identifiers-double-underscore.src.js new file mode 100644 index 0000000..b765d56 --- /dev/null +++ b/tests/fixtures/basics/identifiers-double-underscore.src.js @@ -0,0 +1,9 @@ +var __test = 'ff'; + +class __Foo { + +} + +function __Bar() { + +}