perf(core): use `ngDevMode` to tree-shake error messages (#38612)

This commit adds `ngDevMode` guard to throw some errors only in dev mode
(similar to how things work in other parts of Ivy runtime code). The
`ngDevMode` flag helps to tree-shake these error messages from production
builds (in dev mode everything will work as it works right now) to decrease
production bundle size.

PR Close #38612
This commit is contained in:
Sonu Kapoor 2020-08-27 08:40:19 -04:00 committed by atscott
parent 7869de6136
commit 1150649139
7 changed files with 14 additions and 27 deletions

View File

@ -21,7 +21,7 @@
"master": {
"uncompressed": {
"runtime-es2015": 1485,
"main-es2015": 147573,
"main-es2015": 146989,
"polyfills-es2015": 36571
}
}

View File

@ -384,7 +384,7 @@ export class R3Injector {
let multiRecord = this.records.get(token);
if (multiRecord) {
// It has. Throw a nice error if
if (multiRecord.multi === undefined) {
if (ngDevMode && multiRecord.multi === undefined) {
throwMixedMultiProviderError();
}
} else {
@ -396,7 +396,7 @@ export class R3Injector {
multiRecord.multi!.push(provider);
} else {
const existing = this.records.get(token);
if (existing && existing.multi !== undefined) {
if (ngDevMode && existing && existing.multi !== undefined) {
throwMixedMultiProviderError();
}
}
@ -404,7 +404,7 @@ export class R3Injector {
}
private hydrate<T>(token: Type<T>|InjectionToken<T>, record: Record<T>): T {
if (record.value === CIRCULAR) {
if (ngDevMode && record.value === CIRCULAR) {
throwCyclicDependencyError(stringify(token));
} else if (record.value === NOT_YET) {
record.value = CIRCULAR;
@ -511,7 +511,7 @@ export function providerToFactory(
const classRef = resolveForwardRef(
provider &&
((provider as StaticClassProvider | ClassProvider).useClass || provider.provide));
if (!classRef) {
if (ngDevMode && !classRef) {
throwInvalidProviderError(ngModuleType, providers, provider);
}
if (hasDeps(provider)) {

View File

@ -1375,6 +1375,7 @@ function findDirectiveDefMatches(
ngDevMode &&
assertNodeOfPossibleTypes(
tNode, [TNodeType.Element, TNodeType.ElementContainer, TNodeType.Container]);
const registry = tView.directiveRegistry;
let matches: any[]|null = null;
if (registry) {
@ -1385,13 +1386,14 @@ function findDirectiveDefMatches(
diPublicInInjector(getOrCreateNodeInjectorForNode(tNode, viewData), tView, def.type);
if (isComponentDef(def)) {
ngDevMode &&
assertNodeOfPossibleTypes(
tNode, [TNodeType.Element],
`"${tNode.tagName}" tags cannot be used as component hosts. ` +
`Please use a different tag to activate the ${
stringify(def.type)} component.`);
if (tNode.flags & TNodeFlags.isComponentHost) throwMultipleComponentError(tNode);
if (ngDevMode) {
assertNodeOfPossibleTypes(
tNode, [TNodeType.Element],
`"${tNode.tagName}" tags cannot be used as component hosts. ` +
`Please use a different tag to activate the ${stringify(def.type)} component.`);
if (tNode.flags & TNodeFlags.isComponentHost) throwMultipleComponentError(tNode);
}
markAsComponentHost(tView, tNode);
// The component is always stored first with directives after.
matches.unshift(def);

View File

@ -350,9 +350,6 @@
{
"name": "setUpAttributes"
},
{
"name": "throwMultipleComponentError"
},
{
"name": "unwrapRNode"
},

View File

@ -1586,12 +1586,6 @@
{
"name": "syncPendingControls"
},
{
"name": "throwMixedMultiProviderError"
},
{
"name": "throwMultipleComponentError"
},
{
"name": "toObservable"
},

View File

@ -128,9 +128,6 @@
{
"name": "stringify"
},
{
"name": "throwMixedMultiProviderError"
},
{
"name": "ɵɵdefineInjectable"
},

View File

@ -713,9 +713,6 @@
{
"name": "stringifyForError"
},
{
"name": "throwMultipleComponentError"
},
{
"name": "toTStylingRange"
},