openpinescript 0.0.0-stage → 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (103) hide show
  1. package/LICENSE +674 -0
  2. package/README.md +346 -2
  3. package/dist/cli.mjs +108686 -0
  4. package/dist/index.cjs +108670 -0
  5. package/dist/index.mjs +108624 -0
  6. package/dist/types/index.d.ts +31 -0
  7. package/dist/types/parser/v1/generated/PineV1Lexer.d.ts +66 -0
  8. package/dist/types/parser/v1/generated/PineV1Parser.d.ts +555 -0
  9. package/dist/types/parser/v1/generated/PineV1ParserVisitor.d.ts +318 -0
  10. package/dist/types/parser/v1/index.d.ts +39 -0
  11. package/dist/types/parser/v2/generated/PineV2Lexer.d.ts +67 -0
  12. package/dist/types/parser/v2/generated/PineV2Parser.d.ts +568 -0
  13. package/dist/types/parser/v2/generated/PineV2ParserVisitor.d.ts +325 -0
  14. package/dist/types/parser/v2/index.d.ts +2 -0
  15. package/dist/types/parser/v3/generated/PineV3Lexer.d.ts +67 -0
  16. package/dist/types/parser/v3/generated/PineV3Parser.d.ts +568 -0
  17. package/dist/types/parser/v3/generated/PineV3ParserVisitor.d.ts +325 -0
  18. package/dist/types/parser/v3/index.d.ts +2 -0
  19. package/dist/types/parser/v4/generated/PineV4Lexer.d.ts +86 -0
  20. package/dist/types/parser/v4/generated/PineV4Parser.d.ts +673 -0
  21. package/dist/types/parser/v4/generated/PineV4ParserVisitor.d.ts +367 -0
  22. package/dist/types/parser/v4/index.d.ts +2 -0
  23. package/dist/types/parser/v5/generated/PineV5Lexer.d.ts +95 -0
  24. package/dist/types/parser/v5/generated/PineV5Parser.d.ts +964 -0
  25. package/dist/types/parser/v5/generated/PineV5ParserVisitor.d.ts +521 -0
  26. package/dist/types/parser/v5/index.d.ts +2 -0
  27. package/dist/types/parser/v6/generated/PineV6Lexer.d.ts +98 -0
  28. package/dist/types/parser/v6/generated/PineV6Parser.d.ts +984 -0
  29. package/dist/types/parser/v6/generated/PineV6ParserVisitor.d.ts +528 -0
  30. package/dist/types/parser/v6/index.d.ts +2 -0
  31. package/dist/types/runtime/v1/Series.d.ts +61 -0
  32. package/dist/types/runtime/v1/broker/Broker.d.ts +325 -0
  33. package/dist/types/runtime/v1/broker/index.d.ts +158 -0
  34. package/dist/types/runtime/v1/broker/val.d.ts +28 -0
  35. package/dist/types/runtime/v1/constDefault.d.ts +11 -0
  36. package/dist/types/runtime/v1/context.d.ts +1705 -0
  37. package/dist/types/runtime/v1/footprint.d.ts +32 -0
  38. package/dist/types/runtime/v1/index.d.ts +7 -0
  39. package/dist/types/runtime/v1/language-spec.d.ts +12 -0
  40. package/dist/types/runtime/v1/openTrades.d.ts +12 -0
  41. package/dist/types/runtime/v1/palette.d.ts +18 -0
  42. package/dist/types/runtime/v1/session.d.ts +482 -0
  43. package/dist/types/runtime/v1/sessions.d.ts +31 -0
  44. package/dist/types/runtime/v1/stateClone.d.ts +19 -0
  45. package/dist/types/runtime/v1/stdlib/alerts.d.ts +31 -0
  46. package/dist/types/runtime/v1/stdlib/arrays.d.ts +133 -0
  47. package/dist/types/runtime/v1/stdlib/barmerge.d.ts +27 -0
  48. package/dist/types/runtime/v1/stdlib/barstate.d.ts +79 -0
  49. package/dist/types/runtime/v1/stdlib/cast.d.ts +81 -0
  50. package/dist/types/runtime/v1/stdlib/chart.d.ts +283 -0
  51. package/dist/types/runtime/v1/stdlib/color.d.ts +51 -0
  52. package/dist/types/runtime/v1/stdlib/core.d.ts +162 -0
  53. package/dist/types/runtime/v1/stdlib/dataset.d.ts +36 -0
  54. package/dist/types/runtime/v1/stdlib/display.d.ts +50 -0
  55. package/dist/types/runtime/v1/stdlib/drawings.d.ts +407 -0
  56. package/dist/types/runtime/v1/stdlib/errors.d.ts +21 -0
  57. package/dist/types/runtime/v1/stdlib/font.d.ts +20 -0
  58. package/dist/types/runtime/v1/stdlib/footprint.d.ts +76 -0
  59. package/dist/types/runtime/v1/stdlib/format.d.ts +57 -0
  60. package/dist/types/runtime/v1/stdlib/index.d.ts +71 -0
  61. package/dist/types/runtime/v1/stdlib/input.d.ts +14 -0
  62. package/dist/types/runtime/v1/stdlib/inputs.d.ts +60 -0
  63. package/dist/types/runtime/v1/stdlib/late_members.d.ts +97 -0
  64. package/dist/types/runtime/v1/stdlib/logging.d.ts +31 -0
  65. package/dist/types/runtime/v1/stdlib/maps.d.ts +55 -0
  66. package/dist/types/runtime/v1/stdlib/math.d.ts +71 -0
  67. package/dist/types/runtime/v1/stdlib/matrix.d.ts +201 -0
  68. package/dist/types/runtime/v1/stdlib/metadata.d.ts +14 -0
  69. package/dist/types/runtime/v1/stdlib/mtf.d.ts +15 -0
  70. package/dist/types/runtime/v1/stdlib/renames.d.ts +117 -0
  71. package/dist/types/runtime/v1/stdlib/renames5.d.ts +113 -0
  72. package/dist/types/runtime/v1/stdlib/renames6.d.ts +81 -0
  73. package/dist/types/runtime/v1/stdlib/request.d.ts +207 -0
  74. package/dist/types/runtime/v1/stdlib/scale.d.ts +19 -0
  75. package/dist/types/runtime/v1/stdlib/session.d.ts +113 -0
  76. package/dist/types/runtime/v1/stdlib/sort_field.d.ts +12 -0
  77. package/dist/types/runtime/v1/stdlib/sources.d.ts +24 -0
  78. package/dist/types/runtime/v1/stdlib/str.d.ts +117 -0
  79. package/dist/types/runtime/v1/stdlib/strategy.d.ts +314 -0
  80. package/dist/types/runtime/v1/stdlib/syminfo.d.ts +209 -0
  81. package/dist/types/runtime/v1/stdlib/ta.d.ts +409 -0
  82. package/dist/types/runtime/v1/stdlib/time.d.ts +158 -0
  83. package/dist/types/runtime/v1/stdlib/trades.d.ts +108 -0
  84. package/dist/types/runtime/v1/stdlib/ui.d.ts +196 -0
  85. package/dist/types/runtime/v1/stdlib/v6_members.d.ts +68 -0
  86. package/dist/types/runtime/v1/timeframes.d.ts +139 -0
  87. package/dist/types/runtime/v1/zones.d.ts +30 -0
  88. package/dist/types/transpiler/common/index.d.ts +51 -0
  89. package/dist/types/transpiler/common/libraries.d.ts +29 -0
  90. package/dist/types/transpiler/common/parseErrors.d.ts +38 -0
  91. package/dist/types/transpiler/common/passes/ScopeAnalysis.d.ts +158 -0
  92. package/dist/types/transpiler/common/passes/TypeRules.d.ts +26 -0
  93. package/dist/types/transpiler/common/profiles/index.d.ts +96 -0
  94. package/dist/types/transpiler/common/version.d.ts +40 -0
  95. package/dist/types/transpiler/v1/ToJsVisitor.d.ts +720 -0
  96. package/dist/types/transpiler/v2/ToJsVisitor.d.ts +72 -0
  97. package/dist/types/transpiler/v3/ToJsVisitor.d.ts +87 -0
  98. package/dist/types/transpiler/v4/ToJsVisitor.d.ts +263 -0
  99. package/dist/types/transpiler/v5/ToJsVisitor.d.ts +1101 -0
  100. package/dist/types/transpiler/v6/ToJsVisitor.d.ts +237 -0
  101. package/dist/types/transpiler/v6/rules.d.ts +94 -0
  102. package/dist/types/utils/v2/common.d.ts +4 -0
  103. package/package.json +92 -4
@@ -0,0 +1,237 @@
1
+ /**
2
+ * Pine Script v6 → JavaScript emitter.
3
+ *
4
+ * v6 inherits every line of emit logic from v5 (and so from v1 through v4).
5
+ * This file contains only what TradingView's v6 migration guide and release
6
+ * notes document as different.
7
+ *
8
+ * ── Why so much of v6 lands here ───────────────────────────────────────────
9
+ *
10
+ * "Breaking changes" is TradingView's term for USER SCRIPTS moving v5 to v6.
11
+ * Sorted by where each of the 25 actually lands in this engine, 11 are emit
12
+ * decisions — a different JavaScript expression, or a new compile error over a
13
+ * tree that parses fine. 9 are registry or profile DATA. 5 are run-time, and
14
+ * all 5 are a flag or a broker override rather than a second runtime.
15
+ *
16
+ * So this file is where v6 mostly lives, exactly as transpiler/v5 is where v5
17
+ * mostly lives. Nothing in v1–v5 is touched to add any of it: a v5 script
18
+ * reaches V5ToJsVisitor and emits what it always did.
19
+ */
20
+ import type { PineVersion } from "../common/version.js";
21
+ import { V5ToJsVisitor, V5Options } from "../v5/ToJsVisitor.js";
22
+ import type { StdlibEntry } from "../../runtime/v1/stdlib/metadata.js";
23
+ import { Once_exprContext } from "../../parser/v6/generated/PineV6Parser.js";
24
+ export interface V6Options extends V5Options {
25
+ }
26
+ /** Anything carrying a source position (see the v1 base for why it is structural). */
27
+ interface SourceLocated {
28
+ start?: {
29
+ line: number;
30
+ column: number;
31
+ } | null;
32
+ }
33
+ /**
34
+ * A triple-quoted literal's text, as a JavaScript string literal.
35
+ *
36
+ * Quoted, from the release notes (April 2026):
37
+ *
38
+ * "All code between the """ or ''' delimiters in a multiline string
39
+ * definition represents literal text."
40
+ * "Each code line between the delimiters defines a separate text line"
41
+ * "multiline strings automatically include all spaces used for indentation"
42
+ *
43
+ * So newlines are KEPT, and so is every leading space — unlike the inherited
44
+ * `unwrapString`, which collapses a wrapped ordinary string onto one line.
45
+ * Stripping a common indent, the way some languages do, would be the wrong
46
+ * guess: the notes' own example says "any indentation in the definition is
47
+ * still included literally in the string".
48
+ *
49
+ * Escapes keep their ordinary meaning (`\t`, `\\`, `\"`), which is why a
50
+ * backslash and the character after it are copied as a pair. Everything else
51
+ * is re-escaped for JavaScript: a raw newline becomes `\n`, and a bare `"`
52
+ * — legal inside `'''…'''` — becomes `\"`.
53
+ */
54
+ export declare function unwrapMultilineString(text: string): string;
55
+ export declare class V6ToJsVisitor extends V5ToJsVisitor {
56
+ protected readonly version: PineVersion;
57
+ constructor(options?: V6Options);
58
+ /**
59
+ * MG §"Fractional division of constants": "Non-even int division always
60
+ * returns a fraction (5/2 = 2.5) for all qualifiers." v5 truncated two
61
+ * constant ints; v6 does not.
62
+ */
63
+ protected truncatesConstIntDivision(): boolean;
64
+ /** v6's view of the stdlib. See V6_VIEW for what differs from v5's. */
65
+ protected get registry(): Record<string, StdlibEntry>;
66
+ /**
67
+ * A library is read by the grammar of the version IT declares.
68
+ *
69
+ * A v6 script may import a v5 library, and the two grammars disagree: v5
70
+ * lets a library bind a variable called `once`, v6 does not. Parsing every
71
+ * library as v6 would reject published v5 libraries for using a word that
72
+ * was legal when they were written.
73
+ */
74
+ protected parseLibrary(source: string): {
75
+ parsed: ReturnType<typeof import("../../parser/v5/index.js").parse>;
76
+ version: PineVersion;
77
+ };
78
+ protected createLibraryVisitor(version: PineVersion, options: V5Options): V5ToJsVisitor;
79
+ /** The types a library constant may have. Release notes, June 2025. */
80
+ private static readonly CONSTANT_TYPES;
81
+ /** Names this library exports as constants. */
82
+ protected exportedConstants: Set<string>;
83
+ /** alias → the constants that library exports, so `alias.NAME` resolves. */
84
+ protected libraryConstants: Map<string, Set<string>>;
85
+ /** The visitor of the library compiled most recently — see compileLibrary. */
86
+ private lastLibraryVisitor;
87
+ /**
88
+ * `export const <type> <NAME> = <value>` — the only form the release notes
89
+ * allow: the `const` qualifier, and one of five types. Anything else is a
90
+ * variable a library cannot export, and is refused here by name.
91
+ */
92
+ visitExport_stmt(ctx: any): string;
93
+ protected exportedMemberJs(name: string, types: ReadonlyMap<string, unknown>, enums: ReadonlyMap<string, unknown>): string;
94
+ protected compileLibrary(path: string, alias: string, source: string, ctx: SourceLocated): {
95
+ js: string;
96
+ exports: Set<string>;
97
+ types: Map<string, string[]>;
98
+ methods: Set<string>;
99
+ members: string[];
100
+ enums: Map<string, string[]>;
101
+ };
102
+ /** `alias.NAME` — a constant an imported library exports. */
103
+ protected emitFieldChain(text: string): string | null;
104
+ visitOther_literal(ctx: any): string;
105
+ protected visitContent(ctx: any): string;
106
+ /**
107
+ * `once [<condition>]` — run the block the first time the condition holds,
108
+ * and never again.
109
+ *
110
+ * Lowered onto `var`, because that is precisely the state the manual
111
+ * describes. From the Conditional structures page:
112
+ *
113
+ * - on historical bars the block runs once, the first time the condition
114
+ * is true, and never again;
115
+ * - on the realtime bar the structure's state is ROLLED BACK between ticks,
116
+ * so the block can run on several ticks of one bar, and the structure
117
+ * only goes inactive when the block runs on the bar's closing tick.
118
+ *
119
+ * A `var` flag is committed on a confirmed bar and rolled back on an
120
+ * unconfirmed tick — which is that behaviour exactly, with no new runtime
121
+ * mechanism. `varip` would be wrong: it survives rollback, and would stop
122
+ * the block after the first realtime tick.
123
+ *
124
+ * The flag is keyed by the structure's SOURCE LOCATION through
125
+ * `seriesKey`, so two `once` blocks never share it, and one inside a user
126
+ * function gets the same per-call-site storage a `var` there gets. The
127
+ * manual does not say whether a `once` in a function fires once per call
128
+ * site or once overall; following `var` is the reading consistent with the
129
+ * rest of the language, and it is stated here because it is an assumption.
130
+ *
131
+ * Emitted as a plain `if`, never an IIFE: `once` is a statement with no
132
+ * value (the manual makes assigning one a compile error), and a plain block
133
+ * is what lets `break` and `continue` inside it reach an enclosing loop.
134
+ */
135
+ visitOnce_expr(ctx: Once_exprContext): string;
136
+ /** The value of a block's last statement, or null. */
137
+ protected blockTail(block: any): any | null;
138
+ /** The value an arm of a switch ends with, or null. */
139
+ protected caseTail(arm: any): any | null;
140
+ /**
141
+ * MG §"Explicit bool casting": "int and float values are no longer
142
+ * implicitly cast to bool". A numeric value where a condition is required
143
+ * is a compile error; the fix the guide gives is `bool(x)`.
144
+ */
145
+ protected enforceBoolCondition(node: any, where?: SourceLocated): void;
146
+ visitIf_expr(ctx: any): string;
147
+ visitTernary_expr(ctx: any): string;
148
+ visitUnary_expr(ctx: any): string;
149
+ visitWhile_expr(ctx: any): string;
150
+ /**
151
+ * MG §"Lazy evaluation of conditions": "evaluation stops once the result is
152
+ * determined". v5 evaluated every operand (see the long note on
153
+ * `visitOr_expr` in the v1 base for why, and the golden export that proved
154
+ * it); v6 short-circuits, so a `ta.*` call on the right of an `and` really
155
+ * is skipped on bars where the left is false — the guide's own warning, and
156
+ * TradingView's behaviour, which this engine must reproduce surprise and all.
157
+ *
158
+ * The guide also names the payoff: `arr.size() != 0 and arr.first()` no
159
+ * longer reads an empty array.
160
+ */
161
+ visitOr_expr(ctx: any): string;
162
+ visitAnd_expr(ctx: any): string;
163
+ /**
164
+ * MG §"Boolean values cannot be na": "In if/switch expressions returning
165
+ * bool, a missing branch yields false instead of na."
166
+ *
167
+ * Decided from the FIRST branch's value, which is the type the structure
168
+ * has: Pine requires every branch to agree, and disagreeing is a separate
169
+ * compile error on TradingView.
170
+ */
171
+ protected ifFallthrough(ctx: any): string;
172
+ protected switchFallthrough(ctx: any): string;
173
+ /**
174
+ * MG §"Unique parameters cannot be na": "switch needs a default branch, and
175
+ * if needs an else branch, when the result is a unique type" — because the
176
+ * missing branch would be `na`, which a unique type can no longer hold.
177
+ *
178
+ * Only in VALUE position. A statement-`if` produces nothing, so its missing
179
+ * branch produces no `na` either.
180
+ */
181
+ protected enforceUniqueIfHasElse(ctx: any): void;
182
+ visitSwitch_expr(ctx: any): string;
183
+ /** Is this switch a statement whose value is discarded? */
184
+ protected isStatementSwitch(ctx: any): boolean;
185
+ /**
186
+ * MG §"Boolean values cannot be na": "Declaring a bool with na as its
187
+ * default is invalid."
188
+ */
189
+ visitVar_def(ctx: any): string;
190
+ /**
191
+ * MG §"History-referencing operator":
192
+ *
193
+ * - "[] on a literal or constant is a compile error"
194
+ * - "obj.field[10] is invalid. Use (obj[10]).field"
195
+ */
196
+ visitSqbr_expr(ctx: any): string;
197
+ /**
198
+ * MG §"Dynamic for loop boundaries": "The to_num expression ... is
199
+ * re-evaluated before every iteration." v5 read it once.
200
+ *
201
+ * The same loop as the v1 base in every other respect — start value, step
202
+ * magnitude and DIRECTION are still fixed when the loop starts — with the
203
+ * bound moved into a thunk that is called once before the first iteration
204
+ * and again after each one. Calling it in the loop CONDITION instead would
205
+ * evaluate it twice before the first pass, and a bound with a side effect —
206
+ * the guide's own example appends to an array — would see that.
207
+ */
208
+ visitFor_expr(ctx: any): string;
209
+ /**
210
+ * True when the declaration says `dynamic_requests = false`.
211
+ *
212
+ * MG §"Dynamic requests": v6 defaults it to true, so `request.*()` may run
213
+ * in loops and conditional blocks. Turned off EXPLICITLY, "calling
214
+ * request.*() inside loop or conditional scopes, even through a wrapper
215
+ * function, is a compile error". This engine never restricted request scope
216
+ * at v5 either, so the default case needs nothing; only the opt-out does.
217
+ */
218
+ protected dynamicRequestsOff: boolean;
219
+ /**
220
+ * User functions that issue a request, directly or through another user
221
+ * function — the "wrapper function" of the rule.
222
+ */
223
+ protected requestingFunctions: Set<string>;
224
+ visitPine_script(ctx: any): string;
225
+ protected enforceStaticRequestScope(ctx: any, callee: string): void;
226
+ visitFun_call(ctx: any): string;
227
+ /** The keyword arguments of a call, in order. */
228
+ protected kwArgs(ctx: any): Array<{
229
+ name: string;
230
+ value: any;
231
+ node: any;
232
+ }>;
233
+ /** The positional arguments of a call, in order. */
234
+ protected posArgs(ctx: any): any[];
235
+ protected enforceV6CallRules(ctx: any): void;
236
+ }
237
+ export {};
@@ -0,0 +1,94 @@
1
+ /**
2
+ * Static facts the v6 emitter needs about an expression, and the tables of
3
+ * names the migration guide's rules apply to.
4
+ *
5
+ * ── The rule every predicate here follows ──────────────────────────────────
6
+ *
7
+ * Each answers "PROVABLY", never "probably". These feed compile errors, and
8
+ * the two ways to be wrong are not symmetric: a missed case compiles a script
9
+ * TradingView would have rejected — the status quo at v5 — while a false
10
+ * positive rejects a correct script outright. So a predicate that cannot prove
11
+ * its answer says no. This is the same contract `isStaticallyBool` in
12
+ * ../common/passes/ScopeAnalysis.ts states, and the two are meant to be read
13
+ * together.
14
+ *
15
+ * Source for every table: the v6 migration guide,
16
+ * https://www.tradingview.com/pine-script-docs/migration-guides/to-pine-version-6/
17
+ */
18
+ import type { ScopeInfo } from "../common/passes/ScopeAnalysis.js";
19
+ /** Duck-typed node access — the generated contexts share no usable base type. */
20
+ export declare function kids(node: any): any[];
21
+ export declare function ruleName(node: any): string;
22
+ export declare function unwrap(node: any): any;
23
+ /** Is `node` provably an int or float value? */
24
+ export declare function isStaticallyNumeric(node: any, scopes: ScopeInfo): boolean;
25
+ /** The type name to put in a diagnostic for a numeric node: int, or float. */
26
+ export declare function numericTypeName(node: any, scopes: ScopeInfo): "int" | "float";
27
+ /** Is `node` a literal value — `6`, `"text"`, `true`, `#FF0000`? */
28
+ export declare function isLiteral(node: any): boolean;
29
+ /** Is `node` the bare identifier `na`? */
30
+ export declare function isNaLiteral(node: any): boolean;
31
+ /**
32
+ * MG §"Removal of `when` parameter": removed from these seven functions.
33
+ */
34
+ export declare const WHEN_REMOVED: Set<string>;
35
+ /**
36
+ * MG §"The `transp` parameter is removed": from these six functions.
37
+ */
38
+ export declare const TRANSP_REMOVED: Set<string>;
39
+ /** Does `callee`'s parameter `name` take a unique type? Built-ins only. */
40
+ export declare function isUniqueParam(callee: string, name: string): boolean;
41
+ /** Is `node` a bare read of a unique-type constant, like `plot.style_line`? */
42
+ export declare function isUniqueConstant(node: any): boolean;
43
+ /**
44
+ * Parameters of built-ins that take a "simple" length, where v6 makes passing
45
+ * a mutable variable a compile error (MG §"Mutable variables are always
46
+ * series"). The guide's own example is `ta.ema`; each entry below is a
47
+ * parameter the reference manual types as "simple int". Indices are the
48
+ * POSITIONAL slot, names the keyword.
49
+ */
50
+ export declare const SIMPLE_LENGTH_PARAMS: ReadonlyMap<string, ReadonlyArray<[number, string]>>;
51
+ /**
52
+ * Is `node` provably a "series" value?
53
+ *
54
+ * True when it reads a bar-varying built-in, calls a `ta.*` or `request.*`
55
+ * function, or reads a variable that is reassigned with `:=` — which v6 makes
56
+ * series unconditionally (MG §"Mutable variables are always series").
57
+ */
58
+ export declare function isStaticallySeries(node: any, scopes: ScopeInfo): boolean;
59
+ /**
60
+ * Does `node` read a numeric literal below 1 — `0`, `-5`, `0.5`?
61
+ *
62
+ * MG §"Minimum linewidth is 1". Only literals are decided here: a computed
63
+ * width is a run-time value on TradingView too.
64
+ */
65
+ export declare function isLiteralBelowOne(node: any): boolean;
66
+ /** Does the declaration pass `dynamic_requests = false`? */
67
+ export declare function declaresStaticRequests(root: any): boolean;
68
+ /**
69
+ * User functions that reach a `request.*()` call, directly or by calling
70
+ * another such function. A fixed point over the call graph, because the
71
+ * wrapper may itself be wrapped.
72
+ */
73
+ export declare function findRequestingFunctions(root: any): Set<string>;
74
+ /**
75
+ * Is `node` inside the body of a loop or conditional? Stops at a function
76
+ * definition: a function's body is its own scope, and whether IT runs
77
+ * conditionally is decided where it is called.
78
+ *
79
+ * "Body", not condition: `if request.security(…) > 0` evaluates the request in
80
+ * the enclosing scope, so only a request below a block counts.
81
+ */
82
+ export declare function insideConditionalOrLoop(node: any): boolean;
83
+ /** `dynamic_requests` as the declaration states it: "true", "false", or absent. */
84
+ export declare function dynamicRequestsSetting(root: any): string | null;
85
+ /** The name of the script's declaration call: indicator, strategy or library. */
86
+ export declare function declarationName(root: any): string | null;
87
+ /** Every call name in the script. */
88
+ export declare function allCallNames(root: any): Set<string>;
89
+ export declare function hasIndicatorOutput(root: any): boolean;
90
+ /**
91
+ * Is `node` PROVABLY a colour: a `color.*` constant, a `color.new/rgb/
92
+ * from_gradient` result, or a `#hex` literal.
93
+ */
94
+ export declare function isColorExpression(node: any): boolean;
@@ -0,0 +1,4 @@
1
+ export declare const PREFIX = "opsv2_";
2
+ export declare function removePrefix(str: string): string;
3
+ export declare function extractFunctionName(id: string): string;
4
+ export declare function val(x: any): any;
package/package.json CHANGED
@@ -1,6 +1,94 @@
1
1
  {
2
2
  "name": "openpinescript",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
3
+ "version": "0.1.0",
4
+ "description": "Run TradingView Pine Script locally and offline. Compiles Pine Script v1-v6 to JavaScript and executes it against your own OHLCV data, with indicator, plotting and strategy backtesting output verified against TradingView itself.",
5
+ "keywords": [
6
+ "pine-script",
7
+ "pinescript",
8
+ "tradingview",
9
+ "pine-script-v5",
10
+ "pine-script-v6",
11
+ "trading",
12
+ "backtesting",
13
+ "backtest",
14
+ "technical-analysis",
15
+ "indicators",
16
+ "transpiler",
17
+ "compiler",
18
+ "charting",
19
+ "algorithmic-trading",
20
+ "ohlcv",
21
+ "antlr"
22
+ ],
23
+ "homepage": "https://github.com/be-thomas/OpenPineScript#readme",
24
+ "bugs": {
25
+ "url": "https://github.com/be-thomas/OpenPineScript/issues"
26
+ },
27
+ "repository": {
28
+ "type": "git",
29
+ "url": "git+https://github.com/be-thomas/OpenPineScript.git"
30
+ },
31
+ "license": "GPL-3.0-or-later",
32
+ "author": "be-thomas",
33
+ "type": "module",
34
+ "main": "./dist/index.cjs",
35
+ "module": "./dist/index.mjs",
36
+ "types": "./dist/types/index.d.ts",
37
+ "exports": {
38
+ ".": {
39
+ "types": "./dist/types/index.d.ts",
40
+ "import": "./dist/index.mjs",
41
+ "require": "./dist/index.cjs"
42
+ },
43
+ "./package.json": "./package.json"
44
+ },
45
+ "bin": {
46
+ "openpinescript": "./dist/cli.mjs"
47
+ },
48
+ "files": [
49
+ "dist",
50
+ "!dist/**/*.map",
51
+ "README.md",
52
+ "LICENSE"
53
+ ],
54
+ "sideEffects": false,
55
+ "scripts": {
56
+ "generate:parser": "node scripts/common/build-grammars.mjs && node scripts/common/patch-visitor.cjs",
57
+ "generate:parser:v1": "node scripts/common/build-grammars.mjs v1",
58
+ "generate:parser:v2": "node scripts/common/build-grammars.mjs v2",
59
+ "generate:parser:v3": "node scripts/common/build-grammars.mjs v3",
60
+ "generate:parser:v4": "node scripts/common/build-grammars.mjs v4",
61
+ "generate:parser:v5": "node scripts/common/build-grammars.mjs v5",
62
+ "generate:parser:v6": "node scripts/common/build-grammars.mjs v6",
63
+ "prebuild": "ts-node scripts/common/generate-metadata.ts",
64
+ "build": "npm run generate:parser && node scripts/common/build-dist.mjs",
65
+ "parse": "tsx parser/v2/run_antlr.ts",
66
+ "replv2": "tsx repl/v2/index.ts",
67
+ "opsv2": "tsx mock_run/v2/run.ts",
68
+ "test": "vitest run",
69
+ "test:watch": "vitest",
70
+ "test:cov": "vitest run --coverage",
71
+ "prepare": "npm run generate:parser",
72
+ "build:dist": "node scripts/common/build-dist.mjs",
73
+ "prepublishOnly": "npm run build && npm test"
74
+ },
75
+ "dependencies": {
76
+ "antlr4ng": "^1.0.0"
77
+ },
78
+ "devDependencies": {
79
+ "@types/node": "^22.10.2",
80
+ "antlr-ng": "^1.0.0",
81
+ "esbuild": "^0.27.0",
82
+ "ts-morph": "^27.0.2",
83
+ "ts-node": "^10.9.2",
84
+ "tsx": "^4.21.0",
85
+ "typescript": "^5.6.0",
86
+ "vitest": "^4.0.18"
87
+ },
88
+ "engines": {
89
+ "node": ">=20.0.0"
90
+ },
91
+ "publishConfig": {
92
+ "access": "public"
93
+ }
94
+ }