6
6
7
7
import 'package:args/args.dart' ;
8
8
import 'package:collection/collection.dart' ;
9
+ import 'package:charcode/charcode.dart' ;
9
10
import 'package:path/path.dart' as p;
10
11
import 'package:sass_api/sass_api.dart' ;
11
12
import 'package:source_span/source_span.dart' ;
@@ -191,6 +192,9 @@ class _ModuleMigrationVisitor extends MigrationVisitor {
191
192
"Can't access _configuredVariables when not visiting a dependency." ));
192
193
Set <MemberDeclaration <VariableDeclaration >>? __configuredVariables;
193
194
195
+ /// The number of variables that have been generated from whole cloth.
196
+ var _generatedVariables = 0 ;
197
+
194
198
/// A mapping between member declarations and references.
195
199
///
196
200
/// This performs an initial pass to determine how a declaration seen in the
@@ -354,9 +358,9 @@ class _ModuleMigrationVisitor extends MigrationVisitor {
354
358
var name = declaration.name;
355
359
if (_isPrivate (name) &&
356
360
references.referencedOutsideDeclaringStylesheet (declaration)) {
357
- // Remove leading `-` since private members can't be accessed outside
358
- // the module they're declared in.
359
- name = name. substring ( 1 );
361
+ // Private members can't be accessed outside the module they're declared
362
+ // in.
363
+ name = _privateToPublic (name );
360
364
}
361
365
name = _unprefix (name);
362
366
if (name != declaration.name) {
@@ -372,6 +376,20 @@ class _ModuleMigrationVisitor extends MigrationVisitor {
372
376
return identifier.startsWith ('-' ) || identifier.startsWith ('_' );
373
377
}
374
378
379
+ /// Converts a private identifier to a public one.
380
+ String _privateToPublic (String identifier) {
381
+ assert (_isPrivate (identifier));
382
+ for (var i = 0 ; i < identifier.length; i++ ) {
383
+ var char = identifier.codeUnitAt (i);
384
+ if (char != $dash && char != $underscore) {
385
+ return identifier.substring (i);
386
+ }
387
+ }
388
+
389
+ _generatedVariables++ ;
390
+ return 'var${_generatedVariables }' ;
391
+ }
392
+
375
393
/// Returns whether the member named [name] should be forwarded in the
376
394
/// entrypoint.
377
395
///
@@ -1082,7 +1100,7 @@ class _ModuleMigrationVisitor extends MigrationVisitor {
1082
1100
if (declaration is ImportOnlyMemberDeclaration ) {
1083
1101
name = name.substring (declaration.importOnlyPrefix.length);
1084
1102
}
1085
- if (_isPrivate (name)) name = name. substring ( 1 );
1103
+ if (_isPrivate (name)) name = _privateToPublic (name );
1086
1104
name = _unprefix (name);
1087
1105
if (subprefix.isNotEmpty) name = '$subprefix $name ' ;
1088
1106
if (declaration.member is VariableDeclaration ) name = '\$ $name ' ;
@@ -1235,7 +1253,7 @@ class _ModuleMigrationVisitor extends MigrationVisitor {
1235
1253
/// Otherwise, returns [name] unaltered.
1236
1254
String _unprefix (String name) {
1237
1255
var isPrivate = _isPrivate (name);
1238
- var unprivateName = isPrivate ? name. substring ( 1 ) : name;
1256
+ var unprivateName = isPrivate ? _privateToPublic (name ) : name;
1239
1257
var prefix = _prefixFor (unprivateName);
1240
1258
if (prefix == null ) return name;
1241
1259
return (isPrivate ? '-' : '' ) + unprivateName.substring (prefix.length);
0 commit comments