Skip to content

Commit 4abc387

Browse files
committed
adjust decorator source map locations
1 parent e7a9256 commit 4abc387

File tree

1 file changed

+17
-13
lines changed

1 file changed

+17
-13
lines changed

internal/js_parser/js_parser_lower_class.go

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1232,9 +1232,10 @@ func (ctx *lowerClassContext) hoistComputedProperties(p *parser, classLoweringIn
12321232
for i, decorator := range analysis.propDecorators {
12331233
values[i] = decorator.Value
12341234
}
1235+
atLoc := analysis.propDecorators[0].AtLoc
12351236
decorators = js_ast.Assign(
1236-
js_ast.Expr{Loc: prop.Loc, Data: &js_ast.EIdentifier{Ref: ref}},
1237-
js_ast.Expr{Loc: prop.Loc, Data: &js_ast.EArray{Items: values, IsSingleLine: true}})
1237+
js_ast.Expr{Loc: atLoc, Data: &js_ast.EIdentifier{Ref: ref}},
1238+
js_ast.Expr{Loc: atLoc, Data: &js_ast.EArray{Items: values, IsSingleLine: true}})
12381239
p.recordUsage(ref)
12391240
if decoratorTempRefs == nil {
12401241
decoratorTempRefs = make(map[int]ast.Ref)
@@ -1483,12 +1484,13 @@ func (ctx *lowerClassContext) processProperties(p *parser, classLoweringInfo cla
14831484
for i, decorator := range ctx.class.Decorators {
14841485
values[i] = decorator.Value
14851486
}
1487+
atLoc := ctx.class.Decorators[0].AtLoc
14861488
ctx.computedPropertyChain = js_ast.JoinWithComma(js_ast.Assign(
1487-
js_ast.Expr{Loc: ctx.classLoc, Data: &js_ast.EIdentifier{Ref: decoratorsRef}},
1488-
js_ast.Expr{Loc: ctx.classLoc, Data: &js_ast.EArray{Items: values, IsSingleLine: true}},
1489+
js_ast.Expr{Loc: atLoc, Data: &js_ast.EIdentifier{Ref: decoratorsRef}},
1490+
js_ast.Expr{Loc: atLoc, Data: &js_ast.EArray{Items: values, IsSingleLine: true}},
14891491
), ctx.computedPropertyChain)
14901492
p.recordUsage(decoratorsRef)
1491-
ctx.decoratorClassDecorators = js_ast.Expr{Loc: ctx.classLoc, Data: &js_ast.EIdentifier{Ref: decoratorsRef}}
1493+
ctx.decoratorClassDecorators = js_ast.Expr{Loc: atLoc, Data: &js_ast.EIdentifier{Ref: decoratorsRef}}
14921494
p.recordUsage(decoratorsRef)
14931495
ctx.class.Decorators = nil
14941496
}
@@ -1594,7 +1596,9 @@ func (ctx *lowerClassContext) processProperties(p *parser, classLoweringInfo cla
15941596
initializerIndex := -1
15951597
if len(analysis.propDecorators) > 0 {
15961598
prop.Decorators = nil
1597-
loc := prop.Key.Loc
1599+
loc := prop.Loc
1600+
keyLoc := prop.Key.Loc
1601+
atLoc := analysis.propDecorators[0].AtLoc
15981602

15991603
// Encode information about this property using bit flags
16001604
var flags int
@@ -1635,7 +1639,7 @@ func (ctx *lowerClassContext) processProperties(p *parser, classLoweringInfo cla
16351639
{Loc: loc, Data: &js_ast.EIdentifier{Ref: ctx.decoratorContextRef}},
16361640
{Loc: loc, Data: &js_ast.ENumber{Value: float64(flags)}},
16371641
key,
1638-
{Loc: loc, Data: &js_ast.EIdentifier{Ref: decoratorsRef}},
1642+
{Loc: atLoc, Data: &js_ast.EIdentifier{Ref: decoratorsRef}},
16391643
}
16401644
p.recordUsage(ctx.decoratorContextRef)
16411645
p.recordUsage(decoratorsRef)
@@ -1644,7 +1648,7 @@ func (ctx *lowerClassContext) processProperties(p *parser, classLoweringInfo cla
16441648
privateFnRef := ast.InvalidRef
16451649
if analysis.private != nil {
16461650
// Add the "target" argument (the weak set)
1647-
args = append(args, js_ast.Expr{Loc: loc, Data: &js_ast.EIdentifier{Ref: analysis.private.Ref}})
1651+
args = append(args, js_ast.Expr{Loc: keyLoc, Data: &js_ast.EIdentifier{Ref: analysis.private.Ref}})
16481652
p.recordUsage(analysis.private.Ref)
16491653

16501654
// Add the "extra" argument (the function)
@@ -1657,7 +1661,7 @@ func (ctx *lowerClassContext) processProperties(p *parser, classLoweringInfo cla
16571661
privateFnRef = p.privateSetters[analysis.private.Ref]
16581662
}
16591663
if privateFnRef != ast.InvalidRef {
1660-
args = append(args, js_ast.Expr{Loc: loc, Data: &js_ast.EIdentifier{Ref: privateFnRef}})
1664+
args = append(args, js_ast.Expr{Loc: keyLoc, Data: &js_ast.EIdentifier{Ref: privateFnRef}})
16611665
p.recordUsage(privateFnRef)
16621666
}
16631667
} else {
@@ -1675,14 +1679,14 @@ func (ctx *lowerClassContext) processProperties(p *parser, classLoweringInfo cla
16751679

16761680
// Pass the WeakMap instance into the decorator helper
16771681
autoAccessorWeakMapRef = p.generateTempRef(tempRefNeedsDeclare, p.propertyNameHint(prop.Key, ""))
1678-
args = append(args, js_ast.Expr{Loc: loc, Data: &js_ast.EIdentifier{Ref: autoAccessorWeakMapRef}})
1682+
args = append(args, js_ast.Expr{Loc: keyLoc, Data: &js_ast.EIdentifier{Ref: autoAccessorWeakMapRef}})
16791683
p.recordUsage(autoAccessorWeakMapRef)
16801684
}
16811685

16821686
// Assign the result
16831687
element := p.callRuntime(loc, "__decorateElement", args)
16841688
if privateFnRef != ast.InvalidRef {
1685-
element = js_ast.Assign(js_ast.Expr{Loc: loc, Data: &js_ast.EIdentifier{Ref: privateFnRef}}, element)
1689+
element = js_ast.Assign(js_ast.Expr{Loc: keyLoc, Data: &js_ast.EIdentifier{Ref: privateFnRef}}, element)
16861690
p.recordUsage(privateFnRef)
16871691
} else if prop.Kind == js_ast.PropertyAutoAccessor && analysis.private != nil {
16881692
ref := p.generateTempRef(tempRefNeedsDeclare, "")
@@ -1697,10 +1701,10 @@ func (ctx *lowerClassContext) processProperties(p *parser, classLoweringInfo cla
16971701
js_ast.Expr{Loc: loc, Data: &js_ast.EIdentifier{Ref: ref}},
16981702
element),
16991703
js_ast.Assign(
1700-
js_ast.Expr{Loc: loc, Data: &js_ast.EIdentifier{Ref: privateGetFnRef}},
1704+
js_ast.Expr{Loc: keyLoc, Data: &js_ast.EIdentifier{Ref: privateGetFnRef}},
17011705
js_ast.Expr{Loc: loc, Data: &js_ast.EDot{Target: js_ast.Expr{Loc: loc, Data: &js_ast.EIdentifier{Ref: ref}}, Name: "get", NameLoc: loc}})),
17021706
js_ast.Assign(
1703-
js_ast.Expr{Loc: loc, Data: &js_ast.EIdentifier{Ref: privateSetFnRef}},
1707+
js_ast.Expr{Loc: keyLoc, Data: &js_ast.EIdentifier{Ref: privateSetFnRef}},
17041708
js_ast.Expr{Loc: loc, Data: &js_ast.EDot{Target: js_ast.Expr{Loc: loc, Data: &js_ast.EIdentifier{Ref: ref}}, Name: "set", NameLoc: loc}}))
17051709
p.recordUsage(ref)
17061710
p.recordUsage(privateGetFnRef)

0 commit comments

Comments
 (0)