unplugin-jsx-source 0.1.4 → 0.2.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/README.md +39 -27
- package/dist/astro.cjs +4 -4
- package/dist/astro.d.cts +1 -2
- package/dist/astro.d.ts +1 -2
- package/dist/astro.js +3 -3
- package/dist/{chunk-P7PSQAUX.js → chunk-4TPYADMJ.js} +1 -1
- package/dist/{chunk-OWKZWNFL.js → chunk-B4TVXNJS.js} +1 -1
- package/dist/{chunk-YVXKU3SI.cjs → chunk-GDAWXUM7.cjs} +2 -2
- package/dist/chunk-K22ONW6P.cjs +149 -0
- package/dist/{chunk-UDE6GQN2.js → chunk-MULGLTCU.js} +4 -3
- package/dist/chunk-PSEGIIIQ.js +149 -0
- package/dist/{chunk-DDZ7JYP2.cjs → chunk-TVLQJOF2.cjs} +4 -4
- package/dist/{chunk-P5ROQE6I.cjs → chunk-WGYVTTK2.cjs} +2 -2
- package/dist/{chunk-PEWMSEKB.js → chunk-X4WJLBNU.js} +2 -2
- package/dist/{chunk-KCM5BTMP.cjs → chunk-YA35MEVK.cjs} +4 -3
- package/dist/esbuild.cjs +4 -4
- package/dist/esbuild.d.cts +1 -2
- package/dist/esbuild.d.ts +1 -2
- package/dist/esbuild.js +3 -3
- package/dist/farm.cjs +4 -4
- package/dist/farm.d.cts +1 -2
- package/dist/farm.d.ts +1 -2
- package/dist/farm.js +3 -3
- package/dist/index.cjs +4 -4
- package/dist/index.d.cts +4 -3
- package/dist/index.d.ts +1 -2
- package/dist/index.js +3 -3
- package/dist/nuxt.cjs +7 -7
- package/dist/nuxt.d.cts +4 -3
- package/dist/nuxt.d.ts +1 -2
- package/dist/nuxt.js +5 -5
- package/dist/options.cjs +2 -2
- package/dist/options.d.cts +15 -4
- package/dist/options.d.ts +15 -4
- package/dist/options.js +1 -1
- package/dist/rollup.cjs +4 -4
- package/dist/rollup.d.cts +1 -2
- package/dist/rollup.d.ts +1 -2
- package/dist/rollup.js +3 -3
- package/dist/rspack.cjs +4 -4
- package/dist/rspack.d.cts +1 -2
- package/dist/rspack.d.ts +1 -2
- package/dist/rspack.js +3 -3
- package/dist/transform.cjs +2 -2
- package/dist/transform.d.cts +4 -4
- package/dist/transform.d.ts +4 -4
- package/dist/transform.js +1 -1
- package/dist/vite.cjs +5 -5
- package/dist/vite.d.cts +2 -4
- package/dist/vite.d.ts +2 -4
- package/dist/vite.js +4 -4
- package/dist/webpack.cjs +5 -5
- package/dist/webpack.d.cts +1 -2
- package/dist/webpack.d.ts +1 -2
- package/dist/webpack.js +4 -4
- package/package.json +59 -59
- package/dist/chunk-I5SBNPWQ.js +0 -66
- package/dist/chunk-QR273UPS.cjs +0 -66
package/README.md
CHANGED
|
@@ -4,8 +4,7 @@
|
|
|
4
4
|
|
|
5
5
|
A plugin designed to automatically annotate your JSX components with a `data-at`(configurable) attribute, indicating the file name and line number for easier debugging and development.
|
|
6
6
|
|
|
7
|
-
<img width="
|
|
8
|
-
|
|
7
|
+
<img width="613" alt="image" src="https://github.com/user-attachments/assets/0e3fb65f-5d01-4a19-9888-35e8eff94afb" />
|
|
9
8
|
|
|
10
9
|
## Install
|
|
11
10
|
|
|
@@ -18,13 +17,15 @@ npm i unplugin-jsx-source
|
|
|
18
17
|
|
|
19
18
|
```ts
|
|
20
19
|
// vite.config.ts
|
|
21
|
-
import jsxSource from
|
|
20
|
+
import jsxSource from "unplugin-jsx-source/vite";
|
|
22
21
|
|
|
23
22
|
export default defineConfig({
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
})
|
|
23
|
+
plugins: [
|
|
24
|
+
jsxSource({
|
|
25
|
+
/* options */
|
|
26
|
+
}),
|
|
27
|
+
],
|
|
28
|
+
});
|
|
28
29
|
```
|
|
29
30
|
|
|
30
31
|
Example: [`playground/`](./playground/)
|
|
@@ -36,13 +37,15 @@ Example: [`playground/`](./playground/)
|
|
|
36
37
|
|
|
37
38
|
```ts
|
|
38
39
|
// rollup.config.js
|
|
39
|
-
import jsxSource from
|
|
40
|
+
import jsxSource from "unplugin-jsx-source/rollup";
|
|
40
41
|
|
|
41
42
|
export default {
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
}
|
|
43
|
+
plugins: [
|
|
44
|
+
jsxSource({
|
|
45
|
+
/* options */
|
|
46
|
+
}),
|
|
47
|
+
],
|
|
48
|
+
};
|
|
46
49
|
```
|
|
47
50
|
|
|
48
51
|
<br></details>
|
|
@@ -53,11 +56,13 @@ export default {
|
|
|
53
56
|
```ts
|
|
54
57
|
// webpack.config.js
|
|
55
58
|
module.exports = {
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
}
|
|
59
|
+
/* ... */
|
|
60
|
+
plugins: [
|
|
61
|
+
require("unplugin-jsx-source/webpack")({
|
|
62
|
+
/* options */
|
|
63
|
+
}),
|
|
64
|
+
],
|
|
65
|
+
};
|
|
61
66
|
```
|
|
62
67
|
|
|
63
68
|
<br></details>
|
|
@@ -68,10 +73,15 @@ module.exports = {
|
|
|
68
73
|
```ts
|
|
69
74
|
// nuxt.config.js
|
|
70
75
|
export default defineNuxtConfig({
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
76
|
+
modules: [
|
|
77
|
+
[
|
|
78
|
+
"unplugin-jsx-source/nuxt",
|
|
79
|
+
{
|
|
80
|
+
/* options */
|
|
81
|
+
},
|
|
82
|
+
],
|
|
83
|
+
],
|
|
84
|
+
});
|
|
75
85
|
```
|
|
76
86
|
|
|
77
87
|
> This module works for both Nuxt 2 and [Nuxt Vite](https://github.com/nuxt/vite)
|
|
@@ -84,12 +94,14 @@ export default defineNuxtConfig({
|
|
|
84
94
|
```ts
|
|
85
95
|
// vue.config.js
|
|
86
96
|
module.exports = {
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
97
|
+
configureWebpack: {
|
|
98
|
+
plugins: [
|
|
99
|
+
require("unplugin-jsx-source/webpack")({
|
|
100
|
+
/* options */
|
|
101
|
+
}),
|
|
102
|
+
],
|
|
103
|
+
},
|
|
104
|
+
};
|
|
93
105
|
```
|
|
94
106
|
|
|
95
107
|
<br></details>
|
package/dist/astro.cjs
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
"use strict";Object.defineProperty(exports, "__esModule", {value: true});
|
|
2
2
|
|
|
3
|
-
var
|
|
4
|
-
require('./chunk-
|
|
5
|
-
require('./chunk-
|
|
3
|
+
var _chunkTVLQJOF2cjs = require('./chunk-TVLQJOF2.cjs');
|
|
4
|
+
require('./chunk-K22ONW6P.cjs');
|
|
5
|
+
require('./chunk-YA35MEVK.cjs');
|
|
6
6
|
require('./chunk-P4DSWCF6.cjs');
|
|
7
7
|
|
|
8
8
|
// src/astro.ts
|
|
@@ -12,7 +12,7 @@ var astro_default = (options) => ({
|
|
|
12
12
|
"astro:config:setup": async (astro) => {
|
|
13
13
|
var _a;
|
|
14
14
|
(_a = astro.config.vite).plugins || (_a.plugins = []);
|
|
15
|
-
astro.config.vite.plugins.push(
|
|
15
|
+
astro.config.vite.plugins.push(_chunkTVLQJOF2cjs.index_default.vite(options));
|
|
16
16
|
}
|
|
17
17
|
}
|
|
18
18
|
});
|
package/dist/astro.d.cts
CHANGED
package/dist/astro.d.ts
CHANGED
package/dist/astro.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import {
|
|
2
2
|
index_default
|
|
3
|
-
} from "./chunk-
|
|
4
|
-
import "./chunk-
|
|
5
|
-
import "./chunk-
|
|
3
|
+
} from "./chunk-X4WJLBNU.js";
|
|
4
|
+
import "./chunk-PSEGIIIQ.js";
|
|
5
|
+
import "./chunk-MULGLTCU.js";
|
|
6
6
|
import "./chunk-5JBD5THX.js";
|
|
7
7
|
|
|
8
8
|
// src/astro.ts
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
"use strict";Object.defineProperty(exports, "__esModule", {value: true});
|
|
2
2
|
|
|
3
|
-
var
|
|
3
|
+
var _chunkTVLQJOF2cjs = require('./chunk-TVLQJOF2.cjs');
|
|
4
4
|
|
|
5
5
|
// src/vite.ts
|
|
6
6
|
var _unplugin = require('unplugin');
|
|
7
|
-
var vite_default = _unplugin.createVitePlugin.call(void 0,
|
|
7
|
+
var vite_default = _unplugin.createVitePlugin.call(void 0, _chunkTVLQJOF2cjs.unpluginFactory);
|
|
8
8
|
|
|
9
9
|
|
|
10
10
|
|
|
@@ -0,0 +1,149 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
2
|
+
|
|
3
|
+
var _chunkP4DSWCF6cjs = require('./chunk-P4DSWCF6.cjs');
|
|
4
|
+
|
|
5
|
+
// src/transform.ts
|
|
6
|
+
var _magicstring = require('magic-string'); var _magicstring2 = _interopRequireDefault(_magicstring);
|
|
7
|
+
var _oxcparser = require('oxc-parser');
|
|
8
|
+
function cleanModuleId(id) {
|
|
9
|
+
const q = id.indexOf("?");
|
|
10
|
+
return q === -1 ? id : id.slice(0, q);
|
|
11
|
+
}
|
|
12
|
+
function langFromId(id) {
|
|
13
|
+
const path = cleanModuleId(id);
|
|
14
|
+
if (path.endsWith(".tsx")) return "tsx";
|
|
15
|
+
if (path.endsWith(".ts")) return "ts";
|
|
16
|
+
if (path.endsWith(".jsx")) return "jsx";
|
|
17
|
+
return "js";
|
|
18
|
+
}
|
|
19
|
+
function offsetToLocation(source, offset) {
|
|
20
|
+
let line = 1;
|
|
21
|
+
let lineStart = 0;
|
|
22
|
+
for (let i = 0; i < offset && i < source.length; i++) {
|
|
23
|
+
if (source[i] === "\n") {
|
|
24
|
+
line++;
|
|
25
|
+
lineStart = i + 1;
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
return { line, column: offset - lineStart };
|
|
29
|
+
}
|
|
30
|
+
function spanToSourceLocation(source, start, end) {
|
|
31
|
+
return {
|
|
32
|
+
start: offsetToLocation(source, start),
|
|
33
|
+
end: offsetToLocation(source, end)
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
function isJsxIdentifierName(name) {
|
|
37
|
+
return name.type === "JSXIdentifier";
|
|
38
|
+
}
|
|
39
|
+
function attrNameMatches(attr, name) {
|
|
40
|
+
return attr.type === "JSXAttribute" && attr.name.type === "JSXIdentifier" && attr.name.name === name;
|
|
41
|
+
}
|
|
42
|
+
function findEnclosingComponentName(ancestors) {
|
|
43
|
+
var _a;
|
|
44
|
+
for (let i = ancestors.length - 1; i >= 0; i--) {
|
|
45
|
+
const n = ancestors[i];
|
|
46
|
+
if (n.type === "VariableDeclarator") {
|
|
47
|
+
if (n.id.type === "Identifier") return n.id.name;
|
|
48
|
+
}
|
|
49
|
+
if (n.type === "FunctionDeclaration") {
|
|
50
|
+
const fn = n;
|
|
51
|
+
if (((_a = fn.id) == null ? void 0 : _a.type) === "Identifier") return fn.id.name;
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
return null;
|
|
55
|
+
}
|
|
56
|
+
function walkAst(node, ancestors, visit) {
|
|
57
|
+
if (node.type === "JSXOpeningElement") {
|
|
58
|
+
visit(node, ancestors);
|
|
59
|
+
}
|
|
60
|
+
const keys = _oxcparser.visitorKeys[node.type];
|
|
61
|
+
if (!keys) return;
|
|
62
|
+
const nextAncestors = [...ancestors, node];
|
|
63
|
+
for (const key of keys) {
|
|
64
|
+
const child = node[key];
|
|
65
|
+
if (child == null) continue;
|
|
66
|
+
if (Array.isArray(child)) {
|
|
67
|
+
for (const item of child) {
|
|
68
|
+
if (item && typeof item === "object" && "type" in item) {
|
|
69
|
+
walkAst(item, nextAncestors, visit);
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
} else if (typeof child === "object" && "type" in child) {
|
|
73
|
+
walkAst(child, nextAncestors, visit);
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
function jsxOpeningInsertOffset(code, path) {
|
|
78
|
+
const segment = code.slice(path.start, path.end);
|
|
79
|
+
if (segment.endsWith("/>")) {
|
|
80
|
+
return path.end - 2;
|
|
81
|
+
}
|
|
82
|
+
const i = path.end - 1;
|
|
83
|
+
if (i < path.start || code[i] !== ">") {
|
|
84
|
+
throw new Error(
|
|
85
|
+
`unplugin-jsx-source: could not find closing ">" for JSX opening element`
|
|
86
|
+
);
|
|
87
|
+
}
|
|
88
|
+
return i;
|
|
89
|
+
}
|
|
90
|
+
function fmtAttr(name, value) {
|
|
91
|
+
return ` ${name}=${JSON.stringify(value)}`;
|
|
92
|
+
}
|
|
93
|
+
function transform(code, id, opt) {
|
|
94
|
+
var _a;
|
|
95
|
+
const parseId = cleanModuleId(id);
|
|
96
|
+
const lang = (_a = opt.parserOptions.lang) != null ? _a : langFromId(parseId);
|
|
97
|
+
const result = _oxcparser.parseSync.call(void 0, parseId, code, _chunkP4DSWCF6cjs.__spreadValues.call(void 0, {
|
|
98
|
+
sourceType: "module",
|
|
99
|
+
lang
|
|
100
|
+
}, opt.parserOptions));
|
|
101
|
+
if (result.errors.length > 0) {
|
|
102
|
+
const messages = result.errors.map((e) => e.message).join("\n");
|
|
103
|
+
throw new Error(`oxc parse failed for ${parseId}:
|
|
104
|
+
${messages}`);
|
|
105
|
+
}
|
|
106
|
+
const { program } = result;
|
|
107
|
+
const { at: attrAt, in: attrIn, kind: attrKind } = opt.attributes;
|
|
108
|
+
const inserts = [];
|
|
109
|
+
walkAst(program, [], (path, ancestors) => {
|
|
110
|
+
if (!isJsxIdentifierName(path.name)) return;
|
|
111
|
+
const tag = path.name.name;
|
|
112
|
+
if (tag === "Fragment") return;
|
|
113
|
+
const isComponent = tag[0] === tag[0].toUpperCase();
|
|
114
|
+
const hasSpreadProps = path.attributes.some(
|
|
115
|
+
(attr) => attr.type === "JSXSpreadAttribute"
|
|
116
|
+
);
|
|
117
|
+
const parts = [];
|
|
118
|
+
if (attrAt && !path.attributes.some((a) => attrNameMatches(a, attrAt)) && !hasSpreadProps) {
|
|
119
|
+
const loc = spanToSourceLocation(code, path.start, path.end);
|
|
120
|
+
const fileName = opt.transformFileName(parseId, loc);
|
|
121
|
+
parts.push(fmtAttr(attrAt, fileName));
|
|
122
|
+
}
|
|
123
|
+
if (attrIn && !path.attributes.some((a) => attrNameMatches(a, attrIn)) && !hasSpreadProps) {
|
|
124
|
+
const enclosing = findEnclosingComponentName(ancestors);
|
|
125
|
+
if (enclosing) {
|
|
126
|
+
parts.push(fmtAttr(attrIn, enclosing));
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
if (attrKind && !path.attributes.some((a) => attrNameMatches(a, attrKind)) && isComponent) {
|
|
130
|
+
parts.push(fmtAttr(attrKind, tag));
|
|
131
|
+
}
|
|
132
|
+
if (parts.length === 0) return;
|
|
133
|
+
const offset = jsxOpeningInsertOffset(code, path);
|
|
134
|
+
inserts.push({ offset, text: parts.join("") });
|
|
135
|
+
});
|
|
136
|
+
inserts.sort((a, b) => b.offset - a.offset);
|
|
137
|
+
const s = new (0, _magicstring2.default)(code);
|
|
138
|
+
for (const { offset, text } of inserts) {
|
|
139
|
+
s.appendLeft(offset, text);
|
|
140
|
+
}
|
|
141
|
+
return {
|
|
142
|
+
code: s.toString(),
|
|
143
|
+
map: s.generateMap({ source: parseId, hires: true, includeContent: true })
|
|
144
|
+
};
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
|
|
148
|
+
|
|
149
|
+
exports.transform = transform;
|
|
@@ -3,14 +3,15 @@ import {
|
|
|
3
3
|
} from "./chunk-5JBD5THX.js";
|
|
4
4
|
|
|
5
5
|
// src/options.ts
|
|
6
|
-
var
|
|
6
|
+
var DEFAULT_INCLUDE_PATTERN = /\.[jt]sx?$/;
|
|
7
|
+
function defaultTransformFileName(id, loc) {
|
|
7
8
|
var _a;
|
|
8
9
|
const fileName = (_a = id.split("/").pop()) != null ? _a : "unknown";
|
|
9
10
|
return `${fileName}:${loc.start.line}-${loc.end.line}`;
|
|
10
|
-
}
|
|
11
|
+
}
|
|
11
12
|
function resolveOption(options) {
|
|
12
13
|
return {
|
|
13
|
-
include: options.include || [
|
|
14
|
+
include: options.include || [DEFAULT_INCLUDE_PATTERN],
|
|
14
15
|
exclude: options.exclude || void 0,
|
|
15
16
|
enforce: options.enforce || void 0,
|
|
16
17
|
parserOptions: options.parserOptions || {},
|
|
@@ -0,0 +1,149 @@
|
|
|
1
|
+
import {
|
|
2
|
+
__spreadValues
|
|
3
|
+
} from "./chunk-5JBD5THX.js";
|
|
4
|
+
|
|
5
|
+
// src/transform.ts
|
|
6
|
+
import MagicString from "magic-string";
|
|
7
|
+
import { parseSync, visitorKeys } from "oxc-parser";
|
|
8
|
+
function cleanModuleId(id) {
|
|
9
|
+
const q = id.indexOf("?");
|
|
10
|
+
return q === -1 ? id : id.slice(0, q);
|
|
11
|
+
}
|
|
12
|
+
function langFromId(id) {
|
|
13
|
+
const path = cleanModuleId(id);
|
|
14
|
+
if (path.endsWith(".tsx")) return "tsx";
|
|
15
|
+
if (path.endsWith(".ts")) return "ts";
|
|
16
|
+
if (path.endsWith(".jsx")) return "jsx";
|
|
17
|
+
return "js";
|
|
18
|
+
}
|
|
19
|
+
function offsetToLocation(source, offset) {
|
|
20
|
+
let line = 1;
|
|
21
|
+
let lineStart = 0;
|
|
22
|
+
for (let i = 0; i < offset && i < source.length; i++) {
|
|
23
|
+
if (source[i] === "\n") {
|
|
24
|
+
line++;
|
|
25
|
+
lineStart = i + 1;
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
return { line, column: offset - lineStart };
|
|
29
|
+
}
|
|
30
|
+
function spanToSourceLocation(source, start, end) {
|
|
31
|
+
return {
|
|
32
|
+
start: offsetToLocation(source, start),
|
|
33
|
+
end: offsetToLocation(source, end)
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
function isJsxIdentifierName(name) {
|
|
37
|
+
return name.type === "JSXIdentifier";
|
|
38
|
+
}
|
|
39
|
+
function attrNameMatches(attr, name) {
|
|
40
|
+
return attr.type === "JSXAttribute" && attr.name.type === "JSXIdentifier" && attr.name.name === name;
|
|
41
|
+
}
|
|
42
|
+
function findEnclosingComponentName(ancestors) {
|
|
43
|
+
var _a;
|
|
44
|
+
for (let i = ancestors.length - 1; i >= 0; i--) {
|
|
45
|
+
const n = ancestors[i];
|
|
46
|
+
if (n.type === "VariableDeclarator") {
|
|
47
|
+
if (n.id.type === "Identifier") return n.id.name;
|
|
48
|
+
}
|
|
49
|
+
if (n.type === "FunctionDeclaration") {
|
|
50
|
+
const fn = n;
|
|
51
|
+
if (((_a = fn.id) == null ? void 0 : _a.type) === "Identifier") return fn.id.name;
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
return null;
|
|
55
|
+
}
|
|
56
|
+
function walkAst(node, ancestors, visit) {
|
|
57
|
+
if (node.type === "JSXOpeningElement") {
|
|
58
|
+
visit(node, ancestors);
|
|
59
|
+
}
|
|
60
|
+
const keys = visitorKeys[node.type];
|
|
61
|
+
if (!keys) return;
|
|
62
|
+
const nextAncestors = [...ancestors, node];
|
|
63
|
+
for (const key of keys) {
|
|
64
|
+
const child = node[key];
|
|
65
|
+
if (child == null) continue;
|
|
66
|
+
if (Array.isArray(child)) {
|
|
67
|
+
for (const item of child) {
|
|
68
|
+
if (item && typeof item === "object" && "type" in item) {
|
|
69
|
+
walkAst(item, nextAncestors, visit);
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
} else if (typeof child === "object" && "type" in child) {
|
|
73
|
+
walkAst(child, nextAncestors, visit);
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
function jsxOpeningInsertOffset(code, path) {
|
|
78
|
+
const segment = code.slice(path.start, path.end);
|
|
79
|
+
if (segment.endsWith("/>")) {
|
|
80
|
+
return path.end - 2;
|
|
81
|
+
}
|
|
82
|
+
const i = path.end - 1;
|
|
83
|
+
if (i < path.start || code[i] !== ">") {
|
|
84
|
+
throw new Error(
|
|
85
|
+
`unplugin-jsx-source: could not find closing ">" for JSX opening element`
|
|
86
|
+
);
|
|
87
|
+
}
|
|
88
|
+
return i;
|
|
89
|
+
}
|
|
90
|
+
function fmtAttr(name, value) {
|
|
91
|
+
return ` ${name}=${JSON.stringify(value)}`;
|
|
92
|
+
}
|
|
93
|
+
function transform(code, id, opt) {
|
|
94
|
+
var _a;
|
|
95
|
+
const parseId = cleanModuleId(id);
|
|
96
|
+
const lang = (_a = opt.parserOptions.lang) != null ? _a : langFromId(parseId);
|
|
97
|
+
const result = parseSync(parseId, code, __spreadValues({
|
|
98
|
+
sourceType: "module",
|
|
99
|
+
lang
|
|
100
|
+
}, opt.parserOptions));
|
|
101
|
+
if (result.errors.length > 0) {
|
|
102
|
+
const messages = result.errors.map((e) => e.message).join("\n");
|
|
103
|
+
throw new Error(`oxc parse failed for ${parseId}:
|
|
104
|
+
${messages}`);
|
|
105
|
+
}
|
|
106
|
+
const { program } = result;
|
|
107
|
+
const { at: attrAt, in: attrIn, kind: attrKind } = opt.attributes;
|
|
108
|
+
const inserts = [];
|
|
109
|
+
walkAst(program, [], (path, ancestors) => {
|
|
110
|
+
if (!isJsxIdentifierName(path.name)) return;
|
|
111
|
+
const tag = path.name.name;
|
|
112
|
+
if (tag === "Fragment") return;
|
|
113
|
+
const isComponent = tag[0] === tag[0].toUpperCase();
|
|
114
|
+
const hasSpreadProps = path.attributes.some(
|
|
115
|
+
(attr) => attr.type === "JSXSpreadAttribute"
|
|
116
|
+
);
|
|
117
|
+
const parts = [];
|
|
118
|
+
if (attrAt && !path.attributes.some((a) => attrNameMatches(a, attrAt)) && !hasSpreadProps) {
|
|
119
|
+
const loc = spanToSourceLocation(code, path.start, path.end);
|
|
120
|
+
const fileName = opt.transformFileName(parseId, loc);
|
|
121
|
+
parts.push(fmtAttr(attrAt, fileName));
|
|
122
|
+
}
|
|
123
|
+
if (attrIn && !path.attributes.some((a) => attrNameMatches(a, attrIn)) && !hasSpreadProps) {
|
|
124
|
+
const enclosing = findEnclosingComponentName(ancestors);
|
|
125
|
+
if (enclosing) {
|
|
126
|
+
parts.push(fmtAttr(attrIn, enclosing));
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
if (attrKind && !path.attributes.some((a) => attrNameMatches(a, attrKind)) && isComponent) {
|
|
130
|
+
parts.push(fmtAttr(attrKind, tag));
|
|
131
|
+
}
|
|
132
|
+
if (parts.length === 0) return;
|
|
133
|
+
const offset = jsxOpeningInsertOffset(code, path);
|
|
134
|
+
inserts.push({ offset, text: parts.join("") });
|
|
135
|
+
});
|
|
136
|
+
inserts.sort((a, b) => b.offset - a.offset);
|
|
137
|
+
const s = new MagicString(code);
|
|
138
|
+
for (const { offset, text } of inserts) {
|
|
139
|
+
s.appendLeft(offset, text);
|
|
140
|
+
}
|
|
141
|
+
return {
|
|
142
|
+
code: s.toString(),
|
|
143
|
+
map: s.generateMap({ source: parseId, hires: true, includeContent: true })
|
|
144
|
+
};
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
export {
|
|
148
|
+
transform
|
|
149
|
+
};
|
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
"use strict";Object.defineProperty(exports, "__esModule", {value: true});
|
|
2
2
|
|
|
3
|
-
var
|
|
3
|
+
var _chunkK22ONW6Pcjs = require('./chunk-K22ONW6P.cjs');
|
|
4
4
|
|
|
5
5
|
|
|
6
|
-
var
|
|
6
|
+
var _chunkYA35MEVKcjs = require('./chunk-YA35MEVK.cjs');
|
|
7
7
|
|
|
8
8
|
// src/index.ts
|
|
9
9
|
var _unplugin = require('unplugin');
|
|
10
10
|
var _unpluginutils = require('unplugin-utils');
|
|
11
11
|
var unpluginFactory = (options = {}) => {
|
|
12
|
-
const opt =
|
|
12
|
+
const opt = _chunkYA35MEVKcjs.resolveOption.call(void 0, options);
|
|
13
13
|
const filter = _unpluginutils.createFilter.call(void 0, opt.include, opt.exclude);
|
|
14
14
|
return {
|
|
15
15
|
name: "unplugin-jsx-source",
|
|
@@ -18,7 +18,7 @@ var unpluginFactory = (options = {}) => {
|
|
|
18
18
|
return filter(id);
|
|
19
19
|
},
|
|
20
20
|
transform(code, id) {
|
|
21
|
-
return
|
|
21
|
+
return _chunkK22ONW6Pcjs.transform.call(void 0, code, id, opt);
|
|
22
22
|
}
|
|
23
23
|
};
|
|
24
24
|
};
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
"use strict";Object.defineProperty(exports, "__esModule", {value: true});
|
|
2
2
|
|
|
3
|
-
var
|
|
3
|
+
var _chunkTVLQJOF2cjs = require('./chunk-TVLQJOF2.cjs');
|
|
4
4
|
|
|
5
5
|
// src/webpack.ts
|
|
6
6
|
var _unplugin = require('unplugin');
|
|
7
|
-
var webpack_default = _unplugin.createWebpackPlugin.call(void 0,
|
|
7
|
+
var webpack_default = _unplugin.createWebpackPlugin.call(void 0, _chunkTVLQJOF2cjs.unpluginFactory);
|
|
8
8
|
|
|
9
9
|
|
|
10
10
|
|
|
@@ -3,14 +3,15 @@
|
|
|
3
3
|
var _chunkP4DSWCF6cjs = require('./chunk-P4DSWCF6.cjs');
|
|
4
4
|
|
|
5
5
|
// src/options.ts
|
|
6
|
-
var
|
|
6
|
+
var DEFAULT_INCLUDE_PATTERN = /\.[jt]sx?$/;
|
|
7
|
+
function defaultTransformFileName(id, loc) {
|
|
7
8
|
var _a;
|
|
8
9
|
const fileName = (_a = id.split("/").pop()) != null ? _a : "unknown";
|
|
9
10
|
return `${fileName}:${loc.start.line}-${loc.end.line}`;
|
|
10
|
-
}
|
|
11
|
+
}
|
|
11
12
|
function resolveOption(options) {
|
|
12
13
|
return {
|
|
13
|
-
include: options.include || [
|
|
14
|
+
include: options.include || [DEFAULT_INCLUDE_PATTERN],
|
|
14
15
|
exclude: options.exclude || void 0,
|
|
15
16
|
enforce: options.enforce || void 0,
|
|
16
17
|
parserOptions: options.parserOptions || {},
|
package/dist/esbuild.cjs
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
"use strict";Object.defineProperty(exports, "__esModule", {value: true});
|
|
2
2
|
|
|
3
|
-
var
|
|
4
|
-
require('./chunk-
|
|
5
|
-
require('./chunk-
|
|
3
|
+
var _chunkTVLQJOF2cjs = require('./chunk-TVLQJOF2.cjs');
|
|
4
|
+
require('./chunk-K22ONW6P.cjs');
|
|
5
|
+
require('./chunk-YA35MEVK.cjs');
|
|
6
6
|
require('./chunk-P4DSWCF6.cjs');
|
|
7
7
|
|
|
8
8
|
// src/esbuild.ts
|
|
9
9
|
var _unplugin = require('unplugin');
|
|
10
|
-
var esbuild_default = _unplugin.createEsbuildPlugin.call(void 0,
|
|
10
|
+
var esbuild_default = _unplugin.createEsbuildPlugin.call(void 0, _chunkTVLQJOF2cjs.unpluginFactory);
|
|
11
11
|
|
|
12
12
|
|
|
13
13
|
exports.default = esbuild_default;
|
package/dist/esbuild.d.cts
CHANGED
package/dist/esbuild.d.ts
CHANGED
package/dist/esbuild.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import {
|
|
2
2
|
unpluginFactory
|
|
3
|
-
} from "./chunk-
|
|
4
|
-
import "./chunk-
|
|
5
|
-
import "./chunk-
|
|
3
|
+
} from "./chunk-X4WJLBNU.js";
|
|
4
|
+
import "./chunk-PSEGIIIQ.js";
|
|
5
|
+
import "./chunk-MULGLTCU.js";
|
|
6
6
|
import "./chunk-5JBD5THX.js";
|
|
7
7
|
|
|
8
8
|
// src/esbuild.ts
|
package/dist/farm.cjs
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
"use strict";Object.defineProperty(exports, "__esModule", {value: true});
|
|
2
2
|
|
|
3
|
-
var
|
|
4
|
-
require('./chunk-
|
|
5
|
-
require('./chunk-
|
|
3
|
+
var _chunkTVLQJOF2cjs = require('./chunk-TVLQJOF2.cjs');
|
|
4
|
+
require('./chunk-K22ONW6P.cjs');
|
|
5
|
+
require('./chunk-YA35MEVK.cjs');
|
|
6
6
|
require('./chunk-P4DSWCF6.cjs');
|
|
7
7
|
|
|
8
8
|
// src/farm.ts
|
|
9
9
|
var _unplugin = require('unplugin');
|
|
10
|
-
var farm_default = _unplugin.createFarmPlugin.call(void 0,
|
|
10
|
+
var farm_default = _unplugin.createFarmPlugin.call(void 0, _chunkTVLQJOF2cjs.unpluginFactory);
|
|
11
11
|
|
|
12
12
|
|
|
13
13
|
exports.default = farm_default;
|
package/dist/farm.d.cts
CHANGED
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
import * as _farmfe_core from '@farmfe/core';
|
|
2
2
|
import { Options } from './options.cjs';
|
|
3
|
-
import '
|
|
3
|
+
import 'oxc-parser';
|
|
4
4
|
import 'unplugin-utils';
|
|
5
|
-
import '@babel/types';
|
|
6
5
|
|
|
7
6
|
declare const _default: (options?: Options | undefined) => _farmfe_core.JsPlugin;
|
|
8
7
|
|