Skip to content

Commit

Permalink
Merge pull request #1712 from rollup/fix-1706
Browse files Browse the repository at this point in the history
Fix issue when using labels inside functions
  • Loading branch information
lukastaegert committed Nov 9, 2017
2 parents d60f212 + ab8636f commit 91bbd1f
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 1 deletion.
12 changes: 11 additions & 1 deletion src/ast/ExecutionPathOptions.js
Expand Up @@ -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.
Expand Down Expand Up @@ -245,7 +255,7 @@ export default class ExecutionPathOptions {
* @return {ExecutionPathOptions}
*/
setIgnoreNoLabels () {
return this.set( OPTION_IGNORED_LABELS, null );
return this.remove( OPTION_IGNORED_LABELS );
}

/**
Expand Down
@@ -0,0 +1,3 @@
module.exports = {
description: 'do not fail when using labels inside functions (#1706)'
};
12 changes: 12 additions & 0 deletions 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();

0 comments on commit 91bbd1f

Please sign in to comment.