From 5e4d260c2aa459d328c01e7382c72bdff6192b28 Mon Sep 17 00:00:00 2001 From: Natalie Weizenbaum Date: Sat, 4 Feb 2017 12:39:23 -0800 Subject: [PATCH 1/2] Fix a @content bug. --- CHANGELOG.md | 2 ++ lib/src/visitor/perform.dart | 12 ++++-------- 2 files changed, 6 insertions(+), 8 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 3a269cf7..8aaf2b92 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -73,6 +73,8 @@ * Fix an `@extend` edge case involving multiple combinators in a row. +* Fix a bug where a `@content` block could get incorrectly passed to a mixin. + ## 1.0.0-alpha.8 * Add the `content-exists()` function. diff --git a/lib/src/visitor/perform.dart b/lib/src/visitor/perform.dart index 030691d1..045ded8f 100644 --- a/lib/src/visitor/perform.dart +++ b/lib/src/visitor/perform.dart @@ -714,14 +714,10 @@ class _PerformVisitor return null; } - if (node.children == null) { - _runUserDefinedCallable(node.arguments, mixin, node.span, callback); - } else { - var environment = _environment.closure(); - _runUserDefinedCallable(node.arguments, mixin, node.span, () { - _environment.withContent(node.children, environment, callback); - }); - } + var environment = node.children == null ? null : _environment.closure(); + _runUserDefinedCallable(node.arguments, mixin, node.span, () { + _environment.withContent(node.children, environment, callback); + }); return null; } From 89a7888a0e70bc02b0e8bd8cd297483db6728ee1 Mon Sep 17 00:00:00 2001 From: Natalie Weizenbaum Date: Sat, 4 Feb 2017 14:16:29 -0800 Subject: [PATCH 2/2] Properly isolate callable environments. --- CHANGELOG.md | 3 +++ lib/src/visitor/perform.dart | 8 ++++++-- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 8aaf2b92..b86235f1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -75,6 +75,9 @@ * Fix a bug where a `@content` block could get incorrectly passed to a mixin. +* Properly isolate the lexical environments of different calls to the same mixin + and function. + ## 1.0.0-alpha.8 * Add the `content-exists()` function. diff --git a/lib/src/visitor/perform.dart b/lib/src/visitor/perform.dart index 045ded8f..4167ada7 100644 --- a/lib/src/visitor/perform.dart +++ b/lib/src/visitor/perform.dart @@ -364,7 +364,9 @@ class _PerformVisitor if (block == null) return null; _withStackFrame("@content", node.span, () { - _withEnvironment(_environment.contentEnvironment, () { + // Add an extra closure() call so that modifications to the environment + // don't affect the underlying environment closure. + _withEnvironment(_environment.contentEnvironment.closure(), () { for (var statement in block) { statement.accept(this); } @@ -1118,7 +1120,9 @@ class _PerformVisitor var separator = triple.item3; return _withStackFrame(callable.name + "()", span, () { - return _withEnvironment(callable.environment, () { + // Add an extra closure() call so that modifications to the environment + // don't affect the underlying environment closure. + return _withEnvironment(callable.environment.closure(), () { return _environment.scope(() { _verifyArguments( positional.length, named, callable.declaration.arguments, span);