feat(compiler): set enableLegacyTemplate
to false by default (#18756)
BREAKING CHANGE: the compiler option `enableLegacyTemplate` is now disabled by default as the `<template>` element has been deprecated since v4. Use `<ng-template>` instead. The option `enableLegacyTemplate` and the `<template>` element will both be removed in Angular v6. PR Close #18756
This commit is contained in:

committed by
Jason Aden

parent
fcadeb2079
commit
56238fe94e
@ -79,7 +79,6 @@ export class NgForOfContext<T> {
|
||||
* ### Syntax
|
||||
*
|
||||
* - `<li *ngFor="let item of items; index as i; trackBy: trackByFn">...</li>`
|
||||
* - `<li template="ngFor let item of items; index as i; trackBy: trackByFn">...</li>`
|
||||
*
|
||||
* With `<ng-template>` element:
|
||||
*
|
||||
|
@ -75,7 +75,6 @@ import {Directive, EmbeddedViewRef, Input, TemplateRef, ViewContainerRef} from '
|
||||
*
|
||||
* Simple form:
|
||||
* - `<div *ngIf="condition">...</div>`
|
||||
* - `<div template="ngIf condition">...</div>`
|
||||
* - `<ng-template [ngIf]="condition"><div>...</div></ng-template>`
|
||||
*
|
||||
* Form with an else block:
|
||||
|
@ -101,7 +101,7 @@ export class CodeGenerator {
|
||||
translations: transContent,
|
||||
i18nFormat: cliOptions.i18nFormat || undefined,
|
||||
locale: cliOptions.locale || undefined, missingTranslation,
|
||||
enableLegacyTemplate: options.enableLegacyTemplate !== false,
|
||||
enableLegacyTemplate: options.enableLegacyTemplate === true,
|
||||
enableSummariesForJit: options.enableSummariesForJit !== false,
|
||||
preserveWhitespaces: options.preserveWhitespaces,
|
||||
});
|
||||
|
@ -90,7 +90,7 @@ export interface CompilerOptions extends ts.CompilerOptions {
|
||||
// Print extra information while running the compiler
|
||||
trace?: boolean;
|
||||
|
||||
// Whether to enable support for <template> and the template attribute (true by default)
|
||||
// Whether to enable support for <template> and the template attribute (false by default)
|
||||
enableLegacyTemplate?: boolean;
|
||||
|
||||
// Whether to enable lowering expressions lambdas and expressions in a reference value
|
||||
|
@ -65,7 +65,7 @@ export function createAotCompiler(compilerHost: AotCompilerHost, options: AotCom
|
||||
const config = new CompilerConfig({
|
||||
defaultEncapsulation: ViewEncapsulation.Emulated,
|
||||
useJit: false,
|
||||
enableLegacyTemplate: options.enableLegacyTemplate !== false,
|
||||
enableLegacyTemplate: options.enableLegacyTemplate === true,
|
||||
missingTranslation: options.missingTranslation,
|
||||
preserveWhitespaces: options.preserveWhitespaces,
|
||||
});
|
||||
|
@ -36,7 +36,7 @@ export class CompilerConfig {
|
||||
this.useJit = !!useJit;
|
||||
this.jitDevMode = !!jitDevMode;
|
||||
this.missingTranslation = missingTranslation || null;
|
||||
this.enableLegacyTemplate = enableLegacyTemplate !== false;
|
||||
this.enableLegacyTemplate = enableLegacyTemplate === true;
|
||||
this.preserveWhitespaces = preserveWhitespacesDefault(noUndefined(preserveWhitespaces));
|
||||
}
|
||||
}
|
||||
|
@ -121,16 +121,19 @@ export function main() {
|
||||
schemas?: SchemaMetadata[], preserveWhitespaces?: boolean) => TemplateAst[];
|
||||
let console: ArrayConsole;
|
||||
|
||||
function commonBeforeEach() {
|
||||
function configureCompiler() {
|
||||
console = new ArrayConsole();
|
||||
beforeEach(() => {
|
||||
console = new ArrayConsole();
|
||||
TestBed.configureCompiler({
|
||||
providers: [
|
||||
{provide: Console, useValue: console},
|
||||
{provide: CompilerConfig, useValue: new CompilerConfig({enableLegacyTemplate: true})}
|
||||
],
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
function commonBeforeEach() {
|
||||
beforeEach(inject([TemplateParser], (parser: TemplateParser) => {
|
||||
const someAnimation = new CompileAnimationEntryMetadata('someAnimation', []);
|
||||
const someTemplate = compileTemplateMetadata({animations: [someAnimation]});
|
||||
@ -286,6 +289,7 @@ export function main() {
|
||||
});
|
||||
});
|
||||
|
||||
configureCompiler();
|
||||
commonBeforeEach();
|
||||
|
||||
describe('security context', () => {
|
||||
@ -318,6 +322,7 @@ export function main() {
|
||||
TestBed.configureCompiler({providers: [TEST_COMPILER_PROVIDERS, MOCK_SCHEMA_REGISTRY]});
|
||||
});
|
||||
|
||||
configureCompiler();
|
||||
commonBeforeEach();
|
||||
|
||||
describe('parse', () => {
|
||||
@ -2129,13 +2134,13 @@ The pipe 'test' could not be found ("{{[ERROR ->]a | test}}"): TestComp@0:2`);
|
||||
|
||||
});
|
||||
|
||||
describe('Template Parser - opt-out `<template>` support', () => {
|
||||
describe('Template Parser - `<template>` support disabled by default', () => {
|
||||
beforeEach(() => {
|
||||
TestBed.configureCompiler({
|
||||
providers: [{
|
||||
provide: CompilerConfig,
|
||||
useValue: new CompilerConfig({enableLegacyTemplate: false}),
|
||||
}],
|
||||
providers: [
|
||||
{provide: Console, useValue: console},
|
||||
{provide: CompilerConfig, useValue: new CompilerConfig()}
|
||||
],
|
||||
});
|
||||
});
|
||||
|
||||
|
@ -7,6 +7,7 @@
|
||||
*/
|
||||
|
||||
import {CommonModule} from '@angular/common';
|
||||
import {CompilerConfig} from '@angular/compiler';
|
||||
import {Compiler, ComponentFactory, ComponentRef, ErrorHandler, EventEmitter, Host, Inject, Injectable, InjectionToken, Injector, NO_ERRORS_SCHEMA, NgModule, NgModuleRef, OnDestroy, SkipSelf, ViewRef} from '@angular/core';
|
||||
import {ChangeDetectionStrategy, ChangeDetectorRef, PipeTransform} from '@angular/core/src/change_detection/change_detection';
|
||||
import {getDebugContext} from '@angular/core/src/errors';
|
||||
@ -37,7 +38,14 @@ export function main() {
|
||||
function declareTests({useJit}: {useJit: boolean}) {
|
||||
describe('integration tests', function() {
|
||||
|
||||
beforeEach(() => { TestBed.configureCompiler({useJit}); });
|
||||
beforeEach(() => {
|
||||
TestBed.configureCompiler({
|
||||
useJit,
|
||||
providers: [
|
||||
{provide: CompilerConfig, useValue: new CompilerConfig({enableLegacyTemplate: true})}
|
||||
]
|
||||
});
|
||||
});
|
||||
|
||||
describe('react to record changes', function() {
|
||||
it('should consume text node changes', () => {
|
||||
|
@ -160,7 +160,7 @@ export class JitCompilerFactory implements CompilerFactory {
|
||||
useJit: true,
|
||||
defaultEncapsulation: ViewEncapsulation.Emulated,
|
||||
missingTranslation: MissingTranslationStrategy.Warning,
|
||||
enableLegacyTemplate: true,
|
||||
enableLegacyTemplate: false,
|
||||
};
|
||||
|
||||
this._defaultOptions = [compilerOptions, ...defaultOptions];
|
||||
|
@ -76,7 +76,7 @@ interface Options extends ts.CompilerOptions {
|
||||
// Print extra information while running the compiler
|
||||
trace?: boolean;
|
||||
|
||||
// Whether to enable support for <template> and the template attribute (true by default)
|
||||
// Whether to enable support for <template> and the template attribute (false by default)
|
||||
enableLegacyTemplate?: boolean;
|
||||
|
||||
// Whether to generate .ngsummary.ts files that allow to use AOTed artifacts
|
||||
|
Reference in New Issue
Block a user