-
-
Notifications
You must be signed in to change notification settings - Fork 102
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(jsx-directive): add
v-on
directive with object syntax (#578)
- Loading branch information
1 parent
3915dbf
commit ac5494c
Showing
19 changed files
with
619 additions
and
475 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
--- | ||
'@vue-macros/jsx-directive': minor | ||
'@vue-macros/volar': minor | ||
--- | ||
|
||
add `v-on` directive with object syntax |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import { HELPER_PREFIX, type MagicString } from '@vue-macros/common' | ||
import type { JsxDirectiveNode } from '.' | ||
|
||
export function transformVOn( | ||
nodes: JsxDirectiveNode[], | ||
s: MagicString, | ||
offset: number, | ||
version: number, | ||
) { | ||
if (nodes.length > 0 && version >= 3) | ||
s.prependRight( | ||
offset, | ||
`const ${HELPER_PREFIX}transformVOn = (obj) => Object.entries(obj).reduce((res, [key, value]) => (res['on' + key[0].toUpperCase() + key.slice(1)] = value, res), {})`, | ||
) | ||
|
||
nodes.forEach(({ attribute }) => { | ||
if (version < 3) { | ||
s.remove(attribute.start! + offset, attribute.start! + offset + 2) | ||
return | ||
} | ||
|
||
s.overwriteNode( | ||
attribute, | ||
`{...${HELPER_PREFIX}transformVOn(${s.slice( | ||
attribute.value!.start! + offset + 1, | ||
attribute.value!.end! + offset - 1, | ||
)})}`, | ||
{ offset }, | ||
) | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.