Skip to content

Add parserOptions.vueFeatures.filter option #89

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

Merged
merged 1 commit into from
Dec 3, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
50 changes: 50 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,56 @@ For example:
If the `parserOptions.parser` is `false`, the `vue-eslint-parser` skips parsing `<script>` tags completely.
This is useful for people who use the language ESLint community doesn't provide custom parser implementation.

### parserOptions.vueFeatures

You can use `parserOptions.vueFeatures` property to specify how to parse related to Vue features.
For example:

```json
{
"parser": "vue-eslint-parser",
"parserOptions": {
"vueFeatures": {
"filter": true,
"interpolationAsNonHTML": false,
}
}
}
```

### parserOptions.vueFeatures.filter

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.
For example:

```json
{
"parser": "vue-eslint-parser",
"parserOptions": {
"vueFeatures": {
"filter": false
}
}
}
```

If you specify `false`, it can be parsed in the same way as Vue 3.
The following template parses as a bitwise operation.

```vue
<template>
<div>{{ a | b }}</div>
</template>
```

However, the following template that are valid in Vue 2 cannot be parsed.

```vue
<template>
<div>{{ a | valid:filter }}</div>
</template>
```

### parserOptions.vueFeatures.interpolationAsNonHTML

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).
Expand Down
1 change: 1 addition & 0 deletions src/common/parser-options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ export interface ParserOptions {
parser?: boolean | string
vueFeatures?: {
interpolationAsNonHTML?: boolean // default false
filter?: boolean // default true
}

// espree options
Expand Down
7 changes: 4 additions & 3 deletions src/script/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -654,9 +654,10 @@ export function parseExpression(
): ExpressionParseResult<ESLintExpression | VFilterSequenceExpression> {
debug('[script] parse expression: "%s"', code)

const [mainCode, ...filterCodes] = allowFilters
? splitFilters(code)
: [code]
const [mainCode, ...filterCodes] =
allowFilters && (parserOptions.vueFeatures?.filter ?? true)
? splitFilters(code)
: [code]
if (filterCodes.length === 0) {
return parseExpressionBody(
code,
Expand Down
Loading