Skip to content

Commit

Permalink
fix: addresses bug caused by delete being called on frozen object (#1485
Browse files Browse the repository at this point in the history
)
  • Loading branch information
bcoe committed Nov 19, 2019
1 parent 2fe88f5 commit 9190d03
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 3 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Expand Up @@ -2,6 +2,12 @@

All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines.

### 14.2.2

### Bug Fixes

* temporary fix for libraries that call Object.freeze() ([#1483](https://www.github.com/yargs/yargs/issues/1483)) ([99c2dc8](https://www.github.com/yargs/yargs/commit/99c2dc850e67c606644f8b0c0bca1a59c87dcbcd))

### [14.2.1](https://github.com/yargs/yargs/compare/v14.2.0...v14.2.1) (2019-10-30)


Expand Down
2 changes: 1 addition & 1 deletion package.json
@@ -1,6 +1,6 @@
{
"name": "yargs",
"version": "14.2.1",
"version": "14.2.2",
"description": "yargs the modern, pirate-themed, successor to optimist.",
"main": "./index.js",
"contributors": [
Expand Down
16 changes: 16 additions & 0 deletions test/yargs.js
Expand Up @@ -2327,4 +2327,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 @@ -1191,9 +1191,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

0 comments on commit 9190d03

Please sign in to comment.