From 0f83f251fe1dcfd82835b262c7bedbfe0f93c058 Mon Sep 17 00:00:00 2001 From: Myles Borins Date: Thu, 25 Jan 2018 14:32:43 -0800 Subject: [PATCH] module: enable dynamic import flag for esmodules MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit currently if you want to use dynamic import you must use both the `--experimental-modules` and the `--harmony-dynamic-imports` flags. Chrome is currently shipping dynamic import unflagged, the flag only remains in V8 to guard embedders who have not set the appropriate callback from throwing an unhandled rejection when the feature is used. As such it is reasonable to enable the flag by default for `--experimental-modules` Backport-PR-URL: https://github.com/nodejs/node/pull/17823 PR-URL: https://github.com/nodejs/node/pull/18387 Reviewed-By: Colin Ihrig Reviewed-By: Jan Krems Reviewed-By: Bradley Farias Reviewed-By: Guy Bedford Reviewed-By: Anna Henningsen Reviewed-By: Tiancheng "Timothy" Gu Reviewed-By: Ruben Bridgewater Reviewed-By: James M Snell Reviewed-By: Michaƫl Zasso --- doc/api/esm.md | 4 ++-- src/node.cc | 2 ++ test/es-module/test-esm-dynamic-import.js | 2 +- 3 files changed, 5 insertions(+), 3 deletions(-) diff --git a/doc/api/esm.md b/doc/api/esm.md index 926555fc771484..12805224dac52e 100644 --- a/doc/api/esm.md +++ b/doc/api/esm.md @@ -33,8 +33,8 @@ node --experimental-modules my-app.mjs ### Supported Only the CLI argument for the main entry point to the program can be an entry -point into an ESM graph. In the future `import()` can be used to create entry -points into ESM graphs at run time. +point into an ESM graph. Dynamic import can also be used to create entry points +into ESM graphs at runtime. ### Unsupported diff --git a/src/node.cc b/src/node.cc index ac73f62d190aff..694497eb0a4093 100644 --- a/src/node.cc +++ b/src/node.cc @@ -4154,6 +4154,8 @@ static void ParseArgs(int* argc, config_preserve_symlinks = true; } else if (strcmp(arg, "--experimental-modules") == 0) { config_experimental_modules = true; + new_v8_argv[new_v8_argc] = "--harmony-dynamic-import"; + new_v8_argc += 1; } else if (strcmp(arg, "--loader") == 0) { const char* module = argv[index + 1]; if (!config_experimental_modules) { diff --git a/test/es-module/test-esm-dynamic-import.js b/test/es-module/test-esm-dynamic-import.js index a099a2ddb8a1ce..773b77350180fe 100644 --- a/test/es-module/test-esm-dynamic-import.js +++ b/test/es-module/test-esm-dynamic-import.js @@ -1,4 +1,4 @@ -// Flags: --experimental-modules --harmony-dynamic-import +// Flags: --experimental-modules 'use strict'; const common = require('../common'); const assert = require('assert');