Skip to content

Commit f63e57c

Browse files
committed
Remove paren{Start,End}
1 parent 3ddd98f commit f63e57c

File tree

3 files changed

+13
-48
lines changed

3 files changed

+13
-48
lines changed

src/transform-node.ts

Lines changed: 2 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -32,33 +32,6 @@ function isImplicitThis(node: angular.AST, text: string): boolean {
3232
return start >= end || /^\s+$/.test(text.slice(start, end));
3333
}
3434

35-
function getParenthesizedInformation(ancestors: angular.AST[]) {
36-
const parenthesizedExpression =
37-
getOutermostParenthesizedExpression(ancestors);
38-
39-
if (!parenthesizedExpression) {
40-
return;
41-
}
42-
43-
return {
44-
parenthesized: true,
45-
parenStart: parenthesizedExpression.sourceSpan.start,
46-
parenEnd: parenthesizedExpression.sourceSpan.end,
47-
};
48-
}
49-
50-
function getOutermostParenthesizedExpression(ancestors: angular.AST[]) {
51-
for (const [index, node] of ancestors.entries()) {
52-
if (!(node instanceof angular.ParenthesizedExpression)) {
53-
return;
54-
}
55-
56-
if (!(ancestors[index + 1] instanceof angular.ParenthesizedExpression)) {
57-
return node;
58-
}
59-
}
60-
}
61-
6235
type NodeTransformOptions = {
6336
ancestors: angular.AST[];
6437
};
@@ -85,11 +58,10 @@ class Transformer extends Source {
8558
) {
8659
const node = this.createNode(properties);
8760

88-
const parenthesizedInformation = getParenthesizedInformation(ancestors);
89-
if (parenthesizedInformation) {
61+
if (ancestors[0] instanceof angular.ParenthesizedExpression) {
9062
node.extra = {
9163
...node.extra,
92-
...parenthesizedInformation,
64+
parenthesized: true,
9365
};
9466
}
9567

tests/__snapshots__/transform.test.ts.snap

Lines changed: 6 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,7 @@ NGPipeExpression {
66
"right": "Identifier",
77
"arguments": [],
88
"extra": {
9-
"parenthesized": true,
10-
"parenStart": 1,
11-
"parenEnd": 23
9+
"parenthesized": true
1210
},
1311
"comments": []
1412
}
@@ -18,9 +16,7 @@ NGPipeExpression {
1816
Identifier {
1917
"name": "a",
2018
"extra": {
21-
"parenthesized": true,
22-
"parenStart": 5,
23-
"parenEnd": 14
19+
"parenthesized": true
2420
}
2521
}
2622
> 1 | ( ( ( ( a ) ) | b ))
@@ -29,9 +25,7 @@ Identifier {
2925
Identifier {
3026
"name": "b",
3127
"extra": {
32-
"parenthesized": true,
33-
"parenStart": 1,
34-
"parenEnd": 23
28+
"parenthesized": true
3529
}
3630
}
3731
> 1 | ( ( ( ( a ) ) | b ))
@@ -75,9 +69,7 @@ NGPipeExpression {
7569
"right": "Identifier",
7670
"arguments": [],
7771
"extra": {
78-
"parenthesized": true,
79-
"parenStart": 1,
80-
"parenEnd": 23
72+
"parenthesized": true
8173
},
8274
"comments": []
8375
}
@@ -87,9 +79,7 @@ NGPipeExpression {
8779
Identifier {
8880
"name": "a",
8981
"extra": {
90-
"parenthesized": true,
91-
"parenStart": 5,
92-
"parenEnd": 14
82+
"parenthesized": true
9383
}
9484
}
9585
> 1 | ( ( ( ( a ) ) | b ))
@@ -98,9 +88,7 @@ Identifier {
9888
Identifier {
9989
"name": "b",
10090
"extra": {
101-
"parenthesized": true,
102-
"parenStart": 1,
103-
"parenEnd": 23
91+
"parenthesized": true
10492
}
10593
}
10694
> 1 | ( ( ( ( a ) ) | b ))

tests/helpers.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,10 @@ export function massageAst(ast: any, parser: 'babel' | 'angular'): any {
4646
return ast.map((node) => massageAst(node, parser));
4747
}
4848

49+
if (parser === 'babel' && typeof ast.extra?.parenStart === 'number') {
50+
delete ast.extra.parenStart;
51+
}
52+
4953
// Not exists in types, but exists in node.
5054
if (ast.type === 'ObjectProperty') {
5155
if (ast.method !== undefined && ast.method !== false) {
@@ -54,6 +58,7 @@ export function massageAst(ast: any, parser: 'babel' | 'angular'): any {
5458
);
5559
}
5660
delete ast.method;
61+
5762
if (
5863
ast.shorthand &&
5964
ast.extra &&

0 commit comments

Comments
 (0)