Skip to content

Commit 20d9ca3

Browse files
authored
Merge branch 'vuejs:main' into bwsy/fix/modelvalue
2 parents b956d94 + 9768949 commit 20d9ca3

File tree

7 files changed

+80
-6
lines changed

7 files changed

+80
-6
lines changed

packages/compiler-core/__tests__/transforms/vOn.spec.ts

+15
Original file line numberDiff line numberDiff line change
@@ -271,6 +271,21 @@ describe('compiler: transform v-on', () => {
271271
})
272272
})
273273

274+
test('should NOT wrap as function if expression is already function expression (with Typescript)', () => {
275+
const { node } = parseWithVOn(`<div @click="(e: any): any => foo(e)"/>`)
276+
expect((node.codegenNode as VNodeCall).props).toMatchObject({
277+
properties: [
278+
{
279+
key: { content: `onClick` },
280+
value: {
281+
type: NodeTypes.SIMPLE_EXPRESSION,
282+
content: `(e: any): any => foo(e)`
283+
}
284+
}
285+
]
286+
})
287+
})
288+
274289
test('should NOT wrap as function if expression is already function expression (with newlines)', () => {
275290
const { node } = parseWithVOn(
276291
`<div @click="

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ import { hasScopeRef, isMemberExpression } from '../utils'
1717
import { TO_HANDLER_KEY } from '../runtimeHelpers'
1818

1919
const fnExpRE =
20-
/^\s*([\w$_]+|(async\s*)?\([^)]*?\))\s*=>|^\s*(async\s+)?function(?:\s+[\w$]+)?\s*\(/
20+
/^\s*([\w$_]+|(async\s*)?\([^)]*?\))\s*(:[^=]+)?=>|^\s*(async\s+)?function(?:\s+[\w$]+)?\s*\(/
2121

2222
export interface VOnDirectiveNode extends DirectiveNode {
2323
// v-on without arg is handled directly in ./transformElements.ts due to it affecting

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

+17
Original file line numberDiff line numberDiff line change
@@ -720,6 +720,23 @@ return { props, a, emit }
720720
}"
721721
`;
722722

723+
exports[`SFC compile <script setup> defineProps/defineEmits in multi-variable declaration fix #6757 1`] = `
724+
"export default {
725+
props: ['item'],
726+
emits: ['a'],
727+
setup(__props, { expose, emit }) {
728+
expose();
729+
730+
const props = __props
731+
732+
const a = 1;
733+
734+
return { a, props, emit }
735+
}
736+
737+
}"
738+
`;
739+
723740
exports[`SFC compile <script setup> dev mode import usage check TS annotations 1`] = `
724741
"import { defineComponent as _defineComponent } from 'vue'
725742
import { Foo, Bar, Baz, Qux, Fred } from './x'

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

+15
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,21 @@ const myEmit = defineEmits(['foo', 'bar'])
141141
expect(content).toMatch(`emits: ['a'],`)
142142
})
143143

144+
// #6757
145+
test('defineProps/defineEmits in multi-variable declaration fix #6757 ', () => {
146+
const { content } = compile(`
147+
<script setup>
148+
const a = 1,
149+
props = defineProps(['item']),
150+
emit = defineEmits(['a']);
151+
</script>
152+
`)
153+
assertCode(content)
154+
expect(content).toMatch(`const a = 1;`) // test correct removal
155+
expect(content).toMatch(`props: ['item'],`)
156+
expect(content).toMatch(`emits: ['a'],`)
157+
})
158+
144159
test('defineProps/defineEmits in multi-variable declaration (full removal)', () => {
145160
const { content } = compile(`
146161
<script setup>

packages/compiler-sfc/src/compileScript.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -1177,11 +1177,11 @@ export function compileScript(
11771177
} else {
11781178
let start = decl.start! + startOffset
11791179
let end = decl.end! + startOffset
1180-
if (i < total - 1) {
1181-
// not the last one, locate the start of the next
1180+
if (i === 0) {
1181+
// first one, locate the start of the next
11821182
end = node.declarations[i + 1].start! + startOffset
11831183
} else {
1184-
// last one, locate the end of the prev
1184+
// not first one, locate the end of the prev
11851185
start = node.declarations[i - 1].end! + startOffset
11861186
}
11871187
s.remove(start, end)

packages/shared/__tests__/normalizeProp.spec.ts

+28-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { normalizeClass } from '../src'
1+
import { normalizeClass, parseStringStyle } from '../src'
22

33
describe('normalizeClass', () => {
44
test('handles string correctly', () => {
@@ -16,4 +16,31 @@ describe('normalizeClass', () => {
1616
'foo baz'
1717
)
1818
})
19+
20+
// #6777
21+
test('parse multi-line inline style', () => {
22+
expect(
23+
parseStringStyle(`border: 1px solid transparent;
24+
background: linear-gradient(white, white) padding-box,
25+
repeating-linear-gradient(
26+
-45deg,
27+
#ccc 0,
28+
#ccc 0.5em,
29+
white 0,
30+
white 0.75em
31+
);`)
32+
).toMatchInlineSnapshot(`
33+
Object {
34+
"background": "linear-gradient(white, white) padding-box,
35+
repeating-linear-gradient(
36+
-45deg,
37+
#ccc 0,
38+
#ccc 0.5em,
39+
white 0,
40+
white 0.75em
41+
)",
42+
"border": "1px solid transparent",
43+
}
44+
`)
45+
})
1946
})

packages/shared/src/normalizeProp.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ export function normalizeStyle(
2727
}
2828

2929
const listDelimiterRE = /;(?![^(]*\))/g
30-
const propertyDelimiterRE = /:(.+)/
30+
const propertyDelimiterRE = /:([^]+)/
3131

3232
export function parseStringStyle(cssText: string): NormalizedStyle {
3333
const ret: NormalizedStyle = {}

0 commit comments

Comments
 (0)