Skip to content

Commit 2614dd3

Browse files
authored
feat: support script setup and css var inj for vue 2.7 (#1917)
Closes #1916
1 parent 71622f2 commit 2614dd3

File tree

6 files changed

+51
-13
lines changed

6 files changed

+51
-13
lines changed

docs/rules/no-unsupported-features.md

+3-2
Original file line numberDiff line numberDiff line change
@@ -36,11 +36,12 @@ The `"ignores"` option accepts an array of the following strings.
3636
- Vue.js 3.1.0+
3737
- `"is-attribute-with-vue-prefix"` ... [`is` attribute with `vue:` prefix](https://v3.vuejs.org/api/special-attributes.html#is)
3838
- Vue.js 3.0.0+
39-
- `"style-css-vars-injection"` ... [SFC CSS variable injection][Vue RFCs - 0043-sfc-style-variables]
40-
- `"script-setup"` ... [`<script setup>`][Vue RFCs - 0040-script-setup]
4139
- `"v-model-argument"` ... [argument on `v-model`][Vue RFCs - 0005-replace-v-bind-sync-with-v-model-argument]
4240
- `"v-model-custom-modifiers"` ... [custom modifiers on `v-model`][Vue RFCs - 0011-v-model-api-change]
4341
- `"v-is"` ... [v-is](https://v3.vuejs.org/api/directives.html#v-is) directive.
42+
- Vue.js 2.7.0+
43+
- `"style-css-vars-injection"` ... [SFC CSS variable injection][Vue RFCs - 0043-sfc-style-variables]
44+
- `"script-setup"` ... [`<script setup>`][Vue RFCs - 0040-script-setup]
4445
- Vue.js 2.6.0+
4546
- `"dynamic-directive-arguments"` ... [dynamic directive arguments](https://v3.vuejs.org/guide/template-syntax.html#dynamic-arguments).
4647
- `"v-slot"` ... [v-slot](https://v3.vuejs.org/api/directives.html#v-slot) directive.

lib/rules/no-unsupported-features.js

+8-6
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,13 @@ const FEATURES = {
2020
// Vue.js 2.6.0+
2121
'dynamic-directive-arguments': require('./syntaxes/dynamic-directive-arguments'),
2222
'v-slot': require('./syntaxes/v-slot'),
23+
// Vue.js 2.7.0+
24+
'script-setup': require('./syntaxes/script-setup'),
25+
'style-css-vars-injection': require('./syntaxes/style-css-vars-injection'),
2326
// Vue.js 3.0.0+
2427
'v-model-argument': require('./syntaxes/v-model-argument'),
2528
'v-model-custom-modifiers': require('./syntaxes/v-model-custom-modifiers'),
2629
'v-is': require('./syntaxes/v-is'),
27-
'script-setup': require('./syntaxes/script-setup'),
28-
'style-css-vars-injection': require('./syntaxes/style-css-vars-injection'),
2930
// Vue.js 3.1.0+
3031
'is-attribute-with-vue-prefix': require('./syntaxes/is-attribute-with-vue-prefix'),
3132
// Vue.js 3.2.0+
@@ -95,16 +96,17 @@ module.exports = {
9596
forbiddenDynamicDirectiveArguments:
9697
'Dynamic arguments are not supported until Vue.js "2.6.0".',
9798
forbiddenVSlot: '`v-slot` are not supported until Vue.js "2.6.0".',
99+
// Vue.js 2.7.0+
100+
forbiddenScriptSetup:
101+
'`<script setup>` is not supported until Vue.js "2.7.0".',
102+
forbiddenStyleCssVarsInjection:
103+
'SFC CSS variable injection is not supported until Vue.js ">=3.0.3 || >=2.7.0 <3.0.0".',
98104
// Vue.js 3.0.0+
99105
forbiddenVModelArgument:
100106
'Argument on `v-model` is not supported until Vue.js "3.0.0".',
101107
forbiddenVModelCustomModifiers:
102108
'Custom modifiers on `v-model` are not supported until Vue.js "3.0.0".',
103109
forbiddenVIs: '`v-is` are not supported until Vue.js "3.0.0".',
104-
forbiddenScriptSetup:
105-
'`<script setup>` are not supported until Vue.js "3.0.0".',
106-
forbiddenStyleCssVarsInjection:
107-
'SFC CSS variable injection is not supported until Vue.js "3.0.3".',
108110
// Vue.js 3.1.0+
109111
forbiddenIsAttributeWithVuePrefix:
110112
'`is="vue:"` are not supported until Vue.js "3.1.0".',

lib/rules/syntaxes/script-setup.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
const utils = require('../../utils')
88

99
module.exports = {
10-
supported: '>=3.0.0',
10+
supported: '>=2.7.0',
1111
/** @param {RuleContext} context @returns {TemplateListener} */
1212
createScriptVisitor(context) {
1313
const scriptSetup = utils.getScriptSetupElement(context)

lib/rules/syntaxes/style-css-vars-injection.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
const { getStyleVariablesContext } = require('../../utils/style-variables')
88

99
module.exports = {
10-
supported: '>=3.0.3',
10+
supported: '>=3.0.3 || >=2.7.0 <3.0.0',
1111
/** @param {RuleContext} context @returns {TemplateListener} */
1212
createScriptVisitor(context) {
1313
const styleVars = getStyleVariablesContext(context)

tests/lib/rules/no-unsupported-features/script-setup.js

+7-1
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,12 @@ tester.run('no-unsupported-features/script-setup', rule, {
2424
</script>`,
2525
options: buildOptions()
2626
},
27+
{
28+
code: `
29+
<script setup>
30+
</script>`,
31+
options: buildOptions({ version: '^2.7.0' })
32+
},
2733
{
2834
code: `
2935
<script>
@@ -39,7 +45,7 @@ tester.run('no-unsupported-features/script-setup', rule, {
3945
options: buildOptions({ version: '^2.6.0' }),
4046
errors: [
4147
{
42-
message: '`<script setup>` are not supported until Vue.js "3.0.0".',
48+
message: '`<script setup>` is not supported until Vue.js "2.7.0".',
4349
line: 2
4450
}
4551
]

tests/lib/rules/no-unsupported-features/style-css-vars-injection.js

+31-2
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,35 @@ tester.run('no-unsupported-features/style-css-vars-injection', rule, {
5454
<div class="text">hello</div>
5555
</template>
5656
57+
<script>
58+
export default {
59+
data() {
60+
return {
61+
color: 'red',
62+
font: {
63+
size: '2em',
64+
},
65+
}
66+
},
67+
}
68+
</script>
69+
70+
<style>
71+
.text {
72+
color: v-bind(color);
73+
74+
/* expressions (wrap in quotes) */
75+
font-size: v-bind('font.size');
76+
}
77+
</style>`,
78+
options: buildOptions({ version: '^2.7.0' })
79+
},
80+
{
81+
code: `
82+
<template>
83+
<div class="text">hello</div>
84+
</template>
85+
5786
<script>
5887
</script>
5988
@@ -98,15 +127,15 @@ tester.run('no-unsupported-features/style-css-vars-injection', rule, {
98127
errors: [
99128
{
100129
message:
101-
'SFC CSS variable injection is not supported until Vue.js "3.0.3".',
130+
'SFC CSS variable injection is not supported until Vue.js ">=3.0.3 || >=2.7.0 <3.0.0".',
102131
line: 21,
103132
column: 18,
104133
endLine: 21,
105134
endColumn: 31
106135
},
107136
{
108137
message:
109-
'SFC CSS variable injection is not supported until Vue.js "3.0.3".',
138+
'SFC CSS variable injection is not supported until Vue.js ">=3.0.3 || >=2.7.0 <3.0.0".',
110139
line: 24,
111140
column: 22,
112141
endLine: 24,

0 commit comments

Comments
 (0)