-
-
Notifications
You must be signed in to change notification settings - Fork 859
fix(isolated-declarations): align readonly class array initializer diagnostics with tsc #19218
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
graphite-app
merged 1 commit into
main
from
c/02-10-refactor_isolated-declarations_remove_dead_branch
Feb 10, 2026
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
41 changes: 41 additions & 0 deletions
41
crates/oxc_isolated_declarations/tests/fixtures/readonly-class-property-variations.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,41 @@ | ||
| const tuple = [1, 2] as const; | ||
| const n = 3; | ||
|
|
||
| declare function fn(): number; | ||
|
|
||
| export class ReadonlyClassPropertyVariations { | ||
| readonly emptyArray = []; | ||
| readonly emptyArrayAsConst = [] as const; | ||
| readonly emptyArrayWithTypeAnnotation: number[] = []; | ||
| readonly emptyArrayAsTypeAssertion = [] as number[]; | ||
| readonly emptyArrayAsConstTypeAssertion = <const>[]; | ||
| readonly nestedEmptyArrayAsConst = (([] as const)); | ||
|
|
||
| readonly arrayWithNumberLiterals = [1, 2, 3]; | ||
| readonly arrayWithMixedLiterals = [1, "x", true, null, undefined]; | ||
| readonly arrayWithElision = [, 1, , 2]; | ||
| readonly arrayWithOnlyElision = [,,]; | ||
| readonly arrayAsConst = [1, "x", true] as const; | ||
| readonly nestedArray = [[1], [] as const, [1, 2] as const]; | ||
| readonly arrayWithObjectLiterals = [{ a: 1 }, { b: "x" as const }]; | ||
| readonly arrayWithUnaryNumberLiterals = [-1, +2]; | ||
| readonly arrayWithNoExprTemplateLiteral = [`x`]; | ||
| readonly arrayWithUndefinedIdentifier = [undefined]; | ||
| readonly arrayWithConstAssertedElements = [({ a: 1 } as const), ([1, 2] as const)]; | ||
|
|
||
| readonly arrayWithSpreadConstTuple = [...tuple]; | ||
| readonly arrayWithSpreadLiteral = [...[1, 2]]; | ||
| readonly arrayWithIdentifierElement = [tuple]; | ||
| readonly arrayWithCallElement = [fn()]; | ||
| readonly arrayWithTemplateExprElement = [`x${n}`]; | ||
| readonly arrayWithInvalidUnaryElement = [+"x"]; | ||
| readonly arraySatisfies = [] satisfies number[]; | ||
| readonly arrayNonNull = []!; | ||
| readonly invalidDirectUnary = +"x"; | ||
| readonly invalidTemplateLiteral = `x${n}`; | ||
|
|
||
| readonly annotatedSpread: readonly number[] = [...tuple]; | ||
| readonly annotatedIdentifier: readonly [1, 2] = tuple; | ||
| readonly annotatedCall: unknown[] = [fn()]; | ||
| readonly annotatedTemplateExpr: string[] = [`x${n}`]; | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
218 changes: 218 additions & 0 deletions
218
crates/oxc_isolated_declarations/tests/snapshots/readonly-class-property-variations.snap
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,218 @@ | ||
| --- | ||
| source: crates/oxc_isolated_declarations/tests/mod.rs | ||
| input_file: crates/oxc_isolated_declarations/tests/fixtures/readonly-class-property-variations.ts | ||
| --- | ||
| ``` | ||
| ==================== .D.TS ==================== | ||
|
|
||
| export declare class ReadonlyClassPropertyVariations { | ||
| readonly emptyArray: unknown; | ||
| readonly emptyArrayAsConst: readonly []; | ||
| readonly emptyArrayWithTypeAnnotation: number[]; | ||
| readonly emptyArrayAsTypeAssertion: number[]; | ||
| readonly emptyArrayAsConstTypeAssertion: readonly []; | ||
| readonly nestedEmptyArrayAsConst: readonly []; | ||
| readonly arrayWithNumberLiterals: unknown; | ||
| readonly arrayWithMixedLiterals: unknown; | ||
| readonly arrayWithElision: unknown; | ||
| readonly arrayWithOnlyElision: unknown; | ||
| readonly arrayAsConst: readonly [1, "x", true]; | ||
| readonly nestedArray: unknown; | ||
| readonly arrayWithObjectLiterals: unknown; | ||
| readonly arrayWithUnaryNumberLiterals: unknown; | ||
| readonly arrayWithNoExprTemplateLiteral: unknown; | ||
| readonly arrayWithUndefinedIdentifier: unknown; | ||
| readonly arrayWithConstAssertedElements: unknown; | ||
| readonly arrayWithSpreadConstTuple: unknown; | ||
| readonly arrayWithSpreadLiteral: unknown; | ||
| readonly arrayWithIdentifierElement: unknown; | ||
| readonly arrayWithCallElement: unknown; | ||
| readonly arrayWithTemplateExprElement: unknown; | ||
| readonly arrayWithInvalidUnaryElement: unknown; | ||
| readonly arraySatisfies; | ||
| readonly arrayNonNull; | ||
| readonly invalidDirectUnary; | ||
| readonly invalidTemplateLiteral; | ||
| readonly annotatedSpread: readonly number[]; | ||
| readonly annotatedIdentifier: readonly [1, 2]; | ||
| readonly annotatedCall: unknown[]; | ||
| readonly annotatedTemplateExpr: string[]; | ||
| } | ||
|
|
||
|
|
||
| ==================== Errors ==================== | ||
|
|
||
| x TS9017: Only const arrays can be inferred with --isolatedDeclarations. | ||
| ,-[7:25] | ||
| 6 | export class ReadonlyClassPropertyVariations { | ||
| 7 | readonly emptyArray = []; | ||
| : ^^ | ||
| 8 | readonly emptyArrayAsConst = [] as const; | ||
| `---- | ||
|
|
||
| x TS9017: Only const arrays can be inferred with --isolatedDeclarations. | ||
| ,-[14:38] | ||
| 13 | | ||
| 14 | readonly arrayWithNumberLiterals = [1, 2, 3]; | ||
| : ^^^^^^^^^ | ||
| 15 | readonly arrayWithMixedLiterals = [1, "x", true, null, undefined]; | ||
| `---- | ||
|
|
||
| x TS9017: Only const arrays can be inferred with --isolatedDeclarations. | ||
| ,-[15:37] | ||
| 14 | readonly arrayWithNumberLiterals = [1, 2, 3]; | ||
| 15 | readonly arrayWithMixedLiterals = [1, "x", true, null, undefined]; | ||
| : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
| 16 | readonly arrayWithElision = [, 1, , 2]; | ||
| `---- | ||
|
|
||
| x TS9017: Only const arrays can be inferred with --isolatedDeclarations. | ||
| ,-[16:31] | ||
| 15 | readonly arrayWithMixedLiterals = [1, "x", true, null, undefined]; | ||
| 16 | readonly arrayWithElision = [, 1, , 2]; | ||
| : ^^^^^^^^^^ | ||
| 17 | readonly arrayWithOnlyElision = [,,]; | ||
| `---- | ||
|
|
||
| x TS9017: Only const arrays can be inferred with --isolatedDeclarations. | ||
| ,-[17:35] | ||
| 16 | readonly arrayWithElision = [, 1, , 2]; | ||
| 17 | readonly arrayWithOnlyElision = [,,]; | ||
| : ^^^^ | ||
| 18 | readonly arrayAsConst = [1, "x", true] as const; | ||
| `---- | ||
|
|
||
| x TS9017: Only const arrays can be inferred with --isolatedDeclarations. | ||
| ,-[19:26] | ||
| 18 | readonly arrayAsConst = [1, "x", true] as const; | ||
| 19 | readonly nestedArray = [[1], [] as const, [1, 2] as const]; | ||
| : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
| 20 | readonly arrayWithObjectLiterals = [{ a: 1 }, { b: "x" as const }]; | ||
| `---- | ||
|
|
||
| x TS9017: Only const arrays can be inferred with --isolatedDeclarations. | ||
| ,-[20:38] | ||
| 19 | readonly nestedArray = [[1], [] as const, [1, 2] as const]; | ||
| 20 | readonly arrayWithObjectLiterals = [{ a: 1 }, { b: "x" as const }]; | ||
| : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
| 21 | readonly arrayWithUnaryNumberLiterals = [-1, +2]; | ||
| `---- | ||
|
|
||
| x TS9017: Only const arrays can be inferred with --isolatedDeclarations. | ||
| ,-[21:43] | ||
| 20 | readonly arrayWithObjectLiterals = [{ a: 1 }, { b: "x" as const }]; | ||
| 21 | readonly arrayWithUnaryNumberLiterals = [-1, +2]; | ||
| : ^^^^^^^^ | ||
| 22 | readonly arrayWithNoExprTemplateLiteral = [`x`]; | ||
| `---- | ||
|
|
||
| x TS9017: Only const arrays can be inferred with --isolatedDeclarations. | ||
| ,-[22:45] | ||
| 21 | readonly arrayWithUnaryNumberLiterals = [-1, +2]; | ||
| 22 | readonly arrayWithNoExprTemplateLiteral = [`x`]; | ||
| : ^^^^^ | ||
| 23 | readonly arrayWithUndefinedIdentifier = [undefined]; | ||
| `---- | ||
|
|
||
| x TS9017: Only const arrays can be inferred with --isolatedDeclarations. | ||
| ,-[23:43] | ||
| 22 | readonly arrayWithNoExprTemplateLiteral = [`x`]; | ||
| 23 | readonly arrayWithUndefinedIdentifier = [undefined]; | ||
| : ^^^^^^^^^^^ | ||
| 24 | readonly arrayWithConstAssertedElements = [({ a: 1 } as const), ([1, 2] as const)]; | ||
| `---- | ||
|
|
||
| x TS9017: Only const arrays can be inferred with --isolatedDeclarations. | ||
| ,-[24:45] | ||
| 23 | readonly arrayWithUndefinedIdentifier = [undefined]; | ||
| 24 | readonly arrayWithConstAssertedElements = [({ a: 1 } as const), ([1, 2] as const)]; | ||
| : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
| 25 | | ||
| `---- | ||
|
|
||
| x TS9017: Only const arrays can be inferred with --isolatedDeclarations. | ||
| ,-[26:40] | ||
| 25 | | ||
| 26 | readonly arrayWithSpreadConstTuple = [...tuple]; | ||
| : ^^^^^^^^^^ | ||
| 27 | readonly arrayWithSpreadLiteral = [...[1, 2]]; | ||
| `---- | ||
|
|
||
| x TS9017: Only const arrays can be inferred with --isolatedDeclarations. | ||
| ,-[27:37] | ||
| 26 | readonly arrayWithSpreadConstTuple = [...tuple]; | ||
| 27 | readonly arrayWithSpreadLiteral = [...[1, 2]]; | ||
| : ^^^^^^^^^^^ | ||
| 28 | readonly arrayWithIdentifierElement = [tuple]; | ||
| `---- | ||
|
|
||
| x TS9017: Only const arrays can be inferred with --isolatedDeclarations. | ||
| ,-[28:41] | ||
| 27 | readonly arrayWithSpreadLiteral = [...[1, 2]]; | ||
| 28 | readonly arrayWithIdentifierElement = [tuple]; | ||
| : ^^^^^^^ | ||
| 29 | readonly arrayWithCallElement = [fn()]; | ||
| `---- | ||
|
|
||
| x TS9017: Only const arrays can be inferred with --isolatedDeclarations. | ||
| ,-[29:35] | ||
| 28 | readonly arrayWithIdentifierElement = [tuple]; | ||
| 29 | readonly arrayWithCallElement = [fn()]; | ||
| : ^^^^^^ | ||
| 30 | readonly arrayWithTemplateExprElement = [`x${n}`]; | ||
| `---- | ||
|
|
||
| x TS9017: Only const arrays can be inferred with --isolatedDeclarations. | ||
| ,-[30:43] | ||
| 29 | readonly arrayWithCallElement = [fn()]; | ||
| 30 | readonly arrayWithTemplateExprElement = [`x${n}`]; | ||
| : ^^^^^^^^^ | ||
| 31 | readonly arrayWithInvalidUnaryElement = [+"x"]; | ||
| `---- | ||
|
|
||
| x TS9017: Only const arrays can be inferred with --isolatedDeclarations. | ||
| ,-[31:43] | ||
| 30 | readonly arrayWithTemplateExprElement = [`x${n}`]; | ||
| 31 | readonly arrayWithInvalidUnaryElement = [+"x"]; | ||
| : ^^^^^^ | ||
| 32 | readonly arraySatisfies = [] satisfies number[]; | ||
| `---- | ||
|
|
||
| x TS9012: Property must have an explicit type annotation with | ||
| | --isolatedDeclarations. | ||
| ,-[32:12] | ||
| 31 | readonly arrayWithInvalidUnaryElement = [+"x"]; | ||
| 32 | readonly arraySatisfies = [] satisfies number[]; | ||
| : ^^^^^^^^^^^^^^ | ||
| 33 | readonly arrayNonNull = []!; | ||
| `---- | ||
|
|
||
| x TS9012: Property must have an explicit type annotation with | ||
| | --isolatedDeclarations. | ||
| ,-[33:12] | ||
| 32 | readonly arraySatisfies = [] satisfies number[]; | ||
| 33 | readonly arrayNonNull = []!; | ||
| : ^^^^^^^^^^^^ | ||
| 34 | readonly invalidDirectUnary = +"x"; | ||
| `---- | ||
|
|
||
| x TS9012: Property must have an explicit type annotation with | ||
| | --isolatedDeclarations. | ||
| ,-[34:12] | ||
| 33 | readonly arrayNonNull = []!; | ||
| 34 | readonly invalidDirectUnary = +"x"; | ||
| : ^^^^^^^^^^^^^^^^^^ | ||
| 35 | readonly invalidTemplateLiteral = `x${n}`; | ||
| `---- | ||
|
|
||
| x TS9012: Property must have an explicit type annotation with | ||
| | --isolatedDeclarations. | ||
| ,-[35:12] | ||
| 34 | readonly invalidDirectUnary = +"x"; | ||
| 35 | readonly invalidTemplateLiteral = `x${n}`; | ||
| : ^^^^^^^^^^^^^^^^^^^^^^ | ||
| 36 | | ||
| `---- | ||
|
|
||
|
|
||
| ``` |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.