-
Notifications
You must be signed in to change notification settings - Fork 44
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
[TypeScript] ParseError when declaring class fields #137
Comments
This syntax is unsupported in ESLint itself in regular JS files - eslint/eslint#15016 - Once ESLint supports this and you've upgraded, this should work without any further changes on Svelte's side. |
But the above code was written in TypeScript, and the Update: this issue has nothing to do with the |
I think this problem is caused by the eslint-plugin-svelte3/src/preprocess.js Lines 238 to 242 in e68ea65
TypeScript (4.4.3 in my environment) will preserve class field declarations when targeting ESNext, for example, // source.ts
export class Test {
static value = 'test';
this_breaks_too: number;
} yields // source.js
export class Test {
static value = 'test';
this_breaks_too;
} which breaks eslint. Is there any reason that this plugin uses the above compiler options instead of a user-defined |
@Conduitry: The issue you linked in eslint eslint/eslint#15016 which substantiated closing this one is completely unrelated, it talks only about This issue at hand seems to fail to parse into valid code, so it is not an eslint rule that fails, but it throws "error Unexpected token ParseError", which does not seem to be originating in eslint, but perhaps in svelte compiler after typescript transpiler. All samples below fail: <script lang="ts">
class Test1 {
value = 'test';
this_breaks_too: number;
}
</script> <script>
class Test2 {
value = 'test';
this_breaks_too = 0;
}
</script> Per sveltejs/svelte#6900, setting eslint-plugin-svelte3/src/preprocess.js Lines 238 to 242 in e68ea65
Setting I also patched L239 and it fixed the problem (ParseError is gone and eslint gets to report its findings per the rules): function compile_code(text, compiler, processor_options) {
const ts = processor_options.typescript;
if (!ts) {
return compiler.compile(text, { generate: false, ...processor_options.compiler_options });
} else {
const ts_options = {
reportDiagnostics: false,
compilerOptions: {
- target: ts.ScriptTarget.ESNext,
+ target: ts.ScriptTarget.ES2020, 10:9 warning 'Test1' is defined but never used @typescript-eslint/no-unused-vars
14:9 warning 'Test2' is defined but never used @typescript-eslint/no-unused-vars @Conduitry: please reopen this issue. And as a fix allow compiler options from tsconfig.json to pass into typescript compiler, or at least allow compiler options in |
Just want to note that this is still an issue for me - a basic class property annotation inside a script block with
|
Yep. It even happens in a fresh SvelteKit demo app. pnpm create svelte@latest myapp # Select demo app + TS + ESLint
cd myapp
eslint . results in:
|
Any progress on this? It triggers only in |
The Problem
Declaring any class fields inside svelte components will cause a
ParseError
in eslint, for example:App.svelte:
eslint outputs:
Steps to Reproduce
npm install
npm run lint
The text was updated successfully, but these errors were encountered: