@@ -2,6 +2,7 @@ package normalizer
22
33import (
44 "github.com/bblfsh/sdk/v3/uast"
5+ "github.com/bblfsh/sdk/v3/uast/nodes"
56 "github.com/bblfsh/sdk/v3/uast/role"
67 . "github.com/bblfsh/sdk/v3/uast/transformer"
78 "github.com/bblfsh/sdk/v3/uast/transformer/positioner"
@@ -364,50 +365,47 @@ var Normalizers = []Mapping{
364365 },
365366 Obj {
366367 "names" : Each ("vals" , UASTType (uast.RuntimeImport {},
367- Obj {
368- "Path" : Var ("name" ),
369- })),
368+ Obj {"Path" : Var ("name" )},
369+ )),
370370 },
371371 ), role .Import , role .Declaration , role .Statement ),
372372
373+ // pre-process aliases: remove ones with no alias (useless)
374+ Map (Obj {
375+ uast .KeyType : String ("alias" ),
376+ uast .KeyPos : Any (),
377+ "name" : Check (OfKind (nodes .KindString ), Var ("name" )),
378+ "asname" : Is (nil ),
379+ }, UASTType (uast.Identifier {}, Obj {
380+ uast .KeyPos : UASTType (uast.Positions {}, nil ),
381+ "Name" : Var ("name" ),
382+ })),
383+
373384 // FIXME: aliases doesn't have a position (can't be currently fixed by the tokenizer
374- // because they don't even have a line in the native AST)
385+ // because they don't even have a line in the native AST)
375386 MapSemantic ("alias" , uast.Alias {}, MapObj (
376387 Obj {
377- "name" : Var ("name" ),
378- "asname" : Cases ("case_alias" ,
379- Check (Is (nil ), Var ("nilalias" )),
380- Check (Not (Is (nil )), Var ("alias" )),
388+ "name" : Var ("name" ),
389+ "asname" : Var ("alias" ),
390+ },
391+ Obj {
392+ "Name" : UASTType (uast.Identifier {}, Obj {
393+ "Name" : Var ("name" ),
394+ }),
395+ "Node" : UASTType (uast.Identifier {},
396+ Obj {"Name" : Var ("alias" )},
381397 ),
382398 },
383- CasesObj ("case_alias" ,
384- Obj {
385- "Name" : UASTType (uast.Identifier {}, Obj {
386- "Name" : Var ("name" ),
387- }),
388- },
389- Objs {
390- {"Node" : Obj {}},
391- {
392- "Node" : UASTType (uast.Identifier {},
393- Obj {
394- "Name" : Var ("alias" ),
395- }),
396- }},
397- ))),
399+ )),
398400
399401 // Star imports
400402 MapSemantic ("ImportFrom" , uast.RuntimeImport {}, MapObj (
401403 Fields {
402404 {Name : "names" , Op : Arr (
403405 Obj {
404- uast .KeyType : String ("uast:Alias" ),
405- uast .KeyPos : Var ("pos" ),
406- "Name" : Obj {
407- uast .KeyType : String ("uast:Identifier" ),
408- "Name" : String ("*" ),
409- },
410- "Node" : Obj {},
406+ uast .KeyType : String ("uast:Identifier" ),
407+ uast .KeyPos : Any (),
408+ "Name" : String ("*" ),
411409 },
412410 )},
413411 {Name : "level" , Op : Var ("level" )},
0 commit comments