Skip to content

Commit

Permalink
Merge branch 'main' into feature-dynamic-for-slot
Browse files Browse the repository at this point in the history
  • Loading branch information
Doctor-wu committed May 12, 2024
2 parents bc1b230 + 72589be commit 84cac2d
Show file tree
Hide file tree
Showing 81 changed files with 1,346 additions and 506 deletions.
30 changes: 30 additions & 0 deletions CHANGELOG.md
@@ -1,3 +1,33 @@
# [3.5.0-alpha.2](https://github.com/vuejs/core/compare/v3.4.26...v3.5.0-alpha.2) (2024-05-04)


### Bug Fixes

* **types:** fix app.component() typing with inline defineComponent ([908f70a](https://github.com/vuejs/core/commit/908f70adc06038d1ea253d96f4024367f4a7545d)), closes [#10843](https://github.com/vuejs/core/issues/10843)
* **types:** fix compat with generated types that rely on CreateComponentPublicInstance ([c146186](https://github.com/vuejs/core/commit/c146186396d0c1a65423b8c9a21251c5a6467336)), closes [#10842](https://github.com/vuejs/core/issues/10842)
* **types:** props in defineOptions type should be optional ([124c4ca](https://github.com/vuejs/core/commit/124c4cac833a28ae9bc8edc576c1d0c7c41f5985)), closes [#10841](https://github.com/vuejs/core/issues/10841)


### Features

* **runtime-core:** add app.onUnmount() for registering cleanup functions ([#4619](https://github.com/vuejs/core/issues/4619)) ([582a3a3](https://github.com/vuejs/core/commit/582a3a382b1adda565bac576b913a88d9e8d7a9e)), closes [#4516](https://github.com/vuejs/core/issues/4516)



## [3.4.26](https://github.com/vuejs/core/compare/v3.4.25...v3.4.26) (2024-04-29)


### Bug Fixes

* **compiler-core:** fix bail constant for globals ([fefce06](https://github.com/vuejs/core/commit/fefce06b41e3b75de3d748dc6399628ec5056e78))
* **compiler-core:** remove unnecessary constant bail check ([09b4df8](https://github.com/vuejs/core/commit/09b4df809e59ef5f4bc91acfc56dc8f82a8e243a)), closes [#10807](https://github.com/vuejs/core/issues/10807)
* **runtime-core:** attrs should be readonly in functional components ([#10767](https://github.com/vuejs/core/issues/10767)) ([e8fd644](https://github.com/vuejs/core/commit/e8fd6446d14a6899e5e8ab1ee394d90088e01844))
* **runtime-core:** ensure slot compiler marker writable ([#10825](https://github.com/vuejs/core/issues/10825)) ([9c2de62](https://github.com/vuejs/core/commit/9c2de6244cd44bc5fbfd82b5850c710ce725044f)), closes [#10818](https://github.com/vuejs/core/issues/10818)
* **runtime-core:** properly handle inherit transition during clone VNode ([#10809](https://github.com/vuejs/core/issues/10809)) ([638a79f](https://github.com/vuejs/core/commit/638a79f64a7e184f2a2c65e21d764703f4bda561)), closes [#3716](https://github.com/vuejs/core/issues/3716) [#10497](https://github.com/vuejs/core/issues/10497) [#4091](https://github.com/vuejs/core/issues/4091)
* **Transition:** re-fix [#10620](https://github.com/vuejs/core/issues/10620) ([#10832](https://github.com/vuejs/core/issues/10832)) ([accf839](https://github.com/vuejs/core/commit/accf8396ae1c9dd49759ba0546483f1d2c70c9bc)), closes [#10632](https://github.com/vuejs/core/issues/10632) [#10827](https://github.com/vuejs/core/issues/10827)



# [3.5.0-alpha.1](https://github.com/vuejs/core/compare/v3.4.25...v3.5.0-alpha.1) (2024-04-29)


Expand Down
24 changes: 12 additions & 12 deletions package.json
@@ -1,7 +1,7 @@
{
"private": true,
"version": "3.0.0-vapor",
"packageManager": "[email protected].5",
"packageManager": "[email protected].6",
"type": "module",
"scripts": {
"dev": "node scripts/dev.js vue vue-vapor",
Expand Down Expand Up @@ -72,16 +72,16 @@
"@types/minimist": "^1.2.5",
"@types/node": "^20.12.7",
"@types/semver": "^7.5.8",
"@vitest/coverage-istanbul": "^1.5.0",
"@vitest/ui": "^1.5.0",
"@vitest/coverage-istanbul": "^1.5.2",
"@vitest/ui": "^1.5.2",
"@vue/consolidate": "1.0.0",
"conventional-changelog-cli": "^4.1.0",
"enquirer": "^2.4.1",
"esbuild": "^0.20.2",
"esbuild-plugin-polyfill-node": "^0.3.0",
"eslint": "^9.0.0",
"eslint": "^9.1.1",
"eslint-plugin-import-x": "^0.5.0",
"eslint-plugin-vitest": "^0.5.3",
"eslint-plugin-vitest": "^0.5.4",
"estree-walker": "^2.0.2",
"execa": "^8.0.1",
"jsdom": "^24.0.0",
Expand All @@ -96,23 +96,23 @@
"prettier": "^3.2.5",
"pretty-bytes": "^6.1.1",
"pug": "^3.0.2",
"puppeteer": "~22.6.5",
"puppeteer": "~22.7.1",
"rimraf": "^5.0.5",
"rollup": "^4.16.1",
"rollup": "^4.17.1",
"rollup-plugin-dts": "^6.1.0",
"rollup-plugin-esbuild": "^6.1.1",
"rollup-plugin-polyfill-node": "^0.13.0",
"semver": "^7.6.0",
"serve": "^14.2.1",
"serve": "^14.2.3",
"simple-git-hooks": "^2.11.1",
"terser": "^5.30.3",
"terser": "^5.30.4",
"todomvc-app-css": "^2.4.3",
"tslib": "^2.6.2",
"tsx": "^4.7.2",
"tsx": "^4.7.3",
"typescript": "~5.4.5",
"typescript-eslint": "^7.6.0",
"typescript-eslint": "^7.7.1",
"vite": "^5.2.10",
"vitest": "^1.5.0"
"vitest": "^1.5.2"
},
"pnpm": {
"peerDependencyRules": {
Expand Down
Expand Up @@ -421,6 +421,31 @@ describe('compiler: expression transform', () => {
})
})

// #10807
test('should not bail constant on strings w/ ()', () => {
const node = parseWithExpressionTransform(
`{{ { foo: 'ok()' } }}`,
) as InterpolationNode
expect(node.content).toMatchObject({
constType: ConstantTypes.CAN_STRINGIFY,
})
})

test('should bail constant for global identifiers w/ new or call expressions', () => {
const node = parseWithExpressionTransform(
`{{ new Date().getFullYear() }}`,
) as InterpolationNode
expect(node.content).toMatchObject({
children: [
'new ',
{ constType: ConstantTypes.NOT_CONSTANT },
'().',
{ constType: ConstantTypes.NOT_CONSTANT },
'()',
],
})
})

describe('ES Proposals support', () => {
test('bigInt', () => {
const node = parseWithExpressionTransform(
Expand Down
2 changes: 1 addition & 1 deletion packages/compiler-core/package.json
@@ -1,6 +1,6 @@
{
"name": "@vue/compiler-core",
"version": "3.5.0-alpha.1",
"version": "3.5.0-alpha.2",
"description": "@vue/compiler-core",
"main": "index.js",
"module": "dist/compiler-core.esm-bundler.js",
Expand Down
3 changes: 3 additions & 0 deletions packages/compiler-core/src/babelUtils.ts
Expand Up @@ -10,6 +10,9 @@ import type {
} from '@babel/types'
import { walk } from 'estree-walker'

/**
* Return value indicates whether the AST walked can be a constant
*/
export function walkIdentifiers(
root: Node,
onIdentifier: (
Expand Down
15 changes: 8 additions & 7 deletions packages/compiler-core/src/parser.ts
Expand Up @@ -179,7 +179,7 @@ const tokenizer = new Tokenizer(stack, {
const name = currentOpenTag!.tag
currentOpenTag!.isSelfClosing = true
endOpenTag(end)
if (stack[0]?.tag === name) {
if (stack[0] && stack[0].tag === name) {
onCloseTag(stack.shift()!, end)
}
},
Expand Down Expand Up @@ -587,14 +587,14 @@ function endOpenTag(end: number) {

function onText(content: string, start: number, end: number) {
if (__BROWSER__) {
const tag = stack[0]?.tag
const tag = stack[0] && stack[0].tag
if (tag !== 'script' && tag !== 'style' && content.includes('&')) {
content = currentOptions.decodeEntities!(content, false)
}
}
const parent = stack[0] || currentRoot
const lastNode = parent.children[parent.children.length - 1]
if (lastNode?.type === NodeTypes.TEXT) {
if (lastNode && lastNode.type === NodeTypes.TEXT) {
// merge
lastNode.content += content
setLocEnd(lastNode.loc, end)
Expand Down Expand Up @@ -771,7 +771,8 @@ function isComponent({ tag, props }: ElementNode): boolean {
tag === 'component' ||
isUpperCase(tag.charCodeAt(0)) ||
isCoreComponent(tag) ||
currentOptions.isBuiltInComponent?.(tag) ||
(currentOptions.isBuiltInComponent &&
currentOptions.isBuiltInComponent(tag)) ||
(currentOptions.isNativeTag && !currentOptions.isNativeTag(tag))
) {
return true
Expand Down Expand Up @@ -828,8 +829,8 @@ function condenseWhitespace(
if (node.type === NodeTypes.TEXT) {
if (!inPre) {
if (isAllWhitespace(node.content)) {
const prev = nodes[i - 1]?.type
const next = nodes[i + 1]?.type
const prev = nodes[i - 1] && nodes[i - 1].type
const next = nodes[i + 1] && nodes[i + 1].type
// Remove if:
// - the whitespace is the first or last node, or:
// - (condense mode) the whitespace is between two comments, or:
Expand Down Expand Up @@ -1063,7 +1064,7 @@ export function baseParse(input: string, options?: ParserOptions): RootNode {
currentOptions.ns === Namespaces.SVG ||
currentOptions.ns === Namespaces.MATH_ML

const delimiters = options?.delimiters
const delimiters = options && options.delimiters
if (delimiters) {
tokenizer.delimiterOpen = toCharCodes(delimiters[0])
tokenizer.delimiterClose = toCharCodes(delimiters[1])
Expand Down
17 changes: 7 additions & 10 deletions packages/compiler-core/src/transforms/transformExpression.ts
Expand Up @@ -48,10 +48,6 @@ export const isLiteralWhitelisted = /*#__PURE__*/ makeMap(
'true,false,null,this',
)

// a heuristic safeguard to bail constant expressions on presence of
// likely function invocation and member access
const constantBailRE = /\w\s*\(|\.[^\d]/

export const transformExpression: NodeTransform = (node, context) => {
if (node.type === NodeTypes.INTERPOLATION) {
node.content = processExpression(
Expand Down Expand Up @@ -228,8 +224,6 @@ export function processExpression(

// fast path if expression is a simple identifier.
const rawExp = node.content
// bail constant on parens (function invocation) and dot (member access)
const bailConstant = constantBailRE.test(rawExp)

let ast = node.ast

Expand Down Expand Up @@ -319,7 +313,12 @@ export function processExpression(
} else {
// The identifier is considered constant unless it's pointing to a
// local scope variable (a v-for alias, or a v-slot prop)
if (!(needPrefix && isLocal) && !bailConstant) {
if (
!(needPrefix && isLocal) &&
parent.type !== 'CallExpression' &&
parent.type !== 'NewExpression' &&
parent.type !== 'MemberExpression'
) {
;(node as QualifiedId).isConstant = true
}
// also generate sub-expressions for other identifiers for better
Expand Down Expand Up @@ -373,9 +372,7 @@ export function processExpression(
ret.ast = ast
} else {
ret = node
ret.constType = bailConstant
? ConstantTypes.NOT_CONSTANT
: ConstantTypes.CAN_STRINGIFY
ret.constType = ConstantTypes.CAN_STRINGIFY
}
ret.identifiers = Object.keys(knownIds)
return ret
Expand Down
2 changes: 1 addition & 1 deletion packages/compiler-dom/package.json
@@ -1,6 +1,6 @@
{
"name": "@vue/compiler-dom",
"version": "3.5.0-alpha.1",
"version": "3.5.0-alpha.2",
"description": "@vue/compiler-dom",
"main": "index.js",
"module": "dist/compiler-dom.esm-bundler.js",
Expand Down
2 changes: 1 addition & 1 deletion packages/compiler-sfc/package.json
@@ -1,6 +1,6 @@
{
"name": "@vue/compiler-sfc",
"version": "3.5.0-alpha.1",
"version": "3.5.0-alpha.2",
"description": "@vue/compiler-sfc",
"main": "dist/compiler-sfc.cjs.js",
"module": "dist/compiler-sfc.esm-browser.js",
Expand Down
2 changes: 1 addition & 1 deletion packages/compiler-ssr/package.json
@@ -1,6 +1,6 @@
{
"name": "@vue/compiler-ssr",
"version": "3.5.0-alpha.1",
"version": "3.5.0-alpha.2",
"description": "@vue/compiler-ssr",
"main": "dist/compiler-ssr.cjs.js",
"types": "dist/compiler-ssr.d.ts",
Expand Down
Expand Up @@ -46,3 +46,33 @@ export function render(_ctx) {
return n1
}"
`;

exports[`compiler: v-once > with v-if 1`] = `
"import { createIf as _createIf, template as _template } from 'vue/vapor';
const t0 = _template("<div></div>")
export function render(_ctx) {
const n0 = _createIf(() => (_ctx.expr), () => {
const n2 = t0()
return n2
}, null, true)
return n0
}"
`;

exports[`compiler: v-once > with v-if/else 1`] = `
"import { createIf as _createIf, template as _template } from 'vue/vapor';
const t0 = _template("<div></div>")
const t1 = _template("<p></p>")
export function render(_ctx) {
const n0 = _createIf(() => (_ctx.expr), () => {
const n2 = t0()
return n2
}, () => {
const n4 = t1()
return n4
}, true)
return n0
}"
`;
4 changes: 2 additions & 2 deletions packages/compiler-vapor/__tests__/transforms/vIf.spec.ts
Expand Up @@ -5,16 +5,16 @@ import {
transformChildren,
transformComment,
transformElement,
transformOnce,
transformText,
transformVIf,
transformVOnce,
transformVText,
} from '../../src'
import { NodeTypes } from '@vue/compiler-core'

const compileWithVIf = makeCompile({
nodeTransforms: [
transformOnce,
transformVOnce,
transformVIf,
transformText,
transformElement,
Expand Down
60 changes: 59 additions & 1 deletion packages/compiler-vapor/__tests__/transforms/vOnce.spec.ts
Expand Up @@ -146,6 +146,64 @@ describe('compiler: v-once', () => {
})

test.todo('with hoistStatic: true')
test.todo('with v-if/else')

test('with v-if', () => {
const { ir, code, helpers } = compileWithOnce(`<div v-if="expr" v-once />`)
expect(code).toMatchSnapshot()
expect(helpers).lengthOf(0)
expect(ir.block.effect).lengthOf(0)
expect(ir.block.operation).toMatchObject([
{
type: IRNodeTypes.IF,
id: 0,
once: true,
condition: {
type: NodeTypes.SIMPLE_EXPRESSION,
content: 'expr',
isStatic: false,
},
positive: {
type: IRNodeTypes.BLOCK,
dynamic: {
children: [{ template: 0 }],
},
},
},
])
})

test('with v-if/else', () => {
const { ir, code, helpers } = compileWithOnce(
`<div v-if="expr" v-once /><p v-else/>`,
)
expect(code).toMatchSnapshot()
expect(helpers).lengthOf(0)
expect(ir.block.effect).lengthOf(0)
expect(ir.block.operation).toMatchObject([
{
type: IRNodeTypes.IF,
id: 0,
once: true,
condition: {
type: NodeTypes.SIMPLE_EXPRESSION,
content: 'expr',
isStatic: false,
},
positive: {
type: IRNodeTypes.BLOCK,
dynamic: {
children: [{ template: 0 }],
},
},
negative: {
type: IRNodeTypes.BLOCK,
dynamic: {
children: [{ template: 1 }],
},
},
},
])
})

test.todo('with v-for')
})

0 comments on commit 84cac2d

Please sign in to comment.