|
5 | 5 | import 'package:meta/meta.dart'; |
6 | 6 | import 'package:source_span/source_span.dart'; |
7 | 7 |
|
| 8 | +import '../../../util/span.dart'; |
8 | 9 | import '../../../visitor/interface/expression.dart'; |
9 | 10 | import '../expression.dart'; |
10 | 11 | import '../argument_invocation.dart'; |
11 | 12 | import '../callable_invocation.dart'; |
12 | | -import '../interpolation.dart'; |
| 13 | +import '../reference.dart'; |
13 | 14 |
|
14 | 15 | /// A function invocation. |
15 | 16 | /// |
16 | | -/// This may be a plain CSS function or a Sass function. |
| 17 | +/// This may be a plain CSS function or a Sass function, but may not include |
| 18 | +/// interpolation. |
17 | 19 | /// |
18 | 20 | /// {@category AST} |
19 | 21 | @sealed |
20 | | -class FunctionExpression implements Expression, CallableInvocation { |
| 22 | +class FunctionExpression |
| 23 | + implements Expression, CallableInvocation, SassReference { |
21 | 24 | /// The namespace of the function being invoked, or `null` if it's invoked |
22 | 25 | /// without a namespace. |
23 | 26 | final String? namespace; |
24 | 27 |
|
25 | | - /// The name of the function being invoked. |
26 | | - /// |
27 | | - /// If [namespace] is non-`null`, underscores are converted to hyphens in this name. |
28 | | - /// If [namespace] is `null`, this could be a plain CSS function call, so underscores are kept unchanged. |
29 | | - /// |
30 | | - /// If this is interpolated, the function will be interpreted as plain CSS, |
31 | | - /// even if it has the same name as a Sass function. |
32 | | - final Interpolation name; |
| 28 | + /// The name of the function being invoked, with underscores left as-is. |
| 29 | + final String originalName; |
33 | 30 |
|
34 | 31 | /// The arguments to pass to the function. |
35 | 32 | final ArgumentInvocation arguments; |
36 | 33 |
|
37 | 34 | final FileSpan span; |
38 | 35 |
|
39 | | - FunctionExpression(this.name, this.arguments, this.span, {this.namespace}); |
| 36 | + /// The name of the function being invoked, with underscores converted to |
| 37 | + /// hyphens. |
| 38 | + /// |
| 39 | + /// If this function is a plain CSS function, use [originalName] instead. |
| 40 | + String get name => originalName.replaceAll('_', '-'); |
| 41 | + |
| 42 | + FileSpan get nameSpan { |
| 43 | + if (namespace == null) return span.initialIdentifier(); |
| 44 | + return span.withoutNamespace().initialIdentifier(); |
| 45 | + } |
| 46 | + |
| 47 | + FileSpan? get namespaceSpan => |
| 48 | + namespace == null ? null : span.initialIdentifier(); |
| 49 | + |
| 50 | + FunctionExpression(this.originalName, this.arguments, this.span, |
| 51 | + {this.namespace}); |
40 | 52 |
|
41 | 53 | T accept<T>(ExpressionVisitor<T> visitor) => |
42 | 54 | visitor.visitFunctionExpression(this); |
43 | 55 |
|
44 | 56 | String toString() { |
45 | 57 | var buffer = StringBuffer(); |
46 | 58 | if (namespace != null) buffer.write("$namespace."); |
47 | | - buffer.write("$name$arguments"); |
| 59 | + buffer.write("$originalName$arguments"); |
48 | 60 | return buffer.toString(); |
49 | 61 | } |
50 | 62 | } |
0 commit comments