import { test } from 'node:test'; import assert from 'node:assert/strict'; import { readFileSync } from 'node:fs'; import { fileURLToPath } from 'node:url'; import { dirname, join } from 'node:path'; import { run } from './dist/main.js'; const here = dirname(fileURLToPath(import.meta.url)); test('target 决定语法降级,lib 只影响类型', () => { const out = []; const ret = run((msg) => out.push(msg)); assert.deepEqual(ret, ['2', '0']); assert.deepEqual(out, ret); const es2022 = readFileSync(join(here, 'dist', 'main.js'), 'utf8'); const es2015 = readFileSync(join(here, 'dist-es2015', 'main.js'), 'utf8'); assert.ok(es2022.includes('?.') || es2022.includes('??'), 'ES2022 保留可选链/空值合并'); assert.ok(es2015.includes('?') && !es2015.includes('??'), 'ES2015 不保留空值合并'); });