Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(compiler-sfc): ref sugar work with destructuring + arrow function #3584

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -693,6 +693,21 @@ return { a, b, test }
}"
`;

exports[`SFC compile <script setup> ref: syntax sugar work with destructuring + arrow function expression 1`] = `
"export default {
expose: [],
setup(__props) {

const {} = () => 1;
const {} = useSomthing(() => 1);
const {} = useSomthing(computed(() => 1));

return { }
}

}"
`;

exports[`SFC compile <script setup> should expose top level declarations 1`] = `
"import { x } from './x'

Expand Down
11 changes: 11 additions & 0 deletions packages/compiler-sfc/__tests__/compileScript.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -656,6 +656,17 @@ const emit = defineEmit(['a', 'b'])
})
})

test('work with destructuring + arrow function expression', () => {
const { content } = compile(`
<script setup>
ref: ({} = () => 1);
ref: ({} = useSomthing(() => 1));
ref: ({} = useSomthing(computed(() => 1)));
</script>
`)
assertCode(content)
})

test('multi ref declarations', () => {
const { content, bindings } = compile(`<script setup>
ref: a = 1, b = 2, c = {
Expand Down
7 changes: 4 additions & 3 deletions packages/compiler-sfc/src/compileScript.ts
Original file line number Diff line number Diff line change
Expand Up @@ -348,10 +348,11 @@ export function compileScript(
break
}
}
for (let i = left.end!; i > 0; i++) {
const char = source[i + startOffset]

for (let i = right.end! + startOffset; i > right.start!; i--) {
const char = source[i]
if (char === ')') {
s.remove(i + startOffset, i + startOffset + 1)
s.remove(i, i + 1)
break
}
}
Expand Down