-
Notifications
You must be signed in to change notification settings - Fork 353
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: generate code accessor scenario
修复 state accessor 出码的bug
- Loading branch information
1 parent
7f05029
commit d040e6b
Showing
4 changed files
with
196 additions
and
2 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
11 changes: 11 additions & 0 deletions
11
packages/vue-generator/test/testcases/sfc/accessor/accessor.test.js
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,11 @@ | ||
import { expect, test } from 'vitest' | ||
import { genSFCWithDefaultPlugin } from '@/generator/vue/sfc' | ||
import schema from './schema.json' | ||
import { formatCode } from '@/utils/formatCode' | ||
|
||
test('should validate tagName', async () => { | ||
const res = genSFCWithDefaultPlugin(schema, []) | ||
const formattedCode = formatCode(res, 'vue') | ||
|
||
await expect(formattedCode).toMatchFileSnapshot('./expected/Accessor.vue') | ||
}) |
69 changes: 69 additions & 0 deletions
69
packages/vue-generator/test/testcases/sfc/accessor/expected/Accessor.vue
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,69 @@ | ||
<template> | ||
<div> | ||
<span class="page-header">测试 state accessor 出码场景</span> | ||
</div> | ||
</template> | ||
|
||
<script setup> | ||
import * as vue from 'vue' | ||
import { defineProps, defineEmits } from 'vue' | ||
import { I18nInjectionKey } from 'vue-i18n' | ||
const props = defineProps({}) | ||
const emit = defineEmits([]) | ||
const { t, lowcodeWrap, stores } = vue.inject(I18nInjectionKey).lowcode() | ||
const wrap = lowcodeWrap(props, { emit }) | ||
wrap({ stores }) | ||
const state = vue.reactive({ | ||
firstName: 'Opentiny', | ||
lastName: 'TinyEngine', | ||
nullValue: null, | ||
numberValue: 0, | ||
emptyStr: '', | ||
strVal: 'i am str.', | ||
trueVal: true, | ||
falseVal: false, | ||
arrVal: [1, '2', { aaa: 'aaa' }, [3, 4], true, false], | ||
objVal: { aaa: 'aaa', arr: [1, '2', true, false, 0], ccc: { bbb: 'bbb' }, d: 32432, e: '', f: null, g: false } | ||
}) | ||
wrap({ state }) | ||
vue.watchEffect( | ||
wrap(function () { | ||
this.state.nullValue = `${this.state.firstName} ${this.state.lastName}` | ||
}) | ||
) | ||
vue.watchEffect( | ||
wrap(function () { | ||
this.state.numberValue = `${this.state.firstName} ${this.state.lastName}` | ||
}) | ||
) | ||
vue.watchEffect( | ||
wrap(function () { | ||
this.state.emptyStr = `${this.state.firstName} ${this.state.lastName}` | ||
}) | ||
) | ||
vue.watchEffect( | ||
wrap(function () { | ||
this.state.strVal = `${this.state.firstName} ${this.state.lastName}` | ||
}) | ||
) | ||
vue.watchEffect( | ||
wrap(function () { | ||
this.state.trueVal = `${this.state.firstName} ${this.state.lastName}` | ||
}) | ||
) | ||
vue.watchEffect( | ||
wrap(function () { | ||
this.state.falseVal = `${this.state.firstName} ${this.state.lastName}` | ||
}) | ||
) | ||
vue.watchEffect( | ||
wrap(function () { | ||
this.state.arrVal = `${this.state.firstName} ${this.state.lastName}` | ||
}) | ||
) | ||
</script> | ||
<style scoped></style> |
101 changes: 101 additions & 0 deletions
101
packages/vue-generator/test/testcases/sfc/accessor/schema.json
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,101 @@ | ||
{ | ||
"componentName": "Page", | ||
"fileName": "Accessor", | ||
"css": "", | ||
"props": {}, | ||
"children": [ | ||
{ | ||
"componentName": "Text", | ||
"props": { | ||
"className": "page-header", | ||
"text": "测试 state accessor 出码场景" | ||
} | ||
} | ||
], | ||
"state": { | ||
"firstName": "Opentiny", | ||
"lastName": "TinyEngine", | ||
"nullValue": { | ||
"defaultValue": null, | ||
"accessor": { | ||
"getter": { | ||
"type": "JSFunction", | ||
"value": "function() { this.state.nullValue = `${this.state.firstName} ${this.state.lastName}` }" | ||
} | ||
} | ||
}, | ||
"numberValue": { | ||
"defaultValue": 0, | ||
"accessor": { | ||
"getter": { | ||
"type": "JSFunction", | ||
"value": "function() { this.state.numberValue = `${this.state.firstName} ${this.state.lastName}` }" | ||
} | ||
} | ||
}, | ||
"emptyStr": { | ||
"defaultValue": "", | ||
"accessor": { | ||
"getter": { | ||
"type": "JSFunction", | ||
"value": "function() { this.state.emptyStr = `${this.state.firstName} ${this.state.lastName}` }" | ||
} | ||
} | ||
}, | ||
"strVal": { | ||
"defaultValue": "i am str.", | ||
"accessor": { | ||
"getter": { | ||
"type": "JSFunction", | ||
"value": "function() { this.state.strVal = `${this.state.firstName} ${this.state.lastName}` }" | ||
} | ||
} | ||
}, | ||
"trueVal": { | ||
"defaultValue": true, | ||
"accessor": { | ||
"getter": { | ||
"type": "JSFunction", | ||
"value": "function() { this.state.trueVal = `${this.state.firstName} ${this.state.lastName}` }" | ||
} | ||
} | ||
}, | ||
"falseVal": { | ||
"defaultValue": false, | ||
"accessor": { | ||
"getter": { | ||
"type": "JSFunction", | ||
"value": "function() { this.state.falseVal = `${this.state.firstName} ${this.state.lastName}` }" | ||
} | ||
} | ||
}, | ||
"arrVal": { | ||
"defaultValue": [1, "2", { "aaa": "aaa" }, [3, 4], true, false], | ||
"accessor": { | ||
"getter": { | ||
"type": "JSFunction", | ||
"value": "function() { this.state.arrVal = `${this.state.firstName} ${this.state.lastName}` }" | ||
} | ||
} | ||
}, | ||
"objVal": { | ||
"defaultValue": { | ||
"aaa": "aaa", | ||
"arr": [1, "2", true, false, 0], | ||
"ccc": { "bbb": "bbb" }, | ||
"d": 32432, | ||
"e": "", | ||
"f": null, | ||
"g": false | ||
}, | ||
"accessor": { | ||
"getter": { | ||
"type": "JSFunction", | ||
"value": "function() { this.state.falseVal = `${this.state.firstName} ${this.state.lastName}` }" | ||
} | ||
} | ||
} | ||
}, | ||
"lifeCycles": {}, | ||
"methods": {} | ||
} |