You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+20-17Lines changed: 20 additions & 17 deletions
Original file line number
Diff line number
Diff line change
@@ -36,52 +36,55 @@ This proposal pursues the third option, as we expect it to lead to the best deve
36
36
37
37
Module attributes have to be made available in several different contexts. This section contains one possible syntax, but there are other options, discussed in [#6](https://github.com/littledan/proposal-module-attributes/issues/6).
38
38
39
-
Here, a key-value syntax is used, with the key `type` indicating the module type. Such key-value syntax can be used in various different contexts. Another option is to have just a single string (discussion in [#11](https://github.com/littledan/proposal-module-attributes/issues/11)).
39
+
Here, a key-value syntax is used, with the key `type`used as an example indicating the module type. Such key-value syntax can be used in various different contexts. Another option is to have just a single string (discussion in [#11](https://github.com/littledan/proposal-module-attributes/issues/11)).
40
40
41
-
The JavaScript standard would basically be responsible for passing the options bag up to the host environment, which could then decide how to interpret it. Issues [#24](https://github.com/littledan/proposal-module-attributes/issues/24) and [#25](https://github.com/littledan/proposal-module-attributes/issues/25) discuss the Web and Node.js semantics respectively, and issue [#10](https://github.com/littledan/proposal-module-attributes/issues/10) discusses how much we may or may not want to aim for unified behavior across different JavaScript environments.
41
+
The JavaScript standard would basically be responsible for passing the options bag up to the host environment, which could then decide how to interpret it. Issues [#24](https://github.com/littledan/proposal-module-attributes/issues/24) and [#25](https://github.com/littledan/proposal-module-attributes/issues/25) discuss the Web and Node.js feature and semantic requirements respectively, and issue [#10](https://github.com/littledan/proposal-module-attributes/issues/10) discusses how to allow different JavaScript environments to have interoperability.
42
42
43
43
### import statements
44
44
45
45
The ImportDeclaration would allow any arbitrary attributes after the `with` keyword.
46
46
47
-
A `type` key should be mandatory to load a module that isn't JavaScript (json, css, html, ...).
47
+
For example, in some environments a `type` key could be mandatory to load a module that isn't JavaScript (json, css, html, ...).
48
48
49
49
```js
50
50
importjsonfrom"./foo.json" with type: "json";
51
51
```
52
52
53
53
### dynamic import()
54
54
55
-
The `import` function will allow to provide arbritrary attributes as its second arguments.
55
+
The `import` function will allow to provide arbitrary attributes as its second arguments.
56
56
57
57
```js
58
58
import("foo.json", { type:"json" })
59
59
```
60
+
### Integration Example
60
61
61
-
### HTML
62
+
A host environment may wish to have `type` or similar apply to loading WebAssembly. WebAssembly's validation would fail if the magic number is not correct, but we'd assert that the mimetype matches the type before even before running the WebAssembly validation.
62
63
63
-
```html
64
-
<scriptsrc="foo.wasm"type="webassembly"></script>
65
-
```
66
-
67
-
WebAssembly's validation would fail if the magic number is not correct, but we'd assert that the mimetype matches the type before even before running the WebAssembly validation.
64
+
Note, this is an example; it's still uncertain whether importing WebAssembly modules would need to be marked specially, or could use `type="module"` just like JavaScript (and no special `with type:` in import statements). Further discussion in [#19](https://github.com/littledan/proposal-module-attributes/issues/19).
68
65
69
-
Note, it's still uncertain whether importing WebAssembly modules would need to be marked specially, or could use `type="module"` just like JavaScript (and no special `with type:` in import statements). Further discussion in [#19](https://github.com/littledan/proposal-module-attributes/issues/19).
66
+
From there, a host environment could integrate with its own APIs or even other languages:
70
67
71
-
### WebAssembly
72
-
73
-
For imports of other module types from within a WebAssembly module, this proposal would introduce a new custom section (named `importattributes`) that will annotate with attributes each imported module (which is listed in the import section).
74
-
75
-
### Worker instantiation
68
+
#### Worker instantiation
76
69
77
70
```js
78
71
newWorker("foo.wasm", { type:"webassembly" });
79
72
```
80
73
74
+
#### HTML
75
+
76
+
```html
77
+
<scriptsrc="foo.wasm"type="webassembly"></script>
78
+
```
79
+
80
+
#### WebAssembly
81
+
82
+
For imports of other module types from within a WebAssembly module, this proposal would introduce a new custom section (named `importattributes`) that will annotate with attributes each imported module (which is listed in the import section).
83
+
81
84
## Status and plan for standardization
82
85
83
86
This proposal has not yet been presented in a standards body. It's considered Stage 0 in TC39's process because we plan to present it to the committee. The plan is to collect feedback in issues, and present for Stage 1 in the December 2019 TC39 meeting.
84
87
85
-
Standardization here would consist of building consensus not just in TC39 but also in WHATWG HTML as well as the Node.js ESM effort and a general plan for semantics across various JS environments ([#10](https://github.com/littledan/proposal-module-attributes/issues/10), [#24](https://github.com/littledan/proposal-module-attributes/issues/24) and [#25](https://github.com/littledan/proposal-module-attributes/issues/25)). Stage 2 will also require that we have a strong initial answer for the surface syntax ([#6](https://github.com/littledan/proposal-module-attributes/issues/6)), including the choice of whether we use a single string or key/value pairs ([#12](https://github.com/littledan/proposal-module-attributes/issues/12)).
88
+
Standardization here would consist of building consensus not just in TC39 but also in WHATWG HTML as well as the Node.js ESM effort and a general audit of semantic requirements across various host environments ([#10](https://github.com/littledan/proposal-module-attributes/issues/10), [#24](https://github.com/littledan/proposal-module-attributes/issues/24) and [#25](https://github.com/littledan/proposal-module-attributes/issues/25)). Stage 2 will also require that we have a strong initial answer for the surface syntax ([#6](https://github.com/littledan/proposal-module-attributes/issues/6)), including the choice of whether we use a single string or key/value pairs ([#12](https://github.com/littledan/proposal-module-attributes/issues/12)).
86
89
87
90
Please leave any feedback you have in the [issues](http://github.com/littledan/proposal-module-attributes/issues)!
0 commit comments