[go: nahoru, domu]

Skip to content
This repository has been archived by the owner on Sep 9, 2020. It is now read-only.

Commit

Permalink
Field expressions shouldn't assume they are object comps
Browse files Browse the repository at this point in the history
Fixes #143

Signed-off-by: bryanl <bryanliles@gmail.com>
  • Loading branch information
bryanl committed May 29, 2018
1 parent 52b6acc commit a69cc87
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 13 deletions.
30 changes: 17 additions & 13 deletions ksonnet-gen/printer/printer.go
Original file line number Diff line number Diff line change
Expand Up @@ -714,7 +714,13 @@ func (p *printer) fieldID(kind ast.ObjectFieldKind, expr1 ast.Node, id *ast.Iden
}

func (p *printer) handleObjectComp(oc *ast.ObjectComp) {
p.writeString("{")
p.indentLevel++
p.writeByte(newline, 1)
p.handleObjectField(oc)
p.indentLevel--
p.writeByte(newline, 1)
p.writeString("}")
}

func (p *printer) handleArrayComp(ac *ast.ArrayComp) {
Expand All @@ -735,12 +741,14 @@ func (p *printer) forSpec(spec ast.ForSpec) {
p.writeByte(newline, 1)
}

p.writeString(fmt.Sprintf("for %s in ", string(spec.VarName)))
p.print(spec.Expr)
if spec.VarName != "" {
p.writeString(fmt.Sprintf("for %s in ", string(spec.VarName)))
p.print(spec.Expr)

for _, ifSpec := range spec.Conditions {
p.writeByte(newline, 1)
p.print(ifSpec)
for _, ifSpec := range spec.Conditions {
p.writeByte(newline, 1)
p.print(ifSpec)
}
}
}

Expand Down Expand Up @@ -851,16 +859,12 @@ func (p *printer) handleObjectField(n interface{}) {
p.writeByte(space, 1)
p.print(ofExpr2)
case ast.ObjectFieldExpr:
p.writeString("{")
p.indentLevel++
p.writeByte(newline, 1)
p.writeString(fmt.Sprintf("[%s]: ", ofID))
p.print(ofExpr2)
p.writeByte(newline, 1)
p.forSpec(forSpec)
p.indentLevel--
p.writeByte(newline, 1)
p.writeString("}")
if forSpec.VarName != "" {
p.writeByte(newline, 1)
p.forSpec(forSpec)
}
}
}

Expand Down
11 changes: 11 additions & 0 deletions ksonnet-gen/printer/testdata/upstream/object_comp_local.jsonnet
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
local domain = '.example.org';
local services = ['one', 'two'];
local computedServices = [
local serviceName = service;
local serviceUrl = service + domain;

{ [serviceName]: serviceUrl }
for service in services
];

std.prune(computedServices)

0 comments on commit a69cc87

Please sign in to comment.