ReviewOS

also looking at this

stacks/dtsx

fix(extractor): keep a protected constructor protected

#3125
Open mkantautas wants to merge fix/protected-constructor into main
2 files +77 -2
packages/dtsx/src/extractor/scanner.tsmodified+8-2
Changes to packages/dtsx/src/extractor/scanner.ts
@@ -2723,12 +2723,13 @@ function scanDeclarationsInternal(_source: string, _filename: string, _keepComme
27232723 let isOverride = false
27242724 let isAccessor = false
27252725 let isAsync = false
2726 let protectedEnd = -1
27262727
27272728 const modLoop = true
27282729 while (modLoop) {
27292730 skipWhitespaceAndComments()
27302731 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 }
27322733 if (matchWord('public')) { pos += 6; continue }
27332734 if (matchWord('static')) { isStatic = true; pos += 6; continue }
27342735 if (matchWord('abstract')) { isAbstract = true; pos += 8; continue }
@@ -2769,6 +2770,9 @@ function scanDeclarationsInternal(_source: string, _filename: string, _keepComme
27692770
27702771 // Detect member type
27712772 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))
27722776 pos += 11
27732777 skipWhitespaceAndComments()
27742778 const rawParams = extractParamList()
@@ -2785,8 +2789,10 @@ function scanDeclarationsInternal(_source: string, _filename: string, _keepComme
27852789 pos++
27862790 }
27872791
2792 // A protected constructor stays protected: public, it would let any
2793 // caller construct a class only its subclasses may.
27882794 const dtsParams = buildDtsParams(rawParams)
2789 members.push(` constructor${dtsParams};`)
2795 members.push(` ${isProtectedConstructor ? 'protected ' : ''}constructor${dtsParams};`)
27902796 }
27912797 else if (matchWord('get')) {
27922798 pos += 3