[dart2wasm] Allow JS() to accept a constant template

Change-Id: I1baf01c5a5744251727d7fba2871f0b36a6a6964
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/466132
Reviewed-by: Nate Biggs <natebiggs@google.com>
Commit-Queue: Mayank Patke <fishythefish@google.com>
This commit is contained in:
Mayank Patke
2025-12-08 01:30:02 -08:00
committed by Commit Queue
parent 86ba5040d9
commit b976f6c69b
+14 -3
View File
@@ -94,9 +94,20 @@ class InlineExpander {
}
}
assert(arguments.positional[0] is StringLiteral,
"Code template must be a StringLiteral");
String codeTemplate = (arguments.positional[0] as StringLiteral).value;
Expression templateArgument = arguments.positional.first;
String codeTemplate;
if (templateArgument is StringLiteral) {
codeTemplate = templateArgument.value;
} else {
assert(templateArgument is ConstantExpression,
"Code template must be a StringLiteral or a ConstantExpression");
templateArgument as ConstantExpression;
Constant constant = templateArgument.constant;
assert(constant is StringConstant,
"Constant code template must be a StringConstant");
constant as StringConstant;
codeTemplate = constant.value;
}
String jsMethodName = _methodCollector.generateMethodName();
_inlineJSImportName = 'dart2wasm.$jsMethodName';
_replaceProcedureWithInlineJS =