Skip to content

Commit dec1c3f

Browse files
committed
refactor(core): enhance template inline CSS features
1 parent 584515b commit dec1c3f

File tree

3 files changed

+40
-21
lines changed

3 files changed

+40
-21
lines changed

README.md

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -14,22 +14,23 @@
1414

1515
### Feature Comparison
1616

17-
| Feature | Legacy | New |
18-
| ------------------------------------------ | ------ | ----------------- |
19-
| 语法高亮 |||
20-
| SFC blocks 语言支持 |||
21-
| Emmet 支持 |||
22-
| \<template\> 原生组件标签及属性补全提示 || ✅ (enhanced) |
23-
| 格式化 formatter || 60% (enhanced) |
24-
| 关联 tsconfig 配置 || ✅ (enhanced) |
25-
| 支持 Monorepo |||
26-
| 支持选择 typescript 版本 |||
27-
| SFC 编辑器视图拆分 |||
28-
| \<template\> 支持 TS 类型检查、补全提示... |||
29-
| \<template\> 支持定义跳转、查找参考引用 |||
30-
| \<template\> 样式类名跳转 \<style\> |||
31-
| \<template\> 原生组件属性检查 || in Progress (50%) |
32-
| \<template\> 自定义组件跳转、属性检查 || in Progress |
17+
| Feature | Legacy | New |
18+
| -------------------------------------------- | ------ | ----------------- |
19+
| 语法高亮 |||
20+
| SFC blocks 语言支持 |||
21+
| Emmet 支持 |||
22+
| \<template\> 原生组件标签及属性补全提示 || ✅ (enhanced) |
23+
| 格式化 formatter || 60% (enhanced) |
24+
| 关联 tsconfig 配置 || ✅ (enhanced) |
25+
| 支持 Monorepo |||
26+
| 支持选择 typescript 版本 |||
27+
| SFC 编辑器视图拆分 |||
28+
| \<template\> 支持 TS 类型检查、补全提示... |||
29+
| \<template\> 支持定义跳转、查找参考引用 |||
30+
| \<template\> 样式类名跳转 \<style\> |||
31+
| \<template\> style 属性支持原生 CSS 补全提示 |||
32+
| \<template\> 原生组件属性检查 || in Progress (50%) |
33+
| \<template\> 自定义组件跳转、属性检查 || in Progress |
3334

3435
### More
3536

inspect-extension/components/composition/wxStyle.mpx

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,16 @@
22
<view wx:style="color: {{activeColor}}; font-size: {{fontSize}}px; fontWeight: bold">
33
这是一段测试文字
44
</view>
5-
</template>
5+
<view style="color: {{activeColor}}; font-size: {{fontSize}}px; fontWeight: bold">
6+
这是一段测试文字
7+
</view>
8+
<view style="color: aliceblue;font-weight: 500;"></view>
9+
</template>
10+
11+
<script setup lang="ts">
12+
defineExpose({
13+
activeColor: 'red',
14+
fontSize: 16,
15+
themeColor: 'blue'
16+
})
17+
</script>

packages/language-core/src/plugins/mpx-template-inline-css.ts

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
1+
import type { CodeInformation } from '@volar/language-core'
12
import type { Code, MpxLanguagePlugin } from '../types'
23
import * as CompilerDOM from '@vue/compiler-dom'
34
import { forEachElementNode } from '../codegen/template'
45
import { allCodeFeatures } from './shared'
56

6-
const codeFeatures = {
7+
const codeFeatures: CodeInformation = {
78
...allCodeFeatures,
89
format: false,
910
structure: false,
11+
verification: false,
1012
}
1113

1214
const plugin: MpxLanguagePlugin = () => {
@@ -24,8 +26,7 @@ const plugin: MpxLanguagePlugin = () => {
2426
if (embeddedFile.id !== 'template_inline_css' || !sfc.template?.ast) {
2527
return
2628
}
27-
embeddedFile.parentCodeId =
28-
sfc.template.lang === 'md' ? 'root_tags' : 'template'
29+
embeddedFile.parentCodeId = 'template'
2930
embeddedFile.content.push(...generate(sfc.template.ast))
3031
},
3132
}
@@ -44,7 +45,8 @@ function* generate(
4445
prop.arg?.type === CompilerDOM.NodeTypes.SIMPLE_EXPRESSION &&
4546
prop.exp?.type === CompilerDOM.NodeTypes.SIMPLE_EXPRESSION &&
4647
prop.arg.content === 'style' &&
47-
prop.exp.constType === CompilerDOM.ConstantTypes.CAN_STRINGIFY
48+
prop.exp.constType === CompilerDOM.ConstantTypes.CAN_STRINGIFY &&
49+
hasNotExpression(prop.arg.loc.source)
4850
) {
4951
const endCrt = prop.arg.loc.source[prop.arg.loc.source.length - 1] // " | '
5052
const start = prop.arg.loc.source.indexOf(endCrt) + 1
@@ -63,3 +65,7 @@ function* generate(
6365
}
6466
}
6567
}
68+
69+
function hasNotExpression(source: string): boolean {
70+
return !source.includes('{{') && !source.includes('}}')
71+
}

0 commit comments

Comments
 (0)