Skip to content

Allow evaluation of a detached buffer in a specified context (angular2 templates) #5470

Closed
@alexeagle

Description

@alexeagle

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,

@Component({selector: 'greet', template: 'Hello {{name}}!'})
 class Greet {
   name: string;
   constructor() {
     this.name = 'World';
   }
 }

The template could be represented in TypeScript with the expression

`Hello ${this.name}`

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):

__template_eval(): string { return `Hello ${this.name}`; }

as if this code existed inside the Greet class.

Also we would expect any ranges in the result to give the pos and width locations relative to the buffer we passed, not the Greet class.

Metadata

Metadata

Assignees

Labels

Needs ProposalThis issue needs a plan that clarifies the finer details of how it could be implemented.SuggestionAn idea for TypeScript

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions