refactor: 用域隔离宏重构结构哈希标签
This commit is contained in:
@@ -1,6 +1,27 @@
|
|||||||
use oxide_parser::{
|
use oxide_parser::{
|
||||||
ClassElement, Expression, ForStatementInit, ObjectPropertyKind, PropertyKey, SimpleAssignmentTarget, Statement,
|
ClassElement, Expression, ForStatementInit, ObjectPropertyKind, PropertyKey, SimpleAssignmentTarget, Statement,
|
||||||
};
|
};
|
||||||
|
use std::hash::Hash;
|
||||||
|
|
||||||
|
#[derive(Hash)]
|
||||||
|
enum HashDomain {
|
||||||
|
Statement,
|
||||||
|
Expression,
|
||||||
|
ClassElement,
|
||||||
|
PropertyKey,
|
||||||
|
ObjectPropertyKind,
|
||||||
|
SimpleAssignmentTarget,
|
||||||
|
}
|
||||||
|
|
||||||
|
macro_rules! hash_match {
|
||||||
|
($domain:expr, $value:expr, $h:expr, { $($arms:tt)* }) => {{
|
||||||
|
$domain.hash($h);
|
||||||
|
std::mem::discriminant($value).hash($h);
|
||||||
|
match $value {
|
||||||
|
$($arms)*
|
||||||
|
}
|
||||||
|
}};
|
||||||
|
}
|
||||||
|
|
||||||
pub fn structural_hash(program: &oxide_parser::Program) -> u64 {
|
pub fn structural_hash(program: &oxide_parser::Program) -> u64 {
|
||||||
use std::hash::Hasher;
|
use std::hash::Hasher;
|
||||||
@@ -15,11 +36,8 @@ pub fn structural_hash(program: &oxide_parser::Program) -> u64 {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn hash_statement(stmt: &Statement, h: &mut rustc_hash::FxHasher) {
|
fn hash_statement(stmt: &Statement, h: &mut rustc_hash::FxHasher) {
|
||||||
use std::hash::Hash;
|
hash_match!(HashDomain::Statement, stmt, h, {
|
||||||
|
|
||||||
match stmt {
|
|
||||||
Statement::ExpressionStatement(es) => {
|
Statement::ExpressionStatement(es) => {
|
||||||
0u8.hash(h);
|
|
||||||
hash_expression(&es.expression, h);
|
hash_expression(&es.expression, h);
|
||||||
}
|
}
|
||||||
Statement::VariableDeclaration(decl) => {
|
Statement::VariableDeclaration(decl) => {
|
||||||
@@ -32,13 +50,11 @@ fn hash_statement(stmt: &Statement, h: &mut rustc_hash::FxHasher) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
Statement::ReturnStatement(ret) => {
|
Statement::ReturnStatement(ret) => {
|
||||||
2u8.hash(h);
|
|
||||||
if let Some(arg) = &ret.argument {
|
if let Some(arg) = &ret.argument {
|
||||||
hash_expression(arg, h);
|
hash_expression(arg, h);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Statement::IfStatement(ifs) => {
|
Statement::IfStatement(ifs) => {
|
||||||
3u8.hash(h);
|
|
||||||
hash_expression(&ifs.test, h);
|
hash_expression(&ifs.test, h);
|
||||||
hash_statement(&ifs.consequent, h);
|
hash_statement(&ifs.consequent, h);
|
||||||
if let Some(alt) = &ifs.alternate {
|
if let Some(alt) = &ifs.alternate {
|
||||||
@@ -46,12 +62,10 @@ fn hash_statement(stmt: &Statement, h: &mut rustc_hash::FxHasher) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
Statement::WhileStatement(wh) => {
|
Statement::WhileStatement(wh) => {
|
||||||
4u8.hash(h);
|
|
||||||
hash_expression(&wh.test, h);
|
hash_expression(&wh.test, h);
|
||||||
hash_statement(&wh.body, h);
|
hash_statement(&wh.body, h);
|
||||||
}
|
}
|
||||||
Statement::ForStatement(fr) => {
|
Statement::ForStatement(fr) => {
|
||||||
5u8.hash(h);
|
|
||||||
if let Some(init) = &fr.init {
|
if let Some(init) = &fr.init {
|
||||||
if let Some(expr) = init.as_expression() {
|
if let Some(expr) = init.as_expression() {
|
||||||
hash_expression(expr, h);
|
hash_expression(expr, h);
|
||||||
@@ -74,29 +88,21 @@ fn hash_statement(stmt: &Statement, h: &mut rustc_hash::FxHasher) {
|
|||||||
hash_statement(&fr.body, h);
|
hash_statement(&fr.body, h);
|
||||||
}
|
}
|
||||||
Statement::BlockStatement(block) => {
|
Statement::BlockStatement(block) => {
|
||||||
6u8.hash(h);
|
|
||||||
for s in &block.body {
|
for s in &block.body {
|
||||||
hash_statement(s, h);
|
hash_statement(s, h);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Statement::BreakStatement(_) => {
|
Statement::BreakStatement(_) => {}
|
||||||
7u8.hash(h);
|
Statement::ContinueStatement(_) => {}
|
||||||
}
|
|
||||||
Statement::ContinueStatement(_) => {
|
|
||||||
8u8.hash(h);
|
|
||||||
}
|
|
||||||
Statement::DoWhileStatement(dw) => {
|
Statement::DoWhileStatement(dw) => {
|
||||||
9u8.hash(h);
|
|
||||||
hash_statement(&dw.body, h);
|
hash_statement(&dw.body, h);
|
||||||
hash_expression(&dw.test, h);
|
hash_expression(&dw.test, h);
|
||||||
}
|
}
|
||||||
Statement::ForInStatement(fi) => {
|
Statement::ForInStatement(fi) => {
|
||||||
10u8.hash(h);
|
|
||||||
hash_expression(&fi.right, h);
|
hash_expression(&fi.right, h);
|
||||||
hash_statement(&fi.body, h);
|
hash_statement(&fi.body, h);
|
||||||
}
|
}
|
||||||
Statement::SwitchStatement(sw) => {
|
Statement::SwitchStatement(sw) => {
|
||||||
11u8.hash(h);
|
|
||||||
hash_expression(&sw.discriminant, h);
|
hash_expression(&sw.discriminant, h);
|
||||||
for case in &sw.cases {
|
for case in &sw.cases {
|
||||||
if let Some(test) = &case.test {
|
if let Some(test) = &case.test {
|
||||||
@@ -108,7 +114,6 @@ fn hash_statement(stmt: &Statement, h: &mut rustc_hash::FxHasher) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
Statement::FunctionDeclaration(fd) => {
|
Statement::FunctionDeclaration(fd) => {
|
||||||
12u8.hash(h);
|
|
||||||
if let Some(id) = &fd.id {
|
if let Some(id) = &fd.id {
|
||||||
id.name.as_str().hash(h);
|
id.name.as_str().hash(h);
|
||||||
}
|
}
|
||||||
@@ -120,7 +125,6 @@ fn hash_statement(stmt: &Statement, h: &mut rustc_hash::FxHasher) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
Statement::ClassDeclaration(class) => {
|
Statement::ClassDeclaration(class) => {
|
||||||
13u8.hash(h);
|
|
||||||
if let Some(id) = &class.id {
|
if let Some(id) = &class.id {
|
||||||
id.name.as_str().hash(h);
|
id.name.as_str().hash(h);
|
||||||
}
|
}
|
||||||
@@ -133,11 +137,9 @@ fn hash_statement(stmt: &Statement, h: &mut rustc_hash::FxHasher) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
Statement::ThrowStatement(ts) => {
|
Statement::ThrowStatement(ts) => {
|
||||||
14u8.hash(h);
|
|
||||||
hash_expression(&ts.argument, h);
|
hash_expression(&ts.argument, h);
|
||||||
}
|
}
|
||||||
Statement::TryStatement(ts) => {
|
Statement::TryStatement(ts) => {
|
||||||
34u8.hash(h);
|
|
||||||
for s in &ts.block.body {
|
for s in &ts.block.body {
|
||||||
hash_statement(s, h);
|
hash_statement(s, h);
|
||||||
}
|
}
|
||||||
@@ -157,41 +159,28 @@ fn hash_statement(stmt: &Statement, h: &mut rustc_hash::FxHasher) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
_ => {
|
_ => {}
|
||||||
std::mem::discriminant(stmt).hash(h);
|
});
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn hash_property_key(key: &PropertyKey, h: &mut rustc_hash::FxHasher) {
|
fn hash_property_key(key: &PropertyKey, h: &mut rustc_hash::FxHasher) {
|
||||||
use std::hash::Hash;
|
hash_match!(HashDomain::PropertyKey, key, h, {
|
||||||
|
|
||||||
match key {
|
|
||||||
PropertyKey::StaticIdentifier(ident) => {
|
PropertyKey::StaticIdentifier(ident) => {
|
||||||
0u8.hash(h);
|
|
||||||
ident.name.as_str().hash(h);
|
ident.name.as_str().hash(h);
|
||||||
}
|
}
|
||||||
PropertyKey::StringLiteral(s) => {
|
PropertyKey::StringLiteral(s) => {
|
||||||
1u8.hash(h);
|
|
||||||
s.value.hash(h);
|
s.value.hash(h);
|
||||||
}
|
}
|
||||||
PropertyKey::PrivateIdentifier(pi) => {
|
PropertyKey::PrivateIdentifier(pi) => {
|
||||||
2u8.hash(h);
|
|
||||||
pi.name.as_str().hash(h);
|
pi.name.as_str().hash(h);
|
||||||
}
|
}
|
||||||
_ => {
|
_ => {}
|
||||||
3u8.hash(h);
|
});
|
||||||
std::mem::discriminant(key).hash(h);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn hash_class_element(element: &ClassElement, h: &mut rustc_hash::FxHasher) {
|
fn hash_class_element(element: &ClassElement, h: &mut rustc_hash::FxHasher) {
|
||||||
use std::hash::Hash;
|
hash_match!(HashDomain::ClassElement, element, h, {
|
||||||
|
|
||||||
match element {
|
|
||||||
ClassElement::MethodDefinition(method) => {
|
ClassElement::MethodDefinition(method) => {
|
||||||
0u8.hash(h);
|
|
||||||
method.r#static.hash(h);
|
method.r#static.hash(h);
|
||||||
method.computed.hash(h);
|
method.computed.hash(h);
|
||||||
std::mem::discriminant(&method.kind).hash(h);
|
std::mem::discriminant(&method.kind).hash(h);
|
||||||
@@ -203,30 +192,22 @@ fn hash_class_element(element: &ClassElement, h: &mut rustc_hash::FxHasher) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
_ => {
|
_ => {}
|
||||||
1u8.hash(h);
|
});
|
||||||
std::mem::discriminant(element).hash(h);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn hash_expression(expr: &Expression, h: &mut rustc_hash::FxHasher) {
|
fn hash_expression(expr: &Expression, h: &mut rustc_hash::FxHasher) {
|
||||||
use std::hash::Hash;
|
hash_match!(HashDomain::Expression, expr, h, {
|
||||||
|
|
||||||
match expr {
|
|
||||||
Expression::BinaryExpression(bin) => {
|
Expression::BinaryExpression(bin) => {
|
||||||
0u8.hash(h);
|
|
||||||
std::mem::discriminant(&bin.operator).hash(h);
|
std::mem::discriminant(&bin.operator).hash(h);
|
||||||
hash_expression(&bin.left, h);
|
hash_expression(&bin.left, h);
|
||||||
hash_expression(&bin.right, h);
|
hash_expression(&bin.right, h);
|
||||||
}
|
}
|
||||||
Expression::UnaryExpression(un) => {
|
Expression::UnaryExpression(un) => {
|
||||||
1u8.hash(h);
|
|
||||||
std::mem::discriminant(&un.operator).hash(h);
|
std::mem::discriminant(&un.operator).hash(h);
|
||||||
hash_expression(&un.argument, h);
|
hash_expression(&un.argument, h);
|
||||||
}
|
}
|
||||||
Expression::CallExpression(call) => {
|
Expression::CallExpression(call) => {
|
||||||
2u8.hash(h);
|
|
||||||
(call.arguments.len() as u32).hash(h);
|
(call.arguments.len() as u32).hash(h);
|
||||||
hash_expression(&call.callee, h);
|
hash_expression(&call.callee, h);
|
||||||
for arg in &call.arguments {
|
for arg in &call.arguments {
|
||||||
@@ -236,66 +217,41 @@ fn hash_expression(expr: &Expression, h: &mut rustc_hash::FxHasher) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
Expression::LogicalExpression(log) => {
|
Expression::LogicalExpression(log) => {
|
||||||
3u8.hash(h);
|
|
||||||
std::mem::discriminant(&log.operator).hash(h);
|
std::mem::discriminant(&log.operator).hash(h);
|
||||||
hash_expression(&log.left, h);
|
hash_expression(&log.left, h);
|
||||||
hash_expression(&log.right, h);
|
hash_expression(&log.right, h);
|
||||||
}
|
}
|
||||||
Expression::ConditionalExpression(cond) => {
|
Expression::ConditionalExpression(cond) => {
|
||||||
4u8.hash(h);
|
|
||||||
hash_expression(&cond.test, h);
|
hash_expression(&cond.test, h);
|
||||||
hash_expression(&cond.consequent, h);
|
hash_expression(&cond.consequent, h);
|
||||||
hash_expression(&cond.alternate, h);
|
hash_expression(&cond.alternate, h);
|
||||||
}
|
}
|
||||||
Expression::Identifier(_) => {
|
Expression::Identifier(_) => {}
|
||||||
5u8.hash(h);
|
|
||||||
}
|
|
||||||
Expression::NumericLiteral(num) => {
|
Expression::NumericLiteral(num) => {
|
||||||
6u8.hash(h);
|
|
||||||
num.value.to_bits().hash(h);
|
num.value.to_bits().hash(h);
|
||||||
}
|
}
|
||||||
Expression::StringLiteral(s) => {
|
Expression::StringLiteral(s) => {
|
||||||
7u8.hash(h);
|
|
||||||
s.value.hash(h);
|
s.value.hash(h);
|
||||||
}
|
}
|
||||||
Expression::BooleanLiteral(b) => {
|
Expression::BooleanLiteral(b) => {
|
||||||
8u8.hash(h);
|
|
||||||
b.value.hash(h);
|
b.value.hash(h);
|
||||||
}
|
}
|
||||||
Expression::AssignmentExpression(assign) => {
|
Expression::AssignmentExpression(assign) => {
|
||||||
11u8.hash(h);
|
|
||||||
std::mem::discriminant(&assign.operator).hash(h);
|
std::mem::discriminant(&assign.operator).hash(h);
|
||||||
hash_expression(&assign.right, h);
|
hash_expression(&assign.right, h);
|
||||||
}
|
}
|
||||||
Expression::UpdateExpression(update) => {
|
Expression::UpdateExpression(update) => {
|
||||||
12u8.hash(h);
|
|
||||||
std::mem::discriminant(&update.operator).hash(h);
|
std::mem::discriminant(&update.operator).hash(h);
|
||||||
update.prefix.hash(h);
|
update.prefix.hash(h);
|
||||||
match &update.argument {
|
hash_simple_assignment_target(&update.argument, h);
|
||||||
SimpleAssignmentTarget::AssignmentTargetIdentifier(_) => {
|
|
||||||
0u8.hash(h);
|
|
||||||
}
|
|
||||||
SimpleAssignmentTarget::StaticMemberExpression(member) => {
|
|
||||||
1u8.hash(h);
|
|
||||||
hash_expression(&member.object, h);
|
|
||||||
}
|
|
||||||
SimpleAssignmentTarget::ComputedMemberExpression(member) => {
|
|
||||||
2u8.hash(h);
|
|
||||||
hash_expression(&member.object, h);
|
|
||||||
hash_expression(&member.expression, h);
|
|
||||||
}
|
|
||||||
_ => {}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
Expression::TemplateLiteral(tl) => {
|
Expression::TemplateLiteral(tl) => {
|
||||||
16u8.hash(h);
|
|
||||||
(tl.quasis.len() as u32).hash(h);
|
(tl.quasis.len() as u32).hash(h);
|
||||||
for expr in &tl.expressions {
|
for expr in &tl.expressions {
|
||||||
hash_expression(expr, h);
|
hash_expression(expr, h);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Expression::TaggedTemplateExpression(tt) => {
|
Expression::TaggedTemplateExpression(tt) => {
|
||||||
17u8.hash(h);
|
|
||||||
hash_expression(&tt.tag, h);
|
hash_expression(&tt.tag, h);
|
||||||
(tt.quasi.quasis.len() as u32).hash(h);
|
(tt.quasi.quasis.len() as u32).hash(h);
|
||||||
for expr in &tt.quasi.expressions {
|
for expr in &tt.quasi.expressions {
|
||||||
@@ -303,14 +259,12 @@ fn hash_expression(expr: &Expression, h: &mut rustc_hash::FxHasher) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
Expression::ArrowFunctionExpression(arrow) => {
|
Expression::ArrowFunctionExpression(arrow) => {
|
||||||
15u8.hash(h);
|
|
||||||
(arrow.params.items.len() as u32).hash(h);
|
(arrow.params.items.len() as u32).hash(h);
|
||||||
for s in &arrow.body.statements {
|
for s in &arrow.body.statements {
|
||||||
hash_statement(s, h);
|
hash_statement(s, h);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Expression::FunctionExpression(fe) => {
|
Expression::FunctionExpression(fe) => {
|
||||||
13u8.hash(h);
|
|
||||||
(fe.params.items.len() as u32).hash(h);
|
(fe.params.items.len() as u32).hash(h);
|
||||||
if let Some(body) = &fe.body {
|
if let Some(body) = &fe.body {
|
||||||
for s in &body.statements {
|
for s in &body.statements {
|
||||||
@@ -319,7 +273,6 @@ fn hash_expression(expr: &Expression, h: &mut rustc_hash::FxHasher) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
Expression::ClassExpression(class) => {
|
Expression::ClassExpression(class) => {
|
||||||
18u8.hash(h);
|
|
||||||
if let Some(id) = &class.id {
|
if let Some(id) = &class.id {
|
||||||
id.name.as_str().hash(h);
|
id.name.as_str().hash(h);
|
||||||
}
|
}
|
||||||
@@ -332,26 +285,12 @@ fn hash_expression(expr: &Expression, h: &mut rustc_hash::FxHasher) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
Expression::ObjectExpression(obj) => {
|
Expression::ObjectExpression(obj) => {
|
||||||
20u8.hash(h);
|
|
||||||
(obj.properties.len() as u32).hash(h);
|
(obj.properties.len() as u32).hash(h);
|
||||||
for prop in &obj.properties {
|
for prop in &obj.properties {
|
||||||
match prop {
|
hash_object_property_kind(prop, h);
|
||||||
ObjectPropertyKind::ObjectProperty(p) => {
|
|
||||||
0u8.hash(h);
|
|
||||||
std::mem::discriminant(&p.kind).hash(h);
|
|
||||||
p.method.hash(h);
|
|
||||||
p.computed.hash(h);
|
|
||||||
hash_property_key(&p.key, h);
|
|
||||||
hash_expression(&p.value, h);
|
|
||||||
}
|
|
||||||
ObjectPropertyKind::SpreadProperty(_) => {
|
|
||||||
1u8.hash(h);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Expression::NewExpression(ne) => {
|
Expression::NewExpression(ne) => {
|
||||||
14u8.hash(h);
|
|
||||||
hash_expression(&ne.callee, h);
|
hash_expression(&ne.callee, h);
|
||||||
(ne.arguments.len() as u32).hash(h);
|
(ne.arguments.len() as u32).hash(h);
|
||||||
for arg in &ne.arguments {
|
for arg in &ne.arguments {
|
||||||
@@ -360,17 +299,39 @@ fn hash_expression(expr: &Expression, h: &mut rustc_hash::FxHasher) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Expression::Super(_) => {
|
Expression::Super(_) => {}
|
||||||
19u8.hash(h);
|
|
||||||
}
|
|
||||||
Expression::RegExpLiteral(lit) => {
|
Expression::RegExpLiteral(lit) => {
|
||||||
if let Some(raw) = &lit.raw {
|
if let Some(raw) = &lit.raw {
|
||||||
raw.to_string().hash(h);
|
raw.to_string().hash(h);
|
||||||
}
|
}
|
||||||
std::mem::discriminant(expr).hash(h);
|
|
||||||
}
|
}
|
||||||
_ => {
|
_ => {}
|
||||||
std::mem::discriminant(expr).hash(h);
|
});
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
fn hash_object_property_kind(prop: &ObjectPropertyKind, h: &mut rustc_hash::FxHasher) {
|
||||||
|
hash_match!(HashDomain::ObjectPropertyKind, prop, h, {
|
||||||
|
ObjectPropertyKind::ObjectProperty(p) => {
|
||||||
|
std::mem::discriminant(&p.kind).hash(h);
|
||||||
|
p.method.hash(h);
|
||||||
|
p.computed.hash(h);
|
||||||
|
hash_property_key(&p.key, h);
|
||||||
|
hash_expression(&p.value, h);
|
||||||
|
}
|
||||||
|
ObjectPropertyKind::SpreadProperty(_) => {}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
fn hash_simple_assignment_target(target: &SimpleAssignmentTarget, h: &mut rustc_hash::FxHasher) {
|
||||||
|
hash_match!(HashDomain::SimpleAssignmentTarget, target, h, {
|
||||||
|
SimpleAssignmentTarget::AssignmentTargetIdentifier(_) => {}
|
||||||
|
SimpleAssignmentTarget::StaticMemberExpression(member) => {
|
||||||
|
hash_expression(&member.object, h);
|
||||||
|
}
|
||||||
|
SimpleAssignmentTarget::ComputedMemberExpression(member) => {
|
||||||
|
hash_expression(&member.object, h);
|
||||||
|
hash_expression(&member.expression, h);
|
||||||
|
}
|
||||||
|
_ => {}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -36,6 +36,13 @@ fn structural_hash_same_shape() {
|
|||||||
assert_eq!(hash_a, hash_b);
|
assert_eq!(hash_a, hash_b);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn structural_hash_identifier_renaming_remains_normalized() {
|
||||||
|
let hash_a = parse_to_hash("var left = 1; left + left");
|
||||||
|
let hash_b = parse_to_hash("var right = 1; right + right");
|
||||||
|
assert_eq!(hash_a, hash_b);
|
||||||
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn structural_hash_different_init_values() {
|
fn structural_hash_different_init_values() {
|
||||||
let hash_a = parse_to_hash("var x = 1 + 2;");
|
let hash_a = parse_to_hash("var x = 1 + 2;");
|
||||||
@@ -88,3 +95,25 @@ fn hash_compound_vs_simple_assign() {
|
|||||||
let hash_b = parse_to_hash("x+=1");
|
let hash_b = parse_to_hash("x+=1");
|
||||||
assert_ne!(hash_a, hash_b, "x=1 and x+=1 must produce different hashes");
|
assert_ne!(hash_a, hash_b, "x=1 and x+=1 must produce different hashes");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn object_literal_data_get_set_shapes_differ() {
|
||||||
|
let data = parse_to_hash("var o = { x: 1 };");
|
||||||
|
let getter = parse_to_hash("var o = { get x() { return 1; } };");
|
||||||
|
let setter = parse_to_hash("var o = { set x(v) { this.y = v; } };");
|
||||||
|
|
||||||
|
assert_ne!(data, getter, "data and getter properties must hash differently");
|
||||||
|
assert_ne!(data, setter, "data and setter properties must hash differently");
|
||||||
|
assert_ne!(getter, setter, "getter and setter properties must hash differently");
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn class_method_getter_static_setter_shapes_differ() {
|
||||||
|
let method = parse_to_hash("class A { x() { return 1; } }");
|
||||||
|
let getter = parse_to_hash("class A { get x() { return 1; } }");
|
||||||
|
let static_setter = parse_to_hash("class A { static set x(v) { this.y = v; } }");
|
||||||
|
|
||||||
|
assert_ne!(method, getter, "method and getter must hash differently");
|
||||||
|
assert_ne!(method, static_setter, "method and static setter must hash differently");
|
||||||
|
assert_ne!(getter, static_setter, "getter and static setter must hash differently");
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user