Skip to content

Commit c9143d4

Browse files
committed
warn when name is imported that is not exported
1 parent e81a2d0 commit c9143d4

5 files changed

Lines changed: 35 additions & 1 deletion

File tree

lib/dependencies/HarmonyImportSpecifierDependency.js

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
Author Tobias Koppers @sokra
44
*/
55
var NullDependency = require("./NullDependency");
6+
var HarmonyModulesHelpers = require("./HarmonyModulesHelpers");
67

78
function HarmonyImportSpecifierDependency(importDependency, importedVar, id, name, range) {
89
NullDependency.call(this);
@@ -24,7 +25,20 @@ HarmonyImportSpecifierDependency.prototype.getReference = function() {
2425
module: this.importDependency.module,
2526
importedNames: this.id ? [this.id] : true
2627
};
27-
}
28+
};
29+
30+
HarmonyImportSpecifierDependency.prototype.getWarnings = function() {
31+
var importedModule = this.importDependency.module;
32+
if(importedModule && importedModule.meta && importedModule.meta.harmonyModule) {
33+
if(this.id && !HarmonyModulesHelpers.isExportedByHarmony(importedModule, this.id)) {
34+
return [
35+
new Error("export '" + this.id + "'" +
36+
(this.id !== this.name ? " (imported as '" + this.name + "')" : "") +
37+
" was not found in '" + this.importDependency.userRequest + "'")
38+
];
39+
}
40+
}
41+
};
2842

2943
HarmonyImportSpecifierDependency.prototype.updateHash = function(hash) {
3044
NullDependency.prototype.updateHash.call(this, hash);

test/cases/parsing/harmony-info/commonjs.js

Whitespace-only changes.
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
import def, { a as aa, b, c, d, e } from "./module";
2+
import f, { g } from "./commonjs";
3+
4+
it("should emit the correct warnings", function() {
5+
def, aa, b, c, d, e, f, g
6+
});
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
function b() {}
2+
3+
export {
4+
b
5+
}
6+
7+
export var c = 123;
8+
9+
export function d() {}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
module.exports = [
2+
[/export 'default' \(imported as 'def'\) was not found in '\.\/module'/],
3+
[/export 'e' was not found in '\.\/module'/],
4+
[/export 'a' \(imported as 'aa'\) was not found in '\.\/module'/]
5+
];

0 commit comments

Comments
 (0)