Skip to content

Commit

Permalink
add new parseShortOpen function
Browse files Browse the repository at this point in the history
  • Loading branch information
aq17 committed Sep 27, 2023
1 parent a1b0903 commit 5c18aed
Showing 1 changed file with 12 additions and 26 deletions.
38 changes: 12 additions & 26 deletions ast/expr.go
Original file line number Diff line number Diff line change
Expand Up @@ -533,32 +533,8 @@ func tryParseFunction(node *syntax.ObjectNode) (Expr, syntax.Diagnostics, bool)
case "fn::toString":
parse = parseToString
default:

if providerName, isOpen := strings.CutPrefix(kvp.Key.Value(), "fn::open::"); isOpen {
// transform the node into fn::open format
providerName := strings.TrimPrefix(kvp.Key.Value(), "fn::")
// case 1: inputs are provided
if _, ok := kvp.Value.(*syntax.ObjectNode); ok {
kvp.Value = syntax.Object(
syntax.ObjectPropertyDef{
Key: syntax.StringSyntax(kvp.Syntax, "inputs"),
Value: kvp.Value,
},
syntax.ObjectPropertyDef{
Key: syntax.StringSyntax(kvp.Syntax, "provider"),
Value: syntax.String(providerName),
},
)
} else {
// case 2: inputs are not provided
kvp.Value = syntax.Object(
syntax.ObjectPropertyDef{
Key: syntax.StringSyntax(kvp.Syntax, "inputs"),
Value: syntax.String(providerName),
},
)
}
parse = parseOpen
if strings.HasPrefix(kvp.Key.Value(), "fn::open::") {
parse = parseShortOpen
break
}

Expand Down Expand Up @@ -635,6 +611,16 @@ func parseOpen(node *syntax.ObjectNode, name *StringExpr, args Expr) (Expr, synt
return OpenSyntax(node, name, obj, provider, inputs), diags
}

func parseShortOpen(node *syntax.ObjectNode, name *StringExpr, args Expr) (Expr, syntax.Diagnostics) {
provider := strings.TrimPrefix(node.Key.Value(), "fn::open::")

Check failure on line 615 in ast/expr.go

View workflow job for this annotation

GitHub Actions / lint / lint

node.Key undefined (type *"github.com/pulumi/esc/syntax".ObjectNode has no field or method Key)

Check failure on line 615 in ast/expr.go

View workflow job for this annotation

GitHub Actions / lint / lint

node.Key undefined (type *"github.com/pulumi/esc/syntax".ObjectNode has no field or method Key)

Check failure on line 615 in ast/expr.go

View workflow job for this annotation

GitHub Actions / test / Test (1.21.0, true)

node.Key undefined (type *"github.com/pulumi/esc/syntax".ObjectNode has no field or method Key)
inputs, ok := args.(*ObjectExpr)
if !ok {
return nil, syntax.Diagnostics{ExprError(args, fmt.Sprintf("the argument to fn::open::%s must be an object", provider), "")}
}

return OpenSyntax(node, name, inputs, StringSyntaxValue(name, provider), inputs), nil

Check failure on line 621 in ast/expr.go

View workflow job for this annotation

GitHub Actions / lint / lint

cannot use name (variable of type *StringExpr) as *"github.com/pulumi/esc/syntax".StringNode value in argument to StringSyntaxValue) (typecheck)

Check failure on line 621 in ast/expr.go

View workflow job for this annotation

GitHub Actions / lint / lint

cannot use name (variable of type *StringExpr) as *"github.com/pulumi/esc/syntax".StringNode value in argument to StringSyntaxValue (typecheck)

Check failure on line 621 in ast/expr.go

View workflow job for this annotation

GitHub Actions / test / Test (1.21.0, true)

cannot use name (variable of type *StringExpr) as *"github.com/pulumi/esc/syntax".StringNode value in argument to StringSyntaxValue
}

func parseJoin(node *syntax.ObjectNode, name *StringExpr, args Expr) (Expr, syntax.Diagnostics) {
list, ok := args.(*ListExpr)
if !ok || len(list.Elements) != 2 {
Expand Down

0 comments on commit 5c18aed

Please sign in to comment.