Skip to content

Commit 309a08b

Browse files
committed
Merge branch 'main' into fix/rt-macro
# Conflicts: # packages/reactivity-transform/__tests__/__snapshots__/reactivityTransform.spec.ts.snap
2 parents 1d62c92 + bad3f3c commit 309a08b

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

41 files changed

+892
-303
lines changed

Diff for: .github/workflows/ci.yml

+10-10
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,10 @@ jobs:
1919
- name: Install pnpm
2020
uses: pnpm/action-setup@v2
2121

22-
- name: Set node version to 16
22+
- name: Set node version to 18
2323
uses: actions/setup-node@v3
2424
with:
25-
node-version: 16
25+
node-version: 18
2626
cache: 'pnpm'
2727

2828
- run: pnpm install
@@ -38,10 +38,10 @@ jobs:
3838
- name: Install pnpm
3939
uses: pnpm/action-setup@v2
4040

41-
- name: Set node version to 16
41+
- name: Set node version to 18
4242
uses: actions/setup-node@v3
4343
with:
44-
node-version: 16
44+
node-version: 18
4545
cache: 'pnpm'
4646

4747
- run: pnpm install
@@ -57,19 +57,19 @@ jobs:
5757
- name: Install pnpm
5858
uses: pnpm/action-setup@v2
5959

60-
- name: Set node version to 16
60+
- name: Set node version to 18
6161
uses: actions/setup-node@v3
6262
with:
63-
node-version: 16
63+
node-version: 18
6464
cache: 'pnpm'
6565

6666
- run: pnpm install
6767

6868
- name: Run eslint
6969
run: pnpm run lint
7070

71-
- name: Run prettier
72-
run: pnpm run format-check
71+
# - name: Run prettier
72+
# run: pnpm run format-check
7373

7474
- name: Run type declaration tests
7575
run: pnpm run test-dts
@@ -84,10 +84,10 @@ jobs:
8484
- name: Install pnpm
8585
uses: pnpm/action-setup@v2
8686

87-
- name: Set node version to 16
87+
- name: Set node version to 18
8888
uses: actions/setup-node@v3
8989
with:
90-
node-version: 16
90+
node-version: 18
9191
cache: 'pnpm'
9292

9393
- run: pnpm install

Diff for: .prettierignore

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
dist

Diff for: packages/compiler-core/__tests__/parse.spec.ts

+11
Original file line numberDiff line numberDiff line change
@@ -1980,6 +1980,17 @@ foo
19801980
expect(ast.children[2].type).toBe(NodeTypes.INTERPOLATION)
19811981
})
19821982

1983+
it('should NOT remove whitespaces w/ newline between interpolation and comment', () => {
1984+
const ast = parse(`<!-- foo --> \n {{msg}}`)
1985+
expect(ast.children.length).toBe(3)
1986+
expect(ast.children[0].type).toBe(NodeTypes.COMMENT)
1987+
expect(ast.children[1]).toMatchObject({
1988+
type: NodeTypes.TEXT,
1989+
content: ' '
1990+
})
1991+
expect(ast.children[2].type).toBe(NodeTypes.INTERPOLATION)
1992+
})
1993+
19831994
it('should NOT remove whitespaces w/o newline between elements', () => {
19841995
const ast = parse(`<div/> <div/> <div/>`)
19851996
expect(ast.children.length).toBe(5)

Diff for: packages/compiler-core/__tests__/transforms/vIf.spec.ts

+39
Original file line numberDiff line numberDiff line change
@@ -628,6 +628,24 @@ describe('compiler: v-if', () => {
628628
expect(branch1.props).toMatchObject(createObjectMatcher({ key: `[0]` }))
629629
})
630630

631+
// #6631
632+
test('avoid duplicate keys', () => {
633+
const {
634+
node: { codegenNode }
635+
} = parseWithIfTransform(`<div v-if="ok" key="custom_key" v-bind="obj"/>`)
636+
const branch1 = codegenNode.consequent as VNodeCall
637+
expect(branch1.props).toMatchObject({
638+
type: NodeTypes.JS_CALL_EXPRESSION,
639+
callee: MERGE_PROPS,
640+
arguments: [
641+
createObjectMatcher({
642+
key: 'custom_key'
643+
}),
644+
{ content: `obj` }
645+
]
646+
})
647+
})
648+
631649
test('with spaces between branches', () => {
632650
const {
633651
node: { codegenNode }
@@ -694,6 +712,27 @@ describe('compiler: v-if', () => {
694712
expect(b1.children[3].type).toBe(NodeTypes.ELEMENT)
695713
expect((b1.children[3] as ElementNode).tag).toBe(`p`)
696714
})
715+
716+
// #6843
717+
test('should parse correctly with comments: true in prod', () => {
718+
__DEV__ = false
719+
parseWithIfTransform(
720+
`
721+
<template v-if="ok">
722+
<!--comment1-->
723+
<div v-if="ok2">
724+
<!--comment2-->
725+
</div>
726+
<!--comment3-->
727+
<b v-else/>
728+
<!--comment4-->
729+
<p/>
730+
</template>
731+
`,
732+
{ comments: true }
733+
)
734+
__DEV__ = true
735+
})
697736
})
698737

699738
test('v-on with v-if', () => {

Diff for: 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="

Diff for: packages/compiler-core/src/parse.ts

+8-3
Original file line numberDiff line numberDiff line change
@@ -264,14 +264,19 @@ function parseChildren(
264264
const next = nodes[i + 1]
265265
// Remove if:
266266
// - the whitespace is the first or last node, or:
267-
// - (condense mode) the whitespace is adjacent to a comment, or:
267+
// - (condense mode) the whitespace is between twos comments, or:
268+
// - (condense mode) the whitespace is between comment and element, or:
268269
// - (condense mode) the whitespace is between two elements AND contains newline
269270
if (
270271
!prev ||
271272
!next ||
272273
(shouldCondense &&
273-
(prev.type === NodeTypes.COMMENT ||
274-
next.type === NodeTypes.COMMENT ||
274+
((prev.type === NodeTypes.COMMENT &&
275+
next.type === NodeTypes.COMMENT) ||
276+
(prev.type === NodeTypes.COMMENT &&
277+
next.type === NodeTypes.ELEMENT) ||
278+
(prev.type === NodeTypes.ELEMENT &&
279+
next.type === NodeTypes.COMMENT) ||
275280
(prev.type === NodeTypes.ELEMENT &&
276281
next.type === NodeTypes.ELEMENT &&
277282
/[\r\n]/.test(node.content))))

Diff for: packages/compiler-core/src/transforms/vIf.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -129,9 +129,9 @@ export function processIf(
129129
let i = siblings.indexOf(node)
130130
while (i-- >= -1) {
131131
const sibling = siblings[i]
132-
if (__DEV__ && sibling && sibling.type === NodeTypes.COMMENT) {
132+
if (sibling && sibling.type === NodeTypes.COMMENT) {
133133
context.removeNode(sibling)
134-
comments.unshift(sibling)
134+
__DEV__ && comments.unshift(sibling)
135135
continue
136136
}
137137

Diff for: 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

Diff for: packages/compiler-core/src/utils.ts

+19-12
Original file line numberDiff line numberDiff line change
@@ -397,7 +397,10 @@ export function injectProp(
397397
// if doesn't override user provided keys
398398
const first = props.arguments[0] as string | JSChildNode
399399
if (!isString(first) && first.type === NodeTypes.JS_OBJECT_EXPRESSION) {
400-
first.properties.unshift(prop)
400+
// #6631
401+
if (!hasProp(prop, first)) {
402+
first.properties.unshift(prop)
403+
}
401404
} else {
402405
if (props.callee === TO_HANDLERS) {
403406
// #2366
@@ -411,17 +414,7 @@ export function injectProp(
411414
}
412415
!propsWithInjection && (propsWithInjection = props)
413416
} else if (props.type === NodeTypes.JS_OBJECT_EXPRESSION) {
414-
let alreadyExists = false
415-
// check existing key to avoid overriding user provided keys
416-
if (prop.key.type === NodeTypes.SIMPLE_EXPRESSION) {
417-
const propKeyName = prop.key.content
418-
alreadyExists = props.properties.some(
419-
p =>
420-
p.key.type === NodeTypes.SIMPLE_EXPRESSION &&
421-
p.key.content === propKeyName
422-
)
423-
}
424-
if (!alreadyExists) {
417+
if (!hasProp(prop, props)) {
425418
props.properties.unshift(prop)
426419
}
427420
propsWithInjection = props
@@ -453,6 +446,20 @@ export function injectProp(
453446
}
454447
}
455448

449+
// check existing key to avoid overriding user provided keys
450+
function hasProp(prop: Property, props: ObjectExpression) {
451+
let result = false
452+
if (prop.key.type === NodeTypes.SIMPLE_EXPRESSION) {
453+
const propKeyName = prop.key.content
454+
result = props.properties.some(
455+
p =>
456+
p.key.type === NodeTypes.SIMPLE_EXPRESSION &&
457+
p.key.content === propKeyName
458+
)
459+
}
460+
return result
461+
}
462+
456463
export function toValidAssetId(
457464
name: string,
458465
type: 'component' | 'directive' | 'filter'

0 commit comments

Comments
 (0)