Skip to content

Commit 85c28e5

Browse files
committed
improve printing of implicit public cases
1 parent d481999 commit 85c28e5

File tree

2 files changed

+33
-6
lines changed

2 files changed

+33
-6
lines changed

build/lib/mangleTypeScript.js

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ class ClassData {
136136
return type === 2 /* FieldType.Private */
137137
|| type === 1 /* FieldType.Protected */;
138138
}
139-
static makeImplicitPublicActuallyPublic(data) {
139+
static makeImplicitPublicActuallyPublic(data, reportViolation) {
140140
// TS-HACK
141141
// A subtype can make an inherited protected field public. To prevent accidential
142142
// mangling of public fields we mark the original (protected) fields as public...
@@ -147,7 +147,9 @@ class ClassData {
147147
let parent = data.parent;
148148
while (parent) {
149149
if (parent.fields.get(name)?.type === 1 /* FieldType.Protected */) {
150-
console.warn(`WARN: protected became PUBLIC: '${name}' defined ${parent.fileName}#${info.pos}, PUBLIC via ${data.fileName} (${info.pos})`);
150+
const parentPos = parent.node.getSourceFile().getLineAndCharacterOfPosition(parent.fields.get(name).pos);
151+
const infoPos = data.node.getSourceFile().getLineAndCharacterOfPosition(info.pos);
152+
reportViolation(`'${name}' from ${parent.fileName}:${parentPos.line + 1}`, `${data.fileName}:${infoPos.line + 1}`);
151153
parent.fields.get(name).type = 0 /* FieldType.Public */;
152154
}
153155
parent = parent.parent;
@@ -361,8 +363,20 @@ class Mangler {
361363
setupParents(data);
362364
}
363365
// STEP: make implicit public (actually protected) field really public
366+
const violations = new Map();
364367
for (const data of this.allClassDataByKey.values()) {
365-
ClassData.makeImplicitPublicActuallyPublic(data);
368+
ClassData.makeImplicitPublicActuallyPublic(data, (what, why) => {
369+
const arr = violations.get(what);
370+
if (arr) {
371+
arr.push(why);
372+
}
373+
else {
374+
violations.set(what, [why]);
375+
}
376+
});
377+
}
378+
for (const [why, whys] of violations) {
379+
this.log(`WARN: ${why} became PUBLIC because of: ${whys.join(' , ')}`);
366380
}
367381
// STEP: compute replacement names for each class
368382
for (const data of this.allClassDataByKey.values()) {

build/lib/mangleTypeScript.ts

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ class ClassData {
154154
;
155155
}
156156

157-
static makeImplicitPublicActuallyPublic(data: ClassData): void {
157+
static makeImplicitPublicActuallyPublic(data: ClassData, reportViolation: (what: string, why: string) => void): void {
158158
// TS-HACK
159159
// A subtype can make an inherited protected field public. To prevent accidential
160160
// mangling of public fields we mark the original (protected) fields as public...
@@ -165,7 +165,9 @@ class ClassData {
165165
let parent: ClassData | undefined = data.parent;
166166
while (parent) {
167167
if (parent.fields.get(name)?.type === FieldType.Protected) {
168-
console.warn(`WARN: protected became PUBLIC: '${name}' defined ${parent.fileName}#${info.pos}, PUBLIC via ${data.fileName} (${info.pos})`);
168+
const parentPos = parent.node.getSourceFile().getLineAndCharacterOfPosition(parent.fields.get(name)!.pos);
169+
const infoPos = data.node.getSourceFile().getLineAndCharacterOfPosition(info.pos);
170+
reportViolation(`'${name}' from ${parent.fileName}:${parentPos.line + 1}`, `${data.fileName}:${infoPos.line + 1}`);
169171

170172
parent.fields.get(name)!.type = FieldType.Public;
171173
}
@@ -406,8 +408,19 @@ export class Mangler {
406408
}
407409

408410
// STEP: make implicit public (actually protected) field really public
411+
const violations = new Map<string, string[]>();
409412
for (const data of this.allClassDataByKey.values()) {
410-
ClassData.makeImplicitPublicActuallyPublic(data);
413+
ClassData.makeImplicitPublicActuallyPublic(data, (what, why) => {
414+
const arr = violations.get(what);
415+
if (arr) {
416+
arr.push(why);
417+
} else {
418+
violations.set(what, [why]);
419+
}
420+
});
421+
}
422+
for (const [why, whys] of violations) {
423+
this.log(`WARN: ${why} became PUBLIC because of: ${whys.join(' , ')}`);
411424
}
412425

413426
// STEP: compute replacement names for each class

0 commit comments

Comments
 (0)