pinets 0.9.3 → 0.9.4

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 (29) hide show
  1. package/dist/pinets.min.browser.es.js +25 -24
  2. package/dist/pinets.min.browser.es.js.map +1 -1
  3. package/dist/pinets.min.browser.js +25 -24
  4. package/dist/pinets.min.browser.js.map +1 -1
  5. package/dist/pinets.min.cjs +21 -20
  6. package/dist/pinets.min.cjs.map +1 -1
  7. package/dist/pinets.min.es.js +21 -20
  8. package/dist/pinets.min.es.js.map +1 -1
  9. package/dist/types/NaProxy.d.ts +19 -0
  10. package/dist/types/namespaces/Core.d.ts +3 -23
  11. package/dist/types/namespaces/Str.d.ts +2 -1
  12. package/dist/types/namespaces/Timeframe.d.ts +8 -3
  13. package/dist/types/namespaces/Types.d.ts +18 -1
  14. package/dist/types/namespaces/array/methods/new_bool.d.ts +1 -1
  15. package/dist/types/namespaces/array/methods/new_float.d.ts +1 -1
  16. package/dist/types/namespaces/array/methods/new_int.d.ts +1 -1
  17. package/dist/types/namespaces/array/methods/new_string.d.ts +1 -1
  18. package/dist/types/namespaces/color/PineColor.d.ts +45 -0
  19. package/dist/types/namespaces/linefill/LinefillObject.d.ts +3 -0
  20. package/dist/types/namespaces/math/math.index.d.ts +3 -0
  21. package/dist/types/namespaces/math/methods/__neq.d.ts +13 -0
  22. package/dist/types/namespaces/polyline/PolylineHelper.d.ts +5 -0
  23. package/dist/types/namespaces/request/methods/security_lower_tf.d.ts +2 -1
  24. package/dist/types/namespaces/utils.d.ts +1 -1
  25. package/dist/types/transpiler/analysis/ScopeManager.d.ts +11 -0
  26. package/dist/types/transpiler/pineToJS/codegen.d.ts +5 -0
  27. package/dist/types/transpiler/transformers/MainTransformer.d.ts +12 -0
  28. package/dist/types/transpiler/utils/ASTFactory.d.ts +1 -0
  29. package/package.json +1 -1
@@ -0,0 +1,19 @@
1
+ /**
2
+ * NaProxy: A proxy object that represents `na` for UDT (User-Defined Type) values.
3
+ *
4
+ * In Pine Script, accessing a property on `na` returns `na`, and calling a method on
5
+ * `na` returns `na`. In JavaScript, NaN doesn't support property access, so we use
6
+ * this proxy as a stand-in.
7
+ *
8
+ * Behavior:
9
+ * - Any property access returns the proxy itself (chaining: proxy.bx.get_top → proxy)
10
+ * - Called as a function, returns proxy (proxy() → proxy, for chaining: proxy.method().field)
11
+ * - valueOf() returns NaN (arithmetic: proxy + 5 → NaN)
12
+ * - na.any(proxy) → true
13
+ */
14
+ /** Symbol used to identify NaProxy objects */
15
+ export declare const NA_MARKER: unique symbol;
16
+ /** Singleton NaProxy instance */
17
+ export declare const NA_PROXY: any;
18
+ /** Check if a value is a NaProxy */
19
+ export declare function isNaProxy(val: any): boolean;
@@ -13,29 +13,6 @@ export declare class NAHelper {
13
13
  }
14
14
  export declare class Core {
15
15
  private context;
16
- color: {
17
- param: (source: any, index?: number) => any;
18
- rgb: (r: number, g: number, b: number, a?: number) => string;
19
- new: (color: any, a?: number) => any;
20
- from_gradient: (value: any, bottom_value: any, top_value: any, bottom_color: any, top_color: any) => string;
21
- aqua: "#00BCD4";
22
- black: "#363A45";
23
- blue: "#2196F3";
24
- fuchsia: "#E040FB";
25
- gray: "#787B86";
26
- green: "#4CAF50";
27
- lime: "#00E676";
28
- maroon: "#880E4F";
29
- navy: "#311B92";
30
- olive: "#808000";
31
- orange: "#FF9800";
32
- purple: "#9C27B0";
33
- red: "#F23645";
34
- silver: "#B2B5BE";
35
- teal: "#089981";
36
- white: "#FFFFFF";
37
- yellow: "#FDD835";
38
- };
39
16
  constructor(context: any);
40
17
  private extractPlotOptions;
41
18
  indicator(...args: any[]): any;
@@ -44,6 +21,9 @@ export declare class Core {
44
21
  nz(series: any, replacement?: number): any;
45
22
  fixnan(series: any): any;
46
23
  alertcondition(condition: any, title: any, message: any): void;
24
+ alert(...args: any[]): void;
25
+ error(...args: any[]): void;
26
+ max_bars_back(series?: any, length?: any): void;
47
27
  /**
48
28
  * Converts date/time components to a UNIX timestamp in milliseconds.
49
29
  * Supports multiple signatures:
@@ -1,4 +1,5 @@
1
1
  import { Context } from '..';
2
+ import { PineArrayObject } from './array/PineArrayObject';
2
3
  export declare class Str {
3
4
  private context;
4
5
  constructor(context: Context);
@@ -17,7 +18,7 @@ export declare class Str {
17
18
  pos(source: string, target: string): number;
18
19
  length(source: string): number;
19
20
  match(source: string, pattern: string): RegExpMatchArray;
20
- split(source: string, separator: string): string[][];
21
+ split(source: string, separator: string): PineArrayObject;
21
22
  substring(source: string, begin_pos: number, end_pos: number): string;
22
23
  format(message: string, ...args: any[]): string;
23
24
  }
@@ -1,9 +1,14 @@
1
1
  export declare class Timeframe {
2
2
  private context;
3
+ private _normalized;
3
4
  constructor(context: any);
4
5
  param(source: any, index?: number, name?: string): any;
5
- get main_period(): any;
6
- get period(): any;
6
+ /** Normalized canonical timeframe (cached) */
7
+ private get normalized();
8
+ /** Last character of the normalized timeframe (uppercase) */
9
+ private get unit();
10
+ get main_period(): string;
11
+ get period(): string;
7
12
  get multiplier(): number;
8
13
  get isdwm(): boolean;
9
14
  get isdaily(): boolean;
@@ -13,5 +18,5 @@ export declare class Timeframe {
13
18
  get isminutes(): boolean;
14
19
  get isintraday(): boolean;
15
20
  from_seconds(seconds: number): string | number;
16
- in_seconds(timeframe: string): number;
21
+ in_seconds(timeframe?: string): number;
17
22
  }
@@ -151,11 +151,16 @@ export declare enum extend {
151
151
  none = "n"
152
152
  }
153
153
  export declare enum text {
154
+ align_bottom = "bottom",
155
+ align_top = "top",
154
156
  align_left = "left",
155
157
  align_center = "center",
156
158
  align_right = "right",
157
159
  wrap_auto = "auto",
158
- wrap_none = "none"
160
+ wrap_none = "none",
161
+ format_bold = "bold",
162
+ format_italic = "italic",
163
+ format_none = "none"
159
164
  }
160
165
  export declare enum font {
161
166
  family_default = "default",
@@ -202,6 +207,16 @@ export declare enum position {
202
207
  bottom_center = "bottom_center",
203
208
  bottom_right = "bottom_right"
204
209
  }
210
+ export declare enum scale {
211
+ left = "left",
212
+ none = "none",
213
+ right = "right"
214
+ }
215
+ export declare enum settlement_as_close {
216
+ inherit = "inherit",
217
+ off = "off",
218
+ on = "on"
219
+ }
205
220
  declare const types: {
206
221
  order: typeof order;
207
222
  currency: typeof currency;
@@ -223,5 +238,7 @@ declare const types: {
223
238
  dividends: typeof dividends;
224
239
  splits: typeof splits;
225
240
  position: typeof position;
241
+ scale: typeof scale;
242
+ settlement_as_close: typeof settlement_as_close;
226
243
  };
227
244
  export default types;
@@ -1,2 +1,2 @@
1
1
  import { PineArrayObject } from '../PineArrayObject';
2
- export declare function new_bool(context: any): (size: number, initial_value?: boolean) => PineArrayObject;
2
+ export declare function new_bool(context: any): (size?: number, initial_value?: boolean) => PineArrayObject;
@@ -1,3 +1,3 @@
1
1
  import { PineArrayObject } from '../PineArrayObject';
2
2
  import { Context } from '../../../Context.class';
3
- export declare function new_float(context: Context): (size: number, initial_value?: number) => PineArrayObject;
3
+ export declare function new_float(context: Context): (size?: number, initial_value?: number) => PineArrayObject;
@@ -1,3 +1,3 @@
1
1
  import { PineArrayObject } from '../PineArrayObject';
2
2
  import { Context } from '../../../Context.class';
3
- export declare function new_int(context: Context): (size: number, initial_value?: number) => PineArrayObject;
3
+ export declare function new_int(context: Context): (size?: number, initial_value?: number) => PineArrayObject;
@@ -1,2 +1,2 @@
1
1
  import { PineArrayObject } from '../PineArrayObject';
2
- export declare function new_string(context: any): (size: number, initial_value?: string) => PineArrayObject;
2
+ export declare function new_string(context: any): (size?: number, initial_value?: string) => PineArrayObject;
@@ -0,0 +1,45 @@
1
+ /**
2
+ * PineColor implements the Pine Script `color` namespace.
3
+ *
4
+ * Supports:
5
+ * - color(na) → type-cast (via any())
6
+ * - color.new(color, alpha) → apply transparency
7
+ * - color.rgb(r, g, b, a?) → create from components
8
+ * - color.from_gradient(...) → interpolate between two colors
9
+ * - color.r/g/b/t(color) → extract individual components
10
+ * - color.red, color.blue, ... → named constants
11
+ */
12
+ export declare class PineColor {
13
+ private context;
14
+ constructor(context: any);
15
+ any(value: any): any;
16
+ param(source: any, index?: number): any;
17
+ new(color: any, a?: number): any;
18
+ rgb(r: number, g: number, b: number, a?: number): string;
19
+ from_gradient(value: any, bottom_value: any, top_value: any, bottom_color: any, top_color: any): any;
20
+ /** Extract red component (0-255) from a color string. Returns na if unparsable. */
21
+ r(color: any): number;
22
+ /** Extract green component (0-255) from a color string. Returns na if unparsable. */
23
+ g(color: any): number;
24
+ /** Extract blue component (0-255) from a color string. Returns na if unparsable. */
25
+ b(color: any): number;
26
+ /** Extract transparency (0-100, Pine scale) from a color string. Returns na if unparsable. */
27
+ t(color: any): number;
28
+ aqua(): "#00BCD4";
29
+ black(): "#363A45";
30
+ blue(): "#2196F3";
31
+ fuchsia(): "#E040FB";
32
+ gray(): "#787B86";
33
+ green(): "#4CAF50";
34
+ lime(): "#00E676";
35
+ maroon(): "#880E4F";
36
+ navy(): "#311B92";
37
+ olive(): "#808000";
38
+ orange(): "#FF9800";
39
+ purple(): "#9C27B0";
40
+ red(): "#F23645";
41
+ silver(): "#B2B5BE";
42
+ teal(): "#089981";
43
+ white(): "#FFFFFF";
44
+ yellow(): "#FDD835";
45
+ }
@@ -9,5 +9,8 @@ export declare class LinefillObject {
9
9
  /** Bar index at which this object was created (for streaming rollback) */
10
10
  _createdAtBar: number;
11
11
  constructor(line1: LineObject, line2: LineObject, color: string);
12
+ get_line1(): LineObject;
13
+ get_line2(): LineObject;
14
+ set_color(color: any): void;
12
15
  delete(): void;
13
16
  }
@@ -29,6 +29,7 @@ import { tan } from './methods/tan';
29
29
  import { todegrees } from './methods/todegrees';
30
30
  import { toradians } from './methods/toradians';
31
31
  import { __eq } from './methods/__eq';
32
+ import { __neq } from './methods/__neq';
32
33
  declare const methods: {
33
34
  abs: typeof abs;
34
35
  acos: typeof acos;
@@ -61,6 +62,7 @@ declare const methods: {
61
62
  todegrees: typeof todegrees;
62
63
  toradians: typeof toradians;
63
64
  __eq: typeof __eq;
65
+ __neq: typeof __neq;
64
66
  };
65
67
  export declare class PineMath {
66
68
  private context;
@@ -96,6 +98,7 @@ export declare class PineMath {
96
98
  todegrees: ReturnType<typeof methods.todegrees>;
97
99
  toradians: ReturnType<typeof methods.toradians>;
98
100
  __eq: ReturnType<typeof methods.__eq>;
101
+ __neq: ReturnType<typeof methods.__neq>;
99
102
  constructor(context: any);
100
103
  }
101
104
  export default PineMath;
@@ -0,0 +1,13 @@
1
+ /**
2
+ * Pine Script na-aware inequality comparison.
3
+ *
4
+ * In Pine Script, any comparison involving `na` returns `false`:
5
+ * na != na → false
6
+ * 1 != na → false
7
+ * na != 1 → false
8
+ *
9
+ * This cannot be implemented as `!__eq(a, b)` because __eq(na, na) returns
10
+ * false, and !false = true — which is wrong. Both == and != must independently
11
+ * return false when either operand is na.
12
+ */
13
+ export declare function __neq(context: any): (a: any, b: any) => boolean;
@@ -10,6 +10,11 @@ export declare class PolylineHelper {
10
10
  * Resolve a value that may be a Series, a bound function, or a plain scalar.
11
11
  */
12
12
  private _resolve;
13
+ /**
14
+ * Resolve a color value, preserving NaN (na = no color) instead of
15
+ * letting it fall through to a default via the || operator.
16
+ */
17
+ private _resolveColor;
13
18
  /**
14
19
  * Extract raw ChartPointObject array from a PineArrayObject, Series, or plain array.
15
20
  */
@@ -1,3 +1,4 @@
1
+ import { PineArrayObject } from '../../array/PineArrayObject';
1
2
  /**
2
3
  * Requests the results of an expression from a specified symbol on a timeframe lower than or equal to the chart's timeframe.
3
4
  * It returns an array containing one element for each lower-timeframe bar within the chart bar.
@@ -6,4 +7,4 @@
6
7
  * @param context
7
8
  * @returns
8
9
  */
9
- export declare function security_lower_tf(context: any): (symbol: any, timeframe: any, expression: any, ignore_invalid_symbol?: boolean | any[], currency?: any, ignore_invalid_timeframe?: boolean | any[], calc_bars_count?: number | any[]) => Promise<any>;
10
+ export declare function security_lower_tf(context: any): (symbol: any, timeframe: any, expression: any, ignore_invalid_symbol?: boolean | any[], currency?: any, ignore_invalid_timeframe?: boolean | any[], calc_bars_count?: number | any[]) => Promise<number | PineArrayObject | any[][]>;
@@ -16,4 +16,4 @@ export declare function extractCallsiteId(args: any[]): string | undefined;
16
16
  * @param types - The types to parse, each type is a string representing the type of the argument.
17
17
  * @returns The parsed arguments, the arguments are parsed according to the signatures and types.
18
18
  */
19
- export declare function parseArgsForPineParams<T>(args: any[], signatures: any[], types: Record<string, string>, override?: Record<string, any>): Partial<T> & T & Record<string, any>;
19
+ export declare function parseArgsForPineParams<T>(args: any[], signatures: any[], types: Record<string, string>, override?: Record<string, any>): T & Partial<T> & Record<string, any>;
@@ -19,6 +19,7 @@ export declare class ScopeManager {
19
19
  private suppressHoisting;
20
20
  private reservedNames;
21
21
  private userFunctions;
22
+ private userMethods;
22
23
  get nextParamIdArg(): any;
23
24
  get nextCacheIdArg(): any;
24
25
  getNextTACallId(): any;
@@ -45,8 +46,18 @@ export declare class ScopeManager {
45
46
  addReservedName(name: string): void;
46
47
  addUserFunction(name: string): void;
47
48
  isUserFunction(name: string): boolean;
49
+ addUserMethod(name: string): void;
50
+ isUserMethod(name: string): boolean;
48
51
  addVariable(name: string, kind: string): string;
49
52
  getVariable(name: string): [string, string];
53
+ /**
54
+ * Check if a variable (by original name) lives inside a function scope.
55
+ * Walks the scope stack to find which scope owns the variable, then checks
56
+ * whether any scope from the root up to (and including) that level is a
57
+ * function scope ('fn'). This allows nested scopes (if, else, for, while)
58
+ * inside functions to be correctly treated as function-local.
59
+ */
60
+ isVariableInFunctionScope(name: string): boolean;
50
61
  generateTempVar(): string;
51
62
  enterHoistingScope(): void;
52
63
  exitHoistingScope(): any[];
@@ -6,12 +6,16 @@ export declare class CodeGenerator {
6
6
  private sourceLines;
7
7
  private lastCommentedLine;
8
8
  private includeSourceComments;
9
+ private paramRenameCounter;
10
+ private functionParams;
9
11
  constructor(options?: {
10
12
  indentStr?: string;
11
13
  sourceCode?: string;
12
14
  includeSourceComments?: boolean;
13
15
  });
14
16
  generate(ast: any): string;
17
+ private preProcessAST;
18
+ private collectFunctionParams;
15
19
  writeSourceComment(startLine: any, endLine?: any): void;
16
20
  write(str: any): void;
17
21
  writeLine(str?: string): void;
@@ -20,6 +24,7 @@ export declare class CodeGenerator {
20
24
  generateProgram(node: any): void;
21
25
  generateStatement(node: any): void;
22
26
  generateTypeDefinition(node: any): void;
27
+ private renameIdentifiersInAST;
23
28
  generateFunctionDeclaration(node: any): void;
24
29
  generateVariableDeclaration(node: any): void;
25
30
  generateExpressionStatement(node: any): void;
@@ -1,4 +1,16 @@
1
1
  import ScopeManager from '../analysis/ScopeManager';
2
+ /**
3
+ * Post-pass: propagate async/await through user-defined function call chains.
4
+ *
5
+ * When request.security() is used inside a user-defined function, the transpiler
6
+ * injects `await` but doesn't mark the function as `async` or propagate await
7
+ * to callers via $.call(). This pass:
8
+ * 1. Finds all FunctionDeclarations containing AwaitExpression (directly, not in nested functions)
9
+ * 2. Marks them as async
10
+ * 3. Wraps $.call(fn, ...) invocations of those functions in AwaitExpression
11
+ * 4. Repeats until stable (handles transitive async infection: A calls B calls request.security)
12
+ */
13
+ export declare function propagateAsyncAwait(ast: any): void;
2
14
  export declare function transformEqualityChecks(ast: any): void;
3
15
  export declare function runTransformationPass(ast: any, scopeManager: ScopeManager, originalParamName: string, options?: {
4
16
  debug: boolean;
@@ -19,6 +19,7 @@ export declare const ASTFactory: {
19
19
  createGetCall(source: any, index: any): any;
20
20
  createSetCall(target: any, value: any): any;
21
21
  createMathEqCall(left: any, right: any): any;
22
+ createMathNeqCall(left: any, right: any): any;
22
23
  createWrapperFunction(body: any): any;
23
24
  createVariableDeclaration(name: string, init: any): any;
24
25
  createAwaitExpression(argument: any): any;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pinets",
3
- "version": "0.9.3",
3
+ "version": "0.9.4",
4
4
  "description": "Run Pine Script anywhere. PineTS is an open-source transpiler and runtime that brings Pine Script logic to Node.js and the browser with 1:1 syntax compatibility. Reliably write, port, and run indicators or strategies on your own infrastructure.",
5
5
  "keywords": [
6
6
  "Pine Script",