Skip to content

Commit 8c60b1e

Browse files
committed
feat: Prefix all private methods with _
Mangle _ props
1 parent e0aef03 commit 8c60b1e

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

70 files changed

+501
-494
lines changed

packages/browser/rollup.config.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,9 @@ const terserInstance = terser({
1515
// We need those full names to correctly detect our internal frames for stripping.
1616
// I listed all of them here just for the clarity sake, as they are all used in the frames manipulation process.
1717
reserved: ['captureException', 'captureMessage', 'sentryWrapped'],
18+
properties: {
19+
regex: /^_/,
20+
},
1821
},
1922
});
2023

packages/browser/src/backend.ts

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -36,16 +36,18 @@ export class BrowserBackend extends BaseBackend<BrowserOptions> {
3636
/**
3737
* @inheritdoc
3838
*/
39-
protected setupTransport(): Transport {
40-
if (!this.options.dsn) {
39+
protected _setupTransport(): Transport {
40+
if (!this._options.dsn) {
4141
// We return the noop transport here in case there is no Dsn.
42-
return super.setupTransport();
42+
return super._setupTransport();
4343
}
4444

45-
const transportOptions = this.options.transportOptions ? this.options.transportOptions : { dsn: this.options.dsn };
45+
const transportOptions = this._options.transportOptions
46+
? this._options.transportOptions
47+
: { dsn: this._options.dsn };
4648

47-
if (this.options.transport) {
48-
return new this.options.transport(transportOptions);
49+
if (this._options.transport) {
50+
return new this._options.transport(transportOptions);
4951
} else if (supportsBeacon()) {
5052
return new BeaconTransport(transportOptions);
5153
} else if (supportsFetch()) {
@@ -65,7 +67,7 @@ export class BrowserBackend extends BaseBackend<BrowserOptions> {
6567
const errorEvent = exception as ErrorEvent;
6668
exception = errorEvent.error; // tslint:disable-line:no-parameter-reassignment
6769
event = eventFromStacktrace(computeStackTrace(exception as Error));
68-
return SyncPromise.resolve(this.buildEvent(event, hint));
70+
return SyncPromise.resolve(this._buildEvent(event, hint));
6971
} else if (isDOMError(exception as DOMError) || isDOMException(exception as DOMException)) {
7072
// If it is a DOMError or DOMException (which are legacy APIs, but still supported in some browsers)
7173
// then we just extract the name and message, as they don't provide anything else
@@ -77,12 +79,12 @@ export class BrowserBackend extends BaseBackend<BrowserOptions> {
7779

7880
return this.eventFromMessage(message, Severity.Error, hint).then(messageEvent => {
7981
addExceptionTypeValue(messageEvent, message);
80-
return SyncPromise.resolve(this.buildEvent(messageEvent, hint));
82+
return SyncPromise.resolve(this._buildEvent(messageEvent, hint));
8183
});
8284
} else if (isError(exception as Error)) {
8385
// we have a real Error object, do nothing
8486
event = eventFromStacktrace(computeStackTrace(exception as Error));
85-
return SyncPromise.resolve(this.buildEvent(event, hint));
87+
return SyncPromise.resolve(this._buildEvent(event, hint));
8688
} else if (isPlainObject(exception as {}) && hint && hint.syntheticException) {
8789
// If it is plain Object, serialize it manually and extract options
8890
// This will allow us to group events based on top-level keys
@@ -94,7 +96,7 @@ export class BrowserBackend extends BaseBackend<BrowserOptions> {
9496
synthetic: true,
9597
type: 'generic',
9698
});
97-
return SyncPromise.resolve(this.buildEvent(event, hint));
99+
return SyncPromise.resolve(this._buildEvent(event, hint));
98100
}
99101

100102
// If none of previous checks were valid, then it means that
@@ -110,14 +112,14 @@ export class BrowserBackend extends BaseBackend<BrowserOptions> {
110112
synthetic: true,
111113
type: 'generic',
112114
});
113-
return SyncPromise.resolve(this.buildEvent(messageEvent, hint));
115+
return SyncPromise.resolve(this._buildEvent(messageEvent, hint));
114116
});
115117
}
116118

117119
/**
118120
* This is an internal helper function that creates an event.
119121
*/
120-
private buildEvent(event: Event, hint?: EventHint): Event {
122+
private _buildEvent(event: Event, hint?: EventHint): Event {
121123
return {
122124
...event,
123125
event_id: hint && hint.event_id,
@@ -134,7 +136,7 @@ export class BrowserBackend extends BaseBackend<BrowserOptions> {
134136
message,
135137
};
136138

137-
if (this.options.attachStacktrace && hint && hint.syntheticException) {
139+
if (this._options.attachStacktrace && hint && hint.syntheticException) {
138140
const stacktrace = computeStackTrace(hint.syntheticException);
139141
const frames = prepareFramesForEvent(stacktrace.stack);
140142
event.stacktrace = {

packages/browser/src/client.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ export class BrowserClient extends BaseClient<BrowserBackend, BrowserOptions> {
5050
/**
5151
* @inheritDoc
5252
*/
53-
protected prepareEvent(event: Event, scope?: Scope, hint?: EventHint): SyncPromise<Event | null> {
53+
protected _prepareEvent(event: Event, scope?: Scope, hint?: EventHint): SyncPromise<Event | null> {
5454
event.platform = event.platform || 'javascript';
5555
event.sdk = {
5656
...event.sdk,
@@ -65,7 +65,7 @@ export class BrowserClient extends BaseClient<BrowserBackend, BrowserOptions> {
6565
version: SDK_VERSION,
6666
};
6767

68-
return super.prepareEvent(event, scope, hint);
68+
return super._prepareEvent(event, scope, hint);
6969
}
7070

7171
/**
@@ -80,7 +80,7 @@ export class BrowserClient extends BaseClient<BrowserBackend, BrowserOptions> {
8080
return;
8181
}
8282

83-
if (!this.isEnabled()) {
83+
if (!this._isEnabled()) {
8484
logger.error('Trying to call showReportDialog with Sentry Client is disabled');
8585
return;
8686
}

packages/browser/src/integrations/breadcrumbs.ts

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -48,13 +48,13 @@ export class Breadcrumbs implements Integration {
4848
public static id: string = 'Breadcrumbs';
4949

5050
/** JSDoc */
51-
private readonly options: BreadcrumbIntegrations;
51+
private readonly _options: BreadcrumbIntegrations;
5252

5353
/**
5454
* @inheritDoc
5555
*/
5656
public constructor(options?: BreadcrumbIntegrations) {
57-
this.options = {
57+
this._options = {
5858
beacon: true,
5959
console: true,
6060
dom: true,
@@ -67,7 +67,7 @@ export class Breadcrumbs implements Integration {
6767
}
6868

6969
/** JSDoc */
70-
private instrumentBeacon(): void {
70+
private _instrumentBeacon(): void {
7171
if (!supportsBeacon()) {
7272
return;
7373
}
@@ -117,7 +117,7 @@ export class Breadcrumbs implements Integration {
117117
}
118118

119119
/** JSDoc */
120-
private instrumentConsole(): void {
120+
private _instrumentConsole(): void {
121121
if (!('console' in global)) {
122122
return;
123123
}
@@ -162,7 +162,7 @@ export class Breadcrumbs implements Integration {
162162
}
163163

164164
/** JSDoc */
165-
private instrumentDOM(): void {
165+
private _instrumentDOM(): void {
166166
if (!('document' in global)) {
167167
return;
168168
}
@@ -173,7 +173,7 @@ export class Breadcrumbs implements Integration {
173173
}
174174

175175
/** JSDoc */
176-
private instrumentFetch(): void {
176+
private _instrumentFetch(): void {
177177
if (!supportsNativeFetch()) {
178178
return;
179179
}
@@ -260,7 +260,7 @@ export class Breadcrumbs implements Integration {
260260
}
261261

262262
/** JSDoc */
263-
private instrumentHistory(): void {
263+
private _instrumentHistory(): void {
264264
if (!supportsHistory()) {
265265
return;
266266
}
@@ -330,7 +330,7 @@ export class Breadcrumbs implements Integration {
330330
}
331331

332332
/** JSDoc */
333-
private instrumentXHR(): void {
333+
private _instrumentXHR(): void {
334334
if (!('XMLHttpRequest' in global)) {
335335
return;
336336
}
@@ -471,23 +471,23 @@ export class Breadcrumbs implements Integration {
471471
* - History API
472472
*/
473473
public setupOnce(): void {
474-
if (this.options.console) {
475-
this.instrumentConsole();
474+
if (this._options.console) {
475+
this._instrumentConsole();
476476
}
477-
if (this.options.dom) {
478-
this.instrumentDOM();
477+
if (this._options.dom) {
478+
this._instrumentDOM();
479479
}
480-
if (this.options.xhr) {
481-
this.instrumentXHR();
480+
if (this._options.xhr) {
481+
this._instrumentXHR();
482482
}
483-
if (this.options.fetch) {
484-
this.instrumentFetch();
483+
if (this._options.fetch) {
484+
this._instrumentFetch();
485485
}
486-
if (this.options.beacon) {
487-
this.instrumentBeacon();
486+
if (this._options.beacon) {
487+
this._instrumentBeacon();
488488
}
489-
if (this.options.history) {
490-
this.instrumentHistory();
489+
if (this._options.history) {
490+
this._instrumentHistory();
491491
}
492492
}
493493
}

packages/browser/src/integrations/globalhandlers.ts

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -32,11 +32,11 @@ export class GlobalHandlers implements Integration {
3232
public static id: string = 'GlobalHandlers';
3333

3434
/** JSDoc */
35-
private readonly options: GlobalHandlersIntegrations;
35+
private readonly _options: GlobalHandlersIntegrations;
3636

3737
/** JSDoc */
3838
public constructor(options?: GlobalHandlersIntegrations) {
39-
this.options = {
39+
this._options = {
4040
onerror: true,
4141
onunhandledrejection: true,
4242
...options,
@@ -68,16 +68,19 @@ export class GlobalHandlers implements Integration {
6868
}
6969
const self = getCurrentHub().getIntegration(GlobalHandlers);
7070
if (self) {
71-
getCurrentHub().captureEvent(self.eventFromGlobalHandler(stack), { originalException: error, data: { stack } });
71+
getCurrentHub().captureEvent(self._eventFromGlobalHandler(stack), {
72+
data: { stack },
73+
originalException: error,
74+
});
7275
}
7376
});
7477

75-
if (this.options.onerror) {
78+
if (this._options.onerror) {
7679
logger.log('Global Handler attached: onerror');
7780
installGlobalHandler();
7881
}
7982

80-
if (this.options.onunhandledrejection) {
83+
if (this._options.onunhandledrejection) {
8184
logger.log('Global Handler attached: onunhandledrejection');
8285
installGlobalUnhandledRejectionHandler();
8386
}
@@ -88,7 +91,7 @@ export class GlobalHandlers implements Integration {
8891
*
8992
* @param stacktrace TraceKitStackTrace to be converted to an Event.
9093
*/
91-
private eventFromGlobalHandler(stacktrace: TraceKitStackTrace): Event {
94+
private _eventFromGlobalHandler(stacktrace: TraceKitStackTrace): Event {
9295
const event = eventFromStacktrace(stacktrace);
9396

9497
const data: { [key: string]: string } = {

packages/browser/src/integrations/linkederrors.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,19 +21,19 @@ export class LinkedErrors implements Integration {
2121
/**
2222
* @inheritDoc
2323
*/
24-
private readonly key: string;
24+
private readonly _key: string;
2525

2626
/**
2727
* @inheritDoc
2828
*/
29-
private readonly limit: number;
29+
private readonly _limit: number;
3030

3131
/**
3232
* @inheritDoc
3333
*/
3434
public constructor(options: { key?: string; limit?: number } = {}) {
35-
this.key = options.key || DEFAULT_KEY;
36-
this.limit = options.limit || DEFAULT_LIMIT;
35+
this._key = options.key || DEFAULT_KEY;
36+
this._limit = options.limit || DEFAULT_LIMIT;
3737
}
3838

3939
/**
@@ -56,7 +56,7 @@ export class LinkedErrors implements Integration {
5656
if (!event.exception || !event.exception.values || !hint || !(hint.originalException instanceof Error)) {
5757
return event;
5858
}
59-
const linkedErrors = this.walkErrorTree(hint.originalException, this.key);
59+
const linkedErrors = this.walkErrorTree(hint.originalException, this._key);
6060
event.exception.values = [...linkedErrors, ...event.exception.values];
6161
return event;
6262
}
@@ -65,7 +65,7 @@ export class LinkedErrors implements Integration {
6565
* @inheritDoc
6666
*/
6767
public walkErrorTree(error: ExtendedError, key: string, stack: Exception[] = []): Exception[] {
68-
if (!(error[key] instanceof Error) || stack.length + 1 >= this.limit) {
68+
if (!(error[key] instanceof Error) || stack.length + 1 >= this._limit) {
6969
return stack;
7070
}
7171
const stacktrace = computeStackTrace(error[key]);

packages/browser/src/integrations/trycatch.ts

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import { breadcrumbEventHandler, keypressEventHandler, wrap } from './helpers';
66
/** Wrap timer functions and event targets to catch errors and provide better meta data */
77
export class TryCatch implements Integration {
88
/** JSDoc */
9-
private ignoreOnError: number = 0;
9+
private _ignoreOnError: number = 0;
1010

1111
/**
1212
* @inheritDoc
@@ -19,7 +19,7 @@ export class TryCatch implements Integration {
1919
public static id: string = 'TryCatch';
2020

2121
/** JSDoc */
22-
private wrapTimeFunction(original: () => void): () => number {
22+
private _wrapTimeFunction(original: () => void): () => number {
2323
return function(this: any, ...args: any[]): number {
2424
const originalCallback = args[0];
2525
args[0] = wrap(originalCallback, {
@@ -34,7 +34,7 @@ export class TryCatch implements Integration {
3434
}
3535

3636
/** JSDoc */
37-
private wrapRAF(original: any): (callback: () => void) => any {
37+
private _wrapRAF(original: any): (callback: () => void) => any {
3838
return function(this: any, callback: () => void): () => void {
3939
return original(
4040
wrap(callback, {
@@ -52,7 +52,7 @@ export class TryCatch implements Integration {
5252
}
5353

5454
/** JSDoc */
55-
private wrapEventTarget(target: string): void {
55+
private _wrapEventTarget(target: string): void {
5656
const global = getGlobalObject() as { [key: string]: any };
5757
const proto = global[target] && global[target].prototype;
5858

@@ -168,13 +168,13 @@ export class TryCatch implements Integration {
168168
* and provide better metadata.
169169
*/
170170
public setupOnce(): void {
171-
this.ignoreOnError = this.ignoreOnError;
171+
this._ignoreOnError = this._ignoreOnError;
172172

173173
const global = getGlobalObject();
174174

175-
fill(global, 'setTimeout', this.wrapTimeFunction.bind(this));
176-
fill(global, 'setInterval', this.wrapTimeFunction.bind(this));
177-
fill(global, 'requestAnimationFrame', this.wrapRAF.bind(this));
175+
fill(global, 'setTimeout', this._wrapTimeFunction.bind(this));
176+
fill(global, 'setInterval', this._wrapTimeFunction.bind(this));
177+
fill(global, 'requestAnimationFrame', this._wrapRAF.bind(this));
178178

179179
[
180180
'EventTarget',
@@ -206,7 +206,7 @@ export class TryCatch implements Integration {
206206
'XMLHttpRequest',
207207
'XMLHttpRequestEventTarget',
208208
'XMLHttpRequestUpload',
209-
].forEach(this.wrapEventTarget.bind(this));
209+
].forEach(this._wrapEventTarget.bind(this));
210210
}
211211
}
212212

packages/browser/src/transports/base.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ export abstract class BaseTransport implements Transport {
1111
public url: string;
1212

1313
/** A simple buffer holding all requests. */
14-
protected readonly buffer: PromiseBuffer<Response> = new PromiseBuffer(30);
14+
protected readonly _buffer: PromiseBuffer<Response> = new PromiseBuffer(30);
1515

1616
public constructor(public options: TransportOptions) {
1717
this.url = new API(this.options.dsn).getStoreEndpointWithUrlEncodedAuth();
@@ -28,6 +28,6 @@ export abstract class BaseTransport implements Transport {
2828
* @inheritDoc
2929
*/
3030
public async close(timeout?: number): Promise<boolean> {
31-
return this.buffer.drain(timeout);
31+
return this._buffer.drain(timeout);
3232
}
3333
}

0 commit comments

Comments
 (0)