Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(es/minifier): Remove wrong rule (#6201)
**Related issue:** - vercel/next.js#41527.
- Loading branch information
Showing
13 changed files
with
398 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
238 changes: 238 additions & 0 deletions
238
crates/swc_ecma_minifier/tests/fixture/next/41527/1/input.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,238 @@ | ||
import Delta from 'quill-delta'; | ||
import { EmbedBlot, Scope } from 'parchment'; | ||
import Quill from '../core/quill'; | ||
import logger from '../core/logger'; | ||
import Module from '../core/module'; | ||
const debug = logger('quill:toolbar'); | ||
class Toolbar extends Module { | ||
constructor(quill, options) { | ||
super(quill, options); | ||
if (Array.isArray(this.options.container)) { | ||
const container = document.createElement('div'); | ||
addControls(container, this.options.container); | ||
quill.container.parentNode.insertBefore(container, quill.container); | ||
this.container = container; | ||
} else if (typeof this.options.container === 'string') { | ||
this.container = document.querySelector(this.options.container); | ||
} else { | ||
this.container = this.options.container; | ||
} | ||
if (!(this.container instanceof HTMLElement)) { | ||
debug.error('Container required for toolbar', this.options); | ||
return; | ||
} | ||
this.container.classList.add('ql-toolbar'); | ||
this.controls = []; | ||
this.handlers = {}; | ||
Object.keys(this.options.handlers).forEach((format) => { | ||
this.addHandler(format, this.options.handlers[format]); | ||
}); | ||
Array.from(this.container.querySelectorAll('button, select')).forEach((input) => { | ||
this.attach(input); | ||
}); | ||
this.quill.on(Quill.events.EDITOR_CHANGE, (type, range) => { | ||
if (type === Quill.events.SELECTION_CHANGE) { | ||
this.update(range); | ||
} | ||
}); | ||
this.quill.on(Quill.events.SCROLL_OPTIMIZE, () => { | ||
const [range] = this.quill.selection.getRange(); | ||
this.update(range); | ||
}); | ||
} | ||
addHandler(format, handler) { | ||
this.handlers[format] = handler; | ||
} | ||
attach(input) { | ||
let format = Array.from(input.classList).find((className) => { | ||
return className.indexOf('ql-') === 0; | ||
}); | ||
if (!format) return; | ||
format = format.slice('ql-'.length); | ||
if (input.tagName === 'BUTTON') { | ||
input.setAttribute('type', 'button'); | ||
} | ||
if (this.handlers[format] == null && this.quill.scroll.query(format) == null) { | ||
debug.warn('ignoring attaching to nonexistent format', format, input); | ||
return; | ||
} | ||
const eventName = input.tagName === 'SELECT' ? 'change' : 'click'; | ||
input.addEventListener(eventName, (e) => { | ||
let value; | ||
if (input.tagName === 'SELECT') { | ||
if (input.selectedIndex < 0) return; | ||
const selected = input.options[input.selectedIndex]; | ||
if (selected.hasAttribute('selected')) { | ||
value = false; | ||
} else { | ||
value = selected.value || false; | ||
} | ||
} else { | ||
if (input.classList.contains('ql-active')) { | ||
value = false; | ||
} else { | ||
value = input.value || !input.hasAttribute('value'); | ||
} | ||
e.preventDefault(); | ||
} | ||
this.quill.focus(); | ||
const [range] = this.quill.selection.getRange(); | ||
if (this.handlers[format] != null) { | ||
this.handlers[format].call(this, value); | ||
} else if (this.quill.scroll.query(format).prototype instanceof EmbedBlot) { | ||
value = prompt(`Enter ${format}`); | ||
if (!value) return; | ||
this.quill.updateContents(new Delta().retain(range.index).delete(range.length).insert({ | ||
[format]: value | ||
}), Quill.sources.USER); | ||
} else { | ||
this.quill.format(format, value, Quill.sources.USER); | ||
} | ||
this.update(range); | ||
}); | ||
this.controls.push([ | ||
format, | ||
input | ||
]); | ||
} | ||
update(range) { | ||
const formats = range == null ? {} : this.quill.getFormat(range); | ||
this.controls.forEach((pair) => { | ||
const [format, input] = pair; | ||
if (input.tagName === 'SELECT') { | ||
let option; | ||
if (range == null) { | ||
option = null; | ||
} else if (formats[format] == null) { | ||
option = input.querySelector('option[selected]'); | ||
} else if (!Array.isArray(formats[format])) { | ||
let value = formats[format]; | ||
if (typeof value === 'string') { | ||
value = value.replace(/"/g, '\\"'); | ||
} | ||
option = input.querySelector(`option[value="${value}"]`); | ||
} | ||
if (option == null) { | ||
input.value = ''; | ||
input.selectedIndex = -1; | ||
} else { | ||
option.selected = true; | ||
} | ||
} else if (range == null) { | ||
input.classList.remove('ql-active'); | ||
} else if (input.hasAttribute('value')) { | ||
const isActive = formats[format] === input.getAttribute('value') || formats[format] != null && formats[format].toString() === input.getAttribute('value') || formats[format] == null && !input.getAttribute('value'); | ||
input.classList.toggle('ql-active', isActive); | ||
} else { | ||
input.classList.toggle('ql-active', formats[format] != null); | ||
} | ||
}); | ||
} | ||
} | ||
Toolbar.DEFAULTS = {}; | ||
function addButton(container, format, value) { | ||
const input = document.createElement('button'); | ||
input.setAttribute('type', 'button'); | ||
input.classList.add(`ql-${format}`); | ||
if (value != null) { | ||
input.value = value; | ||
} | ||
container.appendChild(input); | ||
} | ||
function addControls(container, groups) { | ||
if (!Array.isArray(groups[0])) { | ||
groups = [ | ||
groups | ||
]; | ||
} | ||
groups.forEach((controls) => { | ||
const group = document.createElement('span'); | ||
group.classList.add('ql-formats'); | ||
controls.forEach((control) => { | ||
if (typeof control === 'string') { | ||
addButton(group, control); | ||
} else { | ||
const format = Object.keys(control)[0]; | ||
const value = control[format]; | ||
if (Array.isArray(value)) { | ||
addSelect(group, format, value); | ||
} else { | ||
addButton(group, format, value); | ||
} | ||
} | ||
}); | ||
container.appendChild(group); | ||
}); | ||
} | ||
function addSelect(container, format, values) { | ||
const input = document.createElement('select'); | ||
input.classList.add(`ql-${format}`); | ||
values.forEach((value) => { | ||
const option = document.createElement('option'); | ||
if (value !== false) { | ||
option.setAttribute('value', value); | ||
} else { | ||
option.setAttribute('selected', 'selected'); | ||
} | ||
input.appendChild(option); | ||
}); | ||
container.appendChild(input); | ||
} | ||
Toolbar.DEFAULTS = { | ||
container: null, | ||
handlers: { | ||
clean() { | ||
const range = this.quill.getSelection(); | ||
if (range == null) return; | ||
if (range.length === 0) { | ||
const formats = this.quill.getFormat(); | ||
Object.keys(formats).forEach((name) => { | ||
if (this.quill.scroll.query(name, Scope.INLINE) != null) { | ||
this.quill.format(name, false, Quill.sources.USER); | ||
} | ||
}); | ||
} else { | ||
this.quill.removeFormat(range, Quill.sources.USER); | ||
} | ||
}, | ||
direction(value) { | ||
const { align } = this.quill.getFormat(); | ||
if (value === 'rtl' && align == null) { | ||
this.quill.format('align', 'right', Quill.sources.USER); | ||
} else if (!value && align === 'right') { | ||
this.quill.format('align', false, Quill.sources.USER); | ||
} | ||
this.quill.format('direction', value, Quill.sources.USER); | ||
}, | ||
indent(value) { | ||
const range = this.quill.getSelection(); | ||
const formats = this.quill.getFormat(range); | ||
const indent = parseInt(formats.indent || 0, 10); | ||
if (value === '+1' || value === '-1') { | ||
let modifier = value === '+1' ? 1 : -1; | ||
if (formats.direction === 'rtl') modifier *= -1; | ||
this.quill.format('indent', indent + modifier, Quill.sources.USER); | ||
} | ||
}, | ||
link(value) { | ||
if (value === true) { | ||
value = prompt('Enter link URL:'); | ||
} | ||
this.quill.format('link', value, Quill.sources.USER); | ||
}, | ||
list(value) { | ||
const range = this.quill.getSelection(); | ||
const formats = this.quill.getFormat(range); | ||
if (value === 'check') { | ||
if (formats.list === 'checked' || formats.list === 'unchecked') { | ||
this.quill.format('list', false, Quill.sources.USER); | ||
} else { | ||
this.quill.format('list', 'unchecked', Quill.sources.USER); | ||
} | ||
} else { | ||
this.quill.format('list', value, Quill.sources.USER); | ||
} | ||
} | ||
} | ||
}; | ||
export { Toolbar as default, addControls }; |
Oops, something went wrong.
842abd4
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Benchmark
es/full/minify/libraries/antd
1987920106
ns/iter (± 38350667
)1980275902
ns/iter (± 46306263
)1.00
es/full/minify/libraries/d3
454701610
ns/iter (± 22105722
)433243434
ns/iter (± 33146554
)1.05
es/full/minify/libraries/echarts
1822721566
ns/iter (± 430307712
)1658424070
ns/iter (± 69878668
)1.10
es/full/minify/libraries/jquery
116499814
ns/iter (± 11769607
)115088142
ns/iter (± 9354814
)1.01
es/full/minify/libraries/lodash
132333266
ns/iter (± 10850176
)130959579
ns/iter (± 10430462
)1.01
es/full/minify/libraries/moment
79246110
ns/iter (± 13373743
)65224644
ns/iter (± 6799692
)1.21
es/full/minify/libraries/react
22049141
ns/iter (± 1228722
)22352799
ns/iter (± 1524468
)0.99
es/full/minify/libraries/terser
351748932
ns/iter (± 37835653
)342102294
ns/iter (± 14456376
)1.03
es/full/minify/libraries/three
614463318
ns/iter (± 38044971
)628007422
ns/iter (± 240501706
)0.98
es/full/minify/libraries/typescript
3731332042
ns/iter (± 109327183
)3731844430
ns/iter (± 222150843
)1.00
es/full/minify/libraries/victory
1000605691
ns/iter (± 68287295
)863141606
ns/iter (± 16115762
)1.16
es/full/minify/libraries/vue
195728434
ns/iter (± 19696210
)185526411
ns/iter (± 16100830
)1.05
es/full/codegen/es3
38207
ns/iter (± 7380
)33978
ns/iter (± 3938
)1.12
es/full/codegen/es5
36399
ns/iter (± 5843
)33924
ns/iter (± 1607
)1.07
es/full/codegen/es2015
40705
ns/iter (± 6214
)33711
ns/iter (± 2385
)1.21
es/full/codegen/es2016
38705
ns/iter (± 6792
)33571
ns/iter (± 6121
)1.15
es/full/codegen/es2017
40114
ns/iter (± 6343
)34277
ns/iter (± 7727
)1.17
es/full/codegen/es2018
42386
ns/iter (± 7881
)33742
ns/iter (± 2113
)1.26
es/full/codegen/es2019
39960
ns/iter (± 6800
)33684
ns/iter (± 767
)1.19
es/full/codegen/es2020
37409
ns/iter (± 5336
)33476
ns/iter (± 830
)1.12
es/full/all/es3
247828681
ns/iter (± 26836941
)205031486
ns/iter (± 32267580
)1.21
es/full/all/es5
228299889
ns/iter (± 32952433
)213044840
ns/iter (± 21278091
)1.07
es/full/all/es2015
188536936
ns/iter (± 20727926
)172217080
ns/iter (± 19316954
)1.09
es/full/all/es2016
193588097
ns/iter (± 19695210
)158515768
ns/iter (± 11354755
)1.22
es/full/all/es2017
191247476
ns/iter (± 19413051
)166700104
ns/iter (± 14003228
)1.15
es/full/all/es2018
187477093
ns/iter (± 20962967
)151470894
ns/iter (± 10763565
)1.24
es/full/all/es2019
189771349
ns/iter (± 18380408
)145611300
ns/iter (± 10422728
)1.30
es/full/all/es2020
181164204
ns/iter (± 22428478
)146629383
ns/iter (± 20690210
)1.24
es/full/parser
923359
ns/iter (± 141678
)729613
ns/iter (± 43289
)1.27
es/full/base/fixer
31768
ns/iter (± 3808
)29888
ns/iter (± 2688
)1.06
es/full/base/resolver_and_hygiene
105770
ns/iter (± 15684
)100167
ns/iter (± 15700
)1.06
serialization of ast node
272
ns/iter (± 48
)224
ns/iter (± 14
)1.21
serialization of serde
255
ns/iter (± 48
)216
ns/iter (± 14
)1.18
This comment was automatically generated by workflow using github-action-benchmark.