-
Notifications
You must be signed in to change notification settings - Fork 27.1k
Description
In one example angular2 app I have this tsconfig.json:
{
"compilerOptions": {
"target": "es6",
"noEmit": true,
"experimentalDecorators": true,
"baseUrl": "../../..",
"rootDirs": [".", "../../../dist/js/cjs"],
"paths": {
"angular2/*": ["dist/js/cjs/angular2/*"],
"rxjs/*": ["node_modules/rxjs/*"]
}
}
}
which means that a statement like import {} from 'angular2/core'; results in a SourceFile reference with fileName ../../../dist/js/cjs/angular2/core.d.ts.
If I run the metadata collector on a SourceFile containing the reference, then I get metadata that has that path still present:
{"__symbolic":"module","module":"./basic","metadata":{"Basic":{"__symbolic":"class","decorators":[{"__symbolic":"call","expression":{"__symbolic":"reference","name":"Component","module":"../../../dist/js/cjs/angular2/src/core/metadata"},"arguments":[{"selector":"basic","template":"<div>{{ctxProp}}</div>"}]},{"__symbolic":"call","expression":{"__symbolic":"reference","name":"Injectable","module":"../../../dist/js/cjs/angular2/src/core/di/decorators"}}]}}}
This doesn't work with the StaticReflector, which is hard-coded to look for paths starting with angular2:
https://github.com/angular/angular/blob/master/modules/angular2/src/compiler/static_reflector.ts#L138
One possible fix is fix up the path to look like the common case. The metadata collector already does this, but only handles leading node_modules (https://github.com/angular/angular/blob/master/tools/metadata/src/collector.ts#L37 )
The CompilerHost on the calling side could provide a resolution that works backwards to strip the leading ../../.. and then reverse the path mapping of dist/js/cjs/angular2/* to angular2/*. I'd hate to maintain such a thing, unless we find a utility in the typescript CompilerHost that canonicalizes in this way.
Another possible fix is in the StaticReflector, to accept that not all paths to our known decorators will start with angular2/.... But this seems wrong, we really want to get a canonical name and know that the symbol is really ours.
At the moment this blocks my compiler CLI. I could shuffle around my test fixture again, so it doesn't use pathMapping. But even then, users can still create a working TypeScript app that looks this way, so we should support it.