fix(compiler): emits quoted keys only iff they are quoted in the original template

fixes #14292
This commit is contained in:
Victor Berchet
2017-07-05 14:51:39 -07:00
committed by Jason Aden
parent 798947efa4
commit 9c1f6fd06f
11 changed files with 77 additions and 55 deletions

View File

@ -21,7 +21,7 @@ const sameModuleIdentifier = new o.ExternalReference(null, 'someLocalId', null);
const externalModuleIdentifier = new o.ExternalReference(anotherModuleUrl, 'someExternalId', null);
describe('TypeScriptEmitter', () => {
describe('TypeScriptNodeEmitter', () => {
let context: MockAotContext;
let host: MockCompilerHost;
let emitter: TypeScriptNodeEmitter;
@ -166,15 +166,13 @@ describe('TypeScriptEmitter', () => {
expect(emitStmt(o.literal(true).toStmt())).toEqual('true;');
expect(emitStmt(o.literal('someStr').toStmt())).toEqual(`"someStr";`);
expect(emitStmt(o.literalArr([o.literal(1)]).toStmt())).toEqual(`[1];`);
expect(emitStmt(o.literalMap([['someKey', o.literal(1)]]).toStmt()))
.toEqual(`({ someKey: 1 });`);
});
it('should apply quotes to each entry within a map produced with literalMap when true', () => {
expect(emitStmt(
o.literalMap([['a', o.literal('a')], ['*', o.literal('star')]], null, true).toStmt())
expect(emitStmt(o.literalMap([
{key: 'someKey', value: o.literal(1), quoted: false},
{key: 'a', value: o.literal('a'), quoted: false},
{key: '*', value: o.literal('star'), quoted: true},
]).toStmt())
.replace(/\s+/gm, ''))
.toEqual(`({"a":"a","*":"star"});`);
.toEqual(`({someKey:1,a:"a","*":"star"});`);
});
it('should support blank literals', () => {