Skip to content

Commit 1144eb1

Browse files
committed
f5f0038 fix(typescript): strip abstract keyword from properties in .d.ts
1 parent 90b5f7f commit 1144eb1

File tree

15 files changed

+34
-175
lines changed

15 files changed

+34
-175
lines changed

BUILD_INFO

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
Sun May 1 02:40:58 UTC 2016
2-
ad24e01949175336ee6deda8ce2418fb5334a93c
1+
Sun May 1 02:50:49 UTC 2016
2+
f5f0038e03d4003effb7d0f7b42b6e919cb2f317

lib/src/compiler/metadata_resolver.dart

Lines changed: 4 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,7 @@ import "package:angular2/src/core/reflection/reflection.dart" show reflector;
2828
import "package:angular2/src/core/di.dart" show Injectable, Inject, Optional;
2929
import "package:angular2/src/core/platform_directives_and_pipes.dart"
3030
show PLATFORM_DIRECTIVES, PLATFORM_PIPES;
31-
import "util.dart"
32-
show MODULE_SUFFIX, sanitizeIdentifier, ValueTransformer, visitValue;
31+
import "util.dart" show MODULE_SUFFIX, sanitizeIdentifier;
3332
import "assertions.dart" show assertArrayOfStrings;
3433
import "package:angular2/src/compiler/url_resolver.dart" show getUrlScheme;
3534
import "package:angular2/src/core/di/provider.dart" show Provider;
@@ -326,7 +325,9 @@ class CompileMetadataResolver {
326325
? this.getTypeMetadata(
327326
provider.useClass, staticTypeModuleUrl(provider.useClass))
328327
: null,
329-
useValue: convertToCompileValue(provider.useValue),
328+
useValue: isPresent(provider.useValue)
329+
? new cpl.CompileIdentifierMetadata(runtime: provider.useValue)
330+
: null,
330331
useFactory: isPresent(provider.useFactory)
331332
? this.getFactoryMetadata(
332333
provider.useFactory, staticTypeModuleUrl(provider.useFactory))
@@ -431,19 +432,3 @@ String calcTemplateBaseUrl(
431432
}
432433
return reflector.importUri(type);
433434
}
434-
435-
// Only fill CompileIdentifierMetadata.runtime if needed...
436-
dynamic convertToCompileValue(dynamic value) {
437-
return visitValue(value, new _CompileValueConverter(), null);
438-
}
439-
440-
class _CompileValueConverter extends ValueTransformer {
441-
dynamic visitOther(dynamic value, dynamic context) {
442-
if (isStaticType(value)) {
443-
return new cpl.CompileIdentifierMetadata(
444-
name: value["name"], moduleUrl: staticTypeModuleUrl(value));
445-
} else {
446-
return new cpl.CompileIdentifierMetadata(runtime: value);
447-
}
448-
}
449-
}

lib/src/compiler/output/dart_emitter.dart

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -372,10 +372,6 @@ class _DartEmitterVisitor extends AbstractEmitterVisitor
372372

373373
void _visitIdentifier(CompileIdentifierMetadata value,
374374
List<o.Type> typeParams, EmitterVisitorContext ctx) {
375-
if (isBlank(value.name)) {
376-
throw new BaseException(
377-
'''Internal error: unknown identifier ${ value}''');
378-
}
379375
if (isPresent(value.moduleUrl) && value.moduleUrl != this._moduleUrl) {
380376
var prefix = this.importsWithPrefixes[value.moduleUrl];
381377
if (isBlank(prefix)) {

lib/src/compiler/output/js_emitter.dart

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ import "package:angular2/src/facade/lang.dart"
99
evalExpression,
1010
RegExpWrapper,
1111
StringWrapper;
12-
import "package:angular2/src/facade/exceptions.dart" show BaseException;
1312
import "abstract_emitter.dart" show OutputEmitter, EmitterVisitorContext;
1413
import "abstract_js_emitter.dart" show AbstractJsEmitterVisitor;
1514
import "path_util.dart" show getImportModulePath, ImportEnv;
@@ -39,10 +38,6 @@ class JsEmitterVisitor extends AbstractJsEmitterVisitor {
3938
/* super call moved to initializer */;
4039
}
4140
dynamic visitExternalExpr(o.ExternalExpr ast, EmitterVisitorContext ctx) {
42-
if (isBlank(ast.value.name)) {
43-
throw new BaseException(
44-
'''Internal error: unknown identifier ${ ast . value}''');
45-
}
4641
if (isPresent(ast.value.moduleUrl) &&
4742
ast.value.moduleUrl != this._moduleUrl) {
4843
var prefix = this.importsWithPrefixes[ast.value.moduleUrl];

lib/src/compiler/output/ts_emitter.dart

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -330,10 +330,6 @@ class _TsEmitterVisitor extends AbstractEmitterVisitor
330330

331331
void _visitIdentifier(CompileIdentifierMetadata value,
332332
List<o.Type> typeParams, EmitterVisitorContext ctx) {
333-
if (isBlank(value.name)) {
334-
throw new BaseException(
335-
'''Internal error: unknown identifier ${ value}''');
336-
}
337333
if (isPresent(value.moduleUrl) && value.moduleUrl != this._moduleUrl) {
338334
var prefix = this.importsWithPrefixes[value.moduleUrl];
339335
if (isBlank(prefix)) {

lib/src/compiler/util.dart

Lines changed: 1 addition & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,7 @@
11
library angular2.src.compiler.util;
22

33
import "package:angular2/src/facade/lang.dart"
4-
show
5-
IS_DART,
6-
StringWrapper,
7-
Math,
8-
isBlank,
9-
isArray,
10-
isStrictStringMap,
11-
isPrimitive;
12-
import "package:angular2/src/facade/collection.dart" show StringMapWrapper;
4+
show IS_DART, StringWrapper, Math, isBlank;
135

146
var MODULE_SUFFIX = IS_DART ? ".dart" : "";
157
var CAMEL_CASE_REGEXP = new RegExp(r'([A-Z])');
@@ -38,44 +30,3 @@ List<String> splitAtColon(String input, List<String> defaultValues) {
3830
String sanitizeIdentifier(String name) {
3931
return StringWrapper.replaceAll(name, new RegExp(r'\W'), "_");
4032
}
41-
42-
dynamic visitValue(dynamic value, ValueVisitor visitor, dynamic context) {
43-
if (isArray(value)) {
44-
return visitor.visitArray((value as List<dynamic>), context);
45-
} else if (isStrictStringMap(value)) {
46-
return visitor.visitStringMap((value as Map<String, dynamic>), context);
47-
} else if (isBlank(value) || isPrimitive(value)) {
48-
return visitor.visitPrimitive(value, context);
49-
} else {
50-
return visitor.visitOther(value, context);
51-
}
52-
}
53-
54-
abstract class ValueVisitor {
55-
dynamic visitArray(List<dynamic> arr, dynamic context);
56-
dynamic visitStringMap(Map<String, dynamic> map, dynamic context);
57-
dynamic visitPrimitive(dynamic value, dynamic context);
58-
dynamic visitOther(dynamic value, dynamic context);
59-
}
60-
61-
class ValueTransformer implements ValueVisitor {
62-
dynamic visitArray(List<dynamic> arr, dynamic context) {
63-
return arr.map((value) => visitValue(value, this, context)).toList();
64-
}
65-
66-
dynamic visitStringMap(Map<String, dynamic> map, dynamic context) {
67-
var result = {};
68-
StringMapWrapper.forEach(map, (value, key) {
69-
result[key] = visitValue(value, this, context);
70-
});
71-
return result;
72-
}
73-
74-
dynamic visitPrimitive(dynamic value, dynamic context) {
75-
return value;
76-
}
77-
78-
dynamic visitOther(dynamic value, dynamic context) {
79-
return value;
80-
}
81-
}

lib/src/compiler/view_compiler/compile_element.dart

Lines changed: 10 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
library angular2.src.compiler.view_compiler.compile_element;
22

3-
import "package:angular2/src/facade/exceptions.dart" show BaseException;
43
import "../output/output_ast.dart" as o;
54
import "../identifiers.dart" show Identifiers, identifierToken;
65
import "constants.dart" show InjectMethodVars;
@@ -28,7 +27,6 @@ import "util.dart"
2827
import "compile_query.dart"
2928
show CompileQuery, createQueryList, addQueryToTokenMap;
3029
import "compile_method.dart" show CompileMethod;
31-
import "../util.dart" show ValueTransformer, visitValue;
3230

3331
class 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-
}

lib/src/compiler/view_compiler/compile_pipe.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,8 @@ class CompilePipe {
3838
}
3939
return injectFromViewParentInjector(diDep.token, false);
4040
}).toList();
41-
this.view.fields.add(
42-
new o.ClassField(this.instance.name, o.importType(this.meta.type)));
41+
this.view.fields.add(new o.ClassField(this.instance.name,
42+
o.importType(this.meta.type), [o.StmtModifier.Private]));
4343
this.view.createMethod.resetDebugInfo(null, null);
4444
this.view.createMethod.addStmt(o.THIS_EXPR
4545
.prop(this.instance.name)

lib/src/compiler/view_compiler/compile_query.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -109,8 +109,8 @@ o.Expression createQueryList(
109109
o.Expression directiveInstance,
110110
String propertyName,
111111
CompileView compileView) {
112-
compileView.fields
113-
.add(new o.ClassField(propertyName, o.importType(Identifiers.QueryList)));
112+
compileView.fields.add(new o.ClassField(propertyName,
113+
o.importType(Identifiers.QueryList), [o.StmtModifier.Private]));
114114
var expr = o.THIS_EXPR.prop(propertyName);
115115
compileView.createMethod.addStmt(o.THIS_EXPR
116116
.prop(propertyName)

lib/src/compiler/view_compiler/event_binder.dart

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,6 @@ class CompileEventListener {
9292
markPathToRootStart.callMethod("markPathToRootAsCheckOnce", []).toStmt()
9393
]))..addAll(this._method.finish())))
9494
..addAll([new o.ReturnStatement(resultExpr)]));
95-
// private is fine here as no child view will reference the event handler...
9695
this.compileElement.view.eventHandlerMethods.add(new o.ClassMethod(
9796
this._methodName,
9897
[this._eventParam],
@@ -124,7 +123,6 @@ class CompileEventListener {
124123
var disposable = o.variable(
125124
'''disposable_${ this . compileElement . view . disposables . length}''');
126125
this.compileElement.view.disposables.add(disposable);
127-
// private is fine here as no child view will reference the event handler...
128126
this.compileElement.view.createMethod.addStmt(disposable
129127
.set(listenExpr)
130128
.toDeclStmt(o.FUNCTION_TYPE, [o.StmtModifier.Private]));

0 commit comments

Comments
 (0)