Skip to content

Commit 7fb8508

Browse files
Denys Smirnovdennwc
authored andcommitted
collapse one more level of indirection for string interpolation nodes
Signed-off-by: Denys Smirnov <denys@sourced.tech>
1 parent 4b674c5 commit 7fb8508

4 files changed

Lines changed: 71 additions & 360 deletions

File tree

driver/normalizer/normalizer.go

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -507,6 +507,23 @@ var Normalizers = []Mapping{
507507
},
508508
)),
509509

510+
// Collapse one more AST level if the string token is inside InterpolatedStringText.
511+
MapSemantic("InterpolatedStringText", uast.String{}, MapObj(
512+
Obj{
513+
"TextToken": Obj{
514+
uast.KeyType: String(uast.TypeOf(uast.String{})),
515+
uast.KeyPos: Any(),
516+
"Format": String(""),
517+
"Value": Var("val"),
518+
},
519+
"IsMissing": Bool(false),
520+
"IsStructuredTrivia": Bool(false),
521+
},
522+
Obj{
523+
"Value": Var("val"),
524+
},
525+
)),
526+
510527
MapSemantic("TrueLiteralExpression", uast.Bool{}, MapObj(
511528
Obj{
512529
"Token": Obj{

fixtures/issue_18.cs.sem.uast

Lines changed: 6 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -2112,8 +2112,7 @@
21122112
},
21132113
},
21142114
Contents: [
2115-
{ '@type': "csharp:InterpolatedStringText",
2116-
'@role': [Incomplete, Literal, String],
2115+
{ '@type': "uast:String",
21172116
'@pos': { '@type': "uast:Positions",
21182117
start: { '@type': "uast:Position",
21192118
offset: 2124,
@@ -2126,24 +2125,8 @@
21262125
col: 28,
21272126
},
21282127
},
2129-
IsMissing: false,
2130-
IsStructuredTrivia: false,
2131-
TextToken: { '@type': "uast:String",
2132-
'@pos': { '@type': "uast:Positions",
2133-
start: { '@type': "uast:Position",
2134-
offset: 2124,
2135-
line: 52,
2136-
col: 25,
2137-
},
2138-
end: { '@type': "uast:Position",
2139-
offset: 2127,
2140-
line: 52,
2141-
col: 28,
2142-
},
2143-
},
2144-
Format: "",
2145-
Value: "\"[",
2146-
},
2128+
Format: "",
2129+
Value: "\"[",
21472130
},
21482131
{ '@type': "csharp:Interpolation",
21492132
'@role': [Expression, Incomplete, Value],
@@ -2221,8 +2204,7 @@
22212204
ValueText: "{",
22222205
},
22232206
},
2224-
{ '@type': "csharp:InterpolatedStringText",
2225-
'@role': [Incomplete, Literal, String],
2207+
{ '@type': "uast:String",
22262208
'@pos': { '@type': "uast:Positions",
22272209
start: { '@type': "uast:Position",
22282210
offset: 2133,
@@ -2235,24 +2217,8 @@
22352217
col: 37,
22362218
},
22372219
},
2238-
IsMissing: false,
2239-
IsStructuredTrivia: false,
2240-
TextToken: { '@type': "uast:String",
2241-
'@pos': { '@type': "uast:Positions",
2242-
start: { '@type': "uast:Position",
2243-
offset: 2133,
2244-
line: 52,
2245-
col: 34,
2246-
},
2247-
end: { '@type': "uast:Position",
2248-
offset: 2136,
2249-
line: 52,
2250-
col: 37,
2251-
},
2252-
},
2253-
Format: "",
2254-
Value: "]\"",
2255-
},
2220+
Format: "",
2221+
Value: "]\"",
22562222
},
22572223
],
22582224
IsMissing: false,

0 commit comments

Comments
 (0)