also looking at this
fix(extractor): keep a protected constructor protected
#3125
2 files
+77
-2
| @@ -2723,12 +2723,13 @@ function scanDeclarationsInternal(_source: string, _filename: string, _keepComme | ||
| 2723 | 2723 | let isOverride = false |
| 2724 | 2724 | let isAccessor = false |
| 2725 | 2725 | let isAsync = false |
| 2726 | let protectedEnd = -1 | |
| 2726 | 2727 | |
| 2727 | 2728 | const modLoop = true |
| 2728 | 2729 | while (modLoop) { |
| 2729 | 2730 | skipWhitespaceAndComments() |
| 2730 | 2731 | if (matchWord('private')) { isPrivate = true; pos += 7; continue } |
| 2731 | if (matchWord('protected')) { isProtected = true; pos += 9; continue } | |
| 2732 | if (matchWord('protected')) { isProtected = true; pos += 9; protectedEnd = pos; continue } | |
| 2732 | 2733 | if (matchWord('public')) { pos += 6; continue } |
| 2733 | 2734 | if (matchWord('static')) { isStatic = true; pos += 6; continue } |
| 2734 | 2735 | if (matchWord('abstract')) { isAbstract = true; pos += 8; continue } |
| @@ -2769,6 +2770,9 @@ function scanDeclarationsInternal(_source: string, _filename: string, _keepComme | ||
| 2769 | 2770 | |
| 2770 | 2771 | // Detect member type |
| 2771 | 2772 | if (matchWord('constructor')) { |
| 2773 | // A `protected` with a line break after it is a field of that name | |
| 2774 | // (TypeScript reads a modifier only on the same line as what it modifies). | |
| 2775 | const isProtectedConstructor = isProtected && !/[\n\r\u2028\u2029]/.test(source.slice(protectedEnd, pos)) | |
| 2772 | 2776 | pos += 11 |
| 2773 | 2777 | skipWhitespaceAndComments() |
| 2774 | 2778 | const rawParams = extractParamList() |
| @@ -2785,8 +2789,10 @@ function scanDeclarationsInternal(_source: string, _filename: string, _keepComme | ||
| 2785 | 2789 | pos++ |
| 2786 | 2790 | } |
| 2787 | 2791 | |
| 2792 | // A protected constructor stays protected: public, it would let any | |
| 2793 | // caller construct a class only its subclasses may. | |
| 2788 | 2794 | const dtsParams = buildDtsParams(rawParams) |
| 2789 | members.push(` constructor${dtsParams};`) | |
| 2795 | members.push(` ${isProtectedConstructor ? 'protected ' : ''}constructor${dtsParams};`) | |
| 2790 | 2796 | } |
| 2791 | 2797 | else if (matchWord('get')) { |
| 2792 | 2798 | pos += 3 |