From 028e4af11c4cfae472cc27d75e3d7bece7efabab Mon Sep 17 00:00:00 2001 From: gaokefei <260480378@qq.com> Date: Sat, 23 Dec 2023 18:02:39 +0800 Subject: [PATCH 1/4] feat(sg): convert dot to underline --- eslint.config.js | 1 + playground/src/App.vue | 2 ++ src/sg/index.ts | 1 + src/sg/rules/jsx-directive/v-directive.yml | 26 ++++++++++++++-------- 4 files changed, 21 insertions(+), 9 deletions(-) diff --git a/eslint.config.js b/eslint.config.js index 44c1011..bc5e25f 100644 --- a/eslint.config.js +++ b/eslint.config.js @@ -18,5 +18,6 @@ export default antfu( 'yaml/indent': 'off', }, }, + ignores: ['**/playground/**'], }, ) diff --git a/playground/src/App.vue b/playground/src/App.vue index 21393c9..123449d 100644 --- a/playground/src/App.vue +++ b/playground/src/App.vue @@ -20,6 +20,8 @@ const compRef = shallowRef() v-loading.fullscreen.lock="true" v-memo="[select?.id === i.id]" v-on="on" + v-on:click="alert" + @sub-mit.prevent @click.once="select = i" @submit="alert" @update:model-value="select.id = $event" diff --git a/src/sg/index.ts b/src/sg/index.ts index 95f5c00..2edf8e1 100644 --- a/src/sg/index.ts +++ b/src/sg/index.ts @@ -65,6 +65,7 @@ export async function sg(target: string) { if (['setup-sfc', 'define-render', 'export-render'].includes(macro)) { await $`${sg} scan -c ${config}.yml -U --filter '^self-closing-tag' ${target}` + await $`${sg} scan -c ${config}.yml -U --filter '^dot-to-underline' ${target}` await $`${sg} scan -c ${config}.yml -U --filter '^v-' ${target}` await $`${sg} scan -c ${config}.yml -U --filter '^${macro === 'setup-sfc' ? 'export-render' : macro}' ${target}` await useTsx(async () => { diff --git a/src/sg/rules/jsx-directive/v-directive.yml b/src/sg/rules/jsx-directive/v-directive.yml index 06486cf..e3a6218 100644 --- a/src/sg/rules/jsx-directive/v-directive.yml +++ b/src/sg/rules/jsx-directive/v-directive.yml @@ -1,17 +1,25 @@ id: v-directive language: html rule: - kind: attribute + kind: quoted_attribute_value has: + kind: attribute_value + pattern: $V + follows: kind: attribute_name pattern: $NAME - regex: ^v- - precedes: - kind: quoted_attribute_value - has: - kind: attribute_value - pattern: $V - stopBy: end + regex: ^v-|@ + stopBy: end +fix: |- + {$V} + +--- + +id: dot-to-underline +language: html +rule: + kind: attribute_name + pattern: $NAME transform: K: replace: @@ -19,4 +27,4 @@ transform: by: _ source: $NAME fix: |- - $K={$V} + $K From 4ad9daaa165989d81aa4666e21f5a2b0286b670b Mon Sep 17 00:00:00 2001 From: gaokefei <260480378@qq.com> Date: Sat, 23 Dec 2023 18:12:43 +0800 Subject: [PATCH 2/4] feat(sg): remove transform v-on --- src/sg/rules/jsx-directive/v-on.yml | 46 ++++++----------------------- 1 file changed, 9 insertions(+), 37 deletions(-) diff --git a/src/sg/rules/jsx-directive/v-on.yml b/src/sg/rules/jsx-directive/v-on.yml index 97aa4f9..bfe6cfd 100644 --- a/src/sg/rules/jsx-directive/v-on.yml +++ b/src/sg/rules/jsx-directive/v-on.yml @@ -1,48 +1,20 @@ -id: v-on shorthand +id: v-on language: html rule: - kind: attribute - has: - kind: attribute_name - regex: ^@ - pattern: $NAME - precedes: - kind: quoted_attribute_value - has: - kind: attribute_value - pattern: $V - stopBy: end + kind: attribute_name + regex: '^@|v-on:' + pattern: $NAME transform: B: - substring: - startChar: 1 - endChar: 2 + replace: + replace: '^@|v-on:' + by: '' source: $NAME C: convert: source: $B - toCase: upperCase - D: - substring: - startChar: 2 - source: $NAME - K: - replace: - replace: \. - by: _ - source: $D -fix: |- - on$C$K={$V} - ---- - -id: v-on to on -language: tsx -rule: - kind: property_identifier - regex: ^v-on$ -fix: - on + toCase: capitalize +fix: on$C --- From 89a0cf89b6191239c27776460ceb309e43deb67e Mon Sep 17 00:00:00 2001 From: gaokefei <260480378@qq.com> Date: Sat, 23 Dec 2023 18:35:17 +0800 Subject: [PATCH 3/4] feat: remove transform attributeName --- src/sg/rules/jsx-directive/pascal-case.yml | 30 +--------------------- 1 file changed, 1 insertion(+), 29 deletions(-) diff --git a/src/sg/rules/jsx-directive/pascal-case.yml b/src/sg/rules/jsx-directive/pascal-case.yml index e51b874..efca25c 100644 --- a/src/sg/rules/jsx-directive/pascal-case.yml +++ b/src/sg/rules/jsx-directive/pascal-case.yml @@ -15,32 +15,4 @@ transform: source: $A toCase: pascalCase separatedBy: [dash] -fix: - $B - ---- - -id: v-pascal-case for attributeName -language: tsx -rule: - any: - - kind: property_identifier - pattern: $A - regex: ^[^v]- - - kind: identifier - pattern: $A - regex: '-' - follows: - kind: identifier - stopBy: end - inside: - kind: jsx_namespace_name - -transform: - B: - convert: - source: $A - toCase: camelCase - separatedBy: [dash] -fix: - $B +fix: $B From a8f0fa804224467a315e60a1a8c994114dae35ff Mon Sep 17 00:00:00 2001 From: gaokefei <260480378@qq.com> Date: Sat, 23 Dec 2023 18:55:07 +0800 Subject: [PATCH 4/4] chore: release v1.2.1 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 0788b20..cfadc6b 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "@vue-macros/cli", "type": "module", - "version": "1.2.0", + "version": "1.2.1", "packageManager": "pnpm@8.10.5", "description": "Rewriting at vue macros powered by ast-grep.", "author": "zhiyuanzmj ",