-
-
Notifications
You must be signed in to change notification settings - Fork 106
feat: implement inheritAttrs #153
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
Merged
Merged
Changes from 24 commits
Commits
Show all changes
34 commits
Select commit
Hold shift + click to select a range
bb26087
feat(vapor): implement inheritAttrs
Doctor-wu 7e1f592
feat(runtime-vapor): apply inheritAttrs to instance
Doctor-wu 9d8c1e5
feat(runtime-vapor): extract apiSetup & init setup ctx
Doctor-wu 20aa749
feat(runtime-vapor): add setup ctx type
Doctor-wu e4bc5ab
Revert "feat(runtime-vapor): add setup ctx type"
Doctor-wu 2f8b9af
Revert "feat(runtime-vapor): extract apiSetup & init setup ctx"
Doctor-wu 757aa74
feat(runtime-vapor): impl fallthrough attrs
Doctor-wu 2db5e19
test(runtime-vapor): tweak props test case
Doctor-wu 8498ba6
feat(runtime-vapor): update attrs when props update
Doctor-wu 1742efe
feat(runtime-vapor): remove unecessary property & use proper way to s…
Doctor-wu e082299
feat(runtime-vapor, compiler-vapor): add withAttr in singleRoot Compo…
Doctor-wu 5cab771
feat(runtime-vapor, compiler-vapor): resolve nest component attrs
Doctor-wu 1482a20
feat(compiler-vapor): remove unecessary clone props
Doctor-wu b3b6622
feat(runtime-vapor): clean code
Doctor-wu 791f533
chore(runtime-vapor): make lint happy
Doctor-wu f7d4c13
feat(runtime-vapor, compiler-vapor): make inheritAttrs reactive
Doctor-wu bdc1ee4
chore(runtime-vapor): remove unecessary code
Doctor-wu 35499bd
feat(runtime-vapor): should not withAttrs when component set inheritA…
Doctor-wu a474ac4
feat(runtim-vapor, compiler-vapor): simplify implement
Doctor-wu 24488bc
Merge branch 'main' into feature-inherit-attrs
Doctor-wu 6044bf7
test(compiler-vapor): add generator component test case & snapshot
Doctor-wu 8afe97d
Merge branch 'main' into feature-inherit-attrs
Doctor-wu c30a618
feat(runtime-vapor): simplify implement
Doctor-wu c085cda
feat(runtime-vapor): simplify implement
Doctor-wu 0ea395c
refactor: optimize bundle size
sxzz b5879d3
refactor: check if component
sxzz 322f0ba
refactor: remove type casting
sxzz 34c1937
feat(compiler-vapor): optimize single root implemention
Doctor-wu 56ff7c4
fix: type error
sxzz 47754b7
feat(compiler-vapor): perf bundle size
Doctor-wu 5270734
chore(compiler-vapor, runtime-vapor): bundle size & make lint happy
Doctor-wu c068506
refactor: simplify
sxzz 61b572c
chore(compiler-vapor): remove unecessary import
Doctor-wu 47f8b9a
test: undo
sxzz File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
32 changes: 32 additions & 0 deletions
32
packages/compiler-vapor/__tests__/generators/__snapshots__/component.spec.ts.snap
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html | ||
|
||
exports[`generate component > generate multi root component 1`] = ` | ||
"import { resolveComponent as _resolveComponent, createComponent as _createComponent, template as _template } from 'vue/vapor'; | ||
const t0 = _template("123") | ||
|
||
export function render(_ctx) { | ||
const n1 = t0() | ||
const n0 = _createComponent(_resolveComponent("Comp")) | ||
return [n0, n1] | ||
}" | ||
`; | ||
|
||
exports[`generate component > generate single root component (with props) 1`] = ` | ||
"import { resolveComponent as _resolveComponent, createComponent as _createComponent } from 'vue/vapor'; | ||
|
||
export function render(_ctx) { | ||
const n0 = _createComponent(_resolveComponent("Comp"), [{ | ||
foo: () => (foo) | ||
}], true) | ||
return n0 | ||
}" | ||
`; | ||
|
||
exports[`generate component > generate single root component (without props) 1`] = ` | ||
"import { resolveComponent as _resolveComponent, createComponent as _createComponent } from 'vue/vapor'; | ||
|
||
export function render(_ctx) { | ||
const n0 = _createComponent(_resolveComponent("Comp"), null, true) | ||
return n0 | ||
}" | ||
`; |
18 changes: 18 additions & 0 deletions
18
packages/compiler-vapor/__tests__/generators/component.spec.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import { compile } from '@vue/compiler-vapor' | ||
|
||
describe('generate component', () => { | ||
test('generate single root component (without props)', () => { | ||
const { code } = compile(`<Comp/>`) | ||
expect(code).toMatchSnapshot() | ||
}) | ||
|
||
test('generate single root component (with props)', () => { | ||
const { code } = compile(`<Comp :foo="foo"/>`) | ||
expect(code).toMatchSnapshot() | ||
}) | ||
|
||
test('generate multi root component', () => { | ||
const { code } = compile(`<Comp/>123`) | ||
expect(code).toMatchSnapshot() | ||
}) | ||
}) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
155 changes: 155 additions & 0 deletions
155
packages/runtime-vapor/__tests__/componentAttrs.spec.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,155 @@ | ||
import { | ||
createComponent, | ||
getCurrentInstance, | ||
nextTick, | ||
ref, | ||
setText, | ||
template, | ||
watchEffect, | ||
} from '../src' | ||
import { setCurrentInstance } from '../src/component' | ||
import { makeRender } from './_utils' | ||
|
||
const define = makeRender<any>() | ||
|
||
describe('attribute fallthrough', () => { | ||
it('should allow attrs to fallthrough', async () => { | ||
const t0 = template('<div>') | ||
const { component: Child } = define({ | ||
props: ['foo'], | ||
render() { | ||
const instance = getCurrentInstance()! | ||
const n0 = t0() | ||
watchEffect(() => setText(n0, instance.props.foo)) | ||
return n0 | ||
}, | ||
}) | ||
|
||
const foo = ref(1) | ||
const id = ref('a') | ||
const { instance, host } = define({ | ||
setup() { | ||
return { foo, id } | ||
}, | ||
render(_ctx: Record<string, any>) { | ||
return createComponent( | ||
Child, | ||
{ | ||
foo: () => _ctx.foo, | ||
id: () => _ctx.id, | ||
}, | ||
true, | ||
) | ||
}, | ||
}).render() | ||
const reset = setCurrentInstance(instance) | ||
expect(host.innerHTML).toBe('<div id="a">1</div>') | ||
|
||
foo.value++ | ||
await nextTick() | ||
expect(host.innerHTML).toBe('<div id="a">2</div>') | ||
|
||
id.value = 'b' | ||
await nextTick() | ||
expect(host.innerHTML).toBe('<div id="b">2</div>') | ||
reset() | ||
}) | ||
|
||
it('should not fallthrough if explicitly pass inheritAttrs: false', async () => { | ||
const t0 = template('<div>') | ||
const { component: Child } = define({ | ||
props: ['foo'], | ||
inheritAttrs: false, | ||
render() { | ||
const instance = getCurrentInstance()! | ||
const n0 = t0() | ||
watchEffect(() => setText(n0, instance.props.foo)) | ||
return n0 | ||
}, | ||
}) | ||
|
||
const foo = ref(1) | ||
const id = ref('a') | ||
const { instance, host } = define({ | ||
setup() { | ||
return { foo, id } | ||
}, | ||
render(_ctx: Record<string, any>) { | ||
return createComponent( | ||
Child, | ||
{ | ||
foo: () => _ctx.foo, | ||
id: () => _ctx.id, | ||
}, | ||
true, | ||
) | ||
}, | ||
}).render() | ||
const reset = setCurrentInstance(instance) | ||
expect(host.innerHTML).toBe('<div>1</div>') | ||
|
||
foo.value++ | ||
await nextTick() | ||
expect(host.innerHTML).toBe('<div>2</div>') | ||
|
||
id.value = 'b' | ||
await nextTick() | ||
expect(host.innerHTML).toBe('<div>2</div>') | ||
reset() | ||
}) | ||
|
||
it('should pass through attrs in nested single root components', async () => { | ||
const t0 = template('<div>') | ||
const { component: Grandson } = define({ | ||
props: ['custom-attr'], | ||
render() { | ||
const instance = getCurrentInstance()! | ||
const n0 = t0() | ||
watchEffect(() => setText(n0, instance.attrs.foo)) | ||
return n0 | ||
}, | ||
}) | ||
|
||
const { component: Child } = define({ | ||
render() { | ||
const n0 = createComponent( | ||
Grandson, | ||
{ | ||
'custom-attr': () => 'custom-attr', | ||
}, | ||
true, | ||
) | ||
return n0 | ||
}, | ||
}) | ||
|
||
const foo = ref(1) | ||
const id = ref('a') | ||
const { instance, host } = define({ | ||
setup() { | ||
return { foo, id } | ||
}, | ||
render(_ctx: Record<string, any>) { | ||
return createComponent( | ||
Child, | ||
{ | ||
foo: () => _ctx.foo, | ||
id: () => _ctx.id, | ||
}, | ||
true, | ||
) | ||
}, | ||
}).render() | ||
const reset = setCurrentInstance(instance) | ||
expect(host.innerHTML).toBe('<div foo="1" id="a">1</div>') | ||
|
||
foo.value++ | ||
await nextTick() | ||
expect(host.innerHTML).toBe('<div foo="2" id="a">2</div>') | ||
|
||
id.value = 'b' | ||
await nextTick() | ||
expect(host.innerHTML).toBe('<div foo="2" id="b">2</div>') | ||
reset() | ||
}) | ||
}) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.