Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(569)

Unified Diff: lib/src/codegen/js_codegen.dart

Issue 1522773002: Use string interpolation in JS intrinsics to simplify large templates. (Closed) Base URL: git@github.com:dart-lang/dev_compiler.git@master
Patch Set: Created 5 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | tool/input_sdk/private/utils.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: lib/src/codegen/js_codegen.dart
diff --git a/lib/src/codegen/js_codegen.dart b/lib/src/codegen/js_codegen.dart
index 09c730425d6d09c114fe9ce84777c92c259310e8..0ff3baadbffb8904081d3144b30bb3d788b64e54 100644
--- a/lib/src/codegen/js_codegen.dart
+++ b/lib/src/codegen/js_codegen.dart
@@ -1934,10 +1934,30 @@ class JSCodegenVisitor extends GeneralizingAstVisitor with ClosureAnnotator {
if (isInlineJS(e)) {
var args = node.argumentList.arguments;
// arg[0] is static return type, used in `RestrictedStaticTypeAnalyzer`
- var code = args[1] as StringLiteral;
+ var code = args[1];
+ var templateArgs;
+ var source;
+ if (code is StringInterpolation) {
+ if (args.length > 2) {
+ throw new ArgumentError(
+ "Can't mix template args and string interpolation in JS calls.");
+ }
+ templateArgs = <Expression>[];
+ source = code.elements.map((element) {
+ if (element is InterpolationExpression) {
+ templateArgs.add(element.expression);
+ return '#';
+ } else {
+ return (element as InterpolationString).value;
+ }
+ }).join();
+ } else {
+ templateArgs = args.skip(2);
+ source = (code as StringLiteral).stringValue;
+ }
- var template = js.parseForeignJS(code.stringValue);
- var result = template.instantiate(_visitList(args.skip(2)));
+ var template = js.parseForeignJS(source);
+ var result = template.instantiate(_visitList(templateArgs));
// `throw` is emitted as a statement by `parseForeignJS`.
assert(result is JS.Expression || node.parent is ExpressionStatement);
return result;
« no previous file with comments | « no previous file | tool/input_sdk/private/utils.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698