@@ -25,6 +25,11 @@ import 'utils.dart';
25
25
import 'value.dart' ;
26
26
import 'visitor/clone_css.dart' ;
27
27
28
+ // TODO(nweiz): This used to avoid tracking source spans for variables if source
29
+ // map generation was disabled. We always have to track them now to produce
30
+ // better warnings for /-as-division, but once those warnings are gone we should
31
+ // go back to tracking conditionally.
32
+
28
33
/// The lexical environment in which Sass is executed.
29
34
///
30
35
/// This tracks lexically-scoped information, such as variables, functions, and
@@ -77,12 +82,10 @@ class AsyncEnvironment {
77
82
78
83
/// The nodes where each variable in [_variables] was defined.
79
84
///
80
- /// This is `null` if source mapping is disabled.
81
- ///
82
85
/// This stores [AstNode] s rather than [FileSpan] s so it can avoid calling
83
86
/// [AstNode.span] if the span isn't required, since some nodes need to do
84
87
/// real work to manufacture a source span.
85
- final List <Map <String , AstNode >>? _variableNodes;
88
+ final List <Map <String , AstNode >> _variableNodes;
86
89
87
90
/// A map of variable names to their indices in [_variables] .
88
91
///
@@ -145,7 +148,7 @@ class AsyncEnvironment {
145
148
/// Creates an [AsyncEnvironment] .
146
149
///
147
150
/// If [sourceMap] is `true` , this tracks variables' source locations
148
- AsyncEnvironment ({ bool sourceMap = false } )
151
+ AsyncEnvironment ()
149
152
: _modules = {},
150
153
_namespaceNodes = {},
151
154
_globalModules = {},
@@ -155,7 +158,7 @@ class AsyncEnvironment {
155
158
_nestedForwardedModules = null ,
156
159
_allModules = [],
157
160
_variables = [{}],
158
- _variableNodes = sourceMap ? [{}] : null ,
161
+ _variableNodes = [{}],
159
162
_variableIndices = {},
160
163
_functions = [{}],
161
164
_functionIndices = {},
@@ -199,7 +202,7 @@ class AsyncEnvironment {
199
202
_nestedForwardedModules,
200
203
_allModules,
201
204
_variables.toList (),
202
- _variableNodes? .toList (),
205
+ _variableNodes.toList (),
203
206
_functions.toList (),
204
207
_mixins.toList (),
205
208
_content);
@@ -218,7 +221,7 @@ class AsyncEnvironment {
218
221
null ,
219
222
[],
220
223
_variables.toList (),
221
- _variableNodes? .toList (),
224
+ _variableNodes.toList (),
222
225
_functions.toList (),
223
226
_mixins.toList (),
224
227
_content);
@@ -406,7 +409,7 @@ class AsyncEnvironment {
406
409
for (var variable in forwardedVariableNames) {
407
410
_variableIndices.remove (variable);
408
411
_variables.last.remove (variable);
409
- _variableNodes? .last.remove (variable);
412
+ _variableNodes.last.remove (variable);
410
413
}
411
414
for (var function in forwardedFunctionNames) {
412
415
_functionIndices.remove (function);
@@ -468,25 +471,18 @@ class AsyncEnvironment {
468
471
/// required, since some nodes need to do real work to manufacture a source
469
472
/// span.
470
473
AstNode ? getVariableNode (String name, {String ? namespace}) {
471
- var variableNodes = _variableNodes;
472
- if (variableNodes == null ) {
473
- throw StateError (
474
- "getVariableNodes() should only be called if sourceMap = true was "
475
- "passed in." );
476
- }
477
-
478
- if (namespace != null ) return _getModule (namespace).variableNodes! [name];
474
+ if (namespace != null ) return _getModule (namespace).variableNodes[name];
479
475
480
476
if (_lastVariableName == name) {
481
- return variableNodes [_lastVariableIndex! ][name] ??
477
+ return _variableNodes [_lastVariableIndex! ][name] ??
482
478
_getVariableNodeFromGlobalModule (name);
483
479
}
484
480
485
481
var index = _variableIndices[name];
486
482
if (index != null ) {
487
483
_lastVariableName = name;
488
484
_lastVariableIndex = index;
489
- return variableNodes [index][name] ??
485
+ return _variableNodes [index][name] ??
490
486
_getVariableNodeFromGlobalModule (name);
491
487
}
492
488
@@ -496,7 +492,8 @@ class AsyncEnvironment {
496
492
_lastVariableName = name;
497
493
_lastVariableIndex = index;
498
494
_variableIndices[name] = index;
499
- return variableNodes[index][name] ?? _getVariableNodeFromGlobalModule (name);
495
+ return _variableNodes[index][name] ??
496
+ _getVariableNodeFromGlobalModule (name);
500
497
}
501
498
502
499
/// Returns the node for the variable named [name] from a namespaceless
@@ -511,7 +508,7 @@ class AsyncEnvironment {
511
508
// We don't need to worry about multiple modules defining the same variable,
512
509
// because that's already been checked by [getVariable].
513
510
for (var module in _globalModules) {
514
- var value = module.variableNodes! [name];
511
+ var value = module.variableNodes[name];
515
512
if (value != null ) return value;
516
513
}
517
514
return null ;
@@ -559,7 +556,7 @@ class AsyncEnvironment {
559
556
/// defined with the given namespace, if no variable with the given [name] is
560
557
/// defined in module with the given namespace, or if no [namespace] is passed
561
558
/// and multiple global modules define variables named [name] .
562
- void setVariable (String name, Value value, AstNode ? nodeWithSpan,
559
+ void setVariable (String name, Value value, AstNode nodeWithSpan,
563
560
{String ? namespace, bool global = false }) {
564
561
if (namespace != null ) {
565
562
_getModule (namespace).setVariable (name, value, nodeWithSpan);
@@ -587,7 +584,7 @@ class AsyncEnvironment {
587
584
}
588
585
589
586
_variables.first[name] = value;
590
- if (nodeWithSpan != null ) _variableNodes? .first[name] = nodeWithSpan;
587
+ _variableNodes.first[name] = nodeWithSpan;
591
588
return ;
592
589
}
593
590
@@ -617,7 +614,7 @@ class AsyncEnvironment {
617
614
_lastVariableName = name;
618
615
_lastVariableIndex = index;
619
616
_variables[index][name] = value;
620
- _variableNodes? [index][name] = nodeWithSpan! ;
617
+ _variableNodes[index][name] = nodeWithSpan;
621
618
}
622
619
623
620
/// Sets the variable named [name] to [value] , associated with
@@ -629,15 +626,13 @@ class AsyncEnvironment {
629
626
/// This takes an [AstNode] rather than a [FileSpan] so it can avoid calling
630
627
/// [AstNode.span] if the span isn't required, since some nodes need to do
631
628
/// real work to manufacture a source span.
632
- void setLocalVariable (String name, Value value, AstNode ? nodeWithSpan) {
629
+ void setLocalVariable (String name, Value value, AstNode nodeWithSpan) {
633
630
var index = _variables.length - 1 ;
634
631
_lastVariableName = name;
635
632
_lastVariableIndex = index;
636
633
_variableIndices[name] = index;
637
634
_variables[index][name] = value;
638
- if (nodeWithSpan != null ) {
639
- _variableNodes? [index][name] = nodeWithSpan;
640
- }
635
+ _variableNodes[index][name] = nodeWithSpan;
641
636
}
642
637
643
638
/// Returns the value of the function named [name] , optionally with the given
@@ -789,7 +784,7 @@ class AsyncEnvironment {
789
784
_inSemiGlobalScope = semiGlobal;
790
785
791
786
_variables.add ({});
792
- _variableNodes? .add ({});
787
+ _variableNodes.add ({});
793
788
_functions.add ({});
794
789
_mixins.add ({});
795
790
_nestedForwardedModules? .add ([]);
@@ -818,12 +813,12 @@ class AsyncEnvironment {
818
813
var configuration = < String , ConfiguredValue > {};
819
814
for (var i = 0 ; i < _variables.length; i++ ) {
820
815
var values = _variables[i];
821
- var nodes = _variableNodes? [i] ?? < String , AstNode > {} ;
816
+ var nodes = _variableNodes[i];
822
817
for (var entry in values.entries) {
823
818
// Implicit configurations are never invalid, making [configurationSpan]
824
819
// unnecessary, so we pass null here to avoid having to compute it.
825
820
configuration[entry.key] =
826
- ConfiguredValue .implicit (entry.value, nodes[entry.key]);
821
+ ConfiguredValue .implicit (entry.value, nodes[entry.key]! );
827
822
}
828
823
}
829
824
return Configuration .implicit (configuration);
@@ -921,7 +916,7 @@ class _EnvironmentModule implements Module {
921
916
922
917
final List <Module > upstream;
923
918
final Map <String , Value > variables;
924
- final Map <String , AstNode >? variableNodes;
919
+ final Map <String , AstNode > variableNodes;
925
920
final Map <String , AsyncCallable > functions;
926
921
final Map <String , AsyncCallable > mixins;
927
922
final ExtensionStore extensionStore;
@@ -951,10 +946,8 @@ class _EnvironmentModule implements Module {
951
946
_makeModulesByVariable (forwarded),
952
947
_memberMap (environment._variables.first,
953
948
forwarded.map ((module) => module.variables)),
954
- environment._variableNodes.andThen ((nodes) => _memberMap (
955
- nodes.first,
956
- // dart-lang/sdk#45348
957
- forwarded! .map ((module) => module.variableNodes! ))),
949
+ _memberMap (environment._variableNodes.first,
950
+ forwarded.map ((module) => module.variableNodes)),
958
951
_memberMap (environment._functions.first,
959
952
forwarded.map ((module) => module.functions)),
960
953
_memberMap (environment._mixins.first,
@@ -1017,7 +1010,7 @@ class _EnvironmentModule implements Module {
1017
1010
required this .transitivelyContainsExtensions})
1018
1011
: upstream = _environment._allModules;
1019
1012
1020
- void setVariable (String name, Value value, AstNode ? nodeWithSpan) {
1013
+ void setVariable (String name, Value value, AstNode nodeWithSpan) {
1021
1014
var module = _modulesByVariable[name];
1022
1015
if (module != null ) {
1023
1016
module.setVariable (name, value, nodeWithSpan);
@@ -1029,9 +1022,7 @@ class _EnvironmentModule implements Module {
1029
1022
}
1030
1023
1031
1024
_environment._variables.first[name] = value;
1032
- if (nodeWithSpan != null ) {
1033
- _environment._variableNodes? .first[name] = nodeWithSpan;
1034
- }
1025
+ _environment._variableNodes.first[name] = nodeWithSpan;
1035
1026
return ;
1036
1027
}
1037
1028
0 commit comments