| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 176e559 commit 15f6b27
2 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -7,7 +7,6 @@ import { | |||
| 7 | 7 | isStringMap, | |
| 8 | 8 | FunctionWrapper | |
| 9 | 9 | } from 'angular2/src/facade/lang'; | |
| 10 | - import {BaseException} from 'angular2/src/facade/exceptions'; | ||
| 11 | 10 | import { | |
| 12 | 11 | AttributeMetadata, | |
| 13 | 12 | DirectiveMetadata, | |
@@ -35,11 +34,6 @@ import { | |||
| 35 | 34 | SkipSelfMetadata, | |
| 36 | 35 | InjectMetadata, | |
| 37 | 36 | } from "angular2/src/core/di/metadata"; | |
| 38 | - import {OpaqueToken} from 'angular2/src/core/di/opaque_token'; | ||
| 39 | - | ||
| 40 | - export class ModuleContext { | ||
| 41 | - constructor(public moduleId: string, public filePath: string) {} | ||
| 42 | - } | ||
| 43 | 37 | ||
| 44 | 38 | /** | |
| 45 | 39 | * The host of the static resolver is expected to be able to provide module metadata in the form of | |
@@ -71,7 +65,7 @@ export interface StaticReflectorHost { | |||
| 71 | 65 | * | |
| 72 | 66 | * This token is unique for a moduleId and name and can be used as a hash table key. | |
| 73 | 67 | */ | |
| 74 | - export class StaticSymbol implements ModuleContext { | ||
| 68 | + export class StaticSymbol { | ||
| 75 | 69 | constructor(public moduleId: string, public filePath: string, public name: string) {} | |
| 76 | 70 | } | |
| 77 | 71 | ||
@@ -84,8 +78,7 @@ export class StaticReflector implements ReflectorReader { | |||
| 84 | 78 | private propertyCache = new Map<StaticSymbol, {[key: string]: any}>(); | |
| 85 | 79 | private parameterCache = new Map<StaticSymbol, any[]>(); | |
| 86 | 80 | private metadataCache = new Map<string, {[key: string]: any}>(); | |
| 87 | - private conversionMap = | ||
| 88 | - new Map<StaticSymbol, (moduleContext: ModuleContext, args: any[]) => any>(); | ||
| 81 | + private conversionMap = new Map<StaticSymbol, (context: StaticSymbol, args: any[]) => any>(); | ||
| 89 | 82 | ||
| 90 | 83 | constructor(private host: StaticReflectorHost) { this.initializeConversionMap(); } | |
| 91 | 84 | ||
@@ -155,22 +148,20 @@ export class StaticReflector implements ReflectorReader { | |||
| 155 | 148 | } | |
| 156 | 149 | return parameters; | |
| 157 | 150 | } catch (e) { | |
| 158 | - console.error('Failed on type', type, 'with error', e); | ||
| 151 | + console.log(`Failed on type ${type} with error ${e}`); | ||
| 159 | 152 | throw e; | |
| 160 | 153 | } | |
| 161 | 154 | } | |
| 162 | 155 | ||
| 163 | 156 | private registerDecoratorOrConstructor(type: StaticSymbol, ctor: any): void { | |
| 164 | - this.conversionMap.set(type, (moduleContext: ModuleContext, args: any[]) => { | ||
| 157 | + this.conversionMap.set(type, (context: StaticSymbol, args: any[]) => { | ||
| 165 | 158 | let argValues = []; | |
| 166 | 159 | ListWrapper.forEachWithIndex(args, (arg, index) => { | |
| 167 | 160 | let argValue; | |
| 168 | 161 | if (isStringMap(arg) && isBlank(arg['__symbolic'])) { | |
| 169 | - argValue = | ||
| 170 | - mapStringMap(arg, (value, key) => this.simplify( | ||
| 171 | - moduleContext, value) ); | ||
| 162 | + argValue = mapStringMap(arg, (value, key) => this.simplify(context, value)); | ||
| 172 | 163 | } else { | |
| 173 | - argValue = this.simplify(moduleContext, arg); | ||
| 164 | + argValue = this.simplify(context, arg); | ||
| 174 | 165 | } | |
| 175 | 166 | argValues.push(argValue); | |
| 176 | 167 | }); | |
@@ -183,7 +174,6 @@ export class StaticReflector implements ReflectorReader { | |||
| 183 | 174 | let diDecorators = 'angular2/src/core/di/decorators'; | |
| 184 | 175 | let diMetadata = 'angular2/src/core/di/metadata'; | |
| 185 | 176 | let provider = 'angular2/src/core/di/provider'; | |
| 186 | - let opaqueToken = 'angular2/src/core/di/opaque_token'; | ||
| 187 | 177 | this.registerDecoratorOrConstructor(this.host.findDeclaration(provider, 'Provider'), Provider); | |
| 188 | 178 | ||
| 189 | 179 | this.registerDecoratorOrConstructor(this.host.findDeclaration(diDecorators, 'Host'), | |
@@ -236,12 +226,10 @@ export class StaticReflector implements ReflectorReader { | |||
| 236 | 226 | SkipSelfMetadata); | |
| 237 | 227 | this.registerDecoratorOrConstructor(this.host.findDeclaration(diMetadata, 'OptionalMetadata'), | |
| 238 | 228 | OptionalMetadata); | |
| 239 | - this.registerDecoratorOrConstructor(this.host.findDeclaration(opaqueToken, 'OpaqueToken'), | ||
| 240 | - OpaqueToken); | ||
| 241 | 229 | } | |
| 242 | 230 | ||
| 243 | 231 | /** @internal */ | |
| 244 | - public simplify(moduleContext: ModuleContext, value: any): any { | ||
| 232 | + public simplify(context: StaticSymbol, value: any): any { | ||
| 245 | 233 | let _this = this; | |
| 246 | 234 | ||
| 247 | 235 | function simplify(expression: any): any { | |
@@ -331,41 +319,39 @@ export class StaticReflector implements ReflectorReader { | |||
| 331 | 319 | case "reference": | |
| 332 | 320 | if (isPresent(expression['module'])) { | |
| 333 | 321 | staticSymbol = _this.host.findDeclaration(expression['module'], expression['name'], | |
| 334 | - moduleContext.filePath); | ||
| 322 | + context.filePath); | ||
| 335 | 323 | } else { | |
| 336 | - staticSymbol = _this.host.getStaticSymbol( | ||
| 337 | - moduleContext.moduleId, moduleContext.filePath, expression['name']); | ||
| 324 | + staticSymbol = _this.host.getStaticSymbol(context.moduleId, context.filePath, | ||
| 325 | + expression['name']); | ||
| 338 | 326 | } | |
| 339 | 327 | let result = staticSymbol; | |
| 340 | 328 | let moduleMetadata = _this.getModuleMetadata(staticSymbol.filePath); | |
| 341 | - let declarationValue = isPresent(moduleMetadata) ? moduleMetadata['metadata'][staticSymbol.name] : null; | ||
| 329 | + let declarationValue = | ||
| 330 | + isPresent(moduleMetadata) ? moduleMetadata['metadata'][staticSymbol.name] : null; | ||
| 342 | 331 | if (isPresent(declarationValue)) { | |
| 343 | 332 | if (isClassMetadata(declarationValue)) { | |
| 344 | 333 | result = staticSymbol; | |
| 345 | 334 | } else { | |
| 346 | - let newModuleContext = | ||
| 347 | - new ModuleContext(staticSymbol.moduleId, staticSymbol.filePath); | ||
| 348 | - result = _this.simplify(newModuleContext, declarationValue); | ||
| 335 | + result = _this.simplify(staticSymbol, declarationValue); | ||
| 349 | 336 | } | |
| 350 | 337 | } | |
| 351 | 338 | return result; | |
| 339 | + case "class": | ||
| 340 | + return context; | ||
| 352 | 341 | case "new": | |
| 353 | 342 | case "call": | |
| 354 | 343 | let target = expression['expression']; | |
| 355 | - staticSymbol = _this.host.findDeclaration(target['module'], target['name'], | ||
| 356 | - moduleContext.filePath); | ||
| 344 | + staticSymbol = | ||
| 345 | + _this.host.findDeclaration(target['module'], target['name'], context.filePath); | ||
| 357 | 346 | let converter = _this.conversionMap.get(staticSymbol); | |
| 358 | - if (isBlank(converter)) { | ||
| 359 | - throw new BaseException(`Cannot convert call/new expression for ${target['name']} in ${moduleContext.filePath}`) | ||
| 360 | - } | ||
| 361 | 347 | if (isPresent(converter)) { | |
| 362 | 348 | let args = expression['arguments']; | |
| 363 | 349 | if (isBlank(args)) { | |
| 364 | 350 | args = []; | |
| 365 | 351 | } | |
| 366 | - return converter(moduleContext, args); | ||
| 352 | + return converter(context, args); | ||
| 367 | 353 | } else { | |
| 368 | - return staticSymbol; | ||
| 354 | + return context; | ||
| 369 | 355 | } | |
| 370 | 356 | } | |
| 371 | 357 | return null; | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -5,15 +5,14 @@ import {ListWrapper} from 'angular2/src/facade/collection'; | |||
| 5 | 5 | import { | |
| 6 | 6 | StaticReflector, | |
| 7 | 7 | StaticReflectorHost, | |
| 8 | - StaticSymbol, | ||
| 9 | - ModuleContext | ||
| 8 | + StaticSymbol | ||
| 10 | 9 | } from 'angular2/src/compiler/static_reflector'; | |
| 11 | 10 | ||
| 12 | 11 | export function main() { | |
| 13 | 12 | // Static reflector is not supported in Dart | |
| 14 | 13 | // as we use reflection to create objects. | |
| 15 | 14 | if (IS_DART) return; | |
| 16 | - let noContext = new ModuleContext('', ''); | ||
| 15 | + let noContext = new StaticSymbol('', '', ''); | ||
| 17 | 16 | ||
| 18 | 17 | describe('StaticReflector', () => { | |
| 19 | 18 | let host: StaticReflectorHost; | |
@@ -24,8 +23,8 @@ export function main() { | |||
| 24 | 23 | reflector = new StaticReflector(host); | |
| 25 | 24 | }); | |
| 26 | 25 | ||
| 27 | - function simplify(moduleContext: ModuleContext, value: any) { | ||
| 28 | - return reflector.simplify(moduleContext, value); | ||
| 26 | + function simplify(context: StaticSymbol, value: any) { | ||
| 27 | + return reflector.simplify(context, value); | ||
| 29 | 28 | } | |
| 30 | 29 | ||
| 31 | 30 | it('should get annotations for NgFor', () => { | |
@@ -219,9 +218,7 @@ export function main() { | |||
| 219 | 218 | }); | |
| 220 | 219 | ||
| 221 | 220 | it('should simplify an array index', () => { | |
| 222 | - expect( | ||
| 223 | - simplify(noContext, ({__symbolic: "index", expression: [1, 2, 3], index: 2}))) | ||
| 224 | - .toBe(3); | ||
| 221 | + expect(simplify(noContext, ({__symbolic: "index", expression: [1, 2, 3], index: 2}))).toBe(3); | ||
| 225 | 222 | }); | |
| 226 | 223 | ||
| 227 | 224 | it('should simplify an object index', () => { | |
@@ -230,14 +227,14 @@ export function main() { | |||
| 230 | 227 | }); | |
| 231 | 228 | ||
| 232 | 229 | it('should simplify a module reference', () => { | |
| 233 | - expect(simplify(new ModuleContext('', '/src/cases'), | ||
| 234 | - ({__symbolic: "reference", module: "./extern", name: "s"}))) | ||
| 230 | + expect(simplify(new StaticSymbol('', '/src/cases', ''), | ||
| 231 | + ({__symbolic: "reference", module: "./extern", name: "s"}))) | ||
| 235 | 232 | .toEqual("s"); | |
| 236 | 233 | }); | |
| 237 | 234 | ||
| 238 | 235 | it('should simplify a non existing reference as a static symbol', () => { | |
| 239 | - expect(simplify(new ModuleContext('', '/src/cases'), | ||
| 240 | - ({__symbolic: "reference", module: "./extern", name: "nonExisting"}))) | ||
| 236 | + expect(simplify(new StaticSymbol('', '/src/cases', ''), | ||
| 237 | + ({__symbolic: "reference", module: "./extern", name: "nonExisting"}))) | ||
| 241 | 238 | .toEqual(host.getStaticSymbol('', '/src/extern.d.ts', 'nonExisting')); | |
| 242 | 239 | }); | |
| 243 | 240 | }); | |
| Back | FazBrowse Home | New Git URL |
0 commit comments