fix(transpiler): + / - on display constants are set operations - #309
Merged
Merged
Conversation
Pine's `display.*` values form a set type: `+` unions two displays and `-` removes one's surfaces from the other (`display.all - display.price_scale`). The runtime keeps them as member-name strings, so native `-` yielded NaN and `+` a raw concatenation in source order (`display.all + display.none` → 'allnone'). A post-process pass, `transformDisplayArithmetic`, routes `+` / `-` with a `display.*` operand — literal members, chained expressions, or a variable combined with a member — to `display.__union` / `display.__minus`, which compute the set and report it as the canonical concatenation of member names (pane, data_window, status_line, price_scale; 'all' / 'none' for the full / empty set), the shape hosts already parse. `display.all - display.none` → 'all', `display.none - display.all` → 'none', `display.pane + display.pane` → 'pane'. Plain member values and the enum are unchanged. Co-authored-by: Cursor <cursoragent@cursor.com>
Bugbot couldn't run - usage limit reachedBugbot is counted against Cursor usage for this user or team, and this run hit a usage or spend limit. A user or team admin can review and increase usage limits in the Cursor dashboard. (requestId: serverGenReqId_080129f1-075c-476e-a44f-aa8fc8eb9660) |
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.
Problem
Pine's
display.*constants are a set type —+is the union of two displays and-removes one display's surfaces from another (display.all - display.price_scaleis the reference manual's own example). PineTS keeps them as member-name strings, so:display.all - display.price_scaleevaluated toNaN(hosts then fell back to their default — typically showing the plot everywhere);display.all + display.noneproduced the raw concatenation'allnone', in source order, with duplicates (display.pane + display.pane→'panepane').Fix
transformDisplayArithmetic— a post-process pass besidetransformEqualityChecks— rewrites a+/-BinaryExpressionwith adisplay.<member>operand (a literal member, an expression this pass already rewrote, or a variable combined with a member) todisplay.__union(a, b)/display.__minus(a, b), built throughASTFactory. Numeric arithmetic elsewhere is untouched (pinned by test).displayUnion/displayMinus(Types.ts) compute the surface set and report it as the canonical concatenation of member names in the order pane, data_window, status_line, price_scale —'all'/'none'for the full / empty set. This is the shape+on the string enum already produced, so thedisplay.*enum stays string-valued and hosts parsing member names keep working.display.all - display.nonealldisplay.all + display.none/display.none + display.allalldisplay.none - display.allnonedisplay.all - display.price_scalepanedata_windowstatus_linedisplay.pane + display.data_window(either order)panedata_windowdisplay.all - display.pane - display.price_scaledata_windowstatus_linedisplay.pane + display.panepaneTests
tests/namespaces/plot/display-arithmetic.test.ts— written failing first (NaN /'allnone'/'data_windowpane'), now green: the table above, chained and variable forms, hline / plotshape / input arguments, defaults untouched, and a transpiled-code check that only display expressions are routed. Full suite: 175 files / 1873 tests passing (3 pre-existing skips).Docs:
docs/api-coverage/types.md(display combination semantics),CHANGELOG.mdunder Unreleased.Downstream
The Vela Pine engine (LuxAlgo/Vela-pinets#36) already parses this output; once this ships it can bump its
pinetsrange so-becomes a guarantee.Note
Low Risk
Scoped transpiler rewrite and display helpers; fixes incorrect plot visibility strings without touching auth, data, or strategy logic.
Overview
Fixes Pine parity for combining
display.*values:+and-now behave as set union and set difference instead of JavaScript string concatenation orNaN.A new transpiler post-pass,
transformDisplayArithmetic, rewrites+/-when either side is adisplay.<member>(including chained expressions and variables) intodisplay.__union/display.__minus. Runtime helpers inTypes.tsparse the canonical string form, compute surfaces in order pane → data_window → status_line → price_scale, and emit'all'/'none'or the joined member names hosts already understand. Plain literals and unrelated numeric math are unchanged.Tests cover
plot,hline,plotshape, andinputdisplay args; docs note set semantics intypes.md.Reviewed by Cursor Bugbot for commit 8c5cefa. Bugbot is set up for automated code reviews on this repo. Configure here.