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

Side by Side Diff: lib/src/js/template.dart

Issue 1484263002: Use destructuring assignments for named parameters (#180) (Closed) Base URL: git@github.com:dart-lang/dev_compiler.git@master
Patch Set: Destructure function params directly (no more opts in most cases) 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
OLDNEW
1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2014, 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 part of js_ast; 5 part of js_ast;
6 6
7 class TemplateManager { 7 class TemplateManager {
8 Map<String, Template> expressionTemplates = new Map<String, Template>(); 8 Map<String, Template> expressionTemplates = new Map<String, Template>();
9 Map<String, Template> statementTemplates = new Map<String, Template>(); 9 Map<String, Template> statementTemplates = new Map<String, Template>();
10 10
(...skipping 211 matching lines...) Expand 10 before | Expand all | Expand 10 after
222 if (value is Literal) return value; 222 if (value is Literal) return value;
223 error('Interpolated value #$nameOrPosition is not a Literal: $value'); 223 error('Interpolated value #$nameOrPosition is not a Literal: $value');
224 }; 224 };
225 } 225 }
226 226
227 Instantiator visitInterpolatedParameter(InterpolatedParameter node) { 227 Instantiator visitInterpolatedParameter(InterpolatedParameter node) {
228 var nameOrPosition = node.nameOrPosition; 228 var nameOrPosition = node.nameOrPosition;
229 return (arguments) { 229 return (arguments) {
230 var value = arguments[nameOrPosition]; 230 var value = arguments[nameOrPosition];
231 231
232 Identifier toIdentifier(item) { 232 Parameter toIdentifier(item) {
233 if (item is Identifier) return item; 233 if (item is Parameter) return item;
234 if (item is String) return new Identifier(item); 234 if (item is String) return new Identifier(item);
235 return error('Interpolated value #$nameOrPosition is not an Identifier' 235 return error('Interpolated value #$nameOrPosition ($item: ${item?.runtim eType}) is not an Identifier'
Jennifer Messerly 2015/12/01 02:10:27 long line. also, printing the item & runtime type
ochafik 2015/12/02 20:05:47 Done.
236 ' or List of Identifiers: $value'); 236 ' or List of Identifiers: $value');
237 } 237 }
238 if (value is Iterable) return value.map(toIdentifier); 238 if (value is Iterable) return value.map(toIdentifier);
239 return toIdentifier(value); 239 return toIdentifier(value);
240 }; 240 };
241 } 241 }
242 242
243 Instantiator visitInterpolatedSelector(InterpolatedSelector node) { 243 Instantiator visitInterpolatedSelector(InterpolatedSelector node) {
244 // A selector is an expression, as in `a[selector]`. 244 // A selector is an expression, as in `a[selector]`.
245 // A String argument converted into a LiteralString, so `a.#` with argument 245 // A String argument converted into a LiteralString, so `a.#` with argument
(...skipping 571 matching lines...) Expand 10 before | Expand all | Expand 10 after
817 return new CommentExpression(node.comment, makeExpr(arguments)); 817 return new CommentExpression(node.comment, makeExpr(arguments));
818 }; 818 };
819 } 819 }
820 820
821 Instantiator visitAwait(Await node) { 821 Instantiator visitAwait(Await node) {
822 Instantiator makeExpression = visit(node.expression); 822 Instantiator makeExpression = visit(node.expression);
823 return (arguments) { 823 return (arguments) {
824 return new Await(makeExpression(arguments)); 824 return new Await(makeExpression(arguments));
825 }; 825 };
826 } 826 }
827
828 @override
829 Instantiator visitDestructuredVariable(DestructuredVariable node) {
830 Instantiator makeName = visit(node.name);
831 Instantiator makeStructure = visit(node.structure);
832 Instantiator makeDefaultValue = visit(node.defaultValue);
833 return (arguments) {
834 return new DestructuredVariable(
835 makeName(arguments),
836 makeStructure(arguments),
837 makeDefaultValue(arguments));
838 };
839 }
840
841 @override
842 Instantiator visitArrayDestructuring(ArrayDestructuring node) {
843 List<Instantiator> makeVars = node.variables.map(this.visit).toList();
844 return (arguments) {
845 return new ArrayDestructuring(makeVars.map((m) => m(arguments)).toList());
846 };
847 }
848
849 @override
850 Instantiator visitObjectDestructuring(ObjectDestructuring node) {
851 List<Instantiator> makeVars = node.variables.map(this.visit).toList();
852 return (arguments) {
853 return new ObjectDestructuring(makeVars.map((m) => m(arguments)).toList()) ;
Jennifer Messerly 2015/12/01 02:10:28 long line
ochafik 2015/12/02 20:05:47 Done.
854 };
855 }
827 } 856 }
828 857
829 /** 858 /**
830 * InterpolatedNodeAnalysis determines which AST trees contain 859 * InterpolatedNodeAnalysis determines which AST trees contain
831 * [InterpolatedNode]s, and the names of the named interpolated nodes. 860 * [InterpolatedNode]s, and the names of the named interpolated nodes.
832 */ 861 */
833 class InterpolatedNodeAnalysis extends BaseVisitor { 862 class InterpolatedNodeAnalysis extends BaseVisitor {
834 final Set<Node> containsInterpolatedNode = new Set<Node>(); 863 final Set<Node> containsInterpolatedNode = new Set<Node>();
835 final Set<String> holeNames = new Set<String>(); 864 final Set<String> holeNames = new Set<String>();
836 int count = 0; 865 int count = 0;
(...skipping 13 matching lines...) Expand all
850 if (count != before) containsInterpolatedNode.add(node); 879 if (count != before) containsInterpolatedNode.add(node);
851 return null; 880 return null;
852 } 881 }
853 882
854 visitInterpolatedNode(InterpolatedNode node) { 883 visitInterpolatedNode(InterpolatedNode node) {
855 containsInterpolatedNode.add(node); 884 containsInterpolatedNode.add(node);
856 if (node.isNamed) holeNames.add(node.nameOrPosition); 885 if (node.isNamed) holeNames.add(node.nameOrPosition);
857 ++count; 886 ++count;
858 } 887 }
859 } 888 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698