Skip to content

Misc fixes and optimizations#158

Merged
alaa-eddine merged 15 commits intodevfrom
misc-fixes-and-optimizations
Mar 11, 2026
Merged

Misc fixes and optimizations#158
alaa-eddine merged 15 commits intodevfrom
misc-fixes-and-optimizations

Conversation

@alaa-eddine
Copy link
Copy Markdown
Collaborator

No description provided.

add : max_bars_back (no-op in this implementation)
Fix : user functions treated as native functions
….ts)

for-loop update expression — was missing addArrayAccess(), MemberExpression, and CallExpression handlers. Caused infinite loops when Series variables (e.g. bar_index) appeared in for i = 0 to bar_index - X bounds — the update ternary used raw Series objects → NaN → always decremented.
for-loop init expression — same missing addArrayAccess(). Caused for i = bar_index to 0 to assign a raw Series to i instead of the integer value → loop body never executed.
while-loop test condition — missing addArrayAccess() and namespace object check. Caused while bar_index > cnt to compare raw Series → NaN → while body never executed.
2. Transpiler: Function-scoped variable resolution (ScopeManager.ts + ExpressionTransformer.ts)
Added isVariableInFunctionScope() to walk the scope stack and detect variables in nested scopes (if/else/for) inside functions.
createScopedVariableReference() now uses this to correctly resolve var inside if inside functions to local context ($$) instead of global ($).
3. Transpiler: Optional chaining for na UDT drawing fields (ExpressionTransformer.ts)
Added hasGetCallInChain() helper that traverses MemberExpression AND intermediate CallExpression nodes.
Inserts ?. on method calls through $.get() field chains, preventing crashes when UDT drawing fields (box/line/label) are na/undefined.
Positioned AFTER argument transformation to avoid breaking $.get() wrapping.
4. Transpiler: User function vs method call disambiguation (ExpressionTransformer.ts)
Added isChainedPropertyMethod guard — when callee object is a MemberExpression (e.g. aZZ.x.set()), skip user function transformation even if set is a user-defined function name.
Added _skipTransformation = true on function reference identifiers in $.call() to prevent them being resolved to same-named variables.
5. Runtime: linefill.new thunking + instance methods (settings.ts, LinefillHelper.ts, LinefillObject.ts)
Added linefill.new to FACTORY_METHODS so it gets thunk-wrapped in var declarations.
LinefillHelper.new() now resolves line argument thunks before creating the object.
Added get_line1(), get_line2(), set_color() instance methods on LinefillObject for UDT field access patterns.
6. Runtime: alert() + UDT named args (Core.ts, Context.class.ts, settings.ts)
Added alert() stub (was missing, only alertcondition existed).
UDT .new() now detects named argument objects so MyType.new(field1=val1, field2=val2) works correctly.
7. Transpiler: ReturnStatement walk-through (MainTransformer.ts)
ReturnStatement handler now walks into complex return arguments when not in function scope, preventing untransformed expressions in nested return statements.
8. Tests (udt-drawing-objects.test.ts)
Added 6 new tests: uninitialized drawing field access (box/line/label), linefill instance methods, linefill UDT field chain operations.
…pt dynamic signatures

Fix : Label colos and backgrounds
Fix : in_seconds method with undefined timeframe

other fixes
ArrayExpression function parameter scoping — Added isLocalSeriesVar check in ExpressionTransformer.ts so function parameters inside array args use raw identifiers (output) instead of wrong global scope ($.let.output).
color.from_gradient NaN guard — Added null/NaN/undefined checks for all 5 arguments in PineColor.ts to return undefined (na) instead of producing #NANNANNAN hex strings.
Switch tuple destructuring — Wrapped IIFE array returns in 2D ([[a,b,c]]) in AnalysisPass.ts so $.init() preserves tuples instead of treating them as time-series and taking only the last element.
Duplicate red key — Removed duplicate red entry in PineColor.ts COLOR_CONSTANTS.
fixed array and matrix typed declarations
Update : normalized timeframes
Fix : plot color change detection
Fix: str.plit should return a pine array
array safesize
polyline fixes
fix getter when used with  NaN
…,N).method() and isChained for $.get(X,N).field.method()) with detailed comments explaining why it must not be broadened

Added ChainExpression traversal to hasGetCallInChain() so it can see through already-wrapped nodes when checking deeper in the chain

Fix : transpiler function scope property
@alaa-eddine alaa-eddine merged commit e172280 into dev Mar 11, 2026
1 check passed
@github-actions github-actions bot locked and limited conversation to collaborators Mar 11, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant