mirror of
https://github.com/zhw2590582/ArtPlayer.git
synced 2026-10-24 14:41:20 -08:00
build(site): [SITE-07] reproduce and validate Monaco language modes
This commit is contained in:
1 parent
99c208aeee
commit
bc9cb61aaf
36 files changed
+5784
-43
No files matched your search
@@ -1,6 +1,8 @@
|
||||
import assert from 'node:assert/strict'
|
||||
// eslint-disable-next-line test/no-import-node-test -- Verify fixed source transforms without executing archived runtime.
|
||||
import test from 'node:test'
|
||||
import ts from 'typescript'
|
||||
import { emitAmd } from '../scripts/site-vendor/monaco/compiler.ts'
|
||||
import { aliasModule, moduleIds, nameModule, verifyWorkerSources } from '../scripts/site-vendor/monaco/languages.ts'
|
||||
import { browserTypeScript, verifyTypeScriptSource } from '../scripts/site-vendor/monaco/typescript.ts'
|
||||
|
||||
@@ -46,6 +48,8 @@ test('Monaco AMD naming ignores strings and preserves source bodies', () => {
|
||||
assert(named.includes('define(\'library/main\',["exports"]'))
|
||||
assert(!named.includes('sourceMappingURL'))
|
||||
assert.deepEqual(moduleIds(named), ['library/main'])
|
||||
assert.deepEqual(moduleIds(nameModule(anonymous, 'library/lib.index')), ['library/lib.index'])
|
||||
assert.throws(() => nameModule(anonymous, '../library'), /identifier/)
|
||||
assert(nameModule(anonymous.trimEnd(), 'library/main').endsWith('//# sourceMappingURL=source.js.map;'))
|
||||
assert.throws(() => nameModule(named, 'library/main'), /anonymous AMD dependency array/)
|
||||
assert.throws(() => nameModule(anonymous + anonymous, 'library/main'), /one anonymous/)
|
||||
@@ -53,6 +57,17 @@ test('Monaco AMD naming ignores strings and preserves source bodies', () => {
|
||||
assert.throws(() => nameModule(`${anonymous}//# sourceMappingURL=second.map\n`, 'library/main'), /Duplicate source map/)
|
||||
})
|
||||
|
||||
test('Monaco mode emission resolves const enums only from explicit declaration inputs', () => {
|
||||
const source = 'import { ScanError } from "pinned-json"; export const code = ScanError.End;'
|
||||
const declarations = [{ name: 'pinned-json', source: 'export declare const enum ScanError { End = 2 }' }]
|
||||
const compiled = emitAmd(ts, source, ['es5'], true, declarations)
|
||||
assert.match(compiled, /exports.code = 2/)
|
||||
const wrong = emitAmd(ts, source, ['es5'], true, [{ ...declarations[0], source: declarations[0].source.replace('2', '3') }])
|
||||
const fragment = nameModule(compiled, 'mode')
|
||||
assert.throws(() => verifyWorkerSources(nameModule(wrong, 'mode'), ['mode'], [{ id: 'mode', source: fragment }]), /Source differs/)
|
||||
assert(!emitAmd(ts, source, ['es5'], true).includes('exports.code = 2'))
|
||||
})
|
||||
|
||||
test('Monaco worker proof covers helper code, aliases and all module boundaries', () => {
|
||||
const id = 'library/main'
|
||||
const source = nameModule('const helper = 1;\ndefine(["exports"], function (exports) { exports.value = helper; });', id)
|
||||
|
||||
Reference in new issue
Block a user