-
Notifications
You must be signed in to change notification settings - Fork 29.7k
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
RFC: <script type="ts/module"> #14032
Comments
If I understand correctly, it sounds like you want to compile ts which is inlined in html. Is that right? If so, I guess this should be a bug on TypeScript, not vscode, because that would be something they enable for any editor, not something vscode does. |
I need both of you, for example inline |
Everything from syntax highlighting to compilation is provided by typescript, so it would have to start with them. Some tool could take the current stuff and use it to compile TS embedded in html, but I don't really see that fitting with what vscode does today. Would rather see some other tool do that first. |
The tsserver supports embedded js (and ts for this matter). VSCode will need to extract the script tag contents, and send them to the server. all other LS operations should work regularly from this point on. No work on the tsserver-side should be needed, so microsoft/TypeScript#11739 should be closed, and this issue reopened (unless there is another issue tracking this work on the vscode side). It is worth noting that this is hte same support that VS 2015 uses to drive intellisense and other Language Service features in empeded JS code in script tags. |
CC @aeschli |
The subject rose on a discussion with the Polymer team about how to work with TypeScript within an HTML file. 1. Does TypeScript (tsc) work on an embedded TypeScript block within an HTML file? 2. what would be the output of such a file after compilation and how will it effect the structure of the project? The outcome of this would be to create a clear path for Polymer developers to use and enjoy the great power of TypeScript without compromising productivity. |
The TS language service does not do any HTML parsing or understanding. Sorry if i made it sound like so, let me explain. Mapping a section of a file to different language service is a common feature in a lot of editors/IDEs; for instance editing XML in a VB file, or Doc Comments in a JS file. Similarly editing the contents of JS script tag is handled by the JS language service, where as the rest of the file is handled by the HTML language service. this concept is usually referred to as mapped buffers. where the editor maps sections of the source to be handled by multiple language services. For the TS language service, the open file command request accepts an optional To put this all together, the editor has an HTML language service that understands HTML, once it finds a script tag, it will extract the contents (no HTML left here, just JS/TS code) into a new temp buffer, send that to the TS language service and specify scriptKindName as JS/TS. From this point on all TS language service features should work, e.g. completion, quick info, errors, etc.. the only one that needs changes is formatting, the editor needs to set Hope this provides enough information on how mapped buffers work in tsserver and TS LS.
I would expect that the polymer build pipeline will have a similar work flow as outlined above. Before calling the typescript compiler to check errors or generate output, the host (i.e. the build driver, or whoever is calling tsc) would extract script blocks, pass them to the compiler, get the output and place it in the matching script block in the output. |
Thanks @mhegazy for the thorough answer, it puts most of the peaces in place. Lets let the Polymer team figure out how they want to take it from here. |
Looking at the vscode plugin source code I realize this need to be done first https://github.com/Polymer/polymer-analyzer/issues/387 Still need some input if I need to issue for the |
As noted in the comments, I believe this is functionality that an extension or tooling would be able to provide. The recent addition of TypeScript support for Vetur may be a good starting reference for how this could work: vuejs/vetur#94 |
One of the directions modern web components are moving is declarative
html
. A bit likejsx
but the other way around :) Now forhtml / js
@rictic made a extension https://github.com/Polymer/vscode-plugin that brings auto completion for web components and their attribute defenition look up to a next level. https://youtu.be/zxcfPACo4-g?t=1h3m42s So that part is already done and backed by Google. Notice that we are talking web components in general here not just polymer.The problem is there is no
html
inlinets
solution yet. We can't really expect from the polymer team to integrate<script type="ts/module">
by themself in that extension.Now because
ts
is baked in vscode, inlinehtml / ts
compile support should be baked in as well. My first step is to convince everybody that if vscode can handle inlinehtml / ts
it would clear the way for using typescript web components by default. Right now typescript is not being used in polymer components because having two separate files, one forts
, one forhtml
takes away the main strong point of declarative component programing.Jsx
proved already thathtml
andjs
logic can be used together as a great way to structure your code. At Google they do the same but in a morehtml
declarative way.EDIT1:
<script type="ts/module">
content in html filesexample.ts.html
toexample.html
with thescript
contents andscript type
replaced.filename:
example.ts.html
EDIT2: Note I am also looking into how close ES20XX syntax and typescript syntax are going to get that a future browser can just ignore all the typing syntax and read
<script type="ts/module">
just like ES20XX javascript :) The browser doesn't need to look at the typings at all, just be smart enough to ignore typings that's it. If the two syntaxes matches close enough that can't be much to ask for browser vendors and the ECMA262 community right?tc39/ecma262#717
The text was updated successfully, but these errors were encountered: