Skip to content
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

Throws a TypeError with standard EcmaScript class fields #169

Open
jakub791 opened this issue May 27, 2024 · 0 comments
Open

Throws a TypeError with standard EcmaScript class fields #169

jakub791 opened this issue May 27, 2024 · 0 comments

Comments

@jakub791
Copy link

What is the issue?

Break eternity uses static class fields to initialize the Decimal constants like:

public static readonly dZero = FC_NN(0, 0, 0);

FC_NN` is defined as:

let FC_NN = function FC_NN(sign: number, layer: number, mag: number) {
    return Decimal.fromComponents_noNormalize(sign, layer, mag);
};

Decimal.fromComponents_noNormalize invokes the Decimal class constructor (new Decimal()).
But apparently static class fields initializers run before the class is ready to be used as a constructor which causes it to throw a TypeError.

How to reproduce?

Clone this repository, in tsconfig.json change target to "esnext", transpile the library source code using tsc and run the output file in literally any JS runtime that supports ES2022 and you shouldsee an error like Uncaught ReferenceError: can't access lexical declaration 'Decimal' before initialization

note: I feel like this isn't a very great explantion of all this, if you need further info just ask me.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant