Should we bump power precedence? (#3900)
* Should we bump power predecence * add test * fix stupid test name
This commit is contained in:
		
										
											
												File diff suppressed because one or more lines are too long
											
										
									
								
							@ -410,6 +410,11 @@ describe('testing math operators', () => {
 | 
			
		||||
    const mem = await exe(code)
 | 
			
		||||
    expect(mem.get('myVar')?.value).toBe(5)
 | 
			
		||||
  })
 | 
			
		||||
  it('can do power of math', async () => {
 | 
			
		||||
    const code = 'const myNeg2 = 4 ^ 2 - 3 ^ 2 * 2'
 | 
			
		||||
    const mem = await exe(code)
 | 
			
		||||
    expect(mem.get('myNeg2')?.value).toBe(-2)
 | 
			
		||||
  })
 | 
			
		||||
})
 | 
			
		||||
 | 
			
		||||
describe('Testing Errors', () => {
 | 
			
		||||
 | 
			
		||||
@ -2875,7 +2875,7 @@ impl BinaryOperator {
 | 
			
		||||
        match &self {
 | 
			
		||||
            BinaryOperator::Add | BinaryOperator::Sub => 11,
 | 
			
		||||
            BinaryOperator::Mul | BinaryOperator::Div | BinaryOperator::Mod => 12,
 | 
			
		||||
            BinaryOperator::Pow => 6,
 | 
			
		||||
            BinaryOperator::Pow => 13,
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
@ -3465,6 +3465,12 @@ const sketch001 = startSketchOn('XY')
 | 
			
		||||
  //   angleStart: 450,
 | 
			
		||||
  // }, %)
 | 
			
		||||
  |> startProfileAt(%)
 | 
			
		||||
"#
 | 
			
		||||
    );
 | 
			
		||||
    snapshot_test!(
 | 
			
		||||
        bb,
 | 
			
		||||
        r#"
 | 
			
		||||
const my14 = 4 ^ 2 - 3 ^ 2 * 2
 | 
			
		||||
"#
 | 
			
		||||
    );
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
@ -0,0 +1,117 @@
 | 
			
		||||
---
 | 
			
		||||
source: kcl/src/parser/parser_impl.rs
 | 
			
		||||
assertion_line: 3470
 | 
			
		||||
expression: actual
 | 
			
		||||
---
 | 
			
		||||
{
 | 
			
		||||
  "start": 0,
 | 
			
		||||
  "end": 32,
 | 
			
		||||
  "body": [
 | 
			
		||||
    {
 | 
			
		||||
      "type": "VariableDeclaration",
 | 
			
		||||
      "type": "VariableDeclaration",
 | 
			
		||||
      "start": 1,
 | 
			
		||||
      "end": 31,
 | 
			
		||||
      "declarations": [
 | 
			
		||||
        {
 | 
			
		||||
          "type": "VariableDeclarator",
 | 
			
		||||
          "start": 7,
 | 
			
		||||
          "end": 31,
 | 
			
		||||
          "id": {
 | 
			
		||||
            "type": "Identifier",
 | 
			
		||||
            "start": 7,
 | 
			
		||||
            "end": 11,
 | 
			
		||||
            "name": "my14",
 | 
			
		||||
            "digest": null
 | 
			
		||||
          },
 | 
			
		||||
          "init": {
 | 
			
		||||
            "type": "BinaryExpression",
 | 
			
		||||
            "type": "BinaryExpression",
 | 
			
		||||
            "start": 14,
 | 
			
		||||
            "end": 31,
 | 
			
		||||
            "operator": "-",
 | 
			
		||||
            "left": {
 | 
			
		||||
              "type": "BinaryExpression",
 | 
			
		||||
              "type": "BinaryExpression",
 | 
			
		||||
              "start": 14,
 | 
			
		||||
              "end": 19,
 | 
			
		||||
              "operator": "^",
 | 
			
		||||
              "left": {
 | 
			
		||||
                "type": "Literal",
 | 
			
		||||
                "type": "Literal",
 | 
			
		||||
                "start": 14,
 | 
			
		||||
                "end": 15,
 | 
			
		||||
                "value": 4,
 | 
			
		||||
                "raw": "4",
 | 
			
		||||
                "digest": null
 | 
			
		||||
              },
 | 
			
		||||
              "right": {
 | 
			
		||||
                "type": "Literal",
 | 
			
		||||
                "type": "Literal",
 | 
			
		||||
                "start": 18,
 | 
			
		||||
                "end": 19,
 | 
			
		||||
                "value": 2,
 | 
			
		||||
                "raw": "2",
 | 
			
		||||
                "digest": null
 | 
			
		||||
              },
 | 
			
		||||
              "digest": null
 | 
			
		||||
            },
 | 
			
		||||
            "right": {
 | 
			
		||||
              "type": "BinaryExpression",
 | 
			
		||||
              "type": "BinaryExpression",
 | 
			
		||||
              "start": 22,
 | 
			
		||||
              "end": 31,
 | 
			
		||||
              "operator": "*",
 | 
			
		||||
              "left": {
 | 
			
		||||
                "type": "BinaryExpression",
 | 
			
		||||
                "type": "BinaryExpression",
 | 
			
		||||
                "start": 22,
 | 
			
		||||
                "end": 27,
 | 
			
		||||
                "operator": "^",
 | 
			
		||||
                "left": {
 | 
			
		||||
                  "type": "Literal",
 | 
			
		||||
                  "type": "Literal",
 | 
			
		||||
                  "start": 22,
 | 
			
		||||
                  "end": 23,
 | 
			
		||||
                  "value": 3,
 | 
			
		||||
                  "raw": "3",
 | 
			
		||||
                  "digest": null
 | 
			
		||||
                },
 | 
			
		||||
                "right": {
 | 
			
		||||
                  "type": "Literal",
 | 
			
		||||
                  "type": "Literal",
 | 
			
		||||
                  "start": 26,
 | 
			
		||||
                  "end": 27,
 | 
			
		||||
                  "value": 2,
 | 
			
		||||
                  "raw": "2",
 | 
			
		||||
                  "digest": null
 | 
			
		||||
                },
 | 
			
		||||
                "digest": null
 | 
			
		||||
              },
 | 
			
		||||
              "right": {
 | 
			
		||||
                "type": "Literal",
 | 
			
		||||
                "type": "Literal",
 | 
			
		||||
                "start": 30,
 | 
			
		||||
                "end": 31,
 | 
			
		||||
                "value": 2,
 | 
			
		||||
                "raw": "2",
 | 
			
		||||
                "digest": null
 | 
			
		||||
              },
 | 
			
		||||
              "digest": null
 | 
			
		||||
            },
 | 
			
		||||
            "digest": null
 | 
			
		||||
          },
 | 
			
		||||
          "digest": null
 | 
			
		||||
        }
 | 
			
		||||
      ],
 | 
			
		||||
      "kind": "const",
 | 
			
		||||
      "digest": null
 | 
			
		||||
    }
 | 
			
		||||
  ],
 | 
			
		||||
  "nonCodeMeta": {
 | 
			
		||||
    "nonCodeNodes": {},
 | 
			
		||||
    "start": [],
 | 
			
		||||
    "digest": null
 | 
			
		||||
  },
 | 
			
		||||
  "digest": null
 | 
			
		||||
}
 | 
			
		||||
										
											Binary file not shown.
										
									
								
							| 
		 Before Width: | Height: | Size: 52 KiB After Width: | Height: | Size: 57 KiB  | 
		Reference in New Issue
	
	Block a user