@@ -124,7 +124,7 @@ class _ModuleMigrationVisitor extends MigrationVisitor {
124
124
125
125
/// Maps canonical URLs to the original URL and importer from the `@import`
126
126
/// rule that last imported that URL.
127
- final _originalImports = < Uri , Tuple2 <String , Importer >> {};
127
+ final _originalImports = < Uri , Tuple2 <Uri , Importer >> {};
128
128
129
129
/// Tracks members that are unreferencable in the current scope.
130
130
var _unreferencable = UnreferencableMembers ();
@@ -527,7 +527,7 @@ class _ModuleMigrationVisitor extends MigrationVisitor {
527
527
// namespace.
528
528
var paths = {
529
529
for (var source in sources)
530
- source: ruleUrlsForSources[source]! .split ( '/' )
530
+ source: ruleUrlsForSources[source]! .pathSegments. toList ( )
531
531
..removeLast ()
532
532
..removeWhere ((segment) => segment.contains ('.' ))
533
533
};
@@ -586,10 +586,10 @@ class _ModuleMigrationVisitor extends MigrationVisitor {
586
586
/// Given a set of import sources, groups them by the number of path segments
587
587
/// and sorts those groups from fewer to more segments.
588
588
List <Set <ImportSource >> _orderSources (
589
- Map <ImportSource , String > ruleUrlsForSources) {
589
+ Map <ImportSource , Uri > ruleUrlsForSources) {
590
590
var byPathLength = < int , Set <ImportSource >> {};
591
591
for (var entry in ruleUrlsForSources.entries) {
592
- var pathSegments = Uri . parse ( entry.value) .pathSegments;
592
+ var pathSegments = entry.value.pathSegments;
593
593
byPathLength.putIfAbsent (pathSegments.length, () => {}).add (entry.key);
594
594
}
595
595
return [
@@ -616,16 +616,17 @@ class _ModuleMigrationVisitor extends MigrationVisitor {
616
616
}
617
617
if (references.sources.containsKey (node)) {
618
618
var declaration = references.functions[node];
619
+ var fnNameSpan = nameSpan (node);
619
620
if (declaration != null ) {
620
621
_unreferencable.check (declaration, node);
621
- _renameReference (nameSpan (node) , declaration);
622
+ _renameReference (fnNameSpan , declaration);
622
623
}
623
624
_patchNamespaceForFunction (node, declaration, (namespace) {
624
- addPatch (patchBefore (node.name , '$namespace .' ));
625
+ addPatch (Patch . insert (fnNameSpan.start , '$namespace .' ));
625
626
});
626
627
}
627
628
628
- if (node.name.asPlain == "get-function" ) {
629
+ if (node.name == "get-function" ) {
629
630
var declaration = references.getFunctionReferences[node];
630
631
if (declaration != null ) {
631
632
_unreferencable.check (declaration, node);
@@ -774,8 +775,8 @@ class _ModuleMigrationVisitor extends MigrationVisitor {
774
775
var indent = ' ' * node.span.start.column;
775
776
776
777
for (var import in dynamicImports) {
777
- String ? ruleUrl = import.url;
778
- var tuple = importCache.canonicalize (Uri . parse ( ruleUrl) ,
778
+ Uri ? ruleUrl = import.url;
779
+ var tuple = importCache.canonicalize (ruleUrl,
779
780
baseImporter: importer, baseUrl: currentUrl, forImport: true );
780
781
var canonicalImport = tuple? .item2;
781
782
if (canonicalImport != null &&
@@ -834,14 +835,14 @@ class _ModuleMigrationVisitor extends MigrationVisitor {
834
835
/// `@forward` rule from an import-only file that does not forward its
835
836
/// corresponding regular file. This allows imports of import-only files that
836
837
/// redirect to a different path to be migrated in-place.
837
- List <String > _migrateImportToRules (String ruleUrl, FileSpan context) {
838
+ List <String > _migrateImportToRules (Uri ruleUrl, FileSpan context) {
838
839
var tuple = _migrateImportCommon (ruleUrl, context);
839
840
var canonicalUrl = tuple.item1;
840
841
var config = tuple.item2;
841
842
var forwardForConfig = tuple.item3;
842
843
843
844
var asClause = '' ;
844
- var defaultNamespace = namespaceForPath (ruleUrl);
845
+ var defaultNamespace = namespaceForPath (ruleUrl.path );
845
846
// If a member from this dependency is actually referenced, it should
846
847
// already have a namespace from [_determineNamespaces], so we just use
847
848
// a simple number suffix to resolve conflicts at this point.
@@ -877,7 +878,7 @@ class _ModuleMigrationVisitor extends MigrationVisitor {
877
878
///
878
879
/// This is used for migrating `@import` rules that are nested or appear after
879
880
/// some other rules.
880
- String _migrateImportToLoadCss (String ruleUrl, FileSpan context) {
881
+ String _migrateImportToLoadCss (Uri ruleUrl, FileSpan context) {
881
882
var oldUnreferencable = _unreferencable;
882
883
_unreferencable = UnreferencableMembers (_unreferencable);
883
884
for (var declaration in references.allDeclarations) {
@@ -919,20 +920,19 @@ class _ModuleMigrationVisitor extends MigrationVisitor {
919
920
/// to a `show` clause of a `@forward` rule so that they can be configured by
920
921
/// an upstream file.
921
922
Tuple3 <Uri , String ?, String ?> _migrateImportCommon (
922
- String ruleUrl, FileSpan context) {
923
+ Uri ruleUrl, FileSpan context) {
923
924
var oldConfiguredVariables = __configuredVariables;
924
925
__configuredVariables = {};
925
926
_upstreamStylesheets.add (currentUrl);
926
- var parsedUrl = Uri .parse (ruleUrl);
927
- if (migrateDependencies) visitDependency (parsedUrl, context);
927
+ if (migrateDependencies) visitDependency (ruleUrl, context);
928
928
_upstreamStylesheets.remove (currentUrl);
929
929
930
- var tuple = importCache.canonicalize (parsedUrl ,
930
+ var tuple = importCache.canonicalize (ruleUrl ,
931
931
baseImporter: importer, baseUrl: currentUrl);
932
932
933
933
if (tuple == null ) {
934
934
throw MigrationSourceSpanException (
935
- "Could not find Sass file at '${p .prettyUri (parsedUrl )}'." , context);
935
+ "Could not find Sass file at '${p .prettyUri (ruleUrl )}'." , context);
936
936
}
937
937
938
938
// Associate the importer for this URL with the resolved URL so that we can
@@ -1257,7 +1257,7 @@ class _ModuleMigrationVisitor extends MigrationVisitor {
1257
1257
if (! _usedUrls.contains (url)) {
1258
1258
// Add new `@use` rule for indirect dependency
1259
1259
var tuple = _absoluteUrlToDependency (url);
1260
- var defaultNamespace = namespaceForPath (tuple.item1);
1260
+ var defaultNamespace = namespaceForPath (tuple.item1.path );
1261
1261
// There are a few edge cases where the reference in [declaration] wasn't
1262
1262
// tracked by [references.sources], so we add a namespace with simple
1263
1263
// conflict resolution if one for this URL doesn't already exist.
@@ -1279,7 +1279,7 @@ class _ModuleMigrationVisitor extends MigrationVisitor {
1279
1279
/// The first item of the returned tuple is the dependency, the second item
1280
1280
/// is true when this dependency is resolved relative to the current URL and
1281
1281
/// false when it's resolved relative to a load path.
1282
- Tuple2 <String , bool > _absoluteUrlToDependency (Uri url, {Uri ? relativeTo}) {
1282
+ Tuple2 <Uri , bool > _absoluteUrlToDependency (Uri url, {Uri ? relativeTo}) {
1283
1283
relativeTo ?? = currentUrl;
1284
1284
var tuple = _originalImports[url];
1285
1285
if (tuple != null && tuple.item2 is NodeModulesImporter ) {
@@ -1305,9 +1305,10 @@ class _ModuleMigrationVisitor extends MigrationVisitor {
1305
1305
];
1306
1306
var relativePath = minBy <String , int >(potentialUrls, (url) => url.length)! ;
1307
1307
var isRelative = relativePath == potentialUrls.first;
1308
-
1309
1308
return Tuple2 (
1310
- p.url.relative (p.url.join (p.url.dirname (relativePath), basename)),
1309
+ Uri (
1310
+ path: p.url
1311
+ .relative (p.url.join (p.url.dirname (relativePath), basename))),
1311
1312
isRelative);
1312
1313
}
1313
1314
0 commit comments