@unocss/transformer-attributify-jsx 66.3.3 → 66.4.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/README.md +0 -2
- package/dist/index.d.mts +2 -1
- package/dist/index.d.ts +2 -1
- package/dist/index.mjs +24 -39
- package/package.json +4 -2
package/README.md
CHANGED
|
@@ -68,8 +68,6 @@ export default defineConfig({
|
|
|
68
68
|
|
|
69
69
|
## Caveats
|
|
70
70
|
|
|
71
|
-
If you encounter any issues with this package, there is [@unocss/transformer-attributify-jsx-babel](https://github.com/unocss/unocss/tree/main/packages-presets/transformer-attributify-jsx-babel) package that uses Babel to transform JSX.
|
|
72
|
-
|
|
73
71
|
> ⚠️ The rules are almost the same as those of `preset-attributify`, but there are several precautions
|
|
74
72
|
|
|
75
73
|
```html
|
package/dist/index.d.mts
CHANGED
|
@@ -21,4 +21,5 @@ interface TransformerAttributifyJsxOptions {
|
|
|
21
21
|
}
|
|
22
22
|
declare function transformerAttributifyJsx(options?: TransformerAttributifyJsxOptions): SourceCodeTransformer;
|
|
23
23
|
|
|
24
|
-
export {
|
|
24
|
+
export { transformerAttributifyJsx as default };
|
|
25
|
+
export type { FilterPattern, TransformerAttributifyJsxOptions };
|
package/dist/index.d.ts
CHANGED
|
@@ -21,4 +21,5 @@ interface TransformerAttributifyJsxOptions {
|
|
|
21
21
|
}
|
|
22
22
|
declare function transformerAttributifyJsx(options?: TransformerAttributifyJsxOptions): SourceCodeTransformer;
|
|
23
23
|
|
|
24
|
-
export {
|
|
24
|
+
export { transformerAttributifyJsx as default };
|
|
25
|
+
export type { FilterPattern, TransformerAttributifyJsxOptions };
|
package/dist/index.mjs
CHANGED
|
@@ -1,3 +1,6 @@
|
|
|
1
|
+
import process from 'node:process';
|
|
2
|
+
import { parse } from '@babel/parser';
|
|
3
|
+
import traverse from '@babel/traverse';
|
|
1
4
|
import { toArray } from '@unocss/core';
|
|
2
5
|
|
|
3
6
|
function createFilter(include, exclude) {
|
|
@@ -9,9 +12,6 @@ function createFilter(include, exclude) {
|
|
|
9
12
|
return includePattern.some((p) => id.match(p));
|
|
10
13
|
};
|
|
11
14
|
}
|
|
12
|
-
const elementRE = /<([^/?<>0-9$_!][^\s>]*)\s+((?:"[^"]*"|'[^"]*'|(\{[^}]*\})|[^{>])+)>/g;
|
|
13
|
-
const attributeRE = /(?<![~`!$%^&*()_+\-=[{;':"|,.<>/?])([a-z()#][[?\w\-:()#%\]]*)(?:\s*=\s*('[^']*'|"[^"]*"|\S+))?|\{[^}]*\}/gi;
|
|
14
|
-
const valuedAttributeRE = /((?!\d|-{2}|-\d)[\w\u00A0-\uFFFF:!%.~<-]+)=(?:"[^"]*"|'[^']*'|(\{)((?:[`(][^`)]*[`)]|[^}])+)(\}))/g;
|
|
15
15
|
function transformerAttributifyJsx(options = {}) {
|
|
16
16
|
const {
|
|
17
17
|
blocklist = []
|
|
@@ -36,44 +36,29 @@ function transformerAttributifyJsx(options = {}) {
|
|
|
36
36
|
enforce: "pre",
|
|
37
37
|
idFilter,
|
|
38
38
|
async transform(code, _, { uno }) {
|
|
39
|
+
if (process.env.VSCODE_CWD)
|
|
40
|
+
return;
|
|
39
41
|
const tasks = [];
|
|
40
|
-
const
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
if (preLastModifierIndex !== 0)
|
|
59
|
-
return temp;
|
|
60
|
-
return " ".repeat(match.length);
|
|
61
|
-
});
|
|
42
|
+
const ast = parse(code.toString(), {
|
|
43
|
+
sourceType: "module",
|
|
44
|
+
plugins: ["jsx", "typescript"]
|
|
45
|
+
});
|
|
46
|
+
traverse(ast, {
|
|
47
|
+
JSXAttribute(path) {
|
|
48
|
+
if (path.node.value === null) {
|
|
49
|
+
const attr = path.node.name.type === "JSXNamespacedName" ? `${path.node.name.namespace.name}:${path.node.name.name.name}` : path.node.name.name;
|
|
50
|
+
if (isBlocked(attr))
|
|
51
|
+
return;
|
|
52
|
+
tasks.push(
|
|
53
|
+
uno.parseToken(attr).then((matched) => {
|
|
54
|
+
if (matched) {
|
|
55
|
+
code.appendRight(path.node.end, '=""');
|
|
56
|
+
}
|
|
57
|
+
})
|
|
58
|
+
);
|
|
59
|
+
}
|
|
62
60
|
}
|
|
63
|
-
|
|
64
|
-
const matchedRule = attr[0].replace(/:/, "-");
|
|
65
|
-
if (matchedRule.includes("=") || isBlocked(matchedRule))
|
|
66
|
-
continue;
|
|
67
|
-
const updatedMatchedRule = matchedRule.startsWith(attributifyPrefix) ? matchedRule.slice(attributifyPrefix.length) : matchedRule;
|
|
68
|
-
tasks.push(uno.parseToken(updatedMatchedRule).then((matched) => {
|
|
69
|
-
if (matched) {
|
|
70
|
-
const startIdx = (item.index || 0) + (attr.index || 0) + item[0].indexOf(item[2]);
|
|
71
|
-
const endIdx = startIdx + matchedRule.length;
|
|
72
|
-
code.overwrite(startIdx, endIdx, `${matchedRule}=""`);
|
|
73
|
-
}
|
|
74
|
-
}));
|
|
75
|
-
}
|
|
76
|
-
}
|
|
61
|
+
});
|
|
77
62
|
await Promise.all(tasks);
|
|
78
63
|
}
|
|
79
64
|
};
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@unocss/transformer-attributify-jsx",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "66.
|
|
4
|
+
"version": "66.4.1",
|
|
5
5
|
"description": "Support valueless attributify in JSX/TSX.",
|
|
6
6
|
"author": "Anthony Fu <anthonyfu117@hotmail.com>",
|
|
7
7
|
"license": "MIT",
|
|
@@ -33,7 +33,9 @@
|
|
|
33
33
|
"dist"
|
|
34
34
|
],
|
|
35
35
|
"dependencies": {
|
|
36
|
-
"@
|
|
36
|
+
"@babel/parser": "^7.28.0",
|
|
37
|
+
"@babel/traverse": "^7.28.0",
|
|
38
|
+
"@unocss/core": "66.4.1"
|
|
37
39
|
},
|
|
38
40
|
"devDependencies": {
|
|
39
41
|
"magic-string": "^0.30.17"
|