Skip to content

Commit

Permalink
Merge pull request #137 from vuejs/main
Browse files Browse the repository at this point in the history
Update
  • Loading branch information
Tomxuetao authored Nov 14, 2023
2 parents 9c35969 + f18a174 commit 89ff65b
Show file tree
Hide file tree
Showing 71 changed files with 1,184 additions and 290 deletions.
22 changes: 11 additions & 11 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"private": true,
"version": "3.3.8",
"packageManager": "[email protected].2",
"packageManager": "[email protected].3",
"type": "module",
"scripts": {
"dev": "node scripts/dev.js",
Expand All @@ -27,9 +27,9 @@
"dev-esm": "node scripts/dev.js -if esm-bundler-runtime",
"dev-compiler": "run-p \"dev template-explorer\" serve",
"dev-sfc": "run-s dev-sfc-prepare dev-sfc-run",
"dev-sfc-prepare": "node scripts/pre-dev-sfc.js || npm run build-compiler-cjs",
"dev-sfc-prepare": "node scripts/pre-dev-sfc.js || npm run build-all-cjs",
"dev-sfc-serve": "vite packages/sfc-playground --host",
"dev-sfc-run": "run-p \"dev compiler-sfc -f esm-browser\" \"dev vue -if esm-bundler-runtime\" \"dev server-renderer -if esm-bundler\" dev-sfc-serve",
"dev-sfc-run": "run-p \"dev compiler-sfc -f esm-browser\" \"dev vue -if esm-bundler-runtime\" \"dev vue -ipf esm-browser-runtime\" \"dev server-renderer -if esm-bundler\" dev-sfc-serve",
"serve": "serve",
"open": "open http://localhost:3000/packages/template-explorer/local.html",
"build-sfc-playground": "run-s build-all-cjs build-runtime-esm build-ssr-esm build-sfc-playground-self",
Expand Down Expand Up @@ -57,24 +57,24 @@
"node": ">=18.12.0"
},
"devDependencies": {
"@babel/parser": "^7.23.0",
"@babel/types": "^7.23.0",
"@babel/parser": "^7.23.3",
"@babel/types": "^7.23.3",
"@rollup/plugin-alias": "^5.0.1",
"@rollup/plugin-commonjs": "^25.0.7",
"@rollup/plugin-json": "^6.0.1",
"@rollup/plugin-node-resolve": "^15.2.3",
"@rollup/plugin-replace": "^5.0.4",
"@rollup/plugin-terser": "^0.4.4",
"@types/hash-sum": "^1.0.1",
"@types/node": "^20.8.10",
"@typescript-eslint/parser": "^6.9.1",
"@types/hash-sum": "^1.0.2",
"@types/node": "^20.9.0",
"@typescript-eslint/parser": "^6.10.0",
"@vitest/coverage-istanbul": "^0.34.6",
"@vue/consolidate": "0.17.3",
"conventional-changelog-cli": "^4.1.0",
"enquirer": "^2.4.1",
"esbuild": "^0.19.5",
"esbuild-plugin-polyfill-node": "^0.3.0",
"eslint": "^8.52.0",
"eslint": "^8.53.0",
"eslint-plugin-jest": "^27.6.0",
"estree-walker": "^2.0.2",
"execa": "^8.0.1",
Expand All @@ -83,14 +83,14 @@
"lodash": "^4.17.21",
"magic-string": "^0.30.5",
"markdown-table": "^3.0.3",
"marked": "^9.1.4",
"marked": "^9.1.6",
"minimist": "^1.2.8",
"npm-run-all": "^4.1.5",
"picocolors": "^1.0.0",
"prettier": "^3.0.3",
"pretty-bytes": "^6.1.1",
"pug": "^3.0.2",
"puppeteer": "~21.4.1",
"puppeteer": "~21.5.1",
"rimraf": "^5.0.5",
"rollup": "^4.1.4",
"rollup-plugin-dts": "^6.1.0",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,45 @@ return function render(_ctx, _cache, $props, $setup, $data, $options) {
return (_openBlock(), _createElementBlock(\\"div\\", null, _toDisplayString($props.props) + \\" \\" + _toDisplayString($setup.setup) + \\" \\" + _toDisplayString($data.data) + \\" \\" + _toDisplayString($options.options) + \\" \\" + _toDisplayString($setup.isNaN), 1 /* TEXT */))
}"
`;

exports[`compiler: expression transform > bindingMetadata > should not prefix temp variable of for loop 1`] = `
"const { openBlock: _openBlock, createElementBlock: _createElementBlock } = Vue
return function render(_ctx, _cache, $props, $setup, $data, $options) {
return (_openBlock(), _createElementBlock(\\"div\\", {
onClick: () => {
for (let i = 0; i < _ctx.list.length; i++) {
_ctx.log(i)
}
}
}, null, 8 /* PROPS */, [\\"onClick\\"]))
}"
`;

exports[`compiler: expression transform > bindingMetadata > should not prefix temp variable of for...in 1`] = `
"const { openBlock: _openBlock, createElementBlock: _createElementBlock } = Vue
return function render(_ctx, _cache, $props, $setup, $data, $options) {
return (_openBlock(), _createElementBlock(\\"div\\", {
onClick: () => {
for (const x in _ctx.list) {
_ctx.log(x)
}
}
}, null, 8 /* PROPS */, [\\"onClick\\"]))
}"
`;

exports[`compiler: expression transform > bindingMetadata > should not prefix temp variable of for...of 1`] = `
"const { openBlock: _openBlock, createElementBlock: _createElementBlock } = Vue
return function render(_ctx, _cache, $props, $setup, $data, $options) {
return (_openBlock(), _createElementBlock(\\"div\\", {
onClick: () => {
for (const x of _ctx.list) {
_ctx.log(x)
}
}
}, null, 8 /* PROPS */, [\\"onClick\\"]))
}"
`;
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ return function render(_ctx, _cache) {
return (_openBlock(), _createElementBlock(\\"input\\", {
\\"foo-value\\": model,
\\"onUpdate:fooValue\\": $event => ((model) = $event)
}, null, 40 /* PROPS, HYDRATE_EVENTS */, [\\"foo-value\\", \\"onUpdate:fooValue\\"]))
}, null, 40 /* PROPS, NEED_HYDRATION */, [\\"foo-value\\", \\"onUpdate:fooValue\\"]))
}
}"
`;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1089,7 +1089,7 @@ describe('compiler: element transform', () => {
})
})

test('HYDRATE_EVENTS', () => {
test('NEED_HYDRATION for v-on', () => {
// ignore click events (has dedicated fast path)
const { node } = parseWithElementTransform(`<div @click="foo" />`, {
directiveTransforms: {
Expand All @@ -1108,12 +1108,24 @@ describe('compiler: element transform', () => {
}
)
expect(node2.patchFlag).toBe(
genFlagText([PatchFlags.PROPS, PatchFlags.HYDRATE_EVENTS])
genFlagText([PatchFlags.PROPS, PatchFlags.NEED_HYDRATION])
)
})

test('NEED_HYDRATION for v-bind.prop', () => {
const { node } = parseWithBind(`<div v-bind:id.prop="id" />`)
expect(node.patchFlag).toBe(
genFlagText([PatchFlags.PROPS, PatchFlags.NEED_HYDRATION])
)

const { node: node2 } = parseWithBind(`<div .id="id" />`)
expect(node2.patchFlag).toBe(
genFlagText([PatchFlags.PROPS, PatchFlags.NEED_HYDRATION])
)
})

// #5870
test('HYDRATE_EVENTS on dynamic component', () => {
test('NEED_HYDRATION on dynamic component', () => {
const { node } = parseWithElementTransform(
`<component :is="foo" @input="foo" />`,
{
Expand All @@ -1123,7 +1135,7 @@ describe('compiler: element transform', () => {
}
)
expect(node.patchFlag).toBe(
genFlagText([PatchFlags.PROPS, PatchFlags.HYDRATE_EVENTS])
genFlagText([PatchFlags.PROPS, PatchFlags.NEED_HYDRATION])
)
})
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -534,6 +534,42 @@ describe('compiler: expression transform', () => {
expect(code).toMatchSnapshot()
})

test('should not prefix temp variable of for...in', () => {
const { code } = compileWithBindingMetadata(
`<div @click="() => {
for (const x in list) {
log(x)
}
}"/>`
)
expect(code).not.toMatch(`_ctx.x`)
expect(code).toMatchSnapshot()
})

test('should not prefix temp variable of for...of', () => {
const { code } = compileWithBindingMetadata(
`<div @click="() => {
for (const x of list) {
log(x)
}
}"/>`
)
expect(code).not.toMatch(`_ctx.x`)
expect(code).toMatchSnapshot()
})

test('should not prefix temp variable of for loop', () => {
const { code } = compileWithBindingMetadata(
`<div @click="() => {
for (let i = 0; i < list.length; i++) {
log(i)
}
}"/>`
)
expect(code).not.toMatch(`_ctx.i`)
expect(code).toMatchSnapshot()
})

test('inline mode', () => {
const { code } = compileWithBindingMetadata(
`<div>{{ props }} {{ setup }} {{ setupConst }} {{ data }} {{ options }} {{ isNaN }}</div>`,
Expand Down
4 changes: 2 additions & 2 deletions packages/compiler-core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,12 @@
},
"homepage": "https://github.com/vuejs/core/tree/main/packages/compiler-core#readme",
"dependencies": {
"@babel/parser": "^7.23.0",
"@babel/parser": "^7.23.3",
"@vue/shared": "3.3.8",
"estree-walker": "^2.0.2",
"source-map-js": "^1.0.2"
},
"devDependencies": {
"@babel/types": "^7.23.0"
"@babel/types": "^7.23.3"
}
}
13 changes: 13 additions & 0 deletions packages/compiler-core/src/babelUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,19 @@ export function walkBlockDeclarations(
) {
if (stmt.declare || !stmt.id) continue
onIdent(stmt.id)
} else if (
stmt.type === 'ForOfStatement' ||
stmt.type === 'ForInStatement' ||
stmt.type === 'ForStatement'
) {
const variable = stmt.type === 'ForStatement' ? stmt.init : stmt.left
if (variable && variable.type === 'VariableDeclaration') {
for (const decl of variable.declarations) {
for (const id of extractIdentifiers(decl.id)) {
onIdent(id)
}
}
}
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion packages/compiler-core/src/parse.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1063,7 +1063,7 @@ function parseTextData(
) {
return rawText
} else {
// DATA or RCDATA containing "&"". Entity decoding required.
// DATA or RCDATA containing "&". Entity decoding is required.
return context.options.decodeEntities(
rawText,
mode === TextModes.ATTRIBUTE_VALUE
Expand Down
11 changes: 8 additions & 3 deletions packages/compiler-core/src/transforms/transformElement.ts
Original file line number Diff line number Diff line change
Expand Up @@ -550,7 +550,7 @@ export function buildProps(
)
} else {
// directives
const { name, arg, exp, loc } = prop
const { name, arg, exp, loc, modifiers } = prop
const isVBind = name === 'bind'
const isVOn = name === 'on'

Expand Down Expand Up @@ -678,6 +678,11 @@ export function buildProps(
continue
}

// force hydration for v-bind with .prop modifier
if (isVBind && modifiers.includes('prop')) {
patchFlag |= PatchFlags.NEED_HYDRATION
}

const directiveTransform = context.directiveTransforms[name]
if (directiveTransform) {
// has built-in directive transform.
Expand Down Expand Up @@ -743,12 +748,12 @@ export function buildProps(
patchFlag |= PatchFlags.PROPS
}
if (hasHydrationEventBinding) {
patchFlag |= PatchFlags.HYDRATE_EVENTS
patchFlag |= PatchFlags.NEED_HYDRATION
}
}
if (
!shouldUseBlock &&
(patchFlag === 0 || patchFlag === PatchFlags.HYDRATE_EVENTS) &&
(patchFlag === 0 || patchFlag === PatchFlags.NEED_HYDRATION) &&
(hasRef || hasVnodeHook || runtimeDirectives.length > 0)
) {
patchFlag |= PatchFlags.NEED_PATCH
Expand Down
4 changes: 2 additions & 2 deletions packages/compiler-core/src/transforms/vFor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,8 @@ import {
isTemplateNode,
isSlotOutlet,
injectProp,
findDir
findDir,
forAliasRE
} from '../utils'
import {
RENDER_LIST,
Expand Down Expand Up @@ -308,7 +309,6 @@ export function processFor(
}
}

const forAliasRE = /([\s\S]*?)\s+(?:in|of)\s+([\s\S]*)/
// This regex doesn't cover the case if key or index aliases have destructuring,
// but those do not make sense in the first place, so this works in practice.
const forIteratorRE = /,([^,\}\]]*)(?:,([^,\}\]]*))?$/
Expand Down
2 changes: 2 additions & 0 deletions packages/compiler-core/src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -519,3 +519,5 @@ export function getMemoedVNodeCall(node: BlockCodegenNode | MemoExpression) {
return node
}
}

export const forAliasRE = /([\s\S]*?)\s+(?:in|of)\s+([\s\S]*)/
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,7 @@ describe('stringify static html', () => {
}

function repeat(code: string, n: number): string {
return new Array(n)
.fill(0)
.map(() => code)
.join('')
return code.repeat(n)
}

test('should bail on non-eligible static trees', () => {
Expand Down
2 changes: 1 addition & 1 deletion packages/compiler-dom/__tests__/transforms/vOn.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,7 @@ describe('compiler-dom: transform v-on', () => {
// should not treat cached handler as dynamicProp, so it should have no
// dynamicProps flags and only the hydration flag
expect((root as any).children[0].codegenNode.patchFlag).toBe(
genFlagText(PatchFlags.HYDRATE_EVENTS)
genFlagText(PatchFlags.NEED_HYDRATION)
)
expect(prop).toMatchObject({
key: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,24 @@ return { emit }
})"
`;

exports[`defineEmits > w/ type (interface w/ extends) 1`] = `
"import { defineComponent as _defineComponent } from 'vue'
interface Base { (e: 'foo'): void }
interface Emits extends Base { (e: 'bar'): void }
export default /*#__PURE__*/_defineComponent({
emits: [\\"bar\\", \\"foo\\"],
setup(__props, { expose: __expose, emit: __emit }) {
__expose();
const emit = __emit
return { emit }
}
})"
`;

exports[`defineEmits > w/ type (interface) 1`] = `
"import { defineComponent as _defineComponent } from 'vue'
interface Emits { (e: 'foo' | 'bar'): void }
Expand Down
Loading

0 comments on commit 89ff65b

Please sign in to comment.