11library angular2.src.compiler.view_compiler.compile_element;
22
3- import "package:angular2/src/facade/exceptions.dart" show BaseException;
43import "../output/output_ast.dart" as o;
54import "../identifiers.dart" show Identifiers, identifierToken;
65import "constants.dart" show InjectMethodVars;
@@ -28,7 +27,6 @@ import "util.dart"
2827import "compile_query.dart"
2928 show CompileQuery, createQueryList, addQueryToTokenMap;
3029import "compile_method.dart" show CompileMethod;
31- import "../util.dart" show ValueTransformer, visitValue;
3230
3331class CompileNode {
3432 CompileElement parent;
@@ -106,7 +104,6 @@ class CompileElement extends CompileNode {
106104 _createAppElement () {
107105 var fieldName = '''_appEl_${ this . nodeIndex }''' ;
108106 var parentNodeIndex = this .isRootElement () ? null : this .parent.nodeIndex;
109- // private is fine here as no child view will reference an AppElement
110107 this .view.fields.add (new o.ClassField (fieldName,
111108 o.importType (Identifiers .AppElement ), [o.StmtModifier .Private ]));
112109 var statement = o.THIS_EXPR
@@ -190,7 +187,13 @@ class CompileElement extends CompileNode {
190187 .importExpr (provider.useClass)
191188 .instantiate (depsExpr, o.importType (provider.useClass));
192189 } else {
193- return _convertValueToOutputAst (provider.useValue);
190+ if (provider.useValue is CompileIdentifierMetadata ) {
191+ return o.importExpr (provider.useValue);
192+ } else if (provider.useValue is o.Expression ) {
193+ return provider.useValue;
194+ } else {
195+ return o.literal (provider.useValue);
196+ }
194197 }
195198 }).toList ();
196199 var propName =
@@ -465,12 +468,13 @@ o.Expression createProviderProperty(
465468 type = o.DYNAMIC_TYPE ;
466469 }
467470 if (isEager) {
468- view.fields.add (new o.ClassField (propName, type));
471+ view.fields.add (new o.ClassField (propName, type, [o. StmtModifier . Private ] ));
469472 view.createMethod.addStmt (
470473 o.THIS_EXPR .prop (propName).set (resolvedProviderValueExpr).toStmt ());
471474 } else {
472475 var internalField = '''_${ propName }''' ;
473- view.fields.add (new o.ClassField (internalField, type));
476+ view.fields
477+ .add (new o.ClassField (internalField, type, [o.StmtModifier .Private ]));
474478 var getter = new CompileMethod (view);
475479 getter.resetDebugInfo (compileElement.nodeIndex, compileElement.sourceAst);
476480 // Note: Equals is important for JS so that it also checks the undefined case!
@@ -490,37 +494,3 @@ class _QueryWithRead {
490494 this .read = isPresent (query.meta.read) ? query.meta.read : match;
491495 }
492496}
493-
494- o.Expression _convertValueToOutputAst (dynamic value) {
495- return visitValue (value, new _ValueOutputAstTransformer (), null );
496- }
497-
498- class _ValueOutputAstTransformer extends ValueTransformer {
499- o.Expression visitArray (List <dynamic > arr, dynamic context) {
500- return o.literalArr (
501- arr.map ((value) => visitValue (value, this , context)).toList ());
502- }
503-
504- o.Expression visitStringMap (Map <String , dynamic > map, dynamic context) {
505- var entries = [];
506- StringMapWrapper .forEach (map, (value, key) {
507- entries.add ([key, visitValue (value, this , context)]);
508- });
509- return o.literalMap (entries);
510- }
511-
512- o.Expression visitPrimitive (dynamic value, dynamic context) {
513- return o.literal (value);
514- }
515-
516- o.Expression visitOther (dynamic value, dynamic context) {
517- if (value is CompileIdentifierMetadata ) {
518- return o.importExpr (value);
519- } else if (value is o.Expression ) {
520- return value;
521- } else {
522- throw new BaseException (
523- '''Illegal state: Don\' t now how to compile value ${ value }''' );
524- }
525- }
526- }
0 commit comments