From 308d361a79ea6bf62ba95152e7b92c6419fa3752 Mon Sep 17 00:00:00 2001 From: Antoine du Hamel Date: Fri, 8 Jan 2021 16:55:52 +0100 Subject: [PATCH] doc: use ESM syntax for WASI example PR-URL: https://github.com/nodejs/node/pull/36848 Reviewed-By: Jiawen Geng Reviewed-By: Colin Ihrig Reviewed-By: Guy Bedford --- .eslintrc.js | 1 + doc/api/wasi.md | 14 ++++++-------- 2 files changed, 7 insertions(+), 8 deletions(-) diff --git a/.eslintrc.js b/.eslintrc.js index d0360a8c852deb..7bb997d79fad1d 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -57,6 +57,7 @@ module.exports = { 'doc/api/module.md', 'doc/api/modules.md', 'doc/api/packages.md', + 'doc/api/wasi.md', 'test/es-module/test-esm-type-flag.js', 'test/es-module/test-esm-type-flag-alias.js', '*.mjs', diff --git a/doc/api/wasi.md b/doc/api/wasi.md index 66971aa0631540..100e7eac3eb94a 100644 --- a/doc/api/wasi.md +++ b/doc/api/wasi.md @@ -11,9 +11,9 @@ specification. WASI gives sandboxed WebAssembly applications access to the underlying operating system via a collection of POSIX-like functions. ```js -'use strict'; -const fs = require('fs'); -const { WASI } = require('wasi'); +import fs from 'fs'; +import { WASI } from 'wasi'; + const wasi = new WASI({ args: process.argv, env: process.env, @@ -23,12 +23,10 @@ const wasi = new WASI({ }); const importObject = { wasi_snapshot_preview1: wasi.wasiImport }; -(async () => { - const wasm = await WebAssembly.compile(fs.readFileSync('./demo.wasm')); - const instance = await WebAssembly.instantiate(wasm, importObject); +const wasm = await WebAssembly.compile(fs.readFileSync('./demo.wasm')); +const instance = await WebAssembly.instantiate(wasm, importObject); - wasi.start(instance); -})(); +wasi.start(instance); ``` To run the above example, create a new WebAssembly text format file named