Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 42 additions & 0 deletions js-api-spec/value/function.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});
53 changes: 52 additions & 1 deletion js-api-spec/value/mixin.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand Down Expand Up @@ -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);
});