Skip to content

Support HTML files #2218

Not planned
Not planned
@matthewp

Description

@matthewp

Using web components, and HTML Imports it's common to put JavaScript directly into HTML like so:

<template> ... </template>
<script>
(function(){
  // define a custom element here
})();
</script>

You can put these scripts into external files but it's often nicer not to. Would be nice if these <script>s could be flow checked.

Activity

danmindru

danmindru commented on Oct 19, 2016

@danmindru

Same case for .vue (Vue.js) components. There's a nasty workaround in Vue that'll make it work atm (using comments):

/* @flow
<template>...</template>

<style>...</style>
*/

// <script>
...
// </script>

It's nasty to say the least & it might break in a future release of Vue. If Flow could parse the <script> tag all of this will go away.

mickdekkers

mickdekkers commented on Nov 7, 2016

@mickdekkers

+💯

For reference, there is a plugin for ESLint called eslint-plugin-html that enables it to lint HTML files.
Perhaps something similar could be developed for Flow.

cr0cK

cr0cK commented on Dec 24, 2016

@cr0cK

Any progress on it? Vue is more and more popular, it should be nice if a solution à la eslint-plugin-html could be added to Flow... Perhaps like an option?

scottbedard

scottbedard commented on Jan 26, 2017

@scottbedard

Has any progress been made on this, or is anyone working on it? This feature is the only thing preventing me from using Flow.

therealmarv

therealmarv commented on Feb 4, 2017

@therealmarv

Is this a possible workaround for vue components?
Seperate .vue files at the beginning and let them act as kind of "loader" for .js and .html files like in this vue 2.0 boilerplate. It's this way not ugly looking comments.

Example .vue file:

<template src="./index.html"></template>
<script src="./index.js" lang="babel"></script>

and place your index.html and index.js (with your vue code) file in the same directory (let flow ignore .vue).

danmindru

danmindru commented on Feb 4, 2017

@danmindru

That should be fine for standalone, but it won't work for the runtime-only build.

therealmarv

therealmarv commented on Feb 4, 2017

@therealmarv

a workaround for runtime is babel-plugin-tcomb. Explanation here http://stackoverflow.com/a/40130503/756056

sobolevn

sobolevn commented on Feb 22, 2018

@sobolevn

You actually can use flow with vue.

module.exports = {
  "extends": [
    "standard"
  ],
  "plugins": [
    "html",
    "flowtype-errors"
   ],
   "rules": {
      // raise flow errors
      "flowtype-errors/show-errors": 2
   },
   "parser": "babel-eslint",
   "parserOptions": {
     "ecmaVersion": 2017,
     "sourceType": "module"
    }
}

Here's the full example: https://github.com/wemake-services/wemake-vue-template

mrkev

mrkev commented on May 24, 2018

@mrkev
Contributor

JS in HTML is a complicated issue. It potentially necessitates a whole new way of building dependency graphs and also introduces the concept of a cross-file global environment.

goodmind

goodmind commented on Jun 9, 2019

@goodmind
Contributor

@mrkev what you mean by cross-file global environment, isn't this already exists with declare var?

mrkev

mrkev commented on Jun 24, 2019

@mrkev
Contributor

@goodmind I mean the implicit window. I guess it's not necessary per-se, but I was just wondering how we could build a dependency graph with a different way of handling imports/exports.

goodmind

goodmind commented on Jul 28, 2019

@goodmind
Contributor

@mrkev would this require some OCaml HTML parser? jsx parser is not good for html files

mrkev

mrkev commented on Aug 8, 2019

@mrkev
Contributor

@goodmind probably that too for inline JS, yeah.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Development

      No branches or pull requests

        Participants

        @samwgoldman@matthewp@cr0cK@therealmarv@mrkev

        Issue actions

          Support HTML files · Issue #2218 · facebook/flow