Skip to content

Commit

Permalink
feat: add setup-compiler-macros environment for enabling `<script s…
Browse files Browse the repository at this point in the history
…etup>` compiler macro globals
  • Loading branch information
foxxyz committed Oct 28, 2021
1 parent 166dfbf commit 89f2c9a
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 10 deletions.
15 changes: 5 additions & 10 deletions docs/user-guide/README.md
Expand Up @@ -358,26 +358,21 @@ module.exports = {
}
```

#### Compiler macros such as `defineProps` and `defineEmits` are warned by `no-undef` rule
#### Compiler macros such as `defineProps` and `defineEmits` generate `no-undef` warnings

You need to define [global variables](https://eslint.org/docs/user-guide/configuring/language-options#using-configuration-files-1) in your ESLint configuration file.
If you don't want to define global variables, use `import { defineProps, defineEmits } from 'vue'`.
You need to enable the compiler macros environment in your ESLint configuration file.
If you don't want to expose these variables globally, you can use `/* global defineProps, defineEmits */` instead.

Example **.eslintrc.js**:

```js
module.exports = {
globals: {
defineProps: "readonly",
defineEmits: "readonly",
defineExpose: "readonly",
withDefaults: "readonly"
env: {
'vue/setup-compiler-macros': true
}
}
```

See also [ESLint - Specifying Globals > Using configuration files](https://eslint.org/docs/user-guide/configuring/language-options#using-configuration-files-1).

#### Parsing error with Top Level `await`

##### Using ESLint <= v7.x
Expand Down
10 changes: 10 additions & 0 deletions lib/index.js
Expand Up @@ -218,5 +218,15 @@ module.exports = {
},
processors: {
'.vue': require('./processor')
},
environments: {
'setup-compiler-macros': {
globals: {
defineProps: 'readonly',
defineEmits: 'readonly',
defineExpose: 'readonly',
withDefaults: 'readonly'
}
}
}
}
10 changes: 10 additions & 0 deletions tools/update-lib-index.js
Expand Up @@ -37,6 +37,16 @@ module.exports = {
},
processors: {
'.vue': require('./processor')
},
environments: {
'setup-compiler-macros': {
globals: {
defineProps: 'readonly',
defineEmits: 'readonly',
defineExpose: 'readonly',
withDefaults: 'readonly'
}
}
}
}
`
Expand Down

0 comments on commit 89f2c9a

Please sign in to comment.