Skip to content

Commit b99a200

Browse files
committed
Fix Import variable binding for esprima 2, eg import {foo as bar} from "baz";
1 parent 5dabbc5 commit b99a200

4 files changed

Lines changed: 10 additions & 8 deletions

File tree

escodegen.js

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2262,9 +2262,11 @@
22622262
},
22632263

22642264
ExportSpecifier: function (expr, precedence, flags) {
2265-
var result = [ (expr.id || expr.local).name ];
2266-
if (expr.name) {
2267-
result.push(noEmptySpace() + 'as' + noEmptySpace() + generateIdentifier(expr.name));
2265+
var exported = (expr.id || expr.imported).name;
2266+
var result = [ exported ];
2267+
var id = expr.name || expr.local;
2268+
if (id && id.name !== exported) {
2269+
result.push(noEmptySpace() + 'as' + noEmptySpace() + generateIdentifier(id));
22682270
}
22692271
return result;
22702272
},

test/compare-esprima2/import-with-default.expected.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import foo from 'foo';
22
import foo, * as foo from 'foo';
33
import * as foo from 'foo';
44
import ok, {
5-
foo,
6-
test,
5+
foo as bar,
6+
test as testing,
77
logging
88
} from 'foo';
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
import foo from'foo';import foo,*as foo from'foo';import*as foo from'foo';import ok,{foo,test,logging}from'foo'
1+
import foo from'foo';import foo,*as foo from'foo';import*as foo from'foo';import ok,{foo as bar,test as testing,logging}from'foo'

test/compare-esprima2/import-with-default.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import foo from 'foo';
22
import foo, * as foo from 'foo';
33
import * as foo from 'foo';
44
import ok, {
5-
foo,
6-
test,
5+
foo as bar,
6+
test as testing,
77
logging
88
} from 'foo';

0 commit comments

Comments
 (0)