private LanguageExpression ConvertString(StringSyntax syntax) { if (syntax.TryGetLiteralValue() is string literalStringValue) { // no need to build a format string return(new JTokenExpression(literalStringValue));; } if (syntax.Expressions.Length == 1) { const string emptyStringOpen = LanguageConstants.StringDelimiter + LanguageConstants.StringHoleOpen; // '${ const string emptyStringClose = LanguageConstants.StringHoleClose + LanguageConstants.StringDelimiter; // }' // Special-case interpolation of format '${myValue}' because it's a common pattern for userAssignedIdentities. // There's no need for a 'format' function because we just have a single expression with no outer formatting. if (syntax.StringTokens[0].Text == emptyStringOpen && syntax.StringTokens[1].Text == emptyStringClose) { return(ConvertExpression(syntax.Expressions[0])); } } var formatArgs = new LanguageExpression[syntax.Expressions.Length + 1]; var formatString = StringFormatConverter.BuildFormatString(syntax); formatArgs[0] = new JTokenExpression(formatString); for (var i = 0; i < syntax.Expressions.Length; i++) { formatArgs[i + 1] = ConvertExpression(syntax.Expressions[i]); } return(CreateFunction("format", formatArgs)); }
private LanguageExpression ConvertString(StringSyntax syntax) { if (!syntax.IsInterpolated()) { // no need to build a format string return(new JTokenExpression(syntax.GetLiteralValue()));; } var formatArgs = new LanguageExpression[syntax.Expressions.Length + 1]; var formatString = StringFormatConverter.BuildFormatString(syntax); formatArgs[0] = new JTokenExpression(formatString); for (var i = 0; i < syntax.Expressions.Length; i++) { formatArgs[i + 1] = ConvertExpression(syntax.Expressions[i]); } return(new FunctionExpression("format", formatArgs, Array.Empty <LanguageExpression>())); }