fix(animations): always quote string map key values in AOT code (#13602)
This commit is contained in:
parent
c0f750af4e
commit
f49ab56160
|
@ -66,7 +66,7 @@ class _AnimationBuilder implements AnimationAstVisitor {
|
||||||
ast.styles.forEach(entry => {
|
ast.styles.forEach(entry => {
|
||||||
const entries =
|
const entries =
|
||||||
Object.keys(entry).map((key): [string, o.Expression] => [key, o.literal(entry[key])]);
|
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([
|
return o.importExpr(createIdentifier(Identifiers.AnimationStyles)).instantiate([
|
||||||
|
@ -322,12 +322,13 @@ class _AnimationBuilder implements AnimationAstVisitor {
|
||||||
if (isPresent(value)) {
|
if (isPresent(value)) {
|
||||||
const styleMap: any[] = [];
|
const styleMap: any[] = [];
|
||||||
Object.keys(value).forEach(key => { styleMap.push([key, o.literal(value[key])]); });
|
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]);
|
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];
|
const statements: o.Statement[] = [compiledStatesMapStmt, fnStatement];
|
||||||
|
|
||||||
return new AnimationEntryCompileResult(this.animationName, statements, fnVariable);
|
return new AnimationEntryCompileResult(this.animationName, statements, fnVariable);
|
||||||
|
|
|
@ -894,8 +894,10 @@ export function literalArr(values: Expression[], type: Type = null): LiteralArra
|
||||||
return new LiteralArrayExpr(values, type);
|
return new LiteralArrayExpr(values, type);
|
||||||
}
|
}
|
||||||
|
|
||||||
export function literalMap(values: [string, Expression][], type: MapType = null): LiteralMapExpr {
|
export function literalMap(
|
||||||
return new LiteralMapExpr(values.map(entry => new LiteralMapEntry(entry[0], entry[1])), type);
|
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 {
|
export function not(expr: Expression): NotExpr {
|
||||||
|
|
|
@ -113,6 +113,14 @@ export function main() {
|
||||||
expect(emitStmt(o.literalMap([['someKey', o.literal(1)]]).toStmt())).toEqual(`{someKey: 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())
|
||||||
|
.replace(/\s+/gm, ''))
|
||||||
|
.toEqual(`{'a':'a','*':'star'};`);
|
||||||
|
});
|
||||||
|
|
||||||
it('should support blank literals', () => {
|
it('should support blank literals', () => {
|
||||||
expect(emitStmt(o.literal(null).toStmt())).toEqual('(null as any);');
|
expect(emitStmt(o.literal(null).toStmt())).toEqual('(null as any);');
|
||||||
expect(emitStmt(o.literal(undefined).toStmt())).toEqual('(undefined as any);');
|
expect(emitStmt(o.literal(undefined).toStmt())).toEqual('(undefined as any);');
|
||||||
|
|
Loading…
Reference in New Issue