-
Notifications
You must be signed in to change notification settings - Fork 5
feat: 支持自定义组件props类型提示支持 #108
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
Open
Triumph-light
wants to merge
3
commits into
mpx-ecology:main
Choose a base branch
from
Triumph-light:feat-reference-type-props
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
d35a9dc
feat: 支持自定义组件props类型提示支持, close: https://github.com/mpx-ecology/langu…
Triumph-light f655735
fix: update component options and settings for improved type handling…
wangshunnn a99a6df
refactor: simplify component import handling and remove unused naviga…
wangshunnn 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
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
7 changes: 7 additions & 0 deletions
7
inspect-extension/components/reference-type-props/component-js-setup.mpx
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,7 @@ | ||
| <script setup lang="ts"> | ||
| defineProps<{ | ||
| msg: string | ||
| count?: number | ||
| }>() | ||
| defineExpose({}) | ||
| </script> |
21 changes: 21 additions & 0 deletions
21
inspect-extension/components/reference-type-props/component-options.mpx
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,21 @@ | ||
| <script> | ||
| import { createComponent } from "@mpxjs/core"; | ||
|
|
||
| createComponent({ | ||
| properties: { | ||
| parentText: { | ||
| type: String, | ||
| value: '123' | ||
| }, | ||
| name: { | ||
| type: Number | ||
| } | ||
| }, | ||
| }) | ||
| </script> | ||
|
|
||
| <script name="json"> | ||
| module.exports = { | ||
| "component": true, | ||
| } | ||
| </script> | ||
23 changes: 23 additions & 0 deletions
23
inspect-extension/components/reference-type-props/index.mpx
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,23 @@ | ||
| <template> | ||
| <!-- 预期报错:Type 'number' is not assignable to type 'string'.ts-plugin(2322) --> | ||
| <component-options parentText="{{ 123 }}"></component-options> | ||
|
coderabbitai[bot] marked this conversation as resolved.
|
||
| <!-- 预期报错:Type 'string' is not assignable to type 'number'. --> | ||
| <component-js-setup count="{{ 'hello' }}"></component-js-setup> | ||
| </template> | ||
|
|
||
| <script lang="ts"> | ||
| import { createComponent } from '@mpxjs/core' | ||
|
|
||
| createComponent({ | ||
| }) | ||
| </script> | ||
|
|
||
| <script name="json"> | ||
| module.exports = { | ||
| "component": true, | ||
| "usingComponents": { | ||
| "component-options": "./component-options.mpx", | ||
| "component-js-setup": "./component-js-setup.mpx" | ||
| } | ||
| } | ||
| </script> | ||
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
27 changes: 23 additions & 4 deletions
27
packages/language-core/src/codegen/script/componentSelf.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 |
|---|---|---|
| @@ -1,18 +1,37 @@ | ||
| import type { Code } from '../../types' | ||
| import type { ScriptCodegenOptions } from './index' | ||
| import { endOfLine } from '../utils' | ||
| import { endOfLine, newLine } from '../utils' | ||
| import { getSlotsPropertyName } from '../../utils/shared' | ||
|
|
||
| export function* generateComponentSelf( | ||
| options: ScriptCodegenOptions, | ||
| ): Generator<Code> { | ||
| if (options.sfc.scriptSetup) { | ||
| yield `type __VLS_SelfBase = ` | ||
| if (options.scriptSetupRanges?.defineExpose) { | ||
| yield `const __VLS_self = typeof __VLS_defineExpose${endOfLine}` | ||
| yield `typeof __VLS_defineExpose` | ||
| } else { | ||
| yield `const __VLS_self = {}${endOfLine}` | ||
| yield `{}` | ||
| } | ||
| yield endOfLine | ||
| yield `type __VLS_SelfComponent = __VLS_SelfBase & {${newLine}` | ||
| yield ` new (props: __VLS_PublicProps): __VLS_SelfBase & {${newLine}` | ||
| yield ` $props: __VLS_PublicProps${endOfLine}` | ||
| yield ` ${getSlotsPropertyName()}: __VLS_Slots${endOfLine}` | ||
| yield ` }${newLine}` | ||
| yield `}${endOfLine}` | ||
| yield `const __VLS_self = {} as __VLS_SelfComponent${endOfLine}` | ||
| } else { | ||
| yield `const __VLS_self = typeof __VLS_defineComponent${endOfLine}` | ||
| yield `type __VLS_SelfProps = __VLS_GetPropsType<${newLine}` | ||
| yield ` NonNullable<typeof __VLS_defineComponent['$rawOptions']['properties']>${newLine}` | ||
| yield `>${endOfLine}` | ||
| yield `type __VLS_SelfComponent = typeof __VLS_defineComponent & {${newLine}` | ||
| yield ` new (props: __VLS_SelfProps): typeof __VLS_defineComponent & {${newLine}` | ||
| yield ` $props: __VLS_SelfProps${endOfLine}` | ||
| yield ` ${getSlotsPropertyName()}: __VLS_Slots${endOfLine}` | ||
| yield ` }${newLine}` | ||
| yield `}${endOfLine}` | ||
| yield `const __VLS_self = {} as __VLS_SelfComponent${endOfLine}` | ||
| } | ||
| yield `export default __VLS_self${endOfLine}` | ||
| } |
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.
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.