oxc/napi/minify/test/minify.test.ts
翠 / green 6589c3bbb3
feat(mangler): reuse variable names (#8562)
Changed the mangler to reuse variable names where possible.

This will reduce the code size as shorter variable names can be used in
more places. But requires global information and limits parallelism in a
single file and requires more memory.

---------

Co-authored-by: Boshen <boshenc@gmail.com>
Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
2025-01-25 14:00:24 +08:00

34 lines
927 B
TypeScript

import { describe, expect, it } from 'vitest';
import { minify } from '../index';
describe('simple', () => {
const code = 'function foo() { var bar; bar(undefined) } foo();';
it('matches output', () => {
const ret = minify('test.js', code, { sourcemap: true });
expect(ret).toStrictEqual({
'code': 'function foo(){var a;a(void 0)}foo();',
'map': {
'mappings': 'AAAA,SAAS,KAAM,CAAE,IAAIA,EAAK,SAAc,AAAE,CAAC,KAAK',
'names': [
'bar',
],
'sources': [
'test.js',
],
'sourcesContent': [
code,
],
'version': 3,
},
});
});
it('can turn off everything', () => {
const ret = minify('test.js', code, { compress: false, mangle: false, codegen: { whitespace: false } });
expect(ret).toStrictEqual({
'code': 'function foo() {\n\tvar bar;\n\tbar(undefined);\n}\nfoo();\n',
});
});
});