Skip to content

Commit c8084c8

Browse files
authored
Add parserOptions.vueFeatures.filter option (#89)
1 parent 5056775 commit c8084c8

File tree

18 files changed

+4848
-3
lines changed

18 files changed

+4848
-3
lines changed

README.md

+50
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,56 @@ For example:
9090
If the `parserOptions.parser` is `false`, the `vue-eslint-parser` skips parsing `<script>` tags completely.
9191
This is useful for people who use the language ESLint community doesn't provide custom parser implementation.
9292

93+
### parserOptions.vueFeatures
94+
95+
You can use `parserOptions.vueFeatures` property to specify how to parse related to Vue features.
96+
For example:
97+
98+
```json
99+
{
100+
"parser": "vue-eslint-parser",
101+
"parserOptions": {
102+
"vueFeatures": {
103+
"filter": true,
104+
"interpolationAsNonHTML": false,
105+
}
106+
}
107+
}
108+
```
109+
110+
### parserOptions.vueFeatures.filter
111+
112+
You can use `parserOptions.vueFeatures.filter` property to specify whether to parse the Vue2 filter. If you specify `false`, the parser does not parse `|` as a filter.
113+
For example:
114+
115+
```json
116+
{
117+
"parser": "vue-eslint-parser",
118+
"parserOptions": {
119+
"vueFeatures": {
120+
"filter": false
121+
}
122+
}
123+
}
124+
```
125+
126+
If you specify `false`, it can be parsed in the same way as Vue 3.
127+
The following template parses as a bitwise operation.
128+
129+
```vue
130+
<template>
131+
<div>{{ a | b }}</div>
132+
</template>
133+
```
134+
135+
However, the following template that are valid in Vue 2 cannot be parsed.
136+
137+
```vue
138+
<template>
139+
<div>{{ a | valid:filter }}</div>
140+
</template>
141+
```
142+
93143
### parserOptions.vueFeatures.interpolationAsNonHTML
94144

95145
You can use `parserOptions.vueFeatures.interpolationAsNonHTML` property to specify whether to parse the interpolation as HTML. If you specify `true`, the parser handles the interpolation as non-HTML (However, you can use HTML escaping in the interpolation).

src/common/parser-options.ts

+1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ export interface ParserOptions {
33
parser?: boolean | string
44
vueFeatures?: {
55
interpolationAsNonHTML?: boolean // default false
6+
filter?: boolean // default true
67
}
78

89
// espree options

src/script/index.ts

+4-3
Original file line numberDiff line numberDiff line change
@@ -654,9 +654,10 @@ export function parseExpression(
654654
): ExpressionParseResult<ESLintExpression | VFilterSequenceExpression> {
655655
debug('[script] parse expression: "%s"', code)
656656

657-
const [mainCode, ...filterCodes] = allowFilters
658-
? splitFilters(code)
659-
: [code]
657+
const [mainCode, ...filterCodes] =
658+
allowFilters && (parserOptions.vueFeatures?.filter ?? true)
659+
? splitFilters(code)
660+
: [code]
660661
if (filterCodes.length === 0) {
661662
return parseExpressionBody(
662663
code,

0 commit comments

Comments
 (0)