mirror of
https://github.com/danbulant/oxc
synced 2026-05-19 04:08:41 +00:00
feat(napi/transform): perform dce after define plugin (#6312)
This commit is contained in:
parent
642725cd7d
commit
abd3a9fe11
2 changed files with 9 additions and 8 deletions
|
|
@ -189,16 +189,18 @@ pub trait CompilerInterface {
|
|||
scopes = transformer_return.scopes;
|
||||
}
|
||||
|
||||
if let Some(config) = self.define_options() {
|
||||
if let Some(config) = self.inject_options() {
|
||||
let ret =
|
||||
ReplaceGlobalDefines::new(&allocator, config).build(symbols, scopes, &mut program);
|
||||
InjectGlobalVariables::new(&allocator, config).build(symbols, scopes, &mut program);
|
||||
symbols = ret.symbols;
|
||||
scopes = ret.scopes;
|
||||
}
|
||||
|
||||
if let Some(config) = self.inject_options() {
|
||||
let _ret =
|
||||
InjectGlobalVariables::new(&allocator, config).build(symbols, scopes, &mut program);
|
||||
if let Some(config) = self.define_options() {
|
||||
let ret =
|
||||
ReplaceGlobalDefines::new(&allocator, config).build(symbols, scopes, &mut program);
|
||||
Compressor::new(&allocator, CompressOptions::dead_code_elimination())
|
||||
.build_with_symbols_and_scopes(ret.symbols, ret.scopes, &mut program);
|
||||
// symbols = ret.symbols;
|
||||
// scopes = ret.scopes;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -62,11 +62,10 @@ describe('define plugin', () => {
|
|||
it('matches output', () => {
|
||||
const ret = oxc.transform('test.tsx', code, {
|
||||
define: {
|
||||
'process.env.NODE_ENV': 'false',
|
||||
'process.env.NODE_ENV': '"development"',
|
||||
},
|
||||
});
|
||||
// TODO: should be constant folded
|
||||
assert.equal(ret.code, 'if (false === "production") {\n\tfoo;\n}\n');
|
||||
assert.equal(ret.code, '');
|
||||
});
|
||||
});
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue