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

Side by Side 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 unified diff | Download patch
« no previous file with comments | « no previous file | tool/input_sdk/private/utils.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 library dev_compiler.src.codegen.js_codegen; 5 library dev_compiler.src.codegen.js_codegen;
6 6
7 import 'dart:collection' show HashSet, HashMap, SplayTreeSet; 7 import 'dart:collection' show HashSet, HashMap, SplayTreeSet;
8 8
9 import 'package:analyzer/analyzer.dart' hide ConstantEvaluator; 9 import 'package:analyzer/analyzer.dart' hide ConstantEvaluator;
10 import 'package:analyzer/src/generated/ast.dart' hide ConstantEvaluator; 10 import 'package:analyzer/src/generated/ast.dart' hide ConstantEvaluator;
(...skipping 1916 matching lines...) Expand 10 before | Expand all | Expand 10 after
1927 return js.call( 1927 return js.call(
1928 code, [_visit(target), memberName, _visit(node.argumentList)]); 1928 code, [_visit(target), memberName, _visit(node.argumentList)]);
1929 } 1929 }
1930 1930
1931 /// Emits code for the `JS(...)` builtin. 1931 /// Emits code for the `JS(...)` builtin.
1932 _emitForeignJS(MethodInvocation node) { 1932 _emitForeignJS(MethodInvocation node) {
1933 var e = node.methodName.staticElement; 1933 var e = node.methodName.staticElement;
1934 if (isInlineJS(e)) { 1934 if (isInlineJS(e)) {
1935 var args = node.argumentList.arguments; 1935 var args = node.argumentList.arguments;
1936 // arg[0] is static return type, used in `RestrictedStaticTypeAnalyzer` 1936 // arg[0] is static return type, used in `RestrictedStaticTypeAnalyzer`
1937 var code = args[1] as StringLiteral; 1937 var code = args[1];
1938 var templateArgs;
1939 var source;
1940 if (code is StringInterpolation) {
1941 if (args.length > 2) {
1942 throw new ArgumentError(
1943 "Can't mix template args and string interpolation in JS calls.");
1944 }
1945 templateArgs = <Expression>[];
1946 source = code.elements.map((element) {
1947 if (element is InterpolationExpression) {
1948 templateArgs.add(element.expression);
1949 return '#';
1950 } else {
1951 return (element as InterpolationString).value;
1952 }
1953 }).join();
1954 } else {
1955 templateArgs = args.skip(2);
1956 source = (code as StringLiteral).stringValue;
1957 }
1938 1958
1939 var template = js.parseForeignJS(code.stringValue); 1959 var template = js.parseForeignJS(source);
1940 var result = template.instantiate(_visitList(args.skip(2))); 1960 var result = template.instantiate(_visitList(templateArgs));
1941 // `throw` is emitted as a statement by `parseForeignJS`. 1961 // `throw` is emitted as a statement by `parseForeignJS`.
1942 assert(result is JS.Expression || node.parent is ExpressionStatement); 1962 assert(result is JS.Expression || node.parent is ExpressionStatement);
1943 return result; 1963 return result;
1944 } 1964 }
1945 return null; 1965 return null;
1946 } 1966 }
1947 1967
1948 @override 1968 @override
1949 JS.Expression visitFunctionExpressionInvocation( 1969 JS.Expression visitFunctionExpressionInvocation(
1950 FunctionExpressionInvocation node) { 1970 FunctionExpressionInvocation node) {
(...skipping 1550 matching lines...) Expand 10 before | Expand all | Expand 10 after
3501 3521
3502 /// A special kind of element created by the compiler, signifying a temporary 3522 /// A special kind of element created by the compiler, signifying a temporary
3503 /// variable. These objects use instance equality, and should be shared 3523 /// variable. These objects use instance equality, and should be shared
3504 /// everywhere in the tree where they are treated as the same variable. 3524 /// everywhere in the tree where they are treated as the same variable.
3505 class TemporaryVariableElement extends LocalVariableElementImpl { 3525 class TemporaryVariableElement extends LocalVariableElementImpl {
3506 TemporaryVariableElement.forNode(Identifier name) : super.forNode(name); 3526 TemporaryVariableElement.forNode(Identifier name) : super.forNode(name);
3507 3527
3508 int get hashCode => identityHashCode(this); 3528 int get hashCode => identityHashCode(this);
3509 bool operator ==(Object other) => identical(this, other); 3529 bool operator ==(Object other) => identical(this, other);
3510 } 3530 }
OLDNEW
« 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