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

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: 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 | « lib/src/js/printer.dart ('k') | test/codegen/expect/closure.js » ('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) 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 212 matching lines...) Expand 10 before | Expand all | Expand 10 after
223 if (value is Literal) return value; 223 if (value is Literal) return value;
224 error('Interpolated value #$nameOrPosition is not a Literal: $value'); 224 error('Interpolated value #$nameOrPosition is not a Literal: $value');
225 }; 225 };
226 } 226 }
227 227
228 Instantiator visitInterpolatedParameter(InterpolatedParameter node) { 228 Instantiator visitInterpolatedParameter(InterpolatedParameter node) {
229 var nameOrPosition = node.nameOrPosition; 229 var nameOrPosition = node.nameOrPosition;
230 return (arguments) { 230 return (arguments) {
231 var value = arguments[nameOrPosition]; 231 var value = arguments[nameOrPosition];
232 232
233 Identifier toIdentifier(item) { 233 Parameter toIdentifier(item) {
234 if (item is Identifier) return item; 234 if (item is Parameter) return item;
235 if (item is String) return new Identifier(item); 235 if (item is String) return new Identifier(item);
236 return error('Interpolated value #$nameOrPosition is not an Identifier' 236 return error('Interpolated value #$nameOrPosition is not an Identifier'
237 ' or List of Identifiers: $value'); 237 ' or List of Identifiers: $value');
238 } 238 }
239 if (value is Iterable) return value.map(toIdentifier); 239 if (value is Iterable) return value.map(toIdentifier);
240 return toIdentifier(value); 240 return toIdentifier(value);
241 }; 241 };
242 } 242 }
243 243
244 Instantiator visitInterpolatedSelector(InterpolatedSelector node) { 244 Instantiator visitInterpolatedSelector(InterpolatedSelector node) {
(...skipping 574 matching lines...) Expand 10 before | Expand all | Expand 10 after
819 throw new UnimplementedError(); 819 throw new UnimplementedError();
820 820
821 Instantiator visitImportDeclaration(ImportDeclaration node) => 821 Instantiator visitImportDeclaration(ImportDeclaration node) =>
822 throw new UnimplementedError(); 822 throw new UnimplementedError();
823 823
824 Instantiator visitExportDeclaration(ExportDeclaration node) => 824 Instantiator visitExportDeclaration(ExportDeclaration node) =>
825 throw new UnimplementedError(); 825 throw new UnimplementedError();
826 826
827 Instantiator visitExportClause(ExportClause node) => 827 Instantiator visitExportClause(ExportClause node) =>
828 throw new UnimplementedError(); 828 throw new UnimplementedError();
829
830 @override
831 Instantiator visitDestructuredVariable(DestructuredVariable node) {
832 Instantiator makeName = visit(node.name);
833 Instantiator makeStructure = visit(node.structure);
834 Instantiator makeDefaultValue = visit(node.defaultValue);
835 return (arguments) {
836 return new DestructuredVariable(
837 name: makeName(arguments),
838 structure: makeStructure(arguments),
839 defaultValue: makeDefaultValue(arguments));
840 };
841 }
842
843 @override
844 Instantiator visitArrayBindingPattern(ArrayBindingPattern node) {
845 List<Instantiator> makeVars = node.variables.map(this.visit).toList();
846 return (arguments) {
847 return new ArrayBindingPattern(
848 makeVars.map((m) => m(arguments)).toList());
849 };
850 }
851
852 @override
853 Instantiator visitObjectBindingPattern(ObjectBindingPattern node) {
854 List<Instantiator> makeVars = node.variables.map(this.visit).toList();
855 return (arguments) {
856 return new ObjectBindingPattern(
857 makeVars.map((m) => m(arguments)).toList());
858 };
859 }
829 } 860 }
830 861
831 /** 862 /**
832 * InterpolatedNodeAnalysis determines which AST trees contain 863 * InterpolatedNodeAnalysis determines which AST trees contain
833 * [InterpolatedNode]s, and the names of the named interpolated nodes. 864 * [InterpolatedNode]s, and the names of the named interpolated nodes.
834 */ 865 */
835 class InterpolatedNodeAnalysis extends BaseVisitor { 866 class InterpolatedNodeAnalysis extends BaseVisitor {
836 final Set<Node> containsInterpolatedNode = new Set<Node>(); 867 final Set<Node> containsInterpolatedNode = new Set<Node>();
837 final Set<String> holeNames = new Set<String>(); 868 final Set<String> holeNames = new Set<String>();
838 int count = 0; 869 int count = 0;
(...skipping 13 matching lines...) Expand all
852 if (count != before) containsInterpolatedNode.add(node); 883 if (count != before) containsInterpolatedNode.add(node);
853 return null; 884 return null;
854 } 885 }
855 886
856 visitInterpolatedNode(InterpolatedNode node) { 887 visitInterpolatedNode(InterpolatedNode node) {
857 containsInterpolatedNode.add(node); 888 containsInterpolatedNode.add(node);
858 if (node.isNamed) holeNames.add(node.nameOrPosition); 889 if (node.isNamed) holeNames.add(node.nameOrPosition);
859 ++count; 890 ++count;
860 } 891 }
861 } 892 }
OLDNEW
« no previous file with comments | « lib/src/js/printer.dart ('k') | test/codegen/expect/closure.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698