cue: fix compilation bug using $foo identifiers

Change-Id: I3d64316f11e12da8e7ffa617081a9843c052c1a6
Reviewed-on: https://cue-review.googlesource.com/c/cue/+/4320
Reviewed-by: Marcel van Lohuizen <mpvl@golang.org>
diff --git a/cmd/cue/cmd/testdata/script/export.txt b/cmd/cue/cmd/testdata/script/export.txt
index 6d70421..ad5c5cf 100644
--- a/cmd/cue/cmd/testdata/script/export.txt
+++ b/cmd/cue/cmd/testdata/script/export.txt
@@ -2,6 +2,7 @@
 cmp stdout expect-stdout
 -- expect-stdout --
 {
+    "$type": "demo",
     "message": "Hello World!"
 }
 -- hello/data.cue --
@@ -11,5 +12,6 @@
 -- hello/hello.cue --
 package hello
 
+$type:   "demo"
 message: "Hello \(who)!" // who declared in data.cue
 -- hello/cue.mod --
diff --git a/cue/ast/ident.go b/cue/ast/ident.go
index 22e3762..b0a18d9 100644
--- a/cue/ast/ident.go
+++ b/cue/ast/ident.go
@@ -100,7 +100,7 @@
 	}
 
 	for _, r := range ident {
-		if isLetter(r) || isDigit(r) || r == '_' {
+		if isLetter(r) || isDigit(r) || r == '_' || r == '$' {
 			continue
 		}
 		if r == '-' && quoted {