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(vue-script-setup-converter): If context is empty, do not replace #41

Merged
merged 1 commit into from
Sep 14, 2023
Merged
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
33 changes: 32 additions & 1 deletion packages/vue-script-setup-converter/src/lib/convertSrc.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -124,8 +124,39 @@ import { defineComponent, toRefs, computed } from 'vue';
type Props = { msg?: string; }; const props = withDefaults(defineProps<Props>(), { msg: 'HelloWorld' });

const { msg } = toRefs(props);
const newMsg = computed(() => msgvalue + '- HelloWorld');
const newMsg = computed(() => msg.value + '- HelloWorld');
`
);
});

it('props no toRefs', () => {
const output = convertSrc(`<script lang="ts">
import { defineComponent, computed } from 'vue';

export default defineComponent({
name: 'HelloWorld',
props: {
msg: {
type: String,
default: 'HelloWorld'
}
},
setup(props) {
const newMsg = computed(() => props.msg + '- HelloWorld');

return {
newMsg
}
}
})
</script>`);
expect(output).toBe(
`
import { defineComponent, computed } from 'vue';
type Props = { msg?: string; }; const props = withDefaults(defineProps<Props>(), { msg: 'HelloWorld' });

const newMsg = computed(() => props.msg + '- HelloWorld');
`
);
})
});
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,11 @@ export const convertSetup = (node: CallExpression) => {
return blockNode
.forEachChildAsArray()
.filter((x) => x.getKind() !== SyntaxKind.ReturnStatement)
.map((x) => replaceEmit(x.getFullText(), contextName))
.map((x) => {
if (!contextName) {
return x.getFullText();
}
return replaceEmit(x.getFullText(), contextName)
})
.join("");
};