Skip to content

Commit 8e643b5

Browse files
v0.4.3
1 parent 277bba9 commit 8e643b5

File tree

2 files changed

+21
-4
lines changed

2 files changed

+21
-4
lines changed

cjs/import-manager.cjs

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -396,6 +396,7 @@ class ImportManagerUnitMethods {
396396

397397

398398

399+
399400
class ImportManager {
400401

401402
/**
@@ -497,7 +498,10 @@ class ImportManager {
497498

498499
if (node.type === "ImportDeclaration") {
499500
const unit = this.#es6NodeToUnit(node);
500-
if (!unit) return; // TODO: Add warning message
501+
if (!unit) {
502+
this.#unitCreationFailedWarning(node);
503+
return;
504+
}
501505

502506
unit.id = es6Id ++;
503507
unit.index = es6Index ++;
@@ -513,7 +517,10 @@ class ImportManager {
513517

514518
if (part.type === "ImportExpression") {
515519
const unit = this.#dynamicNodeToUnit(node, part);
516-
if (!unit) return; // TODO: Add warning message
520+
if (!unit) {
521+
this.#unitCreationFailedWarning(node);
522+
return;
523+
}
517524

518525
unit.id = dynamicId ++;
519526
unit.index = dynamicIndex ++;
@@ -524,7 +531,10 @@ class ImportManager {
524531

525532
else if (part.type === "Identifier" && part.name === "require") {
526533
const unit = this.#cjsNodeToUnit(node);
527-
if (!unit) return; // TODO: Add warning message
534+
if (!unit) {
535+
this.#unitCreationFailedWarning(node);
536+
return;
537+
}
528538

529539
unit.id = cjsId ++;
530540
unit.index = cjsIndex ++;
@@ -1268,6 +1278,13 @@ class ImportManager {
12681278
this.warnSpamProtection.add(hash);
12691279
this.warn(msg);
12701280
}
1281+
1282+
1283+
#unitCreationFailedWarning(node) {
1284+
const codeSnippet = this.code.slice(node.start, node.end);
1285+
const message = `Could not create a unit from code snippet:${os.EOL}---${os.EOL}${codeSnippet}${os.EOL}---${os.EOL}If the related code is correct, this might be a bug. You can report this on:${os.EOL}https://github.com/UmamiAppearance/ImportManager/issues${os.EOL}`;
1286+
this.warn(message);
1287+
}
12711288
}
12721289

12731290

cjs/import-manager.cjs.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)