Git Product home page Git Product logo

Comments (3)

Dunqing avatar Dunqing commented on June 2, 2024

This seems to be intentional

// unary op counts as write, but checking continues up tree
(SourceType::default(), "let a = 1, b; b = ++a", ReferenceFlag::read_write()),
(SourceType::default(), "let a = 1, b; b = --a", ReferenceFlag::read_write()),
(SourceType::default(), "let a = 1, b; b = a++", ReferenceFlag::read_write()),
(SourceType::default(), "let a = 1, b; b = a--", ReferenceFlag::read_write()),

Same behavior in no_unused_private_class_members rule

r"class C {
#usedOnlyInIncrement;
foo() {
this.#usedOnlyInIncrement++;
}
}",

But I think x += 1 should be flagged as Write because x is never used for reading. I believe this variable can be safely removed by the Minifier/Compressor.

Does this make sense?

from oxc.

overlookmotel avatar overlookmotel commented on June 2, 2024

Hmm. I'm not clear what these flags are meant to represent now!

These are all (broadly) equivalent:

x = x + 1; // Read + Write
x += 1; // Read | Write
x++; // Write
++x; // Write

NB: Also depends on what x is. If it's an object with a valueOf method, the any of the above can have side effects.

This also seems to be inconsistent - it flags x as Read | Write where it could be just Write:

let x = 1;
let y = x = 2;

playground

And something strange going on here - the addition of console.log makes x Read | Write:

console.log;
let x = 1;
x++;

playground

from oxc.

Dunqing avatar Dunqing commented on June 2, 2024

Hmm. I'm not clear what these flags are meant to represent now!
These are all (broadly) equivalent:

x = x + 1; // Read + Write
x += 1; // Read | Write
x++; // Write
++x; // Write

The x = x + 1 is not equivalent. This assignment expression has two references. x + 1 will be flagged Read and x = will be flagged Write

NB: Also depends on what x is. If it's an object with a valueOf method, the any of the above can have side effects.

Yes! I forgot the valueOf method.

This also seems to be inconsistent - it flags x as Read | Write where it could be just Write:

let x = 1;
let y = x = 2;

playground

This case is correct. x = 2 should be flagged as Write and y = x should be flagged as Read

And something strange going on here - the addition of console.log makes x Read | Write:

console.log;
let x = 1;
x++;

playground

This is a bug! I will fix it.

from oxc.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.