@@ -864,66 +864,34 @@ public void visit(NodeTraversal t, Node n, Node parent) {
864
864
private void fixTypeNode (NodeTraversal t , Node typeNode ) {
865
865
if (typeNode .isString ()) {
866
866
String name = typeNode .getString ();
867
- if (ModuleLoader .isPathIdentifier (name )) {
868
- int lastSlash = name .lastIndexOf ('/' );
869
- int endIndex = name .indexOf ('.' , lastSlash );
870
- String localTypeName = null ;
871
- if (endIndex == -1 ) {
872
- endIndex = name .length ();
867
+ List <String > splitted = Splitter .on ('.' ).limit (2 ).splitToList (name );
868
+ String baseName = splitted .get (0 );
869
+ String rest = "" ;
870
+ if (splitted .size () == 2 ) {
871
+ rest = "." + splitted .get (1 );
872
+ }
873
+ Var var = t .getScope ().getVar (baseName );
874
+ if (var != null && var .isGlobal ()) {
875
+ maybeSetNewName (t , typeNode , name , baseName + "$$" + suffix + rest );
876
+ } else if (var == null && importMap .containsKey (baseName )) {
877
+ ModuleOriginalNamePair pair = importMap .get (baseName );
878
+ if (pair .originalName .isEmpty ()) {
879
+ maybeSetNewName (t , typeNode , name , pair .module + rest );
873
880
} else {
874
- localTypeName = name .substring (endIndex );
875
- }
876
-
877
- String moduleName = name .substring (0 , endIndex );
878
- ModuleLoader .ModulePath path =
879
- t .getInput ()
880
- .getPath ()
881
- .resolveJsModule (
882
- moduleName ,
883
- typeNode .getSourceFileName (),
884
- typeNode .getLineno (),
885
- typeNode .getCharno ());
886
-
887
- if (path == null ) {
888
- path = t .getInput ().getPath ().resolveModuleAsPath (moduleName );
889
- }
890
- String globalModuleName = path .toModuleName ();
891
-
892
- maybeSetNewName (
893
- t ,
894
- typeNode ,
895
- name ,
896
- localTypeName == null ? globalModuleName : globalModuleName + localTypeName );
897
- } else {
898
- List <String > splitted = Splitter .on ('.' ).limit (2 ).splitToList (name );
899
- String baseName = splitted .get (0 );
900
- String rest = "" ;
901
- if (splitted .size () == 2 ) {
902
- rest = "." + splitted .get (1 );
881
+ maybeSetNewName (t , typeNode , name , baseName + "$$" + pair .module + rest );
903
882
}
904
- Var var = t .getScope ().getVar (baseName );
905
- if (var != null && var .isGlobal ()) {
906
- maybeSetNewName (t , typeNode , name , baseName + "$$" + suffix + rest );
907
- } else if (var == null && importMap .containsKey (baseName )) {
908
- ModuleOriginalNamePair pair = importMap .get (baseName );
909
- if (pair .originalName .isEmpty ()) {
910
- maybeSetNewName (t , typeNode , name , pair .module + rest );
911
- } else {
912
- maybeSetNewName (t , typeNode , name , baseName + "$$" + pair .module + rest );
913
- }
914
883
915
- if (preprocessorSymbolTable != null ) {
916
- // Jsdoc type node is a single STRING node that spans the whole type. For example
917
- // STRING node "bar.Foo". ES6 import rewrite replaces only "module"
918
- // part of the type: "bar.Foo" => "module$full$path$bar$Foo". We have to record
919
- // "bar" as alias.
920
- Node onlyBaseName = Node .newString (baseName ).useSourceInfoFrom (typeNode );
921
- onlyBaseName .setLength (baseName .length ());
922
- maybeAddAliasToSymbolTable (onlyBaseName , t .getSourceName ());
923
- }
884
+ if (preprocessorSymbolTable != null ) {
885
+ // Jsdoc type node is a single STRING node that spans the whole type. For example
886
+ // STRING node "bar.Foo". ES6 import rewrite replaces only "module"
887
+ // part of the type: "bar.Foo" => "module$full$path$bar$Foo". We have to record
888
+ // "bar" as alias.
889
+ Node onlyBaseName = Node .newString (baseName ).useSourceInfoFrom (typeNode );
890
+ onlyBaseName .setLength (baseName .length ());
891
+ maybeAddAliasToSymbolTable (onlyBaseName , t .getSourceName ());
924
892
}
925
- typeNode .setOriginalName (name );
926
893
}
894
+ typeNode .setOriginalName (name );
927
895
}
928
896
929
897
for (Node child = typeNode .getFirstChild (); child != null ; child = child .getNext ()) {
0 commit comments