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

feat(compiler-sfc): support props name to be defined as a string #7803

Merged
merged 55 commits into from
May 12, 2023
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
Show all changes
55 commits
Select commit Hold shift + click to select a range
508ef22
feat(compiler-sfc): Support props name to be defined as a string
baiwusanyu-c Feb 28, 2023
923afa9
feat(compiler-sfc): updated unit test
baiwusanyu-c Feb 28, 2023
75ec1a9
feat(compiler-sfc): updated unit test
baiwusanyu-c Feb 28, 2023
31b3866
feat(compiler-sfc): updated unit test
baiwusanyu-c Feb 28, 2023
fb9d9e1
fix(compiler-sfc): updated code
baiwusanyu-c Mar 1, 2023
ccb6ce6
fix(compiler-sfc): updated snap
baiwusanyu-c Mar 1, 2023
c2be9b0
fix(compiler-sfc): updated unit test
baiwusanyu-c Mar 1, 2023
9ebb189
fix(compiler-sfc): updated code
baiwusanyu-c Mar 1, 2023
1b49b5a
fix(compiler-sfc): updated code
baiwusanyu-c Mar 1, 2023
ec2468f
fix(compiler-sfc): updated code
baiwusanyu-c Mar 1, 2023
8de19c6
fix(compiler-sfc): updated code
baiwusanyu-c Mar 1, 2023
e6a4ac6
fix(compiler-sfc): updated code
baiwusanyu-c Mar 1, 2023
4d161b1
Update compileScript.spec.ts
baiwusanyu-c Mar 2, 2023
45b6e69
Update packages/compiler-sfc/src/compileScript.ts
baiwusanyu-c Mar 6, 2023
20293f6
Update packages/compiler-sfc/src/compileScript.ts
baiwusanyu-c Mar 6, 2023
c6f3142
fix(compiler-sfc): update code
baiwusanyu-c Mar 6, 2023
1bf1ebd
Update compileScript.spec.ts
baiwusanyu-c Mar 6, 2023
37a1e37
Update compileScript.spec.ts
baiwusanyu-c Mar 6, 2023
30f8611
chore: format
sxzz Mar 6, 2023
0325357
fix: escape string
sxzz Mar 6, 2023
dc30be7
Merge branch 'main' into bwsy/feat/propsKeyString
baiwusanyu-c Mar 17, 2023
bfe8a38
Merge branch 'main' into bwsy/feat/propsKeyString
baiwusanyu-c Mar 20, 2023
f876a98
Merge branch 'main' into bwsy/feat/propsKeyString
baiwusanyu-c Mar 23, 2023
1be11c5
Merge branch 'main' into bwsy/feat/propsKeyString
baiwusanyu-c Mar 24, 2023
a119029
Merge branch 'main' into bwsy/feat/propsKeyString
baiwusanyu-c Mar 27, 2023
fee10fc
Merge remote-tracking branch 'upstream/main' into bwsy/feat/propsKeyS…
baiwusanyu-c Mar 28, 2023
147c1f7
Merge remote-tracking branch 'upstream/main' into bwsy/feat/propsKeyS…
baiwusanyu-c Mar 29, 2023
86c498e
Merge remote-tracking branch 'upstream/main' into bwsy/feat/propsKeyS…
baiwusanyu-c Mar 30, 2023
803e1bd
Merge remote-tracking branch 'upstream/main' into bwsy/feat/propsKeyS…
baiwusanyu-c Mar 30, 2023
44a3e5e
Merge remote-tracking branch 'origin/main' into bwsy/feat/propsKeyString
baiwusanyu-c Apr 5, 2023
1d7372d
update code
baiwusanyu-c Apr 5, 2023
9ee8357
Merge branch 'main' into bwsy/feat/propsKeyString
baiwusanyu-c Apr 6, 2023
0c8dc97
Merge branch 'main' into bwsy/feat/propsKeyString
baiwusanyu-c Apr 6, 2023
f805d20
Merge remote-tracking branch 'upstream/main' into bwsy/feat/propsKeyS…
baiwusanyu-c Apr 10, 2023
555ccf8
update code
baiwusanyu-c Apr 10, 2023
06a96ad
Merge remote-tracking branch 'upstream/main' into bwsy/feat/propsKeyS…
baiwusanyu-c Apr 11, 2023
e94c908
Merge remote-tracking branch 'upstream/main' into bwsy/feat/propsKeyS…
baiwusanyu-c Apr 11, 2023
9c56547
update code
baiwusanyu-c Apr 11, 2023
97bccd2
Merge remote-tracking branch 'upstream/main' into bwsy/feat/propsKeyS…
baiwusanyu-c Apr 14, 2023
0ef564f
update snap and update code
baiwusanyu-c Apr 14, 2023
7404e27
Merge remote-tracking branch 'upstream/main' into bwsy/feat/propsKeyS…
baiwusanyu-c Apr 17, 2023
31afc2f
Merge branch 'main' into bwsy/feat/propsKeyString
baiwusanyu-c Apr 19, 2023
863f908
Merge branch 'main' into bwsy/feat/propsKeyString
baiwusanyu-c Apr 20, 2023
0d99c36
Merge branch 'main' into bwsy/feat/propsKeyString
baiwusanyu-c Apr 20, 2023
cd4e263
Merge branch 'main' into bwsy/feat/propsKeyString
baiwusanyu-c Apr 21, 2023
d142721
Merge branch 'main' into bwsy/feat/propsKeyString
baiwusanyu-c Apr 25, 2023
8bf16b2
Merge branch 'main' into bwsy/feat/propsKeyString
baiwusanyu-c May 4, 2023
b2cb327
Merge branch 'main' into bwsy/feat/propsKeyString
baiwusanyu-c May 6, 2023
1420088
Merge branch 'main' into bwsy/feat/propsKeyString
baiwusanyu-c May 6, 2023
4024023
Merge branch 'main' into bwsy/feat/propsKeyString
baiwusanyu-c May 8, 2023
674c6fd
Merge branch 'main' into bwsy/feat/propsKeyString
baiwusanyu-c May 8, 2023
aa409bc
Merge branch 'main' into bwsy/feat/propsKeyString
baiwusanyu-c May 9, 2023
0699b51
Merge branch 'main' into bwsy/feat/propsKeyString
baiwusanyu-c May 12, 2023
00c2fdd
Merge branch 'main' into bwsy/feat/propsKeyString
baiwusanyu-c May 12, 2023
ec0924a
Update cssVars.ts
baiwusanyu-c May 12, 2023
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 @@ -96,6 +96,23 @@ return () => {}
}"
`;

exports[`sfc props transform > default values w/ type declaration & key is string 1`] = `
"import { defineComponent as _defineComponent } from 'vue'

export default /*#__PURE__*/_defineComponent({
props: {
foo: { type: Number, required: true, default: 1 }
},
setup(__props: any) {



return () => {}
}

})"
`;

exports[`sfc props transform > default values w/ type declaration 1`] = `
"import { defineComponent as _defineComponent } from 'vue'

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,20 @@ describe('sfc props transform', () => {
assertCode(content)
})

test('default values w/ type declaration & key is string', () => {
const { content , bindings} = compile(`
baiwusanyu-c marked this conversation as resolved.
Show resolved Hide resolved
<script setup lang="ts">
const { foo = 1 } = defineProps<{ "foo": number }>()
</script>
`)
expect(bindings).toMatchObject({foo:'props'})
baiwusanyu-c marked this conversation as resolved.
Show resolved Hide resolved
expect(content).toMatch(`
props: {
foo: { type: Number, required: true, default: 1 }
},`)
assertCode(content)
baiwusanyu-c marked this conversation as resolved.
Show resolved Hide resolved
})

test('default values w/ type declaration, prod mode', () => {
const { content } = compile(
`
Expand Down
15 changes: 10 additions & 5 deletions packages/compiler-sfc/src/compileScript.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1889,17 +1889,22 @@ function extractRuntimeProps(
const members = node.type === 'TSTypeLiteral' ? node.members : node.body
for (const m of members) {
if (
(m.type === 'TSPropertySignature' || m.type === 'TSMethodSignature') &&
m.key.type === 'Identifier'
(m.type === 'TSPropertySignature' || m.type === 'TSMethodSignature') &&
(m.key.type === 'Identifier' || m.key.type === 'StringLiteral')
) {
let type
let type, keyName;
if(m.key.type === 'StringLiteral'){
keyName = m.key.value
} else {
keyName = m.key.name
}
baiwusanyu-c marked this conversation as resolved.
Show resolved Hide resolved
if (m.type === 'TSMethodSignature') {
type = ['Function']
} else if (m.typeAnnotation) {
type = inferRuntimeType(m.typeAnnotation.typeAnnotation, declaredTypes)
}
props[m.key.name] = {
key: m.key.name,
props[keyName] = {
key: keyName,
required: !m.optional,
type: type || [`null`]
}
baiwusanyu-c marked this conversation as resolved.
Show resolved Hide resolved
Expand Down