Skip to content

Commit b50d801

Browse files
committed
Disallow passing functions/mixins across compilations
1 parent 8d8f336 commit b50d801

File tree

2 files changed

+94
-1
lines changed

2 files changed

+94
-1
lines changed

js-api-spec/value/function.test.ts

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,3 +80,45 @@ describe('rejects a function signature that', () => {
8080
it('has no closing parenthesis', () => rejectsSignature('foo('));
8181
it('has a non-identifier name', () => rejectsSignature('$foo()'));
8282
});
83+
84+
it('rejects a compiler function from a different compilation', () => {
85+
let plusOne: Value | undefined;
86+
compileString(
87+
`
88+
@use 'sass:meta';
89+
90+
@function plusOne($n) {@return $n + 1}
91+
a {b: meta.call(foo(meta.get-function('plusOne')), 2)}
92+
`,
93+
{
94+
functions: {
95+
'foo($arg)': (args: Value[]) => {
96+
plusOne = args[0];
97+
return plusOne;
98+
},
99+
},
100+
}
101+
);
102+
103+
let plusTwo;
104+
expect(() => {
105+
compileString(
106+
`
107+
@use 'sass:meta';
108+
109+
@function plusTwo($n) {@return $n + 2}
110+
a {b: meta.call(foo(meta.get-function('plusTwo')), 2)}
111+
`,
112+
{
113+
functions: {
114+
'foo($arg)': (args: Value[]) => {
115+
plusTwo = args[0];
116+
return plusOne!;
117+
},
118+
},
119+
}
120+
);
121+
}).toThrowSassException({line: 4});
122+
123+
expect(plusOne).not.toEqual(plusTwo);
124+
});

js-api-spec/value/mixin.test.ts

Lines changed: 52 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
// MIT-style license that can be found in the LICENSE file or at
33
// https://opensource.org/licenses/MIT.
44

5-
import {SassMixin, compileString} from 'sass';
5+
import {SassMixin, compileString, Value} from 'sass';
66

77
import {spy} from '../utils';
88

@@ -44,3 +44,54 @@ it('can round-trip a mixin reference from Sass', () => {
4444

4545
expect(fn).toHaveBeenCalled();
4646
});
47+
48+
it('rejects a compiler mixin from a different compilation', () => {
49+
let a: Value | undefined;
50+
compileString(
51+
`
52+
@use 'sass:meta';
53+
54+
@mixin a() {
55+
a {
56+
b: c;
57+
}
58+
}
59+
60+
@include meta.apply(foo(meta.get-mixin('a')));
61+
`,
62+
{
63+
functions: {
64+
'foo($arg)': (args: Value[]) => {
65+
a = args[0];
66+
return a;
67+
},
68+
},
69+
}
70+
);
71+
72+
let b;
73+
expect(() => {
74+
compileString(
75+
`
76+
@use 'sass:meta';
77+
78+
@mixin b() {
79+
c {
80+
d: e;
81+
}
82+
}
83+
@include meta.apply(foo(meta.get-mixin('b')));
84+
`,
85+
{
86+
functions: {
87+
'foo($arg)': (args: Value[]) => {
88+
b = args[0];
89+
return a!;
90+
},
91+
},
92+
}
93+
);
94+
}).toThrowSassException({line: 8});
95+
96+
expect(a).not.toEqual(b);
97+
});

0 commit comments

Comments
 (0)