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

[html] support 'import' in <script type=module> tags #29315

Closed
vp2177 opened this issue Jun 23, 2017 · 7 comments · May be fixed by #171547
Closed

[html] support 'import' in <script type=module> tags #29315

vp2177 opened this issue Jun 23, 2017 · 7 comments · May be fixed by #171547
Assignees
Labels
feature-request Request for new features or functionality javascript JavaScript support issues
Milestone

Comments

@vp2177
Copy link
Contributor

vp2177 commented Jun 23, 2017

  • VSCode Version: 1.38.1 (originally 1.13.1)
  • OS Version: any

Steps to Reproduce:

  1. Given the files:
    a.js:
/**
 * @param {number} param1
 * @param {string} param2
 */
export function a(param1, param2) {}

index.html:

<script type="module">
  import {a} from './a.js'

  a( )
</script>
  1. When typing a(, the type information is not picked up from the definition of a() in a.js.
  2. Same works from a JS file

Now that import is beginning to appear in browsers I think handling this would make sense

@vscodebot vscodebot bot added new release bug Issue identified by VS Code Team member as probable bug javascript JavaScript support issues labels Jun 23, 2017
@aeschli aeschli changed the title import support in <script> tags [html] support 'input' in <script> tags Jun 26, 2017
@aeschli aeschli added feature-request Request for new features or functionality and removed bug Issue identified by VS Code Team member as probable bug labels Jun 26, 2017
@aeschli aeschli added this to the Backlog milestone Jun 26, 2017
@mjbvz mjbvz self-assigned this Jun 29, 2017
@mjbvz mjbvz changed the title [html] support 'input' in <script> tags [html] support 'import' in <script> tags Jul 3, 2017
@Rich-Harris
Copy link

Adding a note to say that ideally VSCode would also autocomplete import specifiers in<script> tags, the same way it does in .js and .ts files. Opened #35732 for this, but it was closed as a duplicate of this issue.

@vincentvictoria
Copy link

Seems like this issue is vastly ignored.
I have to make a separate js file even if I want to write a short module script in html files because of this issue.
Hope it gets attention.

@bsunderhus
Copy link

This feature would fit greatly with HTML Modules proposal

@aeschli
Copy link
Contributor

aeschli commented Oct 9, 2019

duplicate of #26338

@aeschli aeschli closed this as completed Oct 9, 2019
@Rich-Harris
Copy link

Is this a duplicate of #26338? They feel quite different — this issue is about being able to reuse the logic around import that already exists in .js and .ts files, whereas #26338 seems to be about applying intellisense to code that references legacy scripts that e.g. assign to window, which seems like a different (and much hairier!) problem, especially when considering async and defer attributes. Apologies if I've misunderstood.

@vp2177 vp2177 changed the title [html] support 'import' in <script> tags [html] support 'import' in <script type=module> tags Oct 9, 2019
@aeschli
Copy link
Contributor

aeschli commented Oct 9, 2019

@Rich-Harris Not exactly the same, I agree. Both issues are about making HTML following references and configuring the typescript service with additional files. The challenge for both is that we likely need a project understanding as to where to find the files.

@vp2177
Copy link
Contributor Author

vp2177 commented Oct 10, 2019

As long as the import URL is relative (import './a.js', import 'a.js', import '../a.js' etc.), then relative to the current file.

If the import URL has a http[s] schema, then potentially fetch the file there.

Isn't the only case that's hard to handle an absolute import URL (import '/a.js' etc.)? In which case, I think the current behaviour is fine, just don't reference that file. It probably isn't in the project root and VSCode has no way to know where it would be served from at runtime.
Potentially add a config option, but I think that's a separate feature request.

@vscodebot vscodebot bot locked and limited conversation to collaborators Nov 25, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
feature-request Request for new features or functionality javascript JavaScript support issues
Projects
None yet
Development

Successfully merging a pull request may close this issue.

7 participants