Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
coverage/
dist/
dist*/
node_modules/
*.log
.yarn/*
Expand Down
85 changes: 0 additions & 85 deletions src/__snapshots__/utils.test.ts.snap

This file was deleted.

39 changes: 4 additions & 35 deletions src/source.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import type * as babel from '@babel/types';

import type { LocationInformation, NGNode, RawNGSpan } from './types.ts';
import {
fitSpans,
getCharacterIndex,
getCharacterLastIndex,
sourceSpanToLocationInformation,
Expand All @@ -23,49 +22,19 @@ export class Source {
return getCharacterLastIndex(this.text, pattern, index);
}

transformSpan(
span: RawNGSpan,
{ stripSpaces = false, hasParentParens = false } = {},
): LocationInformation {
if (!stripSpaces) {
return sourceSpanToLocationInformation(span);
}

const { outerSpan, innerSpan, hasParens } = fitSpans(
span,
this.text,
hasParentParens,
);
const locationInformation = sourceSpanToLocationInformation(innerSpan);
if (hasParens) {
locationInformation.extra = {
parenthesized: true,
parenStart: outerSpan.start,
parenEnd: outerSpan.end,
};
}

return locationInformation;
transformSpan(span: RawNGSpan): LocationInformation {
return sourceSpanToLocationInformation(span);
}

createNode<T extends NGNode>(
properties: Partial<T> & { type: T['type'] } & RawNGSpan,
// istanbul ignore next
{ stripSpaces = true, hasParentParens = false } = {},
) {
const { type, start, end } = properties;
const node = {
...properties,
...this.transformSpan(
{ start, end },
{
stripSpaces,
hasParentParens,
},
),
range: [properties.start, properties.end],
} as T & LocationInformation;

switch (type) {
switch (node.type) {
case 'NumericLiteral':
case 'StringLiteral':
case 'RegExpLiteral': {
Expand Down
Loading