diff --git a/crates/oxc_codegen/tests/integration/ts.rs b/crates/oxc_codegen/tests/integration/ts.rs index 6b0ff75024e81..92c50c11c29d5 100644 --- a/crates/oxc_codegen/tests/integration/ts.rs +++ b/crates/oxc_codegen/tests/integration/ts.rs @@ -2,7 +2,7 @@ use oxc_codegen::CodegenOptions; use crate::{ snapshot, snapshot_options, - tester::{test_same, test_tsx}, + tester::{test, test_same, test_tsx}, }; #[test] @@ -14,6 +14,10 @@ fn cases() { test_same( "class Foo {\n\t#name: string;\n\tf() {\n\t\t#name in other && this.#name === other.#name;\n\t}\n}\n", ); + test( + "class C {\n\tstatic\nstatic\n\tstatic\na() {}\n}\n", + "class C {\n\tstatic static;\n\tstatic a() {}\n}\n", + ); } #[test] diff --git a/crates/oxc_codegen/tests/integration/unit.rs b/crates/oxc_codegen/tests/integration/unit.rs index 3dc78c249b4ac..d8d797593f880 100644 --- a/crates/oxc_codegen/tests/integration/unit.rs +++ b/crates/oxc_codegen/tests/integration/unit.rs @@ -75,6 +75,11 @@ fn class() { "export default class Foo {\n\t@x @y accessor #aDef = 1;\n}\n", ); test_minify("class { static [computed] }", "class{static[computed]}"); + + test( + "class C {\n\tstatic\nstatic\n\tstatic\na() {}\n}\n", + "class C {\n\tstatic static;\n\tstatic a() {}\n}\n", + ); } #[test] diff --git a/crates/oxc_minifier/src/peephole/substitute_alternate_syntax.rs b/crates/oxc_minifier/src/peephole/substitute_alternate_syntax.rs index 1551c7ea894a8..04e6be287393b 100644 --- a/crates/oxc_minifier/src/peephole/substitute_alternate_syntax.rs +++ b/crates/oxc_minifier/src/peephole/substitute_alternate_syntax.rs @@ -1800,7 +1800,6 @@ mod test { "class C { static accessor ['__proto__'] = 0 }", "class C { static accessor __proto__ = 0 }", ); - test("class C { static static ['__proto__']() {} }", "class C { static __proto__() {} }"); // // diff --git a/crates/oxc_parser/src/js/class.rs b/crates/oxc_parser/src/js/class.rs index ac0bf162db1cb..d7de3ac373187 100644 --- a/crates/oxc_parser/src/js/class.rs +++ b/crates/oxc_parser/src/js/class.rs @@ -209,7 +209,7 @@ impl<'a> ParserImpl<'a> { let mut r#static = modifiers.contains(ModifierKind::Static); let mut r#async = modifiers.contains(ModifierKind::Async); - if self.at(Kind::Static) { + if !r#static && self.at(Kind::Static) { // static { block } if self.peek_at(Kind::LCurly) { self.bump(Kind::Static); diff --git a/tasks/coverage/snapshots/parser_babel.snap b/tasks/coverage/snapshots/parser_babel.snap index cefbbce2fc167..19cc9c5b4340b 100644 --- a/tasks/coverage/snapshots/parser_babel.snap +++ b/tasks/coverage/snapshots/parser_babel.snap @@ -3,7 +3,7 @@ commit: 578ac4df parser_babel Summary: AST Parsed : 2309/2322 (99.44%) Positive Passed: 2288/2322 (98.54%) -Negative Passed: 1560/1673 (93.25%) +Negative Passed: 1562/1673 (93.37%) 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 @@ -40,8 +40,6 @@ Expect Syntax Error: tasks/coverage/babel/packages/babel-parser/test/fixtures/es Expect Syntax Error: tasks/coverage/babel/packages/babel-parser/test/fixtures/esprima/es2015-generator/generator-parameter-binding-property-reserved/input.js -Expect Syntax Error: tasks/coverage/babel/packages/babel-parser/test/fixtures/esprima/invalid-syntax/migrated_0276/input.js - Expect Syntax Error: tasks/coverage/babel/packages/babel-parser/test/fixtures/estree/class-private-property/typescript-invalid-abstract/input.ts Expect Syntax Error: tasks/coverage/babel/packages/babel-parser/test/fixtures/estree/class-private-property/typescript-invalid-abstract-babel-7/input.ts @@ -172,8 +170,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/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 @@ -11394,6 +11390,13 @@ Expect to Parse: tasks/coverage/babel/packages/babel-parser/test/fixtures/typesc ╰──── help: Try insert a semicolon here + × Expected a semicolon or an implicit semicolon after a statement, but found none + ╭─[babel/packages/babel-parser/test/fixtures/esprima/invalid-syntax/migrated_0276/input.js:1:23] + 1 │ class A {static static static(){}} + · ▲ + ╰──── + help: Try insert a semicolon here + × Identifier expected. 'enum' is a reserved word that cannot be used here. ╭─[babel/packages/babel-parser/test/fixtures/esprima/invalid-syntax/migrated_0277/input.js:1:12] 1 │ class A {a(enum){}} @@ -12944,6 +12947,15 @@ Expect to Parse: tasks/coverage/babel/packages/babel-parser/test/fixtures/typesc 3 │ } ╰──── + × Expected a semicolon or an implicit semicolon after a statement, but found none + ╭─[babel/packages/babel-parser/test/fixtures/typescript/static-blocks/invalid-static-block-with-modifier-static/input.ts:2:16] + 1 │ class Foo { + 2 │ static static {} + · ▲ + 3 │ } + ╰──── + help: Try insert a semicolon here + × 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 { diff --git a/tasks/coverage/snapshots/parser_typescript.snap b/tasks/coverage/snapshots/parser_typescript.snap index f93492027c1c9..ab2039b36c58c 100644 --- a/tasks/coverage/snapshots/parser_typescript.snap +++ b/tasks/coverage/snapshots/parser_typescript.snap @@ -3,7 +3,7 @@ commit: 15392346 parser_typescript Summary: AST Parsed : 6521/6528 (99.89%) Positive Passed: 6509/6528 (99.71%) -Negative Passed: 1315/5757 (22.84%) +Negative Passed: 1321/5757 (22.95%) Expect Syntax Error: tasks/coverage/typescript/tests/cases/compiler/ClassDeclaration24.ts Expect Syntax Error: tasks/coverage/typescript/tests/cases/compiler/ExportAssignment7.ts @@ -3742,8 +3742,6 @@ Expect Syntax Error: tasks/coverage/typescript/tests/cases/compiler/spreadOfPara Expect Syntax Error: tasks/coverage/typescript/tests/cases/compiler/spyComparisonChecking.ts -Expect Syntax Error: tasks/coverage/typescript/tests/cases/compiler/staticAsIdentifier.ts - Expect Syntax Error: tasks/coverage/typescript/tests/cases/compiler/staticClassMemberError.ts Expect Syntax Error: tasks/coverage/typescript/tests/cases/compiler/staticInstanceResolution4.ts @@ -3760,8 +3758,6 @@ Expect Syntax Error: tasks/coverage/typescript/tests/cases/compiler/staticMethod Expect Syntax Error: tasks/coverage/typescript/tests/cases/compiler/staticMismatchBecauseOfPrototype.ts -Expect Syntax Error: tasks/coverage/typescript/tests/cases/compiler/staticModifierAlreadySeen.ts - Expect Syntax Error: tasks/coverage/typescript/tests/cases/compiler/staticMustPrecedePublic.ts Expect Syntax Error: tasks/coverage/typescript/tests/cases/compiler/staticOffOfInstance1.ts @@ -7486,8 +7482,6 @@ Expect Syntax Error: tasks/coverage/typescript/tests/cases/conformance/parser/ec Expect Syntax Error: tasks/coverage/typescript/tests/cases/conformance/parser/ecmascript5/Generics/parserObjectCreation1.ts -Expect Syntax Error: tasks/coverage/typescript/tests/cases/conformance/parser/ecmascript5/IndexMemberDeclarations/parserIndexMemberDeclaration10.ts - Expect Syntax Error: tasks/coverage/typescript/tests/cases/conformance/parser/ecmascript5/IndexMemberDeclarations/parserIndexMemberDeclaration5.ts Expect Syntax Error: tasks/coverage/typescript/tests/cases/conformance/parser/ecmascript5/IndexSignatures/parserIndexSignature4.ts @@ -7512,18 +7506,12 @@ Expect Syntax Error: tasks/coverage/typescript/tests/cases/conformance/parser/ec Expect Syntax Error: tasks/coverage/typescript/tests/cases/conformance/parser/ecmascript5/MemberAccessorDeclarations/parserMemberAccessorDeclaration3.ts -Expect Syntax Error: tasks/coverage/typescript/tests/cases/conformance/parser/ecmascript5/MemberAccessorDeclarations/parserMemberAccessorDeclaration8.ts - Expect Syntax Error: tasks/coverage/typescript/tests/cases/conformance/parser/ecmascript5/MemberAccessorDeclarations/parserMemberAccessorDeclaration9.ts -Expect Syntax Error: tasks/coverage/typescript/tests/cases/conformance/parser/ecmascript5/MemberFunctionDeclarations/parserMemberFunctionDeclaration2.ts - Expect Syntax Error: tasks/coverage/typescript/tests/cases/conformance/parser/ecmascript5/MemberFunctionDeclarations/parserMemberFunctionDeclaration3.ts Expect Syntax Error: tasks/coverage/typescript/tests/cases/conformance/parser/ecmascript5/MemberFunctionDeclarations/parserMemberFunctionDeclaration5.ts -Expect Syntax Error: tasks/coverage/typescript/tests/cases/conformance/parser/ecmascript5/MemberVariableDeclarations/parserMemberVariableDeclaration2.ts - Expect Syntax Error: tasks/coverage/typescript/tests/cases/conformance/parser/ecmascript5/MemberVariableDeclarations/parserMemberVariableDeclaration3.ts Expect Syntax Error: tasks/coverage/typescript/tests/cases/conformance/parser/ecmascript5/ModuleDeclarations/parserModuleDeclaration1.d.ts @@ -14445,6 +14433,15 @@ Expect to Parse: tasks/coverage/typescript/tests/cases/conformance/salsa/private ╰──── help: Remove the duplicate modifier. + × Expected a semicolon or an implicit semicolon after a statement, but found none + ╭─[typescript/tests/cases/compiler/multipleClassPropertyModifiersErrors.ts:4:15] + 3 │ private private p2; + 4 │ static static p3; + · ▲ + 5 │ public private p4; + ╰──── + help: Try insert a semicolon here + × Identifier `x` has already been declared ╭─[typescript/tests/cases/compiler/nameCollisions.ts:2:9] 1 │ module T { @@ -16425,6 +16422,15 @@ Expect to Parse: tasks/coverage/typescript/tests/cases/conformance/salsa/private ╰──── help: A `break` statement can only be used within an enclosing iteration or switch statement. + × Expected a semicolon or an implicit semicolon after a statement, but found none + ╭─[typescript/tests/cases/compiler/staticAsIdentifier.ts:12:18] + 11 │ class C3 { + 12 │ static static p: string; + · ▲ + 13 │ } + ╰──── + help: Try insert a semicolon here + × Expected a semicolon or an implicit semicolon after a statement, but found none ╭─[typescript/tests/cases/compiler/staticClassProps.ts:4:15] 3 │ public foo() { @@ -16434,6 +16440,15 @@ Expect to Parse: tasks/coverage/typescript/tests/cases/conformance/salsa/private ╰──── help: Try insert a semicolon here + × Expected a semicolon or an implicit semicolon after a statement, but found none + ╭─[typescript/tests/cases/compiler/staticModifierAlreadySeen.ts:2:18] + 1 │ class C { + 2 │ static static foo = 1; + · ▲ + 3 │ public static static bar() { } + ╰──── + help: Try insert a semicolon here + × Classes may not have a static property named prototype ╭─[typescript/tests/cases/compiler/staticPrototypeProperty.ts:2:11] 1 │ class C { @@ -26507,6 +26522,14 @@ Expect to Parse: tasks/coverage/typescript/tests/cases/conformance/salsa/private · ─ ╰──── + × Unexpected token + ╭─[typescript/tests/cases/conformance/parser/ecmascript5/IndexMemberDeclarations/parserIndexMemberDeclaration10.ts:2:18] + 1 │ class C { + 2 │ static static [x: string]: string; + · ─ + 3 │ } + ╰──── + × TS(1071): 'public' modifier cannot appear on an index signature. ╭─[typescript/tests/cases/conformance/parser/ecmascript5/IndexMemberDeclarations/parserIndexMemberDeclaration7.ts:2:4] 1 │ class C { @@ -26688,6 +26711,15 @@ Expect to Parse: tasks/coverage/typescript/tests/cases/conformance/salsa/private ╰──── help: Remove the duplicate modifier. + × Expected a semicolon or an implicit semicolon after a statement, but found none + ╭─[typescript/tests/cases/conformance/parser/ecmascript5/MemberAccessorDeclarations/parserMemberAccessorDeclaration8.ts:2:18] + 1 │ class C { + 2 │ static static get Foo() { } + · ▲ + 3 │ } + ╰──── + help: Try insert a semicolon here + × TS(1030): public' modifier already seen. ╭─[typescript/tests/cases/conformance/parser/ecmascript5/MemberFunctionDeclarations/parserMemberFunctionDeclaration1.ts:2:12] 1 │ class C { @@ -26697,6 +26729,15 @@ Expect to Parse: tasks/coverage/typescript/tests/cases/conformance/salsa/private ╰──── help: Remove the duplicate modifier. + × Expected a semicolon or an implicit semicolon after a statement, but found none + ╭─[typescript/tests/cases/conformance/parser/ecmascript5/MemberFunctionDeclarations/parserMemberFunctionDeclaration2.ts:2:18] + 1 │ class C { + 2 │ static static Foo() { } + · ▲ + 3 │ } + ╰──── + help: Try insert a semicolon here + × Expected a semicolon or an implicit semicolon after a statement, but found none ╭─[typescript/tests/cases/conformance/parser/ecmascript5/MemberFunctionDeclarations/parserMemberFunctionDeclaration4.ts:2:11] 1 │ class C { @@ -26771,6 +26812,15 @@ Expect to Parse: tasks/coverage/typescript/tests/cases/conformance/salsa/private ╰──── help: Remove the duplicate modifier. + × Expected a semicolon or an implicit semicolon after a statement, but found none + ╭─[typescript/tests/cases/conformance/parser/ecmascript5/MemberVariableDeclarations/parserMemberVariableDeclaration2.ts:2:16] + 1 │ class C { + 2 │ static static Foo; + · ▲ + 3 │ } + ╰──── + help: Try insert a semicolon here + × Expected a semicolon or an implicit semicolon after a statement, but found none ╭─[typescript/tests/cases/conformance/parser/ecmascript5/MemberVariableDeclarations/parserMemberVariableDeclaration4.ts:2:9] 1 │ class C {