Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support dots in identifiers #19

Open
tshemsedinov opened this issue Jul 16, 2022 · 3 comments · May be fixed by #21
Open

Support dots in identifiers #19

tshemsedinov opened this issue Jul 16, 2022 · 3 comments · May be fixed by #21
Assignees
Labels
metarhia-s'22 Good for newcomers

Comments

@tshemsedinov
Copy link
Member

tshemsedinov commented Jul 16, 2022

We have PR for this issue, it's crashing but it is just to show the problem

Here is a case to be supported

  const sheet = new Sheet();
  sheet.cells['item1.price'] = 100;
  sheet.cells['item2.price'] = 200;
  sheet.cells['item3.price'] = 300;
  sheet.cells['total'] = '=item1.price + item2.price + item3.price';
  test.strictSame(sheet.values['total'], 600);

Now it result:

Node v14.20.0 (v8 8.4.371.23-node.87):
Simple expressions .................................... 3/3
Expression chain ...................................... 2/2
JavaScript Math ....................................... 8/8
Prevent arbitrary js code execution ................... 7/7
Non-table identifiers ................................. 0/1
  not ok fail
    --- wanted
    +++ found
    -[null]
    +{
    +  "message": "Cannot read property 'price' of undefined"
    +  "name": "TypeError"
    +  "stack": "TypeError: Cannot read property 'price' of undefined
    +    at total:2:13
    +    at Object.getValue [as get] (metacalc/lib/sheet.js:22:10)
    +    at ImperativeTest.func (metacalc/test/unit.js:60:31)
    +    at ImperativeTest.runNow (metatests/lib/imperative-test.js:893:22)
    +    at Domain.<anonymous> (metatests/lib/imperative-test.js:875:14)
    +    at Domain.run (domain.js:378:15)
    +    at metatests/lib/imperative-test.js:874:18
    +    at processTicksAndRejections (internal/process/task_queues.js:77:11)"
    +}
    message: Promise rejection
    severity: fail
    type: fail
    at:
      file: /home/marcus/Dropbox/Metarhia/metacalc/test/unit.js
    stack: |
      processTicksAndRejections (internal/process/task_queues.js:95:5)

FAILED test 5
Failed 1/5 tests, 80.00% okay
npm ERR! Test failed.  See above for more details.
@tshemsedinov tshemsedinov added the metarhia-s'22 Good for newcomers label Jul 16, 2022
tshemsedinov added a commit that referenced this issue Jul 16, 2022
@Eternal-Rise
Copy link

Hello! The solution here is to make deep objects or has another approach?

@tshemsedinov
Copy link
Member Author

We can implement it adding proxies. sheet.cells['item1'] -> Proxy instance with hook to read property item1.price @Eternal-Rise

@Eternal-Rise
Copy link

Eternal-Rise commented Jul 28, 2022

@tshemsedinov , what if we "override" some value?

const sheet = new Sheet();
sheet.cells['item1.price'] = 100;
sheet.cells['item2.price'] = 200;
sheet.cells['item3.price'] = 300;
sheet.cells['total'] = '=item1.price + item2.price + item3.price';
test.strictSame(sheet.values['total'], 600);

sheet.cells['item3'] = 42';
test.strictSame(sheet.values['total'], 600); // what we expect here?

Anyway, I want to help with it

Eternal-Rise pushed a commit to Eternal-Rise/metacalc that referenced this issue Aug 3, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
metarhia-s'22 Good for newcomers
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants