-
Notifications
You must be signed in to change notification settings - Fork 29
Fix passing variables across compilations #367
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||||
---|---|---|---|---|---|---|---|---|---|---|
|
@@ -44,7 +44,7 @@ export class Protofier { | |||||||||
get accessedArgumentLists(): number[] { | ||||||||||
return this.argumentLists | ||||||||||
.filter(list => list.keywordsAccessed) | ||||||||||
.map(list => list.id); | ||||||||||
.map(list => list.id as number); | ||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||
} | ||||||||||
|
||||||||||
constructor( | ||||||||||
|
@@ -85,15 +85,23 @@ export class Protofier { | |||||||||
}); | ||||||||||
result.value = {case: 'list', value: list}; | ||||||||||
} else if (value instanceof SassArgumentList) { | ||||||||||
const list = create(proto.Value_ArgumentListSchema, { | ||||||||||
id: value.id, | ||||||||||
separator: this.protofySeparator(value.separator), | ||||||||||
contents: value.asList.map(element => this.protofy(element)).toArray(), | ||||||||||
}); | ||||||||||
for (const [key, mapValue] of value.keywordsInternal) { | ||||||||||
list.keywords[key] = this.protofy(mapValue); | ||||||||||
if (value.compileContext === this.functions.compileContext) { | ||||||||||
const list = create(proto.Value_ArgumentListSchema, { | ||||||||||
id: value.id, | ||||||||||
}); | ||||||||||
Comment on lines
+89
to
+91
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||
result.value = {case: 'argumentList', value: list}; | ||||||||||
} else { | ||||||||||
const list = create(proto.Value_ArgumentListSchema, { | ||||||||||
separator: this.protofySeparator(value.separator), | ||||||||||
contents: value.asList | ||||||||||
.map(element => this.protofy(element)) | ||||||||||
.toArray(), | ||||||||||
}); | ||||||||||
for (const [key, mapValue] of value.keywordsInternal) { | ||||||||||
list.keywords[key] = this.protofy(mapValue); | ||||||||||
} | ||||||||||
result.value = {case: 'argumentList', value: list}; | ||||||||||
} | ||||||||||
result.value = {case: 'argumentList', value: list}; | ||||||||||
} else if (value instanceof SassMap) { | ||||||||||
const map = create(proto.Value_MapSchema, { | ||||||||||
entries: value.contents.toArray().map(([key, value]) => ({ | ||||||||||
|
@@ -104,6 +112,11 @@ export class Protofier { | |||||||||
result.value = {case: 'map', value: map}; | ||||||||||
} else if (value instanceof SassFunction) { | ||||||||||
if (value.id !== undefined) { | ||||||||||
if (value.compileContext !== this.functions.compileContext) { | ||||||||||
throw utils.compilerError( | ||||||||||
`Value ${value} does not belong to this compilation`, | ||||||||||
); | ||||||||||
} | ||||||||||
const fn = create(proto.Value_CompilerFunctionSchema, value); | ||||||||||
result.value = {case: 'compilerFunction', value: fn}; | ||||||||||
} else { | ||||||||||
|
@@ -114,6 +127,11 @@ export class Protofier { | |||||||||
result.value = {case: 'hostFunction', value: fn}; | ||||||||||
} | ||||||||||
} else if (value instanceof SassMixin) { | ||||||||||
if (value.compileContext !== this.functions.compileContext) { | ||||||||||
throw utils.compilerError( | ||||||||||
`Value ${value} does not belong to this compilation`, | ||||||||||
); | ||||||||||
} | ||||||||||
const mixin = create(proto.Value_CompilerMixinSchema, value); | ||||||||||
result.value = {case: 'compilerMixin', value: mixin}; | ||||||||||
} else if (value instanceof SassCalculation) { | ||||||||||
|
@@ -349,6 +367,7 @@ export class Protofier { | |||||||||
), | ||||||||||
separator, | ||||||||||
list.id, | ||||||||||
this.functions.compileContext, | ||||||||||
); | ||||||||||
this.argumentLists.push(result); | ||||||||||
return result; | ||||||||||
|
@@ -369,15 +388,21 @@ export class Protofier { | |||||||||
); | ||||||||||
|
||||||||||
case 'compilerFunction': | ||||||||||
return new SassFunction(value.value.value.id); | ||||||||||
return new SassFunction( | ||||||||||
value.value.value.id, | ||||||||||
this.functions.compileContext, | ||||||||||
); | ||||||||||
|
||||||||||
case 'hostFunction': | ||||||||||
throw utils.compilerError( | ||||||||||
'The compiler may not send Value.host_function.', | ||||||||||
); | ||||||||||
|
||||||||||
case 'compilerMixin': | ||||||||||
return new SassMixin(value.value.value.id); | ||||||||||
return new SassMixin( | ||||||||||
value.value.value.id, | ||||||||||
this.functions.compileContext, | ||||||||||
); | ||||||||||
|
||||||||||
case 'calculation': | ||||||||||
return this.deprotofyCalculation(value.value.value); | ||||||||||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -19,7 +19,18 @@ export class SassArgumentList extends SassList { | |
* part of the package's public API and should not be accessed by user code. | ||
* It may be renamed or removed without warning in the future. | ||
*/ | ||
readonly id: number; | ||
readonly id: number | undefined; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Document what it means for this to be |
||
|
||
/** | ||
* If this argument list is constructed in the compiler, this is the unique | ||
* context that the host uses to determine which compilation this argument | ||
* list belongs to. | ||
* | ||
* This is marked as public so that the protofier can access it, but it's not | ||
* part of the package's public API and should not be accessed by user code. | ||
* It may be renamed or removed without warning in the future. | ||
*/ | ||
readonly compileContext: symbol | undefined; | ||
|
||
/** | ||
* The argument list's keywords. This isn't exposed directly so that we can | ||
|
@@ -54,11 +65,13 @@ export class SassArgumentList extends SassList { | |
keywords: Record<string, Value> | OrderedMap<string, Value>, | ||
separator?: ListSeparator, | ||
id?: number, | ||
compileContext?: symbol, | ||
) { | ||
super(contents, {separator}); | ||
this.keywordsInternal = isOrderedMap(keywords) | ||
? keywords | ||
: OrderedMap(keywords); | ||
this.id = id ?? 0; | ||
this.id = id; | ||
this.compileContext = compileContext; | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please document this.