-
Notifications
You must be signed in to change notification settings - Fork 15
Closed
Labels
Description
Motivation
The v
flags adds class intersection and subtraction as new features. They are simple set operations but they also make it possible to have completely useless elements.
Description
Report useless elements in class intersections and subtractions.
Examples
/* ✗ BAD */
var foo = /[\w&&\d]/v // => /[\d]/v
// \d is a subset of \w, so remove the intersection.
var foo = /[\w&&\s]/v // => /[]/v
// \w and \s are disjoint, so the intersection will be empty.
var foo = /[\w&&[\d\s]]/v // => /[\w&&[\d]]/v
// \s in [\d\s] and \w are disjoint, so \s can be removed.
// Proof: [\w&&[\d\s]] == [[\w&&[\d]][\w&&\s]] == [[\w&&[\d]][]] == [\w&&[\d]]
var foo = /[\w&&[^\d\s]]/v // => /[\w&&[^\d]]/v
// \s in [^\d\s] and \w are disjoint, so \s can be removed.
// Proof: [\w&&[^\d\s]] == [\w&&[[^\d]&&[^\s]]] == [\w&&[[^\s]&&[^\d]]] == [[\w&&[^\s]]&&[^\d]] == [[\w]&&[^\d]]
var foo = /[\w--\s]/v // => /[\w]/v
// \w and \s are disjoint, so the subtraction is useless.
var foo = /[\d--\w]/v // => /[]/v
// \d is a subset of \w, so the subtraction will be empty.
var foo = /[\w--[\d\s]]/v // => /[\w--[\d]]/v
// \s in [\d\s] and \w are disjoint, so \s can be removed.
// Proof: [\w--[\d\s]] == [[\w--\s]--[\d]] == [\w--[\d]]
var foo = /[\w--[^\d\s]]/v // => /[\w--[^\d]]/v
// \s in [^\d\s] and \w are disjoint, so \s can be removed.
// Proof: [\w--[^\d\s]] == [\w--[[^\d]&&[^\s]] == [[\w--[^\d]][\w--[^\s]]] == [[\w--[^\d]][]] == [\w--[^\d]]
ota-meshi