Skip to content

Commit 8b564a1

Browse files
committed
Kill getOuterEnd
1 parent df17302 commit 8b564a1

File tree

2 files changed

+8
-12
lines changed

2 files changed

+8
-12
lines changed

src/transform-node.ts

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,6 @@ function isParenthesized(node: NGNode) {
1717
function getOuterStart(node: NGNode): number {
1818
return isParenthesized(node) ? node.extra.parenStart : node.start!;
1919
}
20-
function getOuterEnd(node: NGNode): number {
21-
return isParenthesized(node) ? node.extra.parenEnd : node.end!;
22-
}
2320

2421
function isOptionalObjectOrCallee(node: NGNode): boolean {
2522
if (node.type === 'TSNonNullExpression' && !isParenthesized(node)) {
@@ -275,20 +272,15 @@ class Transformer extends Source {
275272

276273
if (node instanceof angular.LiteralMap) {
277274
const { keys, values } = node;
278-
const tValues = values.map((value) =>
279-
this.transform<babel.Expression>(value, childTransformOptions),
280-
);
281275
const tProperties = keys.map((property, index) => {
282276
const { key, quoted } = property;
283-
const tValue = tValues[index];
284-
const valueStart = getOuterStart(tValue);
285-
const valueEnd = getOuterEnd(tValue);
277+
const { start: valueStart, end: valueEnd } = values[index].sourceSpan;
286278

287279
const keyStart = this.getCharacterIndex(
288280
/\S/,
289281
index === 0
290282
? node.sourceSpan.start + 1 // {
291-
: this.getCharacterIndex(',', getOuterEnd(tValues[index - 1])) + 1,
283+
: this.getCharacterIndex(',', values[index - 1].sourceSpan.end) + 1,
292284
);
293285
const keyEnd =
294286
valueStart === keyStart
@@ -316,12 +308,16 @@ class Transformer extends Source {
316308
[],
317309
);
318310
const shorthand = tKey.end < tKey.start || keyStart === valueStart;
311+
const value = this.transform<babel.Expression>(
312+
values[index],
313+
childTransformOptions,
314+
);
319315

320316
return this.#create<babel.ObjectProperty>(
321317
{
322318
type: 'ObjectProperty',
323319
key: tKey,
324-
value: tValue,
320+
value,
325321
shorthand,
326322
computed: false,
327323
start: getOuterStart(tKey),

tests/transform.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ describe.each`
5858
${'SafeKeyedRead'} | ${'OptionalMemberExpression'} | ${' a ?. b () ?. [ c ] '} | ${true} | ${true} | ${true} | ${true}
5959
${'ImplicitReceiver'} | ${'ThisExpression'} | ${' this '} | ${true} | ${true} | ${true} | ${true}
6060
${'LiteralArray'} | ${'ArrayExpression'} | ${' [ 1 ] '} | ${true} | ${true} | ${true} | ${true}
61-
${'LiteralMap'} | ${'ObjectExpression'} | ${' ( { "a" : 1 } )'} | ${true} | ${true} | ${true} | ${true}
61+
${'LiteralMap'} | ${'ObjectExpression'} | ${' ( ( { "a" : ( ( 1 ) ) } ) )'} | ${true} | ${true} | ${true} | ${true}
6262
${'LiteralMap'} | ${'ObjectExpression'} | ${' ( { a : 1 } ) '} | ${true} | ${true} | ${true} | ${true}
6363
${'Call'} | ${'CallExpression'} | ${' f ( { a : 1 } ) '} | ${true} | ${true} | ${true} | ${true}
6464
${'LiteralMap'} | ${'ObjectExpression'} | ${' ( {a, b: 2} ) '} | ${true} | ${true} | ${true} | ${true}

0 commit comments

Comments
 (0)