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

Commit 3c1fab0

Browse files
ikatyangJamesHenry
authored andcommitted
Fix: support ImportMeta (fixes #489) (#490)
1 parent 6611535 commit 3c1fab0

File tree

4 files changed

+243
-1
lines changed

4 files changed

+243
-1
lines changed

Diff for: lib/convert.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1729,7 +1729,7 @@ module.exports = function convert(config) {
17291729
type: AST_NODE_TYPES.Identifier,
17301730
range: newToken.range,
17311731
loc: newToken.loc,
1732-
name: "new"
1732+
name: nodeUtils.getTextForTokenKind(node.keywordToken)
17331733
},
17341734
property: convertChild(node.name)
17351735
});

Diff for: lib/node-utils.js

+2
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,8 @@ TOKEN_TO_TEXT[SyntaxKind.AtToken] = "@";
9999
TOKEN_TO_TEXT[SyntaxKind.InKeyword] = "in";
100100
TOKEN_TO_TEXT[SyntaxKind.UniqueKeyword] = "unique";
101101
TOKEN_TO_TEXT[SyntaxKind.KeyOfKeyword] = "keyof";
102+
TOKEN_TO_TEXT[SyntaxKind.NewKeyword] = "new";
103+
TOKEN_TO_TEXT[SyntaxKind.ImportKeyword] = "import";
102104

103105
/**
104106
* Find the first matching child based on the given sourceFile and predicate function.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
import.meta.url;

Diff for: tests/lib/__snapshots__/ecma-features.js.snap

+239
Original file line numberDiff line numberDiff line change
@@ -69303,6 +69303,245 @@ Object {
6930369303
}
6930469304
`;
6930569305

69306+
exports[`ecmaFeatures fixtures/importMeta/simple-import-meta.src 1`] = `
69307+
Object {
69308+
"body": Array [
69309+
Object {
69310+
"expression": Object {
69311+
"computed": false,
69312+
"loc": Object {
69313+
"end": Object {
69314+
"column": 15,
69315+
"line": 1,
69316+
},
69317+
"start": Object {
69318+
"column": 0,
69319+
"line": 1,
69320+
},
69321+
},
69322+
"object": Object {
69323+
"loc": Object {
69324+
"end": Object {
69325+
"column": 11,
69326+
"line": 1,
69327+
},
69328+
"start": Object {
69329+
"column": 0,
69330+
"line": 1,
69331+
},
69332+
},
69333+
"meta": Object {
69334+
"loc": Object {
69335+
"end": Object {
69336+
"column": 6,
69337+
"line": 1,
69338+
},
69339+
"start": Object {
69340+
"column": 0,
69341+
"line": 1,
69342+
},
69343+
},
69344+
"name": "import",
69345+
"range": Array [
69346+
0,
69347+
6,
69348+
],
69349+
"type": "Identifier",
69350+
},
69351+
"property": Object {
69352+
"loc": Object {
69353+
"end": Object {
69354+
"column": 11,
69355+
"line": 1,
69356+
},
69357+
"start": Object {
69358+
"column": 7,
69359+
"line": 1,
69360+
},
69361+
},
69362+
"name": "meta",
69363+
"range": Array [
69364+
7,
69365+
11,
69366+
],
69367+
"type": "Identifier",
69368+
},
69369+
"range": Array [
69370+
0,
69371+
11,
69372+
],
69373+
"type": "MetaProperty",
69374+
},
69375+
"property": Object {
69376+
"loc": Object {
69377+
"end": Object {
69378+
"column": 15,
69379+
"line": 1,
69380+
},
69381+
"start": Object {
69382+
"column": 12,
69383+
"line": 1,
69384+
},
69385+
},
69386+
"name": "url",
69387+
"range": Array [
69388+
12,
69389+
15,
69390+
],
69391+
"type": "Identifier",
69392+
},
69393+
"range": Array [
69394+
0,
69395+
15,
69396+
],
69397+
"type": "MemberExpression",
69398+
},
69399+
"loc": Object {
69400+
"end": Object {
69401+
"column": 16,
69402+
"line": 1,
69403+
},
69404+
"start": Object {
69405+
"column": 0,
69406+
"line": 1,
69407+
},
69408+
},
69409+
"range": Array [
69410+
0,
69411+
16,
69412+
],
69413+
"type": "ExpressionStatement",
69414+
},
69415+
],
69416+
"loc": Object {
69417+
"end": Object {
69418+
"column": 0,
69419+
"line": 2,
69420+
},
69421+
"start": Object {
69422+
"column": 0,
69423+
"line": 1,
69424+
},
69425+
},
69426+
"range": Array [
69427+
0,
69428+
17,
69429+
],
69430+
"sourceType": "module",
69431+
"tokens": Array [
69432+
Object {
69433+
"loc": Object {
69434+
"end": Object {
69435+
"column": 6,
69436+
"line": 1,
69437+
},
69438+
"start": Object {
69439+
"column": 0,
69440+
"line": 1,
69441+
},
69442+
},
69443+
"range": Array [
69444+
0,
69445+
6,
69446+
],
69447+
"type": "Keyword",
69448+
"value": "import",
69449+
},
69450+
Object {
69451+
"loc": Object {
69452+
"end": Object {
69453+
"column": 7,
69454+
"line": 1,
69455+
},
69456+
"start": Object {
69457+
"column": 6,
69458+
"line": 1,
69459+
},
69460+
},
69461+
"range": Array [
69462+
6,
69463+
7,
69464+
],
69465+
"type": "Punctuator",
69466+
"value": ".",
69467+
},
69468+
Object {
69469+
"loc": Object {
69470+
"end": Object {
69471+
"column": 11,
69472+
"line": 1,
69473+
},
69474+
"start": Object {
69475+
"column": 7,
69476+
"line": 1,
69477+
},
69478+
},
69479+
"range": Array [
69480+
7,
69481+
11,
69482+
],
69483+
"type": "Identifier",
69484+
"value": "meta",
69485+
},
69486+
Object {
69487+
"loc": Object {
69488+
"end": Object {
69489+
"column": 12,
69490+
"line": 1,
69491+
},
69492+
"start": Object {
69493+
"column": 11,
69494+
"line": 1,
69495+
},
69496+
},
69497+
"range": Array [
69498+
11,
69499+
12,
69500+
],
69501+
"type": "Punctuator",
69502+
"value": ".",
69503+
},
69504+
Object {
69505+
"loc": Object {
69506+
"end": Object {
69507+
"column": 15,
69508+
"line": 1,
69509+
},
69510+
"start": Object {
69511+
"column": 12,
69512+
"line": 1,
69513+
},
69514+
},
69515+
"range": Array [
69516+
12,
69517+
15,
69518+
],
69519+
"type": "Identifier",
69520+
"value": "url",
69521+
},
69522+
Object {
69523+
"loc": Object {
69524+
"end": Object {
69525+
"column": 16,
69526+
"line": 1,
69527+
},
69528+
"start": Object {
69529+
"column": 15,
69530+
"line": 1,
69531+
},
69532+
},
69533+
"range": Array [
69534+
15,
69535+
16,
69536+
],
69537+
"type": "Punctuator",
69538+
"value": ";",
69539+
},
69540+
],
69541+
"type": "Program",
69542+
}
69543+
`;
69544+
6930669545
exports[`ecmaFeatures fixtures/modules/export-default-array.src 1`] = `
6930769546
Object {
6930869547
"body": Array [

0 commit comments

Comments
 (0)