Skip to content

Commit 77f5d44

Browse files
authored
Merge branch 'vuejs:main' into fix-KeepAlive-Comments
2 parents aa98a88 + bdffc14 commit 77f5d44

File tree

34 files changed

+260
-103
lines changed

34 files changed

+260
-103
lines changed

CHANGELOG.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,16 @@
1+
## [3.2.37](https://github.com/vuejs/core/compare/v3.2.36...v3.2.37) (2022-06-06)
2+
3+
4+
### Bug Fixes
5+
6+
* **compiler-sfc:** improve css v-bind parsing ([e60244b](https://github.com/vuejs/core/commit/e60244bcdf0b386de1560ff7c205ae0870bab355)), closes [#6022](https://github.com/vuejs/core/issues/6022)
7+
* **runtime-core:** hydrate Static vnode ([#6015](https://github.com/vuejs/core/issues/6015)) ([11e17a1](https://github.com/vuejs/core/commit/11e17a1a29cf3d0b37628241d63ff3e8d8525f95)), closes [#6008](https://github.com/vuejs/core/issues/6008)
8+
* **sfc:** avoid auto name inference leading to unwanted recursion ([9734b31](https://github.com/vuejs/core/commit/9734b31c312244a2b5c5cf83c75d7b34076a0c4b)), closes [#5965](https://github.com/vuejs/core/issues/5965) [#6027](https://github.com/vuejs/core/issues/6027) [#6029](https://github.com/vuejs/core/issues/6029)
9+
* **ssr:** ensure app can be unmounted when created with createSSRApp() ([#5992](https://github.com/vuejs/core/issues/5992)) ([d4d3319](https://github.com/vuejs/core/commit/d4d3319c1be16dc9a046b2c5521096debc205f25)), closes [#5990](https://github.com/vuejs/core/issues/5990)
10+
* **ssr:** hydration for transition wrapper components with empty slot content ([#5995](https://github.com/vuejs/core/issues/5995)) ([eb22a62](https://github.com/vuejs/core/commit/eb22a62798d845a8756b0a73b68afdd874feda59)), closes [#5991](https://github.com/vuejs/core/issues/5991)
11+
12+
13+
114
## [3.2.36](https://github.com/vuejs/core/compare/v3.2.35...v3.2.36) (2022-05-23)
215

316

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"private": true,
3-
"version": "3.2.36",
3+
"version": "3.2.37",
44
"packageManager": "[email protected]",
55
"scripts": {
66
"dev": "node scripts/dev.js",

packages/compiler-core/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@vue/compiler-core",
3-
"version": "3.2.36",
3+
"version": "3.2.37",
44
"description": "@vue/compiler-core",
55
"main": "index.js",
66
"module": "dist/compiler-core.esm-bundler.js",
@@ -32,7 +32,7 @@
3232
},
3333
"homepage": "https://github.com/vuejs/core/tree/main/packages/compiler-core#readme",
3434
"dependencies": {
35-
"@vue/shared": "3.2.36",
35+
"@vue/shared": "3.2.37",
3636
"@babel/parser": "^7.16.4",
3737
"estree-walker": "^2.0.2",
3838
"source-map": "^0.6.1"

packages/compiler-dom/package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@vue/compiler-dom",
3-
"version": "3.2.36",
3+
"version": "3.2.37",
44
"description": "@vue/compiler-dom",
55
"main": "index.js",
66
"module": "dist/compiler-dom.esm-bundler.js",
@@ -37,7 +37,7 @@
3737
},
3838
"homepage": "https://github.com/vuejs/core/tree/main/packages/compiler-dom#readme",
3939
"dependencies": {
40-
"@vue/shared": "3.2.36",
41-
"@vue/compiler-core": "3.2.36"
40+
"@vue/shared": "3.2.37",
41+
"@vue/compiler-core": "3.2.37"
4242
}
4343
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
exports[`SFC analyze <script> bindings auto name inference basic 1`] = `
44
"export default {
5-
name: 'FooBar',
5+
__name: 'FooBar',
66
setup(__props, { expose }) {
77
expose();
88
const a = 1

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1650,7 +1650,7 @@ describe('SFC analyze <script> bindings', () => {
16501650
}
16511651
)
16521652
expect(content).toMatch(`export default {
1653-
name: 'FooBar'`)
1653+
__name: 'FooBar'`)
16541654
assertCode(content)
16551655
})
16561656

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

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { compileStyle } from '../src'
1+
import { compileStyle, parse } from '../src'
22
import { mockId, compileSFCScript, assertCode } from './utils'
33

44
describe('CSS vars injection', () => {
@@ -231,5 +231,21 @@ describe('CSS vars injection', () => {
231231
})`)
232232
assertCode(content)
233233
})
234+
235+
// #6022
236+
test('should be able to parse incomplete expressions', () => {
237+
const {
238+
descriptor: { cssVars }
239+
} = parse(
240+
`<script setup>let xxx = 1</script>
241+
<style scoped>
242+
label {
243+
font-weight: v-bind("count.toString(");
244+
font-weight: v-bind(xxx);
245+
}
246+
</style>`
247+
)
248+
expect(cssVars).toMatchObject([`count.toString(`, `xxx`])
249+
})
234250
})
235251
})

packages/compiler-sfc/package.json

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@vue/compiler-sfc",
3-
"version": "3.2.36",
3+
"version": "3.2.37",
44
"description": "@vue/compiler-sfc",
55
"main": "dist/compiler-sfc.cjs.js",
66
"module": "dist/compiler-sfc.esm-browser.js",
@@ -33,11 +33,11 @@
3333
"homepage": "https://github.com/vuejs/core/tree/main/packages/compiler-sfc#readme",
3434
"dependencies": {
3535
"@babel/parser": "^7.16.4",
36-
"@vue/compiler-core": "3.2.36",
37-
"@vue/compiler-dom": "3.2.36",
38-
"@vue/compiler-ssr": "3.2.36",
39-
"@vue/reactivity-transform": "3.2.36",
40-
"@vue/shared": "3.2.36",
36+
"@vue/compiler-core": "3.2.37",
37+
"@vue/compiler-dom": "3.2.37",
38+
"@vue/compiler-ssr": "3.2.37",
39+
"@vue/reactivity-transform": "3.2.37",
40+
"@vue/shared": "3.2.37",
4141
"estree-walker": "^2.0.2",
4242
"magic-string": "^0.25.7",
4343
"source-map": "^0.6.1",

packages/compiler-sfc/src/compileScript.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1463,7 +1463,7 @@ export function compileScript(
14631463
if (!hasDefaultExportName && filename && filename !== DEFAULT_FILENAME) {
14641464
const match = filename.match(/([^/\\]+)\.\w+$/)
14651465
if (match) {
1466-
runtimeOptions += `\n name: '${match[1]}',`
1466+
runtimeOptions += `\n __name: '${match[1]}',`
14671467
}
14681468
}
14691469
if (hasInlinedSsrRenderFn) {

packages/compiler-sfc/src/cssVars.ts

Lines changed: 71 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,6 @@ import { PluginCreator } from 'postcss'
1212
import hash from 'hash-sum'
1313

1414
export const CSS_VARS_HELPER = `useCssVars`
15-
// match v-bind() with max 2-levels of nested parens.
16-
const cssVarRE = /v-bind\s*\(((?:[^)(]+|\((?:[^)(]+|\([^)(]*\))*\))*)\)/g
1715

1816
export function genCssVarsFromList(
1917
vars: string[],
@@ -47,22 +45,71 @@ function normalizeExpression(exp: string) {
4745
return exp
4846
}
4947

48+
const vBindRE = /v-bind\s*\(/g
49+
5050
export function parseCssVars(sfc: SFCDescriptor): string[] {
5151
const vars: string[] = []
5252
sfc.styles.forEach(style => {
5353
let match
5454
// ignore v-bind() in comments /* ... */
5555
const content = style.content.replace(/\/\*([\s\S]*?)\*\//g, '')
56-
while ((match = cssVarRE.exec(content))) {
57-
const variable = normalizeExpression(match[1])
58-
if (!vars.includes(variable)) {
59-
vars.push(variable)
56+
while ((match = vBindRE.exec(content))) {
57+
const start = match.index + match[0].length
58+
const end = lexBinding(content, start)
59+
if (end !== null) {
60+
const variable = normalizeExpression(content.slice(start, end))
61+
if (!vars.includes(variable)) {
62+
vars.push(variable)
63+
}
6064
}
6165
}
6266
})
6367
return vars
6468
}
6569

70+
const enum LexerState {
71+
inParens,
72+
inSingleQuoteString,
73+
inDoubleQuoteString
74+
}
75+
76+
function lexBinding(content: string, start: number): number | null {
77+
let state: LexerState = LexerState.inParens
78+
let parenDepth = 0
79+
80+
for (let i = start; i < content.length; i++) {
81+
const char = content.charAt(i)
82+
switch (state) {
83+
case LexerState.inParens:
84+
if (char === `'`) {
85+
state = LexerState.inSingleQuoteString
86+
} else if (char === `"`) {
87+
state = LexerState.inDoubleQuoteString
88+
} else if (char === `(`) {
89+
parenDepth++
90+
} else if (char === `)`) {
91+
if (parenDepth > 0) {
92+
parenDepth--
93+
} else {
94+
return i
95+
}
96+
}
97+
break
98+
case LexerState.inSingleQuoteString:
99+
if (char === `'`) {
100+
state = LexerState.inParens
101+
}
102+
break
103+
case LexerState.inDoubleQuoteString:
104+
if (char === `"`) {
105+
state = LexerState.inParens
106+
}
107+
break
108+
}
109+
}
110+
return null
111+
}
112+
66113
// for compileStyle
67114
export interface CssVarsPluginOptions {
68115
id: string
@@ -75,10 +122,24 @@ export const cssVarsPlugin: PluginCreator<CssVarsPluginOptions> = opts => {
75122
postcssPlugin: 'vue-sfc-vars',
76123
Declaration(decl) {
77124
// rewrite CSS variables
78-
if (cssVarRE.test(decl.value)) {
79-
decl.value = decl.value.replace(cssVarRE, (_, $1) => {
80-
return `var(--${genVarName(id, normalizeExpression($1), isProd)})`
81-
})
125+
const value = decl.value
126+
if (vBindRE.test(value)) {
127+
vBindRE.lastIndex = 0
128+
let transformed = ''
129+
let lastIndex = 0
130+
let match
131+
while ((match = vBindRE.exec(value))) {
132+
const start = match.index + match[0].length
133+
const end = lexBinding(value, start)
134+
if (end !== null) {
135+
const variable = normalizeExpression(value.slice(start, end))
136+
transformed +=
137+
value.slice(lastIndex, match.index) +
138+
`var(--${genVarName(id, variable, isProd)})`
139+
lastIndex = end + 1
140+
}
141+
}
142+
decl.value = transformed + value.slice(lastIndex)
82143
}
83144
}
84145
}

0 commit comments

Comments
 (0)