## [0.9.4] - 2026-03-11 - Color Namespace, Transpiler Overhaul, request.security & Drawing Improvements#159
Merged
alaa-eddine merged 18 commits intomainfrom Mar 11, 2026
Merged
## [0.9.4] - 2026-03-11 - Color Namespace, Transpiler Overhaul, request.security & Drawing Improvements#159alaa-eddine merged 18 commits intomainfrom
alaa-eddine merged 18 commits intomainfrom
Conversation
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 : tupples destructuring
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
Fix : user methods expressions
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
Misc fixes and optimizations
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
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
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.
Added
colorNamespace Refactor: Extracted the full color implementation fromCore.tsinto a dedicatedsrc/namespaces/color/PineColor.tsmodule. Adds completeCOLOR_CONSTANTS(all named palette colors), improved hex/rgb/rgba/#RRGGBBAAparsing,color.from_gradient()with NaN guard, and a full test suite.alert()Stub: Added the missingalert()function (previously onlyalertconditionexisted). Emits to the context event bus so downstream code can subscribe without crashing.max_bars_back()No-Op: Addedmax_bars_back(source, length)as a compatibility stub. Returns its source argument unchanged (PineTS maintains full history, so there is no lookback cap to configure).linefillInstance Methods:LinefillObjectnow exposesget_line1(),get_line2(), andset_color()directly on the instance, enabling UDT field-chain patterns likemyStruct.fill.set_color(c)..new()Named Arguments:MyType.new(field1=val1, field2=val2)now works correctly. The UDT constructor detects a named-argument object and maps keys to fields instead of positional assignment.linefill.newThunking: Addedlinefill.newtoFACTORY_METHODSso it receives the arrow-function thunk treatment invardeclarations, preventing orphaned linefill objects from being created on every bar.math.__neq()— Inequality Operator: Addedmath.__neq(a, b)to handle Pine Script's!=/<>operator with proper NaN semantics (mirrorsmath.__eq).Fixed
Transpiler
$.get()Wrapping: The for-loop init and update expressions lackedaddArrayAccess,MemberExpression, andCallExpressionhandlers. Series variables appearing in loop bounds (e.g.,for i = 0 to bar_index - 1) were left as raw Series objects, causing the update ternary to evaluate toNaNand producing infinite loops or bodies that never executed.while bar_index > cntand similar conditions with Series variables were not wrapped in$.get(), so the comparison always evaluated against a raw Series object (→NaN). Fixed by adding missingaddArrayAccessand namespace-object skip logic totransformWhileStatement.isVariableInFunctionScope()toScopeManager.createScopedVariableReference()now correctly resolvesvardeclarations inside nestedif/forblocks within functions to the local context ($$) instead of the global context ($).naUDT Drawing Fields:hasGetCallInChain()now traversesMemberExpressionand intermediateCallExpressionnodes to detect$.get()in deeper chains. Inserts?.on the final method call somyStruct.line?.set_x2(x)does not crash when the field isna/undefined.isChainedPropertyMethodguard — when the callee object is itself aMemberExpression(e.g.,myObj.x.set()), the call is not mistakenly redirected through$.call()even ifsethappens to be a user-defined function name. Added_skipTransformation = trueon function-reference identifiers inside$.call()to prevent them from resolving to same-named variables.hasGetCallInChain()Chain Expression Traversal: Extended to walk throughChainExpressionwrapper nodes (?.optional chains) so already-wrapped intermediate nodes are also checked when determining whether to insert optional chaining.ReturnStatementWalk-Through:MainTransformer'sReturnStatementhandler now recurses into complex return arguments when not in function scope, preventing untransformed expressions in nested return statements.parseArgsForPineParamsNaN Handling: Fixed dynamic Pine Script signatures passingNaNvalues through the argument normalizer, which caused downstreamisNaNchecks to misidentify valid numeric0values.request.securitycalls (which are async internally) now correctly propagateasync/awaitthrough the function declaration, preventing unresolved Promise objects from reaching callers.[a, b]returns instead of the required double-bracket[[a, b]]tuple form when=>arrow functions ended with anif/elsethat returned a tuple.color) were being looked up as namespace objects instead of local variables. The transpiler now renames such parameters to avoid the collision.[output, ...]) were incorrectly resolved to the global scope ($.let.output) instead of the local raw identifier (output). AddedisLocalSeriesVarcheck inExpressionTransformer.[[a, b, c]]double-bracket form, causing$.init()to treat the tuple as a time-series and extract only the last element.array<float>,matrix<int>, and other generic typed declarations in variable declarations and function signatures. Strong-typing tests cover all primitive and object element types.Runtime
plotcandleandbarcolor: Fixed incorrect argument mapping and color resolution in both functions.barcolornow correctly applies per-bar color overrides to the candlestick series, andplotcandleproduces properly structured OHLC plot data.request.securityExpression Handling: Complex expressions passed as theexpressionargument (not just simple identifiers or plot references) now evaluate correctly in the secondary context. Also fixed user-defined method expressions being passed across context boundaries.request.security_lower_tfPine Script Behavior: Rewrote lower-timeframe (LTF) aggregation to match TradingView's behavior — values are collected as intra-bar arrays, and the correct array element (first vs. last vs. all) is returned depending onlookahead/gapssettings.timeframe.in_seconds()and related utilities now correctly handle all non-canonical formats ('1h'→'60','1d'→'D','1w'→'W') and returnNaN/0when givenundefinedor an unrecognised string.str.split()Returns Pine Array:str.split()was returning a plain JavaScript array. It now returns aPineArrayObjectso array namespace methods (.get(),.size(), etc.) work on the result.label.set_textcolor()andlabel.set_bgcolor()not applying when called after construction, and resolved parsing inconsistencies inparseArgsForPineParamsthat treated valid color0asna.color.from_gradientNaN Guard: Addednull/NaN/undefinedguards for all five arguments; previously a missing value produced#NANNANNANhex strings.PineColornow handles all Pine Script color representations uniformly: 6-digit hex, 8-digit hex (#RRGGBBAA),rgb(),rgba(), named constants, andcolor.new()output.polyline.new()crash whenpointscontainednaentries, incorrectxlochandling for bar-index vs. time coordinates, and missing default line/fill colors.new_*Capacity Handling:array.new<T>(size, initial)variants now clamp the requested capacity toMAX_ARRAY_SIZEand correctly initialise all elements to the provided default (was previously initialising toundefinedin some typed constructors).table.cell()now guards againstnull/undefinedrow or column indices, preventing a crash when table access patterns involve conditional creation.chart.fg_color: Fixedchart.fg_colorreturning the wrong value (bg_colorwas returned for both properties due to a copy-paste error).polyline.new()andtable.new()no longer require explicit color arguments; sensible defaults are applied when colors are omitted orna.settings.tswere forwarded through the native namespace dispatcher instead of the user function call path.build:dev:browsertarget so browser DevTools correctly resolve transpiled runtime errors to TypeScript source lines.