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

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

Issue 1686953005: Split Parameter and TypeParameter out of Identifier Base URL: git@github.com:dart-lang/dev_compiler.git@master
Patch Set: Created 4 years, 10 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
« no previous file with comments | « no previous file | lib/src/js/builder.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 005808114b65eefe3e35961473b15a75dcb16424..65dddc8093fa1b8fb418b5610058e18df71f9d47 100644
--- a/lib/src/codegen/js_codegen.dart
+++ b/lib/src/codegen/js_codegen.dart
@@ -466,10 +466,12 @@ class JSCodegenVisitor extends GeneralizingAstVisitor
return result;
}
- Iterable<JS.Identifier> _emitTypeParams(TypeParameterizedElement e) sync* {
+ Iterable<JS.TypeParameter> _emitTypeParams(TypeParameterizedElement e) sync* {
if (!options.closure) return;
for (var typeParam in e.typeParameters) {
- yield new JS.Identifier(typeParam.name);
+ yield new JS.TypeParameter(
+ new JS.Identifier(typeParam.name),
+ bound: emitTypeRef(typeParam.bound));
}
}
@@ -483,11 +485,10 @@ class JSCodegenVisitor extends GeneralizingAstVisitor
makeInitialization(VariableDeclaration decl) =>
new JS.VariableInitialization(
- new JS.Identifier(
- // TODO(ochafik): use a refactored _emitMemberName instead.
- decl.name.name,
- type: emitTypeRef(decl.element.type)),
- null);
+ // TODO(ochafik): use a refactored _emitMemberName instead.
+ new JS.Identifier(decl.name.name),
+ null,
+ type: emitTypeRef(decl.element.type));
for (var field in fields) {
yield new JS.VariableDeclarationList(
@@ -1211,7 +1212,7 @@ class JSCodegenVisitor extends GeneralizingAstVisitor
for (var p in ctor.parameters.parameters) {
var element = p.element;
if (element is FieldFormalParameterElement) {
- fields[element.field] = _emitFormalParameter(p, allowType: false);
+ fields[element.field] = _visit(p.identifier);
}
}
@@ -1269,7 +1270,7 @@ class JSCodegenVisitor extends GeneralizingAstVisitor
var body = <JS.Statement>[];
for (var param in parameters.parameters) {
- var jsParam = _emitSimpleIdentifier(param.identifier, allowType: false);
+ var jsParam = _visit(param.identifier);
if (param.kind == ParameterKind.NAMED) {
if (!options.destructureNamedParams) {
@@ -1336,7 +1337,8 @@ class JSCodegenVisitor extends GeneralizingAstVisitor
params.isNotEmpty) {
// []= methods need to return the value. We could also address this at
// call sites, but it's cleaner to instead transform the operator method.
- var returnValue = new JS.Return(params.last);
+ // TODO(ochafik): How do we ensure this is an expression and not a destructing pattern?
+ var returnValue = new JS.Return(params.last.binding as JS.Expression);
var body = fn.body;
if (JS.Return.foundIn(fn)) {
// If a return is inside body, transform `(params) { body }` to
@@ -1543,7 +1545,7 @@ class JSCodegenVisitor extends GeneralizingAstVisitor
}
JS.Fun _emitFunctionBody(List<JS.Parameter> params, FunctionBody body,
- List<JS.Identifier> typeParams, JS.TypeRef returnType) {
+ List<JS.TypeParameter> typeParams, JS.TypeRef returnType) {
// sync*, async, async*
if (body.isAsynchronous || body.isGenerator) {
return new JS.Fun(
@@ -1641,14 +1643,10 @@ class JSCodegenVisitor extends GeneralizingAstVisitor
]);
}
- @override
- JS.Expression visitSimpleIdentifier(SimpleIdentifier node) =>
- _emitSimpleIdentifier(node);
-
/// Writes a simple identifier. This can handle implicit `this` as well as
/// going through the qualified library name if necessary.
- JS.Expression _emitSimpleIdentifier(SimpleIdentifier node,
- {bool allowType: false}) {
+ @override
+ JS.Expression visitSimpleIdentifier(SimpleIdentifier node) {
var accessor = node.staticElement;
if (accessor == null) {
return js.commentExpression(
@@ -1717,10 +1715,7 @@ class JSCodegenVisitor extends GeneralizingAstVisitor
}
}
- return annotate(
- new JS.Identifier(name,
- type: allowType ? emitTypeRef(node.bestType) : null),
- node);
+ return annotate(new JS.Identifier(name), node);
}
JS.TemporaryId _getTemp(Element key, String name) =>
@@ -2095,13 +2090,13 @@ class JSCodegenVisitor extends GeneralizingAstVisitor
var args = <JS.Expression>[];
var named = <JS.Property>[];
for (var arg in node.arguments) {
+ var jsArg = _visit(arg);
if (arg is NamedExpression) {
- named.add(_visit(arg));
+ named.add(jsArg);
} else if (arg is MethodInvocation && isJsSpreadInvocation(arg)) {
- args.add(
- new JS.RestParameter(_visit(arg.argumentList.arguments.single)));
+ args.add(new JS.Spread(jsArg));
} else {
- args.add(_visit(arg));
+ args.add(jsArg);
}
}
if (named.isNotEmpty) {
@@ -2156,17 +2151,12 @@ class JSCodegenVisitor extends GeneralizingAstVisitor
needsOpts = true;
}
} else {
- var jsParam = _visit(param);
- result.add(
- param is DefaultFormalParameter && options.destructureNamedParams
- ? new JS.DestructuredVariable(
- name: jsParam, defaultValue: _defaultParamValue(param))
- : jsParam);
+ result.add(_visit(param));
}
}
if (needsOpts) {
- result.add(_namedArgTemp);
+ result.add(new JS.Parameter(_namedArgTemp));
} else if (namedVars.isNotEmpty) {
// Note: `var {valueOf} = {}` extracts `Object.prototype.valueOf`, so
// in case there are conflicting names we create an object without
@@ -2174,8 +2164,8 @@ class JSCodegenVisitor extends GeneralizingAstVisitor
var defaultOpts = hasNamedArgsConflictingWithObjectProperties
? js.call('Object.create(null)')
: js.call('{}');
- result.add(new JS.DestructuredVariable(
- structure: new JS.ObjectBindingPattern(namedVars),
+ result.add(new JS.Parameter(
+ new JS.ObjectBindingPattern(namedVars),
type: emitNamedParamsArgType(node.parameterElements),
defaultValue: defaultOpts));
}
@@ -2308,9 +2298,9 @@ class JSCodegenVisitor extends GeneralizingAstVisitor
return _emitTopLevelField(node);
}
- var name =
- new JS.Identifier(node.name.name, type: emitTypeRef(node.element.type));
- return new JS.VariableInitialization(name, _visitInitializer(node));
+ var name = new JS.Identifier(node.name.name);
+ return new JS.VariableInitialization(name, _visitInitializer(node),
+ type: emitTypeRef(node.element.type));
}
bool _isFinalJSDecl(AstNode field) =>
@@ -2403,9 +2393,9 @@ class JSCodegenVisitor extends GeneralizingAstVisitor
annotate(
new JS.VariableDeclarationList(declKeyword, [
new JS.VariableInitialization(
- new JS.Identifier(fieldName,
- type: emitTypeRef(field.element.type)),
- jsInit)
+ new JS.Identifier(fieldName),
+ jsInit,
+ type: emitTypeRef(field.element.type))
]),
field,
field.element)
@@ -2837,13 +2827,15 @@ class JSCodegenVisitor extends GeneralizingAstVisitor
_visit(node.expression);
@override
- visitFormalParameter(FormalParameter node) => _emitFormalParameter(node);
-
- _emitFormalParameter(FormalParameter node, {bool allowType: true}) {
- var id = _emitSimpleIdentifier(node.identifier, allowType: allowType);
-
- var isRestArg = findAnnotation(node.element, isJsRestAnnotation) != null;
- return isRestArg ? new JS.RestParameter(id) : id;
+ visitFormalParameter(FormalParameter node) {
+ var defaultValue =
+ node is DefaultFormalParameter && options.destructureNamedParams
+ ? _defaultParamValue(node) : null;
+ return new JS.Parameter(
+ _visit(node.identifier),
+ type: emitTypeRef(node.element.type),
+ defaultValue: defaultValue,
+ isRest: findAnnotation(node.element, isJsRestAnnotation) != null);
}
@override
« no previous file with comments | « no previous file | lib/src/js/builder.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698