@esportsplus/reactivity 0.25.8 → 0.25.9
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/index.d.ts +1 -1
- package/build/transformer/index.js +36 -2
- package/build/transformer/plugins/vite.js +2 -2
- package/package.json +1 -1
- package/src/transformer/index.ts +51 -2
- package/src/transformer/plugins/vite.ts +2 -2
- package/build/transformer/detector.d.ts +0 -2
- package/build/transformer/detector.js +0 -38
- package/src/transformer/detector.ts +0 -56
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { ts } from '@esportsplus/typescript';
|
|
2
2
|
import type { TransformResult } from '../types.js';
|
|
3
|
-
|
|
3
|
+
declare function contains(code: string): boolean;
|
|
4
4
|
declare const transform: (sourceFile: ts.SourceFile) => TransformResult;
|
|
5
5
|
export { contains, transform };
|
|
@@ -1,10 +1,44 @@
|
|
|
1
1
|
import { ts } from '@esportsplus/typescript';
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
2
|
+
import { code as c } from '@esportsplus/typescript/transformer';
|
|
3
|
+
import { COMPILER_ENTRYPOINT, COMPILER_ENTRYPOINT_REGEX, COMPILER_NAMESPACE } from '../constants.js';
|
|
4
4
|
import array from './transforms/array.js';
|
|
5
5
|
import object from './transforms/object.js';
|
|
6
6
|
import primitives from './transforms/primitives.js';
|
|
7
7
|
let transforms = [object, array, primitives];
|
|
8
|
+
function contains(code) {
|
|
9
|
+
if (!c.contains(code, { regex: COMPILER_ENTRYPOINT_REGEX })) {
|
|
10
|
+
return false;
|
|
11
|
+
}
|
|
12
|
+
let ctx = {
|
|
13
|
+
imported: false,
|
|
14
|
+
used: false
|
|
15
|
+
};
|
|
16
|
+
visit(ctx, ts.createSourceFile('detect.ts', code, ts.ScriptTarget.Latest, false));
|
|
17
|
+
return ctx.imported && ctx.used;
|
|
18
|
+
}
|
|
19
|
+
function visit(ctx, node) {
|
|
20
|
+
if (ctx.imported && ctx.used) {
|
|
21
|
+
return;
|
|
22
|
+
}
|
|
23
|
+
if (ts.isImportDeclaration(node) &&
|
|
24
|
+
node.importClause?.namedBindings &&
|
|
25
|
+
ts.isNamedImports(node.importClause.namedBindings)) {
|
|
26
|
+
let elements = node.importClause.namedBindings.elements;
|
|
27
|
+
for (let i = 0, n = elements.length; i < n; i++) {
|
|
28
|
+
let element = elements[i];
|
|
29
|
+
if ((element.propertyName?.text ?? element.name.text) === COMPILER_ENTRYPOINT) {
|
|
30
|
+
ctx.imported = true;
|
|
31
|
+
break;
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
if (ts.isCallExpression(node) &&
|
|
36
|
+
ts.isIdentifier(node.expression) &&
|
|
37
|
+
node.expression.text === COMPILER_ENTRYPOINT) {
|
|
38
|
+
ctx.used = true;
|
|
39
|
+
}
|
|
40
|
+
ts.forEachChild(node, n => visit(ctx, n));
|
|
41
|
+
}
|
|
8
42
|
const transform = (sourceFile) => {
|
|
9
43
|
let bindings = new Map(), code = sourceFile.getFullText(), current = sourceFile, result, transformed = false;
|
|
10
44
|
if (!contains(code)) {
|
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
import { ts } from '@esportsplus/typescript';
|
|
2
2
|
import { TRANSFORM_PATTERN } from '@esportsplus/typescript/transformer';
|
|
3
|
-
import {
|
|
3
|
+
import { transform } from '../../transformer/index.js';
|
|
4
4
|
import { PACKAGE } from '../../constants.js';
|
|
5
5
|
export default () => {
|
|
6
6
|
return {
|
|
7
7
|
enforce: 'pre',
|
|
8
8
|
name: `${PACKAGE}/plugin-vite`,
|
|
9
9
|
transform(code, id) {
|
|
10
|
-
if (!TRANSFORM_PATTERN.test(id) || id.includes('node_modules')
|
|
10
|
+
if (!TRANSFORM_PATTERN.test(id) || id.includes('node_modules')) {
|
|
11
11
|
return null;
|
|
12
12
|
}
|
|
13
13
|
try {
|
package/package.json
CHANGED
package/src/transformer/index.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { ts } from '@esportsplus/typescript';
|
|
2
|
-
import {
|
|
2
|
+
import { code as c } from '@esportsplus/typescript/transformer';
|
|
3
|
+
import { COMPILER_ENTRYPOINT, COMPILER_ENTRYPOINT_REGEX, COMPILER_NAMESPACE } from '~/constants';
|
|
3
4
|
import type { Bindings, TransformResult } from '~/types';
|
|
4
|
-
import { contains } from './detector';
|
|
5
5
|
import array from './transforms/array';
|
|
6
6
|
import object from './transforms/object';
|
|
7
7
|
import primitives from './transforms/primitives';
|
|
@@ -10,6 +10,55 @@ import primitives from './transforms/primitives';
|
|
|
10
10
|
let transforms = [object, array, primitives];
|
|
11
11
|
|
|
12
12
|
|
|
13
|
+
function contains(code: string): boolean {
|
|
14
|
+
if (!c.contains(code, { regex: COMPILER_ENTRYPOINT_REGEX })) {
|
|
15
|
+
return false;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
let ctx = {
|
|
19
|
+
imported: false,
|
|
20
|
+
used: false
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
visit(ctx, ts.createSourceFile('detect.ts', code, ts.ScriptTarget.Latest, false));
|
|
24
|
+
|
|
25
|
+
return ctx.imported && ctx.used;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
function visit(ctx: { imported: boolean; used: boolean; }, node: ts.Node): void {
|
|
29
|
+
if (ctx.imported && ctx.used) {
|
|
30
|
+
return;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
if (
|
|
34
|
+
ts.isImportDeclaration(node) &&
|
|
35
|
+
node.importClause?.namedBindings &&
|
|
36
|
+
ts.isNamedImports(node.importClause.namedBindings)
|
|
37
|
+
) {
|
|
38
|
+
let elements = node.importClause.namedBindings.elements;
|
|
39
|
+
|
|
40
|
+
for (let i = 0, n = elements.length; i < n; i++) {
|
|
41
|
+
let element = elements[i];
|
|
42
|
+
|
|
43
|
+
if ((element.propertyName?.text ?? element.name.text) === COMPILER_ENTRYPOINT) {
|
|
44
|
+
ctx.imported = true;
|
|
45
|
+
break;
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
if (
|
|
51
|
+
ts.isCallExpression(node) &&
|
|
52
|
+
ts.isIdentifier(node.expression) &&
|
|
53
|
+
node.expression.text === COMPILER_ENTRYPOINT
|
|
54
|
+
) {
|
|
55
|
+
ctx.used = true;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
ts.forEachChild(node, n => visit(ctx, n));
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
|
|
13
62
|
const transform = (sourceFile: ts.SourceFile): TransformResult => {
|
|
14
63
|
let bindings: Bindings = new Map(),
|
|
15
64
|
code = sourceFile.getFullText(),
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { Plugin } from 'vite';
|
|
2
2
|
import { ts } from '@esportsplus/typescript';
|
|
3
3
|
import { TRANSFORM_PATTERN } from '@esportsplus/typescript/transformer';
|
|
4
|
-
import {
|
|
4
|
+
import { transform } from '~/transformer';
|
|
5
5
|
import { PACKAGE } from '~/constants';
|
|
6
6
|
|
|
7
7
|
|
|
@@ -10,7 +10,7 @@ export default (): Plugin => {
|
|
|
10
10
|
enforce: 'pre',
|
|
11
11
|
name: `${PACKAGE}/plugin-vite`,
|
|
12
12
|
transform(code: string, id: string) {
|
|
13
|
-
if (!TRANSFORM_PATTERN.test(id) || id.includes('node_modules')
|
|
13
|
+
if (!TRANSFORM_PATTERN.test(id) || id.includes('node_modules')) {
|
|
14
14
|
return null;
|
|
15
15
|
}
|
|
16
16
|
|
|
@@ -1,38 +0,0 @@
|
|
|
1
|
-
import { code as c } from '@esportsplus/typescript/transformer';
|
|
2
|
-
import { ts } from '@esportsplus/typescript';
|
|
3
|
-
import { COMPILER_ENTRYPOINT, COMPILER_ENTRYPOINT_REGEX } from '../constants.js';
|
|
4
|
-
function visit(ctx, node) {
|
|
5
|
-
if (ctx.imported && ctx.used) {
|
|
6
|
-
return;
|
|
7
|
-
}
|
|
8
|
-
if (ts.isImportDeclaration(node) &&
|
|
9
|
-
node.importClause?.namedBindings &&
|
|
10
|
-
ts.isNamedImports(node.importClause.namedBindings)) {
|
|
11
|
-
let elements = node.importClause.namedBindings.elements;
|
|
12
|
-
for (let i = 0, n = elements.length; i < n; i++) {
|
|
13
|
-
let element = elements[i];
|
|
14
|
-
if ((element.propertyName?.text ?? element.name.text) === COMPILER_ENTRYPOINT) {
|
|
15
|
-
ctx.imported = true;
|
|
16
|
-
break;
|
|
17
|
-
}
|
|
18
|
-
}
|
|
19
|
-
}
|
|
20
|
-
if (ts.isCallExpression(node) &&
|
|
21
|
-
ts.isIdentifier(node.expression) &&
|
|
22
|
-
node.expression.text === COMPILER_ENTRYPOINT) {
|
|
23
|
-
ctx.used = true;
|
|
24
|
-
}
|
|
25
|
-
ts.forEachChild(node, n => visit(ctx, n));
|
|
26
|
-
}
|
|
27
|
-
const contains = (code) => {
|
|
28
|
-
if (!c.contains(code, { regex: COMPILER_ENTRYPOINT_REGEX })) {
|
|
29
|
-
return false;
|
|
30
|
-
}
|
|
31
|
-
let ctx = {
|
|
32
|
-
imported: false,
|
|
33
|
-
used: false
|
|
34
|
-
};
|
|
35
|
-
visit(ctx, ts.createSourceFile('detect.ts', code, ts.ScriptTarget.Latest, false));
|
|
36
|
-
return ctx.imported && ctx.used;
|
|
37
|
-
};
|
|
38
|
-
export { contains };
|
|
@@ -1,56 +0,0 @@
|
|
|
1
|
-
import { code as c } from '@esportsplus/typescript/transformer';
|
|
2
|
-
import { ts } from '@esportsplus/typescript';
|
|
3
|
-
import { COMPILER_ENTRYPOINT, COMPILER_ENTRYPOINT_REGEX } from '~/constants';
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
function visit(ctx: { imported: boolean; used: boolean; }, node: ts.Node): void {
|
|
7
|
-
if (ctx.imported && ctx.used) {
|
|
8
|
-
return;
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
if (
|
|
12
|
-
ts.isImportDeclaration(node) &&
|
|
13
|
-
node.importClause?.namedBindings &&
|
|
14
|
-
ts.isNamedImports(node.importClause.namedBindings)
|
|
15
|
-
) {
|
|
16
|
-
let elements = node.importClause.namedBindings.elements;
|
|
17
|
-
|
|
18
|
-
for (let i = 0, n = elements.length; i < n; i++) {
|
|
19
|
-
let element = elements[i];
|
|
20
|
-
|
|
21
|
-
if ((element.propertyName?.text ?? element.name.text) === COMPILER_ENTRYPOINT) {
|
|
22
|
-
ctx.imported = true;
|
|
23
|
-
break;
|
|
24
|
-
}
|
|
25
|
-
}
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
if (
|
|
29
|
-
ts.isCallExpression(node) &&
|
|
30
|
-
ts.isIdentifier(node.expression) &&
|
|
31
|
-
node.expression.text === COMPILER_ENTRYPOINT
|
|
32
|
-
) {
|
|
33
|
-
ctx.used = true;
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
ts.forEachChild(node, n => visit(ctx, n));
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
const contains = (code: string): boolean => {
|
|
41
|
-
if (!c.contains(code, { regex: COMPILER_ENTRYPOINT_REGEX })) {
|
|
42
|
-
return false;
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
let ctx = {
|
|
46
|
-
imported: false,
|
|
47
|
-
used: false
|
|
48
|
-
};
|
|
49
|
-
|
|
50
|
-
visit(ctx, ts.createSourceFile('detect.ts', code, ts.ScriptTarget.Latest, false));
|
|
51
|
-
|
|
52
|
-
return ctx.imported && ctx.used;
|
|
53
|
-
};
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
export { contains };
|