fix(compiler): generate inputs with aliases properly (#26774)

PR Close #26774
This commit is contained in:
Kara Erickson
2018-10-25 23:05:15 -07:00
committed by Matias Niemelä
parent c048358cf9
commit 19fcfc3d00
10 changed files with 69 additions and 24 deletions

View File

@ -86,7 +86,7 @@ export interface R3DirectiveMetadata {
/**
* A mapping of input field names to the property names.
*/
inputs: {[field: string]: string};
inputs: {[field: string]: string | string[]};
/**
* A mapping of output field names to the property names.

View File

@ -532,12 +532,15 @@ function stringAsType(str: string): o.Type {
return o.expressionType(o.literal(str));
}
function stringMapAsType(map: {[key: string]: string}): o.Type {
const mapValues = Object.keys(map).map(key => ({
key,
value: o.literal(map[key]),
quoted: true,
}));
function stringMapAsType(map: {[key: string]: string | string[]}): o.Type {
const mapValues = Object.keys(map).map(key => {
const value = Array.isArray(map[key]) ? map[key][0] : map[key];
return {
key,
value: o.literal(value),
quoted: true,
};
});
return o.expressionType(o.literalMap(mapValues));
}

View File

@ -44,7 +44,7 @@ export interface DirectiveMeta {
*
* Goes from property names to field names.
*/
inputs: {[property: string]: string};
inputs: {[property: string]: string | string[]};
/**
* Set of outputs which this directive claims.

View File

@ -67,8 +67,8 @@ export function asLiteral(value: any): o.Expression {
return o.literal(value, o.INFERRED_TYPE);
}
export function conditionallyCreateMapObjectLiteral(keys: {[key: string]: string}): o.Expression|
null {
export function conditionallyCreateMapObjectLiteral(keys: {[key: string]: string | string[]}):
o.Expression|null {
if (Object.getOwnPropertyNames(keys).length > 0) {
return mapToExpression(keys);
}