@dxup/vanilla 0.0.1
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/LICENSE +21 -0
- package/README.md +50 -0
- package/dist/index.cjs +113 -0
- package/dist/index.d.cts +5 -0
- package/package.json +27 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
The MIT License (MIT)
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025-present KazariEX
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
# @dxup/vanilla
|
|
2
|
+
|
|
3
|
+
[](https://www.npmjs.com/package/@dxup/vanilla)
|
|
4
|
+
[](https://www.npmjs.com/package/@dxup/vanilla)
|
|
5
|
+
[](/LICENSE)
|
|
6
|
+
|
|
7
|
+
This is a TypeScript plugin for Vanilla JS.
|
|
8
|
+
|
|
9
|
+
## Installation
|
|
10
|
+
|
|
11
|
+
```bash
|
|
12
|
+
pnpm i -D @dxup/vanilla
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
Or you can install the VS Code extension for easier setup:
|
|
16
|
+
|
|
17
|
+
```bash
|
|
18
|
+
code --install-extension KazariEX.dxup
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
## Usage
|
|
22
|
+
|
|
23
|
+
Add the following to your `tsconfig.json`:
|
|
24
|
+
|
|
25
|
+
```json
|
|
26
|
+
{
|
|
27
|
+
"compilerOptions": {
|
|
28
|
+
"plugins": [
|
|
29
|
+
{ "name": "@dxup/vanilla" }
|
|
30
|
+
]
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
## Features
|
|
36
|
+
|
|
37
|
+
### 1. signature
|
|
38
|
+
|
|
39
|
+
Go to definition for signature parameters.
|
|
40
|
+
|
|
41
|
+
```ts
|
|
42
|
+
export default defineConfig({
|
|
43
|
+
plugins: [{
|
|
44
|
+
name: "testify",
|
|
45
|
+
transform(code, id, options) {
|
|
46
|
+
// ^^^^^^^
|
|
47
|
+
},
|
|
48
|
+
}],
|
|
49
|
+
});
|
|
50
|
+
```
|
package/dist/index.cjs
ADDED
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
|
|
2
|
+
//#region ../shared/src/index.ts
|
|
3
|
+
function* forEachTouchingNode(ts, sourceFile, position) {
|
|
4
|
+
yield* binaryVisit(ts, sourceFile, sourceFile, position);
|
|
5
|
+
}
|
|
6
|
+
function* binaryVisit(ts, sourceFile, node, position) {
|
|
7
|
+
const nodes = [];
|
|
8
|
+
ts.forEachChild(node, (child) => {
|
|
9
|
+
nodes.push(child);
|
|
10
|
+
});
|
|
11
|
+
let left = 0;
|
|
12
|
+
let right = nodes.length - 1;
|
|
13
|
+
while (left <= right) {
|
|
14
|
+
const mid = Math.floor((left + right) / 2);
|
|
15
|
+
const node$1 = nodes[mid];
|
|
16
|
+
if (position > node$1.getEnd()) left = mid + 1;
|
|
17
|
+
else if (position < node$1.getStart(sourceFile)) right = mid - 1;
|
|
18
|
+
else {
|
|
19
|
+
yield node$1;
|
|
20
|
+
yield* binaryVisit(ts, sourceFile, node$1, position);
|
|
21
|
+
return;
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
//#endregion
|
|
27
|
+
//#region src/index.ts
|
|
28
|
+
const plugin = (module$1) => {
|
|
29
|
+
const { typescript: ts } = module$1;
|
|
30
|
+
return { create(info) {
|
|
31
|
+
for (const [key, method] of [["getDefinitionAndBoundSpan", getDefinitionAndBoundSpan]]) {
|
|
32
|
+
const original = info.languageService[key];
|
|
33
|
+
info.languageService[key] = method(ts, info, original);
|
|
34
|
+
}
|
|
35
|
+
return info.languageService;
|
|
36
|
+
} };
|
|
37
|
+
};
|
|
38
|
+
var src_default = plugin;
|
|
39
|
+
function getDefinitionAndBoundSpan(ts, info, getDefinitionAndBoundSpan$1) {
|
|
40
|
+
return (...args) => {
|
|
41
|
+
const result = getDefinitionAndBoundSpan$1(...args);
|
|
42
|
+
if (!result?.definitions?.length) return result;
|
|
43
|
+
if (result.definitions[0].kind === ts.ScriptElementKind.parameterElement && result.definitions[0].textSpan.start === result.textSpan.start) {
|
|
44
|
+
const program = info.languageService.getProgram();
|
|
45
|
+
const sourceFile = program.getSourceFile(args[0]);
|
|
46
|
+
const checker = program.getTypeChecker();
|
|
47
|
+
let node;
|
|
48
|
+
for (const child of forEachTouchingNode(ts, sourceFile, args[1])) if (ts.isParameter(child)) node = child;
|
|
49
|
+
if (!node || node.dotDotDotToken) return result;
|
|
50
|
+
const firstArg = node.parent.parameters[0];
|
|
51
|
+
const withThis = ts.isIdentifier(firstArg.name) && firstArg.name.text === "this";
|
|
52
|
+
const index = node.parent.parameters.indexOf(node) - Number(withThis);
|
|
53
|
+
const definitions = [];
|
|
54
|
+
for (const signature of forEachSignature(ts, checker, node.parent)) {
|
|
55
|
+
let i = -1;
|
|
56
|
+
for (const declaration of forEachParameter(checker, signature)) {
|
|
57
|
+
if (i++ !== index) continue;
|
|
58
|
+
if (declaration) {
|
|
59
|
+
const sourceFile$1 = declaration.getSourceFile();
|
|
60
|
+
definitions.push({
|
|
61
|
+
fileName: sourceFile$1.fileName,
|
|
62
|
+
textSpan: {
|
|
63
|
+
start: declaration.getStart(sourceFile$1),
|
|
64
|
+
length: declaration.getWidth(sourceFile$1)
|
|
65
|
+
},
|
|
66
|
+
kind: ts.ScriptElementKind.parameterElement,
|
|
67
|
+
name: declaration.getText(sourceFile$1),
|
|
68
|
+
containerKind: ts.ScriptElementKind.unknown,
|
|
69
|
+
containerName: ""
|
|
70
|
+
});
|
|
71
|
+
}
|
|
72
|
+
break;
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
if (definitions.length) result.definitions = definitions;
|
|
76
|
+
}
|
|
77
|
+
return result;
|
|
78
|
+
};
|
|
79
|
+
}
|
|
80
|
+
function* forEachSignature(ts, checker, signature) {
|
|
81
|
+
if (ts.isExpression(signature)) yield* flattenSignatures(checker.getContextualType(signature));
|
|
82
|
+
else if (ts.isMethodDeclaration(signature) && ts.isIdentifier(signature.name) && ts.isObjectLiteralExpression(signature.parent)) {
|
|
83
|
+
const contextualType = checker.getContextualType(signature.parent);
|
|
84
|
+
for (const type of forEachType(contextualType)) {
|
|
85
|
+
const property = type.getProperty(signature.name.text);
|
|
86
|
+
if (property) yield* flattenSignatures(checker.getTypeOfSymbol(property));
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
function* flattenSignatures(type) {
|
|
91
|
+
if (type?.isUnionOrIntersection()) for (const subtype of type.types) yield* flattenSignatures(subtype);
|
|
92
|
+
else if (type) yield* type.getCallSignatures();
|
|
93
|
+
}
|
|
94
|
+
function* forEachType(type) {
|
|
95
|
+
if (type?.isUnionOrIntersection()) for (const subtype of type.types) yield* forEachType(subtype);
|
|
96
|
+
else if (type) yield type;
|
|
97
|
+
}
|
|
98
|
+
function* forEachParameter(checker, signature) {
|
|
99
|
+
yield signature.thisParameter?.valueDeclaration;
|
|
100
|
+
for (const parameter of signature.parameters) {
|
|
101
|
+
const declaration = parameter.valueDeclaration;
|
|
102
|
+
if (declaration?.dotDotDotToken) {
|
|
103
|
+
const type = checker.getTypeOfSymbol(parameter);
|
|
104
|
+
if (checker.isTupleType(type)) {
|
|
105
|
+
const tuple = type.target;
|
|
106
|
+
if (tuple.labeledElementDeclarations) yield* tuple.labeledElementDeclarations;
|
|
107
|
+
}
|
|
108
|
+
} else yield declaration;
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
//#endregion
|
|
113
|
+
module.exports = src_default;
|
package/dist/index.d.cts
ADDED
package/package.json
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@dxup/vanilla",
|
|
3
|
+
"type": "module",
|
|
4
|
+
"version": "0.0.1",
|
|
5
|
+
"description": "TypeScript plugin for Vanilla JS",
|
|
6
|
+
"author": "KazariEX",
|
|
7
|
+
"license": "MIT",
|
|
8
|
+
"repository": "KazariEX/dxup",
|
|
9
|
+
"exports": {
|
|
10
|
+
".": "./dist/index.cjs",
|
|
11
|
+
"./package.json": "./package.json"
|
|
12
|
+
},
|
|
13
|
+
"main": "./dist/index.cjs",
|
|
14
|
+
"types": "./dist/index.d.cts",
|
|
15
|
+
"files": [
|
|
16
|
+
"dist"
|
|
17
|
+
],
|
|
18
|
+
"devDependencies": {
|
|
19
|
+
"@dxup/shared": "",
|
|
20
|
+
"typescript": "^5.9.3"
|
|
21
|
+
},
|
|
22
|
+
"scripts": {
|
|
23
|
+
"build": "tsdown",
|
|
24
|
+
"dev": "tsdown -w --sourcemap",
|
|
25
|
+
"release": "node ../../scripts/release.ts"
|
|
26
|
+
}
|
|
27
|
+
}
|