Skip to content

Commit 52d3980

Browse files
committed
Revert "feat(transformers): changes transformers to collect information about providers and resolve identifiers during linking"
This reverts commit 4e9809b.
1 parent 4e9809b commit 52d3980

45 files changed

Lines changed: 972 additions & 2417 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

modules/angular2/src/compiler/directive_metadata.ts

Lines changed: 30 additions & 90 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,13 @@
11
import {
22
isPresent,
33
isBlank,
4-
isNumber,
5-
isBoolean,
64
normalizeBool,
75
normalizeBlank,
86
serializeEnum,
97
Type,
108
isString,
119
RegExpWrapper,
12-
StringWrapper,
13-
isArray
10+
StringWrapper
1411
} from 'angular2/src/facade/lang';
1512
import {unimplemented} from 'angular2/src/facade/exceptions';
1613
import {StringMapWrapper} from 'angular2/src/facade/collection';
@@ -28,70 +25,64 @@ import {LifecycleHooks, LIFECYCLE_HOOKS_VALUES} from 'angular2/src/core/linker/i
2825
var HOST_REG_EXP = /^(?:(?:\[([^\]]+)\])|(?:\(([^\)]+)\)))$/g;
2926

3027
export abstract class CompileMetadataWithIdentifier {
28+
static fromJson(data: {[key: string]: any}): CompileMetadataWithIdentifier {
29+
return _COMPILE_METADATA_FROM_JSON[data['class']](data);
30+
}
31+
3132
abstract toJson(): {[key: string]: any};
3233

3334
get identifier(): CompileIdentifierMetadata { return <CompileIdentifierMetadata>unimplemented(); }
3435
}
3536

3637
export abstract class CompileMetadataWithType extends CompileMetadataWithIdentifier {
38+
static fromJson(data: {[key: string]: any}): CompileMetadataWithType {
39+
return _COMPILE_METADATA_FROM_JSON[data['class']](data);
40+
}
41+
3742
abstract toJson(): {[key: string]: any};
3843

3944
get type(): CompileTypeMetadata { return <CompileTypeMetadata>unimplemented(); }
4045

4146
get identifier(): CompileIdentifierMetadata { return <CompileIdentifierMetadata>unimplemented(); }
4247
}
4348

44-
export function metadataFromJson(data: {[key: string]: any}): any {
45-
return _COMPILE_METADATA_FROM_JSON[data['class']](data);
46-
}
47-
4849
export class CompileIdentifierMetadata implements CompileMetadataWithIdentifier {
4950
runtime: any;
5051
name: string;
5152
prefix: string;
5253
moduleUrl: string;
5354
constConstructor: boolean;
54-
value: any;
55-
56-
constructor({runtime, name, moduleUrl, prefix, constConstructor, value}: {
55+
constructor({runtime, name, moduleUrl, prefix, constConstructor}: {
5756
runtime?: any,
5857
name?: string,
59-
staticMethodName?: string,
6058
moduleUrl?: string,
6159
prefix?: string,
62-
constConstructor?: boolean,
63-
value?: any
60+
constConstructor?: boolean
6461
} = {}) {
6562
this.runtime = runtime;
6663
this.name = name;
6764
this.prefix = prefix;
6865
this.moduleUrl = moduleUrl;
6966
this.constConstructor = constConstructor;
70-
this.value = value;
7167
}
7268

7369
static fromJson(data: {[key: string]: any}): CompileIdentifierMetadata {
74-
let value = isArray(data['value']) ? arrayFromJson(data['value'], metadataFromJson) :
75-
objFromJson(data['value'], metadataFromJson);
7670
return new CompileIdentifierMetadata({
7771
name: data['name'],
7872
prefix: data['prefix'],
7973
moduleUrl: data['moduleUrl'],
80-
constConstructor: data['constConstructor'],
81-
value: value
74+
constConstructor: data['constConstructor']
8275
});
8376
}
8477

8578
toJson(): {[key: string]: any} {
86-
let value = isArray(this.value) ? arrayToJson(this.value) : objToJson(this.value);
8779
return {
8880
// Note: Runtime type can't be serialized...
8981
'class': 'Identifier',
9082
'name': this.name,
9183
'moduleUrl': this.moduleUrl,
9284
'prefix': this.prefix,
93-
'constConstructor': this.constConstructor,
94-
'value': value
85+
'constConstructor': this.constConstructor
9586
};
9687
}
9788

@@ -186,78 +177,44 @@ export class CompileProviderMetadata {
186177
static fromJson(data: {[key: string]: any}): CompileProviderMetadata {
187178
return new CompileProviderMetadata({
188179
token: objFromJson(data['token'], CompileIdentifierMetadata.fromJson),
189-
useClass: objFromJson(data['useClass'], CompileTypeMetadata.fromJson),
190-
useExisting: objFromJson(data['useExisting'], CompileIdentifierMetadata.fromJson),
191-
useValue: objFromJson(data['useValue'], CompileIdentifierMetadata.fromJson),
192-
useFactory: objFromJson(data['useFactory'], CompileFactoryMetadata.fromJson)
180+
useClass: objFromJson(data['useClass'], CompileTypeMetadata.fromJson)
193181
});
194182
}
195183

196184
toJson(): {[key: string]: any} {
197185
return {
198186
// Note: Runtime type can't be serialized...
199-
'class': 'Provider',
200187
'token': objToJson(this.token),
201-
'useClass': objToJson(this.useClass),
202-
'useExisting': objToJson(this.useExisting),
203-
'useValue': objToJson(this.useValue),
204-
'useFactory': objToJson(this.useFactory)
188+
'useClass': objToJson(this.useClass)
205189
};
206190
}
207191
}
208192

209-
export class CompileFactoryMetadata implements CompileIdentifierMetadata,
210-
CompileMetadataWithIdentifier {
193+
export class CompileFactoryMetadata implements CompileIdentifierMetadata {
211194
runtime: Function;
212195
name: string;
213196
prefix: string;
214197
moduleUrl: string;
215198
constConstructor: boolean;
216-
value: any;
217199
diDeps: CompileDiDependencyMetadata[];
218200

219-
constructor({runtime, name, moduleUrl, prefix, constConstructor, diDeps, value}: {
201+
constructor({runtime, name, moduleUrl, constConstructor, diDeps}: {
220202
runtime?: Function,
221203
name?: string,
222-
prefix?: string,
223204
moduleUrl?: string,
224205
constConstructor?: boolean,
225-
value?: boolean,
226206
diDeps?: CompileDiDependencyMetadata[]
227207
}) {
228208
this.runtime = runtime;
229209
this.name = name;
230-
this.prefix = prefix;
231210
this.moduleUrl = moduleUrl;
232211
this.diDeps = diDeps;
233212
this.constConstructor = constConstructor;
234-
this.value = value;
235213
}
236214

237215
get identifier(): CompileIdentifierMetadata { return this; }
238216

239-
static fromJson(data: {[key: string]: any}): CompileFactoryMetadata {
240-
return new CompileFactoryMetadata({
241-
name: data['name'],
242-
prefix: data['prefix'],
243-
moduleUrl: data['moduleUrl'],
244-
constConstructor: data['constConstructor'],
245-
value: data['value'],
246-
diDeps: arrayFromJson(data['diDeps'], CompileDiDependencyMetadata.fromJson)
247-
});
248-
}
249-
250-
toJson(): {[key: string]: any} {
251-
return {
252-
'class': 'Factory',
253-
'name': this.name,
254-
'prefix': this.prefix,
255-
'moduleUrl': this.moduleUrl,
256-
'constConstructor': this.constConstructor,
257-
'value': this.value,
258-
'diDeps': arrayToJson(this.diDeps)
259-
};
260-
}
217+
toJson() { return null; }
261218
}
262219

263220
/**
@@ -270,17 +227,15 @@ export class CompileTypeMetadata implements CompileIdentifierMetadata, CompileMe
270227
moduleUrl: string;
271228
isHost: boolean;
272229
constConstructor: boolean;
273-
value: any;
274230
diDeps: CompileDiDependencyMetadata[];
275231

276-
constructor({runtime, name, moduleUrl, prefix, isHost, constConstructor, value, diDeps}: {
232+
constructor({runtime, name, moduleUrl, prefix, isHost, constConstructor, diDeps}: {
277233
runtime?: Type,
278234
name?: string,
279235
moduleUrl?: string,
280236
prefix?: string,
281237
isHost?: boolean,
282238
constConstructor?: boolean,
283-
value?: any,
284239
diDeps?: CompileDiDependencyMetadata[]
285240
} = {}) {
286241
this.runtime = runtime;
@@ -289,7 +244,6 @@ export class CompileTypeMetadata implements CompileIdentifierMetadata, CompileMe
289244
this.prefix = prefix;
290245
this.isHost = normalizeBool(isHost);
291246
this.constConstructor = constConstructor;
292-
this.value = value;
293247
this.diDeps = normalizeBlank(diDeps);
294248
}
295249

@@ -300,7 +254,6 @@ export class CompileTypeMetadata implements CompileIdentifierMetadata, CompileMe
300254
prefix: data['prefix'],
301255
isHost: data['isHost'],
302256
constConstructor: data['constConstructor'],
303-
value: data['value'],
304257
diDeps: arrayFromJson(data['diDeps'], CompileDiDependencyMetadata.fromJson)
305258
});
306259
}
@@ -317,7 +270,6 @@ export class CompileTypeMetadata implements CompileIdentifierMetadata, CompileMe
317270
'prefix': this.prefix,
318271
'isHost': this.isHost,
319272
'constConstructor': this.constConstructor,
320-
'value': this.value,
321273
'diDeps': arrayToJson(this.diDeps)
322274
};
323275
}
@@ -430,10 +382,8 @@ export class CompileDirectiveMetadata implements CompileMetadataWithType {
430382
outputs?: string[],
431383
host?: {[key: string]: string},
432384
lifecycleHooks?: LifecycleHooks[],
433-
providers?:
434-
Array<CompileProviderMetadata | CompileTypeMetadata | CompileIdentifierMetadata | any[]>,
435-
viewProviders?:
436-
Array<CompileProviderMetadata | CompileTypeMetadata | CompileIdentifierMetadata | any[]>,
385+
providers?: Array<CompileProviderMetadata | CompileTypeMetadata | any[]>,
386+
viewProviders?: Array<CompileProviderMetadata | CompileTypeMetadata | any[]>,
437387
queries?: CompileQueryMetadata[],
438388
viewQueries?: CompileQueryMetadata[],
439389
template?: CompileTemplateMetadata
@@ -524,10 +474,8 @@ export class CompileDirectiveMetadata implements CompileMetadataWithType {
524474
hostProperties?: {[key: string]: string},
525475
hostAttributes?: {[key: string]: string},
526476
lifecycleHooks?: LifecycleHooks[],
527-
providers?:
528-
Array<CompileProviderMetadata | CompileTypeMetadata | CompileIdentifierMetadata | any[]>,
529-
viewProviders?:
530-
Array<CompileProviderMetadata | CompileTypeMetadata | CompileIdentifierMetadata | any[]>,
477+
providers?: Array<CompileProviderMetadata | CompileTypeMetadata | any[]>,
478+
viewProviders?: Array<CompileProviderMetadata | CompileTypeMetadata | any[]>,
531479
queries?: CompileQueryMetadata[],
532480
viewQueries?: CompileQueryMetadata[],
533481
template?: CompileTemplateMetadata
@@ -546,8 +494,8 @@ export class CompileDirectiveMetadata implements CompileMetadataWithType {
546494
this.lifecycleHooks = lifecycleHooks;
547495
this.providers = normalizeBlank(providers);
548496
this.viewProviders = normalizeBlank(viewProviders);
549-
this.queries = normalizeBlank(queries);
550-
this.viewQueries = normalizeBlank(viewQueries);
497+
this.queries = queries;
498+
this.viewQueries = viewQueries;
551499
this.template = template;
552500
}
553501

@@ -572,10 +520,7 @@ export class CompileDirectiveMetadata implements CompileMetadataWithType {
572520
(<any[]>data['lifecycleHooks']).map(hookValue => LIFECYCLE_HOOKS_VALUES[hookValue]),
573521
template: isPresent(data['template']) ? CompileTemplateMetadata.fromJson(data['template']) :
574522
data['template'],
575-
providers: arrayFromJson(data['providers'], metadataFromJson),
576-
viewProviders: arrayFromJson(data['viewProviders'], metadataFromJson),
577-
queries: arrayFromJson(data['queries'], CompileQueryMetadata.fromJson),
578-
viewQueries: arrayFromJson(data['viewQueries'], CompileQueryMetadata.fromJson)
523+
providers: arrayFromJson(data['providers'], CompileProviderMetadata.fromJson)
579524
});
580525
}
581526

@@ -596,10 +541,7 @@ export class CompileDirectiveMetadata implements CompileMetadataWithType {
596541
'hostAttributes': this.hostAttributes,
597542
'lifecycleHooks': this.lifecycleHooks.map(hook => serializeEnum(hook)),
598543
'template': isPresent(this.template) ? this.template.toJson() : this.template,
599-
'providers': arrayToJson(this.providers),
600-
'viewProviders': arrayToJson(this.viewProviders),
601-
'queries': arrayToJson(this.queries),
602-
'viewQueries': arrayToJson(this.viewQueries)
544+
'providers': arrayToJson(this.providers)
603545
};
604546
}
605547
}
@@ -669,9 +611,7 @@ var _COMPILE_METADATA_FROM_JSON = {
669611
'Directive': CompileDirectiveMetadata.fromJson,
670612
'Pipe': CompilePipeMetadata.fromJson,
671613
'Type': CompileTypeMetadata.fromJson,
672-
'Provider': CompileProviderMetadata.fromJson,
673-
'Identifier': CompileIdentifierMetadata.fromJson,
674-
'Factory': CompileFactoryMetadata.fromJson
614+
'Identifier': CompileIdentifierMetadata.fromJson
675615
};
676616

677617
function arrayFromJson(obj: any[], fn: (a: {[key: string]: any}) => any): any {
@@ -683,9 +623,9 @@ function arrayToJson(obj: any[]): string | {[key: string]: any} {
683623
}
684624

685625
function objFromJson(obj: any, fn: (a: {[key: string]: any}) => any): any {
686-
return (isString(obj) || isBlank(obj) || isBoolean(obj) || isNumber(obj)) ? obj : fn(obj);
626+
return (isString(obj) || isBlank(obj)) ? obj : fn(obj);
687627
}
688628

689629
function objToJson(obj: any): string | {[key: string]: any} {
690-
return (isString(obj) || isBlank(obj) || isBoolean(obj) || isNumber(obj)) ? obj : obj.toJson();
630+
return (isString(obj) || isBlank(obj)) ? obj : obj.toJson();
691631
}

modules/angular2/src/compiler/template_compiler.ts

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -110,9 +110,6 @@ export class TemplateCompiler {
110110
hostAttributes: directive.hostAttributes,
111111
lifecycleHooks: directive.lifecycleHooks,
112112
providers: directive.providers,
113-
viewProviders: directive.viewProviders,
114-
queries: directive.queries,
115-
viewQueries: directive.viewQueries,
116113
template: normalizedTemplate
117114
}));
118115
}

modules/angular2/src/facade/lang.dart

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@ bool isStringMap(Object obj) => obj is Map;
3333
bool isArray(Object obj) => obj is List;
3434
bool isPromise(Object obj) => obj is Future;
3535
bool isNumber(Object obj) => obj is num;
36-
bool isBoolean(Object obj) => obj is bool;
3736
bool isDate(Object obj) => obj is DateTime;
3837

3938
String stringify(obj) {

modules/angular2/src/facade/lang.ts

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -124,14 +124,6 @@ export function isBlank(obj: any): boolean {
124124
return obj === undefined || obj === null;
125125
}
126126

127-
export function isBoolean(obj: any): boolean {
128-
return typeof obj === "boolean";
129-
}
130-
131-
export function isNumber(obj: any): boolean {
132-
return typeof obj === "number";
133-
}
134-
135127
export function isString(obj: any): boolean {
136128
return typeof obj === "string";
137129
}
@@ -156,6 +148,10 @@ export function isArray(obj: any): boolean {
156148
return Array.isArray(obj);
157149
}
158150

151+
export function isNumber(obj): boolean {
152+
return typeof obj === 'number';
153+
}
154+
159155
export function isDate(obj): boolean {
160156
return obj instanceof Date && !isNaN(obj.valueOf());
161157
}

0 commit comments

Comments
 (0)