Skip to content

Commit

Permalink
fix: refine the order of unminify rules
Browse files Browse the repository at this point in the history
  • Loading branch information
pionxzh committed Oct 10, 2023
1 parent f35d07d commit 128b019
Showing 1 changed file with 20 additions and 12 deletions.
32 changes: 20 additions & 12 deletions packages/unminify/src/transformations/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,40 +36,48 @@ import type { Transform } from 'jscodeshift'
export const transformationMap: {
[name: string]: Transform
} = {
// first stage - basically prettify the code
prettier,
'module-mapping': moduleMapping,
'un-sequence-expression1': unSequenceExpression,
'un-variable-merging': unVariableMerging,
'un-curly-braces': unCurlyBraces,

// second stage - prepare the code for unminify
'un-runtime-helper': unRuntimeHelper, // eliminate helpers as early as possible
'un-curly-braces': unCurlyBraces, // add curly braces so that other transformations can works easier, but not required
'un-esm': unEsm, // relies on `un-runtime-helper` to eliminate helpers around `require` calls
'un-export-rename': unExportRename, // relies on `un-esm` to give us the export statements

// third stage - mostly one-to-one transformation
lebab,
'un-runtime-helper': unRuntimeHelper, // `un-esm` relies on this to eliminate helpers around `require` calls
'un-esm': unEsm,
'un-export-rename': unExportRename,
'un-use-strict': unUseStrict,
'un-esmodule-flag': unEsModuleFlag,
'un-boolean': unBoolean,
'un-undefined': unUndefined,
'un-infinity': unInfinity,
'un-numeric-literal': unNumericLiteral,
'un-template-literal': unTemplateLiteral,
'un-bracket-notation': unBracketNotation,
'un-return': unReturn,
'un-while-loop': unWhileLoop,
'un-bracket-notation': unBracketNotation,
'smart-inline': smartInline,
'smart-rename': smartRename,
'un-flip-comparisons': unFlipComparisons,
'un-type-constructor': unTypeConstructor,
'un-indirect-call': unIndirectCall,
'un-type-constructor': unTypeConstructor,
'un-builtin-prototype': unBuiltinPrototype,
'un-sequence-expression2': unSequenceExpression,
'un-parameters': unParameters,
'un-flip-comparisons': unFlipComparisons,

// advanced syntax upgrade
'smart-inline': smartInline,
'smart-rename': smartRename, // partially relies on `un-indirect-call` to work
'un-optional-chaining': unOptionalChaining,
'un-nullish-coalescing': unNullishCoalescing,
'un-conditionals': unConditionals,
'un-sequence-expression3': unSequenceExpression,
'un-conditionals': unConditionals, // need to run after `un-optional-chaining` and `un-nullish-coalescing`
'un-parameters': unParameters, // relies on `un-flip-comparisons` to work
'un-jsx': unJsx,
'un-iife': unIife,
'un-es6-class': unES6Class,
'un-async-await': unAsyncAwait,

// last stage - prettify the code again after we finish all the transformations
'prettier-last': prettier,
}

0 comments on commit 128b019

Please sign in to comment.