Skip to content

Commit

Permalink
fix: prevent process $$ | $
Browse files Browse the repository at this point in the history
  • Loading branch information
zhiyuanzmj committed Nov 8, 2023
1 parent b6a99d9 commit 0921bc8
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
4 changes: 2 additions & 2 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -100,15 +100,15 @@ function transformReactivityFunction(code: string, id: string) {
if (node.type !== 'CallExpression') return

if (
/^\$(?!(\$|ref|computed|shallowRef|toRef|customRef|defineProp|defineProps|defineModels)?(\(|$))/.test(
/^\$(?!(\$|ref|computed|shallowRef|toRef|customRef|defineProp|defineProps|defineModels)?$)/.test(
s.sliceNode(node.callee, { offset })
)
) {
s.appendRight(node.callee.start! + offset + 1, '(')
s.appendRight(node.end! + offset, ')')
}

if (s.sliceNode(node.callee, { offset }).endsWith('$')) {
if (/(?<!^(\$)?)\$$/.test(s.sliceNode(node.callee, { offset }))) {
s.remove(node.callee.end! + offset - 1, node.callee.end! + offset)

node.arguments.forEach((argument) => {
Expand Down
4 changes: 2 additions & 2 deletions src/volar.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ function transform({
) {
if (ts.isCallExpression(node)) {
if (
/^\$(?!(\$|ref|computed|shallowRef|toRef|customRef|defineProp|defineProps|defineModels)?(\(|$))/.test(
/^\$(?!(\$|ref|computed|shallowRef|toRef|customRef|defineProp|defineProps|defineModels)?$)/.test(
node.expression.getText(ast)
)
) {
Expand All @@ -111,7 +111,7 @@ function transform({
replaceSourceRange(codes, source, node.getEnd(), node.getEnd(), ')')
}

if (node.expression.getText(ast).endsWith('$')) {
if (/(?<!^(\$)?)\$$/.test(node.expression.getText(ast))) {
replaceSourceRange(
codes,
source,
Expand Down

0 comments on commit 0921bc8

Please sign in to comment.