Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit ba36127

Browse files
dgp1130atscott
authored andcommitted
fix(core): add noSideEffects() to ɵɵdefineComponent() (#35769)
This marks the function are "pure" and eligible to be tree shaken by Closure. Without this, initializing `ngDevMode` is considered a side effect which prevents this function from being tree shaken and also any component which calls it. PR Close #35769
1 parent dc6a791 commit ba36127

File tree

1 file changed

+52
-52
lines changed

1 file changed

+52
-52
lines changed

packages/core/src/render3/definition.ts

Lines changed: 52 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -289,56 +289,56 @@ export function ɵɵdefineComponent<T>(componentDefinition: {
289289
*/
290290
schemas?: SchemaMetadata[] | null;
291291
}): never {
292-
// Initialize ngDevMode. This must be the first statement in ɵɵdefineComponent.
293-
// See the `initNgDevMode` docstring for more information.
294-
(typeof ngDevMode === 'undefined' || ngDevMode) && initNgDevMode();
295-
296-
const type = componentDefinition.type;
297-
const typePrototype = type.prototype;
298-
const declaredInputs: {[key: string]: string} = {} as any;
299-
const def: Mutable<ComponentDef<any>, keyof ComponentDef<any>> = {
300-
type: type,
301-
providersResolver: null,
302-
decls: componentDefinition.decls,
303-
vars: componentDefinition.vars,
304-
factory: null,
305-
template: componentDefinition.template || null !,
306-
consts: componentDefinition.consts || null,
307-
ngContentSelectors: componentDefinition.ngContentSelectors,
308-
hostBindings: componentDefinition.hostBindings || null,
309-
hostVars: componentDefinition.hostVars || 0,
310-
hostAttrs: componentDefinition.hostAttrs || null,
311-
contentQueries: componentDefinition.contentQueries || null,
312-
declaredInputs: declaredInputs,
313-
inputs: null !, // assigned in noSideEffects
314-
outputs: null !, // assigned in noSideEffects
315-
exportAs: componentDefinition.exportAs || null,
316-
onChanges: null,
317-
onInit: typePrototype.ngOnInit || null,
318-
doCheck: typePrototype.ngDoCheck || null,
319-
afterContentInit: typePrototype.ngAfterContentInit || null,
320-
afterContentChecked: typePrototype.ngAfterContentChecked || null,
321-
afterViewInit: typePrototype.ngAfterViewInit || null,
322-
afterViewChecked: typePrototype.ngAfterViewChecked || null,
323-
onDestroy: typePrototype.ngOnDestroy || null,
324-
onPush: componentDefinition.changeDetection === ChangeDetectionStrategy.OnPush,
325-
directiveDefs: null !, // assigned in noSideEffects
326-
pipeDefs: null !, // assigned in noSideEffects
327-
selectors: componentDefinition.selectors || EMPTY_ARRAY,
328-
viewQuery: componentDefinition.viewQuery || null,
329-
features: componentDefinition.features as DirectiveDefFeature[] || null,
330-
data: componentDefinition.data || {},
331-
// TODO(misko): convert ViewEncapsulation into const enum so that it can be used directly in the
332-
// next line. Also `None` should be 0 not 2.
333-
encapsulation: componentDefinition.encapsulation || ViewEncapsulation.Emulated,
334-
id: 'c',
335-
styles: componentDefinition.styles || EMPTY_ARRAY,
336-
_: null as never,
337-
setInput: null,
338-
schemas: componentDefinition.schemas || null,
339-
tView: null,
340-
};
341-
def._ = noSideEffects(() => {
292+
return noSideEffects(() => {
293+
// Initialize ngDevMode. This must be the first statement in ɵɵdefineComponent.
294+
// See the `initNgDevMode` docstring for more information.
295+
(typeof ngDevMode === 'undefined' || ngDevMode) && initNgDevMode();
296+
297+
const type = componentDefinition.type;
298+
const typePrototype = type.prototype;
299+
const declaredInputs: {[key: string]: string} = {} as any;
300+
const def: Mutable<ComponentDef<any>, keyof ComponentDef<any>> = {
301+
type: type,
302+
providersResolver: null,
303+
decls: componentDefinition.decls,
304+
vars: componentDefinition.vars,
305+
factory: null,
306+
template: componentDefinition.template || null !,
307+
consts: componentDefinition.consts || null,
308+
ngContentSelectors: componentDefinition.ngContentSelectors,
309+
hostBindings: componentDefinition.hostBindings || null,
310+
hostVars: componentDefinition.hostVars || 0,
311+
hostAttrs: componentDefinition.hostAttrs || null,
312+
contentQueries: componentDefinition.contentQueries || null,
313+
declaredInputs: declaredInputs,
314+
inputs: null !, // assigned in noSideEffects
315+
outputs: null !, // assigned in noSideEffects
316+
exportAs: componentDefinition.exportAs || null,
317+
onChanges: null,
318+
onInit: typePrototype.ngOnInit || null,
319+
doCheck: typePrototype.ngDoCheck || null,
320+
afterContentInit: typePrototype.ngAfterContentInit || null,
321+
afterContentChecked: typePrototype.ngAfterContentChecked || null,
322+
afterViewInit: typePrototype.ngAfterViewInit || null,
323+
afterViewChecked: typePrototype.ngAfterViewChecked || null,
324+
onDestroy: typePrototype.ngOnDestroy || null,
325+
onPush: componentDefinition.changeDetection === ChangeDetectionStrategy.OnPush,
326+
directiveDefs: null !, // assigned in noSideEffects
327+
pipeDefs: null !, // assigned in noSideEffects
328+
selectors: componentDefinition.selectors || EMPTY_ARRAY,
329+
viewQuery: componentDefinition.viewQuery || null,
330+
features: componentDefinition.features as DirectiveDefFeature[] || null,
331+
data: componentDefinition.data || {},
332+
// TODO(misko): convert ViewEncapsulation into const enum so that it can be used directly in
333+
// the next line. Also `None` should be 0 not 2.
334+
encapsulation: componentDefinition.encapsulation || ViewEncapsulation.Emulated,
335+
id: 'c',
336+
styles: componentDefinition.styles || EMPTY_ARRAY,
337+
_: null as never,
338+
setInput: null,
339+
schemas: componentDefinition.schemas || null,
340+
tView: null,
341+
};
342342
const directiveTypes = componentDefinition.directives !;
343343
const feature = componentDefinition.features;
344344
const pipeTypes = componentDefinition.pipes !;
@@ -353,9 +353,9 @@ export function ɵɵdefineComponent<T>(componentDefinition: {
353353
def.pipeDefs = pipeTypes ?
354354
() => (typeof pipeTypes === 'function' ? pipeTypes() : pipeTypes).map(extractPipeDef) :
355355
null;
356-
}) as never;
357356

358-
return def as never;
357+
return def as never;
358+
});
359359
}
360360

361361
/**

0 commit comments

Comments
 (0)