@@ -26,14 +26,29 @@ USE_WASM_PACK=false
2626while  [[ $#  -gt  0 ]];  do 
2727    case  $1  in 
2828        -p|--package)
29+             if  [[ $#  -lt  2 ]];  then 
30+                 echo  " Error: Missing argument for $1 " 
31+                 usage
32+                 exit  1
33+             fi 
2934            PACKAGE_NAME=" $2 " 
3035            shift  2
3136            ;;
3237        -t|--target)
38+             if  [[ $#  -lt  2 ]];  then 
39+                 echo  " Error: Missing argument for $1 " 
40+                 usage
41+                 exit  1
42+             fi 
3343            TARGET_TYPE=" $2 " 
3444            shift  2
3545            ;;
3646        -o|--opt-level)
47+             if  [[ $#  -lt  2 ]];  then 
48+                 echo  " Error: Missing argument for $1 " 
49+                 usage
50+                 exit  1
51+             fi 
3752            OPT_LEVEL=" $2 " 
3853            shift  2
3954            ;;
@@ -139,41 +154,40 @@ if [ "$OPT_LEVEL" != "none" ] && command -v wasm-opt &> /dev/null; then
139154        #  Check wasm-opt version to determine available options
140155        WASM_OPT_VERSION=$( wasm-opt --version 2> /dev/null ||  echo  " " ) 
141156
142-         #  Base optimization flags that work with all versions
143-         BASE_FLAGS=(
144-             --code-folding
145-             --const-hoisting
146-             --dce
157+         #  Core optimization flags that should work with most versions
158+         CORE_FLAGS=(
147159            --strip-producers
148160            -Oz
149161            --enable-bulk-memory
150162            --enable-nontrapping-float-to-int
151-             -tnh
152163            --flatten
153164            --rereloop
154165            -Oz
155166            --converge
156167            --vacuum
157-             --dce
158-             --gsi
159-             --inlining-optimizing
160168            --merge-blocks
161169            --simplify-locals
162-             --optimize-added-constants
163-             --optimize-casts
164-             --optimize-instructions
165-             --optimize-stack-ir
166170            --remove-unused-brs
167171            --remove-unused-module-elements
168172            --remove-unused-names
169-             --remove-unused-types
170-             --post-emscripten
171173            -Oz
172174            -Oz
173175        )
174176
175177        #  Additional flags to test for compatibility
176178        OPTIONAL_FLAGS=(
179+             " --code-folding" 
180+             " --const-hoisting" 
181+             " --dce" 
182+             " -tnh" 
183+             " --gsi" 
184+             " --inlining-optimizing" 
185+             " --optimize-added-constants" 
186+             " --optimize-casts" 
187+             " --optimize-instructions" 
188+             " --optimize-stack-ir" 
189+             " --remove-unused-types" 
190+             " --post-emscripten" 
177191            " --generate-global-effects" 
178192            " --abstract-type-refining" 
179193        )
@@ -188,9 +202,9 @@ if [ "$OPT_LEVEL" != "none" ] && command -v wasm-opt &> /dev/null; then
188202            fi 
189203        done 
190204
191-         #  Run optimization with base  flags and any supported optional flags
205+         #  Run optimization with core  flags and any supported optional flags
192206        wasm-opt \
193-             " ${BASE_FLAGS [@]} " 
207+             " ${CORE_FLAGS [@]} " 
194208            " ${SUPPORTED_FLAGS[@]} " 
195209            " $WASM_PATH " 
196210            -o \
0 commit comments