From ab8636f3e008d9fadba7799b9e71acbe23106b4d Mon Sep 17 00:00:00 2001 From: Lukas Taegert Date: Thu, 9 Nov 2017 08:02:22 +0100 Subject: [PATCH] Resolve #1706 --- src/ast/ExecutionPathOptions.js | 12 +++++++++++- .../handle-labels-inside-functions/_config.js | 3 +++ .../samples/handle-labels-inside-functions/main.js | 12 ++++++++++++ 3 files changed, 26 insertions(+), 1 deletion(-) create mode 100644 test/function/samples/handle-labels-inside-functions/_config.js create mode 100644 test/function/samples/handle-labels-inside-functions/main.js diff --git a/src/ast/ExecutionPathOptions.js b/src/ast/ExecutionPathOptions.js index eaaf9a46827..ab979e2a7da 100644 --- a/src/ast/ExecutionPathOptions.js +++ b/src/ast/ExecutionPathOptions.js @@ -35,6 +35,16 @@ export default class ExecutionPathOptions { return this._optionValues.get( option ); } + /** + * Returns a new ExecutionPathOptions instance with the given option removed. + * Does not mutate the current instance. Also works in sub-classes. + * @param {string} option - The name of an option + * @returns {*} Its value + */ + remove ( option ) { + return new this.constructor( this._optionValues.remove( option ) ); + } + /** * Returns a new ExecutionPathOptions instance with the given option set to a new value. * Does not mutate the current instance. Also works in sub-classes. @@ -245,7 +255,7 @@ export default class ExecutionPathOptions { * @return {ExecutionPathOptions} */ setIgnoreNoLabels () { - return this.set( OPTION_IGNORED_LABELS, null ); + return this.remove( OPTION_IGNORED_LABELS ); } /** diff --git a/test/function/samples/handle-labels-inside-functions/_config.js b/test/function/samples/handle-labels-inside-functions/_config.js new file mode 100644 index 00000000000..ca46e3f11ec --- /dev/null +++ b/test/function/samples/handle-labels-inside-functions/_config.js @@ -0,0 +1,3 @@ +module.exports = { + description: 'do not fail when using labels inside functions (#1706)' +}; diff --git a/test/function/samples/handle-labels-inside-functions/main.js b/test/function/samples/handle-labels-inside-functions/main.js new file mode 100644 index 00000000000..1c66d5c71e7 --- /dev/null +++ b/test/function/samples/handle-labels-inside-functions/main.js @@ -0,0 +1,12 @@ +function loopWithLabel () { + label2: { + while ( true ) { + if ( Math.random() < 0.5 ) { + break label2; + } + console.log( 'loop' ); + } + } +} + +loopWithLabel();