Skip to content
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

Support for ES6 Templates #960

Merged
merged 21 commits into from Oct 31, 2014
Merged

Support for ES6 Templates #960

merged 21 commits into from Oct 31, 2014

Conversation

DanielRosenwasser
Copy link
Member

This pull request is meant to add support for ECMAScript 6 templates and address suggestion #13.

Right now this branch supports:

  • Both simple and substitution templates for all emit targets
  • Tagged template parse/emit solely for ES6 (and above) targets.
  • Syntactic highlighting in the LS for template literals
  • Completion lists in substitution position.

Things that will be done in a separate commit:

  • Type checking for tagged template expressions by checking assignability of substitution expressions to respective tag parameters.
  • Add typings for the "cooked strings" parameter of tags.
  • Patch up parts of the languages service that don't account for templates.
  • Better parse errors for places that expect string literals.
  • Experiment with brace matching on substitution templates.
  • Experiment with indentation in the language service.

Questions worth asking:

  • Do we want to accept simple (non-substitution) templates in places we accept string literals (i.e. module names, overloading on string constants, etc.)? On one hand, it would seem more consistent with the rest of our language, but ECMAScript 6 does not accept them in property names.
  • When indexing with a template literal, should we try to perform a static property lookup?
  • Are void-typed items allowed to be in substitution position? Are there any restrictions on what can be go in a substitution expression?
  • Do we want type arguments on a tagged template?

@@ -5932,6 +5939,12 @@ module ts {
return getUnionType([type1, type2]);
}

function checkTemplateExpression(node: TemplateExpression): void {
forEach((<TemplateExpression>node).templateSpans, templateSpan => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Explain why this is correct. I believe it's because we rewrite this to string addition, and string addition allows the other side to be of any type. So we don't need to check for things like void types, etc. But it would be good to comment this bit.

@JsonFreeman
Copy link
Contributor

"Do we want to accept simple (non-substitution) templates in places we accept string literals (i.e. module names, overloading on string constants, etc.)? On one hand, it would seem more consistent with the rest of our language, but ECMAScript 6 does not accept them in property names."

I would say no. I'm not sure we have a reason to be more lenient than ES6.

@DanielRosenwasser
Copy link
Member Author

@JsonFreeman I agree; what about indexing?

@JsonFreeman
Copy link
Contributor

I think we can type an index expression with literal, yes.

Conflicts:
	src/compiler/checker.ts
	src/services/services.ts
Conflicts:
	src/compiler/diagnosticInformationMap.generated.ts
	src/compiler/diagnosticMessages.json
	src/compiler/types.ts
	src/services/utilities.ts
DanielRosenwasser added a commit that referenced this pull request Oct 31, 2014
@DanielRosenwasser DanielRosenwasser merged commit 0a97f5f into master Oct 31, 2014
@DanielRosenwasser DanielRosenwasser deleted the templates branch October 31, 2014 22:19
@vvakame
Copy link
Contributor

vvakame commented Nov 10, 2014

@RyanCavanaugh excuse me. please add es6 label to this issue.
I want to check es6 feature on this url https://github.com/Microsoft/TypeScript/issues?q=label%3AES6

@danquirk danquirk added the ES6 Relates to the ES6 Spec label Nov 10, 2014
@Vadorequest
Copy link

I just noticed that this ES6 feature is still a proposal, so why implement it already? Not that it isn't great and useful, just wondering why focusing on things that are still status: Draft on ES6 specs. I guess you have your reasons, just wonder what they are ;)

@DanielRosenwasser
Copy link
Member Author

It's actually pretty much nailed down, and it's very unlikely that it will be removed/modified drastically. If anything does change, we'll be very mindful in addressing that. =)

@Vadorequest
Copy link

Ok, nice then, it's a nice feature btw, looking forward for 1.4. :)

@topherfangio
Copy link

Hi there, I realize that this is on the Roadmap for 1.4. I'm curious though if we might see it sooner as perhaps an experimental option. My team and I would certainly love to start using this sooner rather than later to clean up our code :-)

Cheers!

@DanielRosenwasser
Copy link
Member Author

Hey @topherfangio, glad to hear you're enthusiastic about this feature.

If you're dying to try it out, you can clone our repo and use our release-1.4 branch, but 1.4 is largely on the horizon, just be patient. =)

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
ES6 Relates to the ES6 Spec
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

9 participants