From cdb1d1795d21591659e2560e201ee4fbf1ea4aca Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kevin=20Deng=20=E4=B8=89=E5=92=B2=E6=99=BA=E5=AD=90?= Date: Wed, 29 May 2024 15:03:20 +0800 Subject: [PATCH 001/125] chore: disallow optional chaining (#10919) --- eslint.config.js | 8 +++++++- packages/compiler-core/src/babelUtils.ts | 2 ++ packages/reactivity/src/effect.ts | 2 ++ packages/runtime-core/src/devtools.ts | 1 + packages/runtime-core/src/hydration.ts | 5 +++++ packages/runtime-core/src/warning.ts | 1 + 6 files changed, 18 insertions(+), 1 deletion(-) diff --git a/eslint.config.js b/eslint.config.js index 3587a815067..334787fd988 100644 --- a/eslint.config.js +++ b/eslint.config.js @@ -45,6 +45,12 @@ export default tseslint.config( message: 'Our output target is ES2016, so async/await syntax should be avoided.', }, + { + selector: 'ChainExpression', + message: + 'Our output target is ES2016, and optional chaining results in ' + + 'verbose helpers and should be avoided.', + }, ], 'sort-imports': ['error', { ignoreDeclarationSort: true }], @@ -134,7 +140,7 @@ export default tseslint.config( { files: [ 'eslint.config.js', - 'rollup.config.js', + 'rollup*.config.js', 'scripts/**', './*.{js,ts}', 'packages/*/*.js', diff --git a/packages/compiler-core/src/babelUtils.ts b/packages/compiler-core/src/babelUtils.ts index d3812f84ce6..7482494e17a 100644 --- a/packages/compiler-core/src/babelUtils.ts +++ b/packages/compiler-core/src/babelUtils.ts @@ -53,6 +53,7 @@ export function walkIdentifiers( } } else if ( node.type === 'ObjectProperty' && + // eslint-disable-next-line no-restricted-syntax parent?.type === 'ObjectPattern' ) { // mark property in destructure pattern @@ -407,6 +408,7 @@ function isReferenced(node: Node, parent: Node, grandparent?: Node): boolean { // no: export { NODE as foo } from "foo"; case 'ExportSpecifier': // @ts-expect-error + // eslint-disable-next-line no-restricted-syntax if (grandparent?.source) { return false } diff --git a/packages/reactivity/src/effect.ts b/packages/reactivity/src/effect.ts index 29d29cc4241..1528f4b1d89 100644 --- a/packages/reactivity/src/effect.ts +++ b/packages/reactivity/src/effect.ts @@ -281,6 +281,7 @@ export function trackEffect( effect._depsLength++ } if (__DEV__) { + // eslint-disable-next-line no-restricted-syntax effect.onTrack?.(extend({ effect }, debuggerEventExtraInfo!)) } } @@ -309,6 +310,7 @@ export function triggerEffects( (tracking ??= dep.get(effect) === effect._trackId) ) { if (__DEV__) { + // eslint-disable-next-line no-restricted-syntax effect.onTrigger?.(extend({ effect }, debuggerEventExtraInfo)) } effect.trigger() diff --git a/packages/runtime-core/src/devtools.ts b/packages/runtime-core/src/devtools.ts index 5bff57a4165..2af81be8370 100644 --- a/packages/runtime-core/src/devtools.ts +++ b/packages/runtime-core/src/devtools.ts @@ -63,6 +63,7 @@ export function setDevtoolsHook(hook: DevtoolsHook, target: any) { // some envs mock window but not fully window.HTMLElement && // also exclude jsdom + // eslint-disable-next-line no-restricted-syntax !window.navigator?.userAgent?.includes('jsdom') ) { const replay = (target.__VUE_DEVTOOLS_HOOK_REPLAY__ = diff --git a/packages/runtime-core/src/hydration.ts b/packages/runtime-core/src/hydration.ts index 87e4c60a253..3be8837ce4b 100644 --- a/packages/runtime-core/src/hydration.ts +++ b/packages/runtime-core/src/hydration.ts @@ -757,11 +757,14 @@ function propHasMismatch( } } + // eslint-disable-next-line no-restricted-syntax const root = instance?.subTree if ( vnode === root || + // eslint-disable-next-line no-restricted-syntax (root?.type === Fragment && (root.children as VNode[]).includes(vnode)) ) { + // eslint-disable-next-line no-restricted-syntax const cssVars = instance?.getCssVars?.() for (const key in cssVars) { expectedMap.set(`--${key}`, String(cssVars[key])) @@ -842,7 +845,9 @@ function toStyleMap(str: string): Map { const styleMap: Map = new Map() for (const item of str.split(';')) { let [key, value] = item.split(':') + // eslint-disable-next-line no-restricted-syntax key = key?.trim() + // eslint-disable-next-line no-restricted-syntax value = value?.trim() if (key && value) { styleMap.set(key, value) diff --git a/packages/runtime-core/src/warning.ts b/packages/runtime-core/src/warning.ts index c3b2ebbd02d..d130638b6af 100644 --- a/packages/runtime-core/src/warning.ts +++ b/packages/runtime-core/src/warning.ts @@ -45,6 +45,7 @@ export function warn(msg: string, ...args: any[]) { instance, ErrorCodes.APP_WARN_HANDLER, [ + // eslint-disable-next-line no-restricted-syntax msg + args.map(a => a.toString?.() ?? JSON.stringify(a)).join(''), instance && instance.proxy, trace From 15ee43f66ad2485ac212b02b444345d867b3c060 Mon Sep 17 00:00:00 2001 From: Yi Yang Date: Thu, 30 May 2024 10:51:30 +0800 Subject: [PATCH 002/125] fix(teleport): do not throw target warning when teleport is disabled (#9818) --- packages/runtime-core/src/components/Teleport.ts | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/packages/runtime-core/src/components/Teleport.ts b/packages/runtime-core/src/components/Teleport.ts index 0de0ebf787e..8d174e2022c 100644 --- a/packages/runtime-core/src/components/Teleport.ts +++ b/packages/runtime-core/src/components/Teleport.ts @@ -47,14 +47,13 @@ const resolveTarget = ( return null } else { const target = select(targetSelector) - if (!target) { - __DEV__ && - warn( - `Failed to locate Teleport target with selector "${targetSelector}". ` + - `Note the target element must exist before the component is mounted - ` + - `i.e. the target cannot be rendered by the component itself, and ` + - `ideally should be outside of the entire Vue component tree.`, - ) + if (__DEV__ && !target && !isTeleportDisabled(props)) { + warn( + `Failed to locate Teleport target with selector "${targetSelector}". ` + + `Note the target element must exist before the component is mounted - ` + + `i.e. the target cannot be rendered by the component itself, and ` + + `ideally should be outside of the entire Vue component tree.`, + ) } return target as T } From 6f9587f63bb908f41bbc92bb35f3dfca0d01e4cd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kevin=20Deng=20=E4=B8=89=E5=92=B2=E6=99=BA=E5=AD=90?= Date: Thu, 30 May 2024 10:51:55 +0800 Subject: [PATCH 003/125] ci: omit pr number (#11033) In the latest version of `maintain-one-comment`, pr number can be set automatically https://github.com/actions-cool/maintain-one-comment/pull/9 --- .github/workflows/size-data.yml | 10 ---------- .github/workflows/size-report.yml | 14 -------------- 2 files changed, 24 deletions(-) diff --git a/.github/workflows/size-data.yml b/.github/workflows/size-data.yml index be57d223550..6ed57014562 100644 --- a/.github/workflows/size-data.yml +++ b/.github/workflows/size-data.yml @@ -41,13 +41,3 @@ jobs: with: name: size-data path: temp/size - - - name: Save PR number - if: ${{github.event_name == 'pull_request'}} - run: echo ${{ github.event.number }} > ./pr.txt - - - uses: actions/upload-artifact@v4 - if: ${{github.event_name == 'pull_request'}} - with: - name: pr-number - path: pr.txt diff --git a/.github/workflows/size-report.yml b/.github/workflows/size-report.yml index 766462d6da9..f84a9398413 100644 --- a/.github/workflows/size-report.yml +++ b/.github/workflows/size-report.yml @@ -35,19 +35,6 @@ jobs: - name: Install dependencies run: pnpm install - - name: Download PR number - uses: dawidd6/action-download-artifact@v3 - with: - name: pr-number - run_id: ${{ github.event.workflow_run.id }} - path: /tmp/pr-number - - - name: Read PR Number - id: pr-number - uses: juliangruber/read-file-action@v1 - with: - path: /tmp/pr-number/pr.txt - - name: Download Size Data uses: dawidd6/action-download-artifact@v3 with: @@ -78,7 +65,6 @@ jobs: uses: actions-cool/maintain-one-comment@v3 with: token: ${{ secrets.GITHUB_TOKEN }} - number: ${{ steps.pr-number.outputs.content }} body: | ${{ steps.size-report.outputs.content }} From a3e8aafbcc82003a66caded61143eb64c4ef02cd Mon Sep 17 00:00:00 2001 From: skirtle <65301168+skirtles-code@users.noreply.github.com> Date: Thu, 30 May 2024 04:03:44 +0100 Subject: [PATCH 004/125] fix(watch): support traversing symbol properties in deep watcher (#10969) close #402 --- .../runtime-core/__tests__/apiWatch.spec.ts | 46 +++++++++++++++++++ packages/runtime-core/src/apiWatch.ts | 5 ++ 2 files changed, 51 insertions(+) diff --git a/packages/runtime-core/__tests__/apiWatch.spec.ts b/packages/runtime-core/__tests__/apiWatch.spec.ts index 8229dce36db..265bc0a0d46 100644 --- a/packages/runtime-core/__tests__/apiWatch.spec.ts +++ b/packages/runtime-core/__tests__/apiWatch.spec.ts @@ -932,6 +932,52 @@ describe('api: watch', () => { expect(dummy).toEqual([1, 2]) }) + it('deep with symbols', async () => { + const symbol1 = Symbol() + const symbol2 = Symbol() + const symbol3 = Symbol() + const symbol4 = Symbol() + + const raw: any = { + [symbol1]: { + [symbol2]: 1, + }, + } + + Object.defineProperty(raw, symbol3, { + writable: true, + enumerable: false, + value: 1, + }) + + const state = reactive(raw) + const spy = vi.fn() + + watch(() => state, spy, { deep: true }) + + await nextTick() + expect(spy).toHaveBeenCalledTimes(0) + + state[symbol1][symbol2] = 2 + await nextTick() + expect(spy).toHaveBeenCalledTimes(1) + + // Non-enumerable properties don't trigger deep watchers + state[symbol3] = 3 + await nextTick() + expect(spy).toHaveBeenCalledTimes(1) + + // Adding a new symbol property + state[symbol4] = 1 + await nextTick() + expect(spy).toHaveBeenCalledTimes(2) + + // Removing a symbol property + delete state[symbol4] + await nextTick() + expect(spy).toHaveBeenCalledTimes(3) + }) + it('immediate', async () => { const count = ref(0) const cb = vi.fn() diff --git a/packages/runtime-core/src/apiWatch.ts b/packages/runtime-core/src/apiWatch.ts index ffad8ad5495..bab9e0764f5 100644 --- a/packages/runtime-core/src/apiWatch.ts +++ b/packages/runtime-core/src/apiWatch.ts @@ -493,6 +493,11 @@ export function traverse( for (const key in value) { traverse(value[key], depth, seen) } + for (const key of Object.getOwnPropertySymbols(value)) { + if (Object.prototype.propertyIsEnumerable.call(value, key)) { + traverse(value[key as any], depth, seen) + } + } } return value } From b9ca202f477be595477e182972ee9bae3f2b9f74 Mon Sep 17 00:00:00 2001 From: huangcheng Date: Thu, 30 May 2024 17:24:37 +0800 Subject: [PATCH 005/125] fix(compiler-core): v-for expression missing source with spaces should emit error (#5821) close #5819 --- .../__tests__/transforms/vFor.spec.ts | 24 +++++++++++++++++++ packages/compiler-core/src/utils.ts | 2 +- 2 files changed, 25 insertions(+), 1 deletion(-) diff --git a/packages/compiler-core/__tests__/transforms/vFor.spec.ts b/packages/compiler-core/__tests__/transforms/vFor.spec.ts index 7fabcbb579c..e434b8888a6 100644 --- a/packages/compiler-core/__tests__/transforms/vFor.spec.ts +++ b/packages/compiler-core/__tests__/transforms/vFor.spec.ts @@ -202,6 +202,18 @@ describe('compiler: v-for', () => { expect(forNode.valueAlias).toBeUndefined() expect((forNode.source as SimpleExpressionNode).content).toBe('items') }) + + test('source containing string expression with spaces', () => { + const { node: forNode } = parseWithForTransform( + ``, + ) + expect(forNode.keyAlias).toBeUndefined() + expect(forNode.objectIndexAlias).toBeUndefined() + expect((forNode.valueAlias as SimpleExpressionNode).content).toBe('item') + expect((forNode.source as SimpleExpressionNode).content).toBe( + "state ['my items']", + ) + }) }) describe('errors', () => { @@ -253,6 +265,18 @@ describe('compiler: v-for', () => { ) }) + test('missing source and have multiple spaces with', () => { + const onError = vi.fn() + parseWithForTransform('', { onError }) + + expect(onError).toHaveBeenCalledTimes(1) + expect(onError).toHaveBeenCalledWith( + expect.objectContaining({ + code: ErrorCodes.X_V_FOR_MALFORMED_EXPRESSION, + }), + ) + }) + test('missing value', () => { const onError = vi.fn() parseWithForTransform('', { onError }) diff --git a/packages/compiler-core/src/utils.ts b/packages/compiler-core/src/utils.ts index 99a2c5b61a8..aa596028440 100644 --- a/packages/compiler-core/src/utils.ts +++ b/packages/compiler-core/src/utils.ts @@ -499,4 +499,4 @@ export function getMemoedVNodeCall(node: BlockCodegenNode | MemoExpression) { } } -export const forAliasRE = /([\s\S]*?)\s+(?:in|of)\s+([\s\S]*)/ +export const forAliasRE = /([\s\S]*?)\s+(?:in|of)\s+(\S[\s\S]*)/ From 4c74302aae64c118752db7fc2a2c229a11ebaead Mon Sep 17 00:00:00 2001 From: mmis1000 <2993977+mmis1000@users.noreply.github.com> Date: Thu, 30 May 2024 17:43:34 +0800 Subject: [PATCH 006/125] fix(ssr): fix the bug that multi slot scope id does not work on component (#6100) close #6093 --- .../__tests__/ssrScopeId.spec.ts | 90 +++++++++++++++++++ packages/server-renderer/src/render.ts | 5 +- 2 files changed, 94 insertions(+), 1 deletion(-) diff --git a/packages/server-renderer/__tests__/ssrScopeId.spec.ts b/packages/server-renderer/__tests__/ssrScopeId.spec.ts index f9d356065d0..4ceb865fb50 100644 --- a/packages/server-renderer/__tests__/ssrScopeId.spec.ts +++ b/packages/server-renderer/__tests__/ssrScopeId.spec.ts @@ -179,4 +179,94 @@ describe('ssr: scopedId runtime behavior', () => { const result = await renderToString(createApp(Comp)) // output: `
` expect(result).toBe(`
`) }) + + // #6093 + test(':slotted on forwarded slots on component', async () => { + const Wrapper = { + __scopeId: 'wrapper', + ssrRender: (ctx: any, push: any, parent: any, attrs: any) => { + //
+ push( + ``, + ) + ssrRenderSlot( + ctx.$slots, + 'default', + {}, + null, + push, + parent, + 'wrapper-s', + ) + push(``) + }, + } + + const Slotted = { + __scopeId: 'slotted', + ssrRender: (ctx: any, push: any, parent: any, attrs: any) => { + // + push( + ssrRenderComponent( + Wrapper, + attrs, + { + default: withCtx( + (_: any, push: any, parent: any, scopeId: string) => { + ssrRenderSlot( + ctx.$slots, + 'default', + {}, + null, + push, + parent, + 'slotted-s' + scopeId, + ) + }, + ), + _: 1, + } as any, + parent, + ), + ) + }, + } + + const Child = { + ssrRender: (ctx: any, push: any, parent: any, attrs: any) => { + push(``) + }, + } + + const Root = { + __scopeId: 'root', + // + ssrRender: (_: any, push: any, parent: any, attrs: any) => { + push( + ssrRenderComponent( + Slotted, + attrs, + { + default: withCtx( + (_: any, push: any, parent: any, scopeId: string) => { + push(ssrRenderComponent(Child, null, null, parent, scopeId)) + }, + ), + _: 1, + } as any, + parent, + ), + ) + }, + } + + const result = await renderToString(createApp(Root)) + expect(result).toBe( + `
` + + `
` + + `
`, + ) + }) }) diff --git a/packages/server-renderer/src/render.ts b/packages/server-renderer/src/render.ts index 28a78c66843..7e274c3b981 100644 --- a/packages/server-renderer/src/render.ts +++ b/packages/server-renderer/src/render.ts @@ -181,7 +181,10 @@ function renderComponentSubTree( if (slotScopeId) { if (!hasCloned) attrs = { ...attrs } - attrs![slotScopeId.trim()] = '' + const slotScopeIdList = slotScopeId.trim().split(' ') + for (let i = 0; i < slotScopeIdList.length; i++) { + attrs![slotScopeIdList[i]] = '' + } } // set current rendering instance for asset resolution From 3ea964473d3ac0ba3e7b0b2c22d71f23d0f69123 Mon Sep 17 00:00:00 2001 From: Travis Date: Thu, 30 May 2024 17:45:11 +0800 Subject: [PATCH 007/125] fix(compiler-core): allow unicode to appear in simple identifiers (#6765) close #6367 --- .../compiler-core/__tests__/transforms/vOn.spec.ts | 14 +++++++++++++- packages/compiler-core/src/utils.ts | 2 +- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/packages/compiler-core/__tests__/transforms/vOn.spec.ts b/packages/compiler-core/__tests__/transforms/vOn.spec.ts index b1c37e3f74e..27d5027533b 100644 --- a/packages/compiler-core/__tests__/transforms/vOn.spec.ts +++ b/packages/compiler-core/__tests__/transforms/vOn.spec.ts @@ -10,6 +10,7 @@ import { baseParse as parse, transform, } from '../../src' +import { transformFor } from '../../src/transforms/vFor' import { transformOn } from '../../src/transforms/vOn' import { transformElement } from '../../src/transforms/transformElement' import { transformExpression } from '../../src/transforms/transformExpression' @@ -17,7 +18,7 @@ import { transformExpression } from '../../src/transforms/transformExpression' function parseWithVOn(template: string, options: CompilerOptions = {}) { const ast = parse(template, options) transform(ast, { - nodeTransforms: [transformExpression, transformElement], + nodeTransforms: [transformExpression, transformElement, transformFor], directiveTransforms: { on: transformOn, }, @@ -602,6 +603,17 @@ describe('compiler: transform v-on', () => { expect(root.cached).toBe(1) }) + test('unicode identifier should not be cached (v-for)', () => { + const { root } = parseWithVOn( + `
`, + { + prefixIdentifiers: true, + cacheHandlers: true, + }, + ) + expect(root.cached).toBe(0) + }) + test('inline function expression handler', () => { const { root, node } = parseWithVOn(`
`, { prefixIdentifiers: true, diff --git a/packages/compiler-core/src/utils.ts b/packages/compiler-core/src/utils.ts index aa596028440..561c6357864 100644 --- a/packages/compiler-core/src/utils.ts +++ b/packages/compiler-core/src/utils.ts @@ -62,7 +62,7 @@ export function isCoreComponent(tag: string): symbol | void { } } -const nonIdentifierRE = /^\d|[^\$\w]/ +const nonIdentifierRE = /^\d|[^\$\w\xA0-\uFFFF]/ export const isSimpleIdentifier = (name: string): boolean => !nonIdentifierRE.test(name) From 5d258502a0faffc8a451b8701f13a31b2566d068 Mon Sep 17 00:00:00 2001 From: Wouter Date: Thu, 30 May 2024 12:19:04 +0200 Subject: [PATCH 008/125] fix(compiler-core): emit TS-compatible function declaration when requested (#9363) Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com> Co-authored-by: Haoqun Jiang --- .../__snapshots__/scopeId.spec.ts.snap | 16 ++++++++++++ .../compiler-core/__tests__/scopeId.spec.ts | 25 +++++++++++++++++++ packages/compiler-core/src/codegen.ts | 3 ++- 3 files changed, 43 insertions(+), 1 deletion(-) diff --git a/packages/compiler-core/__tests__/__snapshots__/scopeId.spec.ts.snap b/packages/compiler-core/__tests__/__snapshots__/scopeId.spec.ts.snap index 445d3fd13ed..7267ba6b041 100644 --- a/packages/compiler-core/__tests__/__snapshots__/scopeId.spec.ts.snap +++ b/packages/compiler-core/__tests__/__snapshots__/scopeId.spec.ts.snap @@ -16,6 +16,22 @@ export function render(_ctx, _cache) { }" `; +exports[`scopeId compiler support > should push typescript-compatible scopeId for hoisted nodes 1`] = ` +"import { createElementVNode as _createElementVNode, toDisplayString as _toDisplayString, createTextVNode as _createTextVNode, openBlock as _openBlock, createElementBlock as _createElementBlock, pushScopeId as _pushScopeId, popScopeId as _popScopeId } from "vue" + +const _withScopeId = (n: any) => (_pushScopeId("test"),n=n(),_popScopeId(),n) +const _hoisted_1 = /*#__PURE__*/ _withScopeId(() => /*#__PURE__*/_createElementVNode("div", null, "hello", -1 /* HOISTED */)) +const _hoisted_2 = /*#__PURE__*/ _withScopeId(() => /*#__PURE__*/_createElementVNode("div", null, "world", -1 /* HOISTED */)) + +export function render(_ctx: any,_cache: any) { + return (_openBlock(), _createElementBlock("div", null, [ + _hoisted_1, + _createTextVNode(_toDisplayString(_ctx.foo), 1 /* TEXT */), + _hoisted_2 + ])) +}" +`; + exports[`scopeId compiler support > should wrap default slot 1`] = ` "import { createElementVNode as _createElementVNode, resolveComponent as _resolveComponent, withCtx as _withCtx, openBlock as _openBlock, createBlock as _createBlock } from "vue" diff --git a/packages/compiler-core/__tests__/scopeId.spec.ts b/packages/compiler-core/__tests__/scopeId.spec.ts index c7a21df7a78..21e7327f2eb 100644 --- a/packages/compiler-core/__tests__/scopeId.spec.ts +++ b/packages/compiler-core/__tests__/scopeId.spec.ts @@ -81,4 +81,29 @@ describe('scopeId compiler support', () => { ].forEach(c => expect(code).toMatch(c)) expect(code).toMatchSnapshot() }) + + test('should push typescript-compatible scopeId for hoisted nodes', () => { + const { ast, code } = baseCompile( + `
hello
{{ foo }}
world
`, + { + mode: 'module', + scopeId: 'test', + hoistStatic: true, + isTS: true, + }, + ) + expect(ast.helpers).toContain(PUSH_SCOPE_ID) + expect(ast.helpers).toContain(POP_SCOPE_ID) + expect(ast.hoists.length).toBe(2) + ;[ + `const _withScopeId = (n: any) => (_pushScopeId("test"),n=n(),_popScopeId(),n)`, + `const _hoisted_1 = /*#__PURE__*/ _withScopeId(() => /*#__PURE__*/_createElementVNode("div", null, "hello", ${genFlagText( + PatchFlags.HOISTED, + )}))`, + `const _hoisted_2 = /*#__PURE__*/ _withScopeId(() => /*#__PURE__*/_createElementVNode("div", null, "world", ${genFlagText( + PatchFlags.HOISTED, + )}))`, + ].forEach(c => expect(code).toMatch(c)) + expect(code).toMatchSnapshot() + }) }) diff --git a/packages/compiler-core/src/codegen.ts b/packages/compiler-core/src/codegen.ts index 987293d5124..39170bac5a0 100644 --- a/packages/compiler-core/src/codegen.ts +++ b/packages/compiler-core/src/codegen.ts @@ -572,8 +572,9 @@ function genHoists(hoists: (JSChildNode | null)[], context: CodegenContext) { // generate inlined withScopeId helper if (genScopeId) { + const param = context.isTS ? '(n: any)' : 'n' push( - `const _withScopeId = n => (${helper( + `const _withScopeId = ${param} => (${helper( PUSH_SCOPE_ID, )}("${scopeId}"),n=n(),${helper(POP_SCOPE_ID)}(),n)`, ) From 3a0b463a2c2e288dfe6850b9cb235f12419f32a6 Mon Sep 17 00:00:00 2001 From: Haoqun Jiang Date: Thu, 30 May 2024 18:22:11 +0800 Subject: [PATCH 009/125] chore: fix typo (DistrubuteRef -> DistributeRef) (#11040) --- packages/reactivity/src/ref.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/reactivity/src/ref.ts b/packages/reactivity/src/ref.ts index 5f40fbb7c28..bd121e47d46 100644 --- a/packages/reactivity/src/ref.ts +++ b/packages/reactivity/src/ref.ts @@ -496,10 +496,10 @@ type BaseTypes = string | number | boolean export interface RefUnwrapBailTypes {} export type ShallowUnwrapRef = { - [K in keyof T]: DistrubuteRef + [K in keyof T]: DistributeRef } -type DistrubuteRef = T extends Ref ? V : T +type DistributeRef = T extends Ref ? V : T export type UnwrapRef = T extends ShallowRef From 70f2f283eee1f34330d38687e5e6d69e2f1d371b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=BF=9C=E6=96=B9os?= Date: Thu, 30 May 2024 18:27:38 +0800 Subject: [PATCH 010/125] refactor(types/compat): improve the types for $set and $delete (#8719) --- packages/runtime-core/src/compat/instance.ts | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/packages/runtime-core/src/compat/instance.ts b/packages/runtime-core/src/compat/instance.ts index 18e745ca4e8..7b89c5ad61c 100644 --- a/packages/runtime-core/src/compat/instance.ts +++ b/packages/runtime-core/src/compat/instance.ts @@ -43,8 +43,15 @@ export type LegacyPublicInstance = ComponentPublicInstance & LegacyPublicProperties export interface LegacyPublicProperties { - $set(target: object, key: string, value: any): void - $delete(target: object, key: string): void + $set, K extends keyof T>( + target: T, + key: K, + value: T[K] + ): void + $delete, K extends keyof T>( + target: T, + key: K + ): void $mount(el?: string | Element): this $destroy(): void $scopedSlots: Slots From f8994da00f523d5d792997671f4f55eca43d6598 Mon Sep 17 00:00:00 2001 From: Alex Liu Date: Thu, 30 May 2024 19:41:38 +0800 Subject: [PATCH 011/125] types: improve readability of built-in type (#9129) --- packages/reactivity/src/reactive.ts | 2 +- packages/reactivity/src/ref.ts | 10 ++-------- packages/runtime-core/src/compat/instance.ts | 4 ++-- 3 files changed, 5 insertions(+), 11 deletions(-) diff --git a/packages/reactivity/src/reactive.ts b/packages/reactivity/src/reactive.ts index a3e7ecc7b56..6e28be404fa 100644 --- a/packages/reactivity/src/reactive.ts +++ b/packages/reactivity/src/reactive.ts @@ -135,7 +135,7 @@ export function shallowReactive( } type Primitive = string | number | boolean | bigint | symbol | undefined | null -type Builtin = Primitive | Function | Date | Error | RegExp +export type Builtin = Primitive | Function | Date | Error | RegExp export type DeepReadonly = T extends Builtin ? T : T extends Map diff --git a/packages/reactivity/src/ref.ts b/packages/reactivity/src/ref.ts index bd121e47d46..99170d154ba 100644 --- a/packages/reactivity/src/ref.ts +++ b/packages/reactivity/src/ref.ts @@ -21,7 +21,7 @@ import { toRaw, toReactive, } from './reactive' -import type { ShallowReactiveMarker } from './reactive' +import type { Builtin, ShallowReactiveMarker } from './reactive' import { type Dep, createDep } from './dep' import { ComputedRefImpl } from './computed' import { getDepFromReactive } from './reactiveEffect' @@ -475,11 +475,6 @@ function propertyToRef( : (new ObjectRefImpl(source, key, defaultValue) as any) } -// corner case when use narrows type -// Ex. type RelativePath = string & { __brand: unknown } -// RelativePath extends object -> true -type BaseTypes = string | number | boolean - /** * This is a special exported interface for other packages to declare * additional types that should bail out for ref unwrapping. For example @@ -509,8 +504,7 @@ export type UnwrapRef = : UnwrapRefSimple export type UnwrapRefSimple = T extends - | Function - | BaseTypes + | Builtin | Ref | RefUnwrapBailTypes[keyof RefUnwrapBailTypes] | { [RawSymbol]?: true } diff --git a/packages/runtime-core/src/compat/instance.ts b/packages/runtime-core/src/compat/instance.ts index 7b89c5ad61c..3fa7b454c79 100644 --- a/packages/runtime-core/src/compat/instance.ts +++ b/packages/runtime-core/src/compat/instance.ts @@ -46,11 +46,11 @@ export interface LegacyPublicProperties { $set, K extends keyof T>( target: T, key: K, - value: T[K] + value: T[K], ): void $delete, K extends keyof T>( target: T, - key: K + key: K, ): void $mount(el?: string | Element): this $destroy(): void From 34a97edd2c8273c213599c44770accdb0846da8e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kevin=20Deng=20=E4=B8=89=E5=92=B2=E6=99=BA=E5=AD=90?= Date: Fri, 31 May 2024 17:08:54 +0800 Subject: [PATCH 012/125] fix(compiler-sfc): throw error when import macro as alias (#11041) --- packages/compiler-sfc/src/compileScript.ts | 48 ++++++++++++++-------- 1 file changed, 32 insertions(+), 16 deletions(-) diff --git a/packages/compiler-sfc/src/compileScript.ts b/packages/compiler-sfc/src/compileScript.ts index 31bee3af74d..8a0aaeaf717 100644 --- a/packages/compiler-sfc/src/compileScript.ts +++ b/packages/compiler-sfc/src/compileScript.ts @@ -49,7 +49,7 @@ import { } from './script/defineEmits' import { DEFINE_EXPOSE, processDefineExpose } from './script/defineExpose' import { DEFINE_OPTIONS, processDefineOptions } from './script/defineOptions' -import { processDefineSlots } from './script/defineSlots' +import { DEFINE_SLOTS, processDefineSlots } from './script/defineSlots' import { DEFINE_MODEL, processDefineModel } from './script/defineModel' import { getImportedName, isCallOf, isLiteralNode } from './script/utils' import { analyzeScriptBindings } from './script/analyzeScriptBindings' @@ -135,6 +135,16 @@ export interface ImportBinding { isUsedInTemplate: boolean } +const MACROS = [ + DEFINE_PROPS, + DEFINE_EMITS, + DEFINE_EXPOSE, + DEFINE_OPTIONS, + DEFINE_SLOTS, + DEFINE_MODEL, + WITH_DEFAULTS, +] + /** * Compile `