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

semantic: ReferenceFlag::Write should only be assigned for assignment expressions #7323

Closed
Boshen opened this issue Nov 17, 2024 · 4 comments · Fixed by #7388
Closed

semantic: ReferenceFlag::Write should only be assigned for assignment expressions #7323

Boshen opened this issue Nov 17, 2024 · 4 comments · Fixed by #7388
Assignees
Labels
C-bug Category - Bug P-high Priority - High

Comments

@Boshen
Copy link
Member

Boshen commented Nov 17, 2024

var a, b;
z = (a, b = _o, x);
        ^ "flags": "Read | Write"

b should be "Write" only.

@Boshen Boshen added the C-bug Category - Bug label Nov 17, 2024
@Boshen Boshen self-assigned this Nov 17, 2024
@overlookmotel
Copy link
Contributor

Related to: #5165

@Boshen Boshen changed the title semantic: ReferenceFlag in SequenceExpression semantic: ReferenceFlag::Write should only be assigned for assignment expressions Nov 20, 2024
@Boshen
Copy link
Member Author

Boshen commented Nov 20, 2024

Found another bug:

const FOO = 1;

({
  files = FOO,
} = arg1);

Warning: Unexpected re-assignment of const variable FOO

@Boshen Boshen added the P-high Priority - High label Nov 20, 2024
@Dunqing
Copy link
Member

Dunqing commented Nov 21, 2024

Found another bug:

const FOO = 1;

({
  files = FOO,
} = arg1);

Warning: Unexpected re-assignment of const variable FOO

Let me take a look at this bug

Boshen pushed a commit that referenced this issue Nov 22, 2024
…spec (#7388)

close #7323

According to the specification re-design the JavaScript-part ReferenceFlags inferring approach.

* https://tc39.es/ecma262/#sec-assignment-operators-runtime-semantics-evaluation
* https://tc39.es/ecma262/#sec-postfix-increment-operator-runtime-semantics-evaluation
* https://tc39.es/ecma262/#sec-runtime-semantics-restdestructuringassignmentevaluation
* ... See references of https://tc39.es/ecma262/#sec-putvalue

### Changes

1. The left-hand of `AssignmentExpression` is always `ReferenceFlags::Write`
```js
let a = 0;
console.log(a = 0);
            ^ Write only
```

2. The `argument` of `UpdateExpression` is always `ReferenceFlags::Read | Write`
```js
let a = 0;
a++;
^ Read and Write
```

This change might cause some trouble for `Minfier` to remove this code, because ‘a’ is not used elsewhere. I have taken a look at `esbuild` and `Terser`. Only the `Terser` can remove this code.
Boshen pushed a commit that referenced this issue Nov 22, 2024
…spec (#7388)

close #7323

According to the specification re-design the JavaScript-part ReferenceFlags inferring approach.

* https://tc39.es/ecma262/#sec-assignment-operators-runtime-semantics-evaluation
* https://tc39.es/ecma262/#sec-postfix-increment-operator-runtime-semantics-evaluation
* https://tc39.es/ecma262/#sec-runtime-semantics-restdestructuringassignmentevaluation
* ... See references of https://tc39.es/ecma262/#sec-putvalue

### Changes

1. The left-hand of `AssignmentExpression` is always `ReferenceFlags::Write`
```js
let a = 0;
console.log(a = 0);
            ^ Write only
```

2. The `argument` of `UpdateExpression` is always `ReferenceFlags::Read | Write`
```js
let a = 0;
a++;
^ Read and Write
```

This change might cause some trouble for `Minfier` to remove this code, because ‘a’ is not used elsewhere. I have taken a look at `esbuild` and `Terser`. Only the `Terser` can remove this code.
@Boshen Boshen closed this as completed Nov 23, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-bug Category - Bug P-high Priority - High
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants