From 5210386bd25dc4101e72053c493b0c36c0cd2c59 Mon Sep 17 00:00:00 2001 From: Rich-Harris Date: Fri, 27 Nov 2015 21:30:50 -0500 Subject: [PATCH] =?UTF-8?q?handle=20top-level=20blocks=20=E2=80=93=20fixes?= =?UTF-8?q?=20#326?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/ast/attachScopes.js | 2 +- test/function/top-level-block/_config.js | 3 +++ test/function/top-level-block/main.js | 3 +++ 3 files changed, 7 insertions(+), 1 deletion(-) create mode 100644 test/function/top-level-block/_config.js create mode 100644 test/function/top-level-block/main.js diff --git a/src/ast/attachScopes.js b/src/ast/attachScopes.js index 6883611..92798e8 100644 --- a/src/ast/attachScopes.js +++ b/src/ast/attachScopes.js @@ -44,7 +44,7 @@ export default function attachScopes ( statement ) { } // create new block scope - if ( node.type === 'BlockStatement' && !/Function/.test( parent.type ) ) { + if ( node.type === 'BlockStatement' && ( !parent || !/Function/.test( parent.type ) ) ) { newScope = new Scope({ parent: scope, block: true diff --git a/test/function/top-level-block/_config.js b/test/function/top-level-block/_config.js new file mode 100644 index 0000000..1cc39db --- /dev/null +++ b/test/function/top-level-block/_config.js @@ -0,0 +1,3 @@ +module.exports = { + description: 'allows top-level block' +}; diff --git a/test/function/top-level-block/main.js b/test/function/top-level-block/main.js new file mode 100644 index 0000000..5948b71 --- /dev/null +++ b/test/function/top-level-block/main.js @@ -0,0 +1,3 @@ +{ + assert.equal( 1 + 1, 2 ); +}