pinets 0.9.27 → 0.9.28

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.
@@ -31,6 +31,7 @@ import { toradians } from './methods/toradians';
31
31
  import { __eq } from './methods/__eq';
32
32
  import { __ge } from './methods/__ge';
33
33
  import { __gt } from './methods/__gt';
34
+ import { __idiv } from './methods/__idiv';
34
35
  import { __le } from './methods/__le';
35
36
  import { __lt } from './methods/__lt';
36
37
  import { __neq } from './methods/__neq';
@@ -68,6 +69,7 @@ declare const methods: {
68
69
  __eq: typeof __eq;
69
70
  __ge: typeof __ge;
70
71
  __gt: typeof __gt;
72
+ __idiv: typeof __idiv;
71
73
  __le: typeof __le;
72
74
  __lt: typeof __lt;
73
75
  __neq: typeof __neq;
@@ -108,6 +110,7 @@ export declare class PineMath {
108
110
  __eq: ReturnType<typeof methods.__eq>;
109
111
  __ge: ReturnType<typeof methods.__ge>;
110
112
  __gt: ReturnType<typeof methods.__gt>;
113
+ __idiv: ReturnType<typeof methods.__idiv>;
111
114
  __le: ReturnType<typeof methods.__le>;
112
115
  __lt: ReturnType<typeof methods.__lt>;
113
116
  __neq: ReturnType<typeof methods.__neq>;
@@ -0,0 +1,20 @@
1
+ /**
2
+ * Pine integer division — the `/` (and `%`, via the transpiler) operator applied
3
+ * to two **integer** operands. In Pine, `int / int` yields an `int`: the result
4
+ * is truncated toward zero (`11 / 2 === 5`, `-11 / 2 === -5`), whereas JavaScript
5
+ * `/` is always float division (`5.5`).
6
+ *
7
+ * The transpiler rewrites a `/` BinaryExpression to this helper ONLY when BOTH
8
+ * operands are provably `int` at compile time (see TypeInferencePass). Any float
9
+ * operand keeps native `/`, so genuine float division (`4.0 / 2.0`, `close / 2`)
10
+ * is untouched.
11
+ *
12
+ * Semantics:
13
+ * - `na` (NaN) in either operand propagates → NaN.
14
+ * - Division by zero follows the same rule as native `/`: `Math.trunc` preserves
15
+ * `1 / 0 → Infinity` and `0 / 0 → NaN`, matching PineTS's existing div-by-zero
16
+ * behavior (truncation only changes finite results).
17
+ * - Non-numeric operands fall back to native `/` (defensive; should not occur
18
+ * given the compile-time int guard).
19
+ */
20
+ export declare function __idiv(context: any): (a: any, b: any) => number;
@@ -0,0 +1,16 @@
1
+ /**
2
+ * Pine Script integer division (`int / int → int`).
3
+ *
4
+ * TradingView truncates the quotient toward zero when BOTH operands are of
5
+ * type `int` (Java semantics: `11 / 2 == 5`, `-7 / 2 == -3`). Plain JS `/`
6
+ * always yields a float, which breaks idioms like `pivots(high, depth / 2)`
7
+ * where the result feeds a series history offset.
8
+ *
9
+ * The pine2js codegen emits this helper only when both operands are
10
+ * statically provable ints (declared `int` vars/params, int literals,
11
+ * `input.int`, int-result expressions). Anything unprovable keeps plain `/`.
12
+ *
13
+ * - `na` in either operand propagates (`NaN`).
14
+ * - Division by zero returns `na` (`NaN`) instead of JS `Infinity`.
15
+ */
16
+ export declare function __intDiv(context: any): (a: any, b: any) => number;
@@ -0,0 +1,2 @@
1
+ import ScopeManager from './ScopeManager';
2
+ export declare function runTypeInferencePass(ast: any, _scopeManager: ScopeManager): void;
@@ -35,5 +35,5 @@ export declare class Lexer {
35
35
  isIdentifierStart(ch: any): boolean;
36
36
  isIdentifierChar(ch: any): boolean;
37
37
  getCurrentIndent(): number;
38
- addToken(type: any, value: any, indent?: any): void;
38
+ addToken(type: any, value: any, indent?: any, raw?: any): void;
39
39
  }
@@ -29,5 +29,6 @@ export declare class Token {
29
29
  line: number;
30
30
  column: number;
31
31
  indent: number;
32
- constructor(type: string, value: any, line: number, column: number, indent?: number);
32
+ raw: string;
33
+ constructor(type: string, value: any, line: number, column: number, indent?: number, raw?: string);
33
34
  }
@@ -21,6 +21,7 @@ export declare const ASTFactory: {
21
21
  createMathEqCall(left: any, right: any): any;
22
22
  createMathNeqCall(left: any, right: any): any;
23
23
  createMathCompareCall(method: string, left: any, right: any): any;
24
+ createMathIntDivCall(left: any, right: any): any;
24
25
  createWrapperFunction(body: any): any;
25
26
  createVariableDeclaration(name: string, init: any): any;
26
27
  createAwaitExpression(argument: any): any;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pinets",
3
- "version": "0.9.27",
3
+ "version": "0.9.28",
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",