Skip to content

Commit 2b006ae

Browse files
committed
Simplify transform
1 parent 5beaa7b commit 2b006ae

File tree

5 files changed

+260
-311
lines changed

5 files changed

+260
-311
lines changed

prettier.config.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,9 @@
1+
/**
2+
* @see https://prettier.io/docs/configuration
3+
* @type {import("prettier").Config}
4+
*/
15
export default {
26
singleQuote: true,
37
trailingComma: 'all',
8+
objectWrap: 'collapse',
49
};

src/source.ts

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import * as angular from '@angular/compiler';
12
import type * as babel from '@babel/types';
23

34
import type { LocationInformation, NGNode, RawNGSpan } from './types.ts';
@@ -27,11 +28,26 @@ export class Source {
2728
}
2829

2930
createNode<T extends NGNode>(
30-
properties: Partial<T> & { type: T['type'] } & RawNGSpan,
31+
properties: Partial<T> & { type: T['type'] },
32+
location: angular.AST | RawNGSpan | [number, number],
3133
) {
34+
let start: number;
35+
let end: number;
36+
let range: [number, number];
37+
if (Array.isArray(location)) {
38+
range = location;
39+
[start, end] = location;
40+
} else {
41+
({ start, end } =
42+
location instanceof angular.AST ? location.sourceSpan : location);
43+
range = [start, end];
44+
}
45+
3246
const node = {
47+
start,
48+
end,
49+
range,
3350
...properties,
34-
range: [properties.start, properties.end],
3551
} as T & LocationInformation;
3652

3753
switch (node.type) {

0 commit comments

Comments
 (0)