Skip to content

Commit fd7213c

Browse files
committed
chore: init
1 parent 6b14c97 commit fd7213c

36 files changed

+2303
-1393
lines changed

.npmrc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
shamefully-hoist=true
1+
shamefully-hoist=true

LICENSE

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
MIT License
22

3-
Copyright (c) 2021-PRESENT Anthony Fu <https://github.com/zhiyuanzmj>
3+
Copyright (c) 2021-PRESENT zhiyuanzmj <https://github.com/zhiyuanzmj>
44

55
Permission is hereby granted, free of charge, to any person obtaining a copy
66
of this software and associated documentation files (the "Software"), to deal

README.md

Lines changed: 11 additions & 125 deletions
Original file line numberDiff line numberDiff line change
@@ -1,134 +1,20 @@
1-
# transformer-attributify-jsx-sg
1+
# vue-macros-sg
22

3-
<!-- @unocss-ignore -->
3+
vue-macros-sg is a cli for rewriting at vue macros powered by ast-grep.
44

5-
Support [valueless attributify](https://github.com/unocss/unocss/tree/main/packages/preset-attributify#valueless-attributify) in JSX/TSX. \
6-
Using [ast-grep](https://github.com/ast-grep/ast-grep) to match attributes, Thanks for [HerringtonDarkholme](https://github.com/HerringtonDarkholme).
5+
## Support vue macros
76

8-
### Benchmark
9-
`pnpm run bench`
10-
```
11-
Running "unocss concurrent transform jsx" suite...
12-
benchRegexTransform:
13-
16 ops/s, ±9.95% | fastest
14-
15-
benchAstGrepTransform:
16-
13 ops/s, ±0.34% | 18.75% slower
17-
18-
benchSwcTransform:
19-
6 ops/s, ±0.84% | 62.5% slower
20-
21-
benchBabelTransform:
22-
2 ops/s, ±1.44% | slowest, 87.5% slower
23-
```
7+
- [x] jsx-directive
8+
- [x] define-render
9+
- [x] export-render
10+
- [x] define-slots
11+
- [x] short-v-model
12+
- [x] setup-sfc
2413

2514
## Usage
2615

27-
```jsx
28-
export function Component() {
29-
return (
30-
<div text-red text-center text-5xl animate-bounce>
31-
unocss
32-
</div>
33-
)
34-
}
35-
```
36-
37-
Will be transformed to:
38-
39-
```jsx
40-
export function Component() {
41-
return (
42-
<div text-red="" text-center="" text-5xl="" animate-bounce="">
43-
unocss
44-
</div>
45-
)
46-
}
47-
```
48-
49-
<details>
50-
<summary>Without this transformer</summary>
51-
52-
JSX by default will treat valueless attributes as boolean attributes.
53-
54-
```jsx
55-
export function Component() {
56-
return (
57-
<div text-red={true} text-center={true} text-5xl={true} animate-bounce={true}>
58-
unocss
59-
</div>
60-
)
61-
}
62-
```
63-
64-
</details>
65-
66-
## Install
67-
68-
```bash
69-
npm i -D transformer-attributify-jsx-sg
70-
```
71-
72-
```ts
73-
// uno.config.ts
74-
import { defineConfig, presetAttributify } from 'unocss'
75-
import transformerAttributifyJsx from 'transformer-attributify-jsx-sg'
76-
77-
export default defineConfig({
78-
// ...
79-
presets: [
80-
// ...
81-
presetAttributify()
82-
],
83-
transformers: [
84-
transformerAttributifyJsx(), // <--
85-
],
86-
})
87-
```
88-
89-
## Caveats
90-
91-
If you encounter any issues with this package, there is [@unocss/transformer-attributify-jsx-babel](https://github.com/unocss/unocss/tree/main/packages/transformer-attributify-jsx-babel) package that uses Babel to transform JSX.
92-
93-
> ⚠️ The rules are almost the same as those of `preset-attributify`, but there are several precautions
94-
95-
```html
96-
<div translate-x-100% /> <!-- cannot end with `%` -->
97-
98-
<div translate-x-[100px] /> <!-- cannot contain `[` or `]` -->
99-
```
100-
101-
Instead, you may want to use valued attributes instead:
102-
103-
```html
104-
<div translate="x-100%" />
105-
106-
<div translate="x-[100px]" />
107-
```
108-
109-
## Blocklist
110-
111-
This transformer will only transform attributes that are valid UnoCSS utilities.
112-
You can also `blocklist` bypass some attributes from been transformed.
113-
114-
```js
115-
transformerAttributifyJsx({
116-
blocklist: [/text-[a-zA-Z]*/, 'text-5xl']
117-
})
118-
```
119-
120-
```jsx
121-
<div text-red text-center text-5xl animate-bounce>
122-
unocss
123-
</div>
124-
```
125-
126-
Will be compiled to:
127-
128-
```html
129-
<div text-red text-center text-5xl animate-bounce="">
130-
unocss
131-
</div>
16+
```shell
17+
npx vue-macros-sg ./src
13218
```
13319

13420
## License

ast-grep/rules/jsx-directive/v-bind.yml

Lines changed: 0 additions & 35 deletions
This file was deleted.

ast-grep/rules/jsx-directive/v-directive.yml

Lines changed: 0 additions & 20 deletions
This file was deleted.

ast-grep/rules/jsx-directive/v-on.yml

Lines changed: 0 additions & 53 deletions
This file was deleted.

ast-grep/rules/render/define-render.yml

Lines changed: 0 additions & 26 deletions
This file was deleted.

ast-grep/rules/render/export-render.yml

Lines changed: 0 additions & 26 deletions
This file was deleted.

ast-grep/utils/is-template.yml

Lines changed: 0 additions & 7 deletions
This file was deleted.

build.config.ts

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,18 @@ import { defineBuildConfig } from 'unbuild'
33
export default defineBuildConfig({
44
entries: [
55
'src/index',
6+
{
7+
builder: 'mkdist',
8+
input: './src',
9+
outDir: './dist',
10+
},
611
],
712
clean: true,
813
declaration: true,
9-
externals: [
10-
'magic-string',
11-
],
1214
rollup: {
13-
emitCJS: true,
15+
esbuild: {
16+
target: 'node16',
17+
},
18+
// emitCJS: true,
1419
},
1520
})

0 commit comments

Comments
 (0)