Skip to content

Commit 6cd1c64

Browse files
Rename from "assertions" to "attributes" (#134)
1 parent 51f5364 commit 6cd1c64

File tree

3 files changed

+248
-248
lines changed

3 files changed

+248
-248
lines changed

README.md

Lines changed: 32 additions & 32 deletions
Original file line numberOriginal file lineDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Import Assertions
1+
# Import Attributes
2

2

3
Champions: Sven Sauleau ([@xtuc](https://github.com/xtuc)), Daniel Ehrenberg ([@littledan](https://github.com/littledan)), Myles Borins ([@MylesBorins](https://github.com/MylesBorins)), Dan Clark ([@dandclark](https://github.com/dandclark)), and Nicolò Ribaudo ([@nicolo-ribaudo](https://github.com/nicolo-ribaudo)).
3
Champions: Sven Sauleau ([@xtuc](https://github.com/xtuc)), Daniel Ehrenberg ([@littledan](https://github.com/littledan)), Myles Borins ([@MylesBorins](https://github.com/MylesBorins)), Dan Clark ([@dandclark](https://github.com/dandclark)), and Nicolò Ribaudo ([@nicolo-ribaudo](https://github.com/nicolo-ribaudo)).
4

4

@@ -7,11 +7,11 @@ Status: Stage 2.
7
> ⚠️ This proposal has been demoted from Stage 3 to Stage 2 in January 2023 due to [problems with the web integration](https://github.com/whatwg/html/issues/7233). TC39 is working on a solution, which will require relaxing the "assert only" semantics and potentially changing the syntax.
7
> ⚠️ This proposal has been demoted from Stage 3 to Stage 2 in January 2023 due to [problems with the web integration](https://github.com/whatwg/html/issues/7233). TC39 is working on a solution, which will require relaxing the "assert only" semantics and potentially changing the syntax.
8
> Import assertions have already been shipped in some implementations, consider the current instability when using them.
8
> Import assertions have already been shipped in some implementations, consider the current instability when using them.
9
9
10-
Please leave any feedback you have in the [issues](http://github.com/tc39/proposal-import-assertions/issues)!
10+
Please leave any feedback you have in the [issues](http://github.com/tc39/proposal-import-attributes/issues)!
11

11

12
## Synopsis
12
## Synopsis
13

13

14-
The Import Assertions proposal adds an inline syntax for module import statements to pass on more information alongside the module specifier. The initial application for such assertions will be to support additional types of modules in a common way across JavaScript environments, starting with [JSON modules](http://github.com/tc39/proposal-json-modules).
14+
The Import Attributes proposal, formerly known as Import Assertions, adds an inline syntax for module import statements to pass on more information alongside the module specifier. The initial application for such attributes will be to support additional types of modules in a common way across JavaScript environments, starting with [JSON modules](http://github.com/tc39/proposal-json-modules).
15

15

16
The syntax will be as follows (shown here is the proposed method for importing a JSON module):
16
The syntax will be as follows (shown here is the proposed method for importing a JSON module):
17
```js
17
```js
@@ -29,59 +29,59 @@ However, in [an issue](https://github.com/w3c/webcomponents/issues/839), Ryosuke
29

29

30
Some developers have the intuition that the file extension could be used to determine the module type, as it is in many existing non-standard module systems. However, it's a deep web architectural principle that the suffix of the URL (which you might think of as the "file extension" outside of the web) does not lead to semantics of how the page is interpreted. In practice, on the web, there is a widespread [mismatch between file extension and the HTTP Content Type header](content-type-vs-file-extension.md). All of this sums up to it being infeasible to depend on file extensions/suffixes included in the module specifier to be the basis for this checking.
30
Some developers have the intuition that the file extension could be used to determine the module type, as it is in many existing non-standard module systems. However, it's a deep web architectural principle that the suffix of the URL (which you might think of as the "file extension" outside of the web) does not lead to semantics of how the page is interpreted. In practice, on the web, there is a widespread [mismatch between file extension and the HTTP Content Type header](content-type-vs-file-extension.md). All of this sums up to it being infeasible to depend on file extensions/suffixes included in the module specifier to be the basis for this checking.
31

31

32-
There are other possible pieces of metadata which could be associated with modules, see [#8](https://github.com/tc39/proposal-import-assertions/issues/8) and [tc39/proposal-import-reflection#18](https://github.com/tc39/proposal-import-reflection/issues/18) for further discussion.
32+
There are other possible pieces of metadata which could be associated with modules, see [#8](https://github.com/tc39/proposal-import-attributes/issues/8) and [tc39/proposal-import-reflection#18](https://github.com/tc39/proposal-import-reflection/issues/18) for further discussion.
33

33

34
Proposed ES module types that are blocked by this security concern, in addition to JSON modules, include [CSS modules](https://github.com/whatwg/html/pull/4898) and potentially [HTML modules](https://github.com/whatwg/html/pull/4505) if the HTML module proposal is restricted to [not allow script](https://github.com/w3c/webcomponents/issues/805).
34
Proposed ES module types that are blocked by this security concern, in addition to JSON modules, include [CSS modules](https://github.com/whatwg/html/pull/4898) and potentially [HTML modules](https://github.com/whatwg/html/pull/4505) if the HTML module proposal is restricted to [not allow script](https://github.com/w3c/webcomponents/issues/805).
35

35

36
## Rationale
36
## Rationale
37

37

38
There are three places where this data could be provided:
38
There are three places where this data could be provided:
39
- As part of the module specifier (e.g., as a pseudo-scheme)
39
- As part of the module specifier (e.g., as a pseudo-scheme)
40-
- Challenges: Adds complexity to URLs or other module specifier syntaxes, and risks being confusing to developers (further discussion: [#11](https://github.com/tc39/proposal-import-assertions/issues/11))
40+
- Challenges: Adds complexity to URLs or other module specifier syntaxes, and risks being confusing to developers (further discussion: [#11](https://github.com/tc39/proposal-import-attributes/issues/11))
41
- webpack supports this sort of construct ([docs](https://webpack.js.org/concepts/loaders/#inline)).
41
- webpack supports this sort of construct ([docs](https://webpack.js.org/concepts/loaders/#inline)).
42
- Demand from users for similar behavior in Parcel, with pushback from some maintainers ([#3477](https://github.com/parcel-bundler/parcel/issues/3477))
42
- Demand from users for similar behavior in Parcel, with pushback from some maintainers ([#3477](https://github.com/parcel-bundler/parcel/issues/3477))
43
- Separately, out of band (e.g., a separate resource file)
43
- Separately, out of band (e.g., a separate resource file)
44-
- Challenges: How to load that resource file; what should the format be; unergonomic to have to jump between files during development (further discussion: [#13](https://github.com/tc39/proposal-import-assertions/issues/13))
44+
- Challenges: How to load that resource file; what should the format be; unergonomic to have to jump between files during development (further discussion: [#13](https://github.com/tc39/proposal-import-attributes/issues/13))
45
- In the JavaScript source text
45
- In the JavaScript source text
46
- Challenges: Requires a change at the JavaScript language level (this proposal)
46
- Challenges: Requires a change at the JavaScript language level (this proposal)
47

47

48
This proposal pursues the third option, as we expect it to lead to the best developer experience, and are hopeful that language design/standardization issues can be resolved.
48
This proposal pursues the third option, as we expect it to lead to the best developer experience, and are hopeful that language design/standardization issues can be resolved.
49

49

50
## Proposed syntax
50
## Proposed syntax
51

51

52-
Import assertions have to be made available in several different contexts. They use a key-value syntax is used preceded by the `with` keyword, with the key `type` used as an example indicating the module type. Such key-value syntax can be used in various different contexts.
52+
Import attributes have to be made available in several different contexts. They use a key-value syntax is used preceded by the `with` keyword, with the key `type` used as an example indicating the module type. Such key-value syntax can be used in various different contexts.
53

53

54
### import statements
54
### import statements
55

55

56-
The ImportDeclaration would allow any arbitrary assertions after the `with` keyword.
56+
The ImportDeclaration would allow any arbitrary attributes after the `with` keyword.
57

57

58-
For example, the `type` assertion could be used to indicate a module type, for example importing a JSON module with the following syntax.
58+
For example, the `type` attribute could be used to indicate a module type, for example importing a JSON module with the following syntax.
59

59

60
```mjs
60
```mjs
61
import json from "./foo.json" with { type: "json" };
61
import json from "./foo.json" with { type: "json" };
62
```
62
```
63

63

64-
The `with` syntax in the `ImportDeclaration` statement uses curly braces, for the following reasons (as discussed in [#5](https://github.com/tc39/proposal-import-assertions/issues/5)):
64+
The `with` syntax in the `ImportDeclaration` statement uses curly braces, for the following reasons (as discussed in [#5](https://github.com/tc39/proposal-import-attributes/issues/5)):
65-
- JavaScript developers are already used to the Object literal syntax and since it allows a trailing comma copy/pasting assertions will be easy.
65+
- JavaScript developers are already used to the Object literal syntax and since it allows a trailing comma copy/pasting attributes will be easy.
66-
- it clearly indicates the end of the assertions list when splitting them across multiple lines.
66+
- it clearly indicates the end of the attributes list when splitting them across multiple lines.
67

67

68
### re-export statements
68
### re-export statements
69

69

70-
Similar to import statements, the ExportDeclaration, when re-exporting from another module, would allow any arbitrary assertions after the `with` keyword.
70+
Similar to import statements, the ExportDeclaration, when re-exporting from another module, would allow any arbitrary attributes after the `with` keyword.
71

71

72
```mjs
72
```mjs
73
export { val } from './foo.js' with { type: "javascript" };
73
export { val } from './foo.js' with { type: "javascript" };
74
```
74
```
75

75

76
### dynamic import()
76
### dynamic import()
77

77

78-
The `import()` pseudo-function would allow import assertions to be indicated in an options bag in the second argument.
78+
The `import()` pseudo-function would allow import attributes to be indicated in an options bag in the second argument.
79

79

80
```js
80
```js
81
import("foo.json", { with: { type: "json" } })
81
import("foo.json", { with: { type: "json" } })
82
```
82
```
83

83

84-
The second parameter to `import()` is an options bag, with the only option currently defined to be `with`: the value here is an object containing the import assertions. There are other proposals for entries to put in the options bag: for example, the [Module Source Imports](https://github.com/tc39/proposal-import-reflection) proposal introduces a `phase` property.
84+
The second parameter to `import()` is an options bag, with the only option currently defined to be `with`: the value here is an object containing the import attributes. There are other proposals for entries to put in the options bag: for example, the [Module Source Imports](https://github.com/tc39/proposal-import-reflection) proposal introduces a `phase` property.
85

85

86
### Integration of modules into environments
86
### Integration of modules into environments
87

87

@@ -93,7 +93,7 @@ Host environments (e.g., the Web platform, Node.js) often provide various differ
93
new Worker("foo.wasm", { type: "module", with: { type: "webassembly" } });
93
new Worker("foo.wasm", { type: "module", with: { type: "webassembly" } });
94
```
94
```
95

95

96-
Sidebar about WebAssembly module types and the web: it's still uncertain whether importing WebAssembly modules would need to be marked specially, or would be imported just like JavaScript. Further discussion in [#19](https://github.com/tc39/proposal-import-assertions/issues/19).
96+
Sidebar about WebAssembly module types and the web: it's still uncertain whether importing WebAssembly modules would need to be marked specially, or would be imported just like JavaScript. Further discussion in [#19](https://github.com/tc39/proposal-import-attributes/issues/19).
97

97

98
#### HTML
98
#### HTML
99

99

@@ -107,15 +107,15 @@ Although changes to HTML won't be specified by TC39, an idea here would be that
107

107

108
#### WebAssembly
108
#### WebAssembly
109

109

110-
In the context of the [WebAssembly/ESM integration proposal](https://github.com/webassembly/esm-integration): for imports of other module types from within a WebAssembly module, this proposal would introduce a new custom section (named `importassertions`) that will annotate with assertions each imported module (which is listed in the import section).
110+
In the context of the [WebAssembly/ESM integration proposal](https://github.com/webassembly/esm-integration): 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).
111

111

112
## Proposed semantics and interoperability
112
## Proposed semantics and interoperability
113

113

114-
This proposal does not specify behavior for any particular assertion key or value. The [JSON modules proposal](https://github.com/tc39/proposal-json-modules) will specify that `type: "json"` must be interpreted as a JSON module, and will specify common semantics for doing so. It is expected the `type` attribute will be leveraged to support additional module types in future TC39 proposals as well as by hosts. HTML and CSS modules are under consideration, and these may use similar explicit `type` syntax when imported.
114+
This proposal does not specify behavior for any particular attribute key or value. The [JSON modules proposal](https://github.com/tc39/proposal-json-modules) will specify that `type: "json"` must be interpreted as a JSON module, and will specify common semantics for doing so. It is expected the `type` attribute will be leveraged to support additional module types in future TC39 proposals as well as by hosts. HTML and CSS modules are under consideration, and these may use similar explicit `type` syntax when imported.
115

115

116-
Assertions in addition than `type` may also be introduced for purposes not yet foreseen.
116+
Attributes in addition than `type` may also be introduced for purposes not yet foreseen.
117

117

118-
JavaScript implementations are encouraged to reject assertions and type values which are not implemented in their environment (rather than ignoring them). This is to allow for maximal flexibility in the design space in the future--in particular, it enables new import assertions to be defined which change the interpretation of a module, without breaking backwards-compatibility.
118+
JavaScript implementations are encouraged to reject attributes and type values which are not implemented in their environment (rather than ignoring them). This is to allow for maximal flexibility in the design space in the future--in particular, it enables new import attributes to be defined which change the interpretation of a module, without breaking backwards-compatibility.
119

119

120
## FAQ
120
## FAQ
121

121

@@ -140,25 +140,25 @@ However, at the same time, behavior of modules in general, and the set of module
140

140

141
We see the management of compatibility issues across environments as similar, independent of whether metadata is held in-band or out-of-band. An out of band solution would also suffer from the risk of inconsistent implementation or support across host environments if some kind of coordination does not occur.
141
We see the management of compatibility issues across environments as similar, independent of whether metadata is held in-band or out-of-band. An out of band solution would also suffer from the risk of inconsistent implementation or support across host environments if some kind of coordination does not occur.
142

142

143-
The topic of attribute divergence is further discussed in [#34](https://github.com/tc39/proposal-import-assertions/issues/34).
143+
The topic of attribute divergence is further discussed in [#34](https://github.com/tc39/proposal-import-attributes/issues/34).
144

144

145
### How would this proposal work with caching?
145
### How would this proposal work with caching?
146

146

147-
Assertions are part of the module cache key and can affect how a module is loaded: the cache key is extended from _(referrer, specifier)_ to _(referrer, specifier, assertions)_.
147+
Attributes are part of the module cache key and can affect how a module is loaded: the cache key is extended from _(referrer, specifier)_ to _(referrer, specifier, attributes)_.
148

148

149
### Why not use more terse syntax to indicate module types, like `import json from "./foo.json" as "json"`?
149
### Why not use more terse syntax to indicate module types, like `import json from "./foo.json" as "json"`?
150

150

151-
Another option considered and not selected has been to use a single string as the attribute, indicating the type. This option is not selected due to its implication that any particular attribute is special; even though this proposal only specifies the `type` attribute, the intention is to be open to more assertions in the future. (discussion in [#12](https://github.com/tc39/proposal-import-assertions/issues/12)).
151+
Another option considered and not selected has been to use a single string as the attribute, indicating the type. This option is not selected due to its implication that any particular attribute is special; even though this proposal only specifies the `type` attribute, the intention is to be open to more attributes in the future. (discussion in [#12](https://github.com/tc39/proposal-import-attributes/issues/12)).
152

152

153
### Should more than just strings be supported as attribute values?
153
### Should more than just strings be supported as attribute values?
154

154

155-
We could permit import assertions to have more complex values than simply strings, for example:
155+
We could permit import attributes to have more complex values than simply strings, for example:
156

156

157
```js
157
```js
158
import value from "module" assert { attr: { key1: "value1", key2: [1, 2, 3] } };
158
import value from "module" assert { attr: { key1: "value1", key2: [1, 2, 3] } };
159
```
159
```
160

160

161-
This would allow import assertions to scale to support a larger variety of metadata.
161+
This would allow import attributes to scale to support a larger variety of metadata.
162

162

163
We propose to omit this generalization in the initial proposal, as a key/value list of strings already affords significant flexibility to start, but we're open to a follow-on proposal providing this kind of generalization.
163
We propose to omit this generalization in the initial proposal, as a key/value list of strings already affords significant flexibility to start, but we're open to a follow-on proposal providing this kind of generalization.
164

164

@@ -173,7 +173,7 @@ We are planning to make descisions and reach consensus during specific stages of
173

173

174
We have achieved consensus on the following core decisions as part of Stage 2, including:
174
We have achieved consensus on the following core decisions as part of Stage 2, including:
175

175

176-
- The attribute form; key-value or single string ([#12](https://github.com/tc39/proposal-import-assertions/issues/12))
176+
- The attribute form; key-value or single string ([#12](https://github.com/tc39/proposal-import-attributes/issues/12))
177

177

178
```mjs
178
```mjs
179
// Not selected
179
// Not selected
@@ -190,14 +190,14 @@ import value from "module" assert { type: "json" };
190

190

191
After Stage 2 and before Stage 3, we're open to settling on some less core details, such as:
191
After Stage 2 and before Stage 3, we're open to settling on some less core details, such as:
192

192

193-
- Considering alternatives for the `with`/`if`/`assert` keywords ([#3](https://github.com/tc39/proposal-import-assertions/issues/3))
193+
- Considering alternatives for the `with`/`if`/`assert` keywords ([#3](https://github.com/tc39/proposal-import-attributes/issues/3))
194

194

195
```mjs
195
```mjs
196
import value from "module" when { type: 'json' };
196
import value from "module" when { type: 'json' };
197
import value from "module" given { type: 'json' };
197
import value from "module" given { type: 'json' };
198
```
198
```
199

199

200-
- How dynamic import would accept import assertions:
200+
- How dynamic import would accept import attributes:
201
```mjs
201
```mjs
202
import("foo.wasm", { with: { type: "webassembly" } });
202
import("foo.wasm", { with: { type: "webassembly" } });
203
```
203
```
@@ -215,16 +215,16 @@ However, that's not possible with the `Worker` API since it already uses an obje
215

215

216
#### Before Stage 4
216
#### Before Stage 4
217

217

218-
- The integration of import assertions into various host environments.
218+
- The integration of import attributes into various host environments.
219-
- For example, in the Web Platform, how import assertions would be enabled when launching a worker (if that is supported in the initial version to be shipped on the Web) or included in a `<script>` tag.
219+
- For example, in the Web Platform, how import attributes would be enabled when launching a worker (if that is supported in the initial version to be shipped on the Web) or included in a `<script>` tag.
220

220

221
```mjs
221
```mjs
222
new Worker("foo.wasm", { type: "module", with: { type: "webassembly" } });
222
new Worker("foo.wasm", { type: "module", with: { type: "webassembly" } });
223
```
223
```
224

224

225-
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/tc39/proposal-import-assertions/issues/10), [#24](https://github.com/tc39/proposal-import-assertions/issues/24) and [#25](https://github.com/tc39/proposal-import-assertions/issues/25)).
225+
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/tc39/proposal-import-attributes/issues/10), [#24](https://github.com/tc39/proposal-import-attributes/issues/24) and [#25](https://github.com/tc39/proposal-import-attributes/issues/25)).
226

226

227
## Specification
227
## Specification
228

228

229-
* [Specification Outline](https://tc39.es/proposal-import-assertions/)
229+
* [Specification Outline](https://tc39.es/proposal-import-attributes/)
230
* [Pull Request for HTML spec integration](https://github.com/whatwg/html/pull/5658)
230
* [Pull Request for HTML spec integration](https://github.com/whatwg/html/pull/5658)

0 commit comments

Comments
 (0)