Skip to content

Commit 73cd394

Browse files
Merge branch 'main' into chore-perf
2 parents aad0a4a + 507f3e7 commit 73cd394

File tree

23 files changed

+428
-70
lines changed

23 files changed

+428
-70
lines changed

.github/contributing.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -330,4 +330,4 @@ Funds donated via Patreon go directly to support Evan You's full-time work on Vu
330330

331331
Thank you to all the people who have already contributed to Vue.js!
332332

333-
<a href="https://github.com/vuejs/vue/graphs/contributors"><img src="https://opencollective.com/vuejs/contributors.svg?width=890" /></a>
333+
<a href="https://github.com/vuejs/core/graphs/contributors"><img src="https://opencollective.com/vuejs/contributors.svg?width=890" /></a>

BACKERS.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,6 @@ Vue.js is an MIT-licensed open source project with its ongoing development made
44

55
<p align="center">
66
<a target="_blank" href="https://sponsors.vuejs.org/backers.svg">
7-
<img alt="sponsors" src="https://sponsors.vuejs.org/backers.svg">
7+
<img alt="sponsors" src="https://sponsors.vuejs.org/backers.svg?v1">
88
</a>
99
</p>

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"private": true,
33
"version": "3.3.4",
4-
"packageManager": "pnpm@8.4.0",
4+
"packageManager": "pnpm@8.6.2",
55
"type": "module",
66
"scripts": {
77
"dev": "node scripts/dev.js",

packages/compiler-core/src/babelUtils.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ export function walkIdentifiers(
3232
root.body[0].type === 'ExpressionStatement' &&
3333
root.body[0].expression
3434

35-
;(walk as any)(root, {
35+
walk(root, {
3636
enter(node: Node & { scopeIds?: Set<string> }, parent: Node | undefined) {
3737
parent && parentStack.push(parent)
3838
if (

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import {
1010
} from '../../src/script/resolveType'
1111

1212
import ts from 'typescript'
13-
registerTS(ts)
13+
registerTS(() => ts)
1414

1515
describe('resolveType', () => {
1616
test('type literal', () => {

packages/compiler-sfc/src/compileScript.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -607,8 +607,8 @@ export function compileScript(
607607
node.type.endsWith('Statement')
608608
) {
609609
const scope: Statement[][] = [scriptSetupAst.body]
610-
;(walk as any)(node, {
611-
enter(child: Node, parent: Node) {
610+
walk(node, {
611+
enter(child: Node, parent: Node | undefined) {
612612
if (isFunctionType(child)) {
613613
this.skip()
614614
}
@@ -633,7 +633,7 @@ export function compileScript(
633633
ctx,
634634
child,
635635
needsSemi,
636-
parent.type === 'ExpressionStatement'
636+
parent!.type === 'ExpressionStatement'
637637
)
638638
}
639639
},

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -238,7 +238,7 @@ export function transformDestructuredProps(
238238
// check root scope first
239239
const ast = ctx.scriptSetupAst!
240240
walkScope(ast, true)
241-
;(walk as any)(ast, {
241+
walk(ast, {
242242
enter(node: Node, parent?: Node) {
243243
parent && parentStack.push(parent)
244244

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

+28-16
Original file line numberDiff line numberDiff line change
@@ -708,13 +708,14 @@ function resolveGlobalScope(ctx: TypeResolveContext): TypeScope[] | undefined {
708708
}
709709
}
710710

711-
let ts: typeof TS
711+
let ts: typeof TS | undefined
712+
let loadTS: (() => typeof TS) | undefined
712713

713714
/**
714715
* @private
715716
*/
716-
export function registerTS(_ts: any) {
717-
ts = _ts
717+
export function registerTS(_loadTS: () => typeof TS) {
718+
loadTS = _loadTS
718719
}
719720

720721
type FS = NonNullable<SFCScriptCompileOptions['fs']>
@@ -723,7 +724,10 @@ function resolveFS(ctx: TypeResolveContext): FS | undefined {
723724
if (ctx.fs) {
724725
return ctx.fs
725726
}
726-
const fs = ctx.options.fs || ts.sys
727+
if (!ts && loadTS) {
728+
ts = loadTS()
729+
}
730+
const fs = ctx.options.fs || ts?.sys
727731
if (!fs) {
728732
return
729733
}
@@ -779,22 +783,25 @@ function importSourceToScope(
779783
} else {
780784
// module or aliased import - use full TS resolution, only supported in Node
781785
if (!__NODE_JS__) {
782-
ctx.error(
786+
return ctx.error(
783787
`Type import from non-relative sources is not supported in the browser build.`,
784788
node,
785789
scope
786790
)
787791
}
788792
if (!ts) {
789-
ctx.error(
790-
`Failed to resolve import source ${JSON.stringify(source)}. ` +
791-
`typescript is required as a peer dep for vue in order ` +
792-
`to support resolving types from module imports.`,
793-
node,
794-
scope
795-
)
793+
if (loadTS) ts = loadTS()
794+
if (!ts) {
795+
return ctx.error(
796+
`Failed to resolve import source ${JSON.stringify(source)}. ` +
797+
`typescript is required as a peer dep for vue in order ` +
798+
`to support resolving types from module imports.`,
799+
node,
800+
scope
801+
)
802+
}
796803
}
797-
resolved = resolveWithTS(scope.filename, source, fs)
804+
resolved = resolveWithTS(scope.filename, source, ts, fs)
798805
}
799806
if (resolved) {
800807
resolved = scope.resolvedImportSources[source] = normalizePath(resolved)
@@ -839,6 +846,7 @@ const tsConfigRefMap = new Map<string, string>()
839846
function resolveWithTS(
840847
containingFile: string,
841848
source: string,
849+
ts: typeof TS,
842850
fs: FS
843851
): string | undefined {
844852
if (!__NODE_JS__) return
@@ -853,7 +861,7 @@ function resolveWithTS(
853861
const normalizedConfigPath = normalizePath(configPath)
854862
const cached = tsConfigCache.get(normalizedConfigPath)
855863
if (!cached) {
856-
configs = loadTSConfig(configPath, fs).map(config => ({ config }))
864+
configs = loadTSConfig(configPath, ts, fs).map(config => ({ config }))
857865
tsConfigCache.set(normalizedConfigPath, configs)
858866
} else {
859867
configs = cached
@@ -918,7 +926,11 @@ function resolveWithTS(
918926
}
919927
}
920928

921-
function loadTSConfig(configPath: string, fs: FS): TS.ParsedCommandLine[] {
929+
function loadTSConfig(
930+
configPath: string,
931+
ts: typeof TS,
932+
fs: FS
933+
): TS.ParsedCommandLine[] {
922934
// The only case where `fs` is NOT `ts.sys` is during tests.
923935
// parse config host requires an extra `readDirectory` method
924936
// during tests, which is stubbed.
@@ -940,7 +952,7 @@ function loadTSConfig(configPath: string, fs: FS): TS.ParsedCommandLine[] {
940952
if (config.projectReferences) {
941953
for (const ref of config.projectReferences) {
942954
tsConfigRefMap.set(ref.path, configPath)
943-
res.unshift(...loadTSConfig(ref.path, fs))
955+
res.unshift(...loadTSConfig(ref.path, ts, fs))
944956
}
945957
}
946958
return res

packages/global.d.ts

+11
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,17 @@ declare module 'file-saver' {
3333
export function saveAs(blob: any, name: any): void
3434
}
3535

36+
declare module 'estree-walker' {
37+
export function walk<T>(
38+
root: T,
39+
options: {
40+
enter?: (node: T, parent: T | undefined) => any
41+
leave?: (node: T, parent: T | undefined) => any
42+
exit?: (node: T) => any
43+
} & ThisType<{ skip: () => void }>
44+
)
45+
}
46+
3647
declare interface String {
3748
/**
3849
* @deprecated Please use String.prototype.slice instead of String.prototype.substring in the repository.

packages/reactivity-transform/src/reactivityTransform.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -636,7 +636,7 @@ export function transformAST(
636636

637637
// check root scope first
638638
walkScope(ast, true)
639-
;(walk as any)(ast, {
639+
walk(ast, {
640640
enter(node: Node, parent?: Node) {
641641
parent && parentStack.push(parent)
642642

packages/runtime-dom/src/components/Transition.ts

+2
Original file line numberDiff line numberDiff line change
@@ -445,6 +445,8 @@ function getTimeout(delays: string[], durations: string[]): number {
445445
// If comma is not replaced with a dot, the input will be rounded down
446446
// (i.e. acting as a floor function) causing unexpected behaviors
447447
function toMs(s: string): number {
448+
// #8409 default value for CSS durations can be 'auto'
449+
if (s === 'auto') return 0
448450
return Number(s.slice(0, -1).replace(',', '.')) * 1000
449451
}
450452

packages/sfc-playground/index.html

+7-7
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,14 @@
88
<title>Vue SFC Playground</title>
99
<script>
1010
// process shim for old versions of @vue/compiler-sfc dependency
11-
window.process = { env: {} }
12-
const savedPreferDark = localStorage.getItem('vue-sfc-playground-prefer-dark')
13-
if (
14-
savedPreferDark === 'true' ||
15-
(!savedPreferDark && window.matchMedia('(prefers-color-scheme: dark)').matches)
16-
) {
11+
window.process = { env: {} }
12+
const savedPreferDark = localStorage.getItem('vue-sfc-playground-prefer-dark')
13+
if (
14+
savedPreferDark === 'true' ||
15+
(!savedPreferDark && window.matchMedia('(prefers-color-scheme: dark)').matches)
16+
) {
1717
document.documentElement.classList.add('dark')
18-
}
18+
}
1919
</script>
2020
<script type="module" src="/src/main.ts"></script>
2121
</head>

packages/sfc-playground/package.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,10 @@
99
},
1010
"devDependencies": {
1111
"@vitejs/plugin-vue": "^4.2.3",
12-
"vite": "^4.3.0"
12+
"vite": "^4.3.9"
1313
},
1414
"dependencies": {
15-
"@vue/repl": "^1.4.1",
15+
"@vue/repl": "^2.4.0",
1616
"file-saver": "^2.0.5",
1717
"jszip": "^3.6.0",
1818
"vue": "workspace:*"

packages/sfc-playground/src/App.vue

+15-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
<script setup lang="ts">
22
import Header from './Header.vue'
33
import { Repl, ReplStore, SFCOptions } from '@vue/repl'
4-
import { ref, watchEffect } from 'vue'
4+
import Monaco from '@vue/repl/monaco-editor'
5+
import { ref, watchEffect, onMounted } from 'vue'
56
67
const setVH = () => {
78
document.documentElement.style.setProperty('--vh', window.innerHeight + `px`)
@@ -71,17 +72,29 @@ function toggleSSR() {
7172
useSSRMode.value = !useSSRMode.value
7273
store.setFiles(store.getFiles())
7374
}
75+
76+
const theme = ref('dark')
77+
function toggleTheme(isDark: boolean) {
78+
theme.value = isDark ? 'dark' : 'light'
79+
}
80+
onMounted(() => {
81+
const cls = document.documentElement.classList
82+
toggleTheme(cls.contains('dark'))
83+
})
7484
</script>
7585

7686
<template>
7787
<Header
7888
:store="store"
7989
:dev="useDevMode"
8090
:ssr="useSSRMode"
91+
@toggle-theme="toggleTheme"
8192
@toggle-dev="toggleDevMode"
8293
@toggle-ssr="toggleSSR"
8394
/>
8495
<Repl
96+
:theme="theme"
97+
:editor="Monaco"
8598
@keydown.ctrl.s.prevent
8699
@keydown.meta.s.prevent
87100
:ssr="useSSRMode"
@@ -108,7 +121,7 @@ body {
108121
}
109122
110123
.vue-repl {
111-
height: calc(var(--vh) - var(--nav-height));
124+
height: calc(var(--vh) - var(--nav-height)) !important;
112125
}
113126
114127
button {

packages/sfc-playground/src/Header.vue

+9-7
Original file line numberDiff line numberDiff line change
@@ -51,14 +51,16 @@ async function copyLink(e: MouseEvent) {
5151
alert('Sharable URL has been copied to clipboard.')
5252
}
5353
54-
function toggleDark() {
54+
const emit = defineEmits(['toggle-theme', 'toggle-ssr','toggle-dev'])
55+
function toggleDark() {
5556
const cls = document.documentElement.classList
56-
cls.toggle('dark')
57-
localStorage.setItem(
58-
'vue-sfc-playground-prefer-dark',
59-
String(cls.contains('dark'))
57+
cls.toggle('dark')
58+
localStorage.setItem(
59+
'vue-sfc-playground-prefer-dark',
60+
String(cls.contains('dark'))
6061
)
61-
}
62+
emit('toggle-theme', cls.contains('dark'))
63+
}
6264
6365
onMounted(async () => {
6466
window.addEventListener('click', () => {
@@ -145,7 +147,7 @@ async function fetchVersions(): Promise<string[]> {
145147
>
146148
<span>{{ ssr ? 'SSR ON' : 'SSR OFF' }}</span>
147149
</button>
148-
<button title="Toggle dark mode" class="toggle-dark" @click="toggleDark">
150+
<button title="Toggle dark mode" class="toggle-dark" @click="toggleDark">
149151
<Sun class="light" />
150152
<Moon class="dark" />
151153
</button>

packages/sfc-playground/src/download/download.ts

+5-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,11 @@ export async function downloadProject(store: ReplStore) {
2727

2828
const files = store.getFiles()
2929
for (const file in files) {
30-
src.file(file, files[file])
30+
if (file !== 'import-map.json') {
31+
src.file(file, files[file])
32+
} else {
33+
zip.file(file, files[file])
34+
}
3135
}
3236

3337
const blob = await zip.generateAsync({ type: 'blob' })

packages/shared/src/globalsAllowList.ts

+3
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,6 @@ const GLOBALS_ALLOWED =
66
'Object,Boolean,String,RegExp,Map,Set,JSON,Intl,BigInt,console'
77

88
export const isGloballyAllowed = /*#__PURE__*/ makeMap(GLOBALS_ALLOWED)
9+
10+
/** @deprecated use `isGloballyAllowed` instead */
11+
export const isGloballyWhitelisted = isGloballyAllowed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
module.exports = require('@vue/compiler-sfc')
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export * from '@vue/compiler-sfc'
+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
if (typeof require !== 'undefined') {
22
try {
3-
require('@vue/compiler-sfc').registerTS(require('typescript'))
3+
require('@vue/compiler-sfc').registerTS(() => require('typescript'))
44
} catch (e) {}
55
}

packages/vue/package.json

+10
Original file line numberDiff line numberDiff line change
@@ -44,10 +44,12 @@
4444
"./compiler-sfc": {
4545
"import": {
4646
"types": "./compiler-sfc/index.d.mts",
47+
"browser": "./compiler-sfc/index.browser.mjs",
4748
"default": "./compiler-sfc/index.mjs"
4849
},
4950
"require": {
5051
"types": "./compiler-sfc/index.d.ts",
52+
"browser": "./compiler-sfc/index.browser.js",
5153
"default": "./compiler-sfc/index.js"
5254
}
5355
},
@@ -99,5 +101,13 @@
99101
"@vue/runtime-dom": "3.3.4",
100102
"@vue/compiler-sfc": "3.3.4",
101103
"@vue/server-renderer": "3.3.4"
104+
},
105+
"peerDependencies": {
106+
"typescript": "*"
107+
},
108+
"peerDependenciesMeta": {
109+
"typescript": {
110+
"optional": true
111+
}
102112
}
103113
}

0 commit comments

Comments
 (0)