Skip to content
Closed
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
6 changes: 5 additions & 1 deletion crates/oxc_codegen/tests/integration/ts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand All @@ -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]
Expand Down
5 changes: 5 additions & 0 deletions crates/oxc_codegen/tests/integration/unit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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__() {} }");

// <https://tc39.es/ecma262/2024/multipage/ecmascript-language-functions-and-classes.html#sec-static-semantics-classelementkind>
// <https://tc39.es/ecma262/2024/multipage/ecmascript-language-functions-and-classes.html#sec-class-definitions-static-semantics-early-errors>
Expand Down
2 changes: 1 addition & 1 deletion crates/oxc_parser/src/js/class.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
22 changes: 17 additions & 5 deletions tasks/coverage/snapshots/parser_babel.snap
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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){}}
Expand Down Expand Up @@ -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 {
Expand Down
76 changes: 63 additions & 13 deletions tasks/coverage/snapshots/parser_typescript.snap
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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() {
Expand All @@ -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 {
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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 {
Expand All @@ -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 {
Expand Down Expand Up @@ -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 {
Expand Down
Loading