@@ -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 ! ) ;
4848 }
4949
5050 constructor (
@@ -85,15 +85,21 @@ 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 , { id : value . id } ) ;
90+ result . value = { case : 'argumentList' , value : list } ;
91+ } else {
92+ const list = create ( proto . Value_ArgumentListSchema , {
93+ separator : this . protofySeparator ( value . separator ) ,
94+ contents : value . asList
95+ . map ( element => this . protofy ( element ) )
96+ . toArray ( ) ,
97+ } ) ;
98+ for ( const [ key , mapValue ] of value . keywordsInternal ) {
99+ list . keywords [ key ] = this . protofy ( mapValue ) ;
100+ }
101+ result . value = { case : 'argumentList' , value : list } ;
95102 }
96- result . value = { case : 'argumentList' , value : list } ;
97103 } else if ( value instanceof SassMap ) {
98104 const map = create ( proto . Value_MapSchema , {
99105 entries : value . contents . toArray ( ) . map ( ( [ key , value ] ) => ( {
@@ -104,6 +110,11 @@ export class Protofier {
104110 result . value = { case : 'map' , value : map } ;
105111 } else if ( value instanceof SassFunction ) {
106112 if ( value . id !== undefined ) {
113+ if ( value . compileContext !== this . functions . compileContext ) {
114+ throw utils . compilerError (
115+ `Value ${ value } does not belong to this compilation` ,
116+ ) ;
117+ }
107118 const fn = create ( proto . Value_CompilerFunctionSchema , value ) ;
108119 result . value = { case : 'compilerFunction' , value : fn } ;
109120 } else {
@@ -114,6 +125,11 @@ export class Protofier {
114125 result . value = { case : 'hostFunction' , value : fn } ;
115126 }
116127 } else if ( value instanceof SassMixin ) {
128+ if ( value . compileContext !== this . functions . compileContext ) {
129+ throw utils . compilerError (
130+ `Value ${ value } does not belong to this compilation` ,
131+ ) ;
132+ }
117133 const mixin = create ( proto . Value_CompilerMixinSchema , value ) ;
118134 result . value = { case : 'compilerMixin' , value : mixin } ;
119135 } else if ( value instanceof SassCalculation ) {
@@ -349,6 +365,7 @@ export class Protofier {
349365 ) ,
350366 separator ,
351367 list . id ,
368+ this . functions . compileContext ,
352369 ) ;
353370 this . argumentLists . push ( result ) ;
354371 return result ;
@@ -369,15 +386,21 @@ export class Protofier {
369386 ) ;
370387
371388 case 'compilerFunction' :
372- return new SassFunction ( value . value . value . id ) ;
389+ return new SassFunction (
390+ value . value . value . id ,
391+ this . functions . compileContext ,
392+ ) ;
373393
374394 case 'hostFunction' :
375395 throw utils . compilerError (
376396 'The compiler may not send Value.host_function.' ,
377397 ) ;
378398
379399 case 'compilerMixin' :
380- return new SassMixin ( value . value . value . id ) ;
400+ return new SassMixin (
401+ value . value . value . id ,
402+ this . functions . compileContext ,
403+ ) ;
381404
382405 case 'calculation' :
383406 return this . deprotofyCalculation ( value . value . value ) ;
0 commit comments