|
| 1 | +import * as semver from 'semver'; |
| 2 | +import * as ts from 'typescript'; |
| 3 | + |
1 | 4 | import { getRealVariables, parseAndAnalyze } from '../util';
|
2 | 5 |
|
3 | 6 | describe('References:', () => {
|
@@ -541,10 +544,11 @@ describe('References:', () => {
|
541 | 544 | );
|
542 | 545 | });
|
543 | 546 |
|
544 |
| - describe('When emitDecoratorMetadata is true', () => { |
545 |
| - it('check type referenced by decorator metadata', () => { |
546 |
| - const { scopeManager } = parseAndAnalyze( |
547 |
| - ` |
| 547 | + if (semver.satisfies(ts.version, '>=4')) { |
| 548 | + describe('When emitDecoratorMetadata is true', () => { |
| 549 | + it('check type referenced by decorator metadata', () => { |
| 550 | + const { scopeManager } = parseAndAnalyze( |
| 551 | + ` |
548 | 552 | @deco
|
549 | 553 | class A {
|
550 | 554 | property: Type1;
|
@@ -585,75 +589,78 @@ describe('References:', () => {
|
585 | 589 | foo(): TypeC;
|
586 | 590 | }
|
587 | 591 | `,
|
588 |
| - { |
589 |
| - emitDecoratorMetadata: true, |
590 |
| - }, |
591 |
| - ); |
592 |
| - |
593 |
| - const classAScope = scopeManager.globalScope!.childScopes[0]; |
594 |
| - const propertyTypeRef = classAScope.references[2]; |
595 |
| - expect(propertyTypeRef.identifier.name).toBe('a'); |
596 |
| - expect(propertyTypeRef.isTypeReference).toBe(true); |
597 |
| - expect(propertyTypeRef.isValueReference).toBe(true); |
598 |
| - |
599 |
| - const setterParamTypeRef = classAScope.childScopes[0].references[0]; |
600 |
| - expect(setterParamTypeRef.identifier.name).toBe('SetterType'); |
601 |
| - expect(setterParamTypeRef.isTypeReference).toBe(true); |
602 |
| - expect(setterParamTypeRef.isValueReference).toBe(false); |
603 |
| - |
604 |
| - const constructorParamTypeRef = classAScope.childScopes[1].references[0]; |
605 |
| - expect(constructorParamTypeRef.identifier.name).toBe('b'); |
606 |
| - expect(constructorParamTypeRef.isTypeReference).toBe(true); |
607 |
| - expect(constructorParamTypeRef.isValueReference).toBe(true); |
608 |
| - |
609 |
| - const methodParamTypeRef = classAScope.childScopes[2].references[0]; |
610 |
| - expect(methodParamTypeRef.identifier.name).toBe('Type2'); |
611 |
| - expect(methodParamTypeRef.isTypeReference).toBe(true); |
612 |
| - expect(methodParamTypeRef.isValueReference).toBe(true); |
613 |
| - const methodParamTypeRef0 = classAScope.childScopes[2].references[2]; |
614 |
| - expect(methodParamTypeRef0.identifier.name).toBe('Type0'); |
615 |
| - expect(methodParamTypeRef0.isTypeReference).toBe(true); |
616 |
| - expect(methodParamTypeRef0.isValueReference).toBe(true); |
617 |
| - |
618 |
| - const methodParamTypeRef1 = classAScope.childScopes[3].references[0]; |
619 |
| - expect(methodParamTypeRef1.identifier.name).toBe('Type3'); |
620 |
| - expect(methodParamTypeRef1.isTypeReference).toBe(true); |
621 |
| - expect(methodParamTypeRef1.isValueReference).toBe(true); |
622 |
| - |
623 |
| - const methodReturnTypeRef = classAScope.childScopes[4].references[0]; |
624 |
| - expect(methodReturnTypeRef.identifier.name).toBe('Type4'); |
625 |
| - expect(methodReturnTypeRef.isTypeReference).toBe(true); |
626 |
| - expect(methodReturnTypeRef.isValueReference).toBe(true); |
627 |
| - |
628 |
| - const setterParamTypeRef1 = classAScope.childScopes[5].references[0]; |
629 |
| - expect(setterParamTypeRef1.identifier.name).toBe('Type5'); |
630 |
| - expect(setterParamTypeRef1.isTypeReference).toBe(true); |
631 |
| - expect(setterParamTypeRef1.isValueReference).toBe(true); |
632 |
| - |
633 |
| - const setterParamTypeRef2 = classAScope.childScopes[6].references[0]; |
634 |
| - expect(setterParamTypeRef2.identifier.name).toBe('Type6'); |
635 |
| - expect(setterParamTypeRef2.isTypeReference).toBe(true); |
636 |
| - expect(setterParamTypeRef2.isValueReference).toBe(true); |
637 |
| - |
638 |
| - const classBScope = scopeManager.globalScope!.childScopes[1]; |
639 |
| - |
640 |
| - const constructorParamTypeRef1 = classBScope.childScopes[0].references[0]; |
641 |
| - expect(constructorParamTypeRef1.identifier.name).toBe('c'); |
642 |
| - expect(constructorParamTypeRef1.isTypeReference).toBe(true); |
643 |
| - expect(constructorParamTypeRef1.isValueReference).toBe(true); |
644 |
| - |
645 |
| - const setterParamTypeRef3 = classBScope.childScopes[1].references[0]; |
646 |
| - // eslint-disable-next-line @typescript-eslint/internal/prefer-ast-types-enum |
647 |
| - expect(setterParamTypeRef3.identifier.name).toBe('Type'); |
648 |
| - expect(setterParamTypeRef3.isTypeReference).toBe(true); |
649 |
| - expect(setterParamTypeRef3.isValueReference).toBe(false); |
650 |
| - |
651 |
| - const classCScope = scopeManager.globalScope!.childScopes[2]; |
652 |
| - |
653 |
| - const methodReturnTypeRef1 = classCScope.childScopes[0].references[0]; |
654 |
| - expect(methodReturnTypeRef1.identifier.name).toBe('TypeC'); |
655 |
| - expect(methodReturnTypeRef1.isTypeReference).toBe(true); |
656 |
| - expect(methodReturnTypeRef1.isValueReference).toBe(false); |
| 592 | + { |
| 593 | + emitDecoratorMetadata: true, |
| 594 | + }, |
| 595 | + ); |
| 596 | + |
| 597 | + const classAScope = scopeManager.globalScope!.childScopes[0]; |
| 598 | + const propertyTypeRef = classAScope.references[2]; |
| 599 | + expect(propertyTypeRef.identifier.name).toBe('a'); |
| 600 | + expect(propertyTypeRef.isTypeReference).toBe(true); |
| 601 | + expect(propertyTypeRef.isValueReference).toBe(true); |
| 602 | + |
| 603 | + const setterParamTypeRef = classAScope.childScopes[0].references[0]; |
| 604 | + expect(setterParamTypeRef.identifier.name).toBe('SetterType'); |
| 605 | + expect(setterParamTypeRef.isTypeReference).toBe(true); |
| 606 | + expect(setterParamTypeRef.isValueReference).toBe(false); |
| 607 | + |
| 608 | + const constructorParamTypeRef = |
| 609 | + classAScope.childScopes[1].references[0]; |
| 610 | + expect(constructorParamTypeRef.identifier.name).toBe('b'); |
| 611 | + expect(constructorParamTypeRef.isTypeReference).toBe(true); |
| 612 | + expect(constructorParamTypeRef.isValueReference).toBe(true); |
| 613 | + |
| 614 | + const methodParamTypeRef = classAScope.childScopes[2].references[0]; |
| 615 | + expect(methodParamTypeRef.identifier.name).toBe('Type2'); |
| 616 | + expect(methodParamTypeRef.isTypeReference).toBe(true); |
| 617 | + expect(methodParamTypeRef.isValueReference).toBe(true); |
| 618 | + const methodParamTypeRef0 = classAScope.childScopes[2].references[2]; |
| 619 | + expect(methodParamTypeRef0.identifier.name).toBe('Type0'); |
| 620 | + expect(methodParamTypeRef0.isTypeReference).toBe(true); |
| 621 | + expect(methodParamTypeRef0.isValueReference).toBe(true); |
| 622 | + |
| 623 | + const methodParamTypeRef1 = classAScope.childScopes[3].references[0]; |
| 624 | + expect(methodParamTypeRef1.identifier.name).toBe('Type3'); |
| 625 | + expect(methodParamTypeRef1.isTypeReference).toBe(true); |
| 626 | + expect(methodParamTypeRef1.isValueReference).toBe(true); |
| 627 | + |
| 628 | + const methodReturnTypeRef = classAScope.childScopes[4].references[0]; |
| 629 | + expect(methodReturnTypeRef.identifier.name).toBe('Type4'); |
| 630 | + expect(methodReturnTypeRef.isTypeReference).toBe(true); |
| 631 | + expect(methodReturnTypeRef.isValueReference).toBe(true); |
| 632 | + |
| 633 | + const setterParamTypeRef1 = classAScope.childScopes[5].references[0]; |
| 634 | + expect(setterParamTypeRef1.identifier.name).toBe('Type5'); |
| 635 | + expect(setterParamTypeRef1.isTypeReference).toBe(true); |
| 636 | + expect(setterParamTypeRef1.isValueReference).toBe(true); |
| 637 | + |
| 638 | + const setterParamTypeRef2 = classAScope.childScopes[6].references[0]; |
| 639 | + expect(setterParamTypeRef2.identifier.name).toBe('Type6'); |
| 640 | + expect(setterParamTypeRef2.isTypeReference).toBe(true); |
| 641 | + expect(setterParamTypeRef2.isValueReference).toBe(true); |
| 642 | + |
| 643 | + const classBScope = scopeManager.globalScope!.childScopes[1]; |
| 644 | + |
| 645 | + const constructorParamTypeRef1 = |
| 646 | + classBScope.childScopes[0].references[0]; |
| 647 | + expect(constructorParamTypeRef1.identifier.name).toBe('c'); |
| 648 | + expect(constructorParamTypeRef1.isTypeReference).toBe(true); |
| 649 | + expect(constructorParamTypeRef1.isValueReference).toBe(true); |
| 650 | + |
| 651 | + const setterParamTypeRef3 = classBScope.childScopes[1].references[0]; |
| 652 | + // eslint-disable-next-line @typescript-eslint/internal/prefer-ast-types-enum |
| 653 | + expect(setterParamTypeRef3.identifier.name).toBe('Type'); |
| 654 | + expect(setterParamTypeRef3.isTypeReference).toBe(true); |
| 655 | + expect(setterParamTypeRef3.isValueReference).toBe(false); |
| 656 | + |
| 657 | + const classCScope = scopeManager.globalScope!.childScopes[2]; |
| 658 | + |
| 659 | + const methodReturnTypeRef1 = classCScope.childScopes[0].references[0]; |
| 660 | + expect(methodReturnTypeRef1.identifier.name).toBe('TypeC'); |
| 661 | + expect(methodReturnTypeRef1.isTypeReference).toBe(true); |
| 662 | + expect(methodReturnTypeRef1.isValueReference).toBe(false); |
| 663 | + }); |
657 | 664 | });
|
658 |
| - }); |
| 665 | + } |
659 | 666 | });
|
0 commit comments