Skip to content

wip(jsx-vapor): this is a collection of my pull requests for pkg.pr.new (don't merge!) #13061

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 35 commits into
base: vapor
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
5fdc953
fix(runtime-vapor): prevent passing an empty string to classList.add
zhiyuanzmj Mar 2, 2025
704fee9
feat(compiler-vapor): support custom generate operation
zhiyuanzmj Mar 16, 2025
efaa5b1
feat(compiler-vapor): support keys and nonKeys modifier for component…
zhiyuanzmj Mar 17, 2025
c50fb0e
fix(compiler-vapor): move setInsertionState to the end to prevent nth…
zhiyuanzmj Mar 17, 2025
015e1ee
fix(compiler-vapor): move `next`, `child` and `nthChild` before the s…
zhiyuanzmj Mar 18, 2025
d1cc06a
Merge branch 'component-modifiers' into jsx-vapor
zhiyuanzmj Mar 18, 2025
0929434
Merge branch 'custom-gen-operation' into jsx-vapor
zhiyuanzmj Mar 18, 2025
13f3ab1
feat: remove __BROWSER__ flag
zhiyuanzmj Mar 18, 2025
eeab9c4
Merge branch 'vapor-runtime-class-list' into jsx-vapor
zhiyuanzmj Mar 18, 2025
8dda0b1
feat(runtime-core): expose pauseTracking and enableTracking
zhiyuanzmj Mar 19, 2025
361c7d4
feat: export resetTracking
zhiyuanzmj Mar 19, 2025
8b7a035
fix: use modelValueModifiers intead of modelModifiers
zhiyuanzmj Mar 19, 2025
9df9281
feat: use for vapor
zhiyuanzmj Mar 20, 2025
d8dd1ff
Merge branch 'fix-define-model' into jsx-vapor
zhiyuanzmj Mar 20, 2025
3e7464f
Merge branch 'export-pauseTracking' into jsx-vapor
zhiyuanzmj Mar 20, 2025
f264ceb
feat(runtime-vapor): support HMR for setup
zhiyuanzmj Mar 25, 2025
b43f4f5
Merge branch 'setup-hmr' into jsx-vapor
zhiyuanzmj Mar 25, 2025
9ab8e4c
chore: update lockfile
edison1105 Apr 1, 2025
09bc000
feat(runtime-vapor): support HMR for setup
zhiyuanzmj Mar 25, 2025
e1f2b08
Merge branch 'vapor' into jsx-vapor
zhiyuanzmj Apr 25, 2025
950bd84
fix(compiler-vapor): prevent caching variables in function expression
zhiyuanzmj Apr 26, 2025
73dc7ed
chore: revert
zhiyuanzmj Apr 26, 2025
b6687fb
Merge branch 'vapor' into fix-cache-variable
zhiyuanzmj Apr 26, 2025
42f38ca
Merge branch 'fix-cache-variable' into jsx-vapor
zhiyuanzmj Apr 26, 2025
d1c4d84
feat(runtime-vapor): add normalizeNode to support non-block nodes
zhiyuanzmj May 7, 2025
2684546
chore: revert docs
zhiyuanzmj May 7, 2025
172df6a
feat(runtime-vapor): support HMR for setup
zhiyuanzmj Mar 25, 2025
41ad10c
chore: revert
zhiyuanzmj Apr 26, 2025
e19086d
chore: merge branch 'vapor' into normalize-node
zhiyuanzmj May 11, 2025
6550188
chore: update deps
zhiyuanzmj May 11, 2025
912b7dc
chore: update deps
zhiyuanzmj May 11, 2025
bb083de
chore: update deps
zhiyuanzmj May 11, 2025
f5caae0
feat(runtime-vapor): expose isVaporComponent
zhiyuanzmj May 11, 2025
bafba42
chore: Merge branch 'expose-isVaporComponent' into jsx-vapor
zhiyuanzmj May 11, 2025
d386396
chore: Merge branch 'normalize-node' into jsx-vapor
zhiyuanzmj May 11, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions packages/compiler-core/__tests__/transforms/vModel.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -449,7 +449,7 @@ describe('compiler: transform v-model', () => {
expect(codegen.dynamicProps).toBe(`["modelValue", "onUpdate:modelValue"]`)
})

test('should generate modelModifiers for component v-model', () => {
test('should generate modelValueModifiers for component v-model', () => {
const root = parseWithVModel('<Comp v-model.trim.bar-baz="foo" />', {
prefixIdentifiers: true,
})
Expand All @@ -461,15 +461,15 @@ describe('compiler: transform v-model', () => {
{ key: { content: `modelValue` } },
{ key: { content: `onUpdate:modelValue` } },
{
key: { content: 'modelModifiers' },
key: { content: 'modelValueModifiers' },
value: {
content: `{ trim: true, "bar-baz": true }`,
isStatic: false,
},
},
],
})
// should NOT include modelModifiers in dynamicPropNames because it's never
// should NOT include modelValueModifiers in dynamicPropNames because it's never
// gonna change
expect(vnodeCall.dynamicProps).toBe(`["modelValue", "onUpdate:modelValue"]`)
})
Expand Down
8 changes: 0 additions & 8 deletions packages/compiler-core/src/babelUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,6 @@ export function walkIdentifiers(
parentStack: Node[] = [],
knownIds: Record<string, number> = Object.create(null),
): void {
if (__BROWSER__) {
return
}

const rootExp =
root.type === 'Program'
? root.body[0].type === 'ExpressionStatement' && root.body[0].expression
Expand Down Expand Up @@ -110,10 +106,6 @@ export function isReferencedIdentifier(
parent: Node | null,
parentStack: Node[],
): boolean {
if (__BROWSER__) {
return false
}

if (!parent) {
return true
}
Expand Down
2 changes: 1 addition & 1 deletion packages/compiler-core/src/transforms/vModel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ export const transformModel: DirectiveTransform = (dir, node, context) => {
? isStaticExp(arg)
? `${arg.content}Modifiers`
: createCompoundExpression([arg, ' + "Modifiers"'])
: `modelModifiers`
: `modelValueModifiers`
props.push(
createObjectProperty(
modifiersKey,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ exports[`defineModel() > basic usage 1`] = `
export default {
props: {
"modelValue": { required: true },
"modelModifiers": {},
"modelValueModifiers": {},
"count": {},
"countModifiers": {},
"toString": { type: Function },
Expand Down Expand Up @@ -34,7 +34,7 @@ export default /*@__PURE__*/_defineComponent({
"modelValue": {
required: true
},
"modelModifiers": {},
"modelValueModifiers": {},
},
emits: ["update:modelValue"],
setup(__props, { expose: __expose }) {
Expand All @@ -60,7 +60,7 @@ export default /*@__PURE__*/_defineComponent({
default: 0,
required: true,
},
"modelModifiers": {},
"modelValueModifiers": {},
},
emits: ["update:modelValue"],
setup(__props, { expose: __expose }) {
Expand All @@ -86,7 +86,7 @@ export default /*@__PURE__*/_defineComponent({
}, {
"modelValue": {
},
"modelModifiers": {},
"modelValueModifiers": {},
}),
emits: ["update:modelValue"],
setup(__props: any, { expose: __expose }) {
Expand All @@ -109,7 +109,7 @@ exports[`defineModel() > w/ Boolean And Function types, production mode 1`] = `
export default /*@__PURE__*/_defineComponent({
props: {
"modelValue": { type: [Boolean, String] },
"modelModifiers": {},
"modelValueModifiers": {},
},
emits: ["update:modelValue"],
setup(__props, { expose: __expose }) {
Expand Down Expand Up @@ -150,7 +150,7 @@ exports[`defineModel() > w/ defineProps and defineEmits 1`] = `
export default {
props: /*@__PURE__*/_mergeModels({ foo: String }, {
"modelValue": { default: 0 },
"modelModifiers": {},
"modelValueModifiers": {},
}),
emits: /*@__PURE__*/_mergeModels(['change'], ["update:modelValue"]),
setup(__props, { expose: __expose }) {
Expand All @@ -172,7 +172,7 @@ exports[`defineModel() > w/ types, basic usage 1`] = `
export default /*@__PURE__*/_defineComponent({
props: {
"modelValue": { type: [Boolean, String] },
"modelModifiers": {},
"modelValueModifiers": {},
"count": { type: Number },
"countModifiers": {},
"disabled": { type: Number, ...{ required: false } },
Expand Down Expand Up @@ -201,7 +201,7 @@ exports[`defineModel() > w/ types, production mode 1`] = `
export default /*@__PURE__*/_defineComponent({
props: {
"modelValue": { type: Boolean },
"modelModifiers": {},
"modelValueModifiers": {},
"fn": {},
"fnModifiers": {},
"fnWithDefault": { type: Function, ...{ default: () => null } },
Expand Down Expand Up @@ -233,7 +233,7 @@ exports[`defineModel() > w/ types, production mode, boolean + multiple types 1`]
export default /*@__PURE__*/_defineComponent({
props: {
"modelValue": { type: [Boolean, String, Object] },
"modelModifiers": {},
"modelValueModifiers": {},
},
emits: ["update:modelValue"],
setup(__props, { expose: __expose }) {
Expand All @@ -253,7 +253,7 @@ exports[`defineModel() > w/ types, production mode, function + runtime opts + mu
export default /*@__PURE__*/_defineComponent({
props: {
"modelValue": { type: [Number, Function], ...{ default: () => 1 } },
"modelModifiers": {},
"modelValueModifiers": {},
},
emits: ["update:modelValue"],
setup(__props, { expose: __expose }) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ describe('defineModel()', () => {
)
assertCode(content)
expect(content).toMatch('"modelValue": { type: [Boolean, String] }')
expect(content).toMatch('"modelModifiers": {}')
expect(content).toMatch('"modelValueModifiers": {}')
expect(content).toMatch('"count": { type: Number }')
expect(content).toMatch(
'"disabled": { type: Number, ...{ required: false } }',
Expand Down
4 changes: 1 addition & 3 deletions packages/compiler-sfc/src/script/defineModel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -167,9 +167,7 @@ export function genModelProps(ctx: ScriptCompileContext) {
modelPropsDecl += `\n ${JSON.stringify(name)}: ${decl},`

// also generate modifiers prop
const modifierPropName = JSON.stringify(
name === 'modelValue' ? `modelModifiers` : `${name}Modifiers`,
)
const modifierPropName = JSON.stringify(`${name}Modifiers`)
modelPropsDecl += `\n ${modifierPropName}: {},`
}
return `{${modelPropsDecl}\n }`
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -157,9 +157,9 @@ export function render(_ctx, $props, $emit, $attrs, $slots) {
const _component_Comp = _resolveComponent("Comp")
const n0 = t0()
const n3 = t1()
const n2 = _child(n3)
_setInsertionState(n3, 0)
const n1 = _createComponentWithFallback(_component_Comp)
const n2 = _child(n3)
_renderEffect(() => {
_setText(n2, _toDisplayString(_ctx.bar))
_setProp(n3, "id", _ctx.foo)
Expand Down Expand Up @@ -230,6 +230,30 @@ export function render(_ctx) {
}"
`;

exports[`compile > setInsertionState > next, child and nthChild should be above the setInsertionState 1`] = `
"import { resolveComponent as _resolveComponent, child as _child, next as _next, setInsertionState as _setInsertionState, createComponentWithFallback as _createComponentWithFallback, nthChild as _nthChild, createIf as _createIf, setProp as _setProp, renderEffect as _renderEffect, template as _template } from 'vue';
const t0 = _template("<div></div>")
const t1 = _template("<div><div></div><!><div></div><!><div><button></button></div></div>", true)

export function render(_ctx) {
const _component_Comp = _resolveComponent("Comp")
const n6 = t1()
const n5 = _next(_child(n6))
const n7 = _nthChild(n6, 3)
const p0 = _next(n7)
const n4 = _child(p0)
_setInsertionState(n6, n5)
const n0 = _createComponentWithFallback(_component_Comp)
_setInsertionState(n6, n7)
const n1 = _createIf(() => (true), () => {
const n3 = t0()
return n3
})
_renderEffect(() => _setProp(n4, "disabled", _ctx.foo))
return n6
}"
`;

exports[`compile > static + dynamic root 1`] = `
"import { toDisplayString as _toDisplayString, setText as _setText, template as _template } from 'vue';
const t0 = _template(" ")
Expand Down
17 changes: 17 additions & 0 deletions packages/compiler-vapor/__tests__/compile.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -220,4 +220,21 @@ describe('compile', () => {
expect(code).matchSnapshot()
})
})

describe('setInsertionState', () => {
test('next, child and nthChild should be above the setInsertionState', () => {
const code = compile(`
<div>
<div />
<Comp />
<div />
<div v-if="true" />
<div>
<button :disabled="foo" />
</div>
</div>
`)
expect(code).toMatchSnapshot()
})
})
})
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,36 @@ export function render(_ctx) {
}"
`;

exports[`compiler: element transform > component event with keys modifier 1`] = `
"import { resolveComponent as _resolveComponent, withKeys as _withKeys, createComponentWithFallback as _createComponentWithFallback } from 'vue';

export function render(_ctx) {
const _component_Foo = _resolveComponent("Foo")
const n0 = _createComponentWithFallback(_component_Foo, { onKeyup: () => _withKeys(_ctx.bar, ["enter"]) }, null, true)
return n0
}"
`;

exports[`compiler: element transform > component event with multiple modifiers and event options 1`] = `
"import { resolveComponent as _resolveComponent, withModifiers as _withModifiers, withKeys as _withKeys, createComponentWithFallback as _createComponentWithFallback } from 'vue';

export function render(_ctx) {
const _component_Foo = _resolveComponent("Foo")
const n0 = _createComponentWithFallback(_component_Foo, { onFooCaptureOnce: () => _withKeys(_withModifiers(_ctx.bar, ["stop","prevent"]), ["enter"]) }, null, true)
return n0
}"
`;

exports[`compiler: element transform > component event with nonKeys modifier 1`] = `
"import { resolveComponent as _resolveComponent, withModifiers as _withModifiers, createComponentWithFallback as _createComponentWithFallback } from 'vue';

export function render(_ctx) {
const _component_Foo = _resolveComponent("Foo")
const n0 = _createComponentWithFallback(_component_Foo, { onFoo: () => _withModifiers(_ctx.bar, ["stop","prevent"]) }, null, true)
return n0
}"
`;

exports[`compiler: element transform > component event with once modifier 1`] = `
"import { resolveComponent as _resolveComponent, createComponentWithFallback as _createComponentWithFallback } from 'vue';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,19 @@ export function render(_ctx) {
}"
`;

exports[`compiler: template ref transform > function ref 1`] = `
"import { createTemplateRefSetter as _createTemplateRefSetter, renderEffect as _renderEffect, template as _template } from 'vue';
const t0 = _template("<div></div>", true)

export function render(_ctx) {
const _setTemplateRef = _createTemplateRefSetter()
const n0 = t0()
let r0
_renderEffect(() => r0 = _setTemplateRef(n0, bar => _ctx.foo = bar, r0))
return n0
}"
`;

exports[`compiler: template ref transform > ref + v-for 1`] = `
"import { createTemplateRefSetter as _createTemplateRefSetter, createFor as _createFor, template as _template } from 'vue';
const t0 = _template("<div></div>", true)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,17 @@ export function render(_ctx) {
}"
`;

exports[`cache multiple access > not cache variable in function expression 1`] = `
"import { setDynamicProps as _setDynamicProps, renderEffect as _renderEffect, template as _template } from 'vue';
const t0 = _template("<div></div>", true)

export function render(_ctx) {
const n0 = t0()
_renderEffect(() => _setDynamicProps(n0, [{ foo: bar => _ctx.foo = bar }], true))
return n0
}"
`;

exports[`cache multiple access > not cache variable only used in property shorthand 1`] = `
"import { setStyle as _setStyle, renderEffect as _renderEffect, template as _template } from 'vue';
const t0 = _template("<div></div>", true)
Expand All @@ -86,6 +97,17 @@ export function render(_ctx) {
}"
`;

exports[`cache multiple access > not cache variable with inline function 1`] = `
"import { setDynamicProps as _setDynamicProps, renderEffect as _renderEffect, template as _template } from 'vue';
const t0 = _template("<div></div>", true)

export function render(_ctx) {
const n0 = t0()
_renderEffect(() => _setDynamicProps(n0, [{ foo: bar => _ctx.foo = bar }], true))
return n0
}"
`;

exports[`cache multiple access > object property chain access 1`] = `
"import { setProp as _setProp, renderEffect as _renderEffect, template as _template } from 'vue';
const t0 = _template("<div></div>")
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html

exports[`compiler: vModel transform > component > v-model for component should generate modelModifiers 1`] = `
exports[`compiler: vModel transform > component > v-model for component should generate modelValueModifiers 1`] = `
"import { resolveComponent as _resolveComponent, createComponentWithFallback as _createComponentWithFallback } from 'vue';

export function render(_ctx) {
const _component_Comp = _resolveComponent("Comp")
const n0 = _createComponentWithFallback(_component_Comp, { modelValue: () => (_ctx.foo),
"onUpdate:modelValue": () => _value => (_ctx.foo = _value),
modelModifiers: () => ({ trim: true, "bar-baz": true }) }, null, true)
modelValueModifiers: () => ({ trim: true, "bar-baz": true }) }, null, true)
return n0
}"
`;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,8 @@ describe('compiler: children transform', () => {
</div>`,
)
// ensure the insertion anchor is generated before the insertion statement
expect(code).toMatch(`const n3 = _next(_child(n4))
_setInsertionState(n4, n3)`)
expect(code).toMatch(`const n3 = _next(_child(n4))`)
expect(code).toMatch(`_setInsertionState(n4, n3)`)
expect(code).toMatchSnapshot()
})
})
Loading