tc39 / proposal-function-and-object-literal-element-decorators

ECMAScript Decorators for Function Expressions and Declarations
https://tc39.es/proposal-function-and-object-literal-element-decorators/
MIT License
48 stars 0 forks source link

Interference with mutual recursion #3

Open ByteEater-pl opened 8 months ago

ByteEater-pl commented 8 months ago

What if decorated functions f and g need to call each other? A problem arises if f is defined, g still isn't, yet f calls (directly or not) g. And they cannot be reordered because g calls f too and the problem would be the same with roles reversed. Without decorators there's hoisting, so no problem.

It seems that a sufficient solution, and possibly a piece of advice to include in educational materials, is for authors to define sets of (2, as above, or even more) mutually recursive decorated functions without any code that runs between their definitions which could call one already defined, inside of which a call to some still undefined "function" would be executed.

WDYT? It seems not to have been discussed at the February meeting, so I'm bringing it to your attention.

BalaM314 commented 4 months ago

Agreed, I think the best solution to this is to put all decorated function declarations before any code that uses them.