Skip to content

Commit 2ecde7b

Browse files
committed
all: remove the dollar identifier
Dollar identifier was a deprecated feature, this change removes it.
1 parent f423f04 commit 2ecde7b

22 files changed

+50
-400
lines changed

ast/ast.go

Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -699,27 +699,6 @@ func (n *Defer) String() string {
699699
return "defer " + n.Call.String()
700700
}
701701

702-
// DollarIdentifier node represents a dollar identifier in the form $id.
703-
type DollarIdentifier struct {
704-
*expression
705-
*Position // position in the source.
706-
Ident *Identifier // identifier.
707-
708-
IR struct {
709-
Ident Expression
710-
}
711-
}
712-
713-
// NewDollarIdentifier returns a new DollarIdentifier node.
714-
func NewDollarIdentifier(pos *Position, ident *Identifier) *DollarIdentifier {
715-
return &DollarIdentifier{&expression{}, pos, ident, struct{ Ident Expression }{}}
716-
}
717-
718-
// String returns the string representation of n.
719-
func (n *DollarIdentifier) String() string {
720-
return "$" + n.Ident.String()
721-
}
722-
723702
// Extends node represents an "extends" declaration.
724703
type Extends struct {
725704
*Position // position in the source.

ast/astutil/clone.go

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -393,9 +393,6 @@ func CloneExpression(expr ast.Expression) ast.Expression {
393393
case *ast.Default:
394394
expr2 = ast.NewDefault(ClonePosition(e.Position), CloneExpression(e.Expr1), CloneExpression(e.Expr2))
395395

396-
case *ast.DollarIdentifier:
397-
expr2 = ast.NewDollarIdentifier(ClonePosition(e.Position), CloneExpression(e.Ident).(*ast.Identifier))
398-
399396
case *ast.Func:
400397
var ident *ast.Identifier
401398
if e.Ident != nil {

ast/astutil/dump_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ func ExampleDump() {
2828
}
2929

3030
for _, c := range cases {
31-
tree, _, err := compiler.ParseTemplateSource([]byte(c), ast.FormatHTML, false, false, false)
31+
tree, _, err := compiler.ParseTemplateSource([]byte(c), ast.FormatHTML, false, false)
3232
if err != nil {
3333
panic(err)
3434
}

ast/astutil/walk.go

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -108,9 +108,6 @@ func Walk(v Visitor, node ast.Node) {
108108
Walk(v, n.Expr1)
109109
Walk(v, n.Expr2)
110110

111-
case *ast.DollarIdentifier:
112-
Walk(v, n.Ident)
113-
114111
case *ast.For:
115112
if n.Init != nil {
116113
Walk(v, n.Init)

ast/astutil/walk_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ func TestWalk(t *testing.T) {
6262
}
6363

6464
for _, c := range stringCases {
65-
tree, _, err := compiler.ParseTemplateSource([]byte(c.input), ast.FormatHTML, false, false, false)
65+
tree, _, err := compiler.ParseTemplateSource([]byte(c.input), ast.FormatHTML, false, false)
6666
if err != nil {
6767
panic(err)
6868
}

internal/compiler/checker_dependencies.go

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -332,10 +332,6 @@ func (d *deps) nodeDeps(n ast.Node, scopes depScopes) []*ast.Identifier {
332332
deps = append(deps, d.nodeDeps(out.Type, scopes)...)
333333
}
334334
return deps
335-
case *ast.DollarIdentifier:
336-
// A valid dollar identifier can at most depend upon global
337-
// identifiers, so it is not considered in the dependency analysis.
338-
return nil
339335
case *ast.Go:
340336
return d.nodeDeps(n.Call, scopes)
341337
case *ast.Goto:

internal/compiler/checker_expressions.go

Lines changed: 0 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -455,9 +455,6 @@ func (tc *typechecker) typeof(expr ast.Expression, typeExpected bool) *typeInfo
455455
}
456456
return t
457457

458-
case *ast.DollarIdentifier:
459-
return tc.checkDollarIdentifier(expr)
460-
461458
case *ast.Identifier:
462459
return tc.checkIdentifier(expr, true)
463460

@@ -2208,51 +2205,6 @@ func (tc *typechecker) isCompileConstant(expr ast.Expression) bool {
22082205
return true
22092206
}
22102207

2211-
// checkDollarIdentifier type checks a dollar identifier $x.
2212-
func (tc *typechecker) checkDollarIdentifier(expr *ast.DollarIdentifier) *typeInfo {
2213-
2214-
// Check that x is a valid identifier.
2215-
if ti, _, ok := tc.scopes.Lookup(expr.Ident.Name); ok {
2216-
// Check that x is not a builtin function.
2217-
if ti.IsBuiltinFunction() {
2218-
panic(tc.errorf(expr.Ident, "use of builtin %s not in function call", expr.Ident))
2219-
}
2220-
// Check that x is not a type.
2221-
if ti.IsType() {
2222-
panic(tc.errorf(expr.Ident, "unexpected type in dollar identifier"))
2223-
}
2224-
// Check that x is not a local identifier.
2225-
if _, _, ok := tc.scopes.LookupInFunc(expr.Ident.Name); ok {
2226-
panic(tc.errorf(expr, "use of local identifier within dollar identifier"))
2227-
}
2228-
// Check that x is not declared in the file/package block, that
2229-
// contains, for example, the variable declarations at the top level of
2230-
// an imported or extending file.
2231-
if _, ok := tc.scopes.FilePackage(expr.Ident.Name); ok {
2232-
panic(tc.errorf(expr, "use of top-level identifier within dollar identifier"))
2233-
}
2234-
}
2235-
2236-
// Set the IR of the expression.
2237-
var arg *ast.Identifier
2238-
var pos = expr.Pos()
2239-
if _, ok := tc.scopes.Global(expr.Ident.Name); ok {
2240-
arg = expr.Ident // "x"
2241-
} else {
2242-
arg = ast.NewIdentifier(pos, "nil") // "nil"
2243-
}
2244-
// expr.IR.Ident is set to "interface{}(x)" or "interface{}(nil)".
2245-
expr.IR.Ident = ast.NewCall(
2246-
pos,
2247-
ast.NewInterface(pos), // "interface{}"
2248-
[]ast.Expression{arg}, // "x" or "nil"
2249-
false,
2250-
)
2251-
2252-
// Type check the IR of the expression and return its type info.
2253-
return tc.checkExpr(expr.IR.Ident)
2254-
}
2255-
22562208
// checkDefault type checks a default expression. show indicates if the
22572209
// default expression is in a show statement.
22582210
func (tc *typechecker) checkDefault(expr *ast.Default, show bool) typeInfoPair {

internal/compiler/checker_template_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,7 @@ func TestCheckerTemplateExpressions(t *testing.T) {
168168
}
169169
options := checkerOptions{mod: templateMod, formatTypes: formatTypes, mdConverter: mdConverter}
170170
for _, expr := range checkerTemplateExprs {
171-
var lex = scanTemplate([]byte("{{ "+expr.src+" }}"), ast.FormatText, false, false)
171+
var lex = scanTemplate([]byte("{{ "+expr.src+" }}"), ast.FormatText, false)
172172
func() {
173173
defer func() {
174174
if r := recover(); r != nil {
@@ -241,7 +241,7 @@ var checkerTemplateExprErrors = []struct {
241241
func TestCheckerTemplateExpressionErrors(t *testing.T) {
242242
options := checkerOptions{mod: templateMod, formatTypes: formatTypes}
243243
for _, expr := range checkerTemplateExprErrors {
244-
var lex = scanTemplate([]byte("{{ "+expr.src+" }}"), ast.FormatText, false, false)
244+
var lex = scanTemplate([]byte("{{ "+expr.src+" }}"), ast.FormatText, false)
245245
func() {
246246
defer func() {
247247
if r := recover(); r != nil {

internal/compiler/compiler.go

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -62,13 +62,6 @@ type Options struct {
6262
AllowGoStmt bool
6363
NoParseShortShowStmt bool
6464

65-
// DollarIdentifier, when true, keeps the backward compatibility by
66-
// supporting the dollar identifier.
67-
//
68-
// NOTE: the dollar identifier is deprecated and will be removed in a
69-
// future version of Scriggo.
70-
DollarIdentifier bool
71-
7265
FormatTypes map[ast.Format]reflect.Type
7366
Globals native.Declarations
7467

@@ -166,7 +159,7 @@ func BuildTemplate(fsys fs.FS, name string, opts Options) (*Code, error) {
166159

167160
// Parse the source code.
168161
var err error
169-
tree, err = ParseTemplate(fsys, name, opts.NoParseShortShowStmt, opts.DollarIdentifier)
162+
tree, err = ParseTemplate(fsys, name, opts.NoParseShortShowStmt)
170163
if err != nil {
171164
return nil, err
172165
}

internal/compiler/emitter_expressions.go

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -150,16 +150,6 @@ func (em *emitter) _emitExpr(expr ast.Expression, dstType reflect.Type, reg int8
150150

151151
return em.emitCompositeLiteral(expr, reg, dstType)
152152

153-
case *ast.DollarIdentifier:
154-
155-
// The field expr.IR.Ident has been set by the type checker; it may be
156-
// interface{}(x) if x is an existing global identifier, or
157-
// interface{}(nil) otherwise.
158-
//
159-
// So, the emission of a dollar identifier can be done simply by
160-
// emitting expr.IR.Ident.
161-
return em._emitExpr(expr.IR.Ident, dstType, reg, useGivenReg, allowK)
162-
163153
case *ast.Default:
164154
ex := expr.Expr1
165155
if ti := em.ti(expr.Expr1); ti == nil {

0 commit comments

Comments
 (0)