Skip to content
This repository was archived by the owner on Aug 27, 2018. It is now read-only.

Commit 55fa170

Browse files
authored
Merge pull request #128 from myitcv/remove_aria_hack
react: revert Aria hack; JSX parsing to follow
2 parents a7280a2 + 1609b4d commit 55fa170

34 files changed

+277
-205
lines changed

.vendor.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
./_vendor/src/golang.org/x/crypto 3cb07270c9455e8ad27956a70891c962d121a228 https://go.googlesource.com/crypto
44
./_vendor/src/golang.org/x/tools 620ecdb8d7943e20dc030b61bfe898d1b000bdea https://go.googlesource.com/tools
55
./_vendor/src/github.com/jteeuwen/go-bindata a0ff2567cfb70903282db057e799fd826784d41d [email protected]:jteeuwen/go-bindata
6-
./_vendor/src/github.com/gopherjs/gopherjs 558a9132744c22476178edf3126fd35a9754f565 [email protected]:gopherjs/gopherjs
6+
./_vendor/src/github.com/gopherjs/gopherjs e14987c0ef06db387b90fec85e8d06dc05598e24 [email protected]:gopherjs/gopherjs
77
./_vendor/src/github.com/gopherjs/jsbuiltin 67703bfb044e3192fbcab025c3aeaeedafad1f2f [email protected]:gopherjs/jsbuiltin
88
./_vendor/src/github.com/kisielk/gotool 0de1eaf82fa3f583ce21fde859f1e7e0c5e9b220 [email protected]:kisielk/gotool
99
./_vendor/src/github.com/fsnotify/fsnotify 7d7316ed6e1ed2de075aab8dfc76de5d158d66e1 [email protected]:fsnotify/fsnotify

_vendor/src/github.com/gopherjs/gopherjs/compiler/expressions.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -516,9 +516,9 @@ func (c *funcContext) translateExpr(expr ast.Expr) *expression {
516516
fields, jsTag := c.translateSelection(sel, e.Pos())
517517
if jsTag != "" {
518518
if _, ok := sel.Type().(*types.Signature); ok {
519-
return c.formatExpr("$internalize(%1e.%2s.%3s, %4s, %1e.%2s)", e.X, strings.Join(fields, "."), jsTag, c.typeName(sel.Type()))
519+
return c.formatExpr("$internalize(%1e.%2s%3s, %4s, %1e.%2s)", e.X, strings.Join(fields, "."), formatJSStructTagVal(jsTag), c.typeName(sel.Type()))
520520
}
521-
return c.internalize(c.formatExpr("%e.%s.%s", e.X, strings.Join(fields, "."), jsTag), sel.Type())
521+
return c.internalize(c.formatExpr("%e.%s%s", e.X, strings.Join(fields, "."), formatJSStructTagVal(jsTag)), sel.Type())
522522
}
523523
return c.formatExpr("%e.%s", e.X, strings.Join(fields, "."))
524524
case types.MethodVal:
@@ -669,7 +669,7 @@ func (c *funcContext) translateExpr(expr ast.Expr) *expression {
669669
case types.FieldVal:
670670
fields, jsTag := c.translateSelection(sel, f.Pos())
671671
if jsTag != "" {
672-
call := c.formatExpr("%e.%s.%s(%s)", f.X, strings.Join(fields, "."), jsTag, externalizeArgs(e.Args))
672+
call := c.formatExpr("%e.%s%s(%s)", f.X, strings.Join(fields, "."), formatJSStructTagVal(jsTag), externalizeArgs(e.Args))
673673
switch sig.Results().Len() {
674674
case 0:
675675
return call

_vendor/src/github.com/gopherjs/gopherjs/compiler/statements.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -703,7 +703,7 @@ func (c *funcContext) translateAssign(lhs, rhs ast.Expr, define bool) string {
703703
}
704704
fields, jsTag := c.translateSelection(sel, l.Pos())
705705
if jsTag != "" {
706-
return fmt.Sprintf("%s.%s.%s = %s;", c.translateExpr(l.X), strings.Join(fields, "."), jsTag, c.externalize(rhsExpr.String(), sel.Type()))
706+
return fmt.Sprintf("%s.%s%s = %s;", c.translateExpr(l.X), strings.Join(fields, "."), formatJSStructTagVal(jsTag), c.externalize(rhsExpr.String(), sel.Type()))
707707
}
708708
return fmt.Sprintf("%s.%s = %s;", c.translateExpr(l.X), strings.Join(fields, "."), rhsExpr)
709709
case *ast.StarExpr:

_vendor/src/github.com/gopherjs/gopherjs/compiler/utils.go

+28
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ import (
1212
"sort"
1313
"strconv"
1414
"strings"
15+
"text/template"
16+
"unicode"
1517

1618
"github.com/gopherjs/gopherjs/compiler/analysis"
1719
"github.com/gopherjs/gopherjs/compiler/typesutil"
@@ -643,3 +645,29 @@ func endsWithReturn(stmts []ast.Stmt) bool {
643645
func encodeIdent(name string) string {
644646
return strings.Replace(url.QueryEscape(name), "%", "$", -1)
645647
}
648+
649+
// formatJSStructTagVal returns JavaScript code for accessing an object's property
650+
// identified by jsTag. It prefers the dot notation over the bracket notation when
651+
// possible, since the dot notation produces slightly smaller output.
652+
//
653+
// For example:
654+
//
655+
// "my_name" -> ".my_name"
656+
// "my name" -> `["my name"]`
657+
//
658+
// For more information about JavaScript property accessors and identifiers, see
659+
// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Property_Accessors and
660+
// https://developer.mozilla.org/en-US/docs/Glossary/Identifier.
661+
//
662+
func formatJSStructTagVal(jsTag string) string {
663+
for i, r := range jsTag {
664+
ok := unicode.IsLetter(r) || (i != 0 && unicode.IsNumber(r)) || r == '$' || r == '_'
665+
if !ok {
666+
// Saw an invalid JavaScript identifier character,
667+
// so use bracket notation.
668+
return `["` + template.JSEscapeString(jsTag) + `"]`
669+
}
670+
}
671+
// Safe to use dot notation without any escaping.
672+
return "." + jsTag
673+
}

_vendor/src/github.com/gopherjs/gopherjs/js/js_test.go

+23
Original file line numberDiff line numberDiff line change
@@ -597,3 +597,26 @@ func TestTypeSwitchJSObject(t *testing.T) {
597597
}
598598
}
599599
}
600+
601+
func TestStructWithNonIdentifierJSTag(t *testing.T) {
602+
type S struct {
603+
*js.Object
604+
Name string `js:"@&\"'<>//my name"`
605+
}
606+
s := S{Object: js.Global.Get("Object").New()}
607+
608+
// externalise a value via field
609+
s.Name = "Paul"
610+
611+
// internalise via field
612+
got := s.Name
613+
if want := "Paul"; got != want {
614+
t.Errorf("value via field with non-identifier js tag gave %q, want %q", got, want)
615+
}
616+
617+
// verify we can do a Get with the struct tag
618+
got = s.Get("@&\"'<>//my name").String()
619+
if want := "Paul"; got != want {
620+
t.Errorf("value via js.Object.Get gave %q, want %q", got, want)
621+
}
622+
}

core.go

+4-1
Original file line numberDiff line numberDiff line change
@@ -28,13 +28,16 @@ type DataSet map[string]string
2828
type BasicHTMLElement struct {
2929
*BasicElement
3030

31+
AriaHasPopup bool `js:"aria-haspopup"`
32+
AriaExpanded bool `js:"aria-expanded"`
33+
AriaLabelledBy string `js:"aria-labelledby"`
34+
3135
ID string `js:"id" react:"omitempty"`
3236
Key string `js:"key" react:"omitempty"`
3337
ClassName string `js:"className"`
3438
Role string `js:"role"`
3539
Style *CSS `js:"style"`
3640

37-
AriaSet
3841
DataSet
3942

4043
OnChange `js:"onChange"`

examples/sites/syntaxviewer/app.go

+8-10
Original file line numberDiff line numberDiff line change
@@ -75,22 +75,20 @@ func (a AppDef) Render() react.Element {
7575
&react.DivProps{ClassName: "dropdown", Style: &react.CSS{Float: "right"}},
7676
react.Button(
7777
&react.ButtonProps{
78-
ClassName: "btn btn-default dropdown-toggle",
79-
Type: "button",
80-
ID: "dropdownMenu1",
81-
DataSet: react.DataSet{"toggle": "dropdown"},
82-
AriaSet: react.AriaSet{
83-
"haspopup": "true",
84-
"expanded": "true",
85-
},
78+
ClassName: "btn btn-default dropdown-toggle",
79+
Type: "button",
80+
ID: "dropdownMenu1",
81+
DataSet: react.DataSet{"toggle": "dropdown"},
82+
AriaHasPopup: true,
83+
AriaExpanded: true,
8684
},
8785
react.S(s.Name+" "),
8886
react.Span(&react.SpanProps{ClassName: "caret"}),
8987
),
9088
react.Ul(
9189
&react.UlProps{
92-
ClassName: "dropdown-menu dropdown-menu-right",
93-
AriaSet: react.AriaSet{"labelledby": "dropdownMenu1"},
90+
ClassName: "dropdown-menu dropdown-menu-right",
91+
AriaLabelledBy: "dropdownMenu1",
9492
},
9593
buildLi(a.State().Go),
9694
buildLi(a.State().Shell),

gen_AProps_reactGen.go

+8-6
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

gen_BrProps_reactGen.go

+8-6
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

gen_ButtonProps_reactGen.go

+8-6
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

gen_CodeProps_reactGen.go

+8-6
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

gen_DivProps_reactGen.go

+8-6
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

gen_FooterProps_reactGen.go

+8-6
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

gen_FormProps_reactGen.go

+8-6
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

gen_H1Props_reactGen.go

+8-6
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)