增加部分语法检测
parent
549718fac8
commit
51becf6943
|
@ -31,3 +31,42 @@ export function checkMedia(type, isAudio = 1) {
|
|||
}
|
||||
return 0
|
||||
}
|
||||
|
||||
export function checkAsyncAwait() {
|
||||
try {
|
||||
eval('async function foo(){return await 123}')
|
||||
return 1.25
|
||||
} catch (e) {
|
||||
return 0
|
||||
}
|
||||
}
|
||||
|
||||
export function checkPrivateFeatures() {
|
||||
try {
|
||||
eval('class Foo { #bar = 3}')
|
||||
return 1.25
|
||||
} catch (e) {
|
||||
return 0
|
||||
}
|
||||
}
|
||||
|
||||
export function checkObjectSpread() {
|
||||
try {
|
||||
eval(`let a = [11, 22]
|
||||
let b = [...a]
|
||||
;[a[1], a[0]] = [a[0], a[1]]`)
|
||||
return 1
|
||||
} catch (e) {
|
||||
return 0
|
||||
}
|
||||
}
|
||||
|
||||
export function checkOptionalChaining() {
|
||||
try {
|
||||
// ?。 和 ?? 同时期出现的, 检测一个即可
|
||||
window.a?.b?.c()
|
||||
return 1
|
||||
} catch (e) {
|
||||
return 0
|
||||
}
|
||||
}
|
||||
|
|
51
src/store.js
51
src/store.js
|
@ -1,7 +1,14 @@
|
|||
import { reactive } from 'vue'
|
||||
|
||||
import * as env from '@/lib/env.js'
|
||||
import { checkCanvas, checkMedia } from '@/lib/checks.js'
|
||||
import {
|
||||
checkCanvas,
|
||||
checkMedia,
|
||||
checkAsyncAwait,
|
||||
checkPrivateFeatures,
|
||||
checkObjectSpread,
|
||||
checkOptionalChaining
|
||||
} from '@/lib/checks.js'
|
||||
|
||||
const store = reactive({
|
||||
scores: 80,
|
||||
|
@ -160,30 +167,48 @@ const store = reactive({
|
|||
]
|
||||
},
|
||||
{
|
||||
name: 'ES6模块',
|
||||
name: '一些语法支持',
|
||||
total: 0,
|
||||
factor: 40,
|
||||
scores: [1, env.SUPPORT_ASSERTIONS ? 2.5 : 0],
|
||||
items: ['import/export', 'Import assertions']
|
||||
},
|
||||
{
|
||||
name: '性能',
|
||||
total: 0,
|
||||
factor: 70,
|
||||
scores: [!!navigator.serviceWorker ^ 0, window.WebAssembly ? 1.5 : 0],
|
||||
items: ['Web Workers', 'WebAssembly']
|
||||
factor: 60,
|
||||
scores: [
|
||||
!!window.BigInt ^ 0,
|
||||
checkObjectSpread(),
|
||||
checkOptionalChaining(),
|
||||
1 /* 能打开这个页面, 就是支持esm的了 */,
|
||||
env.SUPPORT_ASSERTIONS ? 2.5 : 0,
|
||||
checkAsyncAwait(),
|
||||
checkPrivateFeatures()
|
||||
],
|
||||
items: [
|
||||
'BigInt',
|
||||
'Object Spread',
|
||||
'?. and ??',
|
||||
'import/export',
|
||||
'Import assertions',
|
||||
'async / await',
|
||||
'Private class features'
|
||||
]
|
||||
},
|
||||
{
|
||||
name: '其他',
|
||||
total: 0,
|
||||
factor: 80,
|
||||
scores: [
|
||||
!!navigator.serviceWorker ^ 0,
|
||||
window.WebAssembly ? 1.5 : 0,
|
||||
!!navigator.bluetooth ^ 0,
|
||||
navigator.clipboard ? 0.8 : 0,
|
||||
navigator.usb ? 2 : 0,
|
||||
!!navigator.windowControlsOverlay ^ 0
|
||||
],
|
||||
items: ['Bluetooth', 'clipboard', 'USB', 'Window Controls Overlay']
|
||||
items: [
|
||||
'Web Workers',
|
||||
'WebAssembly',
|
||||
'Bluetooth',
|
||||
'clipboard',
|
||||
'USB',
|
||||
'Window Controls Overlay'
|
||||
]
|
||||
}
|
||||
]
|
||||
})
|
||||
|
|
Loading…
Reference in New Issue