@esportsplus/typescript 0.18.1 → 0.19.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/build/transformer/ast/expression.d.ts +6 -0
- package/build/transformer/ast/expression.js +33 -0
- package/build/transformer/ast/index.d.ts +2 -0
- package/build/transformer/ast/index.js +2 -0
- package/build/transformer/ast/range.d.ts +8 -0
- package/build/transformer/ast/range.js +13 -0
- package/build/transformer/index.d.ts +2 -1
- package/build/transformer/index.js +2 -1
- package/package.json +1 -1
- package/src/transformer/ast/expression.ts +48 -0
- package/src/transformer/ast/index.ts +2 -0
- package/src/transformer/ast/range.ts +25 -0
- package/src/transformer/index.ts +2 -1
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { ts } from '../../index.js';
|
|
2
|
+
declare const getExpressionName: (node: ts.Expression) => string | null;
|
|
3
|
+
declare const getPropertyPath: (node: ts.Expression) => string[] | null;
|
|
4
|
+
declare const getPropertyPathString: (node: ts.Expression) => string | null;
|
|
5
|
+
declare const unwrapParentheses: (expr: ts.Expression) => ts.Expression;
|
|
6
|
+
export { getExpressionName, getPropertyPath, getPropertyPathString, unwrapParentheses };
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { ts } from '../../index.js';
|
|
2
|
+
const getExpressionName = (node) => {
|
|
3
|
+
if (ts.isIdentifier(node)) {
|
|
4
|
+
return node.text;
|
|
5
|
+
}
|
|
6
|
+
if (ts.isPropertyAccessExpression(node)) {
|
|
7
|
+
return getPropertyPathString(node);
|
|
8
|
+
}
|
|
9
|
+
return null;
|
|
10
|
+
};
|
|
11
|
+
const getPropertyPath = (node) => {
|
|
12
|
+
let current = node, parts = [];
|
|
13
|
+
while (ts.isPropertyAccessExpression(current)) {
|
|
14
|
+
parts.push(current.name.text);
|
|
15
|
+
current = current.expression;
|
|
16
|
+
}
|
|
17
|
+
if (ts.isIdentifier(current)) {
|
|
18
|
+
parts.push(current.text);
|
|
19
|
+
return parts.reverse();
|
|
20
|
+
}
|
|
21
|
+
return null;
|
|
22
|
+
};
|
|
23
|
+
const getPropertyPathString = (node) => {
|
|
24
|
+
let parts = getPropertyPath(node);
|
|
25
|
+
return parts ? parts.join('.') : null;
|
|
26
|
+
};
|
|
27
|
+
const unwrapParentheses = (expr) => {
|
|
28
|
+
while (ts.isParenthesizedExpression(expr)) {
|
|
29
|
+
expr = expr.expression;
|
|
30
|
+
}
|
|
31
|
+
return expr;
|
|
32
|
+
};
|
|
33
|
+
export { getExpressionName, getPropertyPath, getPropertyPathString, unwrapParentheses };
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
type Range = {
|
|
2
|
+
end: number;
|
|
3
|
+
start: number;
|
|
4
|
+
};
|
|
5
|
+
declare const containsPosition: (range: Range, pos: number) => boolean;
|
|
6
|
+
declare const inRange: (ranges: Range[], start: number, end: number) => boolean;
|
|
7
|
+
export { containsPosition, inRange };
|
|
8
|
+
export type { Range };
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
const containsPosition = (range, pos) => {
|
|
2
|
+
return pos >= range.start && pos <= range.end;
|
|
3
|
+
};
|
|
4
|
+
const inRange = (ranges, start, end) => {
|
|
5
|
+
for (let i = 0, n = ranges.length; i < n; i++) {
|
|
6
|
+
let r = ranges[i];
|
|
7
|
+
if (start >= r.start && end <= r.end) {
|
|
8
|
+
return true;
|
|
9
|
+
}
|
|
10
|
+
}
|
|
11
|
+
return false;
|
|
12
|
+
};
|
|
13
|
+
export { containsPosition, inRange };
|
|
@@ -1,6 +1,7 @@
|
|
|
1
|
+
export * as ast from './ast/index.js';
|
|
1
2
|
export { default as code } from './code.js';
|
|
2
|
-
export { default as program } from './program.js';
|
|
3
3
|
export { default as plugin } from './plugins/index.js';
|
|
4
|
+
export { default as program } from './program.js';
|
|
4
5
|
export { default as uid } from './uid.js';
|
|
5
6
|
export type * from './types.js';
|
|
6
7
|
export * from './constants.js';
|
|
@@ -1,5 +1,6 @@
|
|
|
1
|
+
export * as ast from './ast/index.js';
|
|
1
2
|
export { default as code } from './code.js';
|
|
2
|
-
export { default as program } from './program.js';
|
|
3
3
|
export { default as plugin } from './plugins/index.js';
|
|
4
|
+
export { default as program } from './program.js';
|
|
4
5
|
export { default as uid } from './uid.js';
|
|
5
6
|
export * from './constants.js';
|
package/package.json
CHANGED
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { ts } from '../..';
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
const getExpressionName = (node: ts.Expression): string | null => {
|
|
5
|
+
if (ts.isIdentifier(node)) {
|
|
6
|
+
return node.text;
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
if (ts.isPropertyAccessExpression(node)) {
|
|
10
|
+
return getPropertyPathString(node);
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
return null;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
const getPropertyPath = (node: ts.Expression): string[] | null => {
|
|
17
|
+
let current: ts.Node = node,
|
|
18
|
+
parts: string[] = [];
|
|
19
|
+
|
|
20
|
+
while (ts.isPropertyAccessExpression(current)) {
|
|
21
|
+
parts.push(current.name.text);
|
|
22
|
+
current = current.expression;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
if (ts.isIdentifier(current)) {
|
|
26
|
+
parts.push(current.text);
|
|
27
|
+
return parts.reverse();
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
return null;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
const getPropertyPathString = (node: ts.Expression): string | null => {
|
|
34
|
+
let parts = getPropertyPath(node);
|
|
35
|
+
|
|
36
|
+
return parts ? parts.join('.') : null;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
const unwrapParentheses = (expr: ts.Expression): ts.Expression => {
|
|
40
|
+
while (ts.isParenthesizedExpression(expr)) {
|
|
41
|
+
expr = expr.expression;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
return expr;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
|
|
48
|
+
export { getExpressionName, getPropertyPath, getPropertyPathString, unwrapParentheses };
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
type Range = {
|
|
2
|
+
end: number;
|
|
3
|
+
start: number;
|
|
4
|
+
};
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
const containsPosition = (range: Range, pos: number): boolean => {
|
|
8
|
+
return pos >= range.start && pos <= range.end;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
const inRange = (ranges: Range[], start: number, end: number): boolean => {
|
|
12
|
+
for (let i = 0, n = ranges.length; i < n; i++) {
|
|
13
|
+
let r = ranges[i];
|
|
14
|
+
|
|
15
|
+
if (start >= r.start && end <= r.end) {
|
|
16
|
+
return true;
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
return false;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
export { containsPosition, inRange };
|
|
25
|
+
export type { Range };
|
package/src/transformer/index.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
|
+
export * as ast from './ast';
|
|
1
2
|
export { default as code } from './code';
|
|
2
|
-
export { default as program } from './program';
|
|
3
3
|
export { default as plugin } from './plugins';
|
|
4
|
+
export { default as program } from './program';
|
|
4
5
|
export { default as uid } from './uid';
|
|
5
6
|
export type * from './types';
|
|
6
7
|
export * from './constants';
|