Skip to content
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
refactor(semantic): align handling of declaring symbol for class wi…
…th TypeScript (#10094)

Same as #10086 but for `class`
  • Loading branch information
Dunqing committed Mar 29, 2025
commit dc3602c36482a636cbe0e180d5d73e2d431f68a6
6 changes: 1 addition & 5 deletions crates/oxc_semantic/src/binder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -122,11 +122,7 @@ impl<'a> Binder<'a> for Class<'a> {
ident.span,
&ident.name,
SymbolFlags::Class,
if self.is_declaration() {
SymbolFlags::ClassExcludes
} else {
SymbolFlags::empty()
},
SymbolFlags::ClassExcludes,
);
ident.symbol_id.set(Some(symbol_id));
}
Expand Down
3 changes: 2 additions & 1 deletion crates/oxc_syntax/src/symbol.rs
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,8 @@ bitflags! {
/// they can not merge with anything in the value space
const BlockScopedVariableExcludes = Self::Value.bits();
const FunctionExcludes = Self::Value.bits() & !(Self::Function.bits() | Self::ValueModule.bits() | Self::Class.bits());
const ClassExcludes = (Self::Value.bits() | Self::TypeAlias.bits()) & !(Self::ValueModule.bits() | Self::Interface.bits());
const ClassExcludes = (Self::Value.bits() | Self::Type.bits()) & !(Self::ValueModule.bits() | Self::Function.bits() | Self::Interface.bits());

const ImportBindingExcludes = Self::Import.bits() | Self::TypeImport.bits();
// Type specific excludes
const TypeAliasExcludes = Self::Type.bits();
Expand Down
72 changes: 0 additions & 72 deletions tasks/coverage/snapshots/parser_test262.snap
Original file line number Diff line number Diff line change
Expand Up @@ -2691,15 +2691,6 @@ Expect to Parse: tasks/coverage/test262/test/language/statements/function/S14_A5
× Identifier `f` has already been declared
╭─[test262/test/language/block-scope/syntax/redeclaration/async-function-name-redeclaration-attempt-with-class.js:24:18]
23 │
24 │ { async function f() {} class f {} }
· ┬ ┬
· │ ╰── It can not be redeclared here
· ╰── `f` has already been declared here
╰────

× Identifier `f` has already been declared
╭─[test262/test/language/block-scope/syntax/redeclaration/async-function-name-redeclaration-attempt-with-class.js:24:18]
23 │
24 │ { async function f() {} class f {} }
· ┬ ┬
· │ ╰── It can not be redeclared here
Expand Down Expand Up @@ -2772,15 +2763,6 @@ Expect to Parse: tasks/coverage/test262/test/language/statements/function/S14_A5
× Identifier `f` has already been declared
╭─[test262/test/language/block-scope/syntax/redeclaration/async-generator-name-redeclaration-attempt-with-class.js:24:19]
23 │
24 │ { async function* f() {} class f {} }
· ┬ ┬
· │ ╰── It can not be redeclared here
· ╰── `f` has already been declared here
╰────

× Identifier `f` has already been declared
╭─[test262/test/language/block-scope/syntax/redeclaration/async-generator-name-redeclaration-attempt-with-class.js:24:19]
23 │
24 │ { async function* f() {} class f {} }
· ┬ ┬
· │ ╰── It can not be redeclared here
Expand Down Expand Up @@ -3082,15 +3064,6 @@ Expect to Parse: tasks/coverage/test262/test/language/statements/function/S14_A5
× Identifier `f` has already been declared
╭─[test262/test/language/block-scope/syntax/redeclaration/function-name-redeclaration-attempt-with-class.js:23:12]
22 │
23 │ { function f() {} class f {} }
· ┬ ┬
· │ ╰── It can not be redeclared here
· ╰── `f` has already been declared here
╰────

× Identifier `f` has already been declared
╭─[test262/test/language/block-scope/syntax/redeclaration/function-name-redeclaration-attempt-with-class.js:23:12]
22 │
23 │ { function f() {} class f {} }
· ┬ ┬
· │ ╰── It can not be redeclared here
Expand Down Expand Up @@ -3163,15 +3136,6 @@ Expect to Parse: tasks/coverage/test262/test/language/statements/function/S14_A5
× Identifier `f` has already been declared
╭─[test262/test/language/block-scope/syntax/redeclaration/generator-name-redeclaration-attempt-with-class.js:24:13]
23 │
24 │ { function* f() {} class f {} }
· ┬ ┬
· │ ╰── It can not be redeclared here
· ╰── `f` has already been declared here
╰────

× Identifier `f` has already been declared
╭─[test262/test/language/block-scope/syntax/redeclaration/generator-name-redeclaration-attempt-with-class.js:24:13]
23 │
24 │ { function* f() {} class f {} }
· ┬ ┬
· │ ╰── It can not be redeclared here
Expand Down Expand Up @@ -38288,15 +38252,6 @@ Expect to Parse: tasks/coverage/test262/test/language/statements/function/S14_A5
× Identifier `f` has already been declared
╭─[test262/test/language/statements/switch/syntax/redeclaration/async-function-name-redeclaration-attempt-with-class.js:24:37]
23 │
24 │ switch (0) { case 1: async function f() {} default: class f {} }
· ┬ ┬
· │ ╰── It can not be redeclared here
· ╰── `f` has already been declared here
╰────

× Identifier `f` has already been declared
╭─[test262/test/language/statements/switch/syntax/redeclaration/async-function-name-redeclaration-attempt-with-class.js:24:37]
23 │
24 │ switch (0) { case 1: async function f() {} default: class f {} }
· ┬ ┬
· │ ╰── It can not be redeclared here
Expand Down Expand Up @@ -38369,15 +38324,6 @@ Expect to Parse: tasks/coverage/test262/test/language/statements/function/S14_A5
× Identifier `f` has already been declared
╭─[test262/test/language/statements/switch/syntax/redeclaration/async-generator-name-redeclaration-attempt-with-class.js:24:38]
23 │
24 │ switch (0) { case 1: async function* f() {} default: class f {} }
· ┬ ┬
· │ ╰── It can not be redeclared here
· ╰── `f` has already been declared here
╰────

× Identifier `f` has already been declared
╭─[test262/test/language/statements/switch/syntax/redeclaration/async-generator-name-redeclaration-attempt-with-class.js:24:38]
23 │
24 │ switch (0) { case 1: async function* f() {} default: class f {} }
· ┬ ┬
· │ ╰── It can not be redeclared here
Expand Down Expand Up @@ -38594,15 +38540,6 @@ Expect to Parse: tasks/coverage/test262/test/language/statements/function/S14_A5
× Identifier `f` has already been declared
╭─[test262/test/language/statements/switch/syntax/redeclaration/function-name-redeclaration-attempt-with-class.js:23:31]
22 │
23 │ switch (0) { case 1: function f() {} default: class f {} }
· ┬ ┬
· │ ╰── It can not be redeclared here
· ╰── `f` has already been declared here
╰────

× Identifier `f` has already been declared
╭─[test262/test/language/statements/switch/syntax/redeclaration/function-name-redeclaration-attempt-with-class.js:23:31]
22 │
23 │ switch (0) { case 1: function f() {} default: class f {} }
· ┬ ┬
· │ ╰── It can not be redeclared here
Expand Down Expand Up @@ -38675,15 +38612,6 @@ Expect to Parse: tasks/coverage/test262/test/language/statements/function/S14_A5
× Identifier `f` has already been declared
╭─[test262/test/language/statements/switch/syntax/redeclaration/generator-name-redeclaration-attempt-with-class.js:24:32]
23 │
24 │ switch (0) { case 1: function* f() {} default: class f {} }
· ┬ ┬
· │ ╰── It can not be redeclared here
· ╰── `f` has already been declared here
╰────

× Identifier `f` has already been declared
╭─[test262/test/language/statements/switch/syntax/redeclaration/generator-name-redeclaration-attempt-with-class.js:24:32]
23 │
24 │ switch (0) { case 1: function* f() {} default: class f {} }
· ┬ ┬
· │ ╰── It can not be redeclared here
Expand Down
132 changes: 8 additions & 124 deletions tasks/coverage/snapshots/parser_typescript.snap
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ commit: 15392346

parser_typescript Summary:
AST Parsed : 6522/6531 (99.86%)
Positive Passed: 6510/6531 (99.68%)
Negative Passed: 1296/5754 (22.52%)
Positive Passed: 6511/6531 (99.69%)
Negative Passed: 1290/5754 (22.42%)
Expect Syntax Error: tasks/coverage/typescript/tests/cases/compiler/ClassDeclaration24.ts
Expect Syntax Error: tasks/coverage/typescript/tests/cases/compiler/ExportAssignment7.ts
Expect Syntax Error: tasks/coverage/typescript/tests/cases/compiler/ExportAssignment8.ts
Expand Down Expand Up @@ -220,6 +220,9 @@ Expect Syntax Error: tasks/coverage/typescript/tests/cases/compiler/callOnInstan
Expect Syntax Error: tasks/coverage/typescript/tests/cases/compiler/callOverloadViaElementAccessExpression.ts
Expect Syntax Error: tasks/coverage/typescript/tests/cases/compiler/callOverloads1.ts
Expect Syntax Error: tasks/coverage/typescript/tests/cases/compiler/callOverloads2.ts
Expect Syntax Error: tasks/coverage/typescript/tests/cases/compiler/callOverloads3.ts
Expect Syntax Error: tasks/coverage/typescript/tests/cases/compiler/callOverloads4.ts
Expect Syntax Error: tasks/coverage/typescript/tests/cases/compiler/callOverloads5.ts
Expect Syntax Error: tasks/coverage/typescript/tests/cases/compiler/callSignaturesShouldBeResolvedBeforeSpecialization.ts
Expect Syntax Error: tasks/coverage/typescript/tests/cases/compiler/callWithWrongNumberOfTypeArguments.ts
Expect Syntax Error: tasks/coverage/typescript/tests/cases/compiler/callbackArgsDifferByOptionality.ts
Expand Down Expand Up @@ -318,6 +321,7 @@ Expect Syntax Error: tasks/coverage/typescript/tests/cases/compiler/classMemberI
Expect Syntax Error: tasks/coverage/typescript/tests/cases/compiler/classMergedWithInterfaceMultipleBasesNoError.ts
Expect Syntax Error: tasks/coverage/typescript/tests/cases/compiler/classOrder2.ts
Expect Syntax Error: tasks/coverage/typescript/tests/cases/compiler/classOverloadForFunction.ts
Expect Syntax Error: tasks/coverage/typescript/tests/cases/compiler/classOverloadForFunction2.ts
Expect Syntax Error: tasks/coverage/typescript/tests/cases/compiler/classPropertyErrorOnNameOnly.ts
Expect Syntax Error: tasks/coverage/typescript/tests/cases/compiler/classSideInheritance1.ts
Expect Syntax Error: tasks/coverage/typescript/tests/cases/compiler/classSideInheritance2.ts
Expand Down Expand Up @@ -848,6 +852,7 @@ Expect Syntax Error: tasks/coverage/typescript/tests/cases/compiler/forInStrictN
Expect Syntax Error: tasks/coverage/typescript/tests/cases/compiler/forwardDeclaredCommonTypes01.ts
Expect Syntax Error: tasks/coverage/typescript/tests/cases/compiler/forwardRefInClassProperties.ts
Expect Syntax Error: tasks/coverage/typescript/tests/cases/compiler/forwardRefInEnum.ts
Expect Syntax Error: tasks/coverage/typescript/tests/cases/compiler/funClodule.ts
Expect Syntax Error: tasks/coverage/typescript/tests/cases/compiler/functionAndImportNameConflict.ts
Expect Syntax Error: tasks/coverage/typescript/tests/cases/compiler/functionAndInterfaceWithSeparateErrors.ts
Expect Syntax Error: tasks/coverage/typescript/tests/cases/compiler/functionArgShadowing.ts
Expand Down Expand Up @@ -1880,6 +1885,7 @@ Expect Syntax Error: tasks/coverage/typescript/tests/cases/compiler/spreadInvali
Expect Syntax Error: tasks/coverage/typescript/tests/cases/compiler/spreadOfParamsFromGeneratorMakesRequiredParams.ts
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
Expect Syntax Error: tasks/coverage/typescript/tests/cases/compiler/staticInstanceResolution5.ts
Expect Syntax Error: tasks/coverage/typescript/tests/cases/compiler/staticMemberExportAccess.ts
Expand Down Expand Up @@ -4557,20 +4563,6 @@ Expect to Parse: tasks/coverage/typescript/tests/cases/compiler/bom-utf16be.ts
1 │ ￾瘀愀爀 砀㴀㄀ 㬀ഀ਀
· ─
╰────
Expect to Parse: tasks/coverage/typescript/tests/cases/compiler/constructorOverloads5.ts

× Identifier `RegExp` has already been declared
╭─[typescript/tests/cases/compiler/constructorOverloads5.ts:4:21]
3 │ declare module M {
4 │ export function RegExp(pattern: string): RegExp;
· ───┬──
· ╰── `RegExp` has already been declared here
5 │ export function RegExp(pattern: string, flags: string): RegExp;
6 │ export class RegExp {
· ───┬──
· ╰── It can not be redeclared here
7 │ constructor(pattern: string);
╰────
Expect to Parse: tasks/coverage/typescript/tests/cases/compiler/elidedEmbeddedStatementsReplacedWithSemicolon.ts

× 'with' statements are not allowed
Expand Down Expand Up @@ -5476,30 +5468,6 @@ Expect to Parse: tasks/coverage/typescript/tests/cases/conformance/salsa/private
13 │ foo() {
╰────

× Identifier `y3` has already been declared
╭─[typescript/tests/cases/compiler/augmentedTypesFunction.ts:13:10]
12 │ // function then class
13 │ function y3() { } // error
· ─┬
· ╰── `y3` has already been declared here
14 │ class y3 { } // error
· ─┬
· ╰── It can not be redeclared here
15 │
╰────

× Identifier `y3a` has already been declared
╭─[typescript/tests/cases/compiler/augmentedTypesFunction.ts:16:10]
15 │
16 │ function y3a() { } // error
· ─┬─
· ╰── `y3a` has already been declared here
17 │ class y3a { public foo() { } } // error
· ─┬─
· ╰── It can not be redeclared here
18 │
╰────

× Identifier `y4` has already been declared
╭─[typescript/tests/cases/compiler/augmentedTypesFunction.ts:20:10]
19 │ // function then enum
Expand Down Expand Up @@ -5857,42 +5825,6 @@ Expect to Parse: tasks/coverage/typescript/tests/cases/conformance/salsa/private
· ─
╰────

× Identifier `Foo` has already been declared
╭─[typescript/tests/cases/compiler/callOverloads3.ts:1:10]
1 │ function Foo():Foo; // error
· ─┬─
· ╰── `Foo` has already been declared here
2 │ function Foo(s:string):Foo; // error
3 │ class Foo { // error
· ─┬─
· ╰── It can not be redeclared here
4 │ bar1() { /*WScript.Echo("bar1");*/ }
╰────

× Identifier `Foo` has already been declared
╭─[typescript/tests/cases/compiler/callOverloads4.ts:1:10]
1 │ function Foo():Foo; // error
· ─┬─
· ╰── `Foo` has already been declared here
2 │ function Foo(s:string):Foo; // error
3 │ class Foo { // error
· ─┬─
· ╰── It can not be redeclared here
4 │ bar1() { /*WScript.Echo("bar1");*/ }
╰────

× Identifier `Foo` has already been declared
╭─[typescript/tests/cases/compiler/callOverloads5.ts:1:10]
1 │ function Foo():Foo; // error
· ─┬─
· ╰── `Foo` has already been declared here
2 │ function Foo(s:string):Foo; // error
3 │ class Foo { // error
· ─┬─
· ╰── It can not be redeclared here
4 │ bar1(s:string);
╰────

× Unexpected token
╭─[typescript/tests/cases/compiler/cannotInvokeNewOnErrorExpression.ts:5:22]
4 │ }
Expand Down Expand Up @@ -5997,16 +5929,6 @@ Expect to Parse: tasks/coverage/typescript/tests/cases/conformance/salsa/private
3 │ }
╰────

× Identifier `bar` has already been declared
╭─[typescript/tests/cases/compiler/classOverloadForFunction2.ts:1:10]
1 │ function bar(): string;
· ─┬─
· ╰── `bar` has already been declared here
2 │ class bar {}
· ─┬─
· ╰── It can not be redeclared here
╰────

× Expected a semicolon or an implicit semicolon after a statement, but found none
╭─[typescript/tests/cases/compiler/classUpdateTests.ts:93:9]
92 │ constructor() {
Expand Down Expand Up @@ -8307,20 +8229,6 @@ Expect to Parse: tasks/coverage/typescript/tests/cases/conformance/salsa/private
╰────
help: This iterator's type will be inferred from the iterable. You can safely remove the type annotation.

× Identifier `foo3` has already been declared
╭─[typescript/tests/cases/compiler/funClodule.ts:15:10]
14 │
15 │ function foo3() { }
· ──┬─
· ╰── `foo3` has already been declared here
16 │ module foo3 {
17 │ export function x(): any { }
18 │ }
19 │ class foo3 { } // Should error
· ──┬─
· ╰── It can not be redeclared here
╰────

× Identifier `aaaaa` has already been declared
╭─[typescript/tests/cases/compiler/functionAndPropertyNameConflict.ts:2:12]
1 │ class C65 {
Expand Down Expand Up @@ -10006,18 +9914,6 @@ Expect to Parse: tasks/coverage/typescript/tests/cases/conformance/salsa/private
26 │
╰────

× Identifier `C2` has already been declared
╭─[typescript/tests/cases/compiler/nameCollisions.ts:36:14]
35 │
36 │ function C2() { }
· ─┬
· ╰── `C2` has already been declared here
37 │ class C2 { } // error
· ─┬
· ╰── It can not be redeclared here
38 │
╰────

× Expected a semicolon or an implicit semicolon after a statement, but found none
╭─[typescript/tests/cases/compiler/nestedGlobalNamespaceInClass.ts:3:11]
2 │ class C {
Expand Down Expand Up @@ -12120,18 +12016,6 @@ 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.

× Identifier `Foo` has already been declared
╭─[typescript/tests/cases/compiler/staticClassMemberError.ts:9:10]
8 │ // just want to make sure this one doesn't crash the compiler
9 │ function Foo();
· ─┬─
· ╰── `Foo` has already been declared here
10 │ class Foo {
· ─┬─
· ╰── It can not be redeclared here
11 │ static bar;
╰────

× 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 Down
Loading