Skip to content

Commit 5beaa7b

Browse files
authored
Simplify with ParenthesizedExpression (#353)
1 parent 832070a commit 5beaa7b

File tree

10 files changed

+320
-560
lines changed

10 files changed

+320
-560
lines changed

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
coverage/
2-
dist/
2+
dist*/
33
node_modules/
44
*.log
55
.yarn/*

src/__snapshots__/utils.test.ts.snap

Lines changed: 0 additions & 85 deletions
This file was deleted.

src/source.ts

Lines changed: 4 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ import type * as babel from '@babel/types';
22

33
import type { LocationInformation, NGNode, RawNGSpan } from './types.ts';
44
import {
5-
fitSpans,
65
getCharacterIndex,
76
getCharacterLastIndex,
87
sourceSpanToLocationInformation,
@@ -23,49 +22,19 @@ export class Source {
2322
return getCharacterLastIndex(this.text, pattern, index);
2423
}
2524

26-
transformSpan(
27-
span: RawNGSpan,
28-
{ stripSpaces = false, hasParentParens = false } = {},
29-
): LocationInformation {
30-
if (!stripSpaces) {
31-
return sourceSpanToLocationInformation(span);
32-
}
33-
34-
const { outerSpan, innerSpan, hasParens } = fitSpans(
35-
span,
36-
this.text,
37-
hasParentParens,
38-
);
39-
const locationInformation = sourceSpanToLocationInformation(innerSpan);
40-
if (hasParens) {
41-
locationInformation.extra = {
42-
parenthesized: true,
43-
parenStart: outerSpan.start,
44-
parenEnd: outerSpan.end,
45-
};
46-
}
47-
48-
return locationInformation;
25+
transformSpan(span: RawNGSpan): LocationInformation {
26+
return sourceSpanToLocationInformation(span);
4927
}
5028

5129
createNode<T extends NGNode>(
5230
properties: Partial<T> & { type: T['type'] } & RawNGSpan,
53-
// istanbul ignore next
54-
{ stripSpaces = true, hasParentParens = false } = {},
5531
) {
56-
const { type, start, end } = properties;
5732
const node = {
5833
...properties,
59-
...this.transformSpan(
60-
{ start, end },
61-
{
62-
stripSpaces,
63-
hasParentParens,
64-
},
65-
),
34+
range: [properties.start, properties.end],
6635
} as T & LocationInformation;
6736

68-
switch (type) {
37+
switch (node.type) {
6938
case 'NumericLiteral':
7039
case 'StringLiteral':
7140
case 'RegExpLiteral': {

0 commit comments

Comments
 (0)