Skip to content

Commit de68c09

Browse files
authored
Simplify transform (#354)
1 parent 5beaa7b commit de68c09

File tree

6 files changed

+259
-359
lines changed

6 files changed

+259
-359
lines changed

eslint.config.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import globals from 'globals';
66
import tseslint from 'typescript-eslint';
77

88
export default tseslint.config(
9-
{ ignores: ['coverage/', 'lib/', '**/.yarn/**', '**/.pnp.*'] },
9+
{ ignores: ['coverage/', 'lib/', '**/.yarn/**', '**/.pnp.*', 'dist*/'] },
1010
eslintPluginJs.configs.recommended,
1111
...tseslint.configs.recommended,
1212
eslintConfigPrettier,

prettier.config.js

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

src/angular-parser.ts

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,10 +38,7 @@ function extractComments(text: string, shouldExtractComment: boolean) {
3838
}),
3939
};
4040

41-
return {
42-
text: text.slice(0, commentStart),
43-
comments: [comment],
44-
};
41+
return { text: text.slice(0, commentStart), comments: [comment] };
4542
}
4643

4744
function createAngularParseFunction<

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)