Skip to content
GitLab
Projects Groups Snippets
  • /
  • Help
    • Help
    • Support
    • Community forum
    • Submit feedback
    • Contribute to GitLab
  • Sign in / Register
  • S sweet-core
  • Project information
    • Project information
    • Activity
    • Labels
    • Members
  • Repository
    • Repository
    • Files
    • Commits
    • Branches
    • Tags
    • Contributors
    • Graph
    • Compare
  • Issues 62
    • Issues 62
    • List
    • Boards
    • Service Desk
    • Milestones
  • Merge requests 4
    • Merge requests 4
  • CI/CD
    • CI/CD
    • Pipelines
    • Jobs
    • Schedules
  • Deployments
    • Deployments
    • Environments
    • Releases
  • Packages and registries
    • Packages and registries
    • Package Registry
    • Infrastructure Registry
  • Monitor
    • Monitor
    • Incidents
  • Analytics
    • Analytics
    • Value stream
    • CI/CD
    • Repository
  • Wiki
    • Wiki
  • Snippets
    • Snippets
  • Activity
  • Graph
  • Create a new issue
  • Jobs
  • Commits
  • Issue Boards
Collapse sidebar
  • sweet-js
  • sweet-core
  • Issues
  • #748
Closed
Open
Issue created Feb 12, 2018 by kevin-dp@kevin-dp

Operator precedence not respected

I want to define an operator >>= which performs member access (i.e. is equivalent to .).

My first attempt does not compile:

operator >>= left 19 = (left, right) => {
    return #`${left}.${right}]`;
};

My second attempt (using computed member access) works but not as expected:

operator >>= left 19 = (left, right) => {
  let r = right.name.token.value; // string representation of an identifier
  let dummy = #`dummy`.get(0);
  return #`${left} [${fromStringLiteral(dummy, r)}]`;
};

I deliberately give my >>= operator precedence 19, which is the same precedence as javascript's member access operator (see JS operator precedence).

Based on the given precedence i would expect this to be possible:

var obj = {
    foo: function() {
        // return a promise
    }
};

obj>>=foo.then(res => { console.log(res); })

However, this does not compile. For some reason the right argument of my >>= operator is a call expression (i.e. foo.then(...)).

So, based on the given precedence i would expect obj>>=foo.then(...) to be equivalent to (obj>>=foo).then(...), however it seems to be interpreted as obj>>=(foo.then(...)).

If i manually add the parentheses as follows (obj>>=foo).then(...), then it works.

Assignee
Assign to
Time tracking