diff --git a/modules/@angular/compiler/src/animation/animation_compiler.ts b/modules/@angular/compiler/src/animation/animation_compiler.ts index 5e48d7623d..66682d7170 100644 --- a/modules/@angular/compiler/src/animation/animation_compiler.ts +++ b/modules/@angular/compiler/src/animation/animation_compiler.ts @@ -66,7 +66,7 @@ class _AnimationBuilder implements AnimationAstVisitor { ast.styles.forEach(entry => { const entries = Object.keys(entry).map((key): [string, o.Expression] => [key, o.literal(entry[key])]); - stylesArr.push(o.literalMap(entries)); + stylesArr.push(o.literalMap(entries, null, true)); }); return o.importExpr(createIdentifier(Identifiers.AnimationStyles)).instantiate([ @@ -322,12 +322,13 @@ class _AnimationBuilder implements AnimationAstVisitor { if (isPresent(value)) { const styleMap: any[] = []; Object.keys(value).forEach(key => { styleMap.push([key, o.literal(value[key])]); }); - variableValue = o.literalMap(styleMap); + variableValue = o.literalMap(styleMap, null, true); } lookupMap.push([stateName, variableValue]); }); - const compiledStatesMapStmt = this._statesMapVar.set(o.literalMap(lookupMap)).toDeclStmt(); + const compiledStatesMapStmt = + this._statesMapVar.set(o.literalMap(lookupMap, null, true)).toDeclStmt(); const statements: o.Statement[] = [compiledStatesMapStmt, fnStatement]; return new AnimationEntryCompileResult(this.animationName, statements, fnVariable); diff --git a/modules/@angular/compiler/src/output/output_ast.ts b/modules/@angular/compiler/src/output/output_ast.ts index 867d19258e..9f31466f32 100644 --- a/modules/@angular/compiler/src/output/output_ast.ts +++ b/modules/@angular/compiler/src/output/output_ast.ts @@ -894,8 +894,10 @@ export function literalArr(values: Expression[], type: Type = null): LiteralArra return new LiteralArrayExpr(values, type); } -export function literalMap(values: [string, Expression][], type: MapType = null): LiteralMapExpr { - return new LiteralMapExpr(values.map(entry => new LiteralMapEntry(entry[0], entry[1])), type); +export function literalMap( + values: [string, Expression][], type: MapType = null, quoted: boolean = false): LiteralMapExpr { + return new LiteralMapExpr( + values.map(entry => new LiteralMapEntry(entry[0], entry[1], quoted)), type); } export function not(expr: Expression): NotExpr { diff --git a/modules/@angular/compiler/test/output/ts_emitter_spec.ts b/modules/@angular/compiler/test/output/ts_emitter_spec.ts index 2b59a0dd1c..3a6d6cdf22 100644 --- a/modules/@angular/compiler/test/output/ts_emitter_spec.ts +++ b/modules/@angular/compiler/test/output/ts_emitter_spec.ts @@ -113,6 +113,14 @@ export function main() { 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()) + .replace(/\s+/gm, '')) + .toEqual(`{'a':'a','*':'star'};`); + }); + it('should support blank literals', () => { expect(emitStmt(o.literal(null).toStmt())).toEqual('(null as any);'); expect(emitStmt(o.literal(undefined).toStmt())).toEqual('(undefined as any);');