feat(compiler): Added "strictMetadataEmit" option to ngc (#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.
This commit is contained in:
@ -19,5 +19,8 @@
|
||||
"index.ts",
|
||||
"testing.ts",
|
||||
"../../../node_modules/zone.js/dist/zone.js.d.ts"
|
||||
]
|
||||
],
|
||||
"angularCompilerOptions": {
|
||||
"strictMetadataEmit": true
|
||||
}
|
||||
}
|
||||
|
@ -20,5 +20,8 @@
|
||||
"index.ts",
|
||||
"testing.ts",
|
||||
"../../../node_modules/zone.js/dist/zone.js.d.ts"
|
||||
]
|
||||
],
|
||||
"angularCompilerOptions": {
|
||||
"strictMetadataEmit": true
|
||||
}
|
||||
}
|
||||
|
@ -572,13 +572,13 @@ function expandedMessage(error: any): string {
|
||||
switch (error.message) {
|
||||
case 'Reference to non-exported class':
|
||||
if (error.context && error.context.className) {
|
||||
return `Reference to a non-exported class ${error.context.className}`;
|
||||
return `Reference to a non-exported class ${error.context.className}. Consider exporting the class`;
|
||||
}
|
||||
break;
|
||||
case 'Variable not initialized':
|
||||
return 'Only initialized variables and constants can be referenced';
|
||||
return 'Only initialized variables and constants can be referenced because the value of this variable is needed by the template compiler';
|
||||
case 'Destructuring not supported':
|
||||
return 'Referencing an exported destructured variable or constant is not supported';
|
||||
return 'Referencing an exported destructured variable or constant is not supported by the template compiler. Consider simplifying this to avoid destructuring';
|
||||
case 'Could not resolve type':
|
||||
if (error.context && error.context.typeName) {
|
||||
return `Could not resolve type ${error.context.typeName}`;
|
||||
|
@ -38,6 +38,7 @@ describe('reflector_host', () => {
|
||||
genDir: '/tmp/project/src/gen/',
|
||||
basePath: '/tmp/project/src',
|
||||
skipMetadataEmit: false,
|
||||
strictMetadataEmit: false,
|
||||
skipTemplateCodegen: false,
|
||||
trace: false
|
||||
},
|
||||
@ -47,6 +48,7 @@ describe('reflector_host', () => {
|
||||
genDir: '/tmp/project/gen',
|
||||
basePath: '/tmp/project/src/',
|
||||
skipMetadataEmit: false,
|
||||
strictMetadataEmit: false,
|
||||
skipTemplateCodegen: false,
|
||||
trace: false
|
||||
},
|
||||
|
@ -20,5 +20,8 @@
|
||||
"testing.ts",
|
||||
"../../../node_modules/zone.js/dist/zone.js.d.ts",
|
||||
"../../system.d.ts"
|
||||
]
|
||||
],
|
||||
"angularCompilerOptions": {
|
||||
"strictMetadataEmit": true
|
||||
}
|
||||
}
|
||||
|
@ -21,5 +21,8 @@
|
||||
"testing.ts",
|
||||
"../../../node_modules/zone.js/dist/zone.js.d.ts",
|
||||
"../../system.d.ts"
|
||||
]
|
||||
],
|
||||
"angularCompilerOptions": {
|
||||
"strictMetadataEmit": true
|
||||
}
|
||||
}
|
||||
|
@ -23,5 +23,8 @@
|
||||
"files": [
|
||||
"index.ts",
|
||||
"../../../node_modules/zone.js/dist/zone.js.d.ts"
|
||||
]
|
||||
],
|
||||
"angularCompilerOptions": {
|
||||
"strictMetadataEmit": true
|
||||
}
|
||||
}
|
||||
|
@ -24,5 +24,8 @@
|
||||
"files": [
|
||||
"index.ts",
|
||||
"../../../node_modules/zone.js/dist/zone.js.d.ts"
|
||||
]
|
||||
],
|
||||
"angularCompilerOptions": {
|
||||
"strictMetadataEmit": true
|
||||
}
|
||||
}
|
||||
|
@ -21,5 +21,8 @@
|
||||
"index.ts",
|
||||
"testing.ts",
|
||||
"../../../node_modules/zone.js/dist/zone.js.d.ts"
|
||||
]
|
||||
],
|
||||
"angularCompilerOptions": {
|
||||
"strictMetadataEmit": true
|
||||
}
|
||||
}
|
||||
|
@ -22,5 +22,8 @@
|
||||
"index.ts",
|
||||
"testing.ts",
|
||||
"../../../node_modules/zone.js/dist/zone.js.d.ts"
|
||||
]
|
||||
],
|
||||
"angularCompilerOptions": {
|
||||
"strictMetadataEmit": true
|
||||
}
|
||||
}
|
||||
|
@ -27,5 +27,5 @@ export {WORKER_UI_LOCATION_PROVIDERS} from './src/web_workers/ui/location_provid
|
||||
|
||||
export {NgProbeToken} from './src/dom/debug/ng_probe';
|
||||
export * from './src/worker_render';
|
||||
export * from './src/worker_app';
|
||||
export {platformWorkerApp, WorkerAppModule} from './src/worker_app';
|
||||
export * from './private_export';
|
@ -21,7 +21,12 @@ import {ServiceMessageBrokerFactory, ServiceMessageBrokerFactory_} from './web_w
|
||||
import {WebWorkerRootRenderer} from './web_workers/worker/renderer';
|
||||
import {WorkerDomAdapter} from './web_workers/worker/worker_adapter';
|
||||
|
||||
class PrintLogger {
|
||||
/**
|
||||
* Logger for web workers.
|
||||
*
|
||||
* @experimental
|
||||
*/
|
||||
export class PrintLogger {
|
||||
log = print;
|
||||
logError = print;
|
||||
logGroup = print;
|
||||
@ -33,7 +38,12 @@ class PrintLogger {
|
||||
*/
|
||||
export const platformWorkerApp = createPlatformFactory(platformCore, 'workerApp');
|
||||
|
||||
function _exceptionHandler(): ExceptionHandler {
|
||||
/**
|
||||
* Exception handler factory function.
|
||||
*
|
||||
* @experimental
|
||||
*/
|
||||
export function exceptionHandler(): ExceptionHandler {
|
||||
return new ExceptionHandler(new PrintLogger());
|
||||
}
|
||||
|
||||
@ -44,7 +54,12 @@ let _postMessage = {
|
||||
}
|
||||
};
|
||||
|
||||
function createMessageBus(zone: NgZone): MessageBus {
|
||||
/**
|
||||
* MessageBus factory function.
|
||||
*
|
||||
* @experimental
|
||||
*/
|
||||
export function createMessageBus(zone: NgZone): MessageBus {
|
||||
let sink = new PostMessageBusSink(_postMessage);
|
||||
let source = new PostMessageBusSource();
|
||||
let bus = new PostMessageBus(sink, source);
|
||||
@ -52,7 +67,12 @@ function createMessageBus(zone: NgZone): MessageBus {
|
||||
return bus;
|
||||
}
|
||||
|
||||
function setupWebWorker(): void {
|
||||
/**
|
||||
* Application initializer for web workers.
|
||||
*
|
||||
* @experimental
|
||||
*/
|
||||
export function setupWebWorker(): void {
|
||||
WorkerDomAdapter.makeCurrent();
|
||||
}
|
||||
|
||||
@ -68,7 +88,7 @@ function setupWebWorker(): void {
|
||||
{provide: ServiceMessageBrokerFactory, useClass: ServiceMessageBrokerFactory_},
|
||||
WebWorkerRootRenderer, {provide: RootRenderer, useExisting: WebWorkerRootRenderer},
|
||||
{provide: ON_WEB_WORKER, useValue: true}, RenderStore,
|
||||
{provide: ExceptionHandler, useFactory: _exceptionHandler, deps: []},
|
||||
{provide: ExceptionHandler, useFactory: exceptionHandler, deps: []},
|
||||
{provide: MessageBus, useFactory: createMessageBus, deps: [NgZone]},
|
||||
{provide: APP_INITIALIZER, useValue: setupWebWorker, multi: true}
|
||||
],
|
||||
|
@ -13,17 +13,13 @@ import {BrowserDomAdapter} from '../src/browser/browser_adapter';
|
||||
import {AnimationDriver} from '../src/dom/animation_driver';
|
||||
import {ELEMENT_PROBE_PROVIDERS} from '../src/dom/debug/ng_probe';
|
||||
|
||||
import {BrowserDetection} from './browser_util';
|
||||
import {BrowserDetection, createNgZone} from './browser_util';
|
||||
|
||||
function initBrowserTests() {
|
||||
BrowserDomAdapter.makeCurrent();
|
||||
BrowserDetection.setup();
|
||||
}
|
||||
|
||||
function createNgZone(): NgZone {
|
||||
return new NgZone({enableLongStackTrace: true});
|
||||
}
|
||||
|
||||
const _TEST_BROWSER_PLATFORM_PROVIDERS: Provider[] =
|
||||
[{provide: PLATFORM_INITIALIZER, useValue: initBrowserTests, multi: true}];
|
||||
|
||||
|
@ -6,6 +6,7 @@
|
||||
* found in the LICENSE file at https://angular.io/license
|
||||
*/
|
||||
|
||||
import {NgZone} from '@angular/core';
|
||||
import {getDOM} from '../src/dom/dom_adapter';
|
||||
import {ListWrapper} from '../src/facade/collection';
|
||||
import {RegExp, StringWrapper, global, isPresent, isString} from '../src/facade/lang';
|
||||
@ -129,3 +130,7 @@ export function stringifyElement(el: any /** TODO #9100 */): string {
|
||||
}
|
||||
|
||||
export var browserDetection: BrowserDetection = new BrowserDetection(null);
|
||||
|
||||
export function createNgZone(): NgZone {
|
||||
return new NgZone({enableLongStackTrace: true});
|
||||
}
|
||||
|
@ -29,5 +29,8 @@
|
||||
"../../../node_modules/@types/jasmine/index.d.ts",
|
||||
"../../../node_modules/@types/protractor/index.d.ts",
|
||||
"../../../node_modules/zone.js/dist/zone.js.d.ts"
|
||||
]
|
||||
],
|
||||
"angularCompilerOptions": {
|
||||
"strictMetadataEmit": true
|
||||
}
|
||||
}
|
||||
|
@ -30,5 +30,8 @@
|
||||
"../../../node_modules/@types/jasmine/index.d.ts",
|
||||
"../../../node_modules/@types/protractor/index.d.ts",
|
||||
"../../../node_modules/zone.js/dist/zone.js.d.ts"
|
||||
]
|
||||
],
|
||||
"angularCompilerOptions": {
|
||||
"strictMetadataEmit": true
|
||||
}
|
||||
}
|
||||
|
@ -30,5 +30,8 @@
|
||||
"../../../node_modules/@types/jasmine/index.d.ts",
|
||||
"../../../node_modules/@types/node/index.d.ts",
|
||||
"../../../node_modules/zone.js/dist/zone.js.d.ts"
|
||||
]
|
||||
],
|
||||
"angularCompilerOptions": {
|
||||
"strictMetadataEmit": true
|
||||
}
|
||||
}
|
||||
|
@ -31,5 +31,8 @@
|
||||
"../../../node_modules/@types/jasmine/index.d.ts",
|
||||
"../../../node_modules/@types/node/index.d.ts",
|
||||
"../../../node_modules/zone.js/dist/zone.js.d.ts"
|
||||
]
|
||||
],
|
||||
"angularCompilerOptions": {
|
||||
"strictMetadataEmit": true
|
||||
}
|
||||
}
|
||||
|
@ -39,7 +39,12 @@ export class SpyNgModuleFactoryLoader implements NgModuleFactoryLoader {
|
||||
}
|
||||
}
|
||||
|
||||
function setupTestingRouter(
|
||||
/**
|
||||
* Router setup factory function used for testing.
|
||||
*
|
||||
* @experimental
|
||||
*/
|
||||
export function setupTestingRouter(
|
||||
urlSerializer: UrlSerializer, outletMap: RouterOutletMap, location: Location,
|
||||
loader: NgModuleFactoryLoader, compiler: Compiler, injector: Injector, routes: Route[][]) {
|
||||
return new Router(
|
||||
|
@ -24,5 +24,8 @@
|
||||
"files": [
|
||||
"index.ts",
|
||||
"testing.ts"
|
||||
]
|
||||
],
|
||||
"angularCompilerOptions": {
|
||||
"strictMetadataEmit": true
|
||||
}
|
||||
}
|
@ -24,7 +24,8 @@
|
||||
"files": [
|
||||
"index.ts",
|
||||
"testing.ts"
|
||||
]
|
||||
],
|
||||
"angularCompilerOptions": {
|
||||
"strictMetadataEmit": true
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
@ -22,5 +22,8 @@
|
||||
"files": [
|
||||
"index.ts",
|
||||
"../../../node_modules/zone.js/dist/zone.js.d.ts"
|
||||
]
|
||||
],
|
||||
"angularCompilerOptions": {
|
||||
"strictMetadataEmit": true
|
||||
}
|
||||
}
|
||||
|
@ -23,5 +23,8 @@
|
||||
"files": [
|
||||
"index.ts",
|
||||
"../../../node_modules/zone.js/dist/zone.js.d.ts"
|
||||
]
|
||||
],
|
||||
"angularCompilerOptions": {
|
||||
"strictMetadataEmit": true
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user