mirror of
https://github.com/danbulant/oxc
synced 2026-05-24 12:21:58 +00:00
fix(semantic): remove inherting ScopeFlags::Modifier from parent scope (#7932)
close: #7900 After #4283 changed, we don't need to inherit `ScopeFlags` from the `constructor`, `set`, `get` anymore, I think this is a logic of forgetting to remove
This commit is contained in:
parent
dcb27ff6cd
commit
14c51ffa1d
4 changed files with 19 additions and 37 deletions
|
|
@ -41,8 +41,19 @@ impl Rule for NoSetterReturn {
|
||||||
let AstKind::ReturnStatement(stmt) = node.kind() else {
|
let AstKind::ReturnStatement(stmt) = node.kind() else {
|
||||||
return;
|
return;
|
||||||
};
|
};
|
||||||
if stmt.argument.is_some() && ctx.scopes().get_flags(node.scope_id()).is_set_accessor() {
|
if stmt.argument.is_none() {
|
||||||
ctx.diagnostic(no_setter_return_diagnostic(stmt.span));
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
for scope_id in ctx.scopes().ancestors(node.scope_id()) {
|
||||||
|
let flags = ctx.scopes().get_flags(scope_id);
|
||||||
|
if flags.is_set_accessor() {
|
||||||
|
ctx.diagnostic(no_setter_return_diagnostic(stmt.span));
|
||||||
|
} else if flags.is_function() {
|
||||||
|
break;
|
||||||
|
} else {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -143,21 +143,9 @@ impl ScopeTree {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Get [`ScopeFlags`] for a new child scope under `parent_scope_id`.
|
/// Get [`ScopeFlags`] for a new child scope under `parent_scope_id`.
|
||||||
pub fn get_new_scope_flags(
|
pub fn get_new_scope_flags(&self, flags: ScopeFlags, parent_scope_id: ScopeId) -> ScopeFlags {
|
||||||
&self,
|
|
||||||
mut flags: ScopeFlags,
|
|
||||||
parent_scope_id: ScopeId,
|
|
||||||
) -> ScopeFlags {
|
|
||||||
// https://tc39.es/ecma262/#sec-strict-mode-code
|
// https://tc39.es/ecma262/#sec-strict-mode-code
|
||||||
let parent_scope_flags = self.get_flags(parent_scope_id);
|
flags | self.get_flags(parent_scope_id) & ScopeFlags::StrictMode
|
||||||
flags |= parent_scope_flags & ScopeFlags::StrictMode;
|
|
||||||
|
|
||||||
// inherit flags for non-function scopes
|
|
||||||
if !flags.contains(ScopeFlags::Function) {
|
|
||||||
flags |= parent_scope_flags & ScopeFlags::Modifiers;
|
|
||||||
}
|
|
||||||
|
|
||||||
flags
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
|
|
|
||||||
|
|
@ -54767,7 +54767,7 @@ Bindings mismatch:
|
||||||
after transform: ScopeId(32): ["A", "B", "C", "E"]
|
after transform: ScopeId(32): ["A", "B", "C", "E"]
|
||||||
rebuilt : ScopeId(24): ["E"]
|
rebuilt : ScopeId(24): ["E"]
|
||||||
Scope flags mismatch:
|
Scope flags mismatch:
|
||||||
after transform: ScopeId(32): ScopeFlags(StrictMode | Constructor)
|
after transform: ScopeId(32): ScopeFlags(StrictMode)
|
||||||
rebuilt : ScopeId(24): ScopeFlags(StrictMode | Function)
|
rebuilt : ScopeId(24): ScopeFlags(StrictMode | Function)
|
||||||
Bindings mismatch:
|
Bindings mismatch:
|
||||||
after transform: ScopeId(34): ["C", "E"]
|
after transform: ScopeId(34): ["C", "E"]
|
||||||
|
|
@ -54785,7 +54785,7 @@ Bindings mismatch:
|
||||||
after transform: ScopeId(38): ["A", "B", "C", "E"]
|
after transform: ScopeId(38): ["A", "B", "C", "E"]
|
||||||
rebuilt : ScopeId(30): ["E"]
|
rebuilt : ScopeId(30): ["E"]
|
||||||
Scope flags mismatch:
|
Scope flags mismatch:
|
||||||
after transform: ScopeId(38): ScopeFlags(StrictMode | GetAccessor)
|
after transform: ScopeId(38): ScopeFlags(StrictMode)
|
||||||
rebuilt : ScopeId(30): ScopeFlags(StrictMode | Function)
|
rebuilt : ScopeId(30): ScopeFlags(StrictMode | Function)
|
||||||
Symbol flags mismatch for "E":
|
Symbol flags mismatch for "E":
|
||||||
after transform: SymbolId(1): SymbolFlags(RegularEnum)
|
after transform: SymbolId(1): SymbolFlags(RegularEnum)
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
commit: 54a8389f
|
commit: 54a8389f
|
||||||
|
|
||||||
Passed: 110/125
|
Passed: 111/125
|
||||||
|
|
||||||
# All Passed:
|
# All Passed:
|
||||||
* babel-plugin-transform-class-static-block
|
* babel-plugin-transform-class-static-block
|
||||||
|
|
@ -16,24 +16,7 @@ Passed: 110/125
|
||||||
* regexp
|
* regexp
|
||||||
|
|
||||||
|
|
||||||
# babel-plugin-transform-class-properties (11/14)
|
# babel-plugin-transform-class-properties (12/14)
|
||||||
* instance-prop-initializer-no-existing-constructor/input.js
|
|
||||||
Scope flags mismatch:
|
|
||||||
after transform: ScopeId(12): ScopeFlags(StrictMode)
|
|
||||||
rebuilt : ScopeId(13): ScopeFlags(StrictMode | Constructor)
|
|
||||||
Scope flags mismatch:
|
|
||||||
after transform: ScopeId(13): ScopeFlags(StrictMode)
|
|
||||||
rebuilt : ScopeId(14): ScopeFlags(StrictMode | Constructor)
|
|
||||||
Scope flags mismatch:
|
|
||||||
after transform: ScopeId(14): ScopeFlags(StrictMode)
|
|
||||||
rebuilt : ScopeId(15): ScopeFlags(StrictMode | Constructor)
|
|
||||||
Scope flags mismatch:
|
|
||||||
after transform: ScopeId(15): ScopeFlags(StrictMode)
|
|
||||||
rebuilt : ScopeId(16): ScopeFlags(StrictMode | Constructor)
|
|
||||||
Scope flags mismatch:
|
|
||||||
after transform: ScopeId(20): ScopeFlags(StrictMode)
|
|
||||||
rebuilt : ScopeId(21): ScopeFlags(StrictMode | Constructor)
|
|
||||||
|
|
||||||
* typescript/optional-call/input.ts
|
* typescript/optional-call/input.ts
|
||||||
Symbol reference IDs mismatch for "X":
|
Symbol reference IDs mismatch for "X":
|
||||||
after transform: SymbolId(0): [ReferenceId(0), ReferenceId(2), ReferenceId(6), ReferenceId(11), ReferenceId(16)]
|
after transform: SymbolId(0): [ReferenceId(0), ReferenceId(2), ReferenceId(6), ReferenceId(11), ReferenceId(16)]
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue