Invariances

The goal of SemanticDiff is to help you focus on the relevant changes. To achieve this, SemanticDiff tries to hide changes that do not affect the execution of the program. These invariances can be divided into two categories. The first category contains changes that do not modify the program on a syntactic level. This is usually defined by the grammar of the programming language and includes things like line breaks between parameters or optional commas. The second category contains changes that modify the code on a syntactic level but that do not change the semantics of a program. An example would be replacing for(;;) with while(1).

In the following sections we give an overview of the invariances supported by SemanticDiff. We will mainly focus on the second category (semantic equivalence).

C#

  • Adding/Removing unnecessary parenthesis
  • Changing the base of an integer literal
  • Escaping characters in strings

CSS

(Only syntactic equivalence)

Go

  • Adding/Removing unnecessary parenthesis
  • Changing the base of an integer literal
  • Escaping characters in strings
  • Reordering of type elements in a type term

HTML

  • Collapse whitespace according to CSS rules (based on default tag display type)
  • Ignore order of attributes in tags
  • Ignore order of classes in class attributes
  • Ignore order of values in rel attributes
  • Ignore value of boolean attributes
  • Treat tag and attribute names as case-insensitive
  • Treat HTML entities and their textual representation as invariant

Java

  • Adding/Removing unnecessary parenthesis
  • Changing the base of an integer literal
  • Escaping characters in strings

JavaScript / JSX

  • Adding/Removing unnecessary parenthesis
  • Changing the base of an integer literal
  • Escaping characters in strings
  • Reordering keys in an object declaration
  • Converting between an anonymous/arrow function
  • Ignore whitespace in JSX tags according to React’s whitespace handling rules
  • Collapse multiple whitespace characters in JSX tags to improve readability of diff
  • Treat HTML entities and their textual representation as invariant
  • Ignore JSX attribute order unless a spread operator is encountered

JSON5

  • Changing the base of an integer literal
  • Escaping characters in strings
  • Reordering of keys

Gettext .po

  • Escaping characters in strings
  • Reordering of messages

Python

  • Adding/Removing unnecessary parenthesis
  • Changing the base of an integer literal
  • Escaping characters in strings
  • Splitting / combining of strings
  • Reordering of keyword arguments

Rust

  • Adding/Removing unnecessary parenthesis
  • Changing the base of an integer literal
  • Escaping characters in a string/char
  • Exchanging the deprecated ... range operator with ..=

SCSS

(Only syntactic equivalence)

Swift

  • Adding/Removing whitespaces or line breaks outside of strings and comments
  • Adding/Removing optional commas
  • Adding/Removing unnecessary parenthesis
  • Exchanging numeric literals with equivalent ones in different bases
  • Exchanging escaped characters in a string/char with an equivalent representation (e.g. the literal)

TypeScript / TSX

  • Adding/Removing unnecessary parenthesis
  • Changing the base of an integer literal
  • Escaping characters in strings
  • Reordering keys in an object declaration
  • Converting between an anonymous/arrow function
  • Ignore whitespace in TSX tags according to React’s whitespace handling rules
  • Collapse multiple whitespace characters in TSX tags to improve readability of diff
  • Treat HTML entities and their textual representation as invariant
  • Ignore TSX attribute order unless a spread operator is encountered

Vue SFC

  • Ignore order of classes in class attributes
  • Ignore order of values in rel attributes
  • Treat HTML entities and their textual representation as invariant
  • Ignore order of attributes in tags unless a v-bind is encountered
  • Treat tag and attribute names as case-insensitive
  • Collapse whitespace according to CSS rules while evaluating all possible states of conditional directives (e.g. v-if)