microsoft / microsoft/TypeScript
Temp variable re-usage breaks JS when building into single file
Open
Nobody has claimed this yet.
Needs More Info
- Dominant language
- Go
- Stars
- 111k
- Forks
- 14.4k
- Avg merge
- 1d 19h
- Merged PRs (30d)
- 117
Description
🔎 Search Terms
static
🕗 Version & Regression Information
- This changed between versions
5.2.0-betaand5.2.1-rc. I found that this issue appeared in5.2.0-dev.20230805build, probably caused by merging https://github.com/microsoft/TypeScript/pull/55262
⏯ Playground Link
💻 Code
// catch.ts
class Catch {
public static reportErr = (): boolean => {
return Catch.onErrorInternalHandler();
};
public static onErrorInternalHandler = (): boolean => {
return true;
};
public static doesReject = async () => {
return false
};
}
// another-catch.ts
class AnotherCatch {
public static reportSomething = (): boolean => {
return AnotherCatch.onSomethingHandler();
};
public static onSomethingHandler = (): boolean => {
return true;
};
public static doesReject = async () => {
return false
};
}
// compile these 2 files into a single one with "tsc catch.ts another-catch.ts --outFile test.js --module none --target es2017"
🙁 Actual behavior
In compiled JS it converts to:
var _a;
class Catch {
}
_a = Catch;
Catch.reportErr = () => {
return _a.onErrorInternalHandler();
};
Catch.onErrorInternalHandler = () => {
return true;
};
Catch.doesReject = async () => {
return false;
};
var _a;
class AnotherCatch {
}
_a = AnotherCatch;
AnotherCatch.reportSomething = () => {
return _a.onSomethingHandler();
};
AnotherCatch.onSomethingHandler = () => {
return true;
};
AnotherCatch.doesReject = async () => {
return false;
};
Which leads to _a.onErrorInternalHandler is not a function error when trying to perform Catch.reportErr() later in the code.
🙂 Expected behavior
In 5.2.0-beta it compiled to
var _a;
class Catch {
}
_a = Catch;
Catch.reportErr = () => {
return Catch.onErrorInternalHandler();
};
And it worked well.
Additional information about the issue
No response
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Reproduce the issue with catch.ts and another-catch.ts using tsc catch.ts another-catch.ts --outFile test.js --module none --target es2017, then inspect the generated test.js. Compare the emitted temporary-variable handling with the expected output and verify that both static methods work when the files are bundled into one output file.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript, typescript
- Domain
- compilers
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 38/100