@@ -388,14 +388,15 @@ class ImportManagerUnitMethods {
388
388
* It handles code analysis, creates units from import
389
389
* statements, attaches methods to the units and more.
390
390
*
391
- * @version 0.4.2
391
+ * @version 0.4.3
392
392
* @author UmamiAppearance [mail@umamiappearance.eu]
393
393
* @license MIT
394
394
* @see https://github.com/UmamiAppearance/rollup-plugin-import-manager
395
395
*/
396
396
397
397
398
398
399
+
399
400
class ImportManager {
400
401
401
402
/**
@@ -497,6 +498,11 @@ class ImportManager {
497
498
498
499
if ( node . type === "ImportDeclaration" ) {
499
500
const unit = this . #es6NodeToUnit( node ) ;
501
+ if ( ! unit ) {
502
+ this . #unitCreationFailedWarning( node ) ;
503
+ return ;
504
+ }
505
+
500
506
unit . id = es6Id ++ ;
501
507
unit . index = es6Index ++ ;
502
508
unit . hash = this . #makeHash( unit ) ;
@@ -511,6 +517,11 @@ class ImportManager {
511
517
512
518
if ( part . type === "ImportExpression" ) {
513
519
const unit = this . #dynamicNodeToUnit( node , part ) ;
520
+ if ( ! unit ) {
521
+ this . #unitCreationFailedWarning( node ) ;
522
+ return ;
523
+ }
524
+
514
525
unit . id = dynamicId ++ ;
515
526
unit . index = dynamicIndex ++ ;
516
527
unit . hash = this . #makeHash( unit ) ;
@@ -520,6 +531,11 @@ class ImportManager {
520
531
521
532
else if ( part . type === "Identifier" && part . name === "require" ) {
522
533
const unit = this . #cjsNodeToUnit( node ) ;
534
+ if ( ! unit ) {
535
+ this . #unitCreationFailedWarning( node ) ;
536
+ return ;
537
+ }
538
+
523
539
unit . id = cjsId ++ ;
524
540
unit . index = cjsIndex ++ ;
525
541
unit . hash = this . #makeHash( unit ) ;
@@ -600,6 +616,7 @@ class ImportManager {
600
616
* @returns {object } - Import Manager Unit Object.
601
617
*/
602
618
#es6NodeToUnit( node , oStart , oEnd ) {
619
+ if ( ! node ) return ;
603
620
604
621
let code ;
605
622
if ( typeof node === "string" ) {
@@ -736,6 +753,7 @@ class ImportManager {
736
753
* @returns {object } - Import Manager Unit Object.
737
754
*/
738
755
#dynamicNodeToUnit( node , importObject ) {
756
+ if ( ! node ) return ;
739
757
740
758
const code = this . code . slice ( node . start , node . end ) ;
741
759
@@ -772,6 +790,7 @@ class ImportManager {
772
790
* @returns {object } - Import Manager Unit Object.
773
791
*/
774
792
#cjsNodeToUnit( node ) {
793
+ if ( ! node || ! node . declarations ) return ;
775
794
776
795
const code = this . code . slice ( node . start , node . end ) ;
777
796
@@ -1259,6 +1278,13 @@ class ImportManager {
1259
1278
this . warnSpamProtection . add ( hash ) ;
1260
1279
this . warn ( msg ) ;
1261
1280
}
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
+ }
1262
1288
}
1263
1289
1264
1290
0 commit comments