mirror of
https://github.com/swc-project/swc.git
synced 2024-11-30 15:23:33 +03:00
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:
parent
5276054df3
commit
5812c3c10f
@ -468,12 +468,12 @@ where
|
|||||||
|
|
||||||
if let Expr::Ident(i) = e {
|
if let Expr::Ident(i) = e {
|
||||||
if cfg!(feature = "debug") {
|
if cfg!(feature = "debug") {
|
||||||
tracing::debug!(
|
// tracing::debug!(
|
||||||
"Usage: `{}``; update = {:?}, assign_lhs = {:?} ",
|
// "Usage: `{}``; update = {:?}, assign_lhs = {:?} ",
|
||||||
i,
|
// i,
|
||||||
self.ctx.in_update_arg,
|
// self.ctx.in_update_arg,
|
||||||
self.ctx.in_assign_lhs
|
// self.ctx.in_assign_lhs
|
||||||
);
|
// );
|
||||||
}
|
}
|
||||||
|
|
||||||
if self.ctx.in_update_arg {
|
if self.ctx.in_update_arg {
|
||||||
|
@ -2,7 +2,7 @@ use super::Optimizer;
|
|||||||
use crate::{
|
use crate::{
|
||||||
compress::optimize::Ctx,
|
compress::optimize::Ctx,
|
||||||
mode::Mode,
|
mode::Mode,
|
||||||
util::{idents_used_by, make_number},
|
util::{idents_captured_by, idents_used_by, make_number},
|
||||||
};
|
};
|
||||||
use std::{
|
use std::{
|
||||||
collections::HashMap,
|
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(¶m.to_id()) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if !body.stmts.iter().all(|stmt| match stmt {
|
if !body.stmts.iter().all(|stmt| match stmt {
|
||||||
Stmt::Decl(Decl::Var(VarDecl {
|
Stmt::Decl(Decl::Var(VarDecl {
|
||||||
kind: VarDeclKind::Var | VarDeclKind::Let,
|
kind: VarDeclKind::Var | VarDeclKind::Let,
|
||||||
|
@ -1972,25 +1972,41 @@ where
|
|||||||
fn visit_mut_for_in_stmt(&mut self, n: &mut ForInStmt) {
|
fn visit_mut_for_in_stmt(&mut self, n: &mut ForInStmt) {
|
||||||
n.right.visit_mut_with(self);
|
n.right.visit_mut_with(self);
|
||||||
|
|
||||||
let ctx = Ctx {
|
{
|
||||||
in_var_decl_of_for_in_or_of_loop: true,
|
let ctx = Ctx {
|
||||||
..self.ctx
|
in_var_decl_of_for_in_or_of_loop: true,
|
||||||
};
|
..self.ctx
|
||||||
n.left.visit_mut_with(&mut *self.with_ctx(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) {
|
fn visit_mut_for_of_stmt(&mut self, n: &mut ForOfStmt) {
|
||||||
n.right.visit_mut_with(self);
|
n.right.visit_mut_with(self);
|
||||||
|
|
||||||
let ctx = Ctx {
|
{
|
||||||
in_var_decl_of_for_in_or_of_loop: true,
|
let ctx = Ctx {
|
||||||
..self.ctx
|
in_var_decl_of_for_in_or_of_loop: true,
|
||||||
};
|
..self.ctx
|
||||||
n.left.visit_mut_with(&mut *self.with_ctx(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) {
|
fn visit_mut_for_stmt(&mut self, s: &mut ForStmt) {
|
||||||
|
@ -6836,13 +6836,15 @@
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
0 === notloadedImgs.length && (console.log("Images loaded"), !1 === sequence ? (function(src) {
|
0 === notloadedImgs.length && (console.log("Images loaded"), !1 === sequence ? (function(src) {
|
||||||
var url, tags = arguments.length > 1 && void 0 !== arguments[1] ? arguments[1] : AvailableTags;
|
var tags = arguments.length > 1 && void 0 !== arguments[1] ? arguments[1] : AvailableTags;
|
||||||
return /^blob:/i.test(src) ? (url = src, new Promise(function(resolve, reject) {
|
return /^blob:/i.test(src) ? (function(url) {
|
||||||
var http = new XMLHttpRequest();
|
return new Promise(function(resolve, reject) {
|
||||||
http.open("GET", url, !0), http.responseType = "blob", http.onreadystatechange = function() {
|
var http = new XMLHttpRequest();
|
||||||
http.readyState === XMLHttpRequest.DONE && (200 === http.status || 0 === http.status) && resolve(this.response);
|
http.open("GET", url, !0), http.responseType = "blob", http.onreadystatechange = function() {
|
||||||
}, http.onerror = reject, http.send();
|
http.readyState === XMLHttpRequest.DONE && (200 === http.status || 0 === http.status) && resolve(this.response);
|
||||||
})).then(readToBuffer).then(function(buffer) {
|
}, http.onerror = reject, http.send();
|
||||||
|
});
|
||||||
|
})(src).then(readToBuffer).then(function(buffer) {
|
||||||
return (function(file) {
|
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 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) {
|
var exifTag = Object.keys(ExifTags).filter(function(tag) {
|
||||||
|
@ -2325,7 +2325,7 @@
|
|||||||
};
|
};
|
||||||
var EditorView = function(place, props) {
|
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) {
|
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,
|
time: 0,
|
||||||
x: 0,
|
x: 0,
|
||||||
y: 0,
|
y: 0,
|
||||||
@ -2456,12 +2456,12 @@
|
|||||||
}
|
}
|
||||||
storedMarks && tr.ensureMarks(storedMarks), view8.dispatch(tr.scrollIntoView());
|
storedMarks && tr.ensureMarks(storedMarks), view8.dispatch(tr.scrollIntoView());
|
||||||
})(view7, from1, to1, typeOver1, added);
|
})(view7, from1, to1, typeOver1, added);
|
||||||
}), view7.domObserver.start(), view7.domChangeCount = 0, view7.eventHandlers = Object.create(null), handlers1){
|
}), view7.domObserver.start(), view7.domChangeCount = 0, view7.eventHandlers = Object.create(null), handlers1)!function(event6) {
|
||||||
var event5, handler;
|
var handler = handlers1[event6];
|
||||||
handler = handlers1[event5 = event6], view7.dom.addEventListener(event5, view7.eventHandlers[event5] = function(event) {
|
view7.dom.addEventListener(event6, view7.eventHandlers[event6] = function(event) {
|
||||||
!eventBelongsToView(view7, event) || runCustomHandler(view7, event) || !view7.editable && event.type in editHandlers || handler(view7, event);
|
!eventBelongsToView(view7, event) || runCustomHandler(view7, event) || !view7.editable && event.type in editHandlers || handler(view7, event);
|
||||||
});
|
});
|
||||||
}
|
}(event5);
|
||||||
result1.safari && view7.dom.addEventListener("input", function() {
|
result1.safari && view7.dom.addEventListener("input", function() {
|
||||||
return null;
|
return null;
|
||||||
}), ensureListeners(view7);
|
}), ensureListeners(view7);
|
||||||
|
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@ -3700,15 +3700,17 @@ Cookie.write = function(key, value, options) {
|
|||||||
},
|
},
|
||||||
initialize: function(path, options) {
|
initialize: function(path, options) {
|
||||||
this.instance = "Swiff_" + String.uniqueID(), this.setOptions(options), options = this.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] = {};
|
Swiff.CallBacks[this.instance] = {};
|
||||||
var params = options.params, vars = options.vars, callBacks = options.callBacks, properties = Object.append({
|
var params = options.params, vars = options.vars, callBacks = options.callBacks, properties = Object.append({
|
||||||
height: options.height,
|
height: options.height,
|
||||||
width: options.width
|
width: options.width
|
||||||
}, options.properties), self = this;
|
}, options.properties), self = this;
|
||||||
for(var callBack in callBacks)option = callBacks[callBack], Swiff.CallBacks[this.instance][callBack] = function() {
|
for(var callBack in callBacks)Swiff.CallBacks[this.instance][callBack] = (function(option) {
|
||||||
return option.apply(self.object, arguments);
|
return function() {
|
||||||
}, vars[callBack] = "Swiff.CallBacks." + this.instance + "." + callBack;
|
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;
|
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 + "\"";
|
var build = "<object id=\"" + id + "\"";
|
||||||
for(var property in properties)build += " " + property + "=\"" + properties[property] + "\"";
|
for(var property in properties)build += " " + property + "=\"" + properties[property] + "\"";
|
||||||
|
Loading…
Reference in New Issue
Block a user