Skip to content

Commit ec7ff38

Browse files
authored
Merge branch 'main' into edison/fix/12241
2 parents 759d5b4 + 9fa787c commit ec7ff38

File tree

17 files changed

+640
-398
lines changed

17 files changed

+640
-398
lines changed

.github/workflows/test.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,5 +104,8 @@ jobs:
104104
- name: Run prettier
105105
run: pnpm run format-check
106106

107+
- name: Run tsc
108+
run: pnpm run check
109+
107110
- name: Run type declaration tests
108111
run: pnpm run test-dts

package.json

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"private": true,
33
"version": "3.5.14",
4-
"packageManager": "pnpm@10.9.0",
4+
"packageManager": "pnpm@10.11.0",
55
"type": "module",
66
"scripts": {
77
"dev": "node scripts/dev.js",
@@ -71,21 +71,21 @@
7171
"@rollup/plugin-replace": "5.0.4",
7272
"@swc/core": "^1.11.24",
7373
"@types/hash-sum": "^1.0.2",
74-
"@types/node": "^22.14.1",
74+
"@types/node": "^22.15.21",
7575
"@types/semver": "^7.7.0",
7676
"@types/serve-handler": "^6.1.4",
77-
"@vitest/coverage-v8": "^3.1.3",
78-
"@vitest/eslint-plugin": "^1.1.44",
77+
"@vitest/coverage-v8": "^3.1.4",
78+
"@vitest/eslint-plugin": "^1.2.0",
7979
"@vue/consolidate": "1.0.0",
8080
"conventional-changelog-cli": "^5.0.0",
8181
"enquirer": "^2.4.1",
8282
"esbuild": "^0.25.4",
8383
"esbuild-plugin-polyfill-node": "^0.3.0",
84-
"eslint": "^9.25.1",
85-
"eslint-plugin-import-x": "^4.11.0",
84+
"eslint": "^9.27.0",
85+
"eslint-plugin-import-x": "^4.12.2",
8686
"estree-walker": "catalog:",
8787
"jsdom": "^26.1.0",
88-
"lint-staged": "^15.5.1",
88+
"lint-staged": "^15.5.2",
8989
"lodash": "^4.17.21",
9090
"magic-string": "^0.30.17",
9191
"markdown-table": "^3.0.4",
@@ -95,21 +95,21 @@
9595
"prettier": "^3.5.3",
9696
"pretty-bytes": "^6.1.1",
9797
"pug": "^3.0.3",
98-
"puppeteer": "~24.8.2",
98+
"puppeteer": "~24.9.0",
9999
"rimraf": "^6.0.1",
100-
"rollup": "^4.40.2",
100+
"rollup": "^4.41.0",
101101
"rollup-plugin-dts": "^6.2.1",
102102
"rollup-plugin-esbuild": "^6.2.1",
103103
"rollup-plugin-polyfill-node": "^0.13.0",
104-
"semver": "^7.7.1",
104+
"semver": "^7.7.2",
105105
"serve": "^14.2.4",
106106
"serve-handler": "^6.1.6",
107107
"simple-git-hooks": "^2.13.0",
108108
"todomvc-app-css": "^2.4.3",
109109
"tslib": "^2.8.1",
110110
"typescript": "~5.6.2",
111-
"typescript-eslint": "^8.31.1",
111+
"typescript-eslint": "^8.32.1",
112112
"vite": "catalog:",
113-
"vitest": "^3.1.3"
113+
"vitest": "^3.1.4"
114114
}
115115
}

packages-private/dts-test/defineComponent.test-d.tsx

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,9 @@ import { type IsAny, type IsUnion, describe, expectType } from './utils'
2020
describe('with object props', () => {
2121
interface ExpectedProps {
2222
a?: number | undefined
23+
aa: number
24+
aaa: number | null
25+
aaaa: number | undefined
2326
b: string
2427
e?: Function
2528
h: boolean
@@ -53,6 +56,19 @@ describe('with object props', () => {
5356

5457
const props = {
5558
a: Number,
59+
aa: {
60+
type: Number as PropType<number | undefined>,
61+
default: 1,
62+
},
63+
aaa: {
64+
type: Number as PropType<number | null>,
65+
default: 1,
66+
},
67+
aaaa: {
68+
type: Number as PropType<number | undefined>,
69+
// `as const` prevents widening to `boolean` (keeps literal `true` type)
70+
required: true as const,
71+
},
5672
// required should make property non-void
5773
b: {
5874
type: String,
@@ -146,6 +162,13 @@ describe('with object props', () => {
146162
setup(props) {
147163
// type assertion. See https://github.com/SamVerschueren/tsd
148164
expectType<ExpectedProps['a']>(props.a)
165+
expectType<ExpectedProps['aa']>(props.aa)
166+
expectType<ExpectedProps['aaa']>(props.aaa)
167+
168+
// @ts-expect-error should included `undefined`
169+
expectType<number>(props.aaaa)
170+
expectType<ExpectedProps['aaaa']>(props.aaaa)
171+
149172
expectType<ExpectedProps['b']>(props.b)
150173
expectType<ExpectedProps['e']>(props.e)
151174
expectType<ExpectedProps['h']>(props.h)
@@ -198,6 +221,8 @@ describe('with object props', () => {
198221
render() {
199222
const props = this.$props
200223
expectType<ExpectedProps['a']>(props.a)
224+
expectType<ExpectedProps['aa']>(props.aa)
225+
expectType<ExpectedProps['aaa']>(props.aaa)
201226
expectType<ExpectedProps['b']>(props.b)
202227
expectType<ExpectedProps['e']>(props.e)
203228
expectType<ExpectedProps['h']>(props.h)
@@ -225,6 +250,8 @@ describe('with object props', () => {
225250

226251
// should also expose declared props on `this`
227252
expectType<ExpectedProps['a']>(this.a)
253+
expectType<ExpectedProps['aa']>(this.aa)
254+
expectType<ExpectedProps['aaa']>(this.aaa)
228255
expectType<ExpectedProps['b']>(this.b)
229256
expectType<ExpectedProps['e']>(this.e)
230257
expectType<ExpectedProps['h']>(this.h)
@@ -269,6 +296,7 @@ describe('with object props', () => {
269296
expectType<JSX.Element>(
270297
<MyComponent
271298
a={1}
299+
aaaa={1}
272300
b="b"
273301
bb="bb"
274302
e={() => {}}
@@ -295,6 +323,7 @@ describe('with object props', () => {
295323

296324
expectType<Component>(
297325
<MyComponent
326+
aaaa={1}
298327
b="b"
299328
dd={{ n: 1 }}
300329
ddd={['ddd']}

packages/compiler-core/src/transforms/transformElement.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -594,11 +594,9 @@ export function buildProps(
594594
hasDynamicKeys = true
595595
if (exp) {
596596
if (isVBind) {
597-
// #10696 in case a v-bind object contains ref
598-
pushRefVForMarker()
599-
// have to merge early for compat build check
600-
pushMergeArg()
601597
if (__COMPAT__) {
598+
// have to merge early for compat build check
599+
pushMergeArg()
602600
// 2.x v-bind object order compat
603601
if (__DEV__) {
604602
const hasOverridableKeys = mergeArgs.some(arg => {
@@ -641,6 +639,9 @@ export function buildProps(
641639
}
642640
}
643641

642+
// #10696 in case a v-bind object contains ref
643+
pushRefVForMarker()
644+
pushMergeArg()
644645
mergeArgs.push(exp)
645646
} else {
646647
// v-on="obj" -> toHandlers(obj)

packages/compiler-sfc/__tests__/compileScript.spec.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1007,7 +1007,7 @@ describe('SFC compile <script setup>', () => {
10071007
expect(() =>
10081008
compile(`<script setup>
10091009
let bar = 1
1010-
defineModel({
1010+
const model = defineModel({
10111011
default: () => bar
10121012
})
10131013
</script>`),
@@ -1017,7 +1017,7 @@ describe('SFC compile <script setup>', () => {
10171017
expect(() =>
10181018
compile(`<script setup>
10191019
const bar = 1
1020-
defineModel({
1020+
const model = defineModel({
10211021
default: () => bar
10221022
})
10231023
</script>`),
@@ -1027,7 +1027,7 @@ describe('SFC compile <script setup>', () => {
10271027
expect(() =>
10281028
compile(`<script setup>
10291029
let bar = 1
1030-
defineModel({
1030+
const model = defineModel({
10311031
get: () => bar,
10321032
set: () => bar
10331033
})

packages/compiler-sfc/__tests__/compileScript/defineModel.spec.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -269,4 +269,16 @@ describe('defineModel()', () => {
269269
modelValue: BindingTypes.SETUP_REF,
270270
})
271271
})
272+
273+
test('error when defineModel is not assigned to a variable', () => {
274+
expect(() =>
275+
compile(`
276+
<script setup>
277+
defineModel()
278+
</script>
279+
`),
280+
).toThrow(
281+
'defineModel() must be assigned to a variable. For example: const model = defineModel()',
282+
)
283+
})
272284
})

packages/compiler-sfc/__tests__/compileStyle.spec.ts

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -529,7 +529,31 @@ describe('SFC style preprocessors', () => {
529529
}"
530530
`)
531531
expect(compileScoped(`.foo * { color: red; }`)).toMatchInlineSnapshot(`
532-
".foo[data-v-test] * { color: red;
532+
".foo[data-v-test] [data-v-test] { color: red;
533+
}"
534+
`)
535+
expect(compileScoped(`.foo :active { color: red; }`))
536+
.toMatchInlineSnapshot(`
537+
".foo[data-v-test] :active { color: red;
538+
}"
539+
`)
540+
expect(compileScoped(`.foo *:active { color: red; }`))
541+
.toMatchInlineSnapshot(`
542+
".foo[data-v-test] [data-v-test]:active { color: red;
543+
}"
544+
`)
545+
expect(compileScoped(`.foo * .bar { color: red; }`)).toMatchInlineSnapshot(`
546+
".foo * .bar[data-v-test] { color: red;
547+
}"
548+
`)
549+
expect(compileScoped(`:last-child * { color: red; }`))
550+
.toMatchInlineSnapshot(`
551+
"[data-v-test]:last-child [data-v-test] { color: red;
552+
}"
553+
`)
554+
expect(compileScoped(`:last-child *:active { color: red; }`))
555+
.toMatchInlineSnapshot(`
556+
"[data-v-test]:last-child [data-v-test]:active { color: red;
533557
}"
534558
`)
535559
})

packages/compiler-sfc/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,6 @@
6262
"postcss-modules": "^6.0.1",
6363
"postcss-selector-parser": "^7.1.0",
6464
"pug": "^3.0.3",
65-
"sass": "^1.86.3"
65+
"sass": "^1.89.0"
6666
}
6767
}

packages/compiler-sfc/src/compileScript.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1324,7 +1324,7 @@ export function mergeSourceMaps(
13241324
},
13251325
original: {
13261326
line: m.originalLine,
1327-
column: m.originalColumn,
1327+
column: m.originalColumn!,
13281328
},
13291329
source: m.source,
13301330
name: m.name,

packages/compiler-sfc/src/script/defineModel.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,13 @@ export function processDefineModel(
2222
return false
2323
}
2424

25+
if (!declId) {
26+
ctx.error(
27+
'defineModel() must be assigned to a variable. For example: const model = defineModel()',
28+
node,
29+
)
30+
}
31+
2532
ctx.hasDefineModelCall = true
2633

2734
const type =

packages/compiler-sfc/src/style/pluginScoped.ts

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,7 @@ function rewriteSelector(
102102
slotted = false,
103103
) {
104104
let node: selectorParser.Node | null = null
105+
let starNode: selectorParser.Node | null = null
105106
let shouldInject = !deep
106107
// find the last child node to insert attribute selector
107108
selector.each(n => {
@@ -216,12 +217,13 @@ function rewriteSelector(
216217
return false
217218
}
218219
}
219-
// .foo * -> .foo[xxxxxxx] *
220-
if (node) return
220+
// store the universal selector so it can be rewritten later
221+
// .foo * -> .foo[xxxxxxx] [xxxxxxx]
222+
starNode = n
221223
}
222224

223225
if (
224-
(n.type !== 'pseudo' && n.type !== 'combinator') ||
226+
(n.type !== 'pseudo' && n.type !== 'combinator' && n.type !== 'universal') ||
225227
(isPseudoClassIsOrWhere(n) &&
226228
(!node ||
227229
n.nodes.some(
@@ -233,6 +235,7 @@ function rewriteSelector(
233235
)))
234236
) {
235237
node = n
238+
starNode = null
236239
}
237240
})
238241

@@ -279,6 +282,20 @@ function rewriteSelector(
279282
quoteMark: `"`,
280283
}),
281284
)
285+
// Used for trailing universal selectors (#12906)
286+
// `.foo * {}` -> `.foo[xxxxxxx] [xxxxxxx] {}`
287+
if (starNode) {
288+
selector.insertBefore(
289+
starNode,
290+
selectorParser.attribute({
291+
attribute: idToAdd,
292+
value: idToAdd,
293+
raws: {},
294+
quoteMark: `"`,
295+
}),
296+
)
297+
selector.removeChild(starNode)
298+
}
282299
}
283300
}
284301

packages/runtime-core/src/componentProps.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,9 @@ type InferPropType<T, NullAsAny = true> = [T] extends [null]
143143
export type ExtractPropTypes<O> = {
144144
// use `keyof Pick<O, RequiredKeys<O>>` instead of `RequiredKeys<O>` to
145145
// support IDE features
146-
[K in keyof Pick<O, RequiredKeys<O>>]: InferPropType<O[K]>
146+
[K in keyof Pick<O, RequiredKeys<O>>]: O[K] extends { default: any }
147+
? Exclude<InferPropType<O[K]>, undefined>
148+
: InferPropType<O[K]>
147149
} & {
148150
// use `keyof Pick<O, OptionalKeys<O>>` instead of `OptionalKeys<O>` to
149151
// support IDE features

0 commit comments

Comments
 (0)