Skip to content
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

feat: support v-bind shorthand #3705

Closed
wants to merge 26 commits into from
Closed
Show file tree
Hide file tree
Changes from 12 commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
682c49d
add configuration
so1ve Nov 3, 2023
9428437
Merge branch 'master' into feat/v-bind-shorthand-inlay-hint
so1ve Nov 3, 2023
f52f8d0
tests
so1ve Nov 3, 2023
78feeda
add expect error
so1ve Nov 3, 2023
db38813
update deps
so1ve Nov 8, 2023
91dd739
update deps
so1ve Nov 8, 2023
45a0661
type checking!
so1ve Nov 9, 2023
a1990ad
some part of inlay hint
so1ve Nov 9, 2023
39155f1
update test
so1ve Nov 9, 2023
686ddc0
Merge branch 'master' into feat/v-bind-shorthand-inlay-hint
so1ve Nov 9, 2023
9b26126
go to both definitions
so1ve Nov 9, 2023
1f86f8f
adapt `CompilerDOM.compile`
so1ve Nov 9, 2023
b3f9d5f
revert inlay hint
so1ve Nov 9, 2023
fcf35a8
fix invalid argument name
so1ve Nov 9, 2023
c17df64
add reference teest
so1ve Nov 9, 2023
a2c4ce3
fixed an edge case
so1ve Nov 9, 2023
48d999b
small refactor
so1ve Nov 9, 2023
770eda9
avoid undefined == undefined
so1ve Nov 9, 2023
e561e42
feat: upgrade to Volar 2.0 alpha (#3736)
johnsoncodehk Dec 6, 2023
9f54a24
refactor(langauge-core): codegen based on Generator (#3778)
johnsoncodehk Dec 6, 2023
7128f1e
refactor(tsc): deprecate hooks api (#3793)
johnsoncodehk Dec 12, 2023
2bd1917
fix(language-core): `resolveSourceFileName` condition incorrect
johnsoncodehk Dec 12, 2023
9f1950d
refactor(extension): Optimized the destruction of some events and ref…
Simon-He95 Dec 14, 2023
a5e665a
chore: bump deps
so1ve Dec 29, 2023
28c6389
Merge branch 'master' into feat/v-bind-shorthand-inlay-hint
so1ve Dec 29, 2023
81890eb
fix types
so1ve Dec 29, 2023
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
7 changes: 6 additions & 1 deletion extensions/vscode/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -474,7 +474,7 @@
"items": {
"type": "string"
},
"default": [],
"default": [ ],
"description": "List any additional file extensions that should be processed as Vue files (requires restart)."
},
"vue.server.fullCompletionList": {
Expand Down Expand Up @@ -595,6 +595,11 @@
"type": "boolean",
"default": false,
"description": "Show inlay hints for component options wrapper for type support."
},
"vue.inlayHints.vbindShorthand": {
"type": "boolean",
"default": false,
"description": "Show inlay hints for v-bind shorthand."
}
}
},
Expand Down
6 changes: 3 additions & 3 deletions packages/language-core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@
"dependencies": {
"@volar/language-core": "~1.11.0",
"@volar/source-map": "~1.11.0",
"@vue/compiler-dom": "^3.3.0",
"@vue/shared": "^3.3.0",
"@vue/compiler-dom": "npm:@vue/[email protected].0",
"@vue/shared": "npm:@vue/[email protected].0",
"computeds": "^0.0.1",
"minimatch": "^9.0.3",
"muggle-string": "^0.3.1",
Expand All @@ -27,7 +27,7 @@
"@types/minimatch": "^5.1.2",
"@types/node": "latest",
"@types/path-browserify": "^1.0.1",
"@vue/compiler-sfc": "^3.3.0"
"@vue/compiler-sfc": "npm:@vue/[email protected].0"
},
"peerDependencies": {
"typescript": "*"
Expand Down
16 changes: 15 additions & 1 deletion packages/language-core/src/generators/template.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1297,7 +1297,8 @@ export function generate(
);
}
codes.push(': (');
if (prop.exp && !(prop.exp.constType === CompilerDOM.ConstantTypes.CAN_STRINGIFY)) { // style='z-index: 2' will compile to {'z-index':'2'}
const isShorthand = prop.exp?.loc.start.offset === prop.exp?.loc.end.offset;
rchl marked this conversation as resolved.
Show resolved Hide resolved
if (prop.exp && !isShorthand && !(prop.exp.constType === CompilerDOM.ConstantTypes.CAN_STRINGIFY)) { // style='z-index: 2' will compile to {'z-index':'2'}
codes.push(
...createInterpolationCode(
prop.exp.loc.source,
Expand All @@ -1318,6 +1319,19 @@ export function generate(
);
}
}
else if (prop.arg && isShorthand && prop.arg.type === CompilerDOM.NodeTypes.SIMPLE_EXPRESSION) {
const propVariableName = camelize(prop.arg.content);
codes.push(
...createInterpolationCode(
propVariableName,
prop.arg.loc,
prop.arg.loc.start.offset,
caps_all,
'(',
')',
),
);
}
else {
codes.push('{}');
}
Expand Down
2 changes: 1 addition & 1 deletion packages/language-service/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
"@volar/language-core": "~1.11.0",
"@volar/language-service": "~1.11.0",
"@volar/typescript": "~1.11.0",
"@vue/compiler-dom": "^3.3.0",
"@vue/compiler-dom": "npm:@vue/[email protected].0",
"@vue/language-core": "1.8.22",
"@vue/shared": "^3.3.0",
"computeds": "^0.0.1",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ const plugin: Service = (context) => {

const hint: {
setting: string;
label: string;
label: string | vscode.InlayHintLabelPart[];
tooltip: string;
paddingRight?: boolean;
paddingLeft?: boolean;
Expand Down
111 changes: 83 additions & 28 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions test-workspace/tsc/vue3/v-bind-shorthand/Comp.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<script setup lang="ts">
defineProps<{
foo?: number;
bar?: number;
}>();
</script>
12 changes: 12 additions & 0 deletions test-workspace/tsc/vue3/v-bind-shorthand/main.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<script setup lang="ts">
import Comp from './Comp.vue';

const foo = 1;
const bar = '';
</script>

<template>
<Comp :foo></Comp>
<!-- @vue-expect-error should typecheck -->
<Comp :bar></Comp>
</template>