2

When a script for some custom language appears in a webpage how are these scripts executed?

<script type='text/mighty-mouse'>
 // logic expressed in mighty mouse language
</script>

I would guess it would be something like this:

  1. Mighty Mouse interpreter queries the page on load for mighty-mouse scripts.
  2. The interpreter parses the script using standard lexing/compilation strategies and transpiles to JavaScript.
  3. The resulting JavaScript is dynamically injected into a standard script tag on the page, perhaps even eliminating the original mighty-mouse tag.

(I realize that we could have transcompiled before runtime to avoid having to load our interpreter.)

Is this an accurate and complete understanding?

Mario
  • 6,572
  • 3
  • 42
  • 74
  • 1
    You could start by reading the [*HTML5 specification*](http://www.w3.org/html/wg/drafts/html/CR/scripting-1.html#the-script-element): `Note: The exact processing details for these attributes are, for mostly historical reasons, somewhat non-trivial, involving a number of aspects of HTML. The implementation requirements are therefore by necessity scattered throughout the specification. The algorithms below (in this section) describe the core of this processing, but these algorithms reference and are referenced by the parsing rules for script start and end tags in HTML, in foreign content...`. – RobG Jun 29 '14 at 23:00
  • The bottom line is that there is a lot of historical behaviour associated with the script element and javascript. Any new scripting language may choose to leverage that, or head in a completely different direction (e.g. Java plugins and Flash objects). – RobG Jun 29 '14 at 23:03
  • 2
    Basically, the way the browser handles non-standard scripting languages will be implementation dependent. – Barmar Jun 29 '14 at 23:05

1 Answers1

1

As far as I know there are two ways. Either a browser plugin or more likely an interpreter written in JavaScript. Which essentially scans the DOM for the correct type and interpret the content.

CoffeeScript is a good example of the later.

Sukima
  • 9,965
  • 3
  • 46
  • 60