Skip to content

Commit 39a2c39

Browse files
chuckjazkara
authored andcommitted
feat(compiler): Added "strictMetadataEmit" option to ngc (angular#10951)
ngc can now validate metadata before emitting to verify it doesn't contain an error symbol that will result in a runtime error if it is used by the StaticReflector. To enable this add the section, "angularCompilerOptions": { "strictMetadataEmit": true } to the top level of the tsconfig.json file passed to ngc. Enabled metadata validation for packages that are intended to be used statically.
1 parent 45e8e73 commit 39a2c39

32 files changed

+502
-117
lines changed

modules/@angular/common/tsconfig-es2015.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,5 +19,8 @@
1919
"index.ts",
2020
"testing.ts",
2121
"../../../node_modules/zone.js/dist/zone.js.d.ts"
22-
]
22+
],
23+
"angularCompilerOptions": {
24+
"strictMetadataEmit": true
25+
}
2326
}

modules/@angular/common/tsconfig-es5.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,5 +20,8 @@
2020
"index.ts",
2121
"testing.ts",
2222
"../../../node_modules/zone.js/dist/zone.js.d.ts"
23-
]
23+
],
24+
"angularCompilerOptions": {
25+
"strictMetadataEmit": true
26+
}
2427
}

modules/@angular/compiler-cli/src/static_reflector.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -572,13 +572,13 @@ function expandedMessage(error: any): string {
572572
switch (error.message) {
573573
case 'Reference to non-exported class':
574574
if (error.context && error.context.className) {
575-
return `Reference to a non-exported class ${error.context.className}`;
575+
return `Reference to a non-exported class ${error.context.className}. Consider exporting the class`;
576576
}
577577
break;
578578
case 'Variable not initialized':
579-
return 'Only initialized variables and constants can be referenced';
579+
return 'Only initialized variables and constants can be referenced because the value of this variable is needed by the template compiler';
580580
case 'Destructuring not supported':
581-
return 'Referencing an exported destructured variable or constant is not supported';
581+
return 'Referencing an exported destructured variable or constant is not supported by the template compiler. Consider simplifying this to avoid destructuring';
582582
case 'Could not resolve type':
583583
if (error.context && error.context.typeName) {
584584
return `Could not resolve type ${error.context.typeName}`;

modules/@angular/compiler-cli/test/reflector_host_spec.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ describe('reflector_host', () => {
3838
genDir: '/tmp/project/src/gen/',
3939
basePath: '/tmp/project/src',
4040
skipMetadataEmit: false,
41+
strictMetadataEmit: false,
4142
skipTemplateCodegen: false,
4243
trace: false
4344
},
@@ -47,6 +48,7 @@ describe('reflector_host', () => {
4748
genDir: '/tmp/project/gen',
4849
basePath: '/tmp/project/src/',
4950
skipMetadataEmit: false,
51+
strictMetadataEmit: false,
5052
skipTemplateCodegen: false,
5153
trace: false
5254
},

modules/@angular/core/tsconfig-es2015.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,5 +20,8 @@
2020
"testing.ts",
2121
"../../../node_modules/zone.js/dist/zone.js.d.ts",
2222
"../../system.d.ts"
23-
]
23+
],
24+
"angularCompilerOptions": {
25+
"strictMetadataEmit": true
26+
}
2427
}

modules/@angular/core/tsconfig-es5.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,5 +21,8 @@
2121
"testing.ts",
2222
"../../../node_modules/zone.js/dist/zone.js.d.ts",
2323
"../../system.d.ts"
24-
]
24+
],
25+
"angularCompilerOptions": {
26+
"strictMetadataEmit": true
27+
}
2528
}

modules/@angular/forms/tsconfig-es2015.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,5 +23,8 @@
2323
"files": [
2424
"index.ts",
2525
"../../../node_modules/zone.js/dist/zone.js.d.ts"
26-
]
26+
],
27+
"angularCompilerOptions": {
28+
"strictMetadataEmit": true
29+
}
2730
}

modules/@angular/forms/tsconfig-es5.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,5 +24,8 @@
2424
"files": [
2525
"index.ts",
2626
"../../../node_modules/zone.js/dist/zone.js.d.ts"
27-
]
27+
],
28+
"angularCompilerOptions": {
29+
"strictMetadataEmit": true
30+
}
2831
}

modules/@angular/http/tsconfig-es2015.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,5 +21,8 @@
2121
"index.ts",
2222
"testing.ts",
2323
"../../../node_modules/zone.js/dist/zone.js.d.ts"
24-
]
24+
],
25+
"angularCompilerOptions": {
26+
"strictMetadataEmit": true
27+
}
2528
}

modules/@angular/http/tsconfig-es5.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,5 +22,8 @@
2222
"index.ts",
2323
"testing.ts",
2424
"../../../node_modules/zone.js/dist/zone.js.d.ts"
25-
]
25+
],
26+
"angularCompilerOptions": {
27+
"strictMetadataEmit": true
28+
}
2629
}

0 commit comments

Comments
 (0)