Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: temporary fix for libraries that call Object.freeze() #1483

Merged
merged 1 commit into from Nov 19, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
16 changes: 16 additions & 0 deletions test/yargs.js
Expand Up @@ -2339,4 +2339,20 @@ describe('yargs dsl tests', () => {
})
})
})

// see: https://github.com/babel/babel/pull/10733
it('should not fail if command handler freezes object', () => {
const argv = yargs()
.command('cmd', 'a command', (yargs) => {
yargs.parserConfiguration({ 'populate--': true })
}, (argv) => {
Object.freeze(argv)
argv._.should.eql(['cmd'])
argv['--'].should.eql(['foo'])
}).parse(['cmd', '--', 'foo'])
argv._.should.eql(['cmd', 'foo'])
// This should actually not be undefined, once we fix
// #1482.
argv['--'].should.eql(['foo'])
})
})
10 changes: 8 additions & 2 deletions yargs.js
Expand Up @@ -1190,9 +1190,15 @@ function Yargs (processArgs, cwd, parentRequire) {
// we temporarily populate '--' rather than _, with arguments
// after the '--' directive. After the parse, we copy these back.
self._copyDoubleDash = function (argv) {
if (!argv._) return argv
if (!argv._ || !argv['--']) return argv
argv._.push.apply(argv._, argv['--'])
delete argv['--']

// TODO(bcoe): refactor command parsing such that this delete is not
// necessary: https://github.com/yargs/yargs/issues/1482
try {
delete argv['--']
} catch (_err) {}

return argv
}

Expand Down