diff --git a/lib/convert.js b/lib/convert.js index 18d52cd..f24a91d 100644 --- a/lib/convert.js +++ b/lib/convert.js @@ -1729,7 +1729,7 @@ module.exports = function convert(config) { type: AST_NODE_TYPES.Identifier, range: newToken.range, loc: newToken.loc, - name: "new" + name: nodeUtils.getTextForTokenKind(node.keywordToken) }, property: convertChild(node.name) }); diff --git a/lib/node-utils.js b/lib/node-utils.js index 677ff50..ac22ce4 100644 --- a/lib/node-utils.js +++ b/lib/node-utils.js @@ -99,6 +99,8 @@ TOKEN_TO_TEXT[SyntaxKind.AtToken] = "@"; TOKEN_TO_TEXT[SyntaxKind.InKeyword] = "in"; TOKEN_TO_TEXT[SyntaxKind.UniqueKeyword] = "unique"; TOKEN_TO_TEXT[SyntaxKind.KeyOfKeyword] = "keyof"; +TOKEN_TO_TEXT[SyntaxKind.NewKeyword] = "new"; +TOKEN_TO_TEXT[SyntaxKind.ImportKeyword] = "import"; /** * Find the first matching child based on the given sourceFile and predicate function. diff --git a/tests/fixtures/ecma-features/importMeta/simple-import-meta.src.js b/tests/fixtures/ecma-features/importMeta/simple-import-meta.src.js new file mode 100644 index 0000000..bd14f94 --- /dev/null +++ b/tests/fixtures/ecma-features/importMeta/simple-import-meta.src.js @@ -0,0 +1 @@ +import.meta.url; diff --git a/tests/lib/__snapshots__/ecma-features.js.snap b/tests/lib/__snapshots__/ecma-features.js.snap index 2436e0d..fab54a3 100644 --- a/tests/lib/__snapshots__/ecma-features.js.snap +++ b/tests/lib/__snapshots__/ecma-features.js.snap @@ -69303,6 +69303,245 @@ Object { } `; +exports[`ecmaFeatures fixtures/importMeta/simple-import-meta.src 1`] = ` +Object { + "body": Array [ + Object { + "expression": Object { + "computed": false, + "loc": Object { + "end": Object { + "column": 15, + "line": 1, + }, + "start": Object { + "column": 0, + "line": 1, + }, + }, + "object": Object { + "loc": Object { + "end": Object { + "column": 11, + "line": 1, + }, + "start": Object { + "column": 0, + "line": 1, + }, + }, + "meta": Object { + "loc": Object { + "end": Object { + "column": 6, + "line": 1, + }, + "start": Object { + "column": 0, + "line": 1, + }, + }, + "name": "import", + "range": Array [ + 0, + 6, + ], + "type": "Identifier", + }, + "property": Object { + "loc": Object { + "end": Object { + "column": 11, + "line": 1, + }, + "start": Object { + "column": 7, + "line": 1, + }, + }, + "name": "meta", + "range": Array [ + 7, + 11, + ], + "type": "Identifier", + }, + "range": Array [ + 0, + 11, + ], + "type": "MetaProperty", + }, + "property": Object { + "loc": Object { + "end": Object { + "column": 15, + "line": 1, + }, + "start": Object { + "column": 12, + "line": 1, + }, + }, + "name": "url", + "range": Array [ + 12, + 15, + ], + "type": "Identifier", + }, + "range": Array [ + 0, + 15, + ], + "type": "MemberExpression", + }, + "loc": Object { + "end": Object { + "column": 16, + "line": 1, + }, + "start": Object { + "column": 0, + "line": 1, + }, + }, + "range": Array [ + 0, + 16, + ], + "type": "ExpressionStatement", + }, + ], + "loc": Object { + "end": Object { + "column": 0, + "line": 2, + }, + "start": Object { + "column": 0, + "line": 1, + }, + }, + "range": Array [ + 0, + 17, + ], + "sourceType": "module", + "tokens": Array [ + Object { + "loc": Object { + "end": Object { + "column": 6, + "line": 1, + }, + "start": Object { + "column": 0, + "line": 1, + }, + }, + "range": Array [ + 0, + 6, + ], + "type": "Keyword", + "value": "import", + }, + Object { + "loc": Object { + "end": Object { + "column": 7, + "line": 1, + }, + "start": Object { + "column": 6, + "line": 1, + }, + }, + "range": Array [ + 6, + 7, + ], + "type": "Punctuator", + "value": ".", + }, + Object { + "loc": Object { + "end": Object { + "column": 11, + "line": 1, + }, + "start": Object { + "column": 7, + "line": 1, + }, + }, + "range": Array [ + 7, + 11, + ], + "type": "Identifier", + "value": "meta", + }, + Object { + "loc": Object { + "end": Object { + "column": 12, + "line": 1, + }, + "start": Object { + "column": 11, + "line": 1, + }, + }, + "range": Array [ + 11, + 12, + ], + "type": "Punctuator", + "value": ".", + }, + Object { + "loc": Object { + "end": Object { + "column": 15, + "line": 1, + }, + "start": Object { + "column": 12, + "line": 1, + }, + }, + "range": Array [ + 12, + 15, + ], + "type": "Identifier", + "value": "url", + }, + Object { + "loc": Object { + "end": Object { + "column": 16, + "line": 1, + }, + "start": Object { + "column": 15, + "line": 1, + }, + }, + "range": Array [ + 15, + 16, + ], + "type": "Punctuator", + "value": ";", + }, + ], + "type": "Program", +} +`; + exports[`ecmaFeatures fixtures/modules/export-default-array.src 1`] = ` Object { "body": Array [