fix(ivy): take preserveWhitespaces config option into account (FW-650) (#27197)
PR Close #27197
This commit is contained in:
parent
9e391e010c
commit
d819c00fee
|
@ -60,7 +60,7 @@ export class DecorationAnalyzer {
|
||||||
new BaseDefDecoratorHandler(this.typeChecker, this.host),
|
new BaseDefDecoratorHandler(this.typeChecker, this.host),
|
||||||
new ComponentDecoratorHandler(
|
new ComponentDecoratorHandler(
|
||||||
this.typeChecker, this.host, this.scopeRegistry, this.isCore, this.resourceLoader,
|
this.typeChecker, this.host, this.scopeRegistry, this.isCore, this.resourceLoader,
|
||||||
this.rootDirs),
|
this.rootDirs, /* defaultPreserveWhitespaces */ false),
|
||||||
new DirectiveDecoratorHandler(this.typeChecker, this.host, this.scopeRegistry, this.isCore),
|
new DirectiveDecoratorHandler(this.typeChecker, this.host, this.scopeRegistry, this.isCore),
|
||||||
new InjectableDecoratorHandler(this.host, this.isCore),
|
new InjectableDecoratorHandler(this.host, this.isCore),
|
||||||
new NgModuleDecoratorHandler(this.typeChecker, this.host, this.scopeRegistry, this.isCore),
|
new NgModuleDecoratorHandler(this.typeChecker, this.host, this.scopeRegistry, this.isCore),
|
||||||
|
|
|
@ -38,7 +38,8 @@ export class ComponentDecoratorHandler implements
|
||||||
constructor(
|
constructor(
|
||||||
private checker: ts.TypeChecker, private reflector: ReflectionHost,
|
private checker: ts.TypeChecker, private reflector: ReflectionHost,
|
||||||
private scopeRegistry: SelectorScopeRegistry, private isCore: boolean,
|
private scopeRegistry: SelectorScopeRegistry, private isCore: boolean,
|
||||||
private resourceLoader: ResourceLoader, private rootDirs: string[]) {}
|
private resourceLoader: ResourceLoader, private rootDirs: string[],
|
||||||
|
private defaultPreserveWhitespaces: boolean) {}
|
||||||
|
|
||||||
private literalCache = new Map<Decorator, ts.ObjectLiteralExpression>();
|
private literalCache = new Map<Decorator, ts.ObjectLiteralExpression>();
|
||||||
private elementSchemaRegistry = new DomElementSchemaRegistry();
|
private elementSchemaRegistry = new DomElementSchemaRegistry();
|
||||||
|
@ -111,7 +112,7 @@ export class ComponentDecoratorHandler implements
|
||||||
ErrorCode.COMPONENT_MISSING_TEMPLATE, decorator.node, 'component is missing a template');
|
ErrorCode.COMPONENT_MISSING_TEMPLATE, decorator.node, 'component is missing a template');
|
||||||
}
|
}
|
||||||
|
|
||||||
let preserveWhitespaces: boolean = false;
|
let preserveWhitespaces: boolean = this.defaultPreserveWhitespaces;
|
||||||
if (component.has('preserveWhitespaces')) {
|
if (component.has('preserveWhitespaces')) {
|
||||||
const expr = component.get('preserveWhitespaces') !;
|
const expr = component.get('preserveWhitespaces') !;
|
||||||
const value = staticallyResolve(expr, this.reflector, this.checker);
|
const value = staticallyResolve(expr, this.reflector, this.checker);
|
||||||
|
|
|
@ -40,7 +40,7 @@ describe('ComponentDecoratorHandler', () => {
|
||||||
const host = new TypeScriptReflectionHost(checker);
|
const host = new TypeScriptReflectionHost(checker);
|
||||||
const handler = new ComponentDecoratorHandler(
|
const handler = new ComponentDecoratorHandler(
|
||||||
checker, host, new SelectorScopeRegistry(checker, host), false, new NoopResourceLoader(),
|
checker, host, new SelectorScopeRegistry(checker, host), false, new NoopResourceLoader(),
|
||||||
['']);
|
[''], false);
|
||||||
const TestCmp = getDeclaration(program, 'entry.ts', 'TestCmp', ts.isClassDeclaration);
|
const TestCmp = getDeclaration(program, 'entry.ts', 'TestCmp', ts.isClassDeclaration);
|
||||||
const detected = handler.detect(TestCmp, host.getDecoratorsOfDeclaration(TestCmp));
|
const detected = handler.detect(TestCmp, host.getDecoratorsOfDeclaration(TestCmp));
|
||||||
if (detected === undefined) {
|
if (detected === undefined) {
|
||||||
|
|
|
@ -219,7 +219,8 @@ export class NgtscProgram implements api.Program {
|
||||||
const handlers = [
|
const handlers = [
|
||||||
new BaseDefDecoratorHandler(checker, this.reflector),
|
new BaseDefDecoratorHandler(checker, this.reflector),
|
||||||
new ComponentDecoratorHandler(
|
new ComponentDecoratorHandler(
|
||||||
checker, this.reflector, scopeRegistry, this.isCore, this.resourceLoader, this.rootDirs),
|
checker, this.reflector, scopeRegistry, this.isCore, this.resourceLoader, this.rootDirs,
|
||||||
|
this.options.preserveWhitespaces || false),
|
||||||
new DirectiveDecoratorHandler(checker, this.reflector, scopeRegistry, this.isCore),
|
new DirectiveDecoratorHandler(checker, this.reflector, scopeRegistry, this.isCore),
|
||||||
new InjectableDecoratorHandler(this.reflector, this.isCore),
|
new InjectableDecoratorHandler(this.reflector, this.isCore),
|
||||||
new NgModuleDecoratorHandler(checker, this.reflector, scopeRegistry, this.isCore),
|
new NgModuleDecoratorHandler(checker, this.reflector, scopeRegistry, this.isCore),
|
||||||
|
|
|
@ -553,6 +553,46 @@ describe('ngtsc behavioral tests', () => {
|
||||||
expect(trim(jsContents)).toContain(trim(hostBindingsFn));
|
expect(trim(jsContents)).toContain(trim(hostBindingsFn));
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('should take preserveWhitespaces config option into account', () => {
|
||||||
|
env.tsconfig({preserveWhitespaces: true});
|
||||||
|
env.write(`test.ts`, `
|
||||||
|
import {Component} from '@angular/core';
|
||||||
|
@Component({
|
||||||
|
selector: 'test',
|
||||||
|
template: \`
|
||||||
|
<div>
|
||||||
|
Template with whitespaces
|
||||||
|
</div>
|
||||||
|
\`
|
||||||
|
})
|
||||||
|
class FooCmp {}
|
||||||
|
`);
|
||||||
|
env.driveMain();
|
||||||
|
const jsContents = env.getContents('test.js');
|
||||||
|
expect(jsContents)
|
||||||
|
.toContain('text(2, "\\n Template with whitespaces\\n ");');
|
||||||
|
});
|
||||||
|
|
||||||
|
it('@Component\'s preserveWhitespaces should override the one defined in config', () => {
|
||||||
|
env.tsconfig({preserveWhitespaces: true});
|
||||||
|
env.write(`test.ts`, `
|
||||||
|
import {Component} from '@angular/core';
|
||||||
|
@Component({
|
||||||
|
selector: 'test',
|
||||||
|
preserveWhitespaces: false,
|
||||||
|
template: \`
|
||||||
|
<div>
|
||||||
|
Template with whitespaces
|
||||||
|
</div>
|
||||||
|
\`
|
||||||
|
})
|
||||||
|
class FooCmp {}
|
||||||
|
`);
|
||||||
|
env.driveMain();
|
||||||
|
const jsContents = env.getContents('test.js');
|
||||||
|
expect(jsContents).toContain('text(1, " Template with whitespaces ");');
|
||||||
|
});
|
||||||
|
|
||||||
it('should correctly recognize local symbols', () => {
|
it('should correctly recognize local symbols', () => {
|
||||||
env.tsconfig();
|
env.tsconfig();
|
||||||
env.write('module.ts', `
|
env.write('module.ts', `
|
||||||
|
|
Loading…
Reference in New Issue