doc: update es6.md, add import assertions (#79)

* feat: add import assertions

* update
This commit is contained in:
fw_qaq 2022-11-15 14:28:54 +08:00 committed by GitHub
parent 41b42c17b7
commit 7b46142372
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -706,6 +706,23 @@ new URL('data.txt', import.meta.url)
Node.js 环境中,`import.meta.url`返回的总是本地路径,即 `file:URL` 协议的字符串,比如 `file:///home/user/foo.js` Node.js 环境中,`import.meta.url`返回的总是本地路径,即 `file:URL` 协议的字符串,比如 `file:///home/user/foo.js`
### 导入断言Import Assertions
<!--rehype:wrap-class=col-span-2-->
#### 静态导入
```js
import json from "./package.json" assert {type: "json"}
// 导入 json 文件中的所有对象
```
#### 动态导入
```js
const json =
await import("./package.json", { assert: { type: "json" } })
```
Generators Generators
---------- ----------