-
Notifications
You must be signed in to change notification settings - Fork 12.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Allow evaluation of a detached buffer in a specified context (angular2 templates) #5470
Comments
Potentially duplicates #4169 |
Sounds more like #5151. |
Certainly related to those, and it would be better for us to solve this in a generalizable way. |
@billti has been looking into this, we need to come up with an extensibility model for the language service that allows for non-ts file services to be provided, be it completion, goto def, find all refs, etc.. |
Re the above example: How does the template engine know to rewrite It seems as though the template engine already needs to understand some of the scoping/context from the language service, to generate the code to give back to the language service. |
(as a minor clarification, TypeScript "supports" |
"Supports" is generous. It emits valid code, but any usage gives you a build error of If you don't mind errors in your project, then yes, it's supported. 😉 |
So {{Date}} wouldn't work in Angular either. Adding On Mon, Nov 2, 2015 at 3:43 PM Bill Ticehurst notifications@github.com
|
Ah, interesting. So in the simple case does it assume all identifiers are members on the instance? One area where I see this isn't safe is if I'm within a template which introduces a local, such as So it seems the expressions would need to be aware of surrounding tags and any locals they introduce, before they can assume |
Actually, on re-reading the blog, can sibling elements introduce names too? e.g.
EDIT: Adding this link as a useful reference: https://angular.io/docs/ts/latest/guide/template-syntax.html#template-expressions . Note syntax changes to "regular" JavaScript as well as "expression context". To circle back to the original point however: So it would seem the template engine doesn't need context from the underlying component code to understand its references and generate its code. Any identifiers it doesn't recognize (e.g. local names, |
@alexeagle with #12231 in place, do not think we need this issue any longer. can you please confirm? |
This is no longer necessary. |
thanks! closing. |
Angular/Typescript teams discussed this in person.
Angular 2 includes a template parser, and an expression language which may be used in places in the template.
We would like to translate the template to a TypeScript buffer, and pass the buffer to the language services for things like producing semantic errors, requesting intellisense, and the other usual editor features.
However, the template has a backing class (actually a virtual class per @tbosch ) where the fields may be referenced by template expressions. In our canonical example,
The template could be represented in TypeScript with the expression
In order to get intellisense or errors for that expression, we need to evaluate it in a place where
this.name
is defined. The obvious way to do this is for us to pass a "detached buffer", meaning a range of the SourceFile which lives outside the file content. It could look like (just a wild stab at possible syntax):as if this code existed inside the
Greet
class.Also we would expect any ranges in the result to give the
pos
andwidth
locations relative to the buffer we passed, not theGreet
class.The text was updated successfully, but these errors were encountered: