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

Unified Diff: lib/src/js/template.dart

Issue 1029583011: [js_ast] adds Identifier that merges VariableDeclaration/Use and Parameter (Closed) Base URL: git@github.com:dart-lang/dev_compiler.git@master
Patch Set: Created 5 years, 9 months 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
« lib/src/js/printer.dart ('K') | « lib/src/js/printer.dart ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: lib/src/js/template.dart
diff --git a/lib/src/js/template.dart b/lib/src/js/template.dart
index 32ad536f6b8c5f45a0935457857f3946702ad978..b19ae4720206117e606e077c14b81080537b828e 100644
--- a/lib/src/js/template.dart
+++ b/lib/src/js/template.dart
@@ -178,19 +178,12 @@ class InstantiatorGeneratorVisitor implements NodeVisitor<Instantiator> {
throw 'Unimplemented InstantiatorGeneratorVisitor for $node';
}
- static RegExp identiferRE = new RegExp(r'^[A-Za-z_$][A-Za-z_$0-9]*$');
-
- static Expression convertStringToVariableUse(String value) {
- assert(identiferRE.hasMatch(value));
Jennifer Messerly 2015/03/25 21:29:16 this check already happens in the constructor
- return new VariableUse(value);
- }
-
Instantiator visitInterpolatedExpression(InterpolatedExpression node) {
var nameOrPosition = node.nameOrPosition;
return (arguments) {
var value = arguments[nameOrPosition];
if (value is Expression) return value;
- if (value is String) return convertStringToVariableUse(value);
+ if (value is String) return new Identifier(value);
error('Interpolated value #$nameOrPosition is not an Expression: $value');
};
}
@@ -202,7 +195,7 @@ class InstantiatorGeneratorVisitor implements NodeVisitor<Instantiator> {
var value = arguments[nameOrPosition];
Expression toExpression(item) {
if (item is Expression) return item;
- if (item is String) return convertStringToVariableUse(item);
+ if (item is String) return new Identifier(item);
return error('Interpolated value #$nameOrPosition is not '
'an Expression or List of Expressions: $value');
}
@@ -227,14 +220,14 @@ class InstantiatorGeneratorVisitor implements NodeVisitor<Instantiator> {
return (arguments) {
var value = arguments[nameOrPosition];
- Parameter toParameter(item) {
- if (item is Parameter) return item;
- if (item is String) return new Parameter(item);
- return error('Interpolated value #$nameOrPosition is not a Parameter or'
- ' List of Parameters: $value');
+ Identifier toIdentifier(item) {
+ if (item is Identifier) return item;
+ if (item is String) return new Identifier(item);
+ return error('Interpolated value #$nameOrPosition is not an Identifier'
+ ' or List of Identifiers: $value');
}
- if (value is Iterable) return value.map(toParameter);
- return toParameter(value);
+ if (value is Iterable) return value.map(toIdentifier);
+ return toIdentifier(value);
};
}
@@ -274,15 +267,14 @@ class InstantiatorGeneratorVisitor implements NodeVisitor<Instantiator> {
};
}
- Instantiator visitInterpolatedVariableDeclaration(
- InterpolatedVariableDeclaration node) {
+ Instantiator visitInterpolatedIdentifier(InterpolatedIdentifier node) {
var nameOrPosition = node.nameOrPosition;
return (arguments) {
var item = arguments[nameOrPosition];
- if (item is VariableDeclaration) return item;
- if (item is String) return new VariableDeclaration(item);
+ if (item is Identifier) return item;
+ if (item is String) return new Identifier(item);
return error('Interpolated value #$nameOrPosition is not a '
- 'VariableDeclaration or String: $item');
+ 'Identifier or String: $item');
};
}
@@ -370,7 +362,7 @@ class InstantiatorGeneratorVisitor implements NodeVisitor<Instantiator> {
var value = arguments[nameOrPosition];
if (value is bool) return value;
if (value is Expression) return value;
- if (value is String) return convertStringToVariableUse(value);;
+ if (value is String) return new Identifier(value);
error('Interpolated value #$nameOrPosition '
'is not an Expression: $value');
};
@@ -632,17 +624,11 @@ class InstantiatorGeneratorVisitor implements NodeVisitor<Instantiator> {
return (arguments) => new Postfix(op, makeOperand(arguments));
}
- Instantiator visitVariableUse(VariableUse node) =>
- (arguments) => new VariableUse(node.name);
-
Instantiator visitThis(This node) => (arguments) => new This();
Instantiator visitSuper(Super node) => (arguments) => new Super();
- Instantiator visitVariableDeclaration(VariableDeclaration node) =>
- (arguments) => new VariableDeclaration(node.name);
-
- Instantiator visitParameter(Parameter node) =>
- (arguments) => new Parameter(node.name);
+ Instantiator visitIdentifier(Identifier node) =>
+ (arguments) => new Identifier(node.name);
Instantiator visitAccess(PropertyAccess node) {
Instantiator makeReceiver = visit(node.receiver);
@@ -663,7 +649,7 @@ class InstantiatorGeneratorVisitor implements NodeVisitor<Instantiator> {
Instantiator makeBody = visit(node.body);
// TODO(sra): Avoid copying params if no interpolation or forced copying.
return (arguments) {
- List<Parameter> params = <Parameter>[];
+ List<Identifier> params = <Identifier>[];
for (Instantiator instantiator in paramMakers) {
var result = instantiator(arguments);
if (result is Iterable) {
« lib/src/js/printer.dart ('K') | « lib/src/js/printer.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698