Commit bcc3783
committed
FIX: Smart parser selection to support decorators when LWC base config disabled
Problem:
When users set 'disable_lwc_base_config: true', JavaScript files containing
LWC decorators (@api, @track, @wire) failed to parse with error:
'Unexpected character @'
Root Cause:
- createJavascriptConfigArray() used Espree parser (ESLint default)
- Espree does not support decorators, only Babel does
- Users disable LWC base config to avoid LWC-specific rules, but still have
LWC files with decorators that need to be parsed
Solution:
Implement smart parser selection based on file extensions:
- If .js extension is included → Use Babel parser (supports decorators)
- If only .jsx, .mjs, .cjs → Use Espree parser (faster, no decorators needed)
Benefits:
- Fixes decorator parsing when disable_lwc_base_config: true
- Preserves Espree performance optimization for React-only projects
- Both parsers remain useful (no dead code)
- Automatic detection (no new config needed)
- Backwards compatible
Test Cases:
- .js files with LWC decorators: Works (Babel)
- .jsx files with React JSX: Works (Espree for performance)
- Mixed .js + .jsx: Works (Babel handles both)1 parent 3922bc2 commit bcc3783
2 files changed
Lines changed: 32 additions & 10 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | 2 | | |
3 | 3 | | |
4 | | - | |
| 4 | + | |
5 | 5 | | |
6 | 6 | | |
7 | 7 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
148 | 148 | | |
149 | 149 | | |
150 | 150 | | |
151 | | - | |
152 | | - | |
153 | | - | |
154 | | - | |
155 | | - | |
156 | | - | |
157 | | - | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
| 159 | + | |
| 160 | + | |
| 161 | + | |
| 162 | + | |
| 163 | + | |
| 164 | + | |
| 165 | + | |
| 166 | + | |
| 167 | + | |
| 168 | + | |
| 169 | + | |
| 170 | + | |
| 171 | + | |
| 172 | + | |
| 173 | + | |
| 174 | + | |
| 175 | + | |
| 176 | + | |
| 177 | + | |
| 178 | + | |
| 179 | + | |
158 | 180 | | |
159 | 181 | | |
160 | | - | |
161 | | - | |
| 182 | + | |
| 183 | + | |
162 | 184 | | |
163 | 185 | | |
164 | 186 | | |
| |||
0 commit comments