@@ -44,7 +44,7 @@ export class Protofier {
4444 get accessedArgumentLists ( ) : number [ ] {
4545 return this . argumentLists
4646 . filter ( list => list . keywordsAccessed )
47- . map ( list => list . id ) ;
47+ . map ( list => list . id as number ) ;
4848 }
4949
5050 constructor (
@@ -85,15 +85,23 @@ export class Protofier {
8585 } ) ;
8686 result . value = { case : 'list' , value : list } ;
8787 } else if ( value instanceof SassArgumentList ) {
88- const list = create ( proto . Value_ArgumentListSchema , {
89- id : value . id ,
90- separator : this . protofySeparator ( value . separator ) ,
91- contents : value . asList . map ( element => this . protofy ( element ) ) . toArray ( ) ,
92- } ) ;
93- for ( const [ key , mapValue ] of value . keywordsInternal ) {
94- list . keywords [ key ] = this . protofy ( mapValue ) ;
88+ if ( value . compileContext === this . functions . compileContext ) {
89+ const list = create ( proto . Value_ArgumentListSchema , {
90+ id : value . id ,
91+ } ) ;
92+ result . value = { case : 'argumentList' , value : list } ;
93+ } else {
94+ const list = create ( proto . Value_ArgumentListSchema , {
95+ separator : this . protofySeparator ( value . separator ) ,
96+ contents : value . asList
97+ . map ( element => this . protofy ( element ) )
98+ . toArray ( ) ,
99+ } ) ;
100+ for ( const [ key , mapValue ] of value . keywordsInternal ) {
101+ list . keywords [ key ] = this . protofy ( mapValue ) ;
102+ }
103+ result . value = { case : 'argumentList' , value : list } ;
95104 }
96- result . value = { case : 'argumentList' , value : list } ;
97105 } else if ( value instanceof SassMap ) {
98106 const map = create ( proto . Value_MapSchema , {
99107 entries : value . contents . toArray ( ) . map ( ( [ key , value ] ) => ( {
@@ -104,6 +112,11 @@ export class Protofier {
104112 result . value = { case : 'map' , value : map } ;
105113 } else if ( value instanceof SassFunction ) {
106114 if ( value . id !== undefined ) {
115+ if ( value . compileContext !== this . functions . compileContext ) {
116+ throw utils . compilerError (
117+ `Value ${ value } does not belong to this compilation` ,
118+ ) ;
119+ }
107120 const fn = create ( proto . Value_CompilerFunctionSchema , value ) ;
108121 result . value = { case : 'compilerFunction' , value : fn } ;
109122 } else {
@@ -114,6 +127,11 @@ export class Protofier {
114127 result . value = { case : 'hostFunction' , value : fn } ;
115128 }
116129 } else if ( value instanceof SassMixin ) {
130+ if ( value . compileContext !== this . functions . compileContext ) {
131+ throw utils . compilerError (
132+ `Value ${ value } does not belong to this compilation` ,
133+ ) ;
134+ }
117135 const mixin = create ( proto . Value_CompilerMixinSchema , value ) ;
118136 result . value = { case : 'compilerMixin' , value : mixin } ;
119137 } else if ( value instanceof SassCalculation ) {
@@ -349,6 +367,7 @@ export class Protofier {
349367 ) ,
350368 separator ,
351369 list . id ,
370+ this . functions . compileContext ,
352371 ) ;
353372 this . argumentLists . push ( result ) ;
354373 return result ;
@@ -369,15 +388,21 @@ export class Protofier {
369388 ) ;
370389
371390 case 'compilerFunction' :
372- return new SassFunction ( value . value . value . id ) ;
391+ return new SassFunction (
392+ value . value . value . id ,
393+ this . functions . compileContext ,
394+ ) ;
373395
374396 case 'hostFunction' :
375397 throw utils . compilerError (
376398 'The compiler may not send Value.host_function.' ,
377399 ) ;
378400
379401 case 'compilerMixin' :
380- return new SassMixin ( value . value . value . id ) ;
402+ return new SassMixin (
403+ value . value . value . id ,
404+ this . functions . compileContext ,
405+ ) ;
381406
382407 case 'calculation' :
383408 return this . deprotofyCalculation ( value . value . value ) ;
0 commit comments