Skip to content

Commit 01cbbe1

Browse files
committed
Remove dead code
1 parent 3e0e968 commit 01cbbe1

File tree

5 files changed

+4
-210
lines changed

5 files changed

+4
-210
lines changed

src/__snapshots__/utils.test.ts.snap

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

src/source.ts

Lines changed: 2 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -23,29 +23,8 @@ export class Source {
2323
return getCharacterLastIndex(this.text, pattern, index);
2424
}
2525

26-
transformSpan(
27-
span: RawNGSpan,
28-
{ stripSpaces = false, isInParentParens = false } = {},
29-
): LocationInformation {
30-
if (!stripSpaces) {
31-
return sourceSpanToLocationInformation(span);
32-
}
33-
34-
const { outerSpan, innerSpan, hasParens } = fitSpans(
35-
span,
36-
this.text,
37-
isInParentParens,
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;
26+
transformSpan(span: RawNGSpan): LocationInformation {
27+
return sourceSpanToLocationInformation(span);
4928
}
5029

5130
createNode<T extends NGNode>(

src/transform-template-binding.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,7 @@ class TemplateBindingTransformer extends NodeTransformer {
174174
const expression = updateExpressionAlias(lastNode.expression);
175175
body.push(updateSpanEnd({ ...lastNode, expression }, expression.end));
176176
} else {
177-
/* c8 ignore next 2 */
177+
/* c8 ignore next 2 @preserve */
178178
throw new Error(`Unexpected type ${lastNode.type}`);
179179
}
180180
} else {

src/utils.test.ts

Lines changed: 1 addition & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,39 +1,4 @@
1-
import { codeFrameColumns } from '@babel/code-frame';
2-
import { wrap } from 'jest-snapshot-serializer-raw';
3-
4-
import type { RawNGSpan } from './types.ts';
5-
import { fitSpans, getCharacterIndex, getCharacterLastIndex } from './utils.ts';
6-
7-
const text = ` ( ( ( 1 ) ) ) `;
8-
const length = Math.floor(text.length / 2);
9-
10-
describe('fitSpans', () => {
11-
for (let i = 0; i < length; i++) {
12-
const start = i;
13-
const end = text.length - i;
14-
test(`start: ${start}, end: ${end}`, () => {
15-
const { innerSpan, outerSpan, hasParens } = fitSpans(
16-
{ start, end },
17-
text,
18-
false,
19-
);
20-
const show = ({ start: startColumn, end: endColumn }: RawNGSpan) =>
21-
codeFrameColumns(text, {
22-
start: { line: 1, column: startColumn + 1 },
23-
end: { line: 1, column: endColumn + 1 },
24-
});
25-
const snapshot = [
26-
'origin',
27-
show({ start, end }),
28-
'inner',
29-
show(innerSpan),
30-
`outer hasParens=${hasParens}`,
31-
show(outerSpan),
32-
].join('\n');
33-
expect(wrap(snapshot)).toMatchSnapshot();
34-
});
35-
}
36-
});
1+
import { getCharacterIndex, getCharacterLastIndex } from './utils.ts';
372

383
test('getCharacterIndex', () => {
394
expect(getCharacterIndex('foobar', /o/, 0)).toBe(1);

src/utils.ts

Lines changed: 0 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,5 @@
11
import type { LocationInformation, RawNGSpan } from './types.ts';
22

3-
function stripSurroundingSpaces(
4-
{ start: startIndex, end: endIndex }: RawNGSpan,
5-
text: string,
6-
) {
7-
let start = startIndex;
8-
let end = endIndex;
9-
10-
while (end !== start && /\s/.test(text[end - 1])) {
11-
end--;
12-
}
13-
14-
while (start !== end && /\s/.test(text[start])) {
15-
start++;
16-
}
17-
18-
return { start, end };
19-
}
20-
213
function expandSurroundingSpaces(
224
{ start: startIndex, end: endIndex }: RawNGSpan,
235
text: string,
@@ -36,53 +18,6 @@ function expandSurroundingSpaces(
3618
return { start, end };
3719
}
3820

39-
function expandSurroundingParens(span: RawNGSpan, text: string) {
40-
return text[span.start - 1] === '(' && text[span.end] === ')'
41-
? { start: span.start - 1, end: span.end + 1 }
42-
: span;
43-
}
44-
45-
export function fitSpans(
46-
span: RawNGSpan,
47-
text: string,
48-
hasParentParens: boolean,
49-
): { outerSpan: RawNGSpan; innerSpan: RawNGSpan; hasParens: boolean } {
50-
let parensCount = 0;
51-
52-
const outerSpan = { start: span.start, end: span.end };
53-
54-
while (true) {
55-
const spacesExpandedSpan = expandSurroundingSpaces(outerSpan, text);
56-
const parensExpandedSpan = expandSurroundingParens(
57-
spacesExpandedSpan,
58-
text,
59-
);
60-
61-
if (
62-
spacesExpandedSpan.start === parensExpandedSpan.start &&
63-
spacesExpandedSpan.end === parensExpandedSpan.end
64-
) {
65-
break;
66-
}
67-
68-
outerSpan.start = parensExpandedSpan.start;
69-
outerSpan.end = parensExpandedSpan.end;
70-
71-
parensCount++;
72-
}
73-
74-
return {
75-
hasParens: (hasParentParens ? parensCount - 1 : parensCount) !== 0,
76-
outerSpan: stripSurroundingSpaces(
77-
hasParentParens
78-
? { start: outerSpan.start + 1, end: outerSpan.end - 1 }
79-
: outerSpan,
80-
text,
81-
),
82-
innerSpan: stripSurroundingSpaces(span, text),
83-
};
84-
}
85-
8621
function getCharacterSearchTestFunction(pattern: RegExp | string) {
8722
if (typeof pattern === 'string') {
8823
return (character: string) => character === pattern;

0 commit comments

Comments
 (0)