66 ArrayPrototypeShift,
77 ArrayPrototypeSlice,
88 ArrayPrototypePush,
9- ObjectHasOwn,
9+ ObjectPrototypeHasOwnProperty : ObjectHasOwn ,
1010 ObjectEntries,
1111 StringPrototypeCharAt,
1212 StringPrototypeIncludes,
@@ -32,6 +32,12 @@ const {
3232 isShortOptionGroup
3333} = require ( './utils' ) ;
3434
35+ const {
36+ codes : {
37+ ERR_INVALID_SHORT_OPTION ,
38+ } ,
39+ } = require ( './errors' ) ;
40+
3541function getMainArgs ( ) {
3642 // This function is a placeholder for proposed process.mainArgs.
3743 // Work out where to slice process.argv for user supplied arguments.
@@ -66,12 +72,17 @@ function getMainArgs() {
6672 return ArrayPrototypeSlice ( process . argv , 2 ) ;
6773}
6874
75+ const protoKey = '__proto__' ;
6976function storeOptionValue ( options , longOption , value , result ) {
7077 const optionConfig = options [ longOption ] || { } ;
7178
7279 // Flags
7380 result . flags [ longOption ] = true ;
7481
82+ if ( longOption === protoKey ) {
83+ return ;
84+ }
85+
7586 // Values
7687 if ( optionConfig . multiple ) {
7788 // Always store value in array, including for flags.
@@ -97,7 +108,7 @@ const parseArgs = ({
97108 validateObject ( options , 'options' ) ;
98109 ArrayPrototypeForEach (
99110 ObjectEntries ( options ) ,
100- ( [ longOption , optionConfig ] ) => {
111+ ( { 0 : longOption , 1 : optionConfig } ) => {
101112 validateObject ( optionConfig , `options.${ longOption } ` ) ;
102113
103114 if ( ObjectHasOwn ( optionConfig , 'type' ) ) {
@@ -108,7 +119,7 @@ const parseArgs = ({
108119 const shortOption = optionConfig . short ;
109120 validateString ( shortOption , `options.${ longOption } .short` ) ;
110121 if ( shortOption . length !== 1 ) {
111- throw new Error ( `options. ${ longOption } .short must be a single character, got ' ${ shortOption } '` ) ;
122+ throw new ERR_INVALID_SHORT_OPTION ( longOption , shortOption ) ;
112123 }
113124 }
114125
0 commit comments