8000 feat(parser): emit diagnostic for modifiers on static block by ulrichstark · Pull Request #11727 · oxc-project/oxc · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

feat(parser): emit diagnostic for modifiers on static block #11727

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
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
5 changes: 5 additions & 0 deletions crates/oxc_parser/src/diagnostics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -760,3 +760,8 @@ pub fn variable_declarator_definite_type_assertion(span: Span) -> OxcDiagnostic
pub fn invalid_rest_assignment_target(span: Span) -> OxcDiagnostic {
OxcDiagnostic::error("Invalid rest operator's argument.").with_label(span)
}

#[cold]
pub fn modifiers_cannot_appear_here(span: Span) -> OxcDiagnostic {
ts_error("1184", "Modifiers cannot appear here.").with_label(span)
}
3 changes: 3 additions & 0 deletions crates/oxc_parser/src/js/class.rs
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,9 @@ impl<'a> ParserImpl<'a> {
for decorator in decorators {
self.error(diagnostics::decorators_are_not_valid_here(decorator.span));
}
for modifier in modifiers.iter() {
self.error(diagnostics::modifiers_cannot_appear_here(modifier.span));
}
return self.parse_class_static_block(span);
}

Expand Down
92 changes: 73 additions & 19 deletions tasks/coverage/snapshots/parser_babel.snap
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ commit: 1d4546bc
parser_babel Summary:
AST Parsed : 2351/2362 (99.53%)
Positive Passed: 2329/2362 (98.60%)
Negative Passed: 1592/1698 (93.76%)
Negative Passed: 1601/1698 (94.29%)
Expect Syntax Error: tasks/coverage/babel/packages/babel-parser/test/fixtures/core/categorized/invalid-startindex-and-startline-specified-without-startcolumn/input.js

Expect Syntax Error: tasks/coverage/babel/packages/babel-parser/test/fixtures/core/categorized/startline-and-startcolumn-specified/input.js
Expand Down Expand Up @@ -138,24 +138,6 @@ Expect Syntax Error: tasks/coverage/babel/packages/babel-parser/test/fixtures/ty

Expect Syntax Error: tasks/coverage/babel/packages/babel-parser/test/fixtures/typescript/regression/keyword-qualified-type-disallowed-babel-7/input.ts

Expect Syntax Error: tasks/coverage/babel/packages/babel-parser/test/fixtures/typescript/static-blocks/invalid-static-block-with-accessibility-private-01/input.ts

Expect Syntax Error: tasks/coverage/babel/packages/babel-parser/test/fixtures/typescript/static-blocks/invalid-static-block-with-accessibility-protected-01/input.ts

Expect Syntax Error: tasks/coverage/babel/packages/babel-parser/test/fixtures/typescript/static-blocks/invalid-static-block-with-accessibility-public-01/input.ts

Expect Syntax Error: tasks/coverage/babel/packages/babel-parser/test/fixtures/typescript/static-blocks/invalid-static-block-with-modifier-abstract-01/input.ts

Expect Syntax Error: tasks/coverage/babel/packages/babel-parser/test/fixtures/typescript/static-blocks/invalid-static-block-with-modifier-override-01/input.ts

Expect Syntax Error: tasks/coverage/babel/packages/babel-parser/test/fixtures/typescript/static-blocks/invalid-static-block-with-modifier-override-01/invalid-static-block-with-modifier-abstract/input.ts

Expect Syntax Error: tasks/coverage/babel/packages/babel-parser/test/fixtures/typescript/static-blocks/invalid-static-block-with-modifier-static/input.ts

Expect Syntax Error: tasks/coverage/babel/packages/babel-parser/test/fixtures/typescript/static-blocks/invalid-static-blocks-with-modifer-declare-01/input.ts

Expect Syntax Error: tasks/coverage/babel/packages/babel-parser/test/fixtures/typescript/static-blocks/invalid-static-blocks-with-modifier-readonly-01/input.ts

Expect Syntax Error: tasks/coverage/babel/packages/babel-parser/test/fixtures/typescript/type-arguments/empty-function/input.ts

Expect Syntax Error: tasks/coverage/babel/packages/babel-parser/test/fixtures/typescript/type-arguments/empty-function-babel-7/input.ts
Expand Down Expand Up @@ -13170,6 +13152,14 @@ Expect to Parse: tasks/coverage/babel/packages/babel-parser/test/fixtures/typesc
· ╰── It can not be redeclared here
╰────

× TS(1184): Modifiers cannot appear here.
╭─[babel/packages/babel-parser/test/fixtures/typescript/static-blocks/invalid-static-block-with-accessibility-private-01/input.ts:2:3]
1 │ class Foo {
2 │ private static {}
· ───────
3 │ }
╰────

× Unexpected token
╭─[babel/packages/babel-parser/test/fixtures/typescript/static-blocks/invalid-static-block-with-accessibility-private-02/input.ts:2:18]
1 │ class Foo {
Expand All @@ -13178,6 +13168,14 @@ Expect to Parse: tasks/coverage/babel/packages/babel-parser/test/fixtures/typesc
3 │ }
╰────

× TS(1184): Modifiers cannot appear here.
╭─[babel/packages/babel-parser/test/fixtures/typescript/static-blocks/invalid-static-block-with-accessibility-protected-01/input.ts:2:3]
1 │ class Foo {
2 │ protected static {}
· ─────────
3 │ }
╰────

× Unexpected token
╭─[babel/packages/babel-parser/test/fixtures/typescript/static-blocks/invalid-static-block-with-accessibility-protected-02/input.ts:2:20]
1 │ class Foo {
Expand All @@ -13186,6 +13184,14 @@ Expect to Parse: tasks/coverage/babel/packages/babel-parser/test/fixtures/typesc
3 │ }
╰────

× TS(1184): Modifiers cannot appear here.
╭─[babel/packages/babel-parser/test/fixtures/typescript/static-blocks/invalid-static-block-with-accessibility-public-01/input.ts:2:3]
1 │ class Foo {
2 │ public static {}
· ──────
3 │ }
╰────

× Unexpected token
╭─[babel/packages/babel-parser/test/fixtures/typescript/static-blocks/invalid-static-block-with-accessibility-public-02/input.ts:2:17]
1 │ class Foo {
Expand All @@ -13194,6 +13200,14 @@ Expect to Parse: tasks/coverage/babel/packages/babel-parser/test/fixtures/typesc
3 │ }
╰────

× TS(1184): Modifiers cannot appear here.
╭─[babel/packages/babel-parser/test/fixtures/typescript/static-blocks/invalid-static-block-with-modifier-abstract-01/input.ts:2:3]
1 │ class Foo {
2 │ abstract static {}
· ────────
3 │ }
╰────

× Unexpected token
╭─[babel/packages/babel-parser/test/fixtures/typescript/static-blocks/invalid-static-block-with-modifier-abstract-02/input.ts:2:19]
1 │ class Foo {
Expand All @@ -13202,6 +13216,22 @@ Expect to Parse: tasks/coverage/babel/packages/babel-parser/test/fixtures/typesc
3 │ }
╰────

× TS(1184): Modifiers cannot appear here.
╭─[babel/packages/babel-parser/test/fixtures/typescript/static-blocks/invalid-static-block-with-modifier-override-01/input.ts:2:3]
1 │ class Foo {
2 │ override static {}
· ────────
3 │ }
╰────

× TS(1184): Modifiers cannot appear here.
╭─[babel/packages/babel-parser/test/fixtures/typescript/static-blocks/invalid-static-block-with-modifier-override-01/invalid-static-block-with-modifier-abstract/input.ts:2:3]
1 │ class Foo {
2 │ abstract static {}
· ────────
3 │ }
╰────

× Unexpected token
╭─[babel/packages/babel-parser/test/fixtures/typescript/static-blocks/invalid-static-block-with-modifier-override-02/input.ts:2:19]
1 │ class Foo {
Expand All @@ -13210,6 +13240,22 @@ Expect to Parse: tasks/coverage/babel/packages/babel-parser/test/fixtures/typesc
3 │ }
╰────

× TS(1184): Modifiers cannot appear here.
╭─[babel/packages/babel-parser/test/fixtures/typescript/static-blocks/invalid-static-block-with-modifier-static/input.ts:2:3]
1 │ class Foo {
2 │ static static {}
· ──────
3 │ }
╰────

× TS(1184): Modifiers cannot appear here.
╭─[babel/packages/babel-parser/test/fixtures/typescript/static-blocks/invalid-static-blocks-with-modifer-declare-01/input.ts:2:3]
1 │ class Foo {
2 │ declare static {}
· ───────
3 │ }
╰────

× Unexpected token
╭─[babel/packages/babel-parser/test/fixtures/typescript/static-blocks/invalid-static-blocks-with-modifer-declare-02/input.ts:2:18]
1 │ class Foo {
Expand All @@ -13218,6 +13264,14 @@ Expect to Parse: tasks/coverage/babel/packages/babel-parser/test/fixtures/typesc
3 │ }
╰────

× TS(1184): Modifiers cannot appear here.
╭─[babel/packages/babel-parser/test/fixtures/typescript/static-blocks/invalid-static-blocks-with-modifier-readonly-01/input.ts:2:3]
1 │ class Foo {
2 │ readonly static {}
· ────────
3 │ }
╰────

× Unexpected token
╭─[babel/packages/babel-parser/test/fixtures/typescript/static-blocks/invalid-static-blocks-with-modifier-readonly-02/input.ts:2:19]
1 │ class Foo {
Expand Down
36 changes: 33 additions & 3 deletions tasks/coverage/snapshots/parser_typescript.snap
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ commit: 81c95189
parser_typescript Summary:
AST Parsed : 6530/6537 (99.89%)
Positive Passed: 6519/6537 (99.72%)
Negative Passed: 1400/5763 (24.29%)
Negative Passed: 1401/5763 (24.31%)
Expect Syntax Error: tasks/coverage/typescript/tests/cases/compiler/ClassDeclaration24.ts

Expect Syntax Error: tasks/coverage/typescript/tests/cases/compiler/ExportAssignment7.ts
Expand Down Expand Up @@ -4628,8 +4628,6 @@ Expect Syntax Error: tasks/coverage/typescript/tests/cases/conformance/classes/c

Expect Syntax Error: tasks/coverage/typescript/tests/cases/conformance/classes/classExpressions/classWithStaticFieldInParameterInitializer.2.ts

Expect Syntax Error: tasks/coverage/typescript/tests/cases/conformance/classes/classStaticBlock/classStaticBlock20.ts

Expect Syntax Error: tasks/coverage/typescript/tests/cases/conformance/classes/classStaticBlock/classStaticBlock23.ts

Expect Syntax Error: tasks/coverage/typescript/tests/cases/conformance/classes/classStaticBlock/classStaticBlock3.ts
Expand Down Expand Up @@ -19091,6 +19089,38 @@ Expect to Parse: tasks/coverage/typescript/tests/cases/conformance/salsa/private
3 │ static {
╰────

× TS(1184): Modifiers cannot appear here.
╭─[typescript/tests/cases/conformance/classes/classStaticBlock/classStaticBlock20.ts:2:5]
1 │ class C {
2 │ async static {
· ─────
3 │ // something
╰────

× TS(1184): Modifiers cannot appear here.
╭─[typescript/tests/cases/conformance/classes/classStaticBlock/classStaticBlock20.ts:6:5]
5 │
6 │ public static {
· ──────
7 │ // something
╰────

× TS(1184): Modifiers cannot appear here.
╭─[typescript/tests/cases/conformance/classes/classStaticBlock/classStaticBlock20.ts:10:5]
9 │
10 │ readonly private static {
· ────────
11 │ // something
╰────

× TS(1184): Modifiers cannot appear here.
╭─[typescript/tests/cases/conformance/classes/classStaticBlock/classStaticBlock20.ts:10:14]
9 │
10 │ readonly private static {
· ───────
11 │ // something
╰────

× Cannot use `await` as an identifier in an async context
╭─[typescript/tests/cases/conformance/classes/classStaticBlock/classStaticBlock22.ts:4:9]
3 │ static {
Expand Down
Loading
0