Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix wrong variable name in import expression #3073

Merged
merged 3 commits into from Aug 22, 2019
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions src/ast/nodes/ImportExpression.ts
Expand Up @@ -54,6 +54,7 @@ export default class Import extends NodeBase {
);
code.overwrite(this.end - 1, this.end, importMechanism.right);
}
this.source.render(code, options);
}

renderFinalResolution(code: MagicString, resolution: string, format: string) {
Expand Down
6 changes: 6 additions & 0 deletions test/form/samples/import-expression/_config.js
@@ -0,0 +1,6 @@
module.exports = {
description: 'correctly transforms variables in imported expressions',
options: {
external: 'external'
}
};
25 changes: 25 additions & 0 deletions test/form/samples/import-expression/_expected/amd.js
@@ -0,0 +1,25 @@
define(['require', 'external'], function (require, external) { 'use strict';

function _interopNamespace(e) {
if (e && e.__esModule) { return e; } else {
var n = {};
if (e) {
Object.keys(e).forEach(function (k) {
var d = Object.getOwnPropertyDescriptor(e, k);
Object.defineProperty(n, k, d.get ? d : {
enumerable: true,
get: function () {
return e[k];
}
});
});
}
n['default'] = e;
return n;
}
}

new Promise(function (resolve, reject) { require([external.join('a', 'b')], function (m) { resolve(_interopNamespace(m)); }, reject) });
console.log(external.join);

});
25 changes: 25 additions & 0 deletions test/form/samples/import-expression/_expected/cjs.js
@@ -0,0 +1,25 @@
'use strict';

function _interopNamespace(e) {
if (e && e.__esModule) { return e; } else {
var n = {};
if (e) {
Object.keys(e).forEach(function (k) {
var d = Object.getOwnPropertyDescriptor(e, k);
Object.defineProperty(n, k, d.get ? d : {
enumerable: true,
get: function () {
return e[k];
}
});
});
}
n['default'] = e;
return n;
}
}

var external = require('external');

new Promise(function (resolve) { resolve(_interopNamespace(require(external.join('a', 'b')))); });
console.log(external.join);
4 changes: 4 additions & 0 deletions test/form/samples/import-expression/_expected/es.js
@@ -0,0 +1,4 @@
import { join } from 'external';

import(join('a', 'b'));
console.log(join);
7 changes: 7 additions & 0 deletions test/form/samples/import-expression/_expected/iife.js
@@ -0,0 +1,7 @@
(function (external) {
'use strict';

import(external.join('a', 'b'));
console.log(external.join);

}(external));
15 changes: 15 additions & 0 deletions test/form/samples/import-expression/_expected/system.js
@@ -0,0 +1,15 @@
System.register(['external'], function (exports, module) {
'use strict';
var join;
return {
setters: [function (module) {
join = module.join;
}],
execute: function () {

module.import(join('a', 'b'));
console.log(join);

}
};
});
10 changes: 10 additions & 0 deletions test/form/samples/import-expression/_expected/umd.js
@@ -0,0 +1,10 @@
(function (global, factory) {
typeof exports === 'object' && typeof module !== 'undefined' ? factory(require('external')) :
typeof define === 'function' && define.amd ? define(['external'], factory) :
(global = global || self, factory(global.external));
}(this, function (external) { 'use strict';

import(external.join('a', 'b'));
console.log(external.join);

}));
4 changes: 4 additions & 0 deletions test/form/samples/import-expression/main.js
@@ -0,0 +1,4 @@
import { join as pathJoin } from 'external';

import(pathJoin('a', 'b'));
console.log(pathJoin);