fix(es/minifier): Fix codemirror (#3462)

swc_ecma_minifier:
 - Mark for in/of loops as executed multiple times.
 - Check captured identifiers while invoking IIFE.
This commit is contained in:
Donny/강동윤 2022-02-07 11:11:53 +09:00 committed by GitHub
parent 5276054df3
commit 5812c3c10f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 15528 additions and 35 deletions

View File

@ -468,12 +468,12 @@ where
if let Expr::Ident(i) = e {
if cfg!(feature = "debug") {
tracing::debug!(
"Usage: `{}``; update = {:?}, assign_lhs = {:?} ",
i,
self.ctx.in_update_arg,
self.ctx.in_assign_lhs
);
// tracing::debug!(
// "Usage: `{}``; update = {:?}, assign_lhs = {:?} ",
// i,
// self.ctx.in_update_arg,
// self.ctx.in_assign_lhs
// );
}
if self.ctx.in_update_arg {

View File

@ -2,7 +2,7 @@ use super::Optimizer;
use crate::{
compress::optimize::Ctx,
mode::Mode,
util::{idents_used_by, make_number},
util::{idents_captured_by, idents_used_by, make_number},
};
use std::{
collections::HashMap,
@ -526,6 +526,18 @@ where
}
}
if self.ctx.executed_multiple_time {
if !param_ids.is_empty() {
let captured = idents_captured_by(body);
for param in param_ids {
if captured.contains(&param.to_id()) {
return false;
}
}
}
}
if !body.stmts.iter().all(|stmt| match stmt {
Stmt::Decl(Decl::Var(VarDecl {
kind: VarDeclKind::Var | VarDeclKind::Let,

View File

@ -1972,25 +1972,41 @@ where
fn visit_mut_for_in_stmt(&mut self, n: &mut ForInStmt) {
n.right.visit_mut_with(self);
let ctx = Ctx {
in_var_decl_of_for_in_or_of_loop: true,
..self.ctx
};
n.left.visit_mut_with(&mut *self.with_ctx(ctx));
{
let ctx = Ctx {
in_var_decl_of_for_in_or_of_loop: true,
..self.ctx
};
n.left.visit_mut_with(&mut *self.with_ctx(ctx));
}
n.body.visit_mut_with(self);
{
let ctx = Ctx {
executed_multiple_time: true,
..self.ctx
};
n.body.visit_mut_with(&mut *self.with_ctx(ctx));
}
}
fn visit_mut_for_of_stmt(&mut self, n: &mut ForOfStmt) {
n.right.visit_mut_with(self);
let ctx = Ctx {
in_var_decl_of_for_in_or_of_loop: true,
..self.ctx
};
n.left.visit_mut_with(&mut *self.with_ctx(ctx));
{
let ctx = Ctx {
in_var_decl_of_for_in_or_of_loop: true,
..self.ctx
};
n.left.visit_mut_with(&mut *self.with_ctx(ctx));
}
n.body.visit_mut_with(self);
{
let ctx = Ctx {
executed_multiple_time: true,
..self.ctx
};
n.body.visit_mut_with(&mut *self.with_ctx(ctx));
}
}
fn visit_mut_for_stmt(&mut self, s: &mut ForStmt) {

View File

@ -6836,13 +6836,15 @@
break;
}
0 === notloadedImgs.length && (console.log("Images loaded"), !1 === sequence ? (function(src) {
var url, tags = arguments.length > 1 && void 0 !== arguments[1] ? arguments[1] : AvailableTags;
return /^blob:/i.test(src) ? (url = src, new Promise(function(resolve, reject) {
var http = new XMLHttpRequest();
http.open("GET", url, !0), http.responseType = "blob", http.onreadystatechange = function() {
http.readyState === XMLHttpRequest.DONE && (200 === http.status || 0 === http.status) && resolve(this.response);
}, http.onerror = reject, http.send();
})).then(readToBuffer).then(function(buffer) {
var tags = arguments.length > 1 && void 0 !== arguments[1] ? arguments[1] : AvailableTags;
return /^blob:/i.test(src) ? (function(url) {
return new Promise(function(resolve, reject) {
var http = new XMLHttpRequest();
http.open("GET", url, !0), http.responseType = "blob", http.onreadystatechange = function() {
http.readyState === XMLHttpRequest.DONE && (200 === http.status || 0 === http.status) && resolve(this.response);
}, http.onerror = reject, http.send();
});
})(src).then(readToBuffer).then(function(buffer) {
return (function(file) {
var selectedTags = arguments.length > 1 && void 0 !== arguments[1] ? arguments[1] : AvailableTags, dataView = new DataView(file), length = file.byteLength, exifTags = selectedTags.reduce(function(result, selectedTag) {
var exifTag = Object.keys(ExifTags).filter(function(tag) {

View File

@ -2325,7 +2325,7 @@
};
var EditorView = function(place, props) {
this._props = props, this.state = props.state, this.directPlugins = props.plugins || [], this.directPlugins.forEach(checkStateComponent), this.dispatch = this.dispatch.bind(this), this._root = null, this.focused = !1, this.trackWrites = null, this.dom = place && place.mount || document.createElement("div"), place && (place.appendChild ? place.appendChild(this.dom) : place.apply ? place(this.dom) : place.mount && (this.mounted = !0)), this.editable = getEditable(this), this.markCursor = null, this.cursorWrapper = null, updateCursorWrapper(this), this.nodeViews = buildNodeViews(this), this.docView = docViewDesc(this.state.doc, computeDocDeco(this), viewDecorations(this), this.dom, this), this.lastSelectedViewDesc = null, this.dragging = null, (function(view7) {
for(var event6 in view7.shiftKey = !1, view7.mouseDown = null, view7.lastKeyCode = null, view7.lastKeyCodeTime = 0, view7.lastClick = {
for(var event5 in view7.shiftKey = !1, view7.mouseDown = null, view7.lastKeyCode = null, view7.lastKeyCodeTime = 0, view7.lastClick = {
time: 0,
x: 0,
y: 0,
@ -2456,12 +2456,12 @@
}
storedMarks && tr.ensureMarks(storedMarks), view8.dispatch(tr.scrollIntoView());
})(view7, from1, to1, typeOver1, added);
}), view7.domObserver.start(), view7.domChangeCount = 0, view7.eventHandlers = Object.create(null), handlers1){
var event5, handler;
handler = handlers1[event5 = event6], view7.dom.addEventListener(event5, view7.eventHandlers[event5] = function(event) {
}), view7.domObserver.start(), view7.domChangeCount = 0, view7.eventHandlers = Object.create(null), handlers1)!function(event6) {
var handler = handlers1[event6];
view7.dom.addEventListener(event6, view7.eventHandlers[event6] = function(event) {
!eventBelongsToView(view7, event) || runCustomHandler(view7, event) || !view7.editable && event.type in editHandlers || handler(view7, event);
});
}
}(event5);
result1.safari && view7.dom.addEventListener("input", function() {
return null;
}), ensureListeners(view7);

View File

@ -3700,15 +3700,17 @@ Cookie.write = function(key, value, options) {
},
initialize: function(path, options) {
this.instance = "Swiff_" + String.uniqueID(), this.setOptions(options), options = this.options;
var option, id = this.id = options.id || this.instance, container = document.id(options.container);
var id = this.id = options.id || this.instance, container = document.id(options.container);
Swiff.CallBacks[this.instance] = {};
var params = options.params, vars = options.vars, callBacks = options.callBacks, properties = Object.append({
height: options.height,
width: options.width
}, options.properties), self = this;
for(var callBack in callBacks)option = callBacks[callBack], Swiff.CallBacks[this.instance][callBack] = function() {
return option.apply(self.object, arguments);
}, vars[callBack] = "Swiff.CallBacks." + this.instance + "." + callBack;
for(var callBack in callBacks)Swiff.CallBacks[this.instance][callBack] = (function(option) {
return function() {
return option.apply(self.object, arguments);
};
})(callBacks[callBack]), vars[callBack] = "Swiff.CallBacks." + this.instance + "." + callBack;
params.flashVars = Object.toQueryString(vars), Browser.ie ? (properties.classid = "clsid:D27CDB6E-AE6D-11cf-96B8-444553540000", params.movie = path) : properties.type = "application/x-shockwave-flash", properties.data = path;
var build = "<object id=\"" + id + "\"";
for(var property in properties)build += " " + property + "=\"" + properties[property] + "\"";