fix(es/minifier): Fix for @emotion/react and murmur2 (#2637)

swc_ecma_minifier:
 - Check for the operator while folding binary assignments. 
 - `sequences`: More check before inlining into operator assignments.
This commit is contained in:
Donny/강동윤 2021-11-03 22:46:25 +09:00 committed by GitHub
parent a973b0bed4
commit 808d57822b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
20 changed files with 5002 additions and 34 deletions

View File

@ -332,6 +332,10 @@ where
/// `a = a + 1` => `a += 1`.
fn compress_bin_assignment_to_left(&mut self, e: &mut AssignExpr) {
if e.op != op!("=") {
return;
}
// TODO: Handle pure properties.
let lhs = match &e.left {
PatOrExpr::Expr(e) => match &**e {

View File

@ -14,7 +14,9 @@ use std::mem::take;
use swc_atoms::js_word;
use swc_common::{util::take::Take, Spanned, DUMMY_SP};
use swc_ecma_ast::*;
use swc_ecma_utils::{contains_this_expr, ident::IdentLike, undefined, ExprExt, Id, StmtLike};
use swc_ecma_utils::{
contains_this_expr, ident::IdentLike, undefined, ExprExt, Id, StmtLike, UsageFinder,
};
use swc_ecma_visit::{noop_visit_type, Node, Visit, VisitWith};
use tracing::{span, Level};
@ -207,7 +209,7 @@ where
match &mut stmt.init {
Some(VarDeclOrExpr::Expr(e)) => {
if exprs.iter().all(|expr| match &**expr {
Expr::Assign(..) => true,
Expr::Assign(AssignExpr { op: op!("="), .. }) => true,
_ => false,
}) {
let ids_used_by_exprs =
@ -363,7 +365,7 @@ where
Expr::Seq(seq) => {
seq.exprs.len() > 1
&& seq.exprs.iter().all(|expr| match &**expr {
Expr::Assign(..) => true,
Expr::Assign(AssignExpr { op: op!("="), .. }) => true,
_ => false,
})
}
@ -387,7 +389,7 @@ where
Expr::Seq(seq) => {
seq.exprs.len() > 1
&& seq.exprs.iter().all(|expr| match &**expr {
Expr::Assign(..) => true,
Expr::Assign(AssignExpr { op: op!("="), .. }) => true,
_ => false,
})
}
@ -1068,24 +1070,14 @@ where
}
Expr::Assign(b) => {
match &mut b.left {
PatOrExpr::Expr(b) => match &**b {
Expr::Ident(..) => {}
let b_left = get_lhs_ident(&b.left);
let b_left = match b_left {
Some(v) => v.clone(),
None => return Ok(false),
};
_ => {
return Ok(false);
}
},
PatOrExpr::Pat(b) => match &mut **b {
Pat::Expr(b) => match &**b {
Expr::Ident(..) => {}
_ => {
return Ok(false);
}
},
Pat::Ident(..) => {}
_ => return Ok(false),
},
if UsageFinder::find(&b_left, &b.right) {
return Err(());
}
tracing::trace!("seq: Try rhs of assign with op");

View File

@ -21,7 +21,7 @@ where
&*seq.exprs[seq.exprs.len() - 2],
&*seq.exprs[seq.exprs.len() - 1],
) {
(Expr::Assign(assign), Expr::Ident(ident)) => {
(Expr::Assign(assign @ AssignExpr { op: op!("="), .. }), Expr::Ident(ident)) => {
// Check if lhs is same as `ident`.
match &assign.left {
PatOrExpr::Expr(_) => {}
@ -90,7 +90,7 @@ where
}
let assign = match e {
Expr::Assign(v) => v,
Expr::Assign(v @ AssignExpr { op: op!("="), .. }) => v,
_ => return,
};
@ -156,7 +156,7 @@ where
match (&mut *a, &mut *b) {
(
Expr::Assign(a_assign),
Expr::Assign(a_assign @ AssignExpr { op: op!("="), .. }),
Expr::Call(CallExpr {
callee: ExprOrSuper::Expr(b_callee),
args,

View File

@ -4840,7 +4840,7 @@
for(i = 0; i < input.length; i++)(currentValue = input[i]) >= n && currentValue < m && (m = currentValue);
var handledCPCountPlusOne = handledCPCount + 1;
if (m - n > floor((2147483647 - delta) / handledCPCountPlusOne)) throw RangeError("Overflow: input needs wider integers to process");
for(i = 0, delta += (m - n) * handledCPCountPlusOne, n = m; i < input.length; i++){
for(delta += (m - n) * handledCPCountPlusOne, n = m, i = 0; i < input.length; i++){
if ((currentValue = input[i]) < n && ++delta > 2147483647) throw RangeError("Overflow: input needs wider integers to process");
if (currentValue == n) {
for(var q = delta, k = base;; k += base){

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,346 @@
/* harmony default export */
var emotion_memoize_browser_esm = (memoize);
var hyphenateRegex = /[A-Z]|^ms/g;
var animationRegex = /_EMO_([^_]+?)_([^]*?)_EMO_/g;
var unitlessKeys = {
animationIterationCount: 1,
borderImageOutset: 1,
borderImageSlice: 1,
borderImageWidth: 1,
boxFlex: 1,
boxFlexGroup: 1,
boxOrdinalGroup: 1,
columnCount: 1,
columns: 1,
flex: 1,
flexGrow: 1,
flexPositive: 1,
flexShrink: 1,
flexNegative: 1,
flexOrder: 1,
gridRow: 1,
gridRowEnd: 1,
gridRowSpan: 1,
gridRowStart: 1,
gridColumn: 1,
gridColumnEnd: 1,
gridColumnSpan: 1,
gridColumnStart: 1,
msGridRow: 1,
msGridRowSpan: 1,
msGridColumn: 1,
msGridColumnSpan: 1,
fontWeight: 1,
lineHeight: 1,
opacity: 1,
order: 1,
orphans: 1,
tabSize: 1,
widows: 1,
zIndex: 1,
zoom: 1,
WebkitLineClamp: 1,
// SVG-related properties
fillOpacity: 1,
floodOpacity: 1,
stopOpacity: 1,
strokeDasharray: 1,
strokeDashoffset: 1,
strokeMiterlimit: 1,
strokeOpacity: 1,
strokeWidth: 1
};
var unitless_browser_esm = (unitlessKeys);
var isCustomProperty = function isCustomProperty(property) {
return property.charCodeAt(1) === 45;
};
var labelPattern = /label:\s*([^\s;\n{]+)\s*(;|$)/g;
var cursor;
var hash_browser_esm = (murmur2);
function handleInterpolation(mergedProps, registered, interpolation) {
if (interpolation == null) {
return '';
}
if (interpolation.__emotion_styles !== undefined) {
if (false) { }
return interpolation;
}
switch (typeof interpolation) {
case 'boolean': {
return '';
}
case 'object': {
if (interpolation.anim === 1) {
cursor = {
name: interpolation.name,
styles: interpolation.styles,
next: cursor
};
return interpolation.name;
}
if (interpolation.styles !== undefined) {
var next = interpolation.next;
if (next !== undefined) {
// not the most efficient thing ever but this is a pretty rare case
// and there will be very few iterations of this generally
while (next !== undefined) {
cursor = {
name: next.name,
styles: next.styles,
next: cursor
};
next = next.next;
}
}
var styles = interpolation.styles + ";";
if (false) { }
return styles;
}
return createStringFromObject(mergedProps, registered, interpolation);
}
case 'function': {
if (mergedProps !== undefined) {
var previousCursor = cursor;
var result = interpolation(mergedProps);
cursor = previousCursor;
return handleInterpolation(mergedProps, registered, result);
} else if (false) { }
break;
}
case 'string':
if (false) {
var replaced, matched;
}
break;
} // finalize string values (regular strings and functions interpolated into css calls)
if (registered == null) {
return interpolation;
}
var cached = registered[interpolation];
return cached !== undefined ? cached : interpolation;
}
export function serializeStyles(args, registered, mergedProps) {
if (args.length === 1 && typeof args[0] === 'object' && args[0] !== null && args[0].styles !== undefined) {
return args[0];
}
var stringMode = true;
var styles = '';
cursor = undefined;
var strings = args[0];
if (strings == null || strings.raw === undefined) {
stringMode = false;
styles += handleInterpolation(mergedProps, registered, strings);
} else {
if (false) { }
styles += strings[0];
} // we start at 1 since we've already handled the first arg
for (var i = 1; i < args.length; i++) {
styles += handleInterpolation(mergedProps, registered, args[i]);
if (stringMode) {
if (false) { }
styles += strings[i];
}
}
var sourceMap;
if (false) { } // using a global regex with .exec is stateful so lastIndex has to be reset each time
labelPattern.lastIndex = 0;
var identifierName = '';
var match; // https://esbench.com/bench/5b809c2cf2949800a0f61fb5
while ((match = labelPattern.exec(styles)) !== null) {
identifierName += '-' + // $FlowFixMe we know it's not null
match[1];
}
var name = hash_browser_esm(styles) + identifierName;
if (false) { }
return {
name: name,
styles: styles,
next: cursor
};
}
function createStringFromObject(mergedProps, registered, obj) {
var string = '';
if (Array.isArray(obj)) {
for (var i = 0; i < obj.length; i++) {
string += handleInterpolation(mergedProps, registered, obj[i]) + ";";
}
} else {
for (var _key in obj) {
var value = obj[_key];
if (typeof value !== 'object') {
if (registered != null && registered[value] !== undefined) {
string += _key + "{" + registered[value] + "}";
} else if (isProcessableValue(value)) {
string += processStyleName(_key) + ":" + processStyleValue(_key, value) + ";";
}
} else {
if (_key === 'NO_COMPONENT_SELECTOR' && "production" !== 'production') { }
if (Array.isArray(value) && typeof value[0] === 'string' && (registered == null || registered[value[0]] === undefined)) {
for (var _i = 0; _i < value.length; _i++) {
if (isProcessableValue(value[_i])) {
string += processStyleName(_key) + ":" + processStyleValue(_key, value[_i]) + ";";
}
}
} else {
var interpolated = handleInterpolation(mergedProps, registered, value);
switch (_key) {
case 'animation':
case 'animationName': {
string += processStyleName(_key) + ":" + interpolated + ";";
break;
}
default: {
if (false) { }
string += _key + "{" + interpolated + "}";
}
}
}
}
}
}
return string;
}
function murmur2(str) {
// 'm' and 'r' are mixing constants generated offline.
// They're not really 'magic', they just happen to work well.
// const m = 0x5bd1e995;
// const r = 24;
// Initialize the hash
var h = 0; // Mix 4 bytes at a time into the hash
var k,
i = 0,
len = str.length;
for (; len >= 4; ++i, len -= 4) {
k = str.charCodeAt(i) & 0xff | (str.charCodeAt(++i) & 0xff) << 8 | (str.charCodeAt(++i) & 0xff) << 16 | (str.charCodeAt(++i) & 0xff) << 24;
k =
/* Math.imul(k, m): */
(k & 0xffff) * 0x5bd1e995 + ((k >>> 16) * 0xe995 << 16);
k ^=
/* k >>> r: */
k >>> 24;
h =
/* Math.imul(k, m): */
(k & 0xffff) * 0x5bd1e995 + ((k >>> 16) * 0xe995 << 16) ^
/* Math.imul(h, m): */
(h & 0xffff) * 0x5bd1e995 + ((h >>> 16) * 0xe995 << 16);
} // Handle the last few bytes of the input array
switch (len) {
case 3:
h ^= (str.charCodeAt(i + 2) & 0xff) << 16;
case 2:
h ^= (str.charCodeAt(i + 1) & 0xff) << 8;
case 1:
h ^= str.charCodeAt(i) & 0xff;
h =
/* Math.imul(h, m): */
(h & 0xffff) * 0x5bd1e995 + ((h >>> 16) * 0xe995 << 16);
} // Do a few final mixes of the hash to ensure the last few
// bytes are well-incorporated.
h ^= h >>> 13;
h =
/* Math.imul(h, m): */
(h & 0xffff) * 0x5bd1e995 + ((h >>> 16) * 0xe995 << 16);
return ((h ^ h >>> 15) >>> 0).toString(36);
}
function isProcessableValue(value) {
return value != null && typeof value !== 'boolean';
}
var processStyleName = /* #__PURE__ */ emotion_memoize_browser_esm(function (styleName) {
return isCustomProperty(styleName) ? styleName : styleName.replace(hyphenateRegex, '-$&').toLowerCase();
});
var processStyleValue = function processStyleValue(key, value) {
switch (key) {
case 'animation':
case 'animationName': {
if (typeof value === 'string') {
return value.replace(animationRegex, function (match, p1, p2) {
cursor = {
name: p1,
styles: p2,
next: cursor
};
return p1;
});
}
}
}
if (unitless_browser_esm[key] !== 1 && !isCustomProperty(key) && typeof value === 'number' && value !== 0) {
return value + 'px';
}
return value;
};
function memoize(fn) {
var cache = Object.create(null);
return function (arg) {
if (cache[arg] === undefined) cache[arg] = fn(arg);
return cache[arg];
};
}

View File

@ -0,0 +1,155 @@
var cursor, hyphenateRegex = /[A-Z]|^ms/g, animationRegex = /_EMO_([^_]+?)_([^]*?)_EMO_/g, unitless_browser_esm = {
animationIterationCount: 1,
borderImageOutset: 1,
borderImageSlice: 1,
borderImageWidth: 1,
boxFlex: 1,
boxFlexGroup: 1,
boxOrdinalGroup: 1,
columnCount: 1,
columns: 1,
flex: 1,
flexGrow: 1,
flexPositive: 1,
flexShrink: 1,
flexNegative: 1,
flexOrder: 1,
gridRow: 1,
gridRowEnd: 1,
gridRowSpan: 1,
gridRowStart: 1,
gridColumn: 1,
gridColumnEnd: 1,
gridColumnSpan: 1,
gridColumnStart: 1,
msGridRow: 1,
msGridRowSpan: 1,
msGridColumn: 1,
msGridColumnSpan: 1,
fontWeight: 1,
lineHeight: 1,
opacity: 1,
order: 1,
orphans: 1,
tabSize: 1,
widows: 1,
zIndex: 1,
zoom: 1,
WebkitLineClamp: 1,
fillOpacity: 1,
floodOpacity: 1,
stopOpacity: 1,
strokeDasharray: 1,
strokeDashoffset: 1,
strokeMiterlimit: 1,
strokeOpacity: 1,
strokeWidth: 1
}, isCustomProperty = function(property) {
return 45 === property.charCodeAt(1);
}, labelPattern = /label:\s*([^\s;\n{]+)\s*(;|$)/g, hash_browser_esm = function(str) {
for(var k, h = 0, i = 0, len = str.length; len >= 4; ++i, len -= 4)k = (65535 & (k = 255 & str.charCodeAt(i) | (255 & str.charCodeAt(++i)) << 8 | (255 & str.charCodeAt(++i)) << 16 | (255 & str.charCodeAt(++i)) << 24)) * 1540483477 + ((k >>> 16) * 59797 << 16), k ^= k >>> 24, h = (65535 & k) * 1540483477 + ((k >>> 16) * 59797 << 16) ^ (65535 & h) * 1540483477 + ((h >>> 16) * 59797 << 16);
switch(len){
case 3:
h ^= (255 & str.charCodeAt(i + 2)) << 16;
case 2:
h ^= (255 & str.charCodeAt(i + 1)) << 8;
case 1:
h = (65535 & (h ^= 255 & str.charCodeAt(i))) * 1540483477 + ((h >>> 16) * 59797 << 16);
}
return (((h = (65535 & (h ^= h >>> 13)) * 1540483477 + ((h >>> 16) * 59797 << 16)) ^ h >>> 15) >>> 0).toString(36);
};
function handleInterpolation(mergedProps, registered, interpolation) {
if (null == interpolation) return "";
if (void 0 !== interpolation.__emotion_styles) return interpolation;
switch(typeof interpolation){
case "boolean":
return "";
case "object":
if (1 === interpolation.anim) return cursor = {
name: interpolation.name,
styles: interpolation.styles,
next: cursor
}, interpolation.name;
if (void 0 !== interpolation.styles) {
var next = interpolation.next;
if (void 0 !== next) for(; void 0 !== next;)cursor = {
name: next.name,
styles: next.styles,
next: cursor
}, next = next.next;
return interpolation.styles + ";";
}
return createStringFromObject(mergedProps, registered, interpolation);
case "function":
if (void 0 !== mergedProps) {
var previousCursor = cursor, result = interpolation(mergedProps);
return cursor = previousCursor, handleInterpolation(mergedProps, registered, result);
}
break;
case "string":
break;
}
if (null == registered) return interpolation;
var cached = registered[interpolation];
return void 0 !== cached ? cached : interpolation;
}
export function serializeStyles(args, registered, mergedProps) {
if (1 === args.length && "object" == typeof args[0] && null !== args[0] && void 0 !== args[0].styles) return args[0];
var match, stringMode = !0, styles = "";
cursor = void 0;
var strings = args[0];
null == strings || void 0 === strings.raw ? (stringMode = !1, styles += handleInterpolation(mergedProps, registered, strings)) : styles += strings[0];
for(var i = 1; i < args.length; i++)styles += handleInterpolation(mergedProps, registered, args[i]), stringMode && (styles += strings[i]);
labelPattern.lastIndex = 0;
for(var identifierName = ""; null !== (match = labelPattern.exec(styles));)identifierName += "-" + match[1];
return {
name: hash_browser_esm(styles) + identifierName,
styles: styles,
next: cursor
};
}
function createStringFromObject(mergedProps, registered, obj) {
var string = "";
if (Array.isArray(obj)) for(var i = 0; i < obj.length; i++)string += handleInterpolation(mergedProps, registered, obj[i]) + ";";
else for(var _key in obj){
var value = obj[_key];
if ("object" != typeof value) null != registered && void 0 !== registered[value] ? string += _key + "{" + registered[value] + "}" : isProcessableValue(value) && (string += processStyleName(_key) + ":" + processStyleValue(_key, value) + ";");
else if (Array.isArray(value) && "string" == typeof value[0] && (null == registered || void 0 === registered[value[0]])) for(var _i = 0; _i < value.length; _i++)isProcessableValue(value[_i]) && (string += processStyleName(_key) + ":" + processStyleValue(_key, value[_i]) + ";");
else {
var interpolated = handleInterpolation(mergedProps, registered, value);
switch(_key){
case "animation":
case "animationName":
string += processStyleName(_key) + ":" + interpolated + ";";
break;
default:
string += _key + "{" + interpolated + "}";
}
}
}
return string;
}
function isProcessableValue(value) {
return null != value && "boolean" != typeof value;
}
var processStyleName = function(fn) {
var cache = Object.create(null);
return function(arg) {
return void 0 === cache[arg] && (cache[arg] = fn(arg)), cache[arg];
};
}(function(styleName) {
return isCustomProperty(styleName) ? styleName : styleName.replace(hyphenateRegex, "-$&").toLowerCase();
}), processStyleValue = function(key, value) {
switch(key){
case "animation":
case "animationName":
if ("string" == typeof value) return value.replace(animationRegex, function(match, p1, p2) {
return cursor = {
name: p1,
styles: p2,
next: cursor
}, p1;
});
}
return 1 === unitless_browser_esm[key] || isCustomProperty(key) || "number" != typeof value || 0 === value ? value : value + "px";
};

View File

@ -1317,13 +1317,13 @@
time = startOfDate(this.year(), this.month(), this.date() + 1) - 1;
break;
case "hour":
time += 3600000 - mod$1((time = this._d.valueOf()) + (this._isUTC ? 0 : 60000 * this.utcOffset()), 3600000) - 1;
time = this._d.valueOf(), time += 3600000 - mod$1(time + (this._isUTC ? 0 : 60000 * this.utcOffset()), 3600000) - 1;
break;
case "minute":
time += 60000 - mod$1(time = this._d.valueOf(), 60000) - 1;
time = this._d.valueOf(), time += 60000 - mod$1(time, 60000) - 1;
break;
case "second":
time += 1000 - mod$1(time = this._d.valueOf(), 1000) - 1;
time = this._d.valueOf(), time += 1000 - mod$1(time, 1000) - 1;
break;
}
return this._d.setTime(time), hooks.updateOffset(this, !0), this;
@ -1409,13 +1409,13 @@
time = startOfDate(this.year(), this.month(), this.date());
break;
case "hour":
time -= mod$1((time = this._d.valueOf()) + (this._isUTC ? 0 : 60000 * this.utcOffset()), 3600000);
time = this._d.valueOf(), time -= mod$1(time + (this._isUTC ? 0 : 60000 * this.utcOffset()), 3600000);
break;
case "minute":
time -= mod$1(time = this._d.valueOf(), 60000);
time = this._d.valueOf(), time -= mod$1(time, 60000);
break;
case "second":
time -= mod$1(time = this._d.valueOf(), 1000);
time = this._d.valueOf(), time -= mod$1(time, 1000);
break;
}
return this._d.setTime(time), hooks.updateOffset(this, !0), this;

View File

@ -0,0 +1,54 @@
export default function murmur2(str) {
// 'm' and 'r' are mixing constants generated offline.
// They're not really 'magic', they just happen to work well.
// const m = 0x5bd1e995;
// const r = 24;
// Initialize the hash
var h = 0; // Mix 4 bytes at a time into the hash
var k,
i = 0,
len = str.length;
for (; len >= 4; ++i, len -= 4) {
k = str.charCodeAt(i) & 0xff | (str.charCodeAt(++i) & 0xff) << 8 | (str.charCodeAt(++i) & 0xff) << 16 | (str.charCodeAt(++i) & 0xff) << 24;
k =
/* Math.imul(k, m): */
(k & 0xffff) * 0x5bd1e995 + ((k >>> 16) * 0xe995 << 16);
k ^=
/* k >>> r: */
k >>> 24;
h =
/* Math.imul(k, m): */
(k & 0xffff) * 0x5bd1e995 + ((k >>> 16) * 0xe995 << 16) ^
/* Math.imul(h, m): */
(h & 0xffff) * 0x5bd1e995 + ((h >>> 16) * 0xe995 << 16);
} // Handle the last few bytes of the input array
switch (len) {
case 3:
h ^= (str.charCodeAt(i + 2) & 0xff) << 16;
case 2:
h ^= (str.charCodeAt(i + 1) & 0xff) << 8;
case 1:
h ^= str.charCodeAt(i) & 0xff;
h =
/* Math.imul(h, m): */
(h & 0xffff) * 0x5bd1e995 + ((h >>> 16) * 0xe995 << 16);
} // Do a few final mixes of the hash to ensure the last few
// bytes are well-incorporated.
h ^= h >>> 13;
h =
/* Math.imul(h, m): */
(h & 0xffff) * 0x5bd1e995 + ((h >>> 16) * 0xe995 << 16);
return ((h ^ h >>> 15) >>> 0).toString(36);
}
function isProcessableValue(value) {
return value != null && typeof value !== 'boolean';
}

View File

@ -0,0 +1,12 @@
export default function murmur2(str) {
for(var k, h = 0, i = 0, len = str.length; len >= 4; ++i, len -= 4)k = (65535 & (k = 255 & str.charCodeAt(i) | (255 & str.charCodeAt(++i)) << 8 | (255 & str.charCodeAt(++i)) << 16 | (255 & str.charCodeAt(++i)) << 24)) * 1540483477 + ((k >>> 16) * 59797 << 16), k ^= k >>> 24, h = (65535 & k) * 1540483477 + ((k >>> 16) * 59797 << 16) ^ (65535 & h) * 1540483477 + ((h >>> 16) * 59797 << 16);
switch(len){
case 3:
h ^= (255 & str.charCodeAt(i + 2)) << 16;
case 2:
h ^= (255 & str.charCodeAt(i + 1)) << 8;
case 1:
h = (65535 & (h ^= 255 & str.charCodeAt(i))) * 1540483477 + ((h >>> 16) * 59797 << 16);
}
return (((h = (65535 & (h ^= h >>> 13)) * 1540483477 + ((h >>> 16) * 59797 << 16)) ^ h >>> 15) >>> 0).toString(36);
};

View File

@ -0,0 +1,4 @@
{
"defaults": true,
"toplevel": true
}

View File

@ -0,0 +1,376 @@
/* harmony default export */
var emotion_memoize_browser_esm = (memoize);
var hyphenateRegex = /[A-Z]|^ms/g;
var animationRegex = /_EMO_([^_]+?)_([^]*?)_EMO_/g;
var unitlessKeys = {
animationIterationCount: 1,
borderImageOutset: 1,
borderImageSlice: 1,
borderImageWidth: 1,
boxFlex: 1,
boxFlexGroup: 1,
boxOrdinalGroup: 1,
columnCount: 1,
columns: 1,
flex: 1,
flexGrow: 1,
flexPositive: 1,
flexShrink: 1,
flexNegative: 1,
flexOrder: 1,
gridRow: 1,
gridRowEnd: 1,
gridRowSpan: 1,
gridRowStart: 1,
gridColumn: 1,
gridColumnEnd: 1,
gridColumnSpan: 1,
gridColumnStart: 1,
msGridRow: 1,
msGridRowSpan: 1,
msGridColumn: 1,
msGridColumnSpan: 1,
fontWeight: 1,
lineHeight: 1,
opacity: 1,
order: 1,
orphans: 1,
tabSize: 1,
widows: 1,
zIndex: 1,
zoom: 1,
WebkitLineClamp: 1,
// SVG-related properties
fillOpacity: 1,
floodOpacity: 1,
stopOpacity: 1,
strokeDasharray: 1,
strokeDashoffset: 1,
strokeMiterlimit: 1,
strokeOpacity: 1,
strokeWidth: 1
};
var unitless_browser_esm = (unitlessKeys);
var isCustomProperty = function isCustomProperty(property) {
return property.charCodeAt(1) === 45;
};
var labelPattern = /label:\s*([^\s;\n{]+)\s*(;|$)/g;
var cursor;
var hash_browser_esm = (murmur2);
function handleInterpolation(mergedProps, registered, interpolation) {
if (interpolation == null) {
return '';
}
if (interpolation.__emotion_styles !== undefined) {
if (false) { }
return interpolation;
}
switch (typeof interpolation) {
case 'boolean': {
return '';
}
case 'object': {
if (interpolation.anim === 1) {
cursor = {
name: interpolation.name,
styles: interpolation.styles,
next: cursor
};
return interpolation.name;
}
if (interpolation.styles !== undefined) {
var next = interpolation.next;
if (next !== undefined) {
// not the most efficient thing ever but this is a pretty rare case
// and there will be very few iterations of this generally
while (next !== undefined) {
cursor = {
name: next.name,
styles: next.styles,
next: cursor
};
next = next.next;
}
}
var styles = interpolation.styles + ";";
if (false) { }
return styles;
}
return createStringFromObject(mergedProps, registered, interpolation);
}
case 'function': {
if (mergedProps !== undefined) {
var previousCursor = cursor;
var result = interpolation(mergedProps);
cursor = previousCursor;
return handleInterpolation(mergedProps, registered, result);
} else if (false) { }
break;
}
case 'string':
if (false) {
var replaced, matched;
}
break;
} // finalize string values (regular strings and functions interpolated into css calls)
if (registered == null) {
return interpolation;
}
var cached = registered[interpolation];
return cached !== undefined ? cached : interpolation;
}
function serializeStyles(args, registered, mergedProps) {
if (args.length === 1 && typeof args[0] === 'object' && args[0] !== null && args[0].styles !== undefined) {
return args[0];
}
var stringMode = true;
var styles = '';
cursor = undefined;
var strings = args[0];
if (strings == null || strings.raw === undefined) {
stringMode = false;
console.log('stringMode = false')
styles += handleInterpolation(mergedProps, registered, strings);
} else {
if (false) { }
styles += strings[0];
} // we start at 1 since we've already handled the first arg
console.log(`Styles: ${styles}`)
for (var i = 1; i < args.length; i++) {
styles += handleInterpolation(mergedProps, registered, args[i]);
if (stringMode) {
if (false) { }
styles += strings[i];
}
}
console.log(`Styles: ${styles}`)
var sourceMap;
if (false) { } // using a global regex with .exec is stateful so lastIndex has to be reset each time
labelPattern.lastIndex = 0;
var identifierName = '';
var match; // https://esbench.com/bench/5b809c2cf2949800a0f61fb5
while ((match = labelPattern.exec(styles)) !== null) {
identifierName += '-' + // $FlowFixMe we know it's not null
match[1];
}
console.log(`styles = ${styles}`)
console.log(`identifierName = ${identifierName}`)
var name = hash_browser_esm(styles) + identifierName;
if (false) { }
return {
name: name,
styles: styles,
next: cursor
};
}
function createStringFromObject(mergedProps, registered, obj) {
var string = '';
if (Array.isArray(obj)) {
for (var i = 0; i < obj.length; i++) {
string += handleInterpolation(mergedProps, registered, obj[i]) + ";";
}
} else {
for (var _key in obj) {
var value = obj[_key];
if (typeof value !== 'object') {
if (registered != null && registered[value] !== undefined) {
string += _key + "{" + registered[value] + "}";
} else if (isProcessableValue(value)) {
string += processStyleName(_key) + ":" + processStyleValue(_key, value) + ";";
}
} else {
if (_key === 'NO_COMPONENT_SELECTOR' && "production" !== 'production') { }
if (Array.isArray(value) && typeof value[0] === 'string' && (registered == null || registered[value[0]] === undefined)) {
for (var _i = 0; _i < value.length; _i++) {
if (isProcessableValue(value[_i])) {
string += processStyleName(_key) + ":" + processStyleValue(_key, value[_i]) + ";";
}
}
} else {
var interpolated = handleInterpolation(mergedProps, registered, value);
switch (_key) {
case 'animation':
case 'animationName': {
string += processStyleName(_key) + ":" + interpolated + ";";
break;
}
default: {
if (false) { }
string += _key + "{" + interpolated + "}";
}
}
}
}
}
}
return string;
}
function murmur2(str) {
// 'm' and 'r' are mixing constants generated offline.
// They're not really 'magic', they just happen to work well.
// const m = 0x5bd1e995;
// const r = 24;
// Initialize the hash
var h = 0; // Mix 4 bytes at a time into the hash
var k,
i = 0,
len = str.length;
for (; len >= 4; ++i, len -= 4) {
k = str.charCodeAt(i) & 0xff | (str.charCodeAt(++i) & 0xff) << 8 | (str.charCodeAt(++i) & 0xff) << 16 | (str.charCodeAt(++i) & 0xff) << 24;
console.log(`K1: ${k}`);
k =
/* Math.imul(k, m): */
(k & 0xffff) * 0x5bd1e995 + ((k >>> 16) * 0xe995 << 16);
console.log(`K2: ${k}`);
k ^=
/* k >>> r: */
k >>> 24;
console.log(`K3: ${k}`);
h =
/* Math.imul(k, m): */
(k & 0xffff) * 0x5bd1e995 + ((k >>> 16) * 0xe995 << 16) ^
/* Math.imul(h, m): */
(h & 0xffff) * 0x5bd1e995 + ((h >>> 16) * 0xe995 << 16);
console.log(`H: ${h}`);
} // Handle the last few bytes of the input array
switch (len) {
case 3:
h ^= (str.charCodeAt(i + 2) & 0xff) << 16;
case 2:
h ^= (str.charCodeAt(i + 1) & 0xff) << 8;
case 1:
h ^= str.charCodeAt(i) & 0xff;
h =
/* Math.imul(h, m): */
(h & 0xffff) * 0x5bd1e995 + ((h >>> 16) * 0xe995 << 16);
} // Do a few final mixes of the hash to ensure the last few
// bytes are well-incorporated.
h ^= h >>> 13;
h =
/* Math.imul(h, m): */
(h & 0xffff) * 0x5bd1e995 + ((h >>> 16) * 0xe995 << 16);
return ((h ^ h >>> 15) >>> 0).toString(36);
}
function isProcessableValue(value) {
return value != null && typeof value !== 'boolean';
}
var processStyleName = /* #__PURE__ */ emotion_memoize_browser_esm(function (styleName) {
return isCustomProperty(styleName) ? styleName : styleName.replace(hyphenateRegex, '-$&').toLowerCase();
});
var processStyleValue = function processStyleValue(key, value) {
switch (key) {
case 'animation':
case 'animationName': {
if (typeof value === 'string') {
return value.replace(animationRegex, function (match, p1, p2) {
cursor = {
name: p1,
styles: p2,
next: cursor
};
return p1;
});
}
}
}
if (unitless_browser_esm[key] !== 1 && !isCustomProperty(key) && typeof value === 'number' && value !== 0) {
return value + 'px';
}
return value;
};
function memoize(fn) {
var cache = Object.create(null);
return function (arg) {
if (cache[arg] === undefined) cache[arg] = fn(arg);
return cache[arg];
};
}
console.log(serializeStyles(`:root {
--background-color: rebeccapurple;
}`));
console.log(serializeStyles(`:root {
--background-color: rebeccapurple;
}`));
console.log(serializeStyles(`:root {
--background-color: rebeccapurple;
}`));
console.log(serializeStyles(`:root {
--background-color: rebeccapurple;
}`));
console.log(serializeStyles(`:root {
--background-color: rebeccapurple;
}`));
console.log(serializeStyles(`:root {
--background-color: rebeccapurple;
}`));

View File

@ -0,0 +1,4 @@
{
"defaults": true,
"toplevel": true
}

View File

@ -0,0 +1,54 @@
function murmur2(str) {
// 'm' and 'r' are mixing constants generated offline.
// They're not really 'magic', they just happen to work well.
// const m = 0x5bd1e995;
// const r = 24;
// Initialize the hash
var h = 0; // Mix 4 bytes at a time into the hash
var k,
i = 0,
len = str.length;
for (; len >= 4; ++i, len -= 4) {
k = str.charCodeAt(i) & 0xff | (str.charCodeAt(++i) & 0xff) << 8 | (str.charCodeAt(++i) & 0xff) << 16 | (str.charCodeAt(++i) & 0xff) << 24;
k =
/* Math.imul(k, m): */
(k & 0xffff) * 0x5bd1e995 + ((k >>> 16) * 0xe995 << 16);
k ^=
/* k >>> r: */
k >>> 24;
h =
/* Math.imul(k, m): */
(k & 0xffff) * 0x5bd1e995 + ((k >>> 16) * 0xe995 << 16) ^
/* Math.imul(h, m): */
(h & 0xffff) * 0x5bd1e995 + ((h >>> 16) * 0xe995 << 16);
} // Handle the last few bytes of the input array
switch (len) {
case 3:
h ^= (str.charCodeAt(i + 2) & 0xff) << 16;
case 2:
h ^= (str.charCodeAt(i + 1) & 0xff) << 8;
case 1:
h ^= str.charCodeAt(i) & 0xff;
h =
/* Math.imul(h, m): */
(h & 0xffff) * 0x5bd1e995 + ((h >>> 16) * 0xe995 << 16);
} // Do a few final mixes of the hash to ensure the last few
// bytes are well-incorporated.
h ^= h >>> 13;
h =
/* Math.imul(h, m): */
(h & 0xffff) * 0x5bd1e995 + ((h >>> 16) * 0xe995 << 16);
return ((h ^ h >>> 15) >>> 0).toString(36);
}
console.log(murmur2("123421334"))
console.log(murmur2("123asd ;nv"))
console.log(murmur2("1va1ns`klj"))

View File

@ -0,0 +1,4 @@
{
"defaults": true,
"toplevel": true
}

View File

@ -0,0 +1,25 @@
function murmur2(str) {
var h = 0;
var k, i = 0, len = str.length;
for (; len >= 4; ++i, len -= 4) {
k = 255 & str.charCodeAt(i) | (255 & str.charCodeAt(++i)) << 8 | (255 & str.charCodeAt(++i)) << 16 | (255 & str.charCodeAt(++i)) << 24;
k = (65535 & k) * 1540483477 + ((k >>> 16) * 59797 << 16);
k ^= k >>> 24;
h = (65535 & k) * 1540483477 + ((k >>> 16) * 59797 << 16) ^ (65535 & h) * 1540483477 + ((h >>> 16) * 59797 << 16);
}
switch (len) {
case 3:
h ^= (255 & str.charCodeAt(i + 2)) << 16;
case 2:
h ^= (255 & str.charCodeAt(i + 1)) << 8;
case 1:
h ^= 255 & str.charCodeAt(i);
h = (65535 & h) * 1540483477 + ((h >>> 16) * 59797 << 16);
}
h ^= h >>> 13;
h = (65535 & h) * 1540483477 + ((h >>> 16) * 59797 << 16);
return ((h ^ h >>> 15) >>> 0).toString(36);
}
console.log(murmur2("123421334"));
console.log(murmur2("123asd ;nv"));
console.log(murmur2("1va1ns`klj"));

View File

@ -1,3 +1,3 @@
function f(a, b) {
(a -= 42) < 0 && (a = 0), (b.a = a);
(a -= 42) < 0 && (a = 0), b.a = a;
}

View File

@ -1,2 +1,2 @@
var s = Symbol.for("assign"), str = "";
s *= s, s /= s *= 0, s %= s /= 0, s += s %= 0, s += 0, str += s += "", s -= s, s -= 0, s <<= s, s <<= 0, s >>= s, s >>= 0, s >>>= s, s >>>= 0, s &= s, s &= 0, s ^= s, s ^= 0, s |= s, s |= 0, str += s || str;
s *= s, s *= 0, s /= s, s /= 0, s %= s, s %= 0, s += s, s += 0, s += "", str += s, s -= s, s -= 0, s <<= s, s <<= 0, s >>= s, s >>= 0, s >>>= s, s >>>= 0, s &= s, s &= 0, s ^= s, s ^= 0, s |= s, s |= 0, str += s || str;

View File

@ -1,2 +1,2 @@
var s = Symbol.for("assign"), str = "";
s *= s, s /= s *= 0, s %= s /= 0, s += s %= 0, s += 0, str += s += "", s -= s, s -= 0, s <<= s, s <<= 0, s >>= s, s >>= 0, s >>>= s, s >>>= 0, s &= s, s &= 0, s ^= s, s ^= 0, s |= s, s |= 0, str += s || str;
s *= s, s *= 0, s /= s, s /= 0, s %= s, s %= 0, s += s, s += 0, s += "", str += s, s -= s, s -= 0, s <<= s, s <<= 0, s >>= s, s >>= 0, s >>>= s, s >>>= 0, s &= s, s &= 0, s ^= s, s ^= 0, s |= s, s |= 0, str += s || str;