Skip to content

Commit

Permalink
Allow ClojureScript interop symbols
Browse files Browse the repository at this point in the history
  • Loading branch information
candid82 committed May 25, 2018
1 parent 4b514ea commit 830f4f0
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 0 deletions.
6 changes: 6 additions & 0 deletions core/parse.go
Original file line number Diff line number Diff line change
Expand Up @@ -1514,6 +1514,7 @@ func parseSymbol(obj Object, ctx *ParseContext) Expr {
panic(&ParseError{obj: obj, msg: "Unable to resolve symbol: " + sym.ToString(false)})
}
if DIALECT == CLJS && sym.ns == nil {
// Check if this is a "callable namespace"
ns := ctx.GlobalEnv.FindNamespace(sym)
if ns == nil {
ns = ctx.GlobalEnv.CurrentNamespace().aliases[sym.name]
Expand All @@ -1522,6 +1523,11 @@ func parseSymbol(obj Object, ctx *ParseContext) Expr {
ns.isUsed = true
return NewSurrogateExpr(obj)
}
// See if this is a JS interop (i.e. Math.PI)
parts := strings.Split(sym.Name(), ".")
if len(parts) > 1 {
return parseSymbol(DeriveReadObject(obj, MakeSymbol(parts[0])), ctx)
}
}
symNs := ctx.GlobalEnv.NamespaceFor(ctx.GlobalEnv.CurrentNamespace(), sym)
if symNs == nil || symNs == ctx.GlobalEnv.CurrentNamespace() {
Expand Down
4 changes: 4 additions & 0 deletions tests/linter/cljs-interop/input.cljs
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
js/Math.PI
(def m js/Math)
m.PI
g.PI
1 change: 1 addition & 0 deletions tests/linter/cljs-interop/output.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
tests/linter/cljs-interop/input.cljs:4:1: Parse error: Unable to resolve symbol: g

0 comments on commit 830f4f0

Please sign in to comment.