Repository navigation
bun-types: accept a TextDecoder label in any ASCII case
#48360
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
Open
robobun
wants to merge
3
commits into
main
Choose a base branch
from
robobun/045e90c8/bun-types-text-decoder-label-case
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+185
−1
Open
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
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
61 changes: 61 additions & 0 deletions
61
test/cli/check/text-decoder-takes-a-label-in-any-case.test.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,61 @@ | ||
| // `bun compile` type checks what it builds, so a label that runs on Bun and that the declarations of Bun refuse stops the build. | ||
| // The project is the one that `bun init` writes: no library for browsers, and the types of Bun. | ||
| import { expect, test } from "bun:test"; | ||
| import { bunExe, tempDirWithBunTypes } from "harness"; | ||
| import { run } from "../../aot/harness/run"; | ||
|
|
||
| const tsconfig = JSON.stringify({ | ||
| compilerOptions: { | ||
| lib: ["ESNext"], | ||
| target: "ESNext", | ||
| module: "Preserve", | ||
| moduleDetection: "force", | ||
| moduleResolution: "bundler", | ||
| types: ["bun"], | ||
| strict: true, | ||
| skipLibCheck: true, | ||
| noEmit: true, | ||
| }, | ||
| }); | ||
|
|
||
| const program = `console.log(new TextDecoder("UTF-8").encoding, new TextDecoder(" Shift_JIS ", { fatal: true }).encoding); | ||
| console.log(new TextDecoderStream("LATIN1").encoding); | ||
| `; | ||
|
|
||
| const printed = `utf-8 shift_jis | ||
| windows-1252 | ||
| `; | ||
|
|
||
| // The first two labels throw on Bun, and so does the label in the tuple and in the class. The third is known only at run time, | ||
| // and a constructor type whose label is a string could be given any of them. | ||
| const refused = `declare const charset: string; | ||
| // @ts-expect-error | ||
| new TextDecoder("utf-99"); | ||
| // @ts-expect-error | ||
| new TextDecoder("\\u212Aoi8-r"); | ||
| // @ts-expect-error | ||
| new TextDecoder(charset); | ||
| // @ts-expect-error | ||
| export const args: ConstructorParameters<typeof TextDecoder> = ["utf-99"]; | ||
| class Sub extends TextDecoder {} | ||
| // @ts-expect-error | ||
| new Sub("utf-99"); | ||
| // @ts-expect-error | ||
| export const Alias: new (label: string) => TextDecoder = TextDecoder; | ||
| `; | ||
|
|
||
| // One check reads every declaration of Bun and of Node.js, which takes a debug build several seconds. | ||
| test("TextDecoder takes a label in any ASCII case", async () => { | ||
| using dir = tempDirWithBunTypes("check-text-decoder-labels", { | ||
| "tsconfig.json": tsconfig, | ||
| "index.ts": program, | ||
| "refused.ts": refused, | ||
| }); | ||
| expect(await run([bunExe(), "index.ts"], String(dir))).toEqual({ stdout: printed, stderr: "", exitCode: 0 }); | ||
| const checked = await run([bunExe(), "check", "--no-pretty"], String(dir)); | ||
| // The summary on stderr has a time in it. Where the check fails, the message shows all three. | ||
| expect(checked.exitCode === 0 ? { stdout: checked.stdout, exitCode: 0 } : checked).toEqual({ | ||
| stdout: "", | ||
| exitCode: 0, | ||
| }); | ||
| }, 60_000); | ||
|
coderabbitai[bot] marked this conversation as resolved.
Resolved
robobun marked this conversation as resolved.
Resolved
|
||
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
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.