3 ms·
Exactly! You have to know whether something is a script or a module before you can parse it, but with this plan, that's always clear from the context. This is
by s_tec 8y ago
Exactly! You have to know whether something is a script or a module before you can parse it, but with this plan, that's always clear from the context.
This is exactly how browsers do it, by the way. If you `import` something, is a module, period. The `<script>` tag is the only place that supports both, so they use a `module="true"` flag to indicate which is which.
- deleted 8y ago[deleted]
- chrismorgan 8y agoSmall correction: it’s <script type="module">, as distinct from <script> or <script type="text/javascript">.
- jkrems 8y ago> This is exactly how browsers do it, by the way. If you `import` something, is a module, period. The `<script>` tag is the only place that supports both, so they use a `module="true"` flag to indicate which is which. This is not entirely true. If you import something and it's served with a content type associated with JavaScript modules, then it's interpreted as a JS module. But if they are served with a wasm content-type, they may in the future interpreted as wasm modules. In node there's the additional content-type of "CommonJS file" which has to be handled somehow as well. Non-module script tags aren't really relevant because node itself never supported scripts (at least not what the browser and the ECMA standard calls scripts).