diff --git a/js-api-spec/value/function.test.ts b/js-api-spec/value/function.test.ts index c56b8b1b3..b423625fe 100644 --- a/js-api-spec/value/function.test.ts +++ b/js-api-spec/value/function.test.ts @@ -80,3 +80,45 @@ describe('rejects a function signature that', () => { it('has no closing parenthesis', () => rejectsSignature('foo(')); it('has a non-identifier name', () => rejectsSignature('$foo()')); }); + +it('rejects a compiler function from a different compilation', () => { + let plusOne: Value | undefined; + compileString( + ` + @use 'sass:meta'; + + @function plusOne($n) {@return $n + 1} + a {b: meta.call(foo(meta.get-function('plusOne')), 2)} + `, + { + functions: { + 'foo($arg)': (args: Value[]) => { + plusOne = args[0]; + return plusOne; + }, + }, + } + ); + + let plusTwo; + expect(() => { + compileString( + ` + @use 'sass:meta'; + + @function plusTwo($n) {@return $n + 2} + a {b: meta.call(foo(meta.get-function('plusTwo')), 2)} + `, + { + functions: { + 'foo($arg)': (args: Value[]) => { + plusTwo = args[0]; + return plusOne!; + }, + }, + } + ); + }).toThrowSassException({line: 4}); + + expect(plusOne).not.toEqual(plusTwo); +}); diff --git a/js-api-spec/value/mixin.test.ts b/js-api-spec/value/mixin.test.ts index a1413bfa8..e1d05f197 100644 --- a/js-api-spec/value/mixin.test.ts +++ b/js-api-spec/value/mixin.test.ts @@ -2,7 +2,7 @@ // MIT-style license that can be found in the LICENSE file or at // https://opensource.org/licenses/MIT. -import {SassMixin, compileString} from 'sass'; +import {SassMixin, compileString, Value} from 'sass'; import {spy} from '../utils'; @@ -44,3 +44,54 @@ it('can round-trip a mixin reference from Sass', () => { expect(fn).toHaveBeenCalled(); }); + +it('rejects a compiler mixin from a different compilation', () => { + let a: Value | undefined; + compileString( + ` + @use 'sass:meta'; + + @mixin a() { + a { + b: c; + } + } + + @include meta.apply(foo(meta.get-mixin('a'))); + `, + { + functions: { + 'foo($arg)': (args: Value[]) => { + a = args[0]; + return a; + }, + }, + } + ); + + let b; + expect(() => { + compileString( + ` + @use 'sass:meta'; + + @mixin b() { + c { + d: e; + } + } + @include meta.apply(foo(meta.get-mixin('b'))); + `, + { + functions: { + 'foo($arg)': (args: Value[]) => { + b = args[0]; + return a!; + }, + }, + } + ); + }).toThrowSassException({line: 8}); + + expect(a).not.toEqual(b); +});